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 {@see 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} #

Overrides:
Source:

Returns:

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

Type
boolean

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.

Source:

Returns:

Type
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.

getId() → {string} #

Get a unique part ID within the transclusion.

Inherited from:
Source:

Returns:

Unique ID

Type
string
Get a unique part ID within the transclusion.

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

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

Source:

Returns:

Sorted list of parameter names

Type
Array.<string>
Returns the same parameters as {@see getParameters}, i.e.

getOriginalParameterName(name) → {string} #

Parameters:

Name Type Description
name string

Parameter name or alias

Source:

Returns:

Parameter name or alias as originally used in the wikitext

Type
string

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

Parameters:

Name Type Description
name string

Parameter name or alias as originally used in the wikitext

Source:

Returns:

Type
ve.dm.MWParameterModel | undefined

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 {@see serialize}. Might contain placeholders with the parameter name "".

Source:

Returns:

Parameters keyed by name or alias

Type
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.

getSpec() → {ve.dm.MWTemplateSpecModel} #

Source:

Returns:

Template specification

Type
ve.dm.MWTemplateSpecModel

getTarget() → {Object} #

Source:

Returns:

Template target

Type
Object

getTemplateDataQueryTitle() → {string|null} #

Source:

Returns:

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

Type
string | null

getTitle() → {string|null} #

Source:

Returns:

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

Type
string | null

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

Get transclusion part is in.

Inherited from:
Source:

Returns:

Transclusion

Type
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

Source:

Returns:

Parameter is in the template

Type
boolean
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
Source:

Fires:

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 {@see ve.dm.MWTransclusionModel.getPlainObject}. The corresponding deserializer is in {@see ve.dm.MWTransclusionNode.static.getWikitext}.

Overrides:
Source:

Returns:

Serialized representation, raw wikitext, or undefined if empty

Type
Object | string | undefined
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

Source:

Returns:

New template model

Type
ve.dm.MWTemplateModel
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

Source:

Returns:

New template model

Type
ve.dm.MWTemplateModel | null

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.