2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTemplateSpecModel class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2024-04-29 11:52:40 +00:00
|
|
|
/**
|
|
|
|
* See https://www.mediawiki.org/wiki/Extension:TemplateData#Set_object
|
|
|
|
*
|
|
|
|
* @typedef {Object} Set
|
|
|
|
* @memberof ve.dm.MWTemplateSpecModel
|
|
|
|
* @property {string|Object.<string, string>} label A brief name for the parameter set.
|
|
|
|
* @property {string[]} params One or more names of parameters to include in the set.
|
|
|
|
*/
|
|
|
|
|
2021-06-24 07:53:46 +00:00
|
|
|
/**
|
|
|
|
* Object literal returned by the TemplataData API. Expected to be in formatversion=2,
|
|
|
|
* guaranteed via ve.init.mw.Target#getContentApi.
|
|
|
|
*
|
|
|
|
* @class ve.dm.MWTemplatePageMetadata
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @property {string|boolean} [missing] Either "1" or true
|
|
|
|
* @property {string|boolean} [notemplatedata] Either "1" or true when there is no user-provided
|
|
|
|
* documentation `params` are auto-detected in this case.
|
|
|
|
* @property {string} title Template page name including the "Template:" namespace
|
|
|
|
* @property {string|Object.<string,string>} [description] Template description
|
|
|
|
* @property {Object.<string,ve.dm.MWTemplateParamDescription>} [params] Parameters by param name
|
|
|
|
* @property {string[]} [paramOrder] Preferred parameter order as documented via TemplateData. If
|
|
|
|
* given, the TemplateData API makes sure this contains the same parameters as `params`.
|
2024-04-29 11:52:40 +00:00
|
|
|
* @property {ve.dm.MWTemplateSpecModel.Set[]} [sets] List of parameter
|
2021-06-24 07:53:46 +00:00
|
|
|
* sets, i.e. parameters that belong together (whatever that means, this feature is underspecified
|
|
|
|
* and unused)
|
|
|
|
* @property {Object.<string,Object.<string,string|string[]|string[][]>>} [maps] Source to target
|
|
|
|
* parameter mappings for consumers like Citoid or gadgets
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object literal
|
2023-01-16 15:06:40 +00:00
|
|
|
*
|
2021-06-24 07:53:46 +00:00
|
|
|
* @class ve.dm.MWTemplateParamDescription
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @property {string|Object.<string,string>} [label]
|
|
|
|
* @property {string|Object.<string,string>} [description]
|
|
|
|
* @property {string[]} [suggestedvalues]
|
|
|
|
* @property {string} [default]
|
|
|
|
* @property {string|Object.<string,string>} [example]
|
|
|
|
* @property {string} [autovalue]
|
|
|
|
* @property {string} [type]
|
|
|
|
* @property {string[]} [aliases]
|
|
|
|
* @property {boolean} [required]
|
|
|
|
* @property {boolean} [suggested]
|
|
|
|
* @property {boolean|string} [deprecated]
|
|
|
|
*/
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-03 16:25:15 +00:00
|
|
|
* Holds a mixture of:
|
2021-06-24 07:53:46 +00:00
|
|
|
*
|
2021-06-03 16:25:15 +00:00
|
|
|
* - A copy of a template's specification as it is documented via TemplateData.
|
2021-06-24 07:53:46 +00:00
|
|
|
* - Undocumented parameters that appear in a template invocation, {@link #fillFromTemplate}.
|
2021-06-25 14:46:59 +00:00
|
|
|
* - Documented aliases are also considered valid, known parameter names. Use
|
2021-06-24 07:53:46 +00:00
|
|
|
* {@link #isParameterAlias} to differentiate between the two.
|
|
|
|
*
|
2024-02-20 08:29:05 +00:00
|
|
|
* Therefore, this is not the original specification but an accessor to the documentation for an
|
|
|
|
* individual template invocation. It's possibly different for every invocation.
|
2021-06-03 16:25:15 +00:00
|
|
|
*
|
2024-02-20 08:29:05 +00:00
|
|
|
* Meant to be in a 1:1 relationship to {@link ve.dm.MWTemplateModel}.
|
2021-06-03 16:25:15 +00:00
|
|
|
*
|
2024-02-20 08:29:05 +00:00
|
|
|
* The actual, unmodified specification can be found in the {@link #templateData} property and
|
|
|
|
* the local `specCache` in {@link ve.dm.MWTransclusionModel}.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-24 07:53:46 +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
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel = function VeDmMWTemplateSpecModel( template ) {
|
|
|
|
this.template = template;
|
2021-06-24 07:53:46 +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-01 08:24:23 +00:00
|
|
|
this.seenParameterNames = {};
|
2021-06-24 07:53:46 +00:00
|
|
|
/**
|
|
|
|
* @property {Object} templateData Documentation as provided by the TemplateData API
|
|
|
|
*/
|
2021-09-01 10:47:43 +00:00
|
|
|
this.templateData = { notemplatedata: true, params: {} };
|
2021-06-24 07:53:46 +00:00
|
|
|
/**
|
|
|
|
* @property {Object.<string,string>} aliases Maps aliases to primary parameter names
|
|
|
|
*/
|
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-06-24 07:53:46 +00:00
|
|
|
* @param {ve.dm.MWTemplatePageMetadata} data
|
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-12-15 17:44:23 +00:00
|
|
|
// This is currently not optional in the TemplateData API but might be in the future
|
2021-07-01 08:45:56 +00:00
|
|
|
if ( !this.templateData.params ) {
|
|
|
|
this.templateData.params = {};
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2023-04-11 16:15:09 +00:00
|
|
|
// Incomplete server validation makes this possible, but the empty string is reserved for
|
|
|
|
// {@see ve.ui.MWAddParameterPage}.
|
|
|
|
delete this.templateData.params[ '' ];
|
2021-06-23 14:31:07 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
let resolveAliases = false;
|
2021-07-02 15:15:11 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
for ( const primaryName in this.templateData.params ) {
|
2021-07-01 08:45:56 +00:00
|
|
|
this.seenParameterNames[ primaryName ] = true;
|
2021-07-01 08:24:23 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const aliases = this.getParameterAliases( primaryName );
|
|
|
|
for ( let i = 0; i < aliases.length; i++ ) {
|
|
|
|
const alias = aliases[ i ];
|
2021-07-01 08:45:56 +00:00
|
|
|
this.aliases[ alias ] = primaryName;
|
2021-07-02 15:15:11 +00:00
|
|
|
if ( alias in this.seenParameterNames ) {
|
|
|
|
resolveAliases = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( resolveAliases ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const primaryNames = {};
|
|
|
|
for ( const name in this.seenParameterNames ) {
|
2021-07-02 15:15:11 +00:00
|
|
|
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 () {
|
2024-05-21 14:22:56 +00:00
|
|
|
for ( const 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 () {
|
2024-05-21 14:22:56 +00:00
|
|
|
let 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 ) ?
|
2024-04-30 16:44:25 +00:00
|
|
|
this.templateData.paramOrder.filter( ( name ) => name ) :
|
2021-07-01 08:45:56 +00:00
|
|
|
Object.keys( this.templateData.params );
|
2014-01-14 20:15:29 +00:00
|
|
|
};
|
|
|
|
|
2021-08-18 12:43:46 +00:00
|
|
|
/**
|
2021-12-15 17:44:23 +00:00
|
|
|
* The returned array is a copy, i.e. it's safe to manipulate.
|
|
|
|
*
|
2021-08-18 12:43:46 +00:00
|
|
|
* @return {string[]}
|
|
|
|
*/
|
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getUndocumentedParameterNames = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const documentedParameters = this.templateData.params;
|
2021-08-18 12:43:46 +00:00
|
|
|
|
2024-04-30 16:44:25 +00:00
|
|
|
return this.getKnownParameterNames().filter( ( name ) => !( name in documentedParameters ) );
|
2021-08-18 12:43:46 +00:00
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*
|
2021-12-15 17:44:23 +00:00
|
|
|
* The returned array is a copy, i.e. it's safe to manipulate.
|
|
|
|
*
|
2021-07-07 14:28:13 +00:00
|
|
|
* @return {string[]}
|
2021-06-28 10:37:01 +00:00
|
|
|
*/
|
2021-07-07 14:28:13 +00:00
|
|
|
ve.dm.MWTemplateSpecModel.prototype.getCanonicalParameterOrder = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const undocumentedParameters = this.getUndocumentedParameterNames();
|
2021-07-07 14:28:13 +00:00
|
|
|
|
2024-04-30 16:44:25 +00:00
|
|
|
undocumentedParameters.sort( ( a, b ) => {
|
2023-04-21 14:22:33 +00:00
|
|
|
if ( isNaN( a ) ) {
|
|
|
|
// If a and b are string, order alphabetically, otherwise numbers before strings
|
|
|
|
return isNaN( b ) ? a.localeCompare( b ) : 1;
|
|
|
|
} else {
|
|
|
|
// If a and b are numeric, order incrementally, otherwise numbers before strings
|
|
|
|
return !isNaN( b ) ? a - b : -1;
|
2021-07-07 14:28:13 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const 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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @return {ve.dm.MWTemplateSpecModel.Set[]}
|
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
|
|
|
*
|
2024-04-29 11:52:40 +00:00
|
|
|
* @return {Object.<string,Object>}
|
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
|
|
|
};
|