Common.js

From Jurassic Outpost Encyclopedia
Revision as of 23:47, 30 April 2016 by Part Time Hero (talk | contribs) (Created page with "'''MediaWiki:Common.js''' contains JavaScript that will be loaded for all users. Enter "MediaWiki:Common.js" into the search box of your wiki. It will tel...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

MediaWiki:Common.js contains JavaScript that will be loaded for all users. Enter "MediaWiki:Common.js" into the search box of your wiki. It will tell you if the page doesn't exist; if so, and you have the necessary user rights, just create it with the code you need to execute. There are similar pages affecting only users of specific skins (see below).

If Template:Wg is set to true, users can customize the interface for themselves only by creating and importing personal scripts in user subpages with lowercase titles (see below). Extension:Gadgets makes it easier for site admins and users to share JavaScript, see Gadget kitchen.

This page covers the state and configuration variables available. For the general JavaScript API, see the JSDuck documentation.

List of JavaScript pages

Global scripts

Personal scripts

They're only available if Template:Wg is set to true.

mw.config

To ease JavaScript programming, the MediaWiki software exposes a number of configuration values in an object called mw.config.

Note Most of these variables have a wg prefix.

  • For legacy reasons these names are exposed as global JavaScript variables if Template:Wg is true, so they use a prefix to avoid collisions.
  • A subset of these names correspond to $wg variables in PHP, but others are unrelated.
  • If your own JavaScript code references a config variable, make sure you express a module dependency on the module that supplies it.
  • Besides the names in this list, many extensions also set JavaScript config variables prefixed with 'wg'. To use those you need to express a module dependency and document that your code depends on the extension.

Site-wide

Name Type Description Availability
debug Boolean Template:HiddensortMW 1.17+
skin String The internal name of the currently used skin. The "Classic" skin is called "standard". Template:HiddensortMW <1.7 (monobook skin)
MW 1.8+: all skins and pages
stylepath String Full URL to the root directory for skins, containing stylesheets and skin-specific scripts. The path does not contain the skin subdirectory, and is not terminated by a "/". Template:HiddensortMW <1.7 (monobook skin)
MW 1.8+: all skins and pages
wgActionPaths Object See $wgActionPaths. The value is either an empty object, or otherwise has entries for each defined actionpath of the form 'action' : 'path'. So wgActionPaths['edit'] will return the "pretty path" for the edit action, if any is defined. Template:HiddensortMW 1.13+
wgArticlePath String Local path, starting at the root, to reference articles, containing a "$1" placeholder that may be replaced by a page title to get a valid URL to that page. Given a valid page title title, a valid URL may be constructed using wgArticlePath.replace('$1', title). See also $wgArticlePath. Template:HiddensortMW 1.8+
wgAvailableSkins Object Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgCaseSensitiveNamespaces Array Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgContentLanguage String The language code for the default content language of the wiki. Template:HiddensortMW 1.8+
wgContentNamespaces Array of integers The IDs of the namespaces considered "content namespaces" by MediaWiki. Equivalent to the value of the $wgContentNamespaces configuration variable, with 0 included if it is not already. Template:HiddensortMW 1.23+ (Template:Git)
wgCookiePrefix String Prefix added to cookie names by default; used automatically by mw.cookie. Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgCookieDomain String Default domain for cookies; used automatically by mw.cookie. Template:HiddensortMW 1.24+ (gerrit:120806)
wgCookieExpiration Number Default lifetime of cookies, in seconds (or 0 for session cookies); used automatically by mw.cookie. Template:HiddensortMW 1.24+ (gerrit:120806)
wgCookiePath String Default path for cookies; used automatically by mw.cookie. Template:HiddensortMW 1.24+ (gerrit:120806)
wgDBname String The name of the wiki's database. Template:HiddensortMW 1.13+
wgEnableAPI Boolean true if the Mediawiki API is enabled at all; false otherwise. Template:HiddensortMW 1.12+
wgEnableWriteAPI Boolean true if the Mediawiki write API is enabled at all; false otherwise. If wgEnableAPI && !wgEnableWriteAPI, only the read operations of the API are enabled. Template:HiddensortMW 1.12+
wgExtensionAssetsPath String Root path used for extension static assets (e.g. images). Append '/' then the name of the extension to get the root path for a given extension. Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgFileExtensions Array of strings The list of all allowed file extensions (without period). Template:HiddensortMW 1.16+
wgFormattedNamespaces Object Gives a mapping from namespace IDs to localized namespace names. For each namespace, the object has one entry that has the stringified namespace number as the key and the namespace name as its value. Aliases or canonical names are not included. Template:HiddensortMW 1.16+
wgLegacyJavaScriptGlobals Boolean Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgLoadScript String Template:HiddensortMW 1.17+
wgMainPageTitle String The page name of the wiki's main page, including the namespace name, if any. May contain blanks. Template:HiddensortMW 1.16+
wgNamespaceIds Object Gives a mapping from namespace names to namespace IDs. For each namespace name, including aliases, the object has one entry that has namespace name as the key and the namespace ID as its integer value. Canonical names are not included. The keys are all lowercase, with blanks replaced by underscores. Template:HiddensortMW 1.16+
wgResourceLoaderMaxQueryLength Number Template:HiddensortMW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgScript String Full path to the main access point script, starting at the root, including the full script name with extension. On WMF wikis, normally "/w/index.php". See also $wgScript. Template:HiddensortMW 1.11+
wgScriptExtension String The file extension to use for all calls to script access points. Normally ".php". See also $wgScriptExtension. Template:HiddensortMW 1.16+
wgScriptPath String The path part of wgScript, without trailing "/". This is the path to use for direct calls to the php access points such as index.php or api.php. See also $wgScriptPath. Template:HiddensortMW 1.8+
wgServer String The server URL, not terminated by "/". The combination wgServer + wgScriptPath + "/api.php", for instance, results in a valid URL to the API access point script. Template:HiddensortMW 1.8+
wgSiteName String The name of the site, as defined by $wgSitename. Template:HiddensortMW 1.16+
wgUrlProtocols String Stringified regular expression matching all protocols recognized in links, i.e. "http\\:\\/\\/|https\\:\\/\\/|..." Template:HiddensortMW 1.16+
wgVariantArticlePath String or false If a wiki has language variants (such as the Chinese and the Serbian Wikipedias), set to a path beginning at the root for language variants other than wgContentLanguage. The path contains two placeholders: "$1" is to be replaced by the page title, and "$2" is to be replaced by the language code of the language variant (e.g. "zh-tw"). If the wiki does not have language variants, set to false. See also $wgVariantArticlePath. Template:HiddensortMW 1.13+
wgVersion String Identifies the version of MediaWiki that served the page. Template:HiddensortMW 1.12+

Some additional site-wide variables are present only depending on the wiki configuration.

Name Type Description Availability
If Template:Wg and Template:Wg are true:
wgMWSuggestTemplate Template:Deprecated-inline String A URL that can be used to obtain search suggestions. The string contains two placeholders that should be replaced: {searchTerms} is to be replaced by the (urlencoded) search terms, and {namespaces} should be replaced by the namespace numbers of the namespaces to search, separated by a vertical bar ("|"). MW 1.13 - MW 1.19 (Template:Git)
If the Ajax watch feature is enabled, the following variable is available:
wgAjaxWatch Template:Deprecated-inline Object An object containing various user interface messages, localized to wgUserLanguage. MW 1.11 - MW 1.17 (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)

Page-specific

Name Type Description Availability
wgAction String The action performed, e.g. "edit" for edit pages, or "view" for page views. See Manual:Parameters to index.php#Actions. MW 1.10+
wgArticleId Integer The internal ID of the page. For non-existent pages and special pages, it is zero. MW 1.8+
wgBreakFrames Boolean See $wgBreakFrames. MW 1.9+
wgCanonicalNamespace String The canonical (i.e., not localized or aliased) namespace name of the page. MW 1.8+
wgCanonicalSpecialPageName String or false or not defined On special pages, the canonical (i.e., not localized or aliased) name of the special page; otherwise it is not defined at all (up to and including MW 1.15) or is set to false (since MW 1.16). MW 1.9+
wgCategories Array of strings The list of all the categories a page belongs to. This is essentially a JavaScript version of the category box shown on the page (grey box at bottom of page, in Monobook/Vector). If the category box is not shown on the current page (as is the case when editing/viewing history), wgCategories will be an empty array. MW 1.16+
wgCurRevisionId Integer The top revision ID of the currently viewed page at the time the page was served. Also set on diff and history pages; zero for special pages. MW 1.9+
wgDefaultDateFormat String E.g. "dmy". Depends on the page content language since 1.20 (gerrit:14271). MW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgDigitTransformTable Array of two strings Describes digit transformations. If transformations are specified, the first entry contains a string of all Arabic digits ("0123456789"), the second array element gives in the corresponding string positions the replacement according to wgPageContentLanguage. The individual characters in each string are tab-separated. If no transformation is specified for the language, the value of wgDigitTransformTable is ["", ""] (i.e., an array of two empty strings). MW 1.12+
wgIsArticle Boolean true if the content displayed on the page is related to the source of the corresponding article on the wiki. So it is true when viewing a page (regardless of namespace), and also true when viewing a diff that has a rendered revision appended to the bottom of it. It is false for anything else (edit, history, special pages, most generated pages, etc).

Note: This variable is badly named – it has nothing really to do with a page being an "article" or not.

MW 1.8+
wgIsProbablyEditable boolean True if the page is probably editable (based on quickUserCan) by the current user. The 'probably' is necessary for performance reasons. An exact editability check is too costly here, due to cascading protection and hook-based extensions like TitleBlacklist that may be enabled. If this is true, it is likely to be editable. If it is false, it is definitely not editable. (Template:Git)
wgMonthNames Array Like January, February, ... Depends on the page content language since 1.20 (gerrit:14271). MW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgMonthNamesShort Array Like Jan, Feb, ... Depends on the page content language since 1.20 (gerrit:14271). MW 1.18+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgNamespaceNumber Integer The number of the namespace the page is in. MW 1.8+
wgPageContentLanguage String Language code of the page content language (according to $context->getTitle()->getPageLanguage()) MW 1.19+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgPageContentModel String 'wikitext' on typical wiki pages, 'javascript' on pages interpreted as JavaScript, 'css' on pages interpreted as CSS. Template:HiddensortMW 1.22+ (gerrit:62178)
wgPageName String The full name of the page, including the localized namespace name, if the namespace has a name (the main namespace (number 0) doesn't), and with blanks replaced by underscores. MW 1.8+
wgPostEdit Boolean True if the user just saved this page. Add a dependency on the mediawiki.action.view.postEdit module as the variable is set dynamically from JavaScript. If the user did not just save a page the value is omitted entirely (e.g. not set to false but absent in in mw.config). MW 1.21+ (gerrit:50480)
wgRedirectedFrom String When redirected contains the title of the page we were redirected from. If the page was not redirected, the value is omitted entirely (absent in mw.config). Uses the same format as wgPageName MW 1.19+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgRelevantPageName String The full name of the page to which content actions and navigation links (e.g. a skin's tabs) apply. The AJAX watch function uses this to work correctly on special pages such as Special:MovePage and Special:WhatLinksHere. MW 1.19+ (Cite error: Invalid <ref> tag; name cannot be a simple integer. Use a descriptive title)
wgRelevantUserName String or unset The relevant name of the user to which content actions and some extra navigation links (e.g. link to user rights or user contributions) apply. MW 1.23+ (Template:Git)
wgRestrictionEdit Array of strings If the page is editable at all (and is not a special page) and editing of the page is restricted to some user groups, the array contains the minimum user group a user must be in in order to edit the page. For semi-protected pages, it'd contain ["autoconfirmed"]; for fully protected pages ["sysop"]. If there are no explicit restrictions, the value is [] (an array with no elements).

This array contains only explicit protections. Namespace-wide protections (e.g. MediaWiki namespace, $wgNamespaceProtection), cascading protections, or "protections" brought about by the TitleBlacklist extension's "noedit" attribute, are ignored by this array. On such pages, the value is normally [], unless additional protections have been applied specifically to that page.

MW 1.14+
wgRestrictionMove Array of strings If the page is movable at all (and is not a special page) and moving of the page is restricted to some user groups, the array contains the minimum user group a user must be in in order to move the page. For semi-moveprotected pages, it'd contain ["autoconfirmed"]; for fully moveprotected pages ["sysop"]. If there are no explicit restrictions, the value is [] (an array with no elements).

This array contains only explicit protections. Namespace-wide protections (e.g. MediaWiki namespace, $wgNamespaceProtection), cascading protections, or "protections" brought about by the TitleBlacklist extension's "moveonly" attribute, are ignored by this array. On such pages, the value is normally [], unless additional protections have been applied specifically to that page.

MW 1.14+
wgRevisionId Integer The revision ID of the currently viewed revision, or the right revision for diff views. Also set on diff pages; zero for special pages, history pages, or anywhere else inapplicable. MW 1.22+ Template:Git
wgSeparatorTransformTable Array of two strings Describes number separator transformations. The first entry contains a string of all canonical separators (single characters), the second array element gives in the corresponding string positions the replacement according to wgPageContentLanguage. The individual characters in each string are tab-separated. If no transformations are specified, the value of wgSeparatorTransformTable is ["", ""] (i.e., an array of two empty strings). MW 1.12+
wgSearchType String or unset The name of the search backend used to execute search requests. MW 1.23+ (Template:Git)
wgTitle String The page title, without the namespace. May contain spaces – does not contain underscores. MW 1.8+
wgEditMessage String The name of the message used to for the title of EditPage. Used by Live preview to update document.title and #firstHeading with a new displaytitle. MW 1.25+ (Template:Git)

Some additional variables are present only depending on the page namespace, wiki configuration and/or user preferences.

Name Type Description Availability
Main Page
wgIsMainPage Boolean true if the current page is the main page of the wiki. Omitted entirely otherwise (defaulting to null in mw.config). MW 1.18+
If the content language has variants:
wgUserVariant String If the wiki has language variants, the language code of the user's preferred variant. If the wiki does not have variants, the variable is not configured (does not exist), i.e.:
Template:Inline-code
Template:Inline-code.
MW 1.16+
If the Ajax search suggestions are enabled (both globally and in the user's preferences), the following variables are available:
wgMWSuggestMessages Template:Deprecated-inline Array of strings Some localized user interface texts that may be used by the search suggestion engine. MW 1.13 - MW 1.16
wgSearchNamespaces Template:Deprecated-inline Array of integers An array of the namespace numbers of all namespaces to search by default, according to the user's preferences. MW 1.13 - MW 1.19 (Template:Git)
If the live preview is enabled, some MediaWiki versions may provide the following variables. (Note: it appears that these variables have been pulled in MW 1.16).
wgLivepreviewMessageError Template:Deprecated-inline String The contents of MediaWiki:Livepreview-error for wgUserLanguage. MW 1.10-1.15
wgLivepreviewMessageFailed Template:Deprecated-inline String The contents of MediaWiki:Livepreview-failed for wgUserLanguage. MW 1.10-1.15
wgLivepreviewMessageLoading Template:Deprecated-inline String The contents of MediaWiki:Livepreview-loading for wgUserLanguage. MW 1.10-1.15
wgLivepreviewMessageReady Template:Deprecated-inline String The contents of MediaWiki:Livepreview-ready for wgUserLanguage. MW 1.10-1.15

User-specific

Related to the user currently viewing the page:

Name Type Description Availability
wgUserEditCount Number The number of edits the current user made (null if not logged in). Template:HiddensortMW 1.21+
wgUserGroups Array of strings An array containing all the (local) user groups the current user is a member of, or null for non-logged-in users. User groups are identified by the internal user group names, e.g. "sysop", "autoconfirmed", "bureaucrat", and so on. The default user group is named "*". MW 1.10+
wgUserId Number The numeric ID of the current user (null if not logged in). Template:HiddensortMW 1.21+
wgUserLanguage String The language code for the user's interface language, as set in Special→Preferences (which may be overridden by a uselang= parameter in the URL). Template:HiddensortMW 1.8+
wgUserName String The user name of the user currently viewing the page, if it's a logged-in user. For non-logged-in users, it is null (not the user's IP address, unlike PHP $wgUser->getName() on the server). MW 1.8+
wgUserRegistration Number The time and date on which the current user registered, represented as milliseconds since epoch. Null if not logged in. Template:HiddensortMW 1.21+

Hooks for extensions