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
The PAGENAME variable encoding states are not simple. For simplicity in this section, ignore wide characters. The following characters are not allow in wiki page names and will not be further mentioned:
 * # < > [ ] { } |

We will present other ASCII 7-bit values for characters as the URL-style encoding of percent-hex-hex for clarity and utility since this is the same notation one would manually encode them in a URL. For this discussion, we will refer only to ASCII 7-bit values, not accented characters and such. There are also some bizzare combinations that. There are also other snags that are complex. For instance, you can create the a wiki page named
 * http://en.wikipedia.org/wiki/!"$'abc

but you cannot a page named
 * http://en.wikipedia.org/wiki/User:MyUser/!"$'abc

for reasons too complex to explain here, but it has something to do with quotes and stuff.

Some characters returned by PAGENAME are HTML-style encoded:
 * 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;

PAGENAMEE converts spaces to underscore and URL-style encodes some other characters:
 * PAGENAMEE:
 * It converts & ' to %26 %27 and " = ^ ` to %22 %3D %5E %60
 * It does not convert alphanumerics and the characters: ! $ *, - . / : ; @ ~

The URL you cut/paste in your web browser URL is not the same as PAGENAMEE. The urlencode converts almost all characters except alphanumerics and three of the RFC1738 URL "safe" characters: -. _ (dash, period, underscore). While the technique of embedding {{uuencode:{{{userparam|{{PAGENAME}}})))) into off-wiki URLs as a CGI-style parameter can be useful in templates, see notes about PAGENAME above. This can result in a double encoding. An example would be where the HTML-style ampersand of &esc;amp; is converted into to the URL-style %26amp%3B. Sometimes remote web sites can handle this, but many cannot.
 * Web server HTTP interface:
 * 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.
 * For the URL you see in your browser, the situation is more complex. As a URL in a web browser's address box, some characters in pagenames are converted sometimes and othertimes not converted. 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. But many wiki pages have spaces in them and then something different happens. 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 web server. The wiki web server, then converts the string to A_%3D_B and sends that back to the web browser via URL redirection. The wiki web server converted the equals sign because it was next to a blank. Characters that the wiki web servers converts in this way include: " = ^ ` to %22 %3D %5E %60 and + & to %2B %3F . On top of this, your web browser will hide some conversions in a somewhat brower-dependent manner because it does, in effect, a urldecode action on the real URL. This decoding is essential for usability for users of non-English languages such as Asian languages can type in wide characters into a brower's URL address. For instance, a URL ending in %E6%9D%B1%E4%BA%AC, you browser will usually urlconvert it and display it as 東京, which are the two Kanji characters for Tokyo. An easy way to reliably see the real URL is to cut-and-paste it as text into a simple text editor and see what it looks like and how much encoding happened.
 * urlencode:

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.