Expand all

mw.guidedTour

GuidedTour public API

Set as mw.guidedTour and often aliased to gt locally

Namespaces

TransitionAction

Special actions to take when there's a transition (other than simply returning another step)

Classes

IllegalArgumentError
Error subclass for invalid arguments (that are not part of tour definition)
StepBuilder
A builder for defining a step of a guided tour
Tour
A guided tour
TourBuilder
A builder for defining a guided tour
TourDefinitionError
Error subclass for errors that occur during tour definition
TransitionEvent
WikitextDescription
Wikitext to be used as a step description
launcher
A module for launching guided tours that has no dependencies.

Methods

defineTour(tourSpec) → {mw.guidedTour.TourBuilder} #

Creates a tour based on an object specifying it, but does not show it immediately

mw.guidedTour.Tour#constructor has details on tourSpec.name, tourSpec.isSinglePage, and tourSpec.showConditionally.

Parameters:

Name Type Description
tourSpec Object

object specifying tour

Properties:
Name Type Description
steps Array

Array of steps; see mw.guidedTour.TourBuilder#step. In addition, the following option is supported only through defineTour.

Properties:
Name Type Attributes Description
shouldSkip function optional

Function returning a boolean, which specifies whether to skip the current step based on the page state

Properties:
Name Type Description
return boolean

true to skip, false otherwise

Source:

Returns:

the builder used to create the tour

Type
mw.guidedTour.TourBuilder

Throws:

On invalid input

Type
mw.guidedTour.TourDefinitionError

Creates a tour based on an object specifying it, but does not show it immediately

mw.guidedTour.Tour#constructor has details on tourSpec.name, tourSpec.isSinglePage, and tourSpec.showConditionally.

endTour([tourName]) #

Ends the tour, removing user's state

Parameters:

Name Type Attributes Description
tourName string optional

tour to end, defaulting to most recent one that showed a guider

Source:
Ends the tour, removing user's state

getPageAsDescription(guider) #

Parses a wiki page and uses the HTML as the description.

To use this, put the page name as the description, and use this as the value of onShow.

Parameters:

Name Type Description
guider Object

Guider object to set description on

Deprecated:
  • Yes
Source:
Parses a wiki page and uses the HTML as the description.

hasQuery(queryParts, [pageName]) → {boolean} #

Checks whether the query and pageName match the provided ones.

It will return true if and only if the actual query string has all of the mappings from queryParts (the actual query string may be a superset of the expected), and pageName (optional) is exactly equal to wgPageName.

If pageName is falsy, the page name will not be considered in any way.

Parameters:

Name Type Attributes Description
queryParts Object

Object mapping expected query parameter names (string) to expected values (string)

pageName string optional

Page name

Source:

Returns:

true if and only if there is a match per above

Type
boolean
Checks whether the query and pageName match the provided ones.

hideAll() #

Hides the guider(s)

isEditing() → {boolean} #

Checks if the user is editing, with either wikitext or the VisualEditor. Does not include previewing.

Source:

Returns:

true if and only if they are actively editing

Type
boolean

Checks if the user is editing, with either wikitext or the VisualEditor.

isEditingWithVisualEditor() → {boolean} #

Checks if the user is editing with VisualEditor. This is only true if the surface is actually open for edits.

Use isVisualEditorOpen instead if you want to check if there is a VisualEditor instance on the page.

Source:
See:

Returns:

true if and only if they are actively editing with VisualEditor

Type
boolean
Checks if the user is editing with VisualEditor.

isEditingWithWikitext() → {boolean} #

Checks if the user is editing with wikitext. Does not include previewing.

Source:

Returns:

true if and only if they are on the edit action

Type
boolean
Checks if the user is editing with wikitext.

isPage(pageName) → {boolean} #

Checks whether user is on a particular wiki page.

Parameters:

Name Type Description
pageName string

Expected page name

Source:

Returns:

true if the page name is a strict match, false otherwise

Type
boolean
Checks whether user is on a particular wiki page.

isPostEdit() → {boolean} #

Checks whether the user just saved an edit.

You can also handle the 'postEdit' mw.hook in a mw.guidedTour.StepBuilder#transition handler.

