Template gadgets

(Redirected from Template gadget)

Template gadgets are gadgets that load when a certain category is present on a page, usually to implement or extend the functionality of a template. A template typically places the cagegory. Template gadgets allow features that are otherwise impossible in templates, 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).

Limitations

edit
  • Template gadgets will not be loaded in AJAX-based previews like Live preview, real-time preview, VisualEditor, mobile app previews, etc.
  • Template gadgets will not work with 3rd party clients (including the official Wikipedia Android and iOS app) that do not load wiki scripts (typically for security reasons). For this reason make sure your gadget progressively degrades to something functional or at least an error message that says "This is not supported by your client".
  • Template gadgets can be broken by vandalism (e.g. removal of categories from a page).

See also

edit
edit