Constructor
new ve.dm.MWTransclusionModel(doc)
#
Represents a MediaWiki transclusion, i.e. a sequence of one or more template invocations that
strictly belong to each other (e.g. because they are unbalanced), possibly mixed with raw
wikitext snippets. These individual "parts" are subclasses of ve.dm
.MWTransclusionPartModel.
Parameters:
Name | Type | Description |
---|---|---|
doc |
ve.dm.Document | Document to use associate with API requests |
- Mixes in:
- Source:
Properties
doc
#
Properties:
Name | Type | Description |
---|---|---|
parts |
Array.<ve.dm.MWTransclusionPartModel> | |
uid |
number | |
templateDataApiRequests |
Array.<jQuery.Promise> | Currently running API requests. The only reason to keep these around is to be able to abort them earlier when the template dialog closes or resets. |
changeQueue |
Array.<Object> |
Methods
addPart(part, [index]) → {jQuery.Promise}
#
Added asynchronously, but order is preserved.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
part |
ve.dm.MWTransclusionPartModel | ||
index |
number |
optional |
Specific index to add content at, defaults to the end |
Returns:
Promise, resolved when part is added
- Type
- jQuery.Promise
Throws:
-
If part is not valid
- Type
- Error
addPromptedParameters()
#
Add missing required and suggested parameters to each transclusion.
cacheTemplateDataApiResponse([data])private
#
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object |
optional |
Properties:
|
callTemplateDataApi(titles, queue) → {jQuery.Promise}private
#
Parameters:
Name | Type | Description |
---|---|---|
titles |
Array.<string> | |
queue |
Array.<ve.dm.MWTransclusionPartInstruction> |
Returns:
- Type
- jQuery.Promise
containsValuableData() → {boolean}
#
Returns:
True if any transclusion part contains meaningful, non-default user input
- Type
- boolean
getIndex(model) → {number}
#
Get the index of a part or parameter.
Indexes are linear depth-first addresses in the transclusion tree.
Parameters:
Name | Type | Description |
---|---|---|
model |
ve.dm.MWTransclusionPartModel | ve.dm.MWParameterModel | Part or parameter |
Returns:
Page index of model
- Type
- number
getPartFromId([id]) → {ve.dm.MWTransclusionPartModel|undefined
}
#
undefined
}
#
Matching is performed against the first section of the id
, delimited by a '/'.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
string |
optional |
Any id, including slash-delimited template parameter ids |
Returns:
Part with matching ID, if found
- Type
-
ve.dm.MWTransclusionPartModel
|
undefined
id
, delimited by a '/'.
getParts() → {Array.<ve.dm.MWTransclusionPartModel>}
#
Returns:
All parts in this transclusion
getPlainObject() → {Object|null
}
#
null
}
#
Get plain object representation of template transclusion.
Returns:
Plain object representation, or null if empty
- Type
-
Object
|
null
insertTransclusionNode(surfaceFragment, [forceType]) → {jQuery.Promise}
#
Insert transclusion at the end of a surface fragment.
If forceType is not specified and this is used in async mode, users of this method should ensure the surface is not accessible while the type is being evaluated.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
surfaceFragment |
ve.dm.SurfaceFragment | Surface fragment after which to insert. |
|
forceType |
string |
optional |
Force the type to 'inline' or 'block'. If not specified it will be evaluated asynchronously. |
Returns:
Promise which resolves when the node has been inserted. If forceType was specified this will be instant.
- Type
- jQuery.Promise
isEmpty() → {boolean}
#
Returns:
True if the transclusion is literally empty or contains only placeholders
- Type
- boolean
isSingleTemplate() → {boolean}
#
Returns:
True if this is a single template or template placeholder
- Type
- boolean
load(data) → {jQuery.Promise}
#
Load from transclusion data, and fetch spec from server.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Transclusion data |
Returns:
Promise, resolved when spec is loaded
- Type
- jQuery.Promise
markRequestAsDone(apiPromise)private
#
Parameters:
Name | Type | Description |
---|---|---|
apiPromise |
jQuery.Promise |
nextUniquePartId() → {string}
#
Returns:
Next part ID, starting from "part_0", guaranteed to be unique for this transclusion
- Type
- string
processChangeQueue()private
#
removePart(part)
#
replacePart(remove, add) → {jQuery.Promise}
#
Replace asynchronously.
Parameters:
Name | Type | Description |
---|---|---|
remove |
ve.dm.MWTransclusionPartModel | Part to remove |
add |
ve.dm.MWTransclusionPartModel | Part to add |
Returns:
Promise, resolved when part is added
- Type
- jQuery.Promise
Throws:
reset()
#
Resets the model's state.
resolveChangeQueue(queue)private
#
Process one or more queue items.
Parameters:
Name | Type | Description |
---|---|---|
queue |
Array.<ve.dm.MWTransclusionPartInstruction> | List of objects containing parts to add and optionally indexes to add them at, if no index is given parts will be added at the end |
Fires:
updateTransclusionNode(surfaceModel, node)
#
Update transclusion node in a document.
Parameters:
Name | Type | Description |
---|---|---|
surfaceModel |
ve.dm.Surface | Surface model of main document |
node |
ve.dm.MWTransclusionNode | Transclusion node to update |