Help:Magic words

Magic words (which include parser functions, variables and behavior switches) are features of wikitext that enable various instructions to be given to the MediaWiki software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in templates.

A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to the following pages on the MediaWiki site:
 * mw:Help:Magic words for all standard magic words, including the "standard" parser functions
 * mw:Help:Extension:ParserFunctions for some additional parser functions, including conditional expressions

General information
There are three types of magic words:
 * Behavior switches: uppercase words surrounded by double underscores, e.g.  , or keywords using parser function syntax
 * Variables: uppercase words surrounded by double braces, e.g.   (thus resembling templates)
 * Parser functions: keywords (some beginning #) in double braces with parameters after a colon, e.g.  

Some magic words are case-insensitive, but not all. White space is stripped from the start and end of keywords and parameters, as in template syntax.

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

It is possible to substitute parser functions and variables in the same way that templates are substituted (using the subst: keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.

Behavior switches
For documentation, refer to the Behavior Switches section of the MediaWiki page.
 *   (can appear anywhere in the wikitext; suppresses the table of contents)
 *   (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
 *   (places a table of contents at the word's position)


 *   (hides the section "edit" links beside all headings on the page) (use tags to hide the edit link for one header only)
 *  __NEWSECTIONLINK__ </tt> (adds a "+" link for adding a new section on a non-"Talk" page)
 *  __NONEWSECTIONLINK__ </tt> (removes the "+" link on "Talk" pages)


 *  __NOGALLERY__ </tt> (on a category page, replaces thumbnails with normal links)
 *  __HIDDENCAT__ </tt> (on a category page, makes it a hidden category)
 *  __INDEX__ </tt> (tells search engines to index the page)
 *  __NOINDEX__ </tt> (tells search engines not to index the page)
 *  __STATICREDIRECT__ </tt> (On redirect pages, don't allow MediaWiki to automatically update the link when someone moves a page and checks "Update any redirects that point to the original title", also used to tell interwikibots that this redirect might be seen as an article)


 *  </tt> (changes the displayed form of the page title)
 *  </tt> (sets a default category sort key)


 *  </tt> to suppress all Wikidata  automatic interlanguage links. Equivalent to   </tt>. Links for individual languages can be suppressed by specifying language codes in a pipe-separated list, e.g.   </tt>.  See mw:Extension:Wikibase Client.

Variables
For documentation, refer to the Variables section of the MediaWiki page.
 *  </tt> (page title including namespace)
 *  </tt> (page title excluding namespace)
 *  </tt> (page title excluding current subpage and namespace - effectively the parent page without the namespace.)
 *  </tt> (subpage part of title)
 * <tt>, </tt> (associated non-talk page)
 * <tt> </tt> (associated talk page)
 * <tt> </tt> (namespace of current page)
 * <tt>, </tt> (associated non-talk namespace)
 * <tt> </tt> (associated talk namespace)
 * <tt>, </tt> etc. (equivalents encoded for use in MediaWiki URLs)

The above can all take a parameter, to operate on a page other than the current page.


 * <tt> </tt>
 * <tt> </tt>
 * <tt> </tt>
 * <tt> </tt>
 * <tt> </tt> (current MediaWiki version)
 * <tt> </tt> (latest revision to current page)
 * <tt>, , , , , </tt> (date, time, editor at last edit)


 * <tt> 2024, August, August, August, 28,, , Wednesday, , , , </tt> (current date/time variables)
 * <tt> 2024 </tt> etc. (as above, based on site's local time)


 * <tt>, , , , , , , </tt> (statistics on English TechInfoDepot; add <tt>:R</tt> to return numbers without commas)

Parser functions
These are fully documented at the Meta magic words page or ParserFunctions Extension documentation unless otherwise stated.

Metadata

 * <tt> </tt> (unique page identifier number)
 * <tt> </tt> (size of page in bytes)
 * <tt> </tt> (protection level for given action on the current page)
 * <tt> </tt> (level of pending changes protection on the current page)
 * <tt> </tt> (number of pages in the given category)
 * <tt> </tt> (number of users in a specific group)

Add <tt>|R</tt> to return numbers without commas.

Formatting

 * <tt> string </tt> (convert to lower case)
 * <tt> string </tt> (convert first character to lower case)
 * <tt> STRING </tt> (convert to upper case)
 * <tt> String </tt> (convert first character to upper case)
 * <tt> NaN </tt> (format a number with comma separators; add <tt> | R</tt> to unformat a number)
 * <tt> </tt> (formats a date according to user preferences; a default can be given as an optional case-sensitive second parameter for users without date preference; can convert a date from an existing format to any of <tt>dmy</tt>, <tt>mdy</tt>, <tt>ymd</tt> or <tt>ISO 8601</tt> formats, with the user's preference overriding the specified format)
 * <tt> xyz </tt>, <tt> xyz </tt> (pad with zeros to the right or left; an alternative padding string can be given as a third parameter; the alternative padding string may be truncated if its length does not evenly divide the required number of characters)
 * <tt> NaN iss </tt> (produces alternative text according to whether n is greater than 1)
 * <tt> </tt> (for date/time formatting; also <tt>#timel</tt> for local time. Covered at the extension documentation page.)
 * <tt> </tt> (produces alternative text according to the gender specified by the given user in his/her preferences)
 * <tt> </tt> (equivalent to an HTML tag or pair of tags; can be used for nesting references)

Paths

 * <tt> </tt>, <tt>  </tt> (relative path to the title)
 * <tt> </tt>, <tt>  </tt> (absolute path to the title, without a protocol prefix)
 * <tt> </tt>, <tt>  </tt> (absolute path to the title, with a protocol prefix)
 * <tt> </tt> (absolute URL to a media file)
 * <tt> </tt> (input encoded for use in URL query strings: )
 * <tt> </tt> (input encoded for use in URL paths: )
 * <tt> </tt> (input encoded for use as MediaWiki page names: )
 * <tt> </tt> (input encoded for use in MediaWiki URL section anchors)
 * <tt>     </tt> (name for the namespace with index n; use <tt>  </tt> for the equivalent encoded for MediaWiki URLs)
 * <tt> </tt> (converts a relative file path to absolute; see the extension documentation)
 * <tt> </tt> (splits title into parts; see the extension documentation)

Conditional expressions
These are covered at the extension documentation page. Some parameters are optional.
 * <tt> </tt> (evaluates the given expression; see Help:Calculation)
 * <tt> </tt> (selects one of two values based on whether the test string is empty)
 * <tt> </tt> (selects one of two values based on whether the test strings are equal – numerically if applicable)
 * <tt> </tt> (selects value based on whether the test string generates a parser error)
 * <tt> </tt> (selects value based on evaluation of expression)
 * <tt> </tt> (selects value depending on whether a page title exists)
 * <tt> </tt> (provides alternatives based on the value of the test string)

Note that with  expressions, a variable like   always requires a final pipe:. If it is absent, then whenever the parameter 1 is absent, instead of leaving the field blank the software will use the actual text   and the field will never be empty.

For the use of these functions in tables, see Conditional tables.

Other

 * (replacement for the template; see Extension:Babel)
 * (see Extension:GeoData)
 * (calls a function located in a Scribunto module; see TechInfoDepot:Lua)