Difference between revisions of "Help:Magic Words"

MyWikiBiz, Author Your Legacy — Friday November 15, 2024
Jump to navigationJump to search
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This is an organised index of Magic words used in MediaWiki. Tags such as "'''[MW1.5+]'''" indicate the version that first supported the magic word. "XYZ" indicates user input, which is used in the example.
+
{{Help contents back}}
 +
----
 +
This is an organized index of Magic words used in MediaWiki.
  
== Table of contents ==
+
A "'''[[Magic (programming)|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:
:''For details see [[Help:Section]]''  
+
*an upper case word, preceded and followed by two underscores, e.g. '''<nowiki>__NOTOC__</nowiki>'''  
{| class="wikitable" border="2" cellpadding="4" cellspacing="0" width="79%"
+
*an XML object, coded similar to HTML, preceded by "<" (and for the end tag "/") and followed by ">", as in '''&lt;nowiki>'''...'''&lt;/nowiki>'''
! Word
+
*a [[help:parser function|parser function]]: similar to a template, a word preceded by the symbols "'''<nowiki>{{</nowiki>'''" and followed by "'''<nowiki>}}</nowiki>'''", 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. <nowiki>{{</nowiki>'''ns:'''3}} and {{'''#ifexpr:'''<nowiki>{{{1}}}>3|large|small}}</nowiki>
! Explanation
+
*a [[help:variable|variable]]: similar to a template without parameters, a word preceded by the symbols "'''<nowiki>{{</nowiki>'''" and followed by "'''<nowiki>}}</nowiki>'''", except the word used is in all upper case, e.g. '''<nowiki>{{CURRENTDAY}}</nowiki>''' 
|-
+
*a template modifier
| <nowiki>__NOTOC__</nowiki>
+
*an image modifier
| Hides ToC on the current page.
+
 
|-
+
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.
|<nowiki>__FORCETOC__</nowiki>
+
 
| Forces the table of contents to appear.
+
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.
|-
+
 
| <nowiki>__TOC__</nowiki>
+
==Magic words between double underscores==
| Places a ToC here (overriding any <nowiki>__NOTOC__</nowiki>).
 
|}<br clear="left" />
 
  
=== More magic ===
 
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0" width="79%"
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0" width="79%"
 
! Word  
 
! Word  
Line 38: Line 37:
 
|-
 
|-
 
| <nowiki>__END__</nowiki>
 
| <nowiki>__END__</nowiki>
| Allows for trailing whitespace to be included in the page save.
+
| Allows for trailing whitespace to be included in the page save (does not seem to work anymore).
 
|-
 
|-
 
| <nowiki>__START__</nowiki>
 
| <nowiki>__START__</nowiki>
 
| This magic word has no effect but an ID in <tt>MagicWord.php</tt> (<code>MAG_START</code>).
 
| This magic word has no effect but an ID in <tt>MagicWord.php</tt> (<code>MAG_START</code>).
 
|}<br clear="left" />
 
|}<br clear="left" />
 +
 +
==XML-style tags==
 +
'''nowiki''': &lt;nowiki>'''...'''&lt;/nowiki>, disables expansion/interpretation of templates, link syntax, formatting syntax, etc.: <nowiki>&lt;nowiki>'''[[{{tc}}]]'''&lt;/nowiki></nowiki> gives <nowiki>'''[[{{tc}}]]'''</nowiki>
 +
'''pre''': &lt;pre>'''...'''&lt;/pre>, ditto, also for multiple lines; it is rendered with a new paragraph at the start and end: a&lt;pre><nowiki>'''[[{{tc}}]]'''</nowiki>&lt;/pre>b gives a<pre>'''[[{{tc}}]]'''</pre>b
 +
'''math''': &lt;math>'''...'''&lt;/math>, e.g. <nowiki><math>\sqrt{a^2+b^2}</math></nowiki> gives <math>\sqrt{a^2+b^2}</math>; see [[Help:Displaying a formula]]
 +
<br>
 +
'''hiero''': &lt;hiero>'''...'''&lt;/hiero>, e.g. <nowiki><hiero>A1</hiero></nowiki> gives: <hiero>A1</hiero>
  
 
== Variables ==
 
== Variables ==
Line 48: Line 54:
  
 
===Time===  
 
