Help:Magic words
From Memory Alpha, the free Star Trek reference
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.
Contents |
[edit] Behavior switches
- For details see Help: Section.
A behavior switch controls the layout or behavior of the page and can often be used to specify desired omissions and inclusions in the content.
| Word | Description |
|---|---|
| Table of Contents | |
| __NOTOC__ | Hides the table of contents on the current page. |
| __FORCETOC__ | Forces the table of contents to appear at its normal position (above the first header). |
| __TOC__ | Places a table of contents at the location where the magic word occurs (overriding any __NOTOC__). |
| Editing | |
| __NOEDITSECTION__ | Hides the edit links beside headings. |
| __NEWSECTIONLINK__ | Adds a link ("+" by default) beside the "edit" tab for adding a new section on a non-talk page. |
| Categories | |
| __NOGALLERY__ | Used on a category page; replaces thumbnails in the category view with normal links. |
| __HIDDENCAT__ | Used on a category page; hides the category from the lists of categories in its members and parent categories (there is an option in the user preferences to show them). |
| Language conversion | |
| __NOCONTENTCONVERT__ __NOCC__ | Don't perform the content language conversion (character and phase) in article display; for example, only show Chinese (zh) instead of variants such as zh_cn, zh_tw, zh_sg, and zh_hk. |
| __NOTITLECONVERT__ __NOTC__ | Like __NOCONTENTCONVERT__ but affecting article title only, i.e. don't perform language conversion on the title (all other content is converted). |
| Other | |
| __INDEX__ | Tell search engines to index the page (overrides $wgArticleRobotPolicies, but not robots.txt). |
| __NOINDEX__ | Tell search engines not to index the page (i.e., do not list in search engines' results). |
| __STATICREDIRECT__ | On redirect pages, don't allow MediaWiki to automatically update the link when someone moves a page and checks "Update any redirects that point to the original title". |
[edit] Variables
- For details see Help: Variable.
Variables return information about the current page, wiki, or date. Their syntax is similar to templates. If a template name conflicts with a variable, the variable will be used (so to transclude the template Template:PAGENAME you would need to write {{Template:PAGENAME}}). In some cases, adding parameters will force the parser to treat a variable as a template; for example, {{CURRENTDAYNAME|x}} transcludes Template:CURRENTDAYNAME.
Variables highlighted in orange are considered 'expensive', and the number that can be included on a page is limited.
[edit] Date and time
The following variables return the current date and time according to the user's timezone preferences, defaulting to the UTC timezone.
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 | Description |
|---|---|---|
| Year | ||
| {{CURRENTYEAR}} | 2009
| The current year. |
| Month | ||
| {{CURRENTMONTH}} | 11
| The number of the month, zero-padded. |
| {{CURRENTMONTHNAME}} | November
| Same as {{CURRENTMONTH}}, but in named form January .. December. |
| {{CURRENTMONTHNAMEGEN}} | November
| Genitive form of the month name; used for Czech, Polish, Ukrainian, etc. [1] |
| {{CURRENTMONTHABBREV}} | Nov
| Same as {{CURRENTMONTH}}, but in abbreviated form as Jan .. Dec. |
| Day | ||
| {{CURRENTDAY}} | 11
| Displays the current day in numeric form. |
| {{CURRENTDAY2}} | 11
| Same as {{CURRENTDAY}}, but with leading zero (01 .. 31). |
| {{CURRENTDAYNAME}} | Wednesday
| Name of the day in the language of the project or English. |
| {{CURRENTDOW}} | 3
| Same as {{CURRENTDAYNAME}}, but as a number (0=Sunday, 1=Monday...). |
| Time | ||
| {{CURRENTTIME}} | 01:00
| The current time (00:00 .. 23:59). |
| {{CURRENTHOUR}} | 01
| The current hour (00 .. 23). |
| {{CURRENTMINUTE}} | -0
| The current minute (00 .. 59). |
| Other | ||
| {{CURRENTWEEK}} | 46
| Number of the current week (1-53) according to ISO 8601 with no leading zero. |
| {{CURRENTTIMESTAMP}} | 20091111010029
| ISO 8601 time stamp. |
[edit] Local date and time
The time depending on the local timezone of the wiki (not depending on the timezone in the user's preference settings).
| Word | Example | Description |
|---|---|---|
| Year | ||
| {{LOCALYEAR}} | 2009
| The local year. |
| Month | ||
| {{LOCALMONTH}} | 11
| The number 01 .. 12 of the month. |
| {{LOCALMONTHNAME}} | November
| Same as {{LOCALMONTH}}, but in named form as January .. December. |
| {{LOCALMONTHABBREV}} | Nov
| Same as {{LOCALMONTH}}, but in abbreviated form as Jan .. Dec. |
| Day | ||
| {{LOCALDAY}} | 11
| Displays the local day of the month in numeric form. |
| {{LOCALDAY2}} | 11
| Same as {{LOCALDAY}}, but with a leading zero (01 .. 31). |
| {{LOCALDAYNAME}} | Wednesday
| Name of the day in the language of the project or English. |
| {{LOCALDOW}} | 3
| Same as {{LOCALDAYNAME}}, but as a number (0=Sunday, 1=Monday...). |
| Time | ||
| {{LOCALTIME}} | 01:00
| The local time (00:00 .. 23:59). |
| {{LOCALHOUR}} | 01
| The local hour (00 .. 23). |
| Other | ||
| {{LOCALWEEK}} | 46
| Number of the local week (1-53) according to ISO 8601 with no leading zero. |
| {{LOCALTIMESTAMP}} | 20091111010029
| ISO 8601 time stamp. |
[edit] Technical metadata
| Variable | Example | Description |
|---|---|---|
| Site | ||
| {{SITENAME}} | Memory Alpha
| The name of the site ($wgSitename). |
| {{SERVER}} | http://memory-alpha.org | The base URL of the server ($wgServer). |
| {{SERVERNAME}} | memory-alpha.org
| The name of the server without the protocol ($wgServerName). |
| {{DIRMARK}} {{DIRECTIONMARK}} |
| Outputs a unicode-directional mark that matches the wiki's default language's direction (‎ on left-to-right wikis, ‏ on right-to-left wikis), useful in text with multi-directional text.
|
| {{SCRIPTPATH}} | /en
| The base URL path ($wgScriptPath). |
| {{CURRENTVERSION}} | 1.15.1
| Returns the current version of the base MediaWiki software installed on the Memory Alpha server. [2] |
| {{CONTENTLANGUAGE}} | en
| Code of the default interface language ($wgLanguageCode). |
| Latest revision to current page | ||
| {{REVISIONID}} | 1024232
| The unique identifying number of a page, used in comparing two versions of the same page, as when viewing the page history. Note that when editing a page, this value is null. |
| {{REVISIONDAY}} | 18
| The day on which the page was last modified. |
| {{REVISIONDAY2}} | 18
| The day on which the page was last modified, but with a leading zero (01 .. 31). |
| {{REVISIONMONTH}} | 8
| The month in which the page was last modified. |
| {{REVISIONYEAR}} | 2009
| The year in which the page was last modified. |
| {{REVISIONTIMESTAMP}} | 20090818145304
| ISO 8601 time stamp, indicating when the page was last modified. |
| Affects page content | ||
| {{DISPLAYTITLE:xyz}} | {{DISPLAYTITLE:five}}
| Sets the page's title to xyz. Note that the character count must match with that of the actual title or the displayed title will be unchanged. |
| {{DEFAULTSORT:xyz}} | {{DEFAULTSORT:Kim, Harry}}
| Sets a default category sort key for the whole current page (i.e. also applies to category tags before this magic word)[1]. |
[edit] Statistics
Statistics variables give thousands separators unless ":R" for "raw" is added (actually, these versions are parser functions).
| Variable | Example | Description |
|---|---|---|
| Entire wiki | ||
| {{NUMBEROFPAGES}} {{NUMBEROFPAGES:R}} | 90,85590855
| Returns the total number of pages on Memory Alpha. [3] |
| {{NUMBEROFARTICLES}} {{NUMBEROFARTICLES:R}} | 30,99530995
| Returns the total number of articles on Memory Alpha. |
| {{NUMBEROFFILES}} {{NUMBEROFFILES:R}} | 21,97721977
| Returns the number of files uploaded to Memory Alpha (rows in the image table). |
| {{NUMBEROFEDITS}} {{NUMBEROFEDITS:R}} | 1,049,9001049900
| Returns the total number of page edits since MediaWiki, the software that runs Memory Alpha, was installed. |
| {{NUMBEROFUSERS}} {{NUMBEROFUSERS:R}} | 1,677,5051677505
| Returns the number of registered users (rows in the user table). |
| {{NUMBEROFADMINS}} {{NUMBEROFADMINS:R}} | 2323
| Returns the number of administrators (sysop, bureaucrat, steward and checkuser) on Memory Alpha. |
| {{PAGESINCATEGORY:categoryname}} {{PAGESINCAT:categoryname}} | {{PAGESINCATEGORY:Memory Alpha help}} = 77{{PAGESINCAT:Memory Alpha help}} = 77
| Number of pages in the given category. |
| {{NUMBERINGROUP:groupname}} | {{NUMBERINGROUP:bureaucrat}} = 2
| Number of users in a specific group. |
[edit] Namespaces
| Variable | Example | Description |
|---|---|---|
| {{NAMESPACE}} {{NAMESPACEE}} | Help
| Name of the namespace the current page resides in. |
| {{TALKSPACE}} {{TALKSPACEE}} | Help talk
| Name of next odd namespace (e.g. 4 → 5) |
| {{SUBJECTSPACE}} {{SUBJECTSPACEE}} | Help
| Name of last even namespace (e.g. 5 → 4) |
| {{ARTICLESPACE}} {{ARTICLESPACEE}} | Help
| An alias for SUBJECTSPACE(E) |
[edit] Page names
| Variable | Example | Description |
|---|---|---|
| {{PAGENAME}} {{PAGENAMEE}} | Magic wordsMagic_words
| Name of the current page, including all levels (Title/Subtitle). |
| {{BASEPAGENAME}} {{BASEPAGENAMEE}} | Magic words
| The base name of a subpage ("Title/Other" on "Title/Other/Subtitle"). |
| {{SUBPAGENAME}} {{SUBPAGENAMEE}} | Magic words
| Name of the current page, excluding parent pages ("Subtitle" on "Title/Other/Subtitle") in namespaces supporting subpages. |
| {{FULLPAGENAME}} {{FULLPAGENAMEE}} | Help:Magic words
| Shorthands for NAMESPACE+PAGENAME |
| {{SUBJECTPAGENAME}} {{SUBJECTPAGENAMEE}} | Help:Magic words
| FULLPAGENAME in its SUBJECTSPACE |
| {{ARTICLEPAGENAME}} {{ARTICLEPAGENAMEE}} | Help:Magic words
| An alias for SUBJECTPAGENAME(E) |
| {{TALKPAGENAME}} {{TALKPAGENAMEE}} | Help talk:Magic words
| FULLPAGENAME in its TALKSPACE |
[edit] Parser functions
- For details see Meta: Parser function.
[edit] URLs
| Variable | Example | Description |
|---|---|---|
| {{localurl:x y @}} {{localurl:a|b=c}} | /en/wiki/X_y_@
| The local URL of a page (might not exist). Optional query parameter, see Variable. |
| {{fullurl:x y @}} {{fullurl:x y @|a=b}} {{fullurl:m:x y @|b=c}} | http://memory-alpha.org/en/wiki/X_y_@ http://memory-alpha.org/en/index.php?title=X_y_@&a=b http://meta.wikimedia.org/wiki/x_y_@?b=c | The full URL of a given page. Optional query parameter as for localurl:. |
| {{filepath:Wiki.png}} {{filepath:Wiki.png|nowiki}} | ![]() http://images1.wikia.nocookie.net/memoryalpha/en/images/b/bc/Wiki.png | The absolute URL to a media file. |
| {{urlencode:x y @}} | x+y+%40
| Encodes variable values for use in external links. [4] |
| {{anchorencode:x #y @}} | x_.23y_.40
| Encodes variable values for use in section anchors. [5] |
[edit] Namespaces
{{ns:}} returns the localized name for the namespace with that index.
| Content namespaces | Talk namespaces | |||
|---|---|---|---|---|
| Usage | Output | Usage | Output | |
| {{ns:-2}} or {{ns:Media}} | Media | {{ns:-1}} or {{ns:Special}} | Special | |
| {{ns:0}} | {{ns:1}} or {{ns:Talk}} | Talk | ||
| {{ns:2}} or {{ns:User}} | User | {{ns:3}} or {{ns:User talk}} | User talk | |
| {{ns:4}} or {{ns:Project}} | Memory Alpha | {{ns:5}} or {{ns:Project talk}} | Memory Alpha talk | |
| {{ns:6}} or {{ns:File}} or {{ns:Image}} | File | {{ns:7}} or {{ns:File talk}} or {{ns:Image talk}} | File talk | |
| {{ns:8}} or {{ns:MediaWiki}} | MediaWiki | {{ns:9}} or {{ns:MediaWiki talk}} | MediaWiki talk | |
| {{ns:10}} or {{ns:Template}} | Template | {{ns:11}} or {{ns:Template talk}} | Template talk | |
| {{ns:12}} or {{ns:Help}} | Help | {{ns:13}} or {{ns:Help talk}} | Help talk | |
| {{ns:14}} or {{ns:Category}} | Category | {{ns:15}} or {{ns:Category talk}} | Category talk | |
| {{ns:100}} or {{ns:Forum}} | Forum | {{ns:101}} or {{ns:Forum talk}} | Forum talk | |
| {{ns:102}} or {{ns:Portal}} | Portal | {{ns:103}} or {{ns:Portal talk}} | Portal talk | |
[edit] Formatting
| Word | Example | Description |
|---|---|---|
| {{lc:string}} | {{lc:AbC dEf}} = abc def
| Lowercases all characters of a string. |
| {{lcfirst:string}} | {{lcfirst:Ab Cd}} = ab Cd
| Lowercases the first character of a string. |
| {{uc:string}} | {{uc:aBc DeF}} = ABC DEF
| Uppercases all characters of a string. |
| {{ucfirst:string}} | {{ucfirst:aB cD}} = AB cD
| Uppercases the first character of a string. |
| {{formatnum:unformatted number}} {{formatnum:formatted number | R}} | {{formatnum:-299792458.56789}} = -299,792,458.56789{{formatnum:-299,792,458.56789 | R}} = -299792458.56789
| Adds or removes decimal separators to a number. Leading plus or minus is recognized. |
| {{padleft:string | length}} {{padleft:string | length | padstring}} {{padright:string | length}} {{padright:string | length | padstring}} |
{{padleft:7 | 3}} = | Pads a string with a character to the specified width; the default character is 0. 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 |
| {{plural:count | form1 | form2}} | {{plural: 2 | is | are}} outputs are{{plural: 0 | this | these}} outputs these
| count 1 yields form1 (singular), all other values for count yield form2 (plural); plural transformations are used for languages like Russian [6] based on "count mod 10". |
| {{grammar:case | word}} | {{grammar:7sg|Wikipedie}} on cs: is Wikipedií.
| Derived word forms in inflected languages like Czech. [7] |
- "Plural" and "Grammar" are language-dependent functions, defined in [8], [9], 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 Wikipedia:cs:Šablona:Wikivar/GRAMMAR.
[edit] Miscellaneous
| Usage | Output | Description |
|---|---|---|
| {{int:xyz}} | {{int:edit}} = edit this page
| Internationalizes (translates) the given interface (MediaWiki namespace) message into the user language; rendered as <xyz> if MediaWiki:xyz doesn't exist. See also System messages. |
| {{#language:language_code}} | {{#language:da}} = Dansk
| Native name of language code. |
| {{#tag:tagname}} | {{#tag:myextension | attr=val | attr2=val2 | content}} = <myextension attr=val attr2=val2>content</myextension>
| Passes attributes and inner content to an XML-style parser tag, parsing template variables along the way. See Extension:TagParser. |
| {{: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. | |
| {{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}} | Equivalent to {{msg:xyz}} above[2].
| |
| {{subst:xyz}} | In the wikitext, the tag is substituted by the content (single-level evaluation only); see Substitution. |
[edit] Image modifiers
- For details see 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.
[edit] Size
The last unrecognized modifier is used as a caption for framed images or together with thumbnails. It's also used as a description, i.e. alt=text.
| Word | Usage | Description |
|---|---|---|
| framed frame enframed | [[Image:Mediawiki.png|framed]] | Places an image in a frame with a description. Uses original image size. |
| border | [[Image:Mediawiki.png|border]] | Displays a 1px border around the image. |
| thumbnail thumb | [[Image:Mediawiki.png|thumbnail]] | Modifies image size, sets it to dependent on user's favorite thumbnail size in their preferences. |
| thumb=xyz | [[Image:Mediawiki.png|thumb=Wiki.png]] | Manualthumb: instead of displaying an automatically-sized thumbnail for Mediawiki.png, displays the image Wiki.png. |
| width px n1xn2 px | [[Image:Mediawiki.png|40px]] [[Image:Mediawiki.png|100x200px]] | Scales image to given width in pixels. Scales image to no more than n1 pixels wide and no more than n2 high, but image scaled to retain its true aspect ratio within the boundary specified. |
[edit] Position
- For details see Meta: Images and other uploaded files.
The positions are mutually exclusive; the last specified wins. <br clear="all" /> can stop floating. For inline images, only the modifier px (see above) is supported.
| Word | Usage | Description |
|---|---|---|
| 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. |
[edit] Miscellaneous
| Word | Example | Description |
|---|---|---|
| #REDIRECT | #REDIRECT [[target]]at top of source page | Creates a redirect to another page. |
[edit] See also
- ParserFunctions at MediaWiki (#expr:, #if:, #ifeq:, #iferror:, #ifexpr:, #ifexist:, #rel2abs:, #switch:, #time:, #timel:, #titleparts:)
- Magic words at MediaWiki
- Source for Language.php
- Source for MagicWord.php
[edit] References
- ↑ "Technology report", en-Wikipedia Signpost, January 2007
- ↑ Wikimedia SVN revision 12925

