Template gadgets

From mediawiki.org

Template gadgets are gadgets that load when a certain template is present in a page, usually to implement or extend the functionality of the template. Template gadgets allow features that are otherwise impossible in wiki pages, such as API calls, restricted HTML elements, Codex interfaces, and much more.

Existing template gadgets[edit]

Global[edit]

Template gadgets in this list are also global gadgets, designed and ready to be used in any wiki (Wikimedia or not) and in any language.

Local[edit]

Template gadgets in this list are not fully globalized yet.

Create a new template gadget[edit]

If you create a new template gadget, please add it to the appropriate list above so that others may find it, use it and improve it!

General method[edit]

To create a template gadget:

  1. Create a template or Lua module that inserts the basic HTML markup you will need, and categorizes pages in a category created just for this purpose
  2. Develop the necessary JavaScript in your common.js
  3. When ready, ask your community to review and promote your JavaScript to the MediaWiki namespace, and define a gadget that loads said JavaScript for pages in your special category

Best practices[edit]

  • Design your template gadget so that it's usable by other wikis (example). Host it at MediaWiki.org (example) and have other wikis load it from there (example).
  • Separation of concerns can be achieved by moving HTML to the template (example) and CSS to a separate stylesheet (example) that can then be loaded from the template script itself (example).
  • Encapsulate your code within a class to keep it tidy and avoid unnecessary naming conflicts (example).

See also[edit]

External links[edit]