===Time===  
The time in [[:en:UTC|UTC]].
+
The time in [[:en:UTC|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.
 
{| class="wikitable sortable" border="2" cellpadding="4" cellspacing="0"  
 
{| class="wikitable sortable" border="2" cellpadding="4" cellspacing="0"  
 
! Word  
 
! Word  
Line 76: Line 82:
 
| <nowiki>{{CURRENTMONTHABBREV}}</nowiki>
 
| <nowiki>{{CURRENTMONTHABBREV}}</nowiki>
 
| <code>{{CURRENTMONTHABBREV}}</code>
 
| <code>{{CURRENTMONTHABBREV}}</code>
| '''[MW1.5+]''' Same as <nowiki>{{CURRENTMONTH}}</nowiki>, but in abbreviated form as Jan .. Dec.
+
| '''[MW1.5+]''' Same as <nowiki>{{CURRENTMONTH}}</nowiki>, but in abbreviated form (Jan .. Dec).
 
|-
 
|-
 
| <nowiki>{{CURRENTMONTHNAME}}</nowiki>
 
| <nowiki>{{CURRENTMONTHNAME}}</nowiki>
 
| <code>{{CURRENTMONTHNAME}}</code>
 
| <code>{{CURRENTMONTHNAME}}</code>
| Same as <nowiki>{{CURRENTMONTH}}</nowiki>, but in named form January .. December.
+
| Same as <nowiki>{{CURRENTMONTH}}</nowiki>, but in named form (January .. December).
 
|-
 
|-
 
| <nowiki>{{CURRENTTIME}}</nowiki>
 
| <nowiki>{{CURRENTTIME}}</nowiki>
Line 104: Line 110:
  
 
===Local time===  
 
===Local time===  
The time depending on the local timezone of the wiki. (All words '''[MW1.8+]''' )
+
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+]''' )
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"  
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"  
 
! Word  
 
! Word  
Line 162: Line 168:
  
 
=== Statistics ===
 
=== Statistics ===
 +
Statistics variables give thousands separators unless ":R" for "raw" is added (actually, these versions are parser functions).
 +
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"  
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"  
 
! Word  
 
! Word  
Line 170: Line 178:
 
| <code>{{CURRENTVERSION}}</code>
 
| <code>{{CURRENTVERSION}}</code>
 
| '''[MW1.7+]''' {{h:mwg|Version}} [http://mail.wikipedia.org/pipermail/mediawiki-i18n/2006-May/000026.html]
 
| '''[MW1.7+]''' {{h:mwg|Version}} [http://mail.wikipedia.org/pipermail/mediawiki-i18n/2006-May/000026.html]
 +
|-
 +
|<nowiki>{{NUMBEROFEDITS}}</nowiki><br /><nowiki>{{NUMBEROFEDITS:R}}</nowiki>
 +
| <code>{{NUMBEROFEDITS}}</code><br /><code>{{NUMBEROFEDITS:R}}</code>
 +
| '''[MW1.10+ (r21319)]''' Returns the total number of page edits since MediaWiki, the software that runs this site, was installed.
 
|-
 
|-
 
| <nowiki>{{NUMBEROFARTICLES}}</nowiki><br /><nowiki>{{NUMBEROFARTICLES:R}}</nowiki>
 
| <nowiki>{{NUMBEROFARTICLES}}</nowiki><br /><nowiki>{{NUMBEROFARTICLES:R}}</nowiki>
Line 201: Line 213:
  
 
=== Page names and related info ===
 
=== Page names and related info ===
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"
+
{{:H:Page_name_variables}}
! Word
 
! Example
 
! Explanation
 
|-
 
| <nowiki>{{PAGENAME}}</nowiki>
 
| <code>{{PAGENAME}}</code>
 
| Returns the name of the current page, including all levels (Title/Subtitle).
 
|-
 
| <nowiki>{{PAGENAMEE}}</nowiki>
 
| <code>{{PAGENAMEE}}</code>
 
| More URL-friendly percent encoded special characters (To use an articlename in an external link).
 
|-
 
| <nowiki>{{SUBPAGENAME}}</nowiki><br /><nowiki>{{SUBPAGENAMEE}}</nowiki>
 
| <code>{{SUBPAGENAME}}<br />{{SUBPAGENAMEE}}</code>
 
| '''[MW1.6+]''' Name of the current page, excluding parent pages ("Subtitle" on "Title/Other/Subtitle") in namespaces supporting subpages, see [[Help:Link#Subpage_feature|Help:Link]].
 
|-
 
| <nowiki>{{BASEPAGENAME}}</nowiki><br ><nowiki>{{BASEPAGENAMEE}}</nowiki>
 
| <code>{{BASEPAGENAME}}<br />{{BASEPAGENAMEE}}</code>
 
| '''[MW1.7+]''' The basename of a subpage ("Title/Other" on "Title/Other/Subtitle"), see [[Help:Link#Subpage_feature|Help:Link]].
 
|-
 
| <nowiki>{{NAMESPACE}}</nowiki><br /><nowiki>{{NAMESPACEE}}</nowiki>
 
| <code>{{NAMESPACE}}<br />{{NAMESPACEE}}</code>
 
| Returns the name of the namespace the current page resides in.
 
|-
 
| <nowiki>{{FULLPAGENAME}}</nowiki><br ><nowiki>{{FULLPAGENAMEE}}</nowiki>
 
| <code>{{FULLPAGENAME}}<br />{{FULLPAGENAMEE}}</code>
 
| '''[MW1.6+]''' Shorthands for NAMESPACE+PAGENAME
 
|-
 
| <nowiki>{{TALKSPACE}}</nowiki><br ><nowiki>{{TALKSPACEE}}</nowiki>
 
| <code>{{TALKSPACE}}<br />{{TALKSPACEE}}</code>
 
| '''[MW1.7+]''' Name of next odd namespace (e.g. 4 =&gt; 5) 
 
|-
 
| <nowiki>{{SUBJECTSPACE}}</nowiki><br ><nowiki>{{SUBJECTSPACEE}}</nowiki>
 
| <code>{{SUBJECTSPACE}}<br />{{SUBJECTSPACEE}}</code>
 
| '''[MW1.7+]''' Name of last even namespace (e.g. 5 =&gt; 4)
 
|-
 
| <nowiki>{{ARTICLESPACE}}</nowiki><br ><nowiki>{{ARTICLESPACEE}}</nowiki>
 
| <code>{{ARTICLESPACE}}<br />{{ARTICLESPACEE}}</code>
 
| '''[MW1.7+]''' An alias for SUBJECTSPACE(E)
 
|-
 
| <nowiki>{{TALKPAGENAME}}</nowiki><br ><nowiki>{{TALKPAGENAMEE}}</nowiki>
 
| <code>{{TALKPAGENAME}}<br />{{TALKPAGENAMEE}}</code>
 
| '''[MW1.7+]''' FULLPAGENAME in its TALKSPACE
 
|-
 
| <nowiki>{{SUBJECTPAGENAME}}</nowiki><br ><nowiki>{{SUBJECTPAGENAMEE}}</nowiki>
 
| <code>{{SUBJECTPAGENAME}}<br />{{SUBJECTPAGENAMEE}}</code>
 
| '''[MW1.7+]''' FULLPAGENAME in its SUBJECTSPACE
 
|-
 
| <nowiki>{{ARTICLEPAGENAME}}</nowiki><br ><nowiki>{{ARTICLEPAGENAMEE}}</nowiki>
 
| <code>{{ARTICLEPAGENAME}}<br />{{ARTICLEPAGENAMEE}}</code>
 
| '''[MW1.7+]''' An alias for SUBJECTPAGENAME(E)
 
|-
 
| <nowiki>{{REVISIONID}}</nowiki>
 
| <code>{{REVISIONID}}</code>
 
| '''[MW1.5+]''' The unique identifying number of a page, see [[Help:Diff]].
 
|-
 
| <nowiki>{{REVISIONDAY}}</nowiki>
 
| <code>{{REVISIONDAY}}</code>
 
| '''[MW1.8+]''' The day on which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONDAY2}}</nowiki>
 
| <code>{{REVISIONDAY2}}</code>
 
| '''[MW1.8+]''' The day on which the page was last modified, but with a leading zero (01 .. 31).
 
|-
 
| <nowiki>{{REVISIONMONTH}}</nowiki>
 
| <code>{{REVISIONMONTH}}</code>
 
| '''[MW1.8+]''' The month in which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONYEAR}}</nowiki>
 
| <code>{{REVISIONYEAR}}</code>
 
| '''[MW1.8+]''' The year in which the page was last modified.
 
|-
 
| <nowiki>{{REVISIONTIMESTAMP}}</nowiki>
 
| <code>{{REVISIONTIMESTAMP}}</code>
 
| '''[MW1.8+]''' [[w:ISO 8601|ISO 8601]] time stamp, indicating when the page was last modified.
 
|-
 
| <nowiki>{{SITENAME}}</nowiki>
 
| <code>{{SITENAME}}</code>
 
| Value of {{h:mwg|Sitename}}.
 
|-
 
| <nowiki>{{SERVER}}</nowiki>
 
| <small>{{SERVER}}</small>
 
| Value of {{h:mwg|Server}} 
 
|-
 
| <nowiki>{{SCRIPTPATH}}</nowiki>
 
| <code>{{SCRIPTPATH}}</code>
 
| '''[MW1.5+]''' {{h:mwg|ScriptPath}}
 
|-
 
| <nowiki>{{SERVERNAME}}</nowiki>
 
| <code>{{SERVERNAME}}</code>
 
| '''[MW1.5+]''' {{h:mwg|ServerName}}
 
|-
 
|}{{-}}
 
  
 
==Parser functions==
 
==Parser functions==
  
 
:''For details see [[Help:Parser function]].''
 
:''For details see [[Help:Parser function]].''
 +
 +
Not working at the position of the page where the tag is located but on the page header, and throughout the page, respectively (see below):
 +
*DISPLAYTITLE: allow the page header to be different from the page name.
 +
*DEFAULTSORT: Sets a default [[Help:Categories#Sort_key|category sort key]] for the page.
  
 
=== Namespaces and URLs ===
 
=== Namespaces and URLs ===
Line 310: Line 233:
 
| Returns the name of a given [[Help:Namespace|namespace number]].
 
| Returns the name of a given [[Help:Namespace|namespace number]].
 
|-
 
|-
| <nowiki>{{localurl:x y @}}</nowiki><br /><nowiki>{{localurle:x y @}}</nowiki><br /><nowiki>{{localurl:a|b=c}}</nowiki>
+
| <nowiki>{{localurl:x y @}}</nowiki><br /><nowiki>{{localurle:x y @}}</nowiki><br /><nowiki>{{localurl:a|b=c}}</nowiki><br /><nowiki>{{localurl:Wikipedia:Category}}</nowiki>
| <code>{{localurl:x y @}}<br />{{localurle:x y @}}<br />{{localurl:a|b=c}}</code>
+
| <code>{{localurl:x y @}}<br />{{localurle:x y @}}<br />{{localurl:a|b=c}}<br />{{localurl:Wikipedia:Category}}</code>
 
| Returns the local URL of a page (might not exist). Optional ''query'' parameter, see [[Help:Variable]].
 
| Returns the local URL of a page (might not exist). Optional ''query'' parameter, see [[Help:Variable]].
 
|- <!-- intentionally nbsp instead of sp for formatting reasons -->
 
|- <!-- intentionally nbsp instead of sp for formatting reasons -->
Line 357: Line 280:
 
| '''[MW1.7+]''' Add [[w:Decimal_separator#Thousands_separator|decimal separators]] according to the wiki's default locale. Leading minus and plus are recognized.
 
| '''[MW1.7+]''' Add [[w:Decimal_separator#Thousands_separator|decimal separators]] according to the wiki's default locale. Leading minus and plus are recognized.
 
|-
 
|-
| <nowiki>{{padleft:}}</nowiki><br /><nowiki>{{padright:}}</nowiki>
+
|<nowiki>{{padleft:}}</nowiki><br /><br /><br /><br /><br /><nowiki>{{padright:}}</nowiki><br />
| <nowiki>{{padleft:bcd|6|a}}</nowiki> = <code>{{padleft:bcd|6|a}}</code><br /><nowiki>{{padleft:café|6|-}}</nowiki>={{padleft:café|6|-}}<br /><nowiki>{{padright:bcd|6|a}}</nowiki> = <code>{{padright:bcd|6|a}}</code>
+
|  
| '''[MW1.8+]''' Pads a string with a character to the specified width.
+
<nowiki>{{padleft:7|3|0}}</nowiki> = <code>{{padleft:7|3|0}}</code><br/><br/>
 +
<nowiki>{{padleft:0|3|0}}</nowiki> = <code>{{padleft:0|3|0}}</code> (bug)<br/><br/>
 +
<nowiki>{{padleft:bcd|6|a}}</nowiki> = <code>{{padleft:bcd|6|a}}</code><br/>
 +
<nowiki>{{padleft:café|8|-}}</nowiki> = <code>{{padleft:café|8|-}}</code>(<==Bug effect)<br />
 +
<nowiki>{{padleft:cafe|8|-}}</nowiki> = <code>{{padleft:cafe|8|-}}</code><br />
 +
 
 +
<nowiki>{{padleft:bcd|6|{{!}}}}</nowiki> = <code>{{padleft:bcd|6|{{!}}}}</code><br/>
 +
<br/>
 +
<nowiki>{{padright:bcd|6|a}}</nowiki> = <code>{{padright:bcd|6|a}}</code><br />
 +
<nowiki>{{padright:0|6|a}}</nowiki> = <code>{{padright:0|6|a}}</code> (bug)<br />
 +
 
 +
|valign="top"|<br />First case is, for example, applicable to years in a category... giving an ordered year to sort by pipetricks order, or any such ordering where left extended zeros allow a proper sorting.<br /><br /> '''[MW1.8+]''' Pads a string with a character to the specified width. Note that there's a little bug that interprets non-[[w:US-ASCII|US-ASCII]] characters as two, instead of one character (see the difference in''' ''café'' and ''cafe'' '''in the examples.)
 +
 
 +
It does not seem possible to use padleft and padright for padding with characters with a multi-character code, such as <code>&amp;nbsp;</code>, which would be useful with padleft for [[Help:Sorting|sorting tables]] with Javascript.
 +
 
 +
Padding "0" does not work, it returns the same. This seems to be a bug.<ref>Function pad in includes/CoreParserFunctions.php puts, oddly, the $string itself as a condition for the padding. To be reported as bug.</ref>
 
|}{{-}}
 
|}{{-}}
 
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 &amp;nbsp;, which would be useful with padleft for [[Help:Sorting|sorting tables]] with Javascript.
 
  
 
== Template modifiers ==
 
== Template modifiers ==
Line 373: Line 309:
 
|-
 
|-
 
| <nowiki>{{int:xyz}}</nowiki>
 
| <nowiki>{{int:xyz}}</nowiki>
| Shorthand for <nowiki>{{MediaWiki:xyz}}</nowiki>, rendered as {{int:xyz}} if [[MediaWiki:xyz]] doesn't exist. See [[Help:MediaWiki namespace]].
+
| Shorthand for <nowiki>{{MediaWiki:xyz}}</nowiki>, rendered as {{int:xyz}} if [[MediaWiki:xyz]] doesn't exist. See also [[Help:System message]].
 
|-
 
|-
 
| <nowiki>{{msg:xyz}}</nowiki>
 
| <nowiki>{{msg:xyz}}</nowiki>
| Try <nowiki>{{Template:xyz}}</nowiki> before [[Help:Magic words|magic word]] xyz, without this modifier it's the other way around. No additional effect if there is no template xyz.
+
| Even if there is a magic word named "xyz", use template:xyz unless the template doesn't exist (equivalent to <nowiki>{{template:xyz}}</nowiki>). Normally, magic words have priority when there is a conflict.
 
|-
 
|-
 
| <nowiki>{{msgnw:xyz}}</nowiki>
 
| <nowiki>{{msgnw:xyz}}</nowiki>
Line 382: Line 318:
 
|-
 
|-
 
| <nowiki>{{raw:xyz}}</nowiki>
 
| <nowiki>{{raw:xyz}}</nowiki>
| '''[MW1.6+]''' Like <code>{&#123;msg:&#125;}</code> {{unclear}} [http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=12925]
+
| '''[MW1.6+]''' Equivalent to <code><nowiki>{{msg:xyz}}</nowiki></code> above<ref>[http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=12925 Wikimedia SVN revision 12925]</ref>.
 
|-
 
|-
 
| <nowiki>{{subst:xyz}}</nowiki>
 
| <nowiki>{{subst:xyz}}</nowiki>
Line 401: Line 337:
 
| framed<br />frame<br />enframed
 
| framed<br />frame<br />enframed
 
| <nowiki>[[Image:Mediawiki.png|framed]]</nowiki>
 
| <nowiki>[[Image:Mediawiki.png|framed]]</nowiki>
| Places an image in a ''frame'' with a description. Uses original size.
+
| Places an image in a ''frame'' with a description. Uses original size and stubbornly ignores width parameter if given.<br>In general, far better to use thumb, as is only suitable for small images.
 +
|-
 +
| border
 +
| <nowiki>[[Image:Mediawiki.png|border]]</nowiki>
 +
| Shows a 1px border around the image.
 
|-
 
|-
 
| thumbnail<br />thumb
 
| thumbnail<br />thumb
 
| <nowiki>[[Image:Mediawiki.png|thumbnail]]</nowiki>
 
| <nowiki>[[Image:Mediawiki.png|thumbnail]]</nowiki>
| Modifies image size, sets it to dependant on user's favourite thumbnail size in their preferences.
+
| Modifies image size, sets it to dependant on user's favourite thumbnail size in their preferences, or on the given width parameter (see below).
 
|-
 
|-
 
| thumb=''xyz''
 
| thumb=''xyz''
 
| <nowiki>[[Image:Mediawiki.png|thumb=Wiki.png]]</nowiki>
 
| <nowiki>[[Image:Mediawiki.png|thumb=Wiki.png]]</nowiki>
 
| Manualthumb: instead of displaying an automatically-sized thumbnail for <var>Mediawiki.png</var>, display the image <var>Wiki.png</var>.
 
| Manualthumb: instead of displaying an automatically-sized thumbnail for <var>Mediawiki.png</var>, display the image <var>Wiki.png</var>.
|-
+
|-valign="top"
| ''width'' px
+
| ''width'' px<br>100x200px
| <nowiki>[[Image:Mediawiki.png|40px]]</nowiki>
+
| <nowiki>[[Image:Mediawiki.png|40px]]</nowiki><br><nowiki>[[Image:Mediawiki.png|100x200px]]</nowiki>
| Scales image to given ''width''&#160; in pixels
+
| Scales image to given ''width''&#160; in pixels<br>Scales image to no more than 100 pixels wide and no more than 200 high, but image scaled to retain it's true aspect ratio within the boundary specified.
 
|}{{-}}
 
|}{{-}}
  
 
=== Position ===
 
=== Position ===
 
:''For details see [[Help:Images_and_other_uploaded_files]]''
 
:''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.
+
The positions are mutually exclusive; the last specified wins. [[:Template:-]] can stop floating. For inline images only modifier ''px'' (see above) is supported.
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0" width="100%"
 
{| class="wikitable" border="2" cellpadding="4" cellspacing="0" width="100%"
 
! Word  
 
! Word  
Line 457: Line 397:
 
| <nowiki>{{CONTENTLANGUAGE}}</nowiki>
 
| <nowiki>{{CONTENTLANGUAGE}}</nowiki>
 
| <code>{{CONTENTLANGUAGE}}</code>
 
| <code>{{CONTENTLANGUAGE}}</code>
| '''[MW1.7+]''' Default content {{h:mwg|LanguageCode}}
+
| '''[MW1.7+]''' code of the site's default interface language ({{h:mwg|LanguageCode}})
 
|-
 
|-
 
| <nowiki>{{DEFAULTSORT:xyz}}</nowiki>
 
| <nowiki>{{DEFAULTSORT:xyz}}</nowiki>
|  
+
| <nowiki>{{DEFAULTSORT:xyz}}</nowiki>
| '''[MW1.10+]''' Sets a default [[Help:Categories#Sort_key|category sort key]] for the current page<ref>"[[w:Wikipedia:Wikipedia Signpost/2007-01-02/Technology report|Technology report]]", en-Wikipedia Signpost, January 2007</ref>.
+
| '''[MW1.10+]''' Sets a default [[Help:Categories#Sort_key|category sort key]] for the whole current page (also applying for category tags before this tag)<ref>"[[w:Wikipedia:Wikipedia Signpost/2007-01-02/Technology report|Technology report]]", en-Wikipedia Signpost, January 2007</ref>.
 
|-
 
|-
| <nowiki>#redirect</nowiki>  
+
| <nowiki>#REDIRECT</nowiki>  
 
| <code>#REDIRECT&#160;[&#91;target&#93;]</code><br />at top of source page
 
| <code>#REDIRECT&#160;[&#91;target&#93;]</code><br />at top of source page
 
| Creates a [[Help:Redirect|redirect]] to another page.
 
| Creates a [[Help:Redirect|redirect]] to another page.
Line 491: Line 431:
 
"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]].
 
"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.
+
"Plural" is a site-language-dependent switch function, controlled by function convertPlural in Language.php (which distinguishes between 1 and "not 1"), for some languages overridden in Languagexx.php, e.g. for French (which distinguishes between <=1 and >1) and Russian (oddly, first option is 1, 21, 31,.., 91, 101, 121, .., second is 2, 3, 4, 22, 23, 24, 31, 32, 33, 41,.., 94, 102, 103, 104,.., 122, 123,.., and else the third).
See also [[mediazilla:5805]] for the use of "plural" in system messages.
+
 
 +
As opposed to [[ParserFunctions]], "plural" accepts points and commas in numbers and interprets them in a site-language-specific way (depending on $separatorTransformTable in Messagesxx.php); on this site:
 +
*<nowiki>{{plural:1.000|a|b|c}}</nowiki> gives {{plural:1.000|a|b|c}}
 +
*<nowiki>{{plural:1,000|a|b|c}}</nowiki> gives {{plural:1,000|a|b|c}}
  
===See also===
+
(on e.g. the German and the Dutch sites reversed w.r.t. the result on English sites).
*[[m:ParserFunctions|Parser functions]] '''#expr:''', '''#if:''', '''#ifeq:''', etc.
 
*[[mw:Manual:Magic words]]
 
*[http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/languages/Language.php Source for Language.php]
 
*[http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/includes/MagicWord.php Source for MagicWord.php]
 
  
==References==
+
"Plural" is used in various system messages, e.g. {{msg|nmembers}}, where it uses interface language instead of site language.
<div style="font-size:0.9em;"><references /></div>
 
{{H:f|enname=Magic words}}
 

Latest revision as of 12:17, 6 June 2007

Help:Contents

This is an organized 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 underscores, e.g. __NOTOC__
  • an XML object, coded similar to HTML, preceded by "<" (and for the end tag "/") and followed by ">", as in <nowiki>...</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.

Magic words between double underscores

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).


XML-style tags

nowiki: <nowiki>...</nowiki>, disables expansion/interpretation of templates, link syntax, formatting syntax, etc.: <nowiki>'''[[{{tc}}]]'''</nowiki> gives '''[[{{tc}}]]'''

pre: <pre>...</pre>, ditto, also for multiple lines; it is rendered with a new paragraph at the start and end: a<pre>'''[[{{tc}}]]'''</pre>b gives a

'''[[{{tc}}]]'''

b

math: <math>...</math>, e.g. \(\sqrt{a^2+b^2}\) gives \(\sqrt{a^2+b^2}\); see Help:Displaying a formula

hiero: <hiero>...</hiero>, e.g. <hiero>A1</hiero> gives:

A1

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}} 15 Displays the current day in numeric form.
{{CURRENTDAY2}} 15 [MW1.6+] Same as {{CURRENTDAY}}, but with leading zero (01 .. 31).
{{CURRENTDAYNAME}} Friday Name of the day in the language of the project or English.
{{CURRENTDOW}} 5 Same as {{CURRENTDAYNAME}}, but as a number (0=Sunday, 1=Monday...).
{{CURRENTMONTH}} 11 The number 01 .. 12 of the month.
{{CURRENTMONTHABBREV}} Nov [MW1.5+] Same as {{CURRENTMONTH}}, but in abbreviated form (Jan .. Dec).
{{CURRENTMONTHNAME}} November Same as {{CURRENTMONTH}}, but in named form (January .. December).
{{CURRENTTIME}} 14:26 The current time (00:00 .. 23:59).
{{CURRENTHOUR}} 14 The current hour (00 .. 23).
{{CURRENTWEEK}} 46 Number of the current week (1-53) according to ISO 8601 with no leading zero.
{{CURRENTYEAR}} 2024 Returns the current year.
{{CURRENTTIMESTAMP}} 20241115142634 [MW1.7+] ISO 8601 time stamp.

