Help:Magic words
From Wikipedia, the free encyclopedia
This is a copy of the master help page at Meta. Do not edit this copy.
Edits will be lost in the next update from the master page. See below for more information.
This is an organised index of Magic words used in MediaWiki.
A "magic word" is a symbol which is recognized by the MediaWiki software and which when seen in the non-commented text of the page, triggers the software to do something other than display that symbol, or transclude a page with that name, but instead to use the symbol directly. A magic word can be:
- an upper case word, preceded and followed by two underlines "__", e.g. __NOTOC__
- an XML object, coded similar to HTML, preceded by "<" and followed by ">", e.g. <nowiki>
- a parser function: similar to a template, a word preceded by the symbols "{{" and followed by "}}", and optionally parameter definitions between pipe characters, except that the part before the first pipe (or without pipes, the text between the braces) contains a colon (":"), e.g. {{ns:3}} and {{#ifexpr:{{{1}}}>3|large|small}}
- a variable: similar to a template without parameters, a word preceded by the symbols "{{" and followed by "}}", except the word used is in all upper case, e.g. {{CURRENTDAY}}
- a template modifier
- an image modifier
If a page in the template namespace has the same name as a magic word, the magic word will be invoked instead. If you discover you absolutely have to define a template with the same name as a magic word, prefix the name of the template with "msg:" or the name of the template namespace ("Template:"). See below for further details if you need this feature.
Tags which are used on this page such as "[MW1.5+]" indicate the version that first supported the magic word. "XYZ" indicates user input, which is used in the example.
Contents |
Magic words between double underscores
Table of contents
- For details see Help:Section
Word | Explanation |
---|---|
__NOTOC__ | Hides ToC on the current page. |
__FORCETOC__ | Forces the table of contents to appear. |
__TOC__ | Places a ToC here (overriding any __NOTOC__). |
Other
Word | Explanation |
---|---|
__NOEDITSECTION__ | Hides the edit links beside headings. |
__NEWSECTIONLINK__ | [MW1.7+] Gives a "+"-link next to the edit-tab to make a new section on a non-talk page. |
__NOCONTENTCONVERT__ __NOCC__ |
Don't perform the content language conversion (character and phase) in article display; for example, Chinese zh with zh_cn, zh_tw, zh_sg, zh_hk. |
__NOGALLERY__ | [MW1.7+] This magic word allows images in category pages to be displayed as inline links instead of gallery. |
__NOTITLECONVERT__ __NOTC__ |
Like __NOCC__ but affecting article title only. |
__END__ | Allows for trailing whitespace to be included in the page save (does not seem to work anymore). |
__START__ | This magic word has no effect but an ID in MagicWord.php (MAG_START ). |
Variables
- For details see Help:Variable
Time
The time in UTC. Note that if the page was displayed by the same user and has not changed (has not been edited) since the last time it was displayed, it is possible that the page may be cached (by the user's browser) and the displayed time or date may not change. Also, if a heavily used page, rather than freshly rendered by the software each time it is generated, is instead being retrieved from a caching system (such as the main page on Wikipedia) the date or time may not change from the last time the page was originally retrieved by the caching hardware or software.
Word | Example | Explanation |
---|---|---|
{{CURRENTDAY}} | 1 |
Displays the current day in numeric form. |
{{CURRENTDAY2}} | 01 |
[MW1.6+] Same as {{CURRENTDAY}}, but with leading zero (01 .. 31). |
{{CURRENTDAYNAME}} | Sunday |
Name of the day in the language of the project or English. |
{{CURRENTDOW}} | 0 |
Same as {{CURRENTDAYNAME}}, but as a number (0=Sunday, 1=Monday...). |
{{CURRENTMONTH}} | 04 |
The number 01 .. 12 of the month. |
{{CURRENTMONTHABBREV}} | Apr |
[MW1.5+] Same as {{CURRENTMONTH}}, but in abbreviated form as Jan .. Dec. |
{{CURRENTMONTHNAME}} | April |
Same as {{CURRENTMONTH}}, but in named form January .. December. |
{{CURRENTTIME}} | 07:30 |
The current time (00:00 .. 23:59). |
{{CURRENTHOUR}} | 07 |
The current hour (00 .. 23). |
{{CURRENTMINUTE}} | 25 |
The current minute (00 .. 59). |
{{CURRENTWEEK}} | 13 |
Number of the current week (1-53) according to ISO 8601 with no leading zero. |
{{CURRENTYEAR}} | 2007 |
Returns the current year. |
{{CURRENTTIMESTAMP}} | 20070401080414 |
[MW1.7+] ISO 8601 time stamp. |
Local time
The time depending on the local timezone of the wiki (not depending on the timezone in the user's preference settings). (All words [MW1.8+] )
Word | Example | Explanation |
---|---|---|
{{LOCALDAY}} | 1 |
Displays the local day of the month in numeric form. |
{{LOCALDAY2}} | 01 |
Same as {{LOCALDAY}}, but with a leading zero (01 .. 31). |
{{LOCALDAYNAME}} | Sunday |
Name of the day in the language of the project or English. |
{{LOCALDOW}} | 0 |
Same as {{LOCALDAYNAME}}, but as a number (0=Sunday, 1=Monday...). |
{{LOCALMONTH}} | 04 |
The number 01 .. 12 of the month. |
{{LOCALMONTHABBREV}} | Apr |
Same as {{LOCALMONTH}}, but in abbreviated form as Jan .. Dec. |
{{LOCALMONTHNAME}} | April |
Same as {{LOCALMONTH}}, but in named form as January .. December. |
{{LOCALTIME}} | 08:04 |
The local time (00:00 .. 23:59). |
{{LOCALHOUR}} | 08 |
The local hour (00 .. 23). |
{{LOCALWEEK}} | 13 |
Number of the local week (1-53) according to ISO 8601 with no leading zero. |
{{LOCALYEAR}} | 2007 |
Returns the local year. |
{{LOCALTIMESTAMP}} | 20070401080414 |
ISO 8601 time stamp. |
- See also the ParserFunction #time:
Statistics
Statistics variables give thousands separators unless ":R" for "raw" is added (actually, these versions are parser functions).
Word | Example | Explanation |
---|---|---|
{{CURRENTVERSION}} | 1.10alpha (r20145) |
[MW1.7+] $wgVersion [1] |
{{NUMBEROFARTICLES}} {{NUMBEROFARTICLES:R}} |
1,715,442 1715463 |
A variable which returns the total number of articles on the Wiki. |
{{NUMBEROFPAGES}} {{NUMBEROFPAGES:R}} |
8,225,026 8225026 |
[MW1.7+] Returns the total number of pages. [2] |
{{NUMBEROFFILES}} {{NUMBEROFFILES:R}} |
745,646 745646 |
[MW1.5+] Returns the number of uploaded files (rows in the image table). |
{{NUMBEROFUSERS}} {{NUMBEROFUSERS:R}} |
3,999,981 3999981 |
[MW1.7+] Returns the number of registered users (rows in the user table). |
{{NUMBEROFADMINS}} {{NUMBEROFADMINS:R}} |
1,161 1161 |
[MW1.7+] Returns the number of administrators (sysop, bureaucrat, steward and checkuser). |
{{PAGESINNAMESPACE}} | disabled here | Longer alias of PAGESINNS |
{{PAGESINNS:ns}} {{PAGESINNS:ns:R}} |
{{PAGESINNS:2}} {{PAGESINNS:2:R}} disabled here |
[MW1.7+] Returns the number of pages in the given namespace. Disabled by default, enable with $wgAllowSlowParserFunctions. |
Page names and related info
Word | Example | Explanation |
---|---|---|
{{PAGENAME}} | Magic words |
Returns the name of the current page, including all levels (Title/Subtitle). |
{{PAGENAMEE}} | Magic_words |
More URL-friendly percent encoded special characters (To use an articlename in an external link). |
{{SUBPAGENAME}} {{SUBPAGENAMEE}} |
Magic words |
[MW1.6+] Name of the current page, excluding parent pages ("Subtitle" on "Title/Other/Subtitle") in namespaces supporting subpages, see Help:Link. |
{{BASEPAGENAME}} {{BASEPAGENAMEE}} |
Magic words |
[MW1.7+] The basename of a subpage ("Title/Other" on "Title/Other/Subtitle"), see Help:Link. |
{{NAMESPACE}} {{NAMESPACEE}} |
Help |
Returns the name of the namespace the current page resides in. |
{{FULLPAGENAME}} {{FULLPAGENAMEE}} |
Help:Magic words |
[MW1.6+] Shorthands for NAMESPACE+PAGENAME |
{{TALKSPACE}} {{TALKSPACEE}} |
Help talk |
[MW1.7+] Name of next odd namespace (e.g. 4 => 5) |
{{SUBJECTSPACE}} {{SUBJECTSPACEE}} |
Help |
[MW1.7+] Name of last even namespace (e.g. 5 => 4) |
{{ARTICLESPACE}} {{ARTICLESPACEE}} |
Help |
[MW1.7+] An alias for SUBJECTSPACE(E) |
{{TALKPAGENAME}} {{TALKPAGENAMEE}} |
Help talk:Magic words |
[MW1.7+] FULLPAGENAME in its TALKSPACE |
{{SUBJECTPAGENAME}} {{SUBJECTPAGENAMEE}} |
Help:Magic words |
[MW1.7+] FULLPAGENAME in its SUBJECTSPACE |
{{ARTICLEPAGENAME}} {{ARTICLEPAGENAMEE}} |
Help:Magic words |
[MW1.7+] An alias for SUBJECTPAGENAME(E) |
{{REVISIONID}} | 110064065 |
[MW1.5+] The unique identifying number of a page, see Help:Diff. Note that when editing a page, this value is null. |
{{REVISIONDAY}} | 22 |
[MW1.8+] The day on which the page was last modified. |
{{REVISIONDAY2}} | 22 |
[MW1.8+] The day on which the page was last modified, but with a leading zero (01 .. 31). |
{{REVISIONMONTH}} | 2 |
[MW1.8+] The month in which the page was last modified. |
{{REVISIONYEAR}} | 2007 |
[MW1.8+] The year in which the page was last modified. |
{{REVISIONTIMESTAMP}} | 20070222135343 |
[MW1.8+] ISO 8601 time stamp, indicating when the page was last modified. |
{{SITENAME}} | Wikipedia |
Value of $wgSitename. |
{{SERVER}} | http://en.wikipedia.org | Value of $wgServer |
{{SCRIPTPATH}} | /w |
[MW1.5+] $wgScriptPath |
{{SERVERNAME}} | srv42 |
[MW1.5+] $wgServerName |
Parser functions
- For details see Help:Parser function.
Namespaces and URLs
Word | Example | Explanation |
---|---|---|
{{ns:}} | {{ns:4}} = Wikipedia {{ns:project}} = Wikipedia |
Returns the name of a given namespace number. |
{{localurl:x y @}} {{localurle:x y @}} {{localurl:a|b=c}} |
../../../x/_/y/X_y_%40.html |
Returns the local URL of a page (might not exist). Optional query parameter, see Help:Variable. |
{{urlencode:x y @}} | x+y+%40 |
[MW1.7+] Encodes variable values for use in external links. [3] |
{{anchorencode:x #y @}} | x_.23y_.40 |
[MW1.8+] Encodes variable values for use in section anchors. [4] |
{{fullurl:x y @}} {{fullurle:x y @}} {{fullurl:m:a|b=c}} |
http://en.wikipedia.org../../../x/_/y/X_y_%40.html http://en.wikipedia.org../../../x/_/y/X_y_%40.html http://meta.wikimedia.org/wiki/a?b=c |
[MW1.5+] Returns the full URL of a given page. Optional query parameter as for localurl:. |
Formatting
Word | Example | Explanation |
---|---|---|
{{#language:}} | {{#language:da}} = Dansk |
[MW1.7+] Native name of language code. |
{{lc:}} | {{lc:AbC dEf}} = abc def |
[MW1.5+] LowerCase |
{{lcfirst:}} | {{lcfirst:Ab Cd}} = ab Cd |
[MW1.5+] LC first char. |
{{uc:}} | {{uc:aBc DeF}} = ABC DEF |
[MW1.5+] UpperCase |
{{ucfirst:}} | {{ucfirst:aB cD}} = AB cD |
[MW1.5+] UC first char. |
{{formatnum:}} | {{formatnum:-299792458.56789}} = -299,792,458.56789 |
[MW1.7+] Add decimal separators according to the wiki's default locale. Leading minus and plus are recognized. |
{{padleft:}} {{padright:}} |
{{padleft:bcd|6|a}} = aaabcd {{padleft:café|6|-}}=-café {{padright:bcd|6|a}} = bcdaaa |
[MW1.8+] Pads a string with a character to the specified width. |
A letter like é counts for two. It does not seem possible to use padleft and padright for padding with characters with a multi-character code, such as , which would be useful with padleft for sorting tables with Javascript.
Template modifiers
Usage | Explanation |
---|---|
{{:xyz}} | A bare colon is not a template modifier, it's the prefix for the main namespace. Test e.g. article {{:UTC}} vs. template {{UTC}}. Using this syntax you include the text of the main namespace article xyz in another article. |
{{int:xyz}} | Shorthand for {{MediaWiki:xyz}}, rendered as <xyz> if MediaWiki:xyz doesn't exist. See Help:MediaWiki namespace. |
{{msg:xyz}} | Even if there is a magic word named "xyz", use template:xyz unless the template doesn't exist (equivalent to {{template:xyz}}). Normally, magic words have priority when there is a conflict. |
{{msgnw:xyz}} | The unevaluated wikitext is rendered. See msgnw. |
{{raw:xyz}} | [MW1.6+] Equivalent to {{msg:xyz}} above[1]. |
{{subst:xyz}} | In the wikitext, the tag is substituted by the content (single-level evaluation only), see Help:Substitution. |
Image modifiers
- For details see w:en:Wikipedia:Extended image syntax.
These are image modifiers used in [[Image:title.ext|modifier|...|modifier]]
links. Some are mutually exclusive, and then the last specified wins.
Size
The last unrecognized modifier is used as caption for framed images or together with thumbnails. It's also used as description alt=text.
Word | Usage | Explanation |
---|---|---|
framed frame enframed |
[[Image:Mediawiki.png|framed]] | Places an image in a frame with a description. Uses original size. |
thumbnail thumb |
[[Image:Mediawiki.png|thumbnail]] | Modifies image size, sets it to dependant on user's favourite thumbnail size in their preferences. |
thumb=xyz | [[Image:Mediawiki.png|thumb=Wiki.png]] | Manualthumb: instead of displaying an automatically-sized thumbnail for Mediawiki.png, display the image Wiki.png. |
width px | [[Image:Mediawiki.png|40px]] | Scales image to given width in pixels |
Position
- For details see Help:Images_and_other_uploaded_files
The positions are mutually exclusive; the last specified wins. Template:- can stop floating. For inline images only modifier px (see above) is supported.
Word | Usage | Explanation |
---|---|---|
right | [[Image:Mediawiki.png|right]] | Modifies position, floats the image to the right. |
left | [[Image:Mediawiki.png|left]] | Modifies position, floats the image to the left. |
none | [[Image:Mediawiki.png|none]] | Explicitly states that the image should not float. |
center centre |
[[Image:Mediawiki.png|center]] | Modifies position, like none but centered. |
Miscellany
Word | Example | Explanation |
---|---|---|
{{DISPLAYTITLE:xyz}} | default disabled | [MW 1.7+] Set the page's title [5], see $wgAllowDisplayTitle. |
{{DIRMARK}} {{DIRECTIONMARK}} |
|
[MW1.7+] u+200E left to right or u+200D right to left mark |
{{CONTENTLANGUAGE}} | en |
[MW1.7+] code of the site's default interface language ($wgLanguageCode) |
{{DEFAULTSORT:xyz}} | [MW1.10+] Sets a default category sort key for the current page[2]. | |
#REDIRECT | #REDIRECT [[target]] at top of source page |
Creates a redirect to another page. |
Language-dependent word conversions
Word | Example | Explanation |
---|---|---|
{{ CURRENTMONTHNAMEGEN }} | April |
Genitive form of month name used for Czech, Polish, Ukrainian[6] |
{{grammar:case | word }} | {{grammar:7sg|Wikipedie}} on cs: is Wikipedií . |
Derived word forms in inflected languages like Czech [7] |
{{plural:count |form1 |form2 }} {{plural:count |1st | 2nd | 3rd }} |
{{plural: 2 | is | are }} outputs are {{plural: 0 | this | these }} outputs these |
count 1 yields form1 (singular), plural transformations are used for languages like Russian [8] based on "count mod 10". |
"Grammar" and "Plural" are language-dependent functions, defined in [9], [10], etc. (note that in PHP, the modulo operator is the percent sign).
"Grammar" can either be applied to predefined words only, or to arbitrary words, depending on whether the definition is just a 2D array, or involves string manipulations. See also cs:Šablona:Wikivar/GRAMMAR.
"Plural" is a project-dependent switch function, e.g. giving the first text if count = 1, the second if count = 2,3, or 4, and else the third. See also mediazilla:5805 for the use of "plural" in system messages.
See also
- ParserFunctions #expr:, #if:, #ifeq:, etc.
- mw:Manual:Magic words
- Source for Language.php
- Source for MagicWord.php
- Adding parser functions
References
- ^ Wikimedia SVN revision 12925
- ^ "Technology report", en-Wikipedia Signpost, January 2007
edit |
Wikipedia-specific help
There are no known magic words working only for Wikipedia, or working on Meta but not here at the moment.
This page is a copy of the master help page at Meta (for general help information all Wikimedia projects can use), with two Wikipedia-specific templates inserted. To update the main text, edit the master help page for all projects at m:Help:Magic words. For Wikipedia-specific issues, use Template:Ph:Magic words (the extra text at the bottom of this page) or Template:Phh:Magic words for a Wikipedia-specific lead (text appears at the top of this page). You are welcome to copy the exact wikitext from the master page at Meta and paste it into this page at any time. To view this page in other languages see the master page at Meta.