Manual:Interface/JavaScript

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 the page doesn't exist: just create it with the code you need loaded. There are similar pages affecting only users of specific skins (see below).

If $wgAllowUserJs is set to true, users can customize the interface for themselves only by creating user subpages with lowercase titles (see below).

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

Global scripts

 * MediaWiki:Common.js (all skins)
 * MediaWiki:skinname.js (per skin, for example MediaWiki:Vector.js)
 * MediaWiki:Group-group.js (per user group, for example MediaWiki:Group-sysop.js)
 * Special:Gadgets

Personal scripts
They're only available if $wgAllowUserJs is set to true.


 * User:Example/common.js (all skins - introduced in MW v1.17)
 * User:Example/skinname.js (per skin, for example User:Example/vector.js)

mw.config
For the benefit of easier JavaScript programming, the MediaWiki software exposes a number of configuration values into 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  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
Some additional site-wide variables are present only depending on the wiki configuration.

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

User-specific
Related to the user currently viewing the page:

Hooks for extensions

 * ResourceLoaderGetConfigVars: Since MediaWiki 1.17 extensions can add their own site-wide variables through this hook.
 * MakeGlobalVariablesScript: Since MediaWIki 1.14 extensions can add their own variables to the OutputPage. If the variable is not dependent on the page being viewed, use the ResourceLoaderGetConfigVars hook instead.