Expand all

ve.init.mw.Target

Extends

Constructor

new ve.init.mw.Target(config) #

Parameters:

Name Type Description
config Object
Properties:
Name Type Attributes Default Description
surfaceClasses Array.<string> optional
[]

Surface classes to apply

Source:
Initialization MediaWiki target.

Properties

integrationTypestatic #

Type of integration. Used for event tracking.

Properties:

Type Description
string
Source:
Type of integration.

namestatic #

Symbolic name for this target class.

Properties:

Type Description
string
Source:
Symbolic name for this target class.

platformTypestatic #

Type of platform. Used for event tracking.

Properties:

Type Description
string
Source:
Type of platform.

Methods

clearDocState() #

Clear any stored document state

Source:
Clear any stored document state

documentReady(doc) #

Handle both DOM and modules being loaded and ready.

Parameters:

Name Type Description
doc HTMLDocument | string

HTML document or source text

Source:
Handle both DOM and modules being loaded and ready.

getContentApi([doc], [options]) → {mw.Api} #

Get an API object associated with the wiki where the document content is hosted.

This would be overridden if editing content on another wiki.

Parameters:

Name Type Attributes Description
doc ve.dm.Document optional

API for a specific document, should default to document of current surface.

options Object optional

API options

Properties:
Name Type Attributes Description
parameters Object optional

Default query parameters for all API requests. Defaults include action=query, format=json, and formatversion=2 if not specified otherwise.

Returns:

Type
mw.Api
Source:

Get an API object associated with the wiki where the document content is hosted.

getHtml(newDoc, [oldDoc]) → {string} #

Parameters:

Name Type Attributes Description
newDoc HTMLDocument
oldDoc HTMLDocument optional

Returns:

Type
string
Deprecated:
  • Moved to mw.libs.ve.targetSaver.getHtml
Source:

getLocalApi([options]) → {mw.Api} #

Get an API object associated with the local wiki.

For example you would always use getLocalApi for actions associated with the current user.

Parameters:

Name Type Attributes Description
options Object optional

API options

Returns:

Type
mw.Api
Source:
Get an API object associated with the local wiki.

getPageName([doc]) → {string} #

Get the page name associated with a specific document

Parameters:

Name Type Attributes Description
doc ve.dm.Document optional

Document, defaults to current surface's

Returns:

Page name

Type
string
Source:
Get the page name associated with a specific document

getSurfaceClasses() → {Array.<string>} #

Get a list of CSS classes to be added to surfaces, and target widget surfaces

Returns:

CSS classes

Type
Array.<string>
Source:
Get a list of CSS classes to be added to surfaces, and target widget surfaces

getWikitextFragment(doc, [useRevision]) → {jQuery.Promise} #

Get a wikitext fragment from a document

Parameters:

Name Type Attributes Default Description
doc ve.dm.Document
useRevision boolean optional
true

Whether to use the revision ID + ETag

Returns:

Abortable promise which resolves with a wikitext string

Type
jQuery.Promise
Source:
Get a wikitext fragment from a document

initAutosave([config]) #

Intialise autosave, recovering changes if applicable

Parameters:

Name Type Attributes Description
config Object optional

Configuration options

Properties:
Name Type Attributes Default Description
suppressNotification boolean optional
false

Don't notify the user if changes are recovered

docId string optional

Document ID for storage grouping

storage ve.init.SafeStorage optional

Storage interface

storageExpiry number optional

Storage expiry time in seconds (optional)

Source:
Intialise autosave, recovering changes if applicable

isInterwikiUrl(url) → {jQuery.Promise.<boolean>} #

Check if a URL is an interwiki link.

Parameters:

Name Type Description
url string

URL to check

Returns:

Promise resolving to true if the URL is an interwiki link, false otherwise

Type
jQuery.Promise.<boolean>
Source:
Check if a URL is an interwiki link.

parseWikitextFragment(wikitext, pst, [doc], [ajaxOptions]) → {jQuery.Promise} #

Parse a fragment of wikitext into HTML

Parameters:

Name Type Attributes Description
wikitext string
pst boolean

Perform pre-save transform

doc ve.dm.Document optional

Parse for a specific document, defaults to current surface's

ajaxOptions Object optional

Returns:

Abortable promise

Type
jQuery.Promise
Source:
Parse a fragment of wikitext into HTML

refreshUser([doc]) → {jQuery.Promise} #

Refresh our knowledge about the logged-in user.

This should be called in response to a user assertion error, to look up the new user name, and update the current user variables in mw.config.

Parameters:

Name Type Attributes Description
doc ve.dm.Document optional

Document to associate with the API request

Returns:

Promise resolved with new username, or null if anonymous

Type
jQuery.Promise
Source:
Refresh our knowledge about the logged-in user.

setupSurface(doc) #

Switch to editing mode.

Parameters:

Name Type Description
doc HTMLDocument | string

HTML document or source text

Source:
Switch to editing mode.

storeDocState([html]) #

Store a snapshot of the current document state.

Parameters:

Name Type Attributes Description
html string optional

Document HTML, will generate from current state if not provided

Source:
Store a snapshot of the current document state.

surfaceReady() #

Once surface is ready, initialize the UI

Fires:

Source:
Once surface is ready, initialize the UI

track(name) #

Track an event

Parameters:

Name Type Description
name string

Event name

Source:
Track an event

createModelFromDom()static #

fixBase(doc)static #

Fix the base URL from Parsoid if necessary.

Absolutizes the base URL if it's relative, and sets a base URL based on wgArticlePath if there was no base URL at all.

Parameters:

Name Type Description
doc HTMLDocument

Parsoid document

Source:
Fix the base URL from Parsoid if necessary.

parseDocument(documentString, mode, [section], [onlySection]) → {HTMLDocument|string}static #

Parameters:

Name Type Attributes Default Description
documentString string
mode string
section string | null optional

Section. Use null to unwrap all sections.

onlySection boolean optional
false

Only return the requested section, otherwise returns the whole document with just the requested section still wrapped (visual mode only).

Returns:

HTML document, or document string (source mode)

Type
HTMLDocument | string
Source:

Events

teardown() #

Fired when the target has been torn down

Source:
Fired when the target has been torn down