mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
Merge "Make MWTransclusionModel and MWTemplateDialog extensible"
This commit is contained in:
commit
8005868566
|
@ -4,6 +4,9 @@
|
|||
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/* global mw */
|
||||
|
||||
( function () {
|
||||
var hasOwn = Object.hasOwnProperty,
|
||||
specCache = {};
|
||||
|
@ -25,6 +28,7 @@
|
|||
this.uid = 0;
|
||||
this.requests = [];
|
||||
this.queue = [];
|
||||
this.specCache = specCache;
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -189,7 +193,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
var i, len, item, title, request,
|
||||
var i, len, item, title,
|
||||
titles = [],
|
||||
specs = {},
|
||||
queue = this.queue.slice();
|
||||
|
@ -223,15 +227,22 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// Request template specs from server
|
||||
request = ve.init.target.constructor.static.apiRequest( {
|
||||
this.requests.push( this.fetchRequest( titles, specs, queue ) );
|
||||
};
|
||||
|
||||
ve.dm.MWTransclusionModel.prototype.fetchRequest = function ( titles, specs, queue ) {
|
||||
return ve.init.target.constructor.static.apiRequest( {
|
||||
action: 'templatedata',
|
||||
titles: titles.join( '|' ),
|
||||
lang: mw.config.get( 'wgUserLanguage' ),
|
||||
redirects: '1'
|
||||
} )
|
||||
.done( function ( data ) {
|
||||
var i, len, id, aliasMap = [];
|
||||
.done( ve.bind( this.fetchRequestDone, this, titles, specs ) )
|
||||
.always( ve.bind( this.fetchRequestAlways, this, queue ) );
|
||||
};
|
||||
|
||||
ve.dm.MWTransclusionModel.prototype.fetchRequestDone = function ( titles, specs, data ) {
|
||||
var i, len, id, title, aliasMap = [];
|
||||
|
||||
if ( data && data.pages ) {
|
||||
// Keep spec data on hand for future use
|
||||
|
@ -265,18 +276,16 @@
|
|||
|
||||
ve.extendObject( specCache, specs );
|
||||
}
|
||||
} )
|
||||
.always( function () {
|
||||
};
|
||||
|
||||
ve.dm.MWTransclusionModel.prototype.fetchRequestAlways = function ( queue, data, textStatus, jqXHR ) {
|
||||
// Prune completed request
|
||||
var index = ve.indexOf( request, this.requests );
|
||||
var index = ve.indexOf( jqXHR, this.requests );
|
||||
if ( index !== -1 ) {
|
||||
this.requests.splice( index, 1 );
|
||||
}
|
||||
// Actually add queued items
|
||||
this.process( queue );
|
||||
}.bind( this ) );
|
||||
|
||||
this.requests.push( request );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/* global mw */
|
||||
|
||||
/**
|
||||
* Dialog for inserting and editing MediaWiki transclusions.
|
||||
*
|
||||
|
@ -439,7 +441,7 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
|||
this.transclusionModel, data.template
|
||||
);
|
||||
promise = this.transclusionModel.addPart( template ).done( function () {
|
||||
template.addPromptedParameters();
|
||||
this.initializeNewTemplateParameters();
|
||||
} );
|
||||
} else {
|
||||
// New template placeholder
|
||||
|
@ -451,7 +453,10 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
|||
this.actions.setMode( 'edit' );
|
||||
// Load existing template
|
||||
promise = this.transclusionModel
|
||||
.load( ve.copy( this.selectedNode.getAttribute( 'mw' ) ) );
|
||||
.load( ve.copy( this.selectedNode.getAttribute( 'mw' ) ) )
|
||||
.done( ve.bind( function () {
|
||||
this.initializeTemplateParameters();
|
||||
}, this ) );
|
||||
}
|
||||
this.actions.setAbilities( { apply: false, insert: false } );
|
||||
this.pushPending();
|
||||
|
@ -459,6 +464,27 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
|||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize parameters for new template insertion
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
ve.ui.MWTemplateDialog.prototype.initializeNewTemplateParameters = function () {
|
||||
var i, parts = this.transclusionModel.getParts();
|
||||
for ( i = 0; i < parts.length; i++ ) {
|
||||
if ( parts[i] instanceof ve.dm.MWTemplateModel ) {
|
||||
parts[i].addPromptedParameters();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Intentionally empty. This is provided for Wikia extensibility.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
ve.ui.MWTemplateDialog.prototype.initializeTemplateParameters = function () {};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue