Help:Magic words

Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names. This page is about usage of standard magic words; for a technical reference, see.

There are three general types of magic words:
 * Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__
 * Variables: these are uppercase words surrounded by double braces, e.g.  . As such, they look a lot like templates.
 * Parser functions: these take parameters and are either of the form   or  . See also.

Page-dependent magic words will affect or return data about the current page (by default), even if the word is added through a transcluded template or included system message.

Behavior switches
A behavior switch controls the layout or behaviour of the page and can often be used to specify desired omissions and inclusions in the content.

Variables
Variables return information about the current page, wiki, or date. Their syntax is similar to templates. Variables marked as " [expensive] " are tracked by the software, and the number that can be included on a page is limited.

If a template name conflicts with a variable, the variable will be used (so to transclude the template    :PAGENAME you would need to write  ). In some cases, adding parameters will force the parser to invoke a template; for example,  transcludes     :CURRENTDAYNAME not the variable.

Date and time
The following variables return the current date and time in UTC.

Due to MediaWiki and browser caching, these variables frequently show when the page was cached rather than the current time.

The following variables do the same as the above, but using the site's server config or $wgLocaltimezone.


 * For more thorough time formatting, you may want to install Extension:ParserFunctions to use the #time parser function

Technical metadata
Revision variables return data about the latest edit to the current page, even if viewing an older version of the page.

Statistics
Numbers returned by these variables normally contain separators (commas or spaces, depending on the local language), but can return raw numbers with the ":R" flag (for example,  &rarr;  and   &rarr; ). Use "|R" for magic words that require a parameter like PAGESINCATEGORY (for example  and  ). Also applicable to  above.

Page names
The  and   magic words only work in namespaces that have subpages enabled. See for information on enabling subpages.

The following are equivalents encoded for use in MediaWiki URLs (i.e. spaces replaced with underscores and some characters percent-encoded):

As of, these can all take a parameter, allowing specification of the page to be operated on, instead of just the current page:
 * &rarr; 

PAGENAME encoding
PAGENAME encoding has a few special considerations. A page can have a leading space but not a trailing space. The characters that are not allowed in pagenames are the three types of brackets, pound sign, underscore and vertical bar.
 * # < > [ ] _ { | }

We shall refer to these as the "not-allowed pagename characters". We will present other ASCII 7-bit values for characters as the URL-style encoding of percent-hex-hex form known as percent-encoding. When preparing a string for embedding in a CGI-style URL, it might have to be both percent-encoded and all space characters converted to plus sign or %20 which we will call "CGI-encoded".

Some characters returned by PAGENAME are HTML-style encoded: We will refer to these as the "three special pagename characters".
 * PAGENAME:
 * " (double quote %22) is converted to &amp;quot;
 * ' (single quote %27) is converted to &amp;#39; (39 is the decimal value of hexadecimal 27 )
 * & (ambersand %3B) is converted to &amp;amp;

When considering using urlencode to construct an external link URL, especially within a template, there are two design style where that might be appropriate. Which one is appropriate is a matter the trade-offs between generality and ease-of-use.
 * urlencode:
 * For maximum generality, there is no simple combination of PAGENAME and other default wiki magic words to provide a general solution and to handle names that include all possible characters in names. The not-allowed pagename characters and the three special pagename characters both present issues. If a desired name uses any of those characters, then the actual pagename would have to be different. The most general design for a template would be a template with two parameters: a URL-style CGI-encoded parameter for the URL link and an HTML-style parameter for the link label. The URL-style parameter would be added to a search or lookup URL and the HTML-style parameter would be used to label the link. For instance, a template called OrgName that looks up an organization by name with the unusual 10-character organization name of  would call the template as  . Variations on this might use %20 instead of + in the URL-style parameter for space and/or &amp;gt; instead of &amp;62; for the greater-than character in the HTML-style parameter or just the plain characters when they work OK. To be rigorous, one might argue that having two mandatory arguments is the best style for long-term stability in case the page is moved or translated to some other wiki where where the naming style of pages is different such as where a different alphabet is used for naming pages.
 * The urlencode parser function can be used to create a template that might be easy-to-use but not perfectly general. The urlencode function converts almost all characters except alphanumerics and three of the RFC1738 URL "safe" characters: - . (dash, period) and it converts blank to plus. The technique of embedding the code fragment  into a template to create an external link URL can be useful (i.e. treating simple pagenames as data). A pagename with any of the three special pagename characters might be a problem. For example, a pagename with an ampersand, this would result in an HTML-style ampersand (&amp;amp;) being converted into to the URL-style %26amp%3B which most remote web site would not handle successfully. For names with the problematic characters, one could simply not use the template and provide a direct link in the wikisource or by adding appropriate templates or extensions to the wiki to support string manipulations.
 * A compromise between these two styles is a variation on the above code fragment, such as  where the userparam is optional but when explicitly supplied would have to be CGI-encoded.

