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:
|
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.
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.
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
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.
Returns:
Sorted list of parameter names
- Type
- Array.<string>
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
getParameter(name) → {ve.dm.MWParameterModel|undefined
}
#
undefined
}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias as originally used in the wikitext |
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 "".
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}
#
Returns:
Template specification
getTemplateDataQueryTitle() → {string|null
}
#
null
}
#
Returns:
Prefixed page name including the Template:
namespace, but with syntax
elements like subst:
stripped.
- Type
-
string
|
null
getTitle() → {string|null
}
#
null
}
#
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
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
remove()
#
Remove part from transclusion.
- Inherited from:
- Source:
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:
Remove a parameter from this MWTemplateModel, and emit events which result in removing the parameter from the UI.
serialize() → {Object|string|undefined
}
#
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
setOriginalData(data)private
#
Set original data, to be used as a base for serialization.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Original data Properties: |
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:
|
Returns:
New template model
newFromName(transclusion, name) → {ve.dm.MWTemplateModel|null
}static
#
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
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 |
change()
#
Emitted when anything changed, e.g. a parameter was added or removed, or a parameter's value edited.
remove(param)
#
Emitted when a parameter was removed from the template.
Parameters:
Name | Type | Description |
---|---|---|
param |
ve.dm.MWParameterModel | Removed param |