Help:Magic words#Page names and related info

{{pp-vandalism|small=yes}}

{{short description|Special markup for MediaWiki}}

{{redirect|WP:MAGIC|WikiProject Magic|Wikipedia:WikiProject Magic}}

{{redirect|H:MW|the MediaWiki namespace|Help:MediaWiki namespace|information about the entire MediaWiki software application|MediaWiki}}

{{for|an introduction|Help:Magic words for beginners}}

{{Wikipedia how-to|H:MW|WP:MAGIC|WP:MAGICWORDS}}

Magic words (including parser functions, variables, and behavior switches) are features of wiki markup that give instructions to Wikipedia's underlying MediaWiki software. For example, magic words can suppress or position the table of contents, disable indexing by external search engines, and produce output dynamically based on the current page or on user-defined conditional logic. Some of these features are especially useful for templates.

This page is a quick reference for magic words. For more information, refer to the main MediaWiki documentation:

General information

In general, there are three types of magic words.

  1. Behavior switches: often appear in double underscores, all uppercase, e.g., __NOTOC__. They will change the behavior of a page, rather than return a value.
  2. Parser functions: all in lowercase. A parser function will be followed by colon and pipe-separated parameters, e.g., {{#ifexpr:Y|Yes|No}}, wrapped in double braces. They will take a value and return a value.
  3. Variables: these are all uppercase, e.g., {{tld|PAGENAME}}. A variable will be wrapped in double braces and will return a value in its place.

The software generally interprets magic words in the following way:

  • Magic words are case sensitive.
  • White space is generously allowed for readability. It will be stripped from the start and end of their keywords and parameters (as is also done in template calls using named parameters).
  • They can be transcluded, even variables "about the current page". This is ensured by the parsing order.
  • Instead of magically transforming into HTML instructions, {{tag|nowiki|o}} tags remove this magic so a magic word can itself be displayed (documented), e.g. {{#magic:}}or {{#magic:}}.

Magic words compared to templates:

  • As with templates, magic words can be transcluded and substituted.
  • The names of magic words are purposely chosen to be unlike the names of templates, and vice versa. Many parser function names will begin with a #(pound or hash), but template names will not start with a #, and probably not end in a :(colon), or be all-uppercase.
  • The first parameter's syntax differs. In {{#magic: p1 | p2 | p3}}, the name is #magicand it is followed by an unspaced :and a required input parameter, p1. With a template, p1is optional and it is preceded by a |(pipe) instead of a :, e.g. {{template|p1}}.

Most magic words can be used in any needed locations on a page; see MOS:ORDER for guidance on where Wikipedia prefers to place some magic words that are behavior switches (examples: DEFAULTSORT and DISPLAYTITLE).

Behavior switches

{{further|mw:Help:Magic words#Behavior switches}}

class="wikitable plainrowheaders"

! scope="col" | Switch

! scope="col" | Description

scope="row" id="TOC" | __TOC__

| Places the page's table of contents (TOC) at the word's position. This magic word does not work in skins that present the table of contents outside the article content e.g. the default Vector 2022 skin.

scope="row" id="FORCETOC" | __FORCETOC__

| Forces the TOC to appear in its default position, even when there are fewer than four headings. Can be used anywhere on a page. This magic word does not work in skins that present the table of contents outside the article content e.g. the default Vector 2022 skin.

scope="row" id="NOTOC" | __NOTOC__

| Suppresses the appearance of the page's TOC. Can be used anywhere on a page.

scope="row" id="NOEDITSECTION" | __NOEDITSECTION__

| Hides the "edit" links normally beside all headings on the page. To hide the edit link beside a particular heading, specify the heading using e.g. an HTML tag such as {{tag|h2|content=heading}} rather than with the usual wiki equals-signs syntax (e.g. {{nowrap|1=== heading ==}}{{thinsp}}).

scope="row" id="ARCHIVEDTALK" | __ARCHIVEDTALK__

| Hides the "Reply" button

scope="row" id="NEWSECTIONLINK" | __NEWSECTIONLINK__

| On non-talk pages, adds a "{{int:vector-action-addsection}}" link as a means to add a new section to the page.

scope="row" id="NONEWSECTIONLINK" | __NONEWSECTIONLINK__

| Removes the "{{int:vector-action-addsection}}" link (the add-new-section link) on talk pages.

scope="row" id="NOGALLERY" | __NOGALLERY__

| Replaces thumbnails on a category page with normal links.

scope="row" id="HIDDENCAT" | __HIDDENCAT__

| Makes a category hidden when included on that category's page.

scope="row" id="INDEX" | __INDEX__

| Instructs search engines to index the page.

scope="row" id="NOINDEX" | __NOINDEX__

| Instructs search engines not to index the page. See Wikipedia:Controlling search engine indexing.

scope="row" id="STATICREDIRECT" | __STATICREDIRECT__

| Prevents the link on a redirection page from being updated automatically when the page to which it redirects is moved (and "Update any redirects that point to the original title" is selected).

scope="row" id="DISAMBIG" | __DISAMBIG__

| Marks a page as a disambiguation page, adds it to Special:DisambiguationPages and places inward links in Special:DisambiguationPageLinks. (See mw:Extension:Disambiguator.)

scope="row" id="DISPLAYTITLE" | {{DISPLAYTITLE:title}}

| Used to amend the displayed form of the page's title.

scope="row" id="DEFAULTSORT" | {{DEFAULTSORT:sortkey}}

| Sets the default key (the index) under which the page is categorised. Functionality is documented at {{section link|Help:Category#Default sort key}}, and guidelines are at {{section link|Wikipedia:Categorization#Sort keys}}.

scope="row" id="NOEXTERNALLANGLINKS" | {{NOEXTERNALLANGLINKS}}

|| (equivalent to {{NOEXTERNALLANGLINKS:*}}{{thinsp}}) Suppresses the automated inclusion of Wikidata interlanguage links on the lefthand side of the page. Links to particular rather than all languages may be suppressed by using {{NOEXTERNALLANGLINKS:list}}, where list a pipe-delimited list of language codes (e.g. {{NOEXTERNALLANGLINKS:fr{{pipe}}es{{pipe}}ja}} to suppress the French ("fr"), Spanish ("es") and Japanese ("ja") interlanguage links).

Variables

{{Shortcut|WP:VAR}}

{{Further|mw:Help:Magic words#Variables|Wikipedia:Page name#sub}}

{{Redirect|WP:VAR|policies and guidelines with WP:*VAR shortcuts, mostly about style matters|WP:VARS}}

{{Redirect|WP:PAGENAME|the article naming policy|Wikipedia:Article titles}}

class="wikitable plainrowheaders"

! scope="col" | Page name variable

! scope="col" | Output

! scope="col" | Description

scope="row" id="FULLPAGENAME" | {{FULLPAGENAME}}

| {{FULLPAGENAME}}

| Canonical page name. Title line. Title unless letter-case is altered with {{tld|DISPLAYTITLE}}.{{efn|If {{FULLPAGENAME}} is used in a page that is transcluded from another page, it will return the name of the target. {{ml|TEMPLATENAME|main}} can be used to determine the name of the template itself.}}

scope="row" id="PAGENAME" | {{PAGENAME}}

| {{PAGENAME}}

| Title line excluding namespace.

scope="row" id="BASEPAGENAME" | {{BASEPAGENAME}}

| {{BASEPAGENAME}}

| Title of parent page, excluding namespace.

scope="row" id="ROOTPAGENAME" | {{ROOTPAGENAME}}

| {{ROOTPAGENAME}}

| Title of topmost parent (before all subpages), excluding namespace.

scope="row" | {{SUBPAGENAME}}

| {{SUBPAGENAME}}

| On a subpage, rightmost portion of current title; higher subpagenames show as backlinks.

scope="row" id="ARTICLEPAGENAME" | {{ARTICLEPAGENAME}}

| {{ARTICLEPAGENAME}}

| rowspan="2" | Title of the subject page associated with the current page. These are useful on talk pages (but see note about Category talk pages).

scope="row" id="SUBJECTPAGENAME" | {{SUBJECTPAGENAME}}

| {{SUBJECTPAGENAME}}

scope="row" id="TALKPAGENAME" | {{TALKPAGENAME}}

| {{TALKPAGENAME}}

| Title of the talk page associated with the current page. Useful on subject pages.

scope="row" id="NAMESPACENUMBER" | {{NAMESPACENUMBER}}

| {{NAMESPACENUMBER:{{FULLPAGENAME}}}}

| Number of the current page's namespace.

scope="row" id="NAMESPACE" | {{NAMESPACE}}

| {{NAMESPACE}}

| Namespace of the title.

scope="row" id="ARTICLESPACE" | {{ARTICLESPACE}}

| {{ARTICLESPACE}}

| rowspan="2" | On a talk page, the namespace part of the title of the associated subject page.

scope="row" id="SUBJECTSPACE" | {{SUBJECTSPACE}}

| {{SUBJECTSPACE}}

scope="row" id="TALKSPACE" | {{TALKSPACE}}

| {{TALKSPACE}}

| Namespace of the talk page associated with the current page.

scope="row" id="FULLPAGENAMEE" | {{longitem|style=line-height:1.5em|{{FULLPAGENAMEE}},
{{PAGENAMEE}},
{{pad|0.4em}}(etc.)}}

| {{longitem|style=line-height:1.5em|{{FULLPAGENAMEE}},
{{PAGENAMEE}},
(etc.)}}

| Adding an E to the end of the above variables, renders the above encoded for use in MediaWiki URLs (i.e. with underscores replacing spaces).

scope="row" id="SHORTDESC" | {{SHORTDESC}}

|

| Only works on the English Wikipedia, where it displays a short description below the article title on mobile platforms. {{crossref|printworthy=y|See Wikipedia:Short description.}}

{{a note}} The magic words above can also take a parameter, in order to parse values on a page other than the current page. A colon (:) is used to pass the parameter, rather than a pipe ({{!}}) that is used in templates, like {{MAGICWORD:value}}. For example, {{TALKPAGENAME:Wikipedia:MOS}} returns Wikipedia talk:MOS on any page.

{{respond|orangeexclamation|Caution:}} Attempting to use (some) page name variables to create a wikilink to an image page, category page or interlanguage link will produce a different effect: this will respectively place the image on the page, add the page to the category, or create an interlanguage link at the edge of the page. To override this normal behavior, prefix the variable with a colon (:); for example :{{FULLPAGENAME}}.

{{crossref|printworthy=y|For more details on parser functions that relate to page names and namespaces, see: {{section link|meta:Help:Page name#Variables and parser functions}}.}}

class="wikitable plainrowheaders"

! scope="col" | Site variable

! scope="col" | Output

! scope="col" | Description

scope="row" id="SITENAME" | {{SITENAME}}

| {{SITENAME}}

| Site name ($wgSitename).

scope="row" id="SERVER" | {{SERVER}}

| {{SERVER}}

| Domain URL ($wgServer).

scope="row" id="SERVERNAME" | {{SERVERNAME}}

| {{SERVERNAME}}

| Subdomain and domain name.

scope="row" id="ARTICLEPATH" | {{ARTICLEPATH}}

| {{ARTICLEPATH}}

| Relative article path ($wgArticlePath).

scope="row" id="SCRIPTPATH" | {{SCRIPTPATH}}

| {{SCRIPTPATH}}

| Relative script path ($wgScriptPath).

scope="row" id="STYLEPATH" | {{STYLEPATH}}

| {{STYLEPATH}}

| Relative style path ($wgStylePath).

scope="row" id="CURRENTVERSION" | {{CURRENTVERSION}}

| {{CURRENTVERSION}}

| Returns current MediaWiki version.

= Other variables by type =

class="wikitable plainrowheaders" id="Current_date_and_time"

|+ Current date and time

! scope="col" colspan="2" | Universal time

! scope="col" colspan="2" | Local-website time

scope="col" | Variable

! scope="col" | Output

! scope="col" | Variable

! scope="col" | Output

scope="row" id="CURRENTYEAR" | {{CURRENTYEAR}}

| {{CURRENTYEAR}}

! scope="row" id="LOCALYEAR" | {{LOCALYEAR}}

| {{LOCALYEAR}}

scope="row" id="CURRENTMONTH" | {{CURRENTMONTH}}

| {{CURRENTMONTH}}

! scope="row" id="LOCALMONTH" | {{LOCALMONTH}}

| {{LOCALMONTH}}

scope="row" id="CURRENTMONTHNAME" | {{CURRENTMONTHNAME}}

| {{CURRENTMONTHNAME}}

! scope="row" id="LOCALMONTHNAME" | {{LOCALMONTHNAME}}

| {{LOCALMONTHNAME}}

scope="row" id="CURRENTMONTHABBREV" | {{CURRENTMONTHABBREV}}

| {{CURRENTMONTHABBREV}}

! scope="row" id="LOCALMONTHABBREV" | {{LOCALMONTHABBREV}}

| {{LOCALMONTHABBREV}}

scope="row" id="CURRENTDAY" | {{CURRENTDAY}}{{efn|{{CURRENTDAY}}, {{LOCALDAY}} and {{REVISIONDAY}} return the day (e.g. "6"), whilst {{CURRENTDAY2}}, {{LOCALDAY2}} and {{REVISIONDAY2}} return the day with zero-padding (e.g. "06"). For all two-digit days (i.e. 10 to 31), these are the same.|name=daynote}}

| {{CURRENTDAY}}

! scope="row" id="LOCALDAY" | {{LOCALDAY}}{{efn|name=daynote}}

| {{LOCALDAY}}

scope="row" id="CURRENTDAY2" | {{CURRENTDAY2}}{{efn|name=daynote}}

| {{CURRENTDAY2}}

! scope="row" id="LOCALDAY2" | {{LOCALDAY2}}{{efn|name=daynote}}

| {{LOCALDAY2}}

scope="row" id="CURRENTDOW" | {{CURRENTDOW}}

| {{CURRENTDOW}}

! scope="row" id="LOCALDOW" | {{LOCALDOW}}

| {{LOCALDOW}}

scope="row" id="CURRENTDAYNAME" | {{CURRENTDAYNAME}}

| {{CURRENTDAYNAME}}

! scope="row" id="LOCALDAYNAME" | {{LOCALDAYNAME}}

| {{LOCALDAYNAME}}

scope="row" id="CURRENTTIME" | {{CURRENTTIME}}

| {{CURRENTTIME}}

! scope="row" id="LOCALTIME" | {{LOCALTIME}}

| {{LOCALTIME}}

scope="row" id="CURRENTHOUR" | {{CURRENTHOUR}}

| {{CURRENTHOUR}}

! scope="row" id="LOCALHOUR" | {{LOCALHOUR}}

| {{LOCALHOUR}}

scope="row" id="CURRENTWEEK" | {{CURRENTWEEK}}

| {{CURRENTWEEK}}

! scope="row" id="LOCALWEEK" | {{LOCALWEEK}}

| {{LOCALWEEK}}

scope="row" id="CURRENTTIMESTAMP" | {{CURRENTTIMESTAMP}}{{efn|name=formatstamp}}

| {{CURRENTTIMESTAMP}}

! scope="row" id="LOCALTIMESTAMP" | {{LOCALTIMESTAMP}}{{efn|name=formatstamp}}

| {{LOCALTIMESTAMP}}

class="wikitable plainrowheaders" id="Page_revision_data"

|+ Page revision data

! scope="col" | Variable

! scope="col" | Output

scope="row" id="REVISIONDAY" | {{REVISIONDAY}}{{efn|name=daynote}}

| {{REVISIONDAY}}

scope="row" id="REVISIONDAY2" | {{REVISIONDAY2}}{{efn|name=daynote}}

| {{REVISIONDAY2}}

scope="row" id="REVISIONMONTH" | {{REVISIONMONTH}}

| {{REVISIONMONTH}}

scope="row" id="REVISIONYEAR" | {{REVISIONYEAR}}

| {{REVISIONYEAR}}

scope="row" id="REVISIONTIMESTAMP" | {{REVISIONTIMESTAMP}}{{efn|These timestamp outputs can be formatted with {{tl|Format revisiontimestamp}} (aka {{tl|FRTS}}). For example, {{FRTS|{{REVISIONTIMESTAMP}}}} turns "{{REVISIONTIMESTAMP}}" into "{{FRTS|{{REVISIONTIMESTAMP}}}}".|name=formatstamp}}

| {{REVISIONTIMESTAMP}}

scope="row" id="REVISIONUSER" | {{REVISIONUSER}}{{efn|This shows the last user to edit the page. There is no way to show the user viewing the page with magic words due to technical restrictions.}}

| {{REVISIONUSER}}

class="wikitable plainrowheaders"

|+ Wiki statistics

scope="row" id="NUMBEROFPAGES" | {{NUMBEROFPAGES}}

| {{NUMBEROFPAGES}}

scope="row" id="NUMBEROFARTICLES" | {{NUMBEROFARTICLES}}

| {{NUMBEROFARTICLES}}

scope="row" id="NUMBEROFFILES" | {{NUMBEROFFILES}}

| {{NUMBEROFFILES}}

scope="row" id="NUMBEROFEDITS" | {{NUMBEROFEDITS}}

| {{NUMBEROFEDITS}}

scope="row" id="NUMBEROFUSERS" | {{NUMBEROFUSERS}}

| {{NUMBEROFUSERS}}

scope="row" id="NUMBEROFADMINS" | {{NUMBEROFADMINS}}

| {{NUMBEROFADMINS}}

scope="row" id="NUMBEROFACTIVEUSERS" | {{NUMBEROFACTIVEUSERS}}

| {{NUMBEROFACTIVEUSERS}}

Parser functions

{{Shortcut|WP:PF|WP:PARSER}}

{{further|mw:Help:Magic words#Parser functions|mw:Help:Extension:ParserFunctions}}

= Metadata =

class="wikitable plainrowheaders"

! scope="col" | Function

! scope="col" | Description

scope="row" id="PAGEID" | {{PAGEID}}

| Unique page identifier number (for example, this page's ID is {{PAGEID}}).

scope="row" id="PAGESIZE" | {{PAGESIZE:fullpagename}}{{efn|name=expensive|This function is an expensive parser function.}}

| Size of named page in bytes (for example, this page is {{PAGESIZE:{{FULLPAGENAME}}}} bytes).

scope="row" id="PROTECTIONLEVEL" | {{PROTECTIONLEVEL:action{{pipe}}fullpagename}}

| Protection level assigned to action ("edit", "move", etc.) on named page (this page's protection level for "edit" is {{PROTECTIONLEVEL:edit|Help:Magic words}}).

scope="row" id="PROTECTIONEXPIRY" | {{PROTECTIONEXPIRY:action{{pipe}}fullpagename}}

| Protection expiry assigned to action ("edit", "move", etc.) on named page (this page's protection expiry is {{PROTECTIONEXPIRY:edit|Help:Magic words}}).

scope="row" id="PENDINGCHANGELEVEL" | {{PENDINGCHANGELEVEL:fullpagename}}

| Protection level for pending changes on the named page (this page, which doesn't have one, is{{PENDINGCHANGELEVEL}}).

scope="row" id="PAGESINCATEGORY" | {{PAGESINCATEGORY:categoryname}}

| Number of pages in the category named categoryname. Each subcategory is counted as one item.

scope="row" id="NUMBERINGROUP" | {{NUMBERINGROUP:groupname}}

| Number of users in the user group named groupname.

Page IDs can be associated with articles via wikilinks (i.e. Special:Redirect/page/3235121goes to this page).

To output numbers without comma separators (for example, as "123456789" rather than "123,456,789"), append the parameter |R.

= Formatting =

{{further|mw:Help:Magic words#Formatting}}

class="wikitable plainrowheaders"

! scope="col" | Function

! scope="col" | Description

scope="row" id="lc" | {{lc:string}}

| Converts all characters in string to lower case.

scope="row" id="lcfirst" | {{lcfirst:string}}

| Converts first character of string to lower case.

scope="row" id="uc" | {{uc:string}}

| Converts all characters in string to upper case.

scope="row" id="ucfirst" | {{ucfirst:string}}

| Converts first character of string to upper case.

scope="row" id="formatnum" | {{formatnum:unformatted_number}}
{{formatnum:formatted_num {{pipe}}R}}

| Adds comma separators to an unformatted_number (e.g. 123456789 becomes {{formatnum:123456789}}). To remove such formatting, use {{formatnum:formatted_number{{pipe}}R}} (i.e. {{braces|formatnum:7,654,321{{pipe}}R}}, for example, produces {{formatnum:7,654,321|R}}).

scope="row" id="dateformat" | {{#dateformat:date{{pipe}}format}}
{{#formatdate:date{{pipe}}format}}

| 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 dmy, mdy, ymd, or ISO 8601 formats, with the user's preference overriding the specified format.

scope="row" id="padleft" | {{padleft:xyz{{pipe}}stringlength}}
{{padright:xyz{{pipe}}stringlength}}

{{padleft:xyz{{pipe}}length{{pipe}}padstr}}
{{padright:xyz{{pipe}}length{{pipe}}padstr}}

| Pad with zeroes '0' to the right or left, to fill the given length; an alternative padding string can be given as a third parameter; the repeated padding string (padstr) will be truncated if its length does not evenly divide the required number of characters.

scope="row" id="mwplural" | {{plural:N{{pipe}}singular{{pipe}}plural}}

| Outputs singular if N is equal to 1, otherwise outputs plural. See the documentation at mediawiki.org for more details.

scope="row" id="mwtime" | {{#time:format{{pipe}}object}}
{{#timel:format{{pipe}}object}}

{{#time:d F Y{{pipe}}date{{pipe}}langcode}}

{{#timef:object{{pipe}}format type{{pipe}}langcode}}

| Used to format dates and times, for ISO format, dots or English month names. #timel and #timefl are based on local time as defined for each wiki; for English Wikipedia, this is identical to #time and #timef.
The optional 3rd parameter is the output language code (French, German, Swedish: fr, de, sv, etc.). Example Finnish: {{#time:d F Y|June 30, 2016|fi}} shows: {{#time:d F Y|June 30, 2016|fi}} (June). ISO to German: {{#time:d. M Y|1987-10-31|de}} shows: {{#time:d. M Y|1987-10-31|de}}.
For format codes, see: mw:Help:Extension:ParserFunctions##time. Use the format {{#time: H:i, j F Y (e)|...}} to match the format used by timestamps in signatures.
#timef formats a date using a standard format for the selected language, see: mw:Help:Extension:ParserFunctions##timef.

scope="row" id="gender" | {{gender:user{{pipe}}m_out{{pipe}}f_out{{pipe}}u_out}}

| Outputs m_out, f_out or u_out according to whether the gender specified in user{{thinsp}}'s preferences is, respectively, male, female or unspecified. Other parameter permutations are available, see mw:Help:Magic words#gender and translatewiki:Gender.

scope="row" id="mwtag" | {{#tag:tagname{{pipe}}content with magic}}

| Only way to evaluate magic words inside a tag, in order to generate <tagname>magic</tagname>. Also handles tag attributes. Details at mw:Help:Magic words#tag.

= Paths =

class="wikitable plainrowheaders"

! scope="col" | Function

! scope="col" | Description

scope="row" id="localurl" | {{localurl:fullpagename {{pipe}}query}}

| Relative path to page name. The query parameter is optional.

scope="row" id="fullurl" | {{fullurl:fullpagename {{pipe}}query}}

| Absolute path, without protocol prefix (i.e. without "{{thinsp}}http:{{thinsp}}" etc.), to page name. The query parameter is optional.

scope="row" id="canonicalurl" | {{canonicalurl:fullpagename {{pipe}}query}}

| Absolute path, including protocol prefix, to page name. The query parameter is optional.

scope="row" id="filepath" | {{filepath:filename}}

| Absolute path to the media file filename.

scope="row" id="urlencode" | {{urlencode:string}}

| Encodes string for use in URL query strings; {{braces|urlencode:test string}}, for example, produces: {{urlencode:test string}}. To encode string for use in URL paths or MediaWiki page names, append, respectively, {{para||PATH}} or {{para||WIKI}} (to produce "{{urlencode:test string|PATH}}" or "{{urlencode:test string|WIKI}}").

scope="row" id="anchorencode" | {{anchorencode:string}}

| Input encoded for use in MediaWiki URL section anchors.

scope="row" id="ns" | {{ns:n}}

| Returns the name of the namespace whose index is the number n. For MediaWiki URLs, use {{nse:}}.

scope="row" id="rel2abs" | {{#rel2abs:path}}

| Converts a relative file path to an absolute path.

scope="row" id="titleparts" | {{#titleparts:fullpagename{{pipe}}number{{pipe}}first segment}}

| Splits the fullpagename (title) into that number of segments.

=Conditional=

{{further|Help:Conditional expressions}}

class="wikitable plainrowheaders"

! scope="col" | Function

! scope="col" | Description

scope="row" id="expr" |{{#expr:expression}}

| Evaluates expression (see mw:Manual:Expr parser function syntax).

scope="row" id="if" | {{#if:string {{pipe}}result1 {{pipe}}result2}}

| Outputs result2 if string is empty, otherwise outputs result1.

scope="row" id="ifeq" | {{#ifeq:string1{{pipe}}string2 {{pipe}}result1 {{pipe}}result2}}

| Outputs result1 if string1 and string2 are equal (alphabetically or numerically), otherwise outputs result2.

scope="row" id="iferror" | {{#iferror:test_string {{pipe}}result1 {{pipe}}result2}}

| Outputs result1 if test_string generates a parsing error, otherwise outputs result2.

scope="row" id="ifexpr" | {{#ifexpr:expression {{pipe}}result1 {{pipe}}result2}}

| Outputs result1 if expression{{thinsp}} is true, otherwise outputs result2.

scope="row" id="ifexist" | {{#ifexist:pagetitle {{pipe}}result1 {{pipe}}result2}}{{efn|name=expensive|This function is an expensive parser function.}}

| Outputs result1 if the page [[pagetitle]] exists, otherwise outputs result2. Note that underscores are needed for spaces in namespaces.

scope="row" style="white-space: nowrap;" | {{#switch:string {{pipe}}c1=r1 {{pipe}}c2=r2 ... {{pipe}}default}}

| Outputs r1 if string is c1, r2 if string is c2, etc., otherwise outputs default (if provided).

If, in these conditional functions, empty unnamed parameters are to be parsed as empty rather than as text (i.e. as empty rather than as the text "{{{1}}}", "{{{2}}}", etc.), they will require trailing pipes (i.e. {{(((}}1{{pipe}}{{)))}}, {{(((}}2{{pipe}}{{)))}}, etc., rather than {{(((}}1{{)))}}, {{(((}}2{{)))}}, etc.).

= Other =

class="wikitable plainrowheaders"

! scope="col" | Function

! scope="col" | Description

scope="row" id="babel" | mw:Extension:Babel#Usage

| Render userboxes telling your language skills. Improves upon {{tl|Babel}} (an alternative).

scope="row" id="categorytree" | mw:Extension:CategoryTree

| List pages in a category, recursively.

scope="row" | mw:Extension:GeoData#Parser function

| Save the GeoData coordinates of the subject to the page's database. Used in {{tl|coord}}.

scope="row" style="white-space: nowrap;" | mw:Extension:Scribunto#Usage

|| Use Scribunto to transclude a lua template, e.g. function replace in module String.

scope="row" id="language" | {{#language:ISO 639

| Print the name represented by the language code, e.g. enEnglish. Print in language 2 if given, e.g. {{#language:en|zh}} prints {{#language:en|zh}}

scope="row" id="lst" | {{#lst:}}, {{#lsth:}}, {{#lstx:}}

| Three ways to transclude a section of a page.

scope="row" id="mentor" | {{#mentor:Username}}

| Display the currently assigned mentor for target Username, if set.

scope="row" id="property" | m:Wikidata/Notes/Inclusion syntax v0.4

| Include a property (Wikidata) from a named entity, instead of the default on the page.

scope="row" id="related" | {{#related:...}}

| Links to similar topics, to engage readers. (Beta feature.)

scope="row" id="section" | {{#section:}}, {{#section-h:}}, {{#section-x:}}

| Aliases for {{#lst:}}, {{#lsth}}, {{#lstx}} (above).

scope="row" id="statements" | d:Wikidata:How to use data on Wikimedia projects

| Display the value of any statement (Wikidata) included in an item.

scope="row" id="target" | {{#target:fullpagename}}

| Send a message to a list of talk pages on the fullpagename, using the MassMessage function.

scope="row" id="int" | {{int:pagename}}

| Transclude an interface message, i.e. a pagename in MediaWiki namespace

scope="row" id="bang" | {{!}}

| Used to include a pipe character as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creating :Template:! with {{!}} as the content.

scope="row" id="equals" | {{=}}

| Used to include an equal sign as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creating :Template:= with {{=}} as the content.

= Substituting and nesting =

Magic words can sometimes behave weirdly when substituted or nested. It's possible to subst some magic words (so that the page stops being updated if the value of the word changes). Here are some examples of how this works:

class="wikitable plainrowheaders"

! scope="col" | {{idkc}}

! scope="col" | Code

! scope="col" | Output

{{nayc}}

| {{PAGESIZE}}

| {{suppress categories|{{PAGESIZE}}}}

{{yeac}}

| {{PAGESIZE:Help:Magic words}}

| {{PAGESIZE:Help:Magic words}}

{{yeac}}

| {{subst:PAGESIZE:Help:Magic words}}

| {{PAGESIZE:Help:Magic words}}

{{yeac}}

| {{PAGESIZE:{{FULLPAGENAME}}}}

| {{PAGESIZE:{{FULLPAGENAME}}}}

{{nayc}}

| {{subst:PAGESIZE:{{FULLPAGENAME}}}}

| 0

{{yeac}}

| {{PAGESIZE:{{subst:FULLPAGENAME}}}}

| {{PAGESIZE:Help:Magic words}}

{{yeac}}

| {{subst:PAGESIZE:{{subst:FULLPAGENAME}}}}

| {{PAGESIZE:{{FULLPAGENAME}}}}

See also

  • mw:Localisation
  • mw:Manual:Extending wiki markup
  • [https://phabricator.wikimedia.org/diffusion/MW/history/master/includes/parser/CoreParserFunctions.php CoreParserFunctions.php]
  • {{myprefs|Gadgets|Editing|check={{int:gadget-DotsSyntaxHighlighter}}}}
  • Special:Version, see last section "Parser function hooks":a list that should include all of the magic words on this page
  • {{tl|Ifexist not redirect}}, works with the {{#ifexist:}} expression while allowing redirects to be identified and parsed differently

Notes

{{Notelist}}

{{Wikipedia technical help|collapsed}}

Category:Wikipedia features