Expand all

ve.dm.MWTransclusionModel

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:
Represents a MediaWiki transclusion, i.e.

Properties

doc #

Properties:

Name Type Description
parts Array.<ve.dm.MWTransclusionPartModel>
uid number
changeQueue Array.<Object>
Source:

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
Source:
Added asynchronously, but order is preserved.

addPromptedParameters() #

Add missing required and suggested parameters to each transclusion.

Source:
Add missing required and suggested parameters to each transclusion.

cacheTemplateDataApiResponse(pages)private #

callTemplateDataApi(titles, queue) → {jQuery.Promise}private #

Parameters:

Name Type Description
titles Array.<string>
queue Array.<ve.dm.MWTransclusionPartInstruction>

Returns:

Type
jQuery.Promise
Source:

containsValuableData() → {boolean} #

Returns:

True if any transclusion part contains meaningful, non-default user input

Type
boolean
Source:

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
Source:
Get the index of a part or parameter.

getPartFromId([id]) → {ve.dm.MWTransclusionPartModel|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
Source:
Matching is performed against the first section of the id, delimited by a '/'.

getPlainObject() → {Object|null} #

Get plain object representation of template transclusion.

Returns:

Plain object representation, or null if empty

Type
Object | null
Source:
Get plain object representation of template transclusion.

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
Source:
Insert transclusion at the end of a surface fragment.

isEmpty() → {boolean} #

Returns:

True if the transclusion is literally empty or contains only placeholders

Type
boolean
Source:

isSingleTemplate() → {boolean} #

Returns:

True if this is a single template or template placeholder

Type
boolean
Source:

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
Source:
Load from transclusion data, and fetch spec from server.

nextUniquePartId() → {string} #

Returns:

Next part ID, starting from "part_0", guaranteed to be unique for this transclusion

Type
string
Source:

processChangeQueue()private #

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:

  • If part to remove is not valid

    Type
    Error
  • If part to add is not valid

    Type
    Error
Source:
Replace asynchronously.

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:

Source:
Process one or more queue items.

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

Source:
Update transclusion node in a document.