2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
2014-02-24 21:49:48 +00:00
|
|
|
* VisualEditor DataModel MWParameterModel class.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-03 16:25:15 +00:00
|
|
|
* Represents a parameter that's part of a template invocation, centered around the parameter's
|
|
|
|
* value. Holds a reference to the specification of the template and the parameter as it is
|
|
|
|
* documented via TemplateData. Meant to be a sub-element of a {@see ve.dm.MWTemplateModel}, which
|
|
|
|
* is a sub-element of a {@see ve.dm.MWTransclusionModel}.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2024-04-29 17:51:41 +00:00
|
|
|
* @mixes OO.EventEmitter
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-06-04 11:46:16 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template Reference back to the template that contains the
|
|
|
|
* parameter, as well as to the specification
|
|
|
|
* @param {string} [name] Can be missing or empty when meant to be used as a placeholder. Parameters
|
2021-06-17 16:17:54 +00:00
|
|
|
* without a name won't be serialized to wikitext, {@see ve.dm.MWTemplateModel.serialize}.
|
2021-06-04 11:46:16 +00:00
|
|
|
* @param {string} [value='']
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel = function VeDmMWParameterModel( template, name, value ) {
|
2013-12-09 19:05:57 +00:00
|
|
|
// Mixin constructors
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Properties
|
|
|
|
this.template = template;
|
2013-07-10 19:04:11 +00:00
|
|
|
this.originalName = name;
|
2014-03-04 22:56:14 +00:00
|
|
|
this.name = typeof name === 'string' ? name.trim() : '';
|
2013-06-11 19:16:04 +00:00
|
|
|
this.value = value || '';
|
2021-06-14 16:12:05 +00:00
|
|
|
this.id = this.template.getId() + '/' + this.name;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2013-12-09 19:05:57 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
OO.mixinClass( ve.dm.MWParameterModel, OO.EventEmitter );
|
2013-12-09 19:05:57 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2021-07-15 15:07:21 +00:00
|
|
|
* Emitted when the parameter's value changed.
|
|
|
|
*
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.dm.MWParameterModel#change
|
2013-12-09 19:05:57 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-01-14 19:16:49 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {boolean}
|
2014-01-14 19:16:49 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.isRequired = function () {
|
2014-01-14 19:16:49 +00:00
|
|
|
return this.template.getSpec().isParameterRequired( this.name );
|
|
|
|
};
|
|
|
|
|
2014-04-28 19:10:31 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {boolean}
|
2014-04-28 19:10:31 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.isSuggested = function () {
|
|
|
|
return this.template.getSpec().isParameterSuggested( this.name );
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {boolean}
|
2014-04-25 23:50:21 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.isDeprecated = function () {
|
|
|
|
return this.template.getSpec().isParameterDeprecated( this.name );
|
|
|
|
};
|
|
|
|
|
2021-07-15 12:47:21 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.isDocumented = function () {
|
|
|
|
return this.template.getSpec().isParameterDocumented( this.name );
|
|
|
|
};
|
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
/**
|
|
|
|
* Get template of which this parameter is part.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @return {ve.dm.MWTemplateModel}
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getTemplate = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.template;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get unique parameter ID within the transclusion.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Unique ID
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getId = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-04 11:46:16 +00:00
|
|
|
* @return {string} Trimmed parameter name, or an empty string if no name was provided
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getName = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.name;
|
|
|
|
};
|
|
|
|
|
2013-07-10 19:04:11 +00:00
|
|
|
/**
|
2021-06-17 16:17:54 +00:00
|
|
|
* Original parameter name. Will be used in {@see ve.dm.MWTransclusionPartModel.serialize}.
|
2021-06-17 15:54:14 +00:00
|
|
|
*
|
2021-06-04 11:46:16 +00:00
|
|
|
* @return {string|undefined} Untrimmed parameter name as provided on construction time
|
2013-07-10 19:04:11 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getOriginalName = function () {
|
2013-07-10 19:04:11 +00:00
|
|
|
return this.originalName;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Parameter value, or automatic value if there is none stored.
|
2014-10-26 15:22:09 +00:00
|
|
|
* Otherwise an empty string.
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getValue = function () {
|
2014-10-26 15:22:09 +00:00
|
|
|
return this.value || this.getAutoValue() || '';
|
|
|
|
};
|
|
|
|
|
2021-03-11 16:12:45 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {string[]}
|
2021-03-11 16:12:45 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getSuggestedValues = function () {
|
|
|
|
return this.template.getSpec().getParameterSuggestedValues( this.name );
|
|
|
|
};
|
|
|
|
|
2014-10-26 15:22:09 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {string}
|
2014-10-26 15:22:09 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getDefaultValue = function () {
|
|
|
|
return this.template.getSpec().getParameterDefaultValue( this.name );
|
|
|
|
};
|
|
|
|
|
2015-03-04 23:31:05 +00:00
|
|
|
/**
|
2021-07-02 15:52:42 +00:00
|
|
|
* @return {string|null}
|
2015-03-04 23:31:05 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getExampleValue = function () {
|
|
|
|
return this.template.getSpec().getParameterExampleValue( this.name );
|
|
|
|
};
|
|
|
|
|
2014-10-26 15:22:09 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {string}
|
2014-10-26 15:22:09 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getAutoValue = function () {
|
|
|
|
return this.template.getSpec().getParameterAutoValue( this.name );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-29 21:50:14 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @return {string} Parameter type, e.g. "string"
|
2014-10-29 21:50:14 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getType = function () {
|
|
|
|
return this.template.getSpec().getParameterType( this.name );
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2021-06-04 12:00:21 +00:00
|
|
|
* @param {string} value
|
2024-04-29 18:14:26 +00:00
|
|
|
* @fires ve.dm.MWTemplateModel#change
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.setValue = function ( value ) {
|
2021-07-15 15:07:21 +00:00
|
|
|
if ( this.value !== value ) {
|
|
|
|
this.value = value;
|
|
|
|
this.emit( 'change' );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove parameter from template.
|
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.remove = function () {
|
2013-06-29 02:37:42 +00:00
|
|
|
this.template.removeParameter( this );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|