Template:-

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}} 15 Displays the local day of the month in numeric form.
{{LOCALDAY2}} 15 Same as {{LOCALDAY}}, but with a leading zero (01 .. 31).
{{LOCALDAYNAME}} Friday Name of the day in the language of the project or English.
{{LOCALDOW}} 5 Same as {{LOCALDAYNAME}}, but as a number (0=Sunday, 1=Monday...).
{{LOCALMONTH}} 11 The number 01 .. 12 of the month.
{{LOCALMONTHABBREV}} Nov Same as {{LOCALMONTH}}, but in abbreviated form as Jan .. Dec.
{{LOCALMONTHNAME}} November Same as {{LOCALMONTH}}, but in named form as January .. December.
{{LOCALTIME}} 14:26 The local time (00:00 .. 23:59).
{{LOCALHOUR}} 14 The local hour (00 .. 23).
{{LOCALWEEK}} 46 Number of the local week (1-53) according to ISO 8601 with no leading zero.
{{LOCALYEAR}} 2024 Returns the local year.
{{LOCALTIMESTAMP}} 20241115142634 ISO 8601 time stamp.

Template:-

Statistics

Statistics variables give thousands separators unless ":R" for "raw" is added (actually, these versions are parser functions).

Word Example Explanation
{{CURRENTVERSION}} 1.35.3 [MW1.7+] Template:H:mwg [1]
{{NUMBEROFEDITS}}
{{NUMBEROFEDITS:R}}
630,796
630796
[MW1.10+ (r21319)] Returns the total number of page edits since MediaWiki, the software that runs this site, was installed.
{{NUMBEROFARTICLES}}
{{NUMBEROFARTICLES:R}}
9,136
9136
A variable which returns the total number of articles on the Wiki.
{{NUMBEROFPAGES}}
{{NUMBEROFPAGES:R}}
82,064
82064
[MW1.7+] Returns the total number of pages. [2]
{{NUMBEROFFILES}}
{{NUMBEROFFILES:R}}
8,515
8515
[MW1.5+] Returns the number of uploaded files (rows in the image table).
{{NUMBEROFUSERS}}
{{NUMBEROFUSERS:R}}
358,030
358030
[MW1.7+] Returns the number of registered users (rows in the user table).
{{NUMBEROFADMINS}}
{{NUMBEROFADMINS:R}}
6
6
[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 Template:H:mwg.

Template:-

Page names and related info

H:Page name variables

Parser functions

For details see Help:Parser function.

Not working at the position of the page where the tag is located but on the page header, and throughout the page, respectively (see below):

  • DISPLAYTITLE: allow the page header to be different from the page name.
  • DEFAULTSORT: Sets a default category sort key for the page.

Namespaces and URLs

Word Example Explanation
{{ns:}} {{ns:4}} = MyWikiBiz
{{ns:project}} = MyWikiBiz
Returns the name of a given namespace number.
{{localurl:x y @}}
{{localurle:x y @}}
{{localurl:a|b=c}}
{{localurl:Wikipedia:Category}}
/X_y_@
/X_y_@
/index.php?title=A&b=c
/Wikipedia:Category
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}}
https://mywikibiz.com/X_y_@
https://mywikibiz.com/X_y_@
https://mywikibiz.com/index.php?title=M:a&b=c
[MW1.5+] Returns the full URL of a given page. Optional query parameter as for localurl:.

