Expand all

ve.dm.MWTemplateModel

Extends

Constructor

new ve.dm.MWTemplateModel(transclusion, target) #

Represents a template invocation that's part of a (possibly unbalanced) sequence of template invocations and raw wikitext snippets. Meant to be an item in a ve.dm.MWTransclusionModel. Holds a back-reference to its parent.

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.

Parameters:

Name Type Description
transclusion ve.dm.MWTransclusionModel
target Object

Template target

Properties:
Name Type Attributes Description
wt string

Template name as originally used in the wikitext, including optional whitespace

href string optional

Hypertext reference to target, e.g. "./Template:Example"

Source:

Represents a template invocation that's part of a (possibly unbalanced) sequence of template invocations and raw wikitext snippets.

Methods

addParameter(param) #

addPromptedParameters() #

Add all non-existing required and suggested parameters, if any.

Source:
Add all non-existing required and suggested parameters, if any.

containsValuableData() → {boolean} #

Returns:

True if there is meaningful user input that was not e.g. auto-generated

Type
boolean
Overrides:
Source:

getAllParametersOrdered() → {Array.<string>} #

Get all current and potential parameter names in a canonical order that's always the same, unrelated to how the parameters appear in the wikitext. Parameter names and aliases documented via TemplateData are first, in their documented order. Undocumented parameters are sorted with numeric names first, followed by alphabetically sorted names. The unnamed placeholder parameter is last.

Returns:

Type
Array.<string>
Source:

Get all current and potential parameter names in a canonical order that's always the same, unrelated to how the parameters appear in the wikitext.

getId() → {string} #

Get a unique part ID within the transclusion.

Returns:

Unique ID

Type
string
Inherited from:
Source:
Get a unique part ID within the transclusion.

getOrderedParameterNames() → {Array.<string>} #

Returns the same parameters as #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 #getParameters together with Object.keys() instead.

Returns:

Sorted list of parameter names

Type
Array.<string>
Source:
Returns the same parameters as #getParameters, i.e.

getOriginalParameterName(name) → {string} #

Parameters:

Name Type Description
name string

Parameter name or alias

Returns:

Parameter name or alias as originally used in the wikitext

Type
string
Source:

getParameter(name) → {ve.dm.MWParameterModel|undefined} #

Parameters:

Name Type Description
name string

Parameter name or alias as originally used in the wikitext

Returns:

Type
ve.dm.MWParameterModel | undefined
Source:

getParameters() → {Object.<string, ve.dm.MWParameterModel>} #

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 #serialize. Might contain placeholders with the parameter name "".

Returns:

Parameters keyed by name or alias

Type
Object.<string, ve.dm.MWParameterModel>
Source:

Get all parameters that are currently present in this template invocation in the order as they originally appear in the wikitext.

getTarget() → {Object} #

Returns:

Template target

Type
Object
Source:

getTemplateDataQueryTitle() → {string|null} #

Returns:

Prefixed page name including the Template: namespace, but with syntax elements like subst: stripped.

Type
string | null
Source:

getTitle() → {string|null} #

Returns:

Prefixed template title including the "Template:" namespace, if available. Use ve.dm.MWTemplateSpecModel#getLabel for a human-readable label without the namespace.

Type
string | null
Source:

getTransclusion() → {ve.dm.MWTransclusionModel} #

Get transclusion part is in.

hasParameter(name) → {boolean} #

Check if a parameter with this name or one of its aliases is currently part of this template.

Parameters:

Name Type Description
name string

Parameter name or alias

Returns:

Parameter is in the template

Type
boolean
Source:
Check if a parameter with this name or one of its aliases is currently part of this template.

remove() #

Remove part from transclusion.

removeParameter([param]) #

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.

Parameters:

Name Type Attributes Description
param ve.dm.MWParameterModel optional

Fires:

Source:

Remove a parameter from this MWTemplateModel, and emit events which result in removing the parameter from the UI.

serialize() → {Object|string|undefined} #

Create a serialized representation of this part. Contains all information needed to recreate the original wikitext, including extra whitespace. Used in ve.dm.MWTransclusionModel#getPlainObject. The corresponding deserializer is in ve.dm.MWTransclusionNode.static.getWikitext.

Returns:

Serialized representation, raw wikitext, or undefined if empty

Type
Object | string | undefined
Overrides:
Source:
Create a serialized representation of this part.

setOriginalData(data)private #

Set original data, to be used as a base for serialization.

Parameters:

Name Type Description
data Object

Original data

Properties:
Name Type Attributes Description
params Object.<string, Object> optional
Source:
Set original data, to be used as a base for serialization.

newFromData(transclusion, data) → {ve.dm.MWTemplateModel}static #

Data is in the format provided by Parsoid.

Parameters:

Name Type Description
transclusion ve.dm.MWTransclusionModel

Transclusion template is in

data Object

Template data

Properties:
Name Type Description
params Object
Properties:
Name Type Description
wt string

Wikitext

Returns:

New template model

Type
ve.dm.MWTemplateModel
Source:
Data is in the format provided by Parsoid.

newFromName(transclusion, name) → {ve.dm.MWTemplateModel|null}static #

Name is equivalent to what would be entered between double brackets, defaulting to the Template namespace, using a leading colon to access other namespaces.

Parameters:

Name Type Description
transclusion ve.dm.MWTransclusionModel

Transclusion template is in

name string | mw.Title

Template name

Returns:

New template model

Type
ve.dm.MWTemplateModel | null
Source:

Name is equivalent to what would be entered between double brackets, defaulting to the Template namespace, using a leading colon to access other namespaces.

Events

add(param) #

Emitted when a new parameter was added to the template.

Parameters:

Name Type Description
param ve.dm.MWParameterModel

Added param

Source:
Emitted when a new parameter was added to the template.

change() #

Emitted when anything changed, e.g. a parameter was added or removed, or a parameter's value edited.

Overrides:
Source:
Emitted when anything changed, e.g.

remove(param) #

Emitted when a parameter was removed from the template.

Parameters:

Name Type Description
param ve.dm.MWParameterModel

Removed param

Source:
Emitted when a parameter was removed from the template.