User blog:Rappy/Magic Words 101

http://images4.wikia.nocookie.net/__cb20120125034422/kingdomhearts/images/thumb/e/e0/Sorcerer_Mickey_KH3D.png/250px-Sorcerer_Mickey_KH3D.png When you hear the phrase "magic words", your first thought may be, "Is this some kind of hocus pocus mumbo jumbo?" Well in some cases it may be, but in terms of MediaWiki, a magic word is a keyword or phrase that triggers the software to do something special on a page. Mediawiki looks for magic words when a page is loaded for viewing. If a magic word exists on the page, the software runs the function associated with that magic word. Most magic words display text on the page or have some other form of output. Allow me to pull some knowledge out of my hat to share with you.

General
In general, magic words help to accomplish tasks in the MediaWiki software that aren't possible otherwise. From text manipulation and formatting, to complex math and common programming if/then/else statements... it's all possible with built-in magic words.

There are three basic types of magic words: behavioral switches, variables, and parser functions. In addition to this, there are a few Wikia-specific magic words.

Behavioral switches
Behavioral switches are denoted by uppercase words surrounded by double underscores, e.g.  (which places the Table of Contents at the location of the magic word rather than automatically at the top of the page). Behavioral switches are typically used to hide elements of a page, such as hiding the Table of Contents, like I did on this blog (with ) or the section edit links (with  ). These magic words are unique in that they typically have no output. In fact, almost all of them remove parts of the page when viewed.


 * Full list: Behavior switches

Variables
Variables are also uppercase words, but these are surrounded by double braces, similar to templates, e.g.  (which displays the day of the week =>  ). Variables can be quite helpful as most of them are used to display information, such as the current time and date. Other variables can be used to display wiki-specific information, such as the sitename (with ) or the number of edits on a wiki (with  ). These can be used to add a dynamic element to your wiki.


 * Full list: Variables

Parser functions
Parser functions look similar to variables in that they are also surrounded by double braces, but parser functions are not typically written in full caps. Some parser functions are preceded by the # symbol, such as the  function. These are more advanced magic words as they are not simply a phrase or keyword. All parser functions require some data to work with to output the desired information. They typically gather, manipulate, or format text and data. For example,  will return format a string of digits with commas, e.g.  . Another great use of parser functions would be to easily format information or add automatic categorization based on provided data in an infobox.


 * Full list: Parser functions

Wikia-specific
There are five Wikia-specific magic words for use in MediaWiki:Wiki-navigation and two behavioral switches for the category galleries. You can see those seven examples here.

Adding magic words
That's nice and all, but how do you use them? To add a magic word, simply add the magic word to the content of the page. If the magic word has an output, place the magic word where you'd want that output to be displayed. If it doesn't, it can be placed anywhere on the page (generally at the bottom or top so it's not lost in the content). Magic words will not be replaced with the output they generate and will still exist as the magic word when editing the page.

In the visual editor, magic words are denoted by the green puzzle piece (http://images.wikia.com/rappy/images/6/68/Puzzle_piece.png). They cannot be edited in the visual editor, but they can be removed and replaced. Highlighting the puzzle piece will show you what code it represents.
 * Visual editor

Magic words can be added, edited and removed as the code itself in the source editor.
 * Source editor

Conclusion
Now that you know how to make the magic work, go spread the magic to your own wiki! Abrakadabra! Alakazam! Open Sesame! If you have a tip for using Magic words, please share them in the comments below!

Looking for further help?

 * Help:Magic words on MediaWiki.org
 * Wikia's core functions

WikiaTracker