This method is not necessary if post-edit is the only criterion for the transition.

Source:

Returns:

true if they just saved an edit, false otherwise

Type
boolean
Checks whether the user just saved an edit.

isReviewing() → {boolean} #

Checks whether the user is previewing or reviewing changes (after clicking "Show changes")

Source:

Returns:

true if and only if they are reviewing

Type
boolean

Checks whether the user is previewing or reviewing changes (after clicking "Show changes")

isReviewingWithWikitext() → {boolean} #

Checks whether the user is previewing or reviewing wikitext changes (the latter meaning the screen after clicking "Show changes")

Source:

Returns:

true if and only if they are reviewing wikitext

Type
boolean

Checks whether the user is previewing or reviewing wikitext changes (the latter meaning the screen after clicking "Show changes")

isVisualEditorOpen() → {boolean} #

Checks whether VisualEditor is open

Source:

Returns:

true if and only if there is a VisualEditor instance on the page

Type
boolean
Checks whether VisualEditor is open

launchTourFromEnvironment() #

Attempts to automatically launch a tour based on the environment

If the query string has a tour parameter, the method attempts to use that.

Otherwise, the method tries to use the GuidedTour cookie. It checks which tours are applicable to the current page. If more than one is, this method loads the most recently started tour.

If both fail, it does nothing.

Source:

Attempts to automatically launch a tour based on the environment

If the query string has a tour parameter, the method attempts to use that.

launchTourFromQueryString() → {boolean} #

Attempts to launch a tour from the query string (tour parameter)

Source:

Returns:

Whether a tour was launched

Type
boolean
Attempts to launch a tour from the query string (tour parameter)

launchTourFromUserState() → {boolean} #

Attempts to launch a tour from combined user state (cookie + tours launched directly by server)

Source:

Returns:

Whether a tour was launched

Type
boolean

Attempts to launch a tour from combined user state (cookie + tours launched directly by server)

makeTourId(tourInfo) → {string|null} #

Serializes tour information into a string

Parameters:

Name Type Description
tourInfo Object
Properties:
Name Type Description
name string

Tour name

step number | string

Tour step, which can be a string, such as 'preview', or numeric, as either a string ('5') or a number (5).

Source:

Returns:

ID of tour, or null if invalid input

Type
string | null
Serializes tour information into a string

parseDescription(guider) #

Parses description as wikitext

Add this to onShow.

Parameters:

Name Type Description
guider Object

Guider object to set description on

Deprecated:
  • Yes
Source:

Parses description as wikitext

Add this to onShow.

parseTourId(tourId) → {Object|null|string|string} #

Parses tour ID into an object with name and step keys.

Parameters:

Name Type Description
tourId string

ID of tour/step combination

Source:

Returns:

  • Tour info object, or null if invalid input

    Type
    Object | null
  • return.name Tour name

    Type
    string
  • return.step Tour step, always a string, but either textual (e.g. 'preview') or numeric (e.g. '5')

    Type
    string
Parses tour ID into an object with name and step keys.

resumeTour(tourName, [step]) #

Resumes a loaded tour, specifying a tour and (optionally) a step.

If no step is provided, it will first try to get a step from the URL.

If that fails, it will try to resume from the cookie.

Finally, it will default to step 1.

Parameters:

Name Type Attributes Description
tourName string

Tour name

step number | string optional

Step, defaulting to the cookie or first step of tour.

Source:
Resumes a loaded tour, specifying a tour and (optionally) a step.

setTourCookie(name, [step]) #

Sets the tour cookie, given a tour name and optionally, a step.

You can use this when you want the tour to be displayed on a future page. If there is currently no cookie, it will set the start time. This will not be done if only the step is changing.

This does not take into account isSinglePage.

Parameters:

Name Type Attributes Default Description
name string

Tour name

step number | string optional
1

Tour step

Source:
Sets the tour cookie, given a tour name and optionally, a step.

transition(transitionEvent)static #

Checks for a transition after a minimal timeout

Parameters:

Name Type Description
transitionEvent mw.guidedTour.TransitionEvent

event that triggered the check

Source:
Checks for a transition after a minimal timeout