Help:Magic words

From Wikipedia, the free encyclopedia
  (Redirected from Wikipedia:Magic word)
Jump to: navigation, search
"WP:MAGIC" redirects here. For an introduction, see Help:Magic words for beginners. For help on the automatic transformation of wikitext, see Help:Magic. For the WikiProject on stage magic and illusions, see Wikipedia:WikiProject Magic.
Shortcuts:

Magic words (which include parser functions, variables and behavior switches) are features of wiki markup that enable various instructions to be given to the MediaWiki software. For example, the magic words may be used to suppress or position the table of contents, or to produce other variable outputs, as is often required in templates.

A quick reference for magic words can be found on this page. For more complete documentation, see the following pages on the MediaWiki site:

General information[edit]

There are three types of magic words:

  1. Behavior switches: uppercase words surrounded by double underscores, e.g., __NOTOC__ or other keywords using parser function syntax
  2. Variables: uppercase words surrounded by double braces (thus resembling templates), e.g. {{PAGENAME}}
  3. Parser functions: keywords in double braces with parameters after a colon (some beginning with #), e.g. {{#expr:2+2}}

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 most 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[edit]

For documentation, see the Behavior switches section of the MediaWiki page, unless otherwise stated.
__TOC__ Places the page's table of contents (TOC) at the word's position.
__FORCETOC__ Forces the TOC to appear in its default position immediately before the page's first section (first heading). Can be used anywhere on a page.
__NOTOC__ Suppresses the appearance of the page's TOC. Can be used anywhere on a page.
__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 <h2>[Heading]</h2> rather than with the usual wiki equals-signs syntax (e.g. == [Heading] ==).
__NEWSECTIONLINK__ On non-talk pages, adds a "New section" link as a means to add a new section to the page.
__NONEWSECTIONLINK__ Removes the "New section" link (the add-new-section link) on talk pages.
__NOGALLERY__ Replaces thumbnails on a category page with normal links.
__HIDDENCAT__ Makes a category hidden when included on that category's page.
__INDEX__ Instructs search engines to index the page.
__NOINDEX__ Instructs search engines not to index the page.
__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). Also instructs interwiki bots to treat the page as if an article.
__DISAMBIG__ Marks a page as a disambiguation page, adds it to Special:DisambiguationPages and places inward links in Special:DisambiguationPageLinks. (See mw:Extension:Disambiguator.)
{{DISPLAYTITLE:title}} Used to amend the displayed form of the page's title.
{{DEFAULTSORT:sortkey}} Sets the default key (the index) under which the page is categorised.
{{NOEXTERNALLANGLINKS}} (equivalent to {{NOEXTERNALLANGLINKS:*}}) 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|es|ja}} to suppress the French ("fr"), Spanish ("es") and Japanese ("ja") interlanguage links). (See mw:Extension:Wikibase Client#noexternallanglinks.)

Variables[edit]

Shortcut:
For more documentation, see the Variables section of the MediaWiki page.
Variable
Example output on the page
"Help:Magic words/subpage"
Notes
{{ARTICLEPAGENAME}} Help:Magic words/subpage Associated non-talk page (identical to {{SUBJECTPAGENAME}})
{{ARTICLESPACE}} Help Associated non-talk namespace (identical to {{SUBJECTSPACE}})
{{BASEPAGENAME}} Magic words Page title excluding current subpage and namespace (in effect, the parent page less its namespace)
{{FULLPAGENAME}} Help:Magic words/subpage Page title including namespace
{{NAMESPACE}} Help Current page's namespace
{{PAGENAME}} Magic words/subpage Page title excluding namespace
{{SUBJECTPAGENAME}} Help:Magic words/subpage Associated non-talk page (identical to {{ARTICLEPAGENAME}})
{{SUBJECTSPACE}} Help Associated non-talk namespace (identical to {{ARTICLESPACE}})
{{SUBPAGENAME}} subpage Subpage part of title
{{TALKPAGENAME}} Help talk:Magic words/subpage Associated talk page
{{TALKSPACE}} Help talk Associated talk page's namespace
{{FULLPAGENAMEE}},
{{PAGENAMEE}},
 etc.
Help:Magic_words/subpage,
Magic_words/subpage,
etc.
Equivalents of the above encoded for use in MediaWiki URLs (i.e. with underscores replacing spaces)

Note: The variables above can each take a parameter in order to operate on a page other than the current page. For example, {{TALKPAGENAME:WP:MOS}} returns "Wikipedia talk:MOS". A colon (:) is used to pass the parameter, rather than the pipe (|) used in templates.

{{SITENAME}} Wikipedia
{{SERVER}} //en.wikipedia.org
{{SERVERNAME}} en.wikipedia.org
{{SCRIPTPATH}} /w
{{CURRENTVERSION}} 1.24wmf13 (43078d4) Returns current MediaWiki version.

Other variables by type[edit]

Date / time
Universal time
  • {{CURRENTYEAR}}
  • {{CURRENTMONTH}}
  • {{CURRENTMONTHNAME}}
  • {{CURRENTMONTHABBREV}}
  • {{CURRENTDAY}}
  • {{CURRENTDAY2}}
  • {{CURRENTDOW}}
  • {{CURRENTDAYNAME}}
  • {{CURRENTTIME}}
  • {{CURRENTHOUR}}
  • {{CURRENTWEEK}}
  • {{CURRENTTIMESTAMP}}
Local website time
  • {{LOCALYEAR}}
  • {{LOCALMONTH}}
  • {{LOCALMONTHNAME}}
  • {{LOCALMONTHABBREV}}
  • {{LOCALDAY}}
  • {{LOCALDAY2}}
  • {{LOCALDOW}}
  • {{LOCALDAYNAME}}
  • {{LOCALTIME}}
  • {{LOCALHOUR}}
  • {{LOCALWEEK}}
  • {{LOCALTIMESTAMP}}
Revision data
  • {{REVISIONID}}a
  • {{REVISIONDAY}}
  • {{REVISIONDAY2}}
  • {{REVISIONMONTH}}
  • {{REVISIONYEAR}}
  • {{REVISIONTIMESTAMP}}
  • {{REVISIONUSER}}
Statisticsb
  • {{NUMBEROFPAGES}}
  • {{NUMBEROFARTICLES}}
  • {{NUMBEROFFILES}}
  • {{NUMBEROFEDITS}}
  • {{NUMBEROFVIEWS}}
  • {{NUMBEROFUSERS}}
  • {{NUMBEROFADMINS}}
  • {{NUMBEROFACTIVEUSERS}}

a {{REVISIONID}} cannot be substituted and does not function in preview.
b English Wikipedia.

Parser functions[edit]

Shortcut:
For documentation, see the MediaWiki magic words page or the ParserFunctions Extension page, unless otherwise stated.

Metadata[edit]

{{PAGEID}} Unique page identifier number.
{{PAGESIZE:pagename}} Size of page named pagename in bytes.
{{PROTECTIONLEVEL:action|pagename}} Protection level assigned to action ("edit", "move", etc) on page named pagename.
{{PENDINGCHANGELEVEL}} Protection level for pending changes on the current page.
{{PAGESINCATEGORY:categoryname}} Number of pages in the category named categoryname.
{{NUMBERINGROUP:groupname}} Number of users in the usergroup named groupname.

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

Formatting[edit]

{{lc:string}} Converts all characters in string to lower case.
{{lcfirst:string}} Converts first character of string to lower case.
{{uc:string}} Converts all characters in string to upper case.
{{ucfirst:string}} Converts first character of string to upper case.
{{formatnum:unformatted_number}} Adds comma separators to an unformatted_number (e.g. 123456789 becomes 123,456,789). To remove such formatting, use {{formatnum:formatted_number|R}} (i.e. {{formatnum:7,654,321|R}}, for example, produces 7654321).
{{#formatdate:date|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.
{{padleft:xyz|stringlength}}
{{padright:xyz|stringlength}}
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.
{{plural:N |singular |plural}} Outputs singular if N is less than 1, otherwise outputs plural.
{{#time:format|object}}
{{#timel:}} (for local time)
Used to format dates and times. #timel is based on local time as defined for the entire wiki; for the English Wikipedia, where local time is set to UTC, this is identical to #time. (See mw:Help:Extension:ParserFunctions##time.)
{{gender:user |m_out |f_out |u_out}} Outputs m_out, f_out or u_out according to whether the gender specified in user's preferences is, respectively, male, female or unspecified.
{{#tag:tag|content |p1=v1 |p2=v2}} An equivalent to the HTML <tag>...</tag> that is useful when e.g. nesting references.

Paths[edit]

{{localurl:pagename |query}} Relative path to pagename. The query parameter is optional.
{{fullurl:pagename |query}} Absolute path, without protocol prefix (i.e. without "http://" etc), to pagename. The query parameter is optional.
{{canonicalurl:pagename |query}} Absolute path, including protocol prefix, to pagename. The query parameter is optional.
{{filepath:filename}} Absolute path to the media file filename.
{{urlencode:string}} Encodes string for use in URL query strings; {{urlencode:test string}}, for example, produces: test+string. To encode string for use in URL paths or MediaWiki page names, append, respectively, |PATH or |WIKI (to produce "test%20string" or "test_string").
{{anchorencode:string}} Input encoded for use in MediaWiki URL section anchors.
{{ns:n}} Returns the name of the namespace whose index is the number n. For MediaWiki URLs, use {{nse:}}.
{{#rel2abs:path}} Converts a relative file path to an absolute path. (See mw:Help:Extension:ParserFunctions##rel2abs.)
{{#titleparts:pgname|num|first_seg}} Splits the page pgname's title into a number of segments. (See mw:Help:Extension:ParserFunctions##titleparts.)

Conditional[edit]

Some parameters optional. For documentation, see mw:Help:Extension:ParserFunctions.
{{#expr:expression}} Evaluates expression (see Help:Calculation).
{{#if:string |result1 |result2}} Outputs result2 if string is empty, otherwise outputs result1.
{{#ifeq:string1|string2 |result1 |result2}} Outputs result1 if string1 and string2 are equal (alphabetically or numerically), otherwise outputs result2.
{{#iferror:test_string |result1 |result2}} Outputs result1 if test_string generates a parsing error, otherwise outputs result2.
{{#ifexpr:expression |result1 |result2}} Outputs result1 if expression is true, otherwise outputs result2.
{{#ifexist:pagetitle |result1 |result2}} Outputs result1 if the page [[pagetitle]] exists, otherwise outputs result2.
{{#switch:string |c1=r1 |c2=r2 ... |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|}}}, {{{2|}}}, etc, rather than {{{1}}}, {{{2}}}, etc).

Other[edit]

{{#babel:code1|code2|...}} {{Babel}} template replacement (see Extension:Babel).
{{#coordinates:arg1|arg2|...}} GeoData coordinates function (see Extension:GeoData).
{{#invoke:mod|func |arg1 |arg2 |...}} Calls the function func within the Scribunto module mod. (See Wikipedia:Lua.)
{{#language:code1|code2}} Outputs the name of the language identified by the language code code1 in the language identified by code2. If code2 is not supplied, the name of the language identified by code1 will be output in that language. For example, "{{#language:ar}}" outputs "العربية" while "{{#language:ar|en}}" and "{{#language:ar|fr}}" output, respectively, "Arabic" and "arabe". (See mw:Help:Magic words#Miscellaneous.)
{{#property:arg1|arg2|...}} (See m:Wikidata/Notes/Inclusion syntax v0.3.)
{{#target:noticeboard}} MassMessage function (see m:MassMessage and mw:Help:Extension:MassMessage).
{{int:messagename}} Transcludes a page (such as a system message) in MediaWiki namespace according to the user's language preferences.

See also[edit]