2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTemplateSpecModel 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-03 16:25:15 +00:00
|
|
|
* Holds a mixture of:
|
|
|
|
* - A copy of a template's specification as it is documented via TemplateData.
|
|
|
|
* - Undocumented parameters that appear in a template invocation, {@see fillFromTemplate}.
|
2021-06-25 14:46:59 +00:00
|
|
|
* - Documented aliases are also considered valid, known parameter names. Use
|
|
|
|
* {@see isParameterAlias} to differentiate between the two.
|
2021-06-03 16:25:15 +00:00
|
|
|
* Therefore this is not the original specification but an accessor to the documentation for an
|
|
|
|
* individual template invocation. It's possible different for every invocation.
|
|
|
|
*
|
|
|
|
* Meant to be in a 1:1 relationship to {@see ve.dm.MWTemplateModel}.
|
|
|
|
*
|
|
|
|
* The actual, unmodified specification can be found in {@see specCache} in
|
|
|
|
* {@see ve.dm.MWTransclusionModel}.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2020-12-10 15:47:48 +00:00
|
|
|
* See https://github.com/wikimedia/mediawiki-extensions-TemplateData/blob/master/Specification.md
|
2013-06-19 20:00:11 +00:00
|
|
|
* for the latest version of the TemplateData specification.
|
|
|
|
*
|
2013-06-11 19:16:04 +00:00
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* @constructor
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template
|
2021-07-01 08:24:23 +00:00
|
|
|
* @property {Object.<string,boolean>} seenParameterNames Keeps track of any parameter from any
|
|
|
|
* source and in which order they have been seen first. Includes parameters that have been removed
|
|
|
|
* during the lifetime of this object, i.e. {@see fillFromTemplate} doesn't remove parameters that
|
|
|
|
* have been seen before. The order is typically but not necessarily the original order in which
|
|
|
|
* the parameters appear in the template. Aliases are resolved and don't appear on their original
|
|
|
|
* position any more.
|
2021-07-02 15:52:42 +00:00
|
|
|
* @property {Object} templateData Documentation as provided by the TemplateData API
|
|
|
|
* @property {Object.<string,string>} aliases Maps aliases to primary parameter names
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel = function VeDmMWTemplateSpecModel( template ) {
|
|
|
|
// Properties
|
|
|
|
this.template = template;
|
2021-07-01 08:24:23 +00:00
|
|
|
this.seenParameterNames = {};
|
2021-09-01 10:47:43 +00:00
|
|
|
this.templateData = { notemplatedata: true, params: {} };
|
2021-06-24 14:24:04 +00:00
|
|
|
this.aliases = {};
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
// Initialization
|
2018-11-21 12:33:32 +00:00
|
|
|
this.fillFromTemplate();
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 16:36:05 +00:00
|
|
|
OO.initClass( ve.dm.MWTemplateSpecModel );
|
|
|
|
|
|
|
|
/* Static methods */
|
|
|
|
|
2021-06-24 12:44:10 +00:00
|
|
|
/**
|
|
|
|
* @private
|
2021-07-02 15:52:42 +00:00
|
|
|
* @param {string|Object.<string,string>|null} stringOrObject
|
2021-06-24 15:44:07 +00:00
|
|
|
* @param {string} [languageCode]
|
2021-07-02 15:52:42 +00:00
|
|
|
* @return {string|null|undefined}
|
2021-06-24 12:44:10 +00:00
|
|
|
*/
|
2021-06-24 15:44:07 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.static.getLocalValue = function ( stringOrObject, languageCode ) {
|
2018-09-23 16:36:05 +00:00
|
|
|
return stringOrObject && typeof stringOrObject === 'object' ?
|
2021-06-24 15:44:07 +00:00
|
|
|
OO.ui.getLocalValue( stringOrObject, languageCode ) :
|
2018-09-23 16:36:05 +00:00
|
|
|
stringOrObject;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2021-07-01 08:45:56 +00:00
|
|
|
* Template spec data is available from the TemplateData extension's API.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-08-13 10:47:28 +00:00
|
|
|
* @param {Object} data As returned by the TemplataData API. Expected to be in formatversion=2,
|
|
|
|
* guaranteed via {@see ve.init.mw.Target.prototype.getContentApi}.
|
|
|
|
* @param {boolean} [data.notemplatedata] True when there is no user-provided documentation.
|
|
|
|
* `params` are auto-detected in this case.
|
2021-07-02 15:52:42 +00:00
|
|
|
* @param {string|Object.<string,string>} [data.description] Template description
|
2021-06-28 09:14:18 +00:00
|
|
|
* @param {string[]} [data.paramOrder] Preferred parameter order as documented via TemplateData. If
|
|
|
|
* given, the TemplateData API makes sure this contains the same parameters as `params`.
|
2021-07-02 15:52:42 +00:00
|
|
|
* @param {Object.<string,Object>} [data.params] Template param specs keyed by param name
|
|
|
|
* @param {{label:(string|Object.<string,string>),params:string[]}[]} [data.sets] List of parameter
|
|
|
|
* sets, i.e. parameters that belong together (whatever that means, this feature is underspecified
|
|
|
|
* and unused)
|
|
|
|
* @param {Object.<string,Object.<string,string|string[]|string[][]>>} [data.maps] Source to target
|
|
|
|
* parameter mappings for consumers like Citoid or gadgets
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-07-01 09:00:44 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.setTemplateData = function ( data ) {
|
2021-09-01 10:47:43 +00:00
|
|
|
if ( !data || !ve.isPlainObject( data ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.templateData = data;
|
2021-07-01 08:45:56 +00:00
|
|
|
// Better be safe even if the `params` element isn't optional in the TemplateData API
|
|
|
|
if ( !this.templateData.params ) {
|
|
|
|
this.templateData.params = {};
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2021-06-23 14:31:07 +00:00
|
|
|
|
2021-07-02 15:15:11 +00:00
|
|
|
var resolveAliases = false;
|
|
|
|
|
2021-07-01 08:45:56 +00:00
|
|
|
for ( var primaryName in this.templateData.params ) {
|
|
|
|
this.seenParameterNames[ primaryName ] = true;
|
2021-07-01 08:24:23 +00:00
|
|
|
|
2021-07-01 08:45:56 +00:00
|
|
|
var aliases = this.getParameterAliases( primaryName );
|
|
|
|
for ( var i = 0; i < aliases.length; i++ ) {
|
|
|
|
var alias = aliases[ i ];
|
|
|
|
this.aliases[ alias ] = primaryName;
|
2021-07-02 15:15:11 +00:00
|
|
|
if ( alias in this.seenParameterNames ) {
|
|
|
|
resolveAliases = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( resolveAliases ) {
|
|
|
|
var primaryNames = {};
|
|
|
|
for ( var name in this.seenParameterNames ) {
|
|
|
|
primaryNames[ this.getPrimaryParameterName( name ) ] = true;
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2021-07-02 15:15:11 +00:00
|
|
|
this.seenParameterNames = primaryNames;
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* Adds all (possibly undocumented) parameters from the linked template to the list of known
|
|
|
|
* parameters, {@see getKnownParameterNames}. This should be called every time a parameter is added
|
|
|
|
* to the template.
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2018-11-21 12:33:32 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.fillFromTemplate = function () {
|
2021-06-29 06:56:54 +00:00
|
|
|
for ( var name in this.template.getParameters() ) {
|
2021-06-24 14:24:04 +00:00
|
|
|
// Ignore placeholder parameters with no name
|
2021-06-29 06:56:54 +00:00
|
|
|
if ( name && !this.isKnownParameterOrAlias( name ) ) {
|
2021-06-24 14:24:04 +00:00
|
|
|
// There is no information other than the names of the parameters, that they exist, and
|
|
|
|
// in which order
|
2021-06-29 06:56:54 +00:00
|
|
|
this.seenParameterNames[ name ] = true;
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-08-26 13:34:39 +00:00
|
|
|
* @return {string} Normalized template name without the "Template:" namespace prefix, if possible.
|
|
|
|
* Otherwise the unnormalized template name as used in the wikitext. Might even be a string like
|
|
|
|
* `{{example}}` when a template name is dynamically generated.
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getLabel = function () {
|
2021-10-07 11:06:03 +00:00
|
|
|
var title = this.template.getTemplateDataQueryTitle();
|
2013-06-18 19:42:10 +00:00
|
|
|
if ( title ) {
|
|
|
|
try {
|
2013-06-19 00:04:16 +00:00
|
|
|
// Normalize and remove namespace prefix if in the Template: namespace
|
2021-06-21 08:10:27 +00:00
|
|
|
title = new mw.Title( title )
|
|
|
|
.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template );
|
2013-06-18 19:42:10 +00:00
|
|
|
} catch ( e ) { }
|
|
|
|
}
|
2021-08-26 13:34:39 +00:00
|
|
|
return title || this.template.getTarget().wt;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-24 15:44:07 +00:00
|
|
|
* @param {string} [languageCode]
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string|null} Template description or null if not available
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-06-24 15:44:07 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getDescription = function ( languageCode ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
return this.constructor.static.getLocalValue( this.templateData.description || null, languageCode );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2021-08-13 10:47:28 +00:00
|
|
|
/**
|
|
|
|
* True it the template does have any user-provided documentation. Note that undocumented templates
|
|
|
|
* can still have auto-detected `params` and a `paramOrder`, while documented templates might not
|
|
|
|
* have `params`. Use `{@see getDocumentedParameterOrder()}.length` to differentiate.
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isDocumented = function () {
|
|
|
|
return !this.templateData.notemplatedata;
|
|
|
|
};
|
|
|
|
|
2014-01-14 20:15:29 +00:00
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* Preferred order of parameters via TemplateData, without aliases or undocumented parameters. Empty
|
|
|
|
* if the template is not documented. Otherwise the explicit `paramOrder` if given, or the order of
|
|
|
|
* parameters as they appear in TemplateData. Returns a copy, i.e. it's safe to manipulate the
|
|
|
|
* array.
|
2014-01-14 20:15:29 +00:00
|
|
|
*
|
2021-06-28 09:14:18 +00:00
|
|
|
* @return {string[]} Preferred order of parameters via TemplateData, if given
|
2014-01-14 20:15:29 +00:00
|
|
|
*/
|
2021-06-28 09:14:18 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getDocumentedParameterOrder = function () {
|
2021-07-01 08:45:56 +00:00
|
|
|
return Array.isArray( this.templateData.paramOrder ) ?
|
|
|
|
this.templateData.paramOrder.slice() :
|
|
|
|
Object.keys( this.templateData.params );
|
2014-01-14 20:15:29 +00:00
|
|
|
};
|
|
|
|
|
2021-08-18 12:43:46 +00:00
|
|
|
/**
|
|
|
|
* @return {string[]}
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getUndocumentedParameterNames = function () {
|
|
|
|
var documentedParameters = this.templateData.params;
|
|
|
|
|
|
|
|
return this.getKnownParameterNames().filter( function ( name ) {
|
|
|
|
return !( name in documentedParameters );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-06-28 10:37:01 +00:00
|
|
|
/**
|
2021-07-07 14:28:13 +00:00
|
|
|
* Same as {@see getKnownParameterNames}, but in a canonical order that's always the same, unrelated
|
|
|
|
* to how the parameters appear in the wikitext. Primary parameter names documented via TemplateData
|
|
|
|
* are first, in their documented order. Undocumented parameters are sorted with numeric names
|
|
|
|
* first, followed by alphabetically sorted names.
|
|
|
|
*
|
|
|
|
* @return {string[]}
|
2021-06-28 10:37:01 +00:00
|
|
|
*/
|
2021-07-07 14:28:13 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getCanonicalParameterOrder = function () {
|
2021-08-18 12:43:46 +00:00
|
|
|
var undocumentedParameters = this.getUndocumentedParameterNames();
|
2021-07-07 14:28:13 +00:00
|
|
|
|
|
|
|
undocumentedParameters.sort( function ( a, b ) {
|
|
|
|
var aIsNaN = isNaN( a ),
|
|
|
|
bIsNaN = isNaN( b );
|
|
|
|
|
|
|
|
if ( aIsNaN && bIsNaN ) {
|
|
|
|
// Two strings
|
2021-10-07 09:37:10 +00:00
|
|
|
return a.localeCompare( b );
|
2021-07-07 14:28:13 +00:00
|
|
|
}
|
|
|
|
if ( aIsNaN ) {
|
|
|
|
// A is a string
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( bIsNaN ) {
|
|
|
|
// B is a string
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// Two numbers
|
|
|
|
return a - b;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return this.getDocumentedParameterOrder().concat( undocumentedParameters );
|
2021-06-28 10:37:01 +00:00
|
|
|
};
|
|
|
|
|
2013-07-10 19:04:11 +00:00
|
|
|
/**
|
2021-06-28 10:53:45 +00:00
|
|
|
* Check if a parameter name or alias was seen before. This includes parameters and aliases
|
|
|
|
* documented via TemplateData as well as undocumented parameters, e.g. from the original template
|
|
|
|
* invocation. When undocumented parameters are removed from the linked {@see ve.dm.MWTemplateModel}
|
|
|
|
* they are still known and will still be offered via {@see getKnownParameterNames} for the lifetime
|
|
|
|
* of this object.
|
|
|
|
*
|
2021-06-24 12:53:39 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
|
|
|
* @return {boolean}
|
2013-07-10 19:04:11 +00:00
|
|
|
*/
|
2021-06-24 12:53:39 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isKnownParameterOrAlias = function ( name ) {
|
2021-07-01 08:24:23 +00:00
|
|
|
return name in this.seenParameterNames || name in this.aliases;
|
2013-07-10 19:04:11 +00:00
|
|
|
};
|
|
|
|
|
2013-07-11 00:33:21 +00:00
|
|
|
/**
|
|
|
|
* Check if a parameter name is an alias.
|
|
|
|
*
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {boolean}
|
2013-07-11 00:33:21 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isParameterAlias = function ( name ) {
|
2021-06-24 14:24:04 +00:00
|
|
|
return name in this.aliases;
|
2013-07-11 00:33:21 +00:00
|
|
|
};
|
|
|
|
|
2021-07-15 12:47:21 +00:00
|
|
|
/**
|
2021-10-13 13:02:57 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-08-10 14:15:30 +00:00
|
|
|
* @return {boolean}
|
2021-07-15 12:47:21 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isParameterDocumented = function ( name ) {
|
|
|
|
return name in this.templateData.params || name in this.aliases;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:44:07 +00:00
|
|
|
* @param {string} [languageCode]
|
2021-07-02 15:52:42 +00:00
|
|
|
* @return {string} Descriptive label of the parameter, if given. Otherwise the alias or parameter
|
|
|
|
* name as is.
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-06-24 15:44:07 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterLabel = function ( name, languageCode ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:44:07 +00:00
|
|
|
return this.constructor.static.getLocalValue( param && param.label || name, languageCode );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:44:07 +00:00
|
|
|
* @param {string} [languageCode]
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {string|null}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-06-24 15:44:07 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterDescription = function ( name, languageCode ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:44:07 +00:00
|
|
|
return this.constructor.static.getLocalValue( param && param.description || null, languageCode );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 16:12:45 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {string[]}
|
2021-03-11 16:12:45 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterSuggestedValues = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return param && param.suggestedvalues || [];
|
2021-03-11 16:12:45 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* The default value will be placed in the input field when the parameter is added. The user can
|
|
|
|
* edit or even remove it.
|
|
|
|
*
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-07-02 15:52:42 +00:00
|
|
|
* @return {string} e.g. "{{PAGENAME}}"
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterDefaultValue = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 13:43:17 +00:00
|
|
|
return param && param.default || '';
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 23:31:05 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:44:07 +00:00
|
|
|
* @param {string} [languageCode]
|
2021-06-24 13:43:17 +00:00
|
|
|
* @return {string|null}
|
2015-03-04 23:31:05 +00:00
|
|
|
*/
|
2021-06-24 15:44:07 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterExampleValue = function ( name, languageCode ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:44:07 +00:00
|
|
|
return this.constructor.static.getLocalValue( param && param.example || null, languageCode );
|
2015-03-04 23:31:05 +00:00
|
|
|
};
|
|
|
|
|
2014-07-15 07:08:09 +00:00
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* The auto-value will be used by the template in case the user doesn't provide a value. In
|
|
|
|
* VisualEditor this is only for documentation and should not appear in a serialization.
|
|
|
|
*
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {string}
|
2014-07-15 07:08:09 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterAutoValue = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 13:43:17 +00:00
|
|
|
return param && param.autovalue || '';
|
2014-07-15 07:08:09 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {string} e.g. "string"
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterType = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return param && param.type || 'string';
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-07-14 07:31:42 +00:00
|
|
|
* Warning, this does not return a copy. Don't manipulate the returned array.
|
|
|
|
*
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string[]} Alternate parameter names
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterAliases = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return param && param.aliases || [];
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2013-06-28 21:38:40 +00:00
|
|
|
/**
|
2013-07-11 00:33:21 +00:00
|
|
|
* Get the parameter name, resolving an alias.
|
2013-06-28 21:38:40 +00:00
|
|
|
*
|
2013-07-11 00:33:21 +00:00
|
|
|
* If a parameter is not an alias of another, the output will be the same as the input.
|
2013-06-28 21:38:40 +00:00
|
|
|
*
|
2021-06-24 12:48:29 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
|
|
|
* @return {string}
|
2013-06-28 21:38:40 +00:00
|
|
|
*/
|
2021-06-24 12:48:29 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getPrimaryParameterName = function ( name ) {
|
2021-06-24 14:24:04 +00:00
|
|
|
return this.aliases[ name ] || name;
|
2013-06-28 21:38:40 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {boolean}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isParameterRequired = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return !!( param && param.required );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2014-04-28 19:10:31 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {boolean}
|
2014-04-28 19:10:31 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isParameterSuggested = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return !!( param && param.suggested );
|
2014-04-28 19:10:31 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2021-06-24 15:41:23 +00:00
|
|
|
* @return {boolean}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.isParameterDeprecated = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return !!( param && ( param.deprecated || typeof param.deprecated === 'string' ) );
|
2013-06-19 20:00:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-24 14:24:04 +00:00
|
|
|
* @param {string} name Parameter name or alias
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Explaining of why parameter is deprecated, empty if parameter is either not
|
2014-04-25 23:50:21 +00:00
|
|
|
* deprecated or no description has been specified
|
2013-06-19 20:00:11 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterDeprecationDescription = function ( name ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
var param = this.templateData.params[ this.getPrimaryParameterName( name ) ];
|
2021-06-24 15:38:24 +00:00
|
|
|
return param && typeof param.deprecated === 'string' ? param.deprecated : '';
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-28 10:53:45 +00:00
|
|
|
* Get all known primary parameter names, without aliases, in their original order as they became
|
|
|
|
* known (usually but not necessarily the order in which they appear in the template). This still
|
|
|
|
* includes undocumented parameters that have been part of the template at some point during the
|
|
|
|
* lifetime of this object, but have been removed from the linked {@see ve.dm.MWTemplateModel} in
|
|
|
|
* the meantime.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-07-14 07:31:42 +00:00
|
|
|
* The returned array is a copy, i.e. it's safe to manipulate.
|
|
|
|
*
|
2021-06-28 10:53:45 +00:00
|
|
|
* @return {string[]} Primary parameter names
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2021-06-28 10:53:45 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getKnownParameterNames = function () {
|
2021-07-01 08:24:23 +00:00
|
|
|
return Object.keys( this.seenParameterNames );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* See https://www.mediawiki.org/wiki/Extension:TemplateData#Set_object
|
|
|
|
*
|
|
|
|
* @return {{label:(string|Object.<string,string>),params:string[]}[]}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getParameterSets = function () {
|
2021-07-01 08:45:56 +00:00
|
|
|
return this.templateData.sets || [];
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
2014-10-21 10:45:03 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* See https://www.mediawiki.org/wiki/Extension:TemplateData#Maps_object
|
2014-10-21 10:45:03 +00:00
|
|
|
*
|
2021-07-02 15:52:42 +00:00
|
|
|
* @return {Object.<string,Object.<string,string|string[]|string[][]>>}
|
2014-10-21 10:45:03 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getMaps = function () {
|
2021-07-01 08:45:56 +00:00
|
|
|
return this.templateData.maps || {};
|
2014-10-21 10:45:03 +00:00
|
|
|
};
|