Help:Magic words

From Meta, a Wikimedia project coordination wiki
(Redirected from Help:Magic Words)
Jump to navigation Jump to search

A "magic word" is a symbol recognized by the MediaWiki software which triggers special behavior. Some magic words look like template calls, but they are fundamentally different.

A magic word can be:

  • a behavior switch, an upper case word surrounded by pairs of underscores — e.g. __NOTOC__
  • an XML-style tag (AKA, HTML-style), preceded by "<" (and, for the end tag, "/") and followed by ">" — e.g. <nowiki>...</nowiki>
  • a parser function: similar to a template, a word preceded by the symbols "{{" and followed by "}}", and optionally parameter definitions separated by pipe characters, except that the name of the function is immediately followed by a colon (":") — e.g. {{ns:3}} or {{#if: {{{1|}}} | true | false }}
  • a variable: similar to a template without parameters, an upper-case word preceded by the symbols "{{" and followed by "}}" — e.g. {{CURRENTDAY}}
  • a template modifier
  • an image modifier

In the case of template-like magic words, if a page in the template namespace has the same name as a magic word, attempted calls to that template will result in the magic word being invoked instead. To prevent this behavior, begin the template call with the prefix "msg:" or the template-namespace prefix, "Template:". See below for further details if you need this feature.


For details see Help:Variable

Page names and related info[edit]

Word Example Explanation
This page "User:Anonymous user/sandbox/my page" page
"User talk:Anonymous user/sandbox/my page" page
{{PAGENAME}} Magic words Anonymous user/sandbox/my page Returns the name of the current page, including all levels (Title/Subtitle). This does not include the name of the namespace.
{{PAGENAMEE}} Magic_words Anonymous_user/sandbox/my_page More URL-friendly percent encoded special characters (to use an article name in an external link).
Magic words
Anonymous user/sandbox
[MW 1.7+] The basename of a subpage ("Title/Other" on "Title/Other/Subtitle"), see Help:Link.
Magic words
my page
[MW 1.6+] Name of the current page, excluding parent pages ("Subtitle" on "Title/Other/Subtitle") in namespaces supporting subpages, see Help:Link.
Returns the name of the namespace the current page resides in. Note that this returns an empty string for the main (article) space.
User talk
{{NAMESPACENUMBER}} 12 2 Returns the number of the namespace the current page resides in. This makes templates more portable between various languages. For example, File: on the German Wikipedia is "Datei:", but the file namespace number on English, German and any other Wikimedia wiki is always 6.
Help:Magic words
User:Anonymous user/sandbox/my page
[MW 1.6+] Shorthands for NAMESPACE+PAGENAME.
User talk:Anonymous user/sandbox/my page
Help talk
User talk
[MW 1.7+] Name of next odd namespace (e.g. 4 ⇒ 5).
[MW 1.7+] Name of last even namespace (e.g. 5 ⇒ 4).
[MW 1.7+] An alias for SUBJECTSPACE(E).
Help talk:Magic words
User talk:Anonymous user/sandbox/my page
Help:Magic words
User:Anonymous user/sandbox/my page
Help:Magic words
User:Anonymous user/sandbox/my page
[MW 1.7+] An alias for SUBJECTPAGENAME(E).
{{REVISIONDAY}} 12 N/A [MW 1.8+] The day on which the page was last modified.
{{REVISIONDAY2}} 12 N/A [MW 1.8+] The day on which the page was last modified, but with a leading zero (01 … 31).
{{REVISIONMONTH}} 01 N/A [MW 1.8+] The month in which the page was last modified.
{{REVISIONYEAR}} 2023 N/A [MW 1.8+] The year in which the page was last modified.
{{REVISIONTIMESTAMP}} 20230112015240 N/A [MW 1.8+] ISO 8601 time stamp, indicating when the page was last modified.
{{SITENAME}} Meta Value of $wgSitename.
{{SERVER}} // Value of $wgServer.
{{SCRIPTPATH}} /w [MW 1.5+] $wgScriptPath.
{{SERVERNAME}} [MW 1.5+] $wgServerName.

Template modifiers[edit]

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}} Same as {{MediaWiki:xyz}}, except standard message translation is applied depending on subpages and content/user/uselang language. Another difference is: this doesn't appear under "Templates used on this page:". 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 unexpanded wikitext is rendered (more or less, for details 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[edit]

For details see w:en:Wikipedia:Extended image syntax.