PAGENAMEE converts spaces to underscore and URL-style encodes some other characters: This avoids the problematic coding of the three special pagename characters by encoding, for instance, ampersand as %3B, but the typical URL/CGI encoding of space is the plus sign (or sometimes as %20). If no string manipulation is available, then PAGENAMEE might only be useful for constructing a URL back into the wiki for the actual page. Another less common use might be to construct an external link to a site whose URL's actually use underscores and where the pagename otherwise matches.
 * PAGENAMEE:
 * It converts " % & ' + = ? \ ^ ` ~ to %22 %25 %26 %27 %2B %3D %3F %5C %5E %60 %7E
 * It does not convert alphanumerics and the characters: ! $ *, - . / : ; @

The URL you cut/paste in your web browser URL is similar but not exactly the same as PAGENAMEE. While not specific to the wiki web server, for wide characters, the browser performs a partial urldecode action on the real URL. This urldecoding is essential for the usability of wide characters in URLs. As an example, for an otherwise simple URL ending in a UTF-8 string percent-encoded as, your browser will usually urldecode that part and display it as 東京 (Unicode U+6771 U+5EAC), which are the two Kanji characters for Tokyo. This result can be browser-dependent for both 7-bit and wide characters. For instance if you visit the eight-character page named  as:
 * Wiki web server HTTP interface and web browser URL:
 * In order to type in a page name as a URL in your web browser, the following two characters must be URL-style encoded: % ? as %25 %3F . See RFC1738 for details.
 * How a URL is displays in a web browser's address box depends on whether the wiki web server has used URL redirection. The characters of the PAGENAMEE character set will be converted only if they are adjacent to a space. For instance, If you type in a URL into your web browser ending in A_=_B or A=B then it will send that URL directly and you will get to the wiki page if it exists. If you enter a URL into your web browser ending in  (with spaces around the equals sign), then your web browser encodes spaces to %20, and thus sends A%20=%20B to the wiki web server. The wiki web server, then converts the string to A_%3D_B and sends that back to the wiki web browser via URL redirection. You can try to see the real URL by copying the URL in the browser and pasting it as text into a simple text editor but you may find that even this technique produces browser-dependent results.

you may find that your web browser then displays a URL that has urldecoded none, some or all of the percent-encoded characters and that a cut-and-paste of the browser URL into simple text will include none, some or all of this urldecoding.

Namespaces
The following are equivalents encoded for use in MediaWiki URLs (spaces replaced with underscores and some characters percent-encoded):

As of, these can take a page name parameter and will return the namespace of the page name parameter, instead of the current page's:
 * &rarr; 
 * &rarr; 
 * &rarr; 

Parser functions
Parser functions are very similar to variables, but take one or more parameters (technically, any magic word that takes a parameter is a parser function), and the name is sometimes prefixed with a hash to distinguish them from templates.

This page only describes parser functions that are integral to the MediaWiki software. Other parser functions may be added by MediaWiki extensions such as the. For those see Help:Extension:ParserFunctions.

Namespaces
returns the localized name for the namespace with that index. is the equivalent encoded for MediaWiki URLs. It does the same, but it replaces spaces with underscores, making it usable in external links.