Template:-

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:7|3|0}} = 007

{{padleft:0|3|0}} = 000 (bug)

{{padleft:bcd|6|a}} = aaabcd
{{padleft:café|8|-}} = ----café(<==Bug effect)
{{padleft:cafe|8|-}} = ----cafe

{{padleft:bcd|6|{{!}}}} = |||bcd

{{padright:bcd|6|a}} = bcdaaa
{{padright:0|6|a}} = 0aaaaa (bug)


First case is, for example, applicable to years in a category... giving an ordered year to sort by pipetricks order, or any such ordering where left extended zeros allow a proper sorting.

[MW1.8+] Pads a string with a character to the specified width. Note that there's a little bug that interprets non-US-ASCII characters as two, instead of one character (see the difference in café and cafe in the examples.)

It does not seem possible to use padleft and padright for padding with characters with a multi-character code, such as &nbsp;, which would be useful with padleft for sorting tables with Javascript.

Padding "0" does not work, it returns the same. This seems to be a bug.[1]

Template:-

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 also Help:System message.
{{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[2].
{{subst:xyz}} In the wikitext, the tag is substituted by the content (single-level evaluation only), see Help:Substitution.

Template:-

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 and stubbornly ignores width parameter if given.
In general, far better to use thumb, as is only suitable for small images.
border [[Image:Mediawiki.png|border]] Shows a 1px border around the image.
thumbnail
thumb
[[Image:Mediawiki.png|thumbnail]] Modifies image size, sets it to dependant on user's favourite thumbnail size in their preferences, or on the given width parameter (see below).
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
100x200px
[[Image:Mediawiki.png|40px]]
[[Image:Mediawiki.png|100x200px]]
Scales image to given width  in pixels
Scales image to no more than 100 pixels wide and no more than 200 high, but image scaled to retain it's true aspect ratio within the boundary specified.

Template:-

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.

Template:-

Miscellany

Word Example Explanation
{{DISPLAYTITLE:xyz}} default disabled [MW 1.7+] Set the page's title [5], see Template:H:mwg.
{{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 (Template:H:mwg)
{{DEFAULTSORT:xyz}} {{DEFAULTSORT:xyz}} [MW1.10+] Sets a default category sort key for the whole current page (also applying for category tags before this tag)[3].
#REDIRECT #REDIRECT [[target]]
at top of source page
Creates a redirect to another page.

Template:-

Language-dependent word conversions

Word Example Explanation
{{ CURRENTMONTHNAMEGEN }} November Genitive form of month name used for Czech, Polish, Ukrainian[6]
word }} {{grammar:7sg|Wikipedie}}
on cs: is Wikipedií.
Derived word forms in inflected languages like Czech [7]
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".

Template:-

"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 site-language-dependent switch function, controlled by function convertPlural in Language.php (which distinguishes between 1 and "not 1"), for some languages overridden in Languagexx.php, e.g. for French (which distinguishes between <=1 and >1) and Russian (oddly, first option is 1, 21, 31,.., 91, 101, 121, .., second is 2, 3, 4, 22, 23, 24, 31, 32, 33, 41,.., 94, 102, 103, 104,.., 122, 123,.., and else the third).

As opposed to ParserFunctions, "plural" accepts points and commas in numbers and interprets them in a site-language-specific way (depending on $separatorTransformTable in Messagesxx.php); on this site:

  • {{plural:1.000|a|b|c}} gives a
  • {{plural:1,000|a|b|c}} gives b

(on e.g. the German and the Dutch sites reversed w.r.t. the result on English sites).

"Plural" is used in various system messages, e.g. Template:Msg, where it uses interface language instead of site language.

  1. ^ Function pad in includes/CoreParserFunctions.php puts, oddly, the $string itself as a condition for the padding. To be reported as bug.
  2. ^ Wikimedia SVN revision 12925
  3. ^ "Technology report", en-Wikipedia Signpost, January 2007