Help:Magic words

See Help:Magic words on www.mediawiki.org for more magic words in the MediaWiki software. The page here is currently kept for things not yet merged to www.mediawiki.org and for documentation specific to the Wikimedia Foundation. If something is missing from both pages, check the full version of this page and restore the lacking information.

A "magic word" is a symbol recognized by the MediaWiki software and which when seen in the non-commented text of the page, triggers the software to do something other than display that symbol, or transclude a page with that name, but instead to use the symbol directly.

A magic word can be:

a behavior switch, called using an upper case word, preceded and followed by pairs of underscores, e.g. __NOTOC__

XML-style tags, preceded by "<" (and for the end tag "/") and followed by ">", as in <nowiki>...</nowiki>

a parser function: similar to a template, a word preceded by the symbols "{{" and followed by "}}", and optionally parameter definitions between pipe characters, except that the part before the first pipe (or without pipes, the text between the braces) contains a colon (":"), e.g. {{ns:3}} and {{#ifexpr:{{{1}}}>3|large|small}}

a variable: similar to a template without parameters, a word preceded by the symbols "{{" and followed by "}}", except the word used is in all upper case, e.g. {{CURRENTDAY}}

a template modifier

an image modifier

If a page in the template namespace has the same name as a magic word, the magic word will be invoked instead. If you discover you absolutely have to define a template with the same name as a magic word, prefix the name of the template with "msg:" or the name of the template namespace ("Template:"). See below for further details if you need this feature.

A bare colon is not a template modifier, it's the prefix for the main namespace. Test e.g. article {{:UTC}} vs. template {{UTC}}.
Using this syntax you include the text of the main namespace article xyz in another article.

{{int:xyz}}

Same as {{MediaWiki:xyz}}, except standard message translation is applied depending on subpages and content/user/uselang language. Another difference is: this doesn't appear under "Templates used on this page:". Rendered as <xyz> if MediaWiki:xyz doesn't exist. See also Help:System message.

{{msg:xyz}}

Even if there is a magic word named "xyz", use template:xyz unless the template doesn't exist (equivalent to {{template:xyz}}). Normally, magic words have priority when there is a conflict.

{{msgnw:xyz}}

The unexpanded wikitext is rendered (more or less, for details see msgnw).

These are image modifiers used in [[File:title.ext|modifier|...|modifier]] links. Some are mutually exclusive, and then the last specified wins. The last unrecognized modifier is used as caption for framed images or together with thumbnails. It's also used as description alt=text.

Despite its name MAGICNUMBER is no magic word, the ISBN magic works only on the MediaWiki:Booksources page used by Special:Booksources, but talking about [[{{ns:4}}:{{int:Booksources}}|{{ns:8}}:Booksources]] in a way working on any MediaWiki installation is esoteric enough to be noted here.

{{plural: 2 | is | are }}
outputs are
{{plural: 1 | this | these }}
outputs this
{{plural: 0 | his | their }}
outputs their

count1 yields form1 (singular), plural transformations are used for languages like Russian[5] based on "count mod 10".

"Grammar" and "Plural" are language-dependent functions, defined in [6], [7], etc. (note that in PHP, the modulo operator is the percent sign).

"Grammar" can either be applied to predefined words only, or to arbitrary words, depending on whether the definition is just a 2D array, or involves string manipulations.

"Plural" is a site-language-dependent switch function, controlled by function convertPlural in Language.php (which distinguishes between 1 and "not 1"), for some languages overridden in Languagexx.php, e.g. for French (which distinguishes between <=1 and >1) and Russian, which uses a grammar case for amounts ending in 1 (1, 21, 31,...), another case for amounts ending in 2 to 4 (2, 3, 4, 22, 23, 24, ...) and still another case for the remaining quantities.

As opposed to ParserFunctions, "plural" accepts points and commas in numbers and interprets them in a site-language-specific way (depending on $separatorTransformTable in Messagesxx.php); on this site:

{{plural:1.000|a|b|c}} gives a

{{plural:1,000|a|b|c}} gives b

(on e.g. the German and the Dutch sites reversed w.r.t. the result on English sites).