Extension:Gadgets

From MediaWiki.org
Jump to: navigation, search
Language: English  • Deutsch • français
MediaWiki extensions manual - list
Crystal Clear action run.png
Gadgets

Release status: stable

Screenshot-gadgets-tab.png
Implementation MyWiki, Special page, API
Description Allow users to enable JS-based, user-provided gadgets from their preferences page.
Author(s) Daniel Kinzler (DuesentriebTalk)
MediaWiki 1.11+ (current version requires 1.17, versions for older MediaWiki (1.11+) are available here or from Git
Database changes no
License GNU General Public Licence 2.0 or later
Download
README
CHANGELOG
Example Wikimedia Commons: Gadget overview, user preferences (click "Gadgets"; you need to be logged in of course)
Hooks used
ArticleSaveComplete

BeforePageDisplay
GetPreferences
ResourceLoaderRegisterModules
UnitTestsList

Check usage (experimental)


Bugs: list open list all report

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 (aka wiki admins) 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.

Contents

[edit] Downloading

Either download a snapshot or browse to the Gadgets folder in the repository or clone it from

git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Gadgets.git

[edit] Installing

Copy the Gadgets directory into the extensions folder of your MediaWiki installation. Then add the following lines to your LocalSettings.php file (near the end):

require_once( "$IP/extensions/Gadgets/Gadgets.php" );

[edit] Usage

Selection of some gadgets at the user preferences in de.wikipedia

The list of available gadgets is defined on MediaWiki:Gadgets-definition. 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.

[edit] Format

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.

Note Note: 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. Single option can either consist of single option name (in this case it is a flag option), or contain a comma-separated list of values:

option = value1, value2, value3

Examples:

 * mygadget|mygadget.js|mygadget.css

or

 * mygadget[ResourceLoader]|mygadget.js|mygadget.css

or

* mygadget[rights=foo,bar]|mygadget.js|mygadget.css

or

* mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css

[edit] Options

Name Parameters Description Since
ResourceLoader None Marks gadget's scripts as compatible with ResourceLoader.  ?
dependencies Comma-separated ResourceLoader module names See list of modules available by default. 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 Disable the gadget (and make it invisible in preferences) for users who do not have these privileges.  ?
skins Comma-separated skin names Makes the gadget visible in preferences only to users who have these skins.  ?
default None Makes the gadget enabled by default for everyone (including anons!) having the required user rights. Registered users can still disable it in their preferences. 1.18

You can specify extra dependencies for your gadgets, for example:

* mygadget[ResourceLoader|dependencies=jquery.ui, jquery.effects.clip]|mygadget.js|mygadget.css

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.

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:

* modrollback[ResourceLoader|rights=rollback]|modrollback.js
* UTCLiveClock[ResourceLoader|rights=purge]|UTCLiveClock.js
* Ajax_sysop[ResourceLoader|rights=patrol,rollback,markbotedits,delete]|Ajax_sysop.js

[edit] ResourceLoader support

All 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"> 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>.

[edit] Pages

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:

 * frobinator|commonStuff.js|frob.js|frob.css|pretty.css
 * l33t|commonStuff.js|tools.js|l33t.js

[edit] Sections

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:

 == interface-gadgets ==

This would define a new section, with the title defined on the page MediaWiki:Gadget-section-interface-gadgets.

[edit] ToDo

[edit] List of gadget scripts

This table is manually updated. Images link to scripts
Gadgets Usage
MediaWiki.org commons meta wikipedia
en
installed i i i
UTCLiveClock.js Yes check.svg Yes check.svg Yes check.svg Yes check.svg
/SearchFocus.js Yes check.svg Yes check.svg
Pages gadgets
edittop.js Yes check.svg Yes check.svg Yes check.svg
/HomeArrow.js
Category gadgets
/HotCat.js Yes check.svg Yes check.svg Yes check.svg
Tab gadgets
/addsection-plus.js Yes check.svg
Sidebar gadgets
/SubPages.js
/UserRights.js

[edit] See also


Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox
In other languages