mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
0c3ca665d2
Objectives: * Trim leading or trailing whitespace that parsoid may have left on parameter names * Preserve the original name for round-tripping cleanliness * Ignore leading or trailing whitespace when entering new parameter names in the parameter search widget * Consider aliases when listing suggested parameters Changes: ve.ui.MWParameterSearchWidget.js * Use hasParameter method instead of using indexOf - uses map lookup internally, which is much faster, and also take aliases into account * Trim query input value to prevent leading or trailing whitespace from being considered when filtering known or creating unknown parameters * Take aliases into account when showing filtered results ve.dm.MWTransclusionModel.js * Use original name when round-tripping ve.dm.MWTemplateParameterModel.js * Store original name for round tripping, and trim the original name for other uses * Add getOriginalName method ve.dm.MWTemplateModel.js * Add hasParameter method, which currently just does a map lookup, but can do other processing in the future ve.dm.MWTemplateSpecModel.js * Add isParameterKnown method Bug: 50715 Bug: 50717 Change-Id: I36a5e93ca8938ac3401a6e274647597704700468
96 lines
1.9 KiB
JavaScript
96 lines
1.9 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTemplateParameterModel class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* MediaWiki template parameter.
|
|
*
|
|
* @class
|
|
*
|
|
* @constructor
|
|
* @param {ve.dm.MWTemplateModel} template Template
|
|
* @param {string} name Parameter name
|
|
* @param {string} value Parameter value
|
|
*/
|
|
ve.dm.MWTemplateParameterModel = function VeDmMWTemplateParameterModel( template, name, value ) {
|
|
// Properties
|
|
this.template = template;
|
|
this.originalName = name;
|
|
this.name = name.trim();
|
|
this.value = value || '';
|
|
this.id = this.template.getId() + '/' + name;
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get template parameter is part of.
|
|
*
|
|
* @method
|
|
* @returns {ve.dm.MWTemplateModel} Template
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.getTemplate = function () {
|
|
return this.template;
|
|
};
|
|
|
|
/**
|
|
* Get unique parameter ID within the transclusion.
|
|
*
|
|
* @returns {string} Unique ID
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.getId = function () {
|
|
return this.id;
|
|
};
|
|
|
|
/**
|
|
* Get parameter name.
|
|
*
|
|
* @method
|
|
* @returns {string} Parameter name
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.getName = function () {
|
|
return this.name;
|
|
};
|
|
|
|
/**
|
|
* Get parameter name.
|
|
*
|
|
* @method
|
|
* @returns {string} Parameter name
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.getOriginalName = function () {
|
|
return this.originalName;
|
|
};
|
|
|
|
/**
|
|
* Get parameter value.
|
|
*
|
|
* @method
|
|
* @returns {string} Parameter value
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.getValue = function () {
|
|
return this.value;
|
|
};
|
|
|
|
/**
|
|
* Set parameter value.
|
|
*
|
|
* @method
|
|
* @param {string} value Parameter value
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.setValue = function ( value ) {
|
|
this.value = value;
|
|
};
|
|
|
|
/**
|
|
* Remove parameter from template.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.dm.MWTemplateParameterModel.prototype.remove = function () {
|
|
this.template.removeParameter( this );
|
|
};
|