Help:Writing a gadget

How to add utility gadgets for all users of the wiki. These gadgets will be hidden from the Preferences page. The finished gadgets can be found from the Special:Gadgets page.

1. Add the following line to MediaWiki:Gadgets-definition:
 * mygadget[ResourceLoader|hidden|default]|mygadget.js|mygadget.css

2. Enter some description in MediaWiki:Gadget-mygadget My gadget template, do not edit.

3. Add the following JavaScript code to MediaWiki:Gadget-mygadget.js: /** * mygadget Gadget JavaScript * Authors: * Description: This gadget replaces the content within elements with the class "mygadget" *             with the text "Hello, World!" and appends it below the existing content. */

$(document).ready(function {   // Find all elements with the class "mygadget" and append a line break and "Hello, World!" after the existing content.    $('.mygadget').each(function { var helloWorld = $(this).find(''); helloWorld.after(' Hello, World!'); }); });

4. Edit MediaWiki:Gadget-mygadget.css:

5. Create Template:mygadget with the following content: This is some text.

Hello, World!

6. Use the following code to insert your gadget on a page: Some content above.

Some content below.