Extension:Gadgets
![]() Utgivningsstatus: stabil |
|
---|---|
![]() |
|
Genomförande | MinWiki , Speciasida , API |
Beskrivning | Allow users to enable JS-based, user-provided gadgets from their preferences page |
Författare | Daniel Kinzler (Duesentriebdiskussion) |
Kompatibilitetsregler | Snapshots releases along with MediaWiki. Master is not backward compatible. |
MediaWiki | 1.19+ |
Licenser | GNU General Public License 2.0 eller senare |
Ladda ner | README |
Exempel | Wikimedia Commons: Gadget overview, user preferences (click "Gadgets"; you need to be logged in of course) |
|
|
|
|
Översätt tillägget Gadgets om det finns tillgängligt på translatewiki.net | |
Ärenden | Öppna ärenden · Rapportera en bugg |
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.
Installation
- Ladda ner och placera filen/filerna i en katalog som heter
Gadgets
i dinextensions/
-mapp. - Lägg till följande kod längst ner i dina
LocalSettings.php
:wfLoadExtension( 'Gadgets' );
Klart – Ta dig till Special:Version på din wiki för att bekräfta att tillägget har installerats ordentligt.
För användare som kör MediaWiki 1.24 eller äldre:
Instruktionerna ovan beskriver det nya sättet att installera tillägget med wfLoadExtension()
.
Behöver du installera tillägget på en äldre version (MediaWiki 1.24 eller äldre), så behöver du, istället för wfLoadExtension( 'Gadgets' );
, använda:
require_once "$IP/extensions/Gadgets/Gadgets.php";
Användning

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 are defined on pages in the Gadget definition namespace when $wgGadgetsRepoClass
is set to 'GadgetDefinitionNamespaceRepo'
.
![]() | 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.
Format
Using MediaWiki Gadgets Definition
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.
[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:
option = value1, value2, value3
Examples:
* mygadget[ResourceLoader]|mygadget.js|mygadget.css
or
* mygadget[ResourceLoader|package]| mygadget.js | mygadget-Foo.js | mygadget-data.json | mygadget.css
or
* mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
Using Gadget Definition Namespace
Creation of the Gadget definition:mygadget page and putting in it the below JSON code have the same effect as mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
.
{
"settings": {
"rights": [ "foo", "bar" ],
"default": false,
"package": false,
"hidden": false,
"skins": [],
"actions": [],
"category": ""
},
"module": {
"scripts": [ "mygadget.js" ],
"styles": [ "mygadget.css" ],
"datas": [],
"peers": [],
"dependencies": [],
"messages": [],
"type": ""
}
}
In above example, the Gadget:Mygadget.js and the Gadget:mygadget.css are used.
Remember the ResourceLoader
option is always true in the gadget definition namespace.
User rights
gadgets-edit
and gadgets-definition-edit
, which by default aren't given to any group.
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.
$wgGroupPermissions['interface-admin']['gadgets-edit'] = true;
$wgGroupPermissions['interface-admin']['gadgets-definition-edit'] = true;
Alternativ
Name | Parameters | Description | Since |
---|---|---|---|
ResourceLoader |
None | Marks gadget's scripts as compatible with ResourceLoader . | ? |
dependencies |
Comma-separated module names | 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:
|
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, ärende T199478). |
? |
actions |
Comma-separated action names | Make the gadget available only on the specified page actions. E.g. actions = edit, history to load a gadget only while editing and on history pages. Specifying edit action will also load it on action=submit . Invalid actions effectively disable the gadget since it can't be run anywhere. |
1.38-wmf.16 |
default
|
None | Enable the gadget by default for everyone (including IPs). Registered users can still disable it in their preferences. | 1.18 |
package
|
None | Mark this gadget as packaged. In this mode, only the first JavaScript page will be executed. Other pages can be imported by using the require() function. This mode also enables use of JSON pages, which cannot be included otherwise. | 1.38-wmf.16 |
targets
|
desktop (default), mobile or desktop,mobile
|
Set the ResourceLoader target(s) for the gadget. | gerrit:60954 |
type
|
styles or general
|
Use styles for modules that only modify styling for elements already on the page (e.g. when customizing 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.
Using
styles will not load in any specified JavaScript files. For gadgets that modify styling for elements through both JavaScript and CSS, two individual gadget definitions are required. |
1.28 |
peers
|
Comma-separated module names | Require CSS-only gadgets (which usually would be hidden). These gadgets will be loaded sooner than by dependencies , and will be loaded even if JavaScript is disabled. For details, see ResourceLoader/Migration guide (users)#Gadget peers.
|
1.29.0-wmf.11 (pre-release) |
supportsUrlLoad
|
None | true | false | Make the gadget available to be loaded with the ?withgadget URL query parameter.
|
1.38 |
|
None | (borttagen i 1.29) Makes the gadget to be top-loaded. This should be used sparingly, but may be needed for some initialization stuff like registering plugins with VisualEditor. | gerrit:75506 |
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 using the following syntax:
* childgadget[ResourceLoader|dependencies=ext.gadget.parentgadget]|childgadget.js
To enable a gadget by default, use "default
":
* mygadget[ResourceLoader|default|dependencies=mediawiki.util]|mygadget.js|mygadget.css
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
Sidor
The remaining fields on the line refer to the JavaScript, CSS or JSON 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[ResourceLoader]|commonStuff.js|frob.js|frob.css|pretty.css * l33t[ResourceLoader]|commonStuff.js|tools.js|l33t.js * foobar[ResourceLoader|package]|foo.js|bar.js|foobar.json
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>...</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.
Avsnitt
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.
Popular gadgets
See meta:Gadgets for gadgets which are popular in Wikimedia communities.
Se även
![]() | Det här tillägget används på ett eller fler av Wikimedias projekt. Det betyder förmodligen att tillägget är stabilt och fungerar tillräckligt bra för att användas på högtrafikerade hemsidor. Leta efter tilläggets namn i Wikimedias CommonSettings.php och InitialiseSettings.php-konfigureringsfiler för att se var det har installerats. En fullständig lista över tillägg som installerats på en wiki finns på wikins Special:Version-sida. |
![]() | Följande paket och/eller wikihotell innehåller detta tillägg: |
- Extensions bundled with MediaWiki 1.18/sv
- Stable extensions/sv
- Personalization extensions/sv
- Special page extensions/sv
- API extensions/sv
- GPL licensed extensions/sv
- Extensions in Wikimedia version control/sv
- BeforePageDisplay extensions/sv
- CodeEditorGetPageLanguage extensions/sv
- ContentHandlerDefaultModelFor extensions/sv
- DeleteUnknownPreferences extensions/sv
- EditFilterMergedContent extensions/sv
- GetPreferences extensions/sv
- PageDeleteComplete extensions/sv
- PageSaveComplete extensions/sv
- PreferencesGetLegend extensions/sv
- ResourceLoaderRegisterModules extensions/sv
- UserGetDefaultOptions extensions/sv
- WgQueryPages extensions/sv
- All extensions/sv
- Extensions used on Wikimedia/sv
- Extensions included in BlueSpice/sv
- Extensions included in Canasta/sv
- Extensions included in Fandom/sv
- Extensions included in Miraheze/sv
- Extensions included in MyWikis/sv
- Extensions included in ProWiki/sv
- Extensions included in semantic::core/sv
- Gadgets/sv
- JavaScript/sv