Gadget kitchen/de

Willkommen in der Gadget-Küche. This is a tutorial for how you can write and use gadgets and user-scripts in JavaScript.

Was sind Benutzerskripte und Gadgets?
MediaWiki allows anyone to write public JavaScript code to immediately change the behavior of the software. This code can be shared with other users. This code is located in wiki pages.


 * A user script can be edited by the original author (if it is stored in the  namespace) and by anyone with the "edituserjs" user-right (usually just interface administrators). The code is usually hosted on a sub page of your user page. Examples include: XTools/ArticleInfo.js and m:User:Hoo man/useful links.js. User scripts are similar to the personal JavaScript pages such as Special:MyPage/common.js, but they allow single code chunks to be shared with other users.
 * Ein Gadget ist ein Benutzerskript, das von einem Schnittstellenadministrator "hochgestuft" wurde, indem es zu MediaWiki:Gadgets-definition hinzugefügt wurde Logged-in users can enable gadgets in the "Gadgets" tab of their user preferences. Gadgets are created and managed by interface administrators.
 * For completeness: There is also the siteJS located at MediaWiki:Common.js. The JavaScript in that file affects everyone and is executed automatically for both logged-out and logged-in users. Interface administrators can edit that page.

Wenn bei dir eine eigene Version von MediaWiki läuft, muss aktiviert sein, damit Benutzerskripte funktionieren. Die Extension für muss installiert sein, damit Skripte in den Rang von Gadgets befördert werden können. Um angenehmer arbeiten zu können, solltest du die extension in deinem Wiki installiert haben.

Write your first user script
In this section, you create an example user script which calculates the estimated reading time of a wiki page.
 * 1) Ensure you are logged in.
 * 2) Visit Special:MyPage/common.js. This page holds your personal JavaScript that is loaded on every page view (except for Special:Preferences).
 * 3) Either create the page or edit the page if it already exists.
 * 4) Copy the following six lines and paste these lines into the page:
 * 5) Click "Publish changes".
 * 6) Go to any page. Look at the title.
 * 1) Go to any page. Look at the title.

This example user script is taken from. There are more examples for simple user scripts on that page.

Halte dich an die JavaScript-Coding-Konventionen. So schreibst du JavaScript, das zu MediaWiki passt.

Entwickeln von Benutzerskripten und Gadgets
This section lists resources which are either needed or helpful for non-simple user scripts.

ResourceLoader
Since 2015 (MediaWiki 1.26), gadgets must use ResourceLoader (T107399). Der ist eine Kernfunktion des MediaWiki. Er spielt auf intelligente Art und Weise JavaScript- und CSS-Anwendungen aus. Da Gadgets immer in JavaScript geschrieben sind, musst du, wenn du Gadgets schreibst, immer mit dem ResourceLoader arbeiten.

Ihr Gadget sollte nützliche ResourceLoader-Module laden.


 * Modules — Eine Reihe von im ResourceLoader schon vorhandenen JavaScript-Libraries, jQuery-Plugins and MediaWiki-Utilities. Bedien dich einfach!
 * See the jQuery documentation for information about using jQuery in MediaWiki
 * Developing with ResourceLoader — A list of useful practices, like enabling the debug mode and help with debugging.
 * Also see the ResourceLoader best practices.

OOUI
OOUI is a JavaScript library with user interface elements (for example pop-up windows) specifically for use in MediaWiki. The library can be used in gadgets.

MediaWiki Action API
See Special:MyLanguage/API for more information.

VisualEditor
See VisualEditor/Gadgets for a tutorial specifically for VisualEditor gadgets.

Debugging user scripts and gadgets

 * Gadgets are usually compacted by the ResourceLoader, minimized and aggregated. Use the  URI parameter (preceded by   or , of course), to ask for the non-compacted version of the page and to load the "original source form" of your gadget. Also see Developing with ResourceLoader for more information.
 * Learn how to use the Developer Tools of your browser (for example how to disable the cache in your browser). See the corresponding documentation: Chrome/Chromium, Firefox, Internet Explorer, Opera, Safari.
 * If an existing gadget has problems, you can also use the page Special:Gadgets to find the source code location of a gadget.

Privacy and external content
Du solltest keine externen Skripte laden, die die Privatsphäre der NutzerInnen gefährden. In Wikimedia-Wikis gelten die folgenden Domänen als sicher:
 * *.wiktionary.org
 * *.wikimedia.org
 * *.wikibooks.org
 * *.wikisource.org
 * *.wikiversity.org
 * *.wikinews.org
 * *.wikiquote.org
 * *.wikidata.org
 * *.wikivoyage.org
 * www.mediawiki.org

A more complex user script example
Check out MediaWiki:Tutorial-QuickRC.js which uses mw.loader, mw.util, mw.html, mw.user from ResourceLoader, the MediaWiki Action API, a jQuery UI dialog, jQuery AJAX, and jQuery event binding.

Kopiere die Inhalte von MediaWiki:Tutorial-QuickRC.js in Deine Special:MyPage/common.js.

Das Ergebnis ist das gleiche wie vorhin. Aber jetzt kannst du das Skript verändern und ausprobieren, was passiert, wenn du andere Inhalte hineinschreibst.

Load an existing user script
In the previous section, you copied the content of a user script. In this section, you will load the existing script MediaWiki:Tutorial-QuickRC.js instead. Stell sicher, dass du eingeloggt bist
 * 1) Visit Special:MyPage/common.js. This page holds your personal JavaScript that is loaded on every page view (except for Special:Preferences).
 * 2) Either create the page or edit the page if it already exists.
 * 3) Copy the following text and paste it into the page: mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Tutorial-QuickRC.js&action=raw&ctype=text/javascript');
 * 4) Click "Publish changes". You should now have a link in the "Tools" section called "Quick changelog".
 * 5) Click "Quick changelog". You get a pop-up window. It shows you a subset of the recent changes on this website.

Use a script on another Wikimedia wiki
Wenn du dein Skript statt auf MediaWiki.org in der englischsprachigen Wikipedia laufen lassen willst, kannst du das  hier nicht verwenden. Aber du kannst deinen Code über den ResourceLoader laden. Geh einfach auf common.js in der englischsprachigen Wikipedia und füge hinzu: mw.loader.load("//www.mediawiki.org/w/index.php?title=MediaWiki:Tutorial-QuickRC.js&action=raw&ctype=text/javascript");

Natürlich kannst du auch das Benutzerskript laden, dass du gerade geschrieben hast, indem du MediaWiki:Tutorial-QuickRC.js in der URI oben in  änderst. Ta-daa! So einfach ist es, sich eine maßgeschneiderte Wikipedia zu basteln! This first requires that you do not store the code of your user script in Special:MyPage/common.js itself but instead in a separate sub page of your user page.

This also helps to keep code in one single place, so you have to update code in only one place.

Disadvantages and problems of gadgets

 * Gadgets werden von Community-Mitgliedern entwickelt. Bis heute ist für Gadgets auf Wikimedia-Websites keine formale Codeüberprüfung erforderlich (siehe T71445). Bitte befolgen Sie die auf dieser Seite aufgeführten Best Practices.
 * On Wikimedia sites, the process how to "promote" a user script to a gadget in the "Gadgets" tab of the user preferences is not always clear. You will have to find an interface administrator and might have to provide deployment instructions to them.
 * Wikimedia lacks a systematic process for re-using, modifying and contributing to existing user scripts and gadgets.

Ideen woran man arbeiten soll
If you want to write features that directly help Wikimedia community members, see:


 * Gadget Kitchen/Requests in general, however that page does not look be popular so you might waste time.
 * w:Wikipedia:User scripts/Requests for English Wikipedia

Deploying or enabling a gadget
If your user script should become a gadget (see the definitions above) on a wiki, the following steps are needed:


 * Steps for the user script author:
 * Recruit an experienced developer to review your gadget code. There is no formal process to do so.
 * Check with community members if there aren't any concerns with enabling the gadget on a wiki. For the website MediaWiki.org itself, this would be Project:Current_issues.
 * Recruit a site administrator with interface rights. See the page Special:ListUsers/interface-admin on your wiki.
 * Steps for the interface administrator:
 * Copy your JS & CSS files in the  namespace on your wiki, and make sure the page names have the prefix  . Example:
 * Define the gadget on the MediaWiki:Gadgets-definition page of your wiki. That includes the modules used, dependencies, JS, and CSS file names, etc. This will allow users to enable the gadget on the Special:Preferences page of your wiki. Example:
 * Create a page for the gadget in the  namespace with prefix  . This will generate a label for the gadget on the Special:Preferences page of your wiki. Example:

Related pages

 * Wikipedia:User scripts on the English Wikipedia and its alternatives in other languages are the primary hubs for user script and gadget development in Wikipedia.
 * The user scripts guide on the English Wikipedia has tons of useful information to get you started.
 * Wikipedia:Gadget page on English Wikipedia
 * Slides for a workshop to teach the basics of user scripts and gadgets (part of Small wiki toolkits)
 * List of gadgets by popularity across all Wikimedia projects
 * For a specific website, see Special:GadgetUsage for the number of users that each gadget has
 * Compatibility - MediaWiki's JavaScript support per browser and browser version
 * A video tutorial from the year 2012 regarding gadgets and user scripts. This is a bit outdated and the quality could be better, but shows how to use developer tools etc.
 * See Extension:EventLogging for a mechanism to gather data created from users interacting with a gadget.