These are image modifiers used in [[File:title.ext|modifier|...|modifier]] links. Some are mutually exclusive, and then the last specified wins. 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
[[File: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 [[File:Mediawiki.png|border]] Shows a 1 pixel border around the image.
[[File:Mediawiki.png|thumbnail]] Modifies image size, sets it dependent on user's favorite thumbnail size in one's preferences, or on the given width parameter (see hereafter).
thumb=xyz [[File:Mediawiki.png|thumb=Wiki.png]] Manual thumbnail: instead of displaying an automatically-sized thumbnail for Mediawiki.png, display the image Wiki.png.
width px
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 its true aspect ratio within the boundary specified.


For details see Help:Images and other uploaded files.

The positions are mutually exclusive; the last specified wins. Template:Clear can stop floating. For inline images only modifier px (see hereinbefore) is supported.

Word Usage Explanation
right [[File:Mediawiki.png|right]] Sets top of image to the right margin, text will flow from the left.
left [[File:Mediawiki.png|left]] Sets top of image to the left margin, content text will flow from the right.
none [[File:Mediawiki.png|none]] Image will be alone at left, content text will not appear with image.
[[File:Mediawiki.png|center]] Like none with image centered.


Word Example Explanation
{{DISPLAYTITLE:xyz}} no inline output [MW 1.7+] Modify the page's title [1], enabled in Wikimedia projects since June 2007 ([2]). Also see $wgAllowDisplayTitle.

[MW 1.7+] U+200E left-to-right or U+200D right-to-left mark.
{{CONTENTLANGUAGE}} en [MW 1.7+] Code of the site's default interface language ($wgLanguageCode).
{{DEFAULTSORT:xyz}} no inline output [MW 1.10+] Sets a default category sort key for the whole current page (also applying for category tags before this tag)[2].
at top of source page
Creates a redirect to another page (to the target page).

Despite its name, MAGICNUMBER is no magic word, the ISBN magic works only on the MediaWiki:Booksources page used by Special:Booksources, but talking about [[{{ns:4}}:{{int:Booksources}}|{{ns:8}}:Booksources]] in a way working on any MediaWiki installation is esoteric enough to be noted here.

Language-dependent word conversions[edit]

Word Example Explanation
{{CURRENTMONTHNAMEGEN}} February Genitive form of month name, used for Czech, Polish, Ukrainian, etc.
{{LOCALMONTHNAMEGEN}} February Genitive form of month name (local time), used for Czech, Polish, Ukrainian, etc.
{{grammar:case | word }} {{grammar:7sg|Wikipedie}}
on cs: is Wikipedií.
Derived word forms in inflected languages like Latin, German, Czech, etc. Or "prefixed" case for Hebrew (alters the final vowel of the Hebrew word used as prefix, before inserting a "maqaf" hyphen, when the following word is not written in Hebrew).
{{plural:count |form1 |form2 }}
{{plural:count |1st | 2nd | 3rd }}
{{plural: 2 | is | are }}
outputs are
{{plural: 1 | this | these }}
outputs this
{{plural: 0 | his | their }}
outputs their
count 1 yields form1 (singular), plural transformations are used for lot of languages, but the number of plural forms needed is language-dependant . Some Asian languages only have a single form (plurality however may be indicated by adding some complement words), most languages have only 2 forms (singluar and plural), but Baltic, Slavic and Celtic languages have more (singular, dual, paucal, and plural for more). The number zero may also be singular or plural depending on language.

"Grammar" and "Plural" are language-dependent (also script-dependent for languages written with different script variants) functions, defined in phabricator:source/mediawiki/browse/master/includes/languages/ and phabricator:source/mediawiki/browse/master/languages/data/

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

"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, which uses a grammar case for amounts ending in 1 (1, 21, 31,...), another case for amounts ending in 2 to 4 (2, 3, 4, 22, 23, 24, ...) and still another case for the remaining quantities. Note that some languages also used 3 plural forms in past versions (ab, av, ba, bxr, ce, crh_cyrl, cv, inh, koi, krc, kv, lbe, lez, mhr, mrj, myv, ru, tt_cyrl, tyv, udm, xal). The list of languages having either support for grammar forms, or for more than 2 plural forms are defined in plurals.xml (base rules from CLDR) and plurals-mediawiki.xml (additional rules for Mediawiki).

As opposed to ParserFunctions (which only uses the English rules for parsing numbers), "plural" accepts points and commas in numbers and interprets them in a site-language-specific way (depending on $separatorTransformTable in Messagesxx.php, which is defined according to the default/main language of that site); on this site:

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

(on e.g. the German, Dutch, French sites swapped the interpretation of dots and commas in the specified numeric value, w.r.t. the result on English sites).

"Plural" is used in various system messages, e.g. message with id 'nmembers' (talk), where it uses interface language instead of site language.

See also[edit]

Notes and references[edit]

  1. Wikimedia SVN revision 12925
  2. "Technology report", English Wikipedia Signpost, January 2007

Links to other help pages

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences · User style
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Links · URL · Piped links · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Testing · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Transclusion
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors