Constructor
new ve.dm.MWTemplateSpecModel(template)
#
Holds a mixture of:
- A copy of a template's specification as it is documented via TemplateData.
- Undocumented parameters that appear in a template invocation,
#fillFromTemplate
. - Documented aliases are also considered valid, known parameter names. Use
#isParameterAlias
to differentiate between the two.
Therefore, this is not the original specification but an accessor to the documentation for an individual template invocation. It's possibly different for every invocation.
Meant to be in a 1:1 relationship to ve.dm.MWTemplateModel
.
The actual, unmodified specification can be found in the #templateData
property and
the local specCache
in ve.dm.MWTransclusionModel
.
See https://github.com/wikimedia/mediawiki-extensions-TemplateData/blob/master/Specification.md for the latest version of the TemplateData specification.
Parameters:
Name | Type | Description |
---|---|---|
template |
ve.dm.MWTemplateModel |
Holds a mixture of:
- A copy of a template's specification as it is documented via TemplateData.
Properties
aliases
#
Properties:
Name | Type | Description |
---|---|---|
aliases |
Object.<string, string> | Maps aliases to primary parameter names |
seenParameterNames
#
Properties:
Name | Type | Description |
---|---|---|
seenParameterNames |
Object.<string, boolean> | Keeps track of any parameter from any source and in which order they have been seen first. Includes parameters that have been removed during the lifetime of this object, i.e. {@see fillFromTemplate} doesn't remove parameters that have been seen before. The order is typically but not necessarily the original order in which the parameters appear in the template. Aliases are resolved and don't appear on their original position any more. |
templateData
#
Properties:
Name | Type | Description |
---|---|---|
templateData |
Object | Documentation as provided by the TemplateData API |
Methods
fillFromTemplate()
#
Adds all (possibly undocumented) parameters from the linked template to the list of known parameters, {@see getKnownParameterNames}. This should be called every time a parameter is added to the template.
Adds all (possibly undocumented) parameters from the linked template to the list of known parameters, {@see getKnownParameterNames}.
getCanonicalParameterOrder() → {Array.<string>}
#
Same as {@see getKnownParameterNames}, but in a canonical order that's always the same, unrelated to how the parameters appear in the wikitext. Primary parameter names documented via TemplateData are first, in their documented order. Undocumented parameters are sorted with numeric names first, followed by alphabetically sorted names.
The returned array is a copy, i.e. it's safe to manipulate.
Returns:
- Type
- Array.<string>
Same as {@see getKnownParameterNames}, but in a canonical order that's always the same, unrelated to how the parameters appear in the wikitext.
getDescription([languageCode]) → {string|null
}
#
null
}
#
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
languageCode |
string |
optional |
Returns:
Template description or null if not available
- Type
-
string
|
null
getDocumentedParameterOrder() → {Array.<string>}
#
Preferred order of parameters via TemplateData, without aliases or undocumented parameters. Empty
if the template is not documented. Otherwise the explicit paramOrder
if given, or the order of
parameters as they appear in TemplateData. Returns a copy, i.e. it's safe to manipulate the
array.
Returns:
Preferred order of parameters via TemplateData, if given
- Type
- Array.<string>
getKnownParameterNames() → {Array.<string>}
#
Get all known primary parameter names, without aliases, in their original order as they became
known (usually but not necessarily the order in which they appear in the template). This still
includes undocumented parameters that have been part of the template at some point during the
lifetime of this object, but have been removed from the linked {@see ve.dm
.MWTemplateModel} in
the meantime.
The returned array is a copy, i.e. it's safe to manipulate.
Returns:
Primary parameter names
- Type
- Array.<string>
Get all known primary parameter names, without aliases, in their original order as they became known (usually but not necessarily the order in which they appear in the template).
getLabel() → {string}
#
Returns:
Normalized template name without the "Template:" namespace prefix, if possible.
Otherwise the unnormalized template name as used in the wikitext. Might even be a string like
{{example}}
when a template name is dynamically generated.
- Type
- string
getParameterAliases(name) → {Array.<string>}
#
Warning, this does not return a copy. Don't manipulate the returned array.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
Alternate parameter names
- Type
- Array.<string>
getParameterAutoValue(name) → {string}
#
The auto-value will be used by the template in case the user doesn't provide a value. In VisualEditor this is only for documentation and should not appear in a serialization.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- string
getParameterDefaultValue(name) → {string}
#
The default value will be placed in the input field when the parameter is added. The user can edit or even remove it.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
e.g. "{{PAGENAME}}"
- Type
- string
getParameterDeprecationDescription(name) → {string}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
Explaining of why parameter is deprecated, empty if parameter is either not deprecated or no description has been specified
- Type
- string
getParameterDescription(name, [languageCode]) → {string|null
}
#
null
}
#
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Parameter name or alias |
|
languageCode |
string |
optional |
Returns:
- Type
-
string
|
null
getParameterExampleValue(name, [languageCode]) → {string|null
}
#
null
}
#
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Parameter name or alias |
|
languageCode |
string |
optional |
Returns:
- Type
-
string
|
null
getParameterLabel(name, [languageCode]) → {string}
#
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Parameter name or alias |
|
languageCode |
string |
optional |
Returns:
Descriptive label of the parameter, if given. Otherwise the alias or parameter name as is.
- Type
- string
getParameterSets() → {Array.<ve.dm.MWTemplateSpecModel.Set>}
#
Returns:
getParameterSuggestedValues(name) → {Array.<string>}
#
getParameterType(name) → {string}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
e.g. "string"
- Type
- string
getPrimaryParameterName(name) → {string}
#
Get the parameter name, resolving an alias.
If a parameter is not an alias of another, the output will be the same as the input.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- string
getUndocumentedParameterNames() → {Array.<string>}
#
isDocumented() → {boolean}
#
True it the template does have any user-provided documentation. Note that undocumented templates
can still have auto-detected params
and a paramOrder
, while documented templates might not
have params
. Use {@see getDocumentedParameterOrder()}.length
to differentiate.
Returns:
- Type
- boolean
isKnownParameterOrAlias(name) → {boolean}
#
Check if a parameter name or alias was seen before. This includes parameters and aliases
documented via TemplateData as well as undocumented parameters, e.g. from the original template
invocation. When undocumented parameters are removed from the linked {@see ve.dm
.MWTemplateModel}
they are still known and will still be offered via {@see getKnownParameterNames} for the lifetime
of this object.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
isParameterAlias(name) → {boolean}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
isParameterDeprecated(name) → {boolean}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
isParameterDocumented(name) → {boolean}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
isParameterRequired(name) → {boolean}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
isParameterSuggested(name) → {boolean}
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Parameter name or alias |
Returns:
- Type
- boolean
setTemplateData(data)
#
Template spec data is available from the TemplateData extension's API.
Parameters:
Name | Type | Description |
---|---|---|
data |
ve.dm.MWTemplatePageMetadata |
getLocalValue(stringOrObject, [languageCode]) → {string|null
|undefined
}privatestatic
#
null
|undefined
}privatestatic
#
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
stringOrObject |
string
|
Object.<string, string>
|
null
|
||
languageCode |
string |
optional |
Returns:
- Type
-
string
|
null
|undefined