The Gadgets extension provides a way for users to pick JavaScript or CSS based "gadgets" that other wiki users provide.

Gadgets are made up of JavaScript and/or CSS snippets located on pages in the MediaWiki namespace. Each gadget is defined by a line in MediaWiki:Gadgets-definition, providing a name and description for the gadget, and a list of the JS and CSS snippets that it uses (see the Usage section below).

Since Gadgets reside in the MediaWiki namespace (the list defining the gadgets as well as the actual code snippets), only sysops (interface admins from 1.32) can edit the code. This is as it should be: only users especially trusted by the wiki community should be able to edit JavaScript code that is used by other users, since JavaScript can easily be used to hijack accounts or spy on people.

Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension(). If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension('Gadgets');, you need to use:

There are two ways to define gadgets depending on the $wgGadgetsRepoClass. If It is 'MediaWikiGadgetsDefinitionRepo'(the default value), the list of available gadgets is defined on MediaWiki:Gadgets-definition. In an alternative way, Gadget definitions defined on pages in the Gadget definition namespace when $wgGadgetsRepoClass is set to 'GadgetDefinitionNamespaceRepo'. CAUTION: Migration of the existing gadget definitions is not yet supported, So you will lose previously defined gadgets after changing this option.

Once created with at least one valid gadget, gadgets defined there show up in the "Gadgets" section of Special:Preferences, so users can pick the gadgets they would like to use. An overview of the gadgets defined by MediaWiki:Gadgets-definition is also shown on Special:Gadgets, along with links to the respective system messages, for easy editing. Statistics for non-default gadget usage can be seen at Special:GadgetUsage.

Each line in MediaWiki:Gadgets-definition that starts with one or more "*" (asterisks) characters defines a gadget; it must have the following form:

* gadget_name [options (can be omitted)] | page names

The first field ("gadget_name" in the example) is the gadget's internal name, and references a system message (MediaWiki:Gadget-gadget_name in the example) that contains a short description of the gadget, using wiki syntax.

The internal name is used as part of the name of a form field and must follow the rules defined for NAME attribute values. This means it must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Options format:

[option1 | option2 | ... optionN]

whitespace can be omitted. A single option can either consist of a single option name (in this case it is a flag option), or contain a comma-separated list of values:

You can add the following in your LocalSettings.php to provide the appropriate permissions for users who are within the interface-admin group. Editing pages in the Gadget namespace requires the gadgets-edit right and editing pages in the Gadget definition namespace requires the gadgets-definition-edit right.

See list of default modules. Note that this option has no effect if current gadget has no ResourceLoader-compatible resources (i.e. no styles and scripts not marked as compatible).

?

rights

Comma-separated privilege names

Make the gadget available (and visible in preferences) only to users who have the specified privileges.

?

hidden

None

Hide the gadget from the Preferences page. This can be used in two ways:

Enable a gadget by default without ability to disable (as modular alternative to Common.js).

Gadgets that are not meant for end-users, but rather are meant to be loaded by other gadgets. For example to allow two gadgets to re-use the same internal code, or to register the "core" part of a gadget that only loads on certain pages.

1.28

skins

Comma-separated skin names

Make the gadget available (and visible in preferences) only to users who use the specified skins. Before MediaWiki 1.32 it was taking into consideration the skin set in preferences for the user, not the current displayed one (like when adding ?useskin=monobook in the URL, task T199478)

?

default

None

Enable the gadget by default for everyone (including IPs). Registered users can still disable it in their preferences.

1.18

targets

desktop (default), mobile or desktop,mobile

Set the RL target(s) for the gadget. Targeting mobile only is broken, and causes errors on desktop because ResourceLoader complains about the module not being registered, even if not loaded. See also task T173309.

?

type

styles or general

Use styles for modules that only modify styling for elements already on the page (e.g. when customising the skin, layout, or article content). It will cause the CSS files of the module to be included from the page HTML instead of being loaded via JavaScript. For details, see ResourceLoader/Migration guide (users)#Gadget type.

Here, we ask ResourceLoader to load modules jquery.ui and jquery.effects.clip with mygadget. Note that gadgets can't depend on scripts from pages, static files or external URLs, only on modules already registered in ResourceLoader. To make a script from a page depend on another script from a page, each should be a gadget which registers itself as a module in ResourceLoader, then they can be made to have dependencies using the following syntax:

To make the gadget available only to users with appropriate permissions, set the rights option. For example,

* ImprovedDeletion [rights=delete] | ImprovedDeletion.js

makes the gadget available only to users who can actually delete pages. Note that restrictions are based on permissions, not user groups like administrators or bureaucrats. Here are some real examples:

Each gadget's CSS is always loaded via the ResourceLoader. However, older JavaScript is often incompatible with RL, so every gadget must be explicitly marked as compatible in order to have its scripts loaded by RL. Otherwise, plain old <script src="/w/index.php?title=MediaWiki:Gadget-gadget_name.js&action=raw&ctype=text/javascript"> will be used.

Every gadget that at least partially uses ResourceLoader (that is, that has styles or compatible scripts) has its own RL module. The modules are named ext.gadget.<gadget name>.

The remaining fields on the line refer to the JavaScript or CSS code that makes up the gadget, contained in system messages (MediaWiki:Gadget-mygadget.js and MediaWiki:Gadget-mygadget.css in the example); the names of those messages must end with ".js" or ".css", respectively. A gadget can use any number of code messages, specifically, common code can be put into a code message used by several gadgets, in addition to their own specific code, e.g:

Please note that if your code contains strings that could be interpreted as wiki syntax (e.g. the signature code ~~~~), you may want to enclose your code into <nowiki> and </nowiki> and put these tags in JavaScript or CSS comments so they're not interpreted when actually used. See the first and last lines of MediaWiki:Gadget-externalsearch-bar.js for an example.

The list of gadgets in MediaWiki:Gadgets-definition can be broken into sections using lines that start and end with two or more "=" (equals) characters, enclosing the name of a system message that defines the section's name - for example:

This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page.