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

Source:

Returns:

Promise, resolved when part is added

Type
jQuery.Promise

Throws:

If part is not valid

Type
Error
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([data])private #

Parameters:

Name Type Attributes Description
data Object optional
Properties:
Name Type Attributes Description
pages Object.<number, ve.dm.MWTemplatePageMetadata> optional
Source:

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

Parameters:

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

Returns:

Type
jQuery.Promise

containsValuableData() → {boolean} #

Source:

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

Source:

Returns:

Page index of model

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

Source:

Returns:

Part with matching ID, if found

Type
ve.dm.MWTransclusionPartModel | undefined
Matching is performed against the first section of the id, delimited by a '/'.

getParts() → {Array.<ve.dm.MWTransclusionPartModel>} #

Source:

Returns:

All parts in this transclusion

Type
Array.<ve.dm.MWTransclusionPartModel>

getPlainObject() → {Object|null} #

Get plain object representation of template transclusion.

Source:

Returns:

Plain object representation, or null if empty

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

Source:

Returns:

Promise which resolves when the node has been inserted. If forceType was specified this will be instant.

Type
jQuery.Promise
Insert transclusion at the end of a surface fragment.

isEmpty() → {boolean} #

Source:

Returns:

True if the transclusion is literally empty or contains only placeholders

Type
boolean

isSingleTemplate() → {boolean} #

Source:

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

Source:

Returns:

Promise, resolved when spec is loaded

Type
jQuery.Promise
Load from transclusion data, and fetch spec from server.

markRequestAsDone(apiPromise)private #

Parameters:

Name Type Description
apiPromise jQuery.Promise
Source:

nextUniquePartId() → {string} #

Source:

Returns:

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

Type
string

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

Source:

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
Replace asynchronously.

reset() #

Resets the model's state.

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

Source:

Fires:

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.