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 explains only the standard magic words; for a technical reference, see.

There are three general types of magic words:


 * bs>#Behavior switches|Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__.


 * var>#Variables|Variables: these are uppercase words surrounded by double braces, e.g.  . As such, they look a lot like help-templates>Special:MyLanguage/Help:Templates|templates.


 * pfunc>#Parser functions|Parser functions: these take parameters and are either of the form   or  . See also .

Variables and parser functions can use manual-subst>Special:MyLanguage/Manual:subst|subst:, just like templates. 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 behavior 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 help-templates>Special:MyLanguage/Help:Templates|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 date and time magic words are formatted in the wiki content language. Since, they depend on the manual-pagelang>Special:MyLanguage/Manual:Language#page-content-lang|page content language.

The following variables do the same as the preceding ones, but using the site's server config or $wgLocaltimezone</>.

For more thorough time formatting, you may want to install <tvar|ext-parserfunctions></> to use the ext-parserfunct-t>Special:MyLanguage/Help:Extension:ParserFunctions#.23time</>|#time parser function.

Technical metadata
Note: 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, dots or spaces, depending on the local language), but can return raw numbers with the ":R" flag (for example, <tvar|nop-code> </> &rarr; <tvar|nop-result></> and <tvar|nop-r-code> </> &rarr; <tvar|nop-r-result></>).

Use "|R" for magic words that require a parameter like PAGESINCATEGORY (for example <tvar|pic> </> and <tvar|pic-r> </>, or <tvar|pic-subcats> </> and <tvar|pic-subcats-r> </>). Also applicable to <tvar|pagesize> </> hereinbefore.

The number magic words are formatted in the wiki content language. Since, it depends on the manual-pagelang>Special:MyLanguage/Manual:Language#page-content-lang</>|page content language.

Page names
The <tvar|basepagename> </> and <tvar|subpagename> </> magic words only work in namespaces that have subpages enabled. See <tvar|manual-wg-ns-with-subpages></> for information on enabling subpages.

As of, these can all take a parameter, allowing specification of the page to be operated on, instead of just the current page:
 * <tvar|code> </> &rarr; <tvar|result></>

Page titles containing certain characters, such as apostrophes  or asterisks , may produce unexpected results when handled with these magic words, e.g. <tvar|pic> </>. See bugs, , , and. One simple way to fix this is wrapping the pagename in <tvar|titleparts> </> from the help-ext-pf>Special:MyLanguage/Help:Extension:ParserFunctions</>|ParserFunctions extension.

For example, if page name is "<tvar|pagename>L'Aquila</>", the following code will produce the string "<tvar|result>Numeric char encoding</>":

URL encoded page names
The following are equivalents encoded for use in MediaWiki URLs (i.e. spaces replaced with underscores and some characters HTML escaped using numeric character encoding):



Note that <tvar|pagename> </>, <tvar|pagenamee> </> and <tvar|uec> </> have distinct implementations. See manual-pagename-encoding>Special:MyLanguage/Manual:PAGENAMEE encoding</>|Manual:PAGENAMEE encoding for details.

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 full-page-name parameter and will return the requested namespace associated with that page, instead of with the current page:

Parameter must not be a namespace name:
 * &rarr; 
 * &rarr; 
 * &rarr; 
 * &rarr;   (Empty)

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 <tvar|ext-pf></>. For those see <tvar|help-ext-pf></>.

Namespaces
<tvar|ns> </> returns the current localized name for the help-ns>Special:MyLanguage/Help:Namespace</>|namespace with that index, canonical name, or local alias. Thus <tvar|ns6> </>, <tvar|ns-file> </>, and <tvar|ns-img> </> (an old name for the File namespace) all return "   ". On a wiki where the content language is French, <tvar|ns-file-de> </> is also valid, but <tvar|ns-file-incorrect> </> (the localisation of "File" in German) is not.

<tvar|nse> </> is the equivalent encoded for MediaWiki URLs. It does the same, but it replaces spaces with underscores, making it usable in external links.

Don't confuse localised namespaces with manual-custom-ns>Special:MyLanguage/Manual:Using custom namespaces</>|custom namespaces.

Formatting
See also: <tvar|ext-stringfunctions></>.

Localization
Here are the magic words which are used as main localisation tools. Other magic words will often depend on the wiki's locale and configuration or on the chosen language: see in particular date>#Date and time</>|#Date and time, formatting>#Formatting</>|#Formatting, misc>#Miscellaneous</>|#Miscellaneous. More magic words are added by the <tvar|ext-translate></>.

The usage of these magic words can be very complex, and the documentation is currently incomplete; there's some more info on PLURAL, GRAMMAR, GENDER.

Transclusion modifiers
usually transcludes another page, by default from the Template:namespace.

These magic words modify that behavior.