Class: SourceHandler

SourceHandler(configopt)

new SourceHandler(configopt)

TemplateData Source Handler

Loads and validates the templatedata and template parameters whether in the page itself or from its parent.

Parameters:
Name Type Attributes Description
config Object <optional>
Source:

Extends

  • OO.EventEmitter

Methods

buildModel(wikitextopt) → {jQuery.Promise}

Go over the current wikitext and build a new model.

Parameters:
Name Type Attributes Description
wikitext string <optional>

Source of the template.

Source:
Returns:

Promise resolving into a new Model or is rejected if the model was impossible to create.

Type
jQuery.Promise

extractParametersFromTemplateCode(templateCode) → {Array.<string>}

Retrieve template parameters from the template code.

Adapted from https://he.wikipedia.org/wiki/MediaWiki:Gadget-TemplateParamWizard.js

Parameters:
Name Type Description
templateCode string

Source of the template.

Source:
Returns:

An array of parameters that appear in the template code

Type
Array.<string>

findModelInString(templateDataString) → {string|null}

Look for a templatedata json string and return it, if it exists.

Parameters:
Name Type Description
templateDataString string

Wikitext templatedata string

Source:
Returns:

The isolated json string. Empty if no templatedata string was found.

Type
string | null

getApi(page, getTemplateDataopt) → {jQuery.Promise}

Get information from the MediaWiki API

Parameters:
Name Type Attributes Description
page string

Page name

getTemplateData boolean <optional>

Fetch the templatedata in the page.

Source:
Returns:

API promise

Type
jQuery.Promise

getFullPageName() → {string}

Get page full name

Source:
Returns:

Page full name

Type
string

getParametersFromTemplateSource(wikitextopt) → {jQuery.Promise}

Retrieve parameters from the template code from source in this order:

  1. Check if there's a template in the given 'wikitext' parameter. If not,
  2. Check if there's a template in the current page. If not,
  3. Check if the page is a subpage and go up a level to check for template code. If none found,
  4. Repeat until we are in the root of the template
  5. Save the name of the page where the template is taken from

Cache the templateCodePromise so we don't have to do this all over again on each template code request.

Parameters:
Name Type Attributes Description
wikitext string <optional>

Optional. Source of the template.

Source:
Returns:

Promise resolving into template parameter array

Type
jQuery.Promise

getParentPage() → {string}

Get parent page

Source:
Returns:

Parent page

Type
string

getTemplateSourceCodeParams() → {Array.<string>}

Set template source code parameters

Source:
Returns:

Parameters from the template source code

Type
Array.<string>

isPageSubLevel() → {boolean}

Set the page as a sub page of the main template

Source:
Returns:

Page is sublevel

Type
boolean

setFullPageName(pageName)

Get full page name

Parameters:
Name Type Description
pageName string

Page name

Source:

setPageSubLevel(isSubLevel)

Set the page as a sub page of the main template

Parameters:
Name Type Description
isSubLevel boolean

Page is sublevel

Source:

setParentPage(parent)

Set parent page

Parameters:
Name Type Description
parent string

Parent page

Source:

setTemplateSourceCodeParams(params)

Set template source code parameters

Parameters:
Name Type Description
params Array.<string>

Parameters from the template source code

Source: