Help:Magic words: Difference between revisions
m (Text replacement - "Category:Help" to "Category:HelpCategory:Help under review") Tag: Reverted |
m (Text replacement - "Category:HelpCategory:Help under review" to "Category:Help") Tag: Manual revert |
||
Line 291: | Line 291: | ||
__NEWSECTIONLINK__ | __NEWSECTIONLINK__ | ||
[[Category:Help | [[Category:Help]] |
Latest revision as of 23:12, 7 October 2024
Please remember to use enhanced editor when adding these magic words. If you use VisualEditor, it will not work as noinclude is added around the text. |
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:
- MediaWiki's Magic Words for all standard magic words, including the "standard" parser functions
- MediaWiki's Parser Functions 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. __NOTOC__, or keywords using parser function syntax
- Variables: uppercase words surrounded by double braces, e.g. {{PAGENAME}} (thus resembling templates)
- Parser functions: keywords (some beginning #) in double braces with parameters after a colon, e.g. {{#expr:2+2}}
Behavior switches
Please remember to use enhanced editor when adding these magic words. If you use VisualEditor, it will not work as noinclude is added around the text. For further documentation, refer to the Behavior Switches section of the MediaWiki page.
- __NOTOC__ (can appear anywhere in the wikitext; suppresses the table of contents)
- __FORCETOC__ (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
- __TOC__ (places a table of contents at the word's position)
- __NOEDITSECTION__ (hides the section "edit" links beside all headings on the page) (use <h2> tags to hide the edit link for one header only)
- __NEWSECTIONLINK__ (adds a "+" link for adding a new section on a non-"Talk" page)
- __NONEWSECTIONLINK__ (removes the "+" link on "Talk" pages)
- __NOGALLERY__ (on a category page, replaces thumbnails with normal links)
- __HIDDENCAT__ (on a category page, makes it a hidden category)
- __INDEX__ (tells search engines to index the page)
- __NOINDEX__ (tells search engines not to index the page)
- {{DISPLAYTITLE:title}} (changes the displayed form of the page title)
- {{DEFAULTSORT:sortkey}} (sets a default category sort key)
Variables
Date and time
The following variables return the current date and time in Time zone Coordinated Universal Time (UTC).
Due to MediaWiki and browser caching, these variables frequently show when the page was cached rather than the current time.
The use of those variables cause pages to be cached for a more limited number of seconds. This is configured in MagicWordFactory.
Variable | Output | Description |
---|---|---|
Year | ||
{{CURRENTYEAR}}
|
2025 | Year |
Month | ||
{{CURRENTMONTH}}
|
01 | Month (zero-padded number) |
{{CURRENTMONTH1}}
|
1 | Month (unpadded number) |
{{CURRENTMONTHNAME}}
|
January | Month (name) |
{{CURRENTMONTHNAMEGEN}}
|
January | Month (genitive form) |
{{CURRENTMONTHABBREV}}
|
Jan | Month (abbreviation) |
Day | ||
{{CURRENTDAY}}
|
23 | Day of the month (unpadded number) |
{{CURRENTDAY2}}
|
23 | Day of the month (zero-padded number) |
{{CURRENTDOW}}
|
4 | Day of the week (unpadded number), 0 (for Sunday) through 6 (for Saturday) |
{{CURRENTDAYNAME}}
|
Thursday | Day of the week (name) |
Time | ||
{{CURRENTTIME}}
|
09:28 | Time (24-hour HH:mm format) |
{{CURRENTHOUR}}
|
09 | Hour (24-hour zero-padded number) |
Other | ||
{{CURRENTWEEK}}
|
4 | Week (number) |
{{CURRENTTIMESTAMP}}
|
20250123092840 |
YYYYMMDDHHmmss timestamp |
The following variables do the same as the preceding ones, but using the site's server config or $wgLocaltimezone.
{{LOCALYEAR}}
- {{LOCALMONTH}}
- {{LOCALMONTH1}}
- {{LOCALMONTHNAME}}
- {{LOCALMONTHNAMEGEN}}
- {{LOCALMONTHABBREV}}
- {{LOCALDAY}}
- {{LOCALDAY2}}
- {{LOCALDOW}}
- {{LOCALDAYNAME}}
- {{LOCALTIME}}
- {{LOCALHOUR}}
- {{LOCALWEEK}}
{{LOCALTIMESTAMP}}
For more thorough time formatting, or to output the current year and week with better compliance with ISO-8601, you may want to install Extension:ParserFunctions to use the [[mediawikiwiki:Help:Extension:ParserFunctions#
Parser functions
URL data
Parser function |
Input → Output |
Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
{{localurl:page name}}
|
{{localurl:MediaWiki}} → /wiki/MediaWiki {{localurl:MediaWiki|printable=yes}} → /w/index.php?title=MediaWiki&printable=yes |
The relative path to the title. | ||||||||||
{{fullurl:page name}}
|
{{fullurl:Category:Top level}} → https://saintapedia.org/wiki/Category:Top_level
|
A protocol-relative path to the title. This will also resolve Interwiki prefixes. Note: Unbracketed (plain) protocol-relative links are not automagically linked. | ||||||||||
{{canonicalurl:page name}}
|
{{canonicalurl:Category:Top level}} → https://saintapedia.org/wiki/Category:Top_level
|
The absolute path to the title, using the canonical URL. This will also resolve interwiki prefixes. | ||||||||||
{{filepath:file name}}
|
{{filepath:Wiki.png}} →
|
A protocol-relative path to the full size or thumbnail of a media file. | ||||||||||
{{urlencode:string}} or
|
{{urlencode:x:y/z á é}} or {{urlencode:x:y/z á é|QUERY}} → x%3Ay%2Fz+%C3%A1+%C3%A9 {{urlencode:x:y/z á é|WIKI}} → x:y/z_%C3%A1_%C3%A9 {{urlencode:x:y/z á é|PATH}} → x%3Ay%2Fz%20%C3%A1%20%C3%A9 Note that the default changed from <tvar|wiki> |
The input encoded for use in URLs. Note that there is no urldecode function like there is in the obsolete Extension:StringFunctions.
| ||||||||||
{{anchorencode:string}}
|
{{anchorencode:x y z á é}} → x_y_z_á_é |
The input encoded for use in URL section anchors (after the “#” symbol in a URL). |
Full url
When linking to diffs, logs, etc., please use the {{fullurl}} parser function. Including the entire URL may cause users to switch between the secure and insecure servers, and the diffs of the page it is included in to widen the page substantially.
Examples
[{{fullurl:{{FULLPAGENAME}}|action=edit}}]
- Links to edit this page: [1]
[{{fullurl:Special:Log|type=block&page=User:Jimbo_Wales}}]
- Links to Jimbo's block log. [2]
[{{fullurl:{{FULLPAGENAME}}|oldid={{REVISIONID}}&diff=prev}}]
- Link to the last edit of this page. [3]
This can be used as any URL, with text, or as a bare URL, in addition to as a [N] link as shown above.
Technical metadata of another page
Parser function | Output (for page MediaWiki) |
Description |
---|---|---|
{{REVISIONID: page name }}
|
1721 | [ Expensive] Unique revision ID of the last revision on the specified page*. |
{{REVISIONDAY: page name }}
|
5 | [ Expensive] Day of edit from the last revision of the specified page* (unpadded number). |
{{REVISIONDAY2: page name }}
|
05 | [ Expensive] Day of edit from the last revision of the specified page* (zero-padded number). |
{{REVISIONMONTH: page name }}
|
09 | [ Expensive] Month of edit from the last revision specified page* (zero-padded number as <tvar |1>1.17+</>, unpadded number in prior versions). |
{{REVISIONMONTH1: page name }}
|
9 | [ Expensive] Month of edit from the last revision of the specified page* (unpadded number). |
{{REVISIONYEAR: page name }}
|
2024 | [ Expensive] Year of edit from the last revision of the specified page*. |
{{REVISIONUSER: page name }}
|
Tom | [ Expensive] The username from the last revision on the specified page*. |
|
External links
The most comprehensive resource for information on MediaWiki's "Magic words" can be found on:
- Wikipedia at Help:Magic_words and
- MediaWiki's Help:Magic words article
- Wikipedia:WikiProject Time