2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTemplateModel class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-04 12:43:21 +00:00
|
|
|
* Represents a template invocation that's part of a (possibly unbalanced) sequence of template
|
2021-06-03 16:25:15 +00:00
|
|
|
* invocations and raw wikitext snippets. Meant to be an item in a {@see ve.dm.MWTransclusionModel}.
|
2021-06-18 08:44:32 +00:00
|
|
|
* Holds a back-reference to its parent.
|
2021-06-03 16:25:15 +00:00
|
|
|
*
|
|
|
|
* Holds a reference to the specification of the template, i.e. how the template is documented via
|
|
|
|
* TemplateData. The actual invocation might be entirely different, missing parameters as well as
|
|
|
|
* containing undocumented ones.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.MWTransclusionPartModel
|
|
|
|
*
|
|
|
|
* @constructor
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {ve.dm.MWTransclusionModel} transclusion
|
2013-06-11 19:16:04 +00:00
|
|
|
* @param {Object} target Template target
|
|
|
|
* @param {string} target.wt Original wikitext of target
|
|
|
|
* @param {string} [target.href] Hypertext reference to target
|
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.dm.MWTemplateModel = function VeDmMWTemplateModel( transclusion, target ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWTemplateModel.super.call( this, transclusion );
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.target = target;
|
2013-10-09 21:20:51 +00:00
|
|
|
|
|
|
|
// TODO: Either here or in uses of this constructor we need to validate the title
|
2020-03-20 17:08:24 +00:00
|
|
|
this.title = target.href ? mw.libs.ve.normalizeParsoidResourceName( target.href ) : null;
|
2021-06-04 12:04:10 +00:00
|
|
|
this.orderedParameterNames = null;
|
2013-06-11 19:16:04 +00:00
|
|
|
this.params = {};
|
|
|
|
this.spec = new ve.dm.MWTemplateSpecModel( this );
|
2013-07-12 00:23:33 +00:00
|
|
|
this.originalData = null;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWTemplateModel, ve.dm.MWTransclusionPartModel );
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event add
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event remove
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
|
2013-07-12 00:23:33 +00:00
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create from data.
|
|
|
|
*
|
|
|
|
* Data is in the format provided by Parsoid.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionModel} transclusion Transclusion template is in
|
|
|
|
* @param {Object} data Template data
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {ve.dm.MWTemplateModel} New template model
|
2013-07-12 00:23:33 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.newFromData = function ( transclusion, data ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var template = new ve.dm.MWTemplateModel( transclusion, data.target );
|
2013-07-12 00:23:33 +00:00
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var key in data.params ) {
|
2013-07-12 00:23:33 +00:00
|
|
|
template.addParameter(
|
2015-08-19 17:33:02 +00:00
|
|
|
new ve.dm.MWParameterModel( template, key, data.params[ key ].wt )
|
2013-07-12 00:23:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template.setOriginalData( data );
|
|
|
|
|
|
|
|
return template;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create from name.
|
|
|
|
*
|
|
|
|
* Name is equivalent to what would be entered between double brackets, defaulting to the Template
|
|
|
|
* namespace, using a leading colon to access other namespaces.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionModel} transclusion Transclusion template is in
|
2014-10-30 16:24:04 +00:00
|
|
|
* @param {string|mw.Title} name Template name
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {ve.dm.MWTemplateModel|null} New template model
|
2013-07-12 00:23:33 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.newFromName = function ( transclusion, name ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var title,
|
2014-11-10 20:03:10 +00:00
|
|
|
templateNs = mw.config.get( 'wgNamespaceIds' ).template;
|
2014-10-30 16:24:04 +00:00
|
|
|
if ( name instanceof mw.Title ) {
|
|
|
|
title = name;
|
2014-11-10 20:03:10 +00:00
|
|
|
name = title.getRelativeText( templateNs );
|
2014-10-30 16:24:04 +00:00
|
|
|
} else {
|
2014-11-10 20:03:10 +00:00
|
|
|
title = mw.Title.newFromText( name, templateNs );
|
2014-10-30 16:24:04 +00:00
|
|
|
}
|
|
|
|
if ( title !== null ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var href = title.getPrefixedText();
|
2015-01-11 17:38:36 +00:00
|
|
|
return new ve.dm.MWTemplateModel( transclusion, { href: href, wt: name } );
|
2014-10-30 16:24:04 +00:00
|
|
|
}
|
2013-07-12 00:23:33 +00:00
|
|
|
|
2014-10-30 16:24:04 +00:00
|
|
|
return null;
|
2013-07-12 00:23:33 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object} Template target
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getTarget = function () {
|
|
|
|
return this.target;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string|null} Template title, if available
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getTitle = function () {
|
|
|
|
return this.title;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {ve.dm.MWTemplateSpecModel} Template specification
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getSpec = function () {
|
|
|
|
return this.spec;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-28 10:53:45 +00:00
|
|
|
* Get all parameters that are currently present in this template invocation in the order as they
|
|
|
|
* originally appear in the wikitext. This is critical for {@see serialize}. Might contain
|
|
|
|
* placeholders with the parameter name "".
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-28 10:53:45 +00:00
|
|
|
* @return {Object.<string,ve.dm.MWParameterModel>} Parameters keyed by name or alias
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getParameters = function () {
|
|
|
|
return this.params;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name Parameter name
|
2021-06-18 08:44:32 +00:00
|
|
|
* @return {ve.dm.MWParameterModel|undefined}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getParameter = function ( name ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
return this.params[ name ];
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2013-07-10 19:04:11 +00:00
|
|
|
/**
|
|
|
|
* Check if a parameter exists.
|
|
|
|
*
|
|
|
|
* @param {string} name Parameter name
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Parameter exists
|
2013-07-10 19:04:11 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.hasParameter = function ( name ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var params = this.params;
|
2013-07-10 19:04:11 +00:00
|
|
|
|
|
|
|
// Check if name (which may be an alias) is present in the template
|
2021-06-08 13:09:52 +00:00
|
|
|
if ( name in params ) {
|
2013-07-10 19:04:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the name is known at all
|
2021-06-24 12:53:39 +00:00
|
|
|
if ( !this.spec.isKnownParameterOrAlias( name ) ) {
|
2021-06-08 13:09:52 +00:00
|
|
|
return false;
|
2013-07-10 19:04:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 12:48:29 +00:00
|
|
|
var primaryName = this.spec.getPrimaryParameterName( name );
|
2021-06-08 13:09:52 +00:00
|
|
|
// Check for primary name (may be the same as name)
|
|
|
|
if ( primaryName in params ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Check for other aliases (may include name)
|
|
|
|
return this.spec.getParameterAliases( primaryName ).some( function ( alias ) {
|
|
|
|
return alias in params;
|
|
|
|
} );
|
2013-07-10 19:04:11 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-18 08:44:32 +00:00
|
|
|
* Get all potential parameters, known and unknown.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-18 08:44:32 +00:00
|
|
|
* All parameters reported by TemplateData, plus any unknown parameters present
|
2021-06-18 08:44:32 +00:00
|
|
|
* in the template invocation. Known parameters are ordered according to
|
|
|
|
* `paramOrder`, or when absent to the order of parameters as they appear in
|
|
|
|
* TemplateData.
|
2021-06-18 08:44:32 +00:00
|
|
|
*
|
2021-06-18 08:44:32 +00:00
|
|
|
* Known parameters are in TemplateData order, and unknown parameters are sorted
|
|
|
|
* with numeric names first, followed by alphabetically sorted names.
|
2021-06-18 14:09:52 +00:00
|
|
|
*
|
|
|
|
* @return {string[]}
|
2021-06-18 08:44:32 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getAllParametersOrdered = function () {
|
2021-06-28 10:37:01 +00:00
|
|
|
var spec = this.spec,
|
|
|
|
currentParams = Object.keys( this.params ),
|
2021-06-28 10:53:45 +00:00
|
|
|
undocumentedParams = currentParams.filter( function ( name ) {
|
2021-06-28 10:37:01 +00:00
|
|
|
return !spec.isDocumentedParameterOrAlias( name );
|
2021-06-28 10:53:45 +00:00
|
|
|
} );
|
2021-06-28 10:37:01 +00:00
|
|
|
|
2021-06-18 08:44:32 +00:00
|
|
|
// Unknown parameters in alpha-numeric order second, empty string at the very end
|
2021-06-28 10:53:45 +00:00
|
|
|
undocumentedParams.sort( function ( a, b ) {
|
2021-06-18 08:44:32 +00:00
|
|
|
var aIsNaN = isNaN( a ),
|
|
|
|
bIsNaN = isNaN( b );
|
|
|
|
|
|
|
|
if ( a === '' ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( b === '' ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ( aIsNaN && bIsNaN ) {
|
|
|
|
// Two strings
|
|
|
|
return a < b ? -1 : a === b ? 0 : 1;
|
|
|
|
}
|
|
|
|
if ( aIsNaN ) {
|
|
|
|
// A is a string
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( bIsNaN ) {
|
|
|
|
// B is a string
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// Two numbers
|
|
|
|
return a - b;
|
|
|
|
} );
|
2021-06-28 10:37:01 +00:00
|
|
|
|
|
|
|
var documentedParams = spec.getDocumentedParameterOrder();
|
|
|
|
|
|
|
|
// Restore aliases in the list of documented parameters
|
|
|
|
currentParams.forEach( function ( name ) {
|
|
|
|
if ( spec.isParameterAlias( name ) ) {
|
|
|
|
documentedParams.splice(
|
|
|
|
// This can never fail because only documented parameters can have aliases
|
|
|
|
documentedParams.indexOf( spec.getPrimaryParameterName( name ) ),
|
|
|
|
1,
|
|
|
|
name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-06-18 08:44:32 +00:00
|
|
|
// TODO: cache results
|
2021-06-28 10:37:01 +00:00
|
|
|
return documentedParams.concat( undocumentedParams );
|
2021-06-18 08:44:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-28 10:53:45 +00:00
|
|
|
* Returns the same parameters as {@see getParameters}, i.e. parameters that are currently present
|
|
|
|
* in this template invocation, but sorted in a canonical order for presentational purposes.
|
|
|
|
*
|
|
|
|
* Don't use this if you need the parameters as they originally appear in the wikitext, or if you
|
|
|
|
* don't care about an order. Use {@see getParameters} together with `Object.keys()` instead.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-28 10:53:45 +00:00
|
|
|
* @return {string[]} Sorted list of parameter names
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-06-04 12:04:10 +00:00
|
|
|
ve.dm.MWTemplateModel.prototype.getOrderedParameterNames = function () {
|
|
|
|
if ( !this.orderedParameterNames ) {
|
2021-06-18 08:44:32 +00:00
|
|
|
var paramNames = Object.keys( this.params );
|
|
|
|
this.orderedParameterNames = this.getAllParametersOrdered().filter( function ( name ) {
|
|
|
|
return paramNames.indexOf( name ) !== -1;
|
2013-06-11 19:16:04 +00:00
|
|
|
} );
|
|
|
|
}
|
2021-06-04 12:04:10 +00:00
|
|
|
return this.orderedParameterNames;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2014-03-01 00:39:02 +00:00
|
|
|
/**
|
|
|
|
* Get parameter from its ID.
|
|
|
|
*
|
|
|
|
* @param {string} id Parameter ID
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {ve.dm.MWParameterModel|null} Parameter with matching ID, null if no parameters match
|
2014-03-01 00:39:02 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getParameterFromId = function ( id ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var name in this.params ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( this.params[ name ].getId() === id ) {
|
|
|
|
return this.params[ name ];
|
2014-03-01 00:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Add a parameter to template.
|
|
|
|
*
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Parameter to add
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires add
|
2021-06-25 14:46:59 +00:00
|
|
|
* @fires change
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-06-29 02:37:42 +00:00
|
|
|
ve.dm.MWTemplateModel.prototype.addParameter = function ( param ) {
|
|
|
|
var name = param.getName();
|
2021-06-04 12:04:10 +00:00
|
|
|
this.orderedParameterNames = null;
|
2015-08-19 17:33:02 +00:00
|
|
|
this.params[ name ] = param;
|
2018-11-21 12:33:32 +00:00
|
|
|
this.spec.fillFromTemplate();
|
2014-08-22 20:50:48 +00:00
|
|
|
param.connect( this, { change: [ 'emit', 'change' ] } );
|
2013-06-11 19:16:04 +00:00
|
|
|
this.emit( 'add', param );
|
2013-12-09 19:05:57 +00:00
|
|
|
this.emit( 'change' );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-17 16:32:26 +00:00
|
|
|
* Remove a parameter from this MWTemplateModel, and emit events which result in removing the
|
|
|
|
* parameter from the UI. Note this does *not* remove the parameter from the linked specification.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-04 11:46:16 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} [param]
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires remove
|
2021-06-17 16:32:26 +00:00
|
|
|
* @fires change
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-06-29 02:37:42 +00:00
|
|
|
ve.dm.MWTemplateModel.prototype.removeParameter = function ( param ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
if ( param ) {
|
2021-06-04 12:04:10 +00:00
|
|
|
this.orderedParameterNames = null;
|
2015-08-19 17:33:02 +00:00
|
|
|
delete this.params[ param.getName() ];
|
2013-12-09 19:05:57 +00:00
|
|
|
param.disconnect( this );
|
2013-06-11 19:16:04 +00:00
|
|
|
this.emit( 'remove', param );
|
2013-12-09 19:05:57 +00:00
|
|
|
this.emit( 'change' );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
};
|
2013-07-12 00:23:33 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-13 19:43:47 +00:00
|
|
|
* @inheritdoc
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2014-04-28 19:10:31 +00:00
|
|
|
ve.dm.MWTemplateModel.prototype.addPromptedParameters = function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var addedCount = 0,
|
2021-06-08 13:09:52 +00:00
|
|
|
params = this.params,
|
2021-07-02 15:30:54 +00:00
|
|
|
spec = this.spec,
|
2021-06-28 10:53:45 +00:00
|
|
|
names = spec.getKnownParameterNames();
|
2013-12-02 20:10:55 +00:00
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var i = 0; i < names.length; i++ ) {
|
|
|
|
var name = names[ i ];
|
|
|
|
var foundAlias = spec.getParameterAliases( name ).some( function ( alias ) {
|
2021-06-08 13:09:52 +00:00
|
|
|
return alias in params;
|
|
|
|
} );
|
2014-04-28 19:10:31 +00:00
|
|
|
if (
|
2016-09-30 00:57:23 +00:00
|
|
|
!foundAlias &&
|
2021-06-08 13:09:52 +00:00
|
|
|
!params[ name ] &&
|
2016-06-30 15:46:38 +00:00
|
|
|
(
|
|
|
|
spec.isParameterRequired( name ) ||
|
|
|
|
spec.isParameterSuggested( name )
|
|
|
|
)
|
|
|
|
) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.addParameter( new ve.dm.MWParameterModel( this, names[ i ] ) );
|
2014-07-21 21:06:54 +00:00
|
|
|
addedCount++;
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-21 21:06:54 +00:00
|
|
|
|
|
|
|
return addedCount;
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set original data, to be used as a base for serialization.
|
2016-10-28 19:02:36 +00:00
|
|
|
*
|
|
|
|
* @param {Object} data Original data
|
2013-07-12 00:23:33 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.setOriginalData = function ( data ) {
|
|
|
|
this.originalData = data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.serialize = function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var origData = this.originalData || {},
|
2014-11-10 20:00:34 +00:00
|
|
|
origParams = origData.params || {},
|
2021-07-02 15:30:54 +00:00
|
|
|
template = { target: this.target, params: {} },
|
|
|
|
spec = this.spec,
|
|
|
|
params = this.params;
|
2013-07-12 00:23:33 +00:00
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var name in params ) {
|
2014-03-20 05:27:59 +00:00
|
|
|
if ( name === '' ) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-16 18:43:00 +00:00
|
|
|
|
2021-03-12 21:50:42 +00:00
|
|
|
if (
|
|
|
|
// Don't add empty parameters (T101075)
|
|
|
|
params[ name ].getValue() === '' &&
|
|
|
|
// …unless they were present before the edit
|
|
|
|
!Object.prototype.hasOwnProperty.call( origParams, name ) &&
|
|
|
|
// …unless they are required (T276989)
|
2021-06-24 12:53:39 +00:00
|
|
|
!( spec.isKnownParameterOrAlias( name ) && spec.isParameterRequired( name ) )
|
2021-03-12 21:50:42 +00:00
|
|
|
) {
|
2020-11-16 18:43:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
var origName = params[ name ].getOriginalName();
|
2015-08-19 17:33:02 +00:00
|
|
|
template.params[ origName ] = ve.extendObject(
|
2014-11-10 20:00:34 +00:00
|
|
|
{},
|
2015-08-19 17:33:02 +00:00
|
|
|
origParams[ origName ],
|
|
|
|
{ wt: params[ name ].getValue() }
|
2014-11-10 20:00:34 +00:00
|
|
|
);
|
|
|
|
|
2013-07-12 00:23:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 20:00:34 +00:00
|
|
|
// Performs a non-deep extend, so this won't reintroduce
|
2018-08-09 14:10:53 +00:00
|
|
|
// deleted parameters (T75134)
|
2014-11-10 20:00:34 +00:00
|
|
|
template = ve.extendObject( {}, origData, template );
|
2014-08-22 20:50:48 +00:00
|
|
|
return { template: template };
|
2013-07-12 00:23:33 +00:00
|
|
|
};
|
2013-12-09 19:05:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.getWikitext = function () {
|
2021-07-02 15:30:54 +00:00
|
|
|
var wikitext = this.target.wt;
|
2013-12-09 19:05:57 +00:00
|
|
|
|
2021-07-02 15:30:54 +00:00
|
|
|
for ( var param in this.params ) {
|
2014-03-20 05:27:59 +00:00
|
|
|
if ( param === '' ) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-09 19:05:57 +00:00
|
|
|
wikitext += '|' + param + '=' +
|
2021-07-02 15:30:54 +00:00
|
|
|
ve.dm.MWTransclusionNode.static.escapeParameter( this.params[ param ].getValue() );
|
2013-12-09 19:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return '{{' + wikitext + '}}';
|
|
|
|
};
|
2021-05-17 11:26:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateModel.prototype.isEmpty = function () {
|
2021-07-02 15:30:54 +00:00
|
|
|
var params = this.params;
|
2021-05-17 11:26:11 +00:00
|
|
|
|
|
|
|
return Object.keys( params ).every( function ( name ) {
|
|
|
|
// There is always an unnamed placeholder at the start
|
|
|
|
if ( !name ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-04 12:04:10 +00:00
|
|
|
var param = params[ name ],
|
|
|
|
value = param.getValue();
|
2021-05-17 11:26:11 +00:00
|
|
|
// Check that the value has not been set, or is indistinguishable from
|
|
|
|
// the automatically-set value. See `MWParameterModel.getValue`
|
|
|
|
return value === '' || value === param.getAutoValue();
|
|
|
|
} );
|
|
|
|
};
|