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:
- mw:Help:Magic words: All standard magic words, including the "standard" parser functions.
- mw:Help:Extension:ParserFunctions: Additional parser functions, including conditional expressions.
General information
In general, there are three types of magic words.
- 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.__ - Parser functions: all in lowercase. A parser function will be followed by colon and pipe-separated parameters, e.g.,
, wrapped in double braces. They will take a value and return a value.{{#ifexpr:Y|Yes|No}} - 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.
or{{#magic:}}
.{{#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:
, the name isp1 | p2 | p3}} #magic
and it is followed by an unspaced:
and a required input parameter,p1
. With a template,p1
is 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" | | 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" | | 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" | | Suppresses the appearance of the page's TOC. Can be used anywhere on a page. |
scope="row" id="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" | | Hides the "Reply" button |
scope="row" id="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" | | Removes the "{{int:vector-action-addsection}}" link (the add-new-section link) on talk pages. |
scope="row" id="NOGALLERY" | | Replaces thumbnails on a category page with normal links. |
scope="row" id="HIDDENCAT" | | Makes a category hidden when included on that category's page. |
scope="row" id="INDEX" | | Instructs search engines to index the page. |
scope="row" id="NOINDEX" | | Instructs search engines not to index the page. See Wikipedia:Controlling search engine indexing. |
scope="row" id="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" | | 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" | { | Used to amend the displayed form of the page's title. |
scope="row" id="DEFAULTSORT" | { | 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" | { || (equivalent to { |
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}} | Canonical page name. Title line. Title unless letter-case is altered with {{tld|DISPLAYTITLE}}.{{efn|If |
---|
scope="row" id="PAGENAME" | { | {{PAGENAME}} | Title line excluding namespace. |
scope="row" id="BASEPAGENAME" | { | {{BASEPAGENAME}} | Title of parent page, excluding namespace. |
scope="row" id="ROOTPAGENAME" | { | {{ROOTPAGENAME}} | Title of topmost parent (before all subpages), excluding namespace. |
scope="row" | { | {{SUBPAGENAME}} | On a subpage, rightmost portion of current title; higher subpagenames show as backlinks. |
scope="row" id="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}} |
scope="row" id="TALKPAGENAME" | { | {{TALKPAGENAME}} | Title of the talk page associated with the current page. Useful on subject pages. |
scope="row" id="NAMESPACENUMBER" | { | {{NAMESPACENUMBER:{{FULLPAGENAME}}}} | Number of the current page's namespace. |
scope="row" id="NAMESPACE" | { | {{NAMESPACE}} | Namespace of the title. |
scope="row" id="ARTICLESPACE" | { | {{ARTICLESPACE}} | rowspan="2" | On a talk page, the namespace part of the title of the associated subject page. |
scope="row" id="SUBJECTSPACE" | { | {{SUBJECTSPACE}} |
scope="row" id="TALKSPACE" | { | {{TALKSPACE}} | Namespace of the talk page associated with the current page. |
scope="row" id="FULLPAGENAMEE" | {{longitem|style=line-height:1.5em|{ { {{pad|0.4em}}(etc.)}} | {{longitem|style=line-height:1.5em|{{FULLPAGENAMEE}}, | 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" | { | | 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
{{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
{{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}} | Site name ($wgSitename). |
---|
scope="row" id="SERVER" | { | {{SERVER}} |
scope="row" id="SERVERNAME" | { | {{SERVERNAME}} | Subdomain and domain name. |
scope="row" id="ARTICLEPATH" | { | {{ARTICLEPATH}} | Relative article path ($wgArticlePath). |
scope="row" id="SCRIPTPATH" | { | {{SCRIPTPATH}} | Relative script path ($wgScriptPath). |
scope="row" id="STYLEPATH" | { | {{STYLEPATH}} | Relative style path ($wgStylePath). |
scope="row" id="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}} ! scope="row" id="LOCALYEAR" | { | {{LOCALYEAR}} |
scope="row" id="CURRENTMONTH" | { | {{CURRENTMONTH}} ! scope="row" id="LOCALMONTH" | { | {{LOCALMONTH}} |
scope="row" id="CURRENTMONTHNAME" | { | {{CURRENTMONTHNAME}} ! scope="row" id="LOCALMONTHNAME" | { | {{LOCALMONTHNAME}} |
scope="row" id="CURRENTMONTHABBREV" | { | {{CURRENTMONTHABBREV}} ! scope="row" id="LOCALMONTHABBREV" | { | {{LOCALMONTHABBREV}} |
scope="row" id="CURRENTDAY" | { | {{CURRENTDAY}} ! scope="row" id="LOCALDAY" | { | {{LOCALDAY}} |
scope="row" id="CURRENTDAY2" | { | {{CURRENTDAY2}} ! scope="row" id="LOCALDAY2" | { | {{LOCALDAY2}} |
scope="row" id="CURRENTDOW" | { | {{CURRENTDOW}} ! scope="row" id="LOCALDOW" | { | {{LOCALDOW}} |
scope="row" id="CURRENTDAYNAME" | { | {{CURRENTDAYNAME}} ! scope="row" id="LOCALDAYNAME" | { | {{LOCALDAYNAME}} |
scope="row" id="CURRENTTIME" | { | {{CURRENTTIME}} ! scope="row" id="LOCALTIME" | { | {{LOCALTIME}} |
scope="row" id="CURRENTHOUR" | { | {{CURRENTHOUR}} ! scope="row" id="LOCALHOUR" | { | {{LOCALHOUR}} |
scope="row" id="CURRENTWEEK" | { | {{CURRENTWEEK}} ! scope="row" id="LOCALWEEK" | { | {{LOCALWEEK}} |
scope="row" id="CURRENTTIMESTAMP" | { | {{CURRENTTIMESTAMP}} ! scope="row" id="LOCALTIMESTAMP" | { | {{LOCALTIMESTAMP}} |
class="wikitable plainrowheaders" id="Page_revision_data"
|+ Page revision data ! scope="col" | Variable ! scope="col" | Output |
scope="row" id="REVISIONDAY" | { | {{REVISIONDAY}} |
---|
scope="row" id="REVISIONDAY2" | { | {{REVISIONDAY2}} |
scope="row" id="REVISIONMONTH" | { | {{REVISIONMONTH}} |
scope="row" id="REVISIONYEAR" | { | {{REVISIONYEAR}} |
scope="row" id="REVISIONTIMESTAMP" | { | {{REVISIONTIMESTAMP}} |
scope="row" id="REVISIONUSER" | { | {{REVISIONUSER}} |
class="wikitable plainrowheaders"
|+ Wiki statistics |
scope="row" id="NUMBEROFPAGES" | { | {{NUMBEROFPAGES}} |
---|
scope="row" id="NUMBEROFARTICLES" | { | {{NUMBEROFARTICLES}} |
scope="row" id="NUMBEROFFILES" | { | {{NUMBEROFFILES}} |
scope="row" id="NUMBEROFEDITS" | { | {{NUMBEROFEDITS}} |
scope="row" id="NUMBEROFUSERS" | { | {{NUMBEROFUSERS}} |
scope="row" id="NUMBEROFADMINS" | { | {{NUMBEROFADMINS}} |
scope="row" id="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" | { | Unique page identifier number (for example, this page's ID is {{PAGEID}}). |
---|
scope="row" id="PAGESIZE" | { | Size of named page in bytes (for example, this page is {{PAGESIZE:{{FULLPAGENAME}}}} bytes). |
scope="row" id="PROTECTIONLEVEL" | { | 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" | { | 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" | { | Protection level for pending changes on the named page (this page, which doesn't have one, is{{PENDINGCHANGELEVEL}}). |
scope="row" id="PAGESINCATEGORY" | { | Number of pages in the category named categoryname. Each subcategory is counted as one item. |
scope="row" id="NUMBERINGROUP" | { | Number of users in the user group named groupname. |
Page IDs can be associated with articles via wikilinks (i.e. Special:Redirect/page/3235121
goes 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" | { | Converts all characters in string to lower case. |
---|
scope="row" id="lcfirst" | { | Converts first character of string to lower case. |
scope="row" id="uc" | { | Converts all characters in string to upper case. |
scope="row" id="ucfirst" | { | Converts first character of string to upper case. |
scope="row" id="formatnum" | { { | Adds comma separators to an unformatted_number (e.g. 123456789 becomes {{formatnum:123456789}}). To remove such formatting, use { |
scope="row" id="dateformat" | { { | 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 |
scope="row" id="padleft" | { { { { | 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" | { | Outputs singular if N is equal to 1, otherwise outputs plural. See the documentation at mediawiki.org for more details. |
scope="row" id="mwtime" | { { { { | 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. |
scope="row" id="gender" | { | 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" | { | Only way to evaluate magic words inside a tag, in order to generate |
= Paths =
class="wikitable plainrowheaders"
! scope="col" | Function ! scope="col" | Description |
scope="row" id="localurl" | { | Relative path to page name. The query parameter is optional. |
---|
scope="row" id="fullurl" | { | Absolute path, without protocol prefix (i.e. without "{{thinsp}} |
scope="row" id="canonicalurl" | { | Absolute path, including protocol prefix, to page name. The query parameter is optional. |
scope="row" id="filepath" | { | Absolute path to the media file filename. |
scope="row" id="urlencode" | { | 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" | { | Input encoded for use in MediaWiki URL section anchors. |
scope="row" id="ns" | { | Returns the name of the namespace whose index is the number n. For MediaWiki URLs, use { |
scope="row" id="rel2abs" | { | Converts a relative file path to an absolute path. |
scope="row" id="titleparts" | { | 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" |{ | Evaluates expression (see mw:Manual:Expr parser function syntax). |
---|
scope="row" id="if" | { | Outputs result2 if string is empty, otherwise outputs result1. |
scope="row" id="ifeq" | { | Outputs result1 if string1 and string2 are equal (alphabetically or numerically), otherwise outputs result2. |
scope="row" id="iferror" | { | Outputs result1 if test_string generates a parsing error, otherwise outputs result2. |
scope="row" id="ifexpr" | { | Outputs result1 if expression{{thinsp}} is true, otherwise outputs result2. |
scope="row" id="ifexist" | { | Outputs result1 if the page [ |
scope="row" style="white-space: nowrap;" | { | 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.).
- For the use of these functions in tables, see Help:Conditional tables.
= 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" | { | Print the name represented by the language code, e.g. en → English. Print in language 2 if given, e.g. |
scope="row" id="lst" | | Three ways to transclude a section of a page. |
scope="row" id="mentor" | | 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" | { | Links to similar topics, to engage readers. (Beta feature.) |
scope="row" id="section" | { | Aliases for |
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" | { | Send a message to a list of talk pages on the fullpagename, using the MassMessage function. |
scope="row" id="int" | { | 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 |
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 |
= 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}}
| | {{suppress categories|{{PAGESIZE}}}} |
{{yeac}}
| | {{PAGESIZE:Help:Magic words}} |
{{yeac}}
| | {{PAGESIZE:Help:Magic words}} |
{{yeac}}
| | {{PAGESIZE:{{FULLPAGENAME}}}} |
{{nayc}}
| | 0 |
{{yeac}}
| | {{PAGESIZE:Help:Magic words}} |
{{yeac}}
| | {{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
expression while allowing redirects to be identified and parsed differently{{#ifexist:}}