Help:Variables

From SoftMC-Wiki
Jump to: navigation, search

Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names. This page is about usage of standard magic words.

There are three general types of magic words:

  • Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__
  • Variables: these are uppercase words surrounded by double braces, e.g. {{FOO}}. As such, they look a lot like templates.
  • Parser functions: these take parameters and are either of the form {{foo:...}} or {{#foo:...}}.

Page-dependent magic words will affect or return data about the current page (by default), even if the word is added through a transcluded template or included system message.

Behavior switches

A behavior switch controls the layout or behaviour of the page and can often be used to specify desired omissions and inclusions in the content.

Word Description Versions
Table of contents
__NOTOC__ Hides the table of contents (TOC).
__FORCETOC__ Forces the table of content to appear at its normal position (above the first header).
__TOC__ Places a table of contents at the word's current position (overriding __NOTOC__). If this is used multiple times, the table of contents will appear at the first word's position.
Editing
__NOEDITSECTION__ Hides the section edit links beside headings.
__NEWSECTIONLINK__ Adds a link ("+" by default) beside the "edit" tab for adding a new section on a non-talk page. 1.7+
__NONEWSECTIONLINK__ Removes the link beside the "edit" tab on pages in talk namespaces. 1.15+
Categories
__NOGALLERY__ Used on a category page, replaces thumbnails in the category view with normal links. 1.7+
__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). 1.13+

Variables

Variables return information about the current page, wiki, or date. Their syntax is similar to templates. Variables marked as "[expensive]" are tracked by the software, and the number that can be included on a page is limited.

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.

Date & time

The following variables return the current date and time in UTC.

Due to MediaWiki and browser caching, these variables frequently show when the page was cached rather than the current time.

Variable Output Description Versions
Year
{{CURRENTYEAR}} 2024 Year
Month
{{CURRENTMONTH}} 04 Month (zero-padded number)
{{CURRENTMONTHNAME}} April Month (name)
{{CURRENTMONTHNAMEGEN}} April Month (genitive form)
{{CURRENTMONTHABBREV}} Apr Month (abbreviation) 1.5+
Day
{{CURRENTDAY}} 30 Day of the month (unpadded number)
{{CURRENTDAY2}} 30 Day of the month (zero-padded number) 1.6+
{{CURRENTDOW}} 2 Day of the week (unpadded number)
{{CURRENTDAYNAME}} Tuesday Day of the week (name)
Time
{{CURRENTTIME}} 15:42 Time (24-hour HH:mm format)
{{CURRENTHOUR}} 15 Hour (24-hour zero-padded number)
Other
{{CURRENTWEEK}} 18 Week (number)
{{CURRENTTIMESTAMP}} 20240430154207 YYYYMMDDHHmmss timestamp 1.7+

The following variables do the same as the above, but using the site's server config or $wgLocaltimezone.

  • {{LOCALYEAR}}
  • {{LOCALMONTH}}
  • {{LOCALMONTHNAME}}
  • {{LOCALMONTHNAMEGEN}}
  • {{LOCALMONTHABBREV}}
  • {{LOCALDAY}}
  • {{LOCALDAY2}}
  • {{LOCALDOW}}
  • {{LOCALDAYNAME}}
  • {{LOCALTIME}}
  • {{LOCALHOUR}}
  • {{LOCALWEEK}}
  • {{LOCALTIMESTAMP}}
For more thorough time formatting, you may want to install Extension:ParserFunctions to use the #time parser function

Technical metadata

Revision variables return data about the latest edit to the current page, even if viewing an older version of the page.

Variable Output Description Versions
Site
{{SITENAME}} SoftMC-Wiki The wiki's site name.
{{SERVER}} http://softmc.servotronix.com Domain URL.
{{SERVERNAME}} softmc.servotronix.com Domain name.
Latest revision to current page
{{REVISIONID}} 103423 Unique revision ID 1.5+
{{REVISIONDAY}} 25 Day edit was made (unpadded number) 1.8+
{{REVISIONDAY2}} 25 Day edit was made (zero-padded number) 1.8+
{{REVISIONMONTH}} 04 Month edit was made (zero-padded number) 1.8+
{{REVISIONYEAR}} 2012 Year edit was made 1.8+
{{REVISIONTIMESTAMP}} 20120425124035 Timestamp as of time of edit 1.8+
{{REVISIONUSER}} Anonymous The username of the user who made the most recent edit to the page 1.15+
{{PAGESIZE:page name}} 0 [expensive] Returns the byte size of the specified page. 1.13+
{{PROTECTIONLEVEL:action}} protection level Outputs the protection level (e.g. 'autoconfirm', 'sysop') for a given action (e.g. 'edit', 'move') on the current page or an empty string if not protected. 1.15+
Affects page content
{{DISPLAYTITLE:title}} Format the current page's title header. The value must be equivalent to the default title: only capitalization changes and replacing spaces with underscores. 1.7+
{{DEFAULTSORT:sortkey}}
{{DEFAULTSORTKEY:sortkey}}
{{DEFAULTCATEGORYSORT:sortkey}}
Used for categorizing pages, sets a default category sort key. For example if you put {{DEFAULTSORT:Smith, John}} at the end of John Smith, the page would be sorted under "S" by default in categories. 1.10+

Statistics

Numbers returned by these variables normally contain separators (commas or spaces, depending on the local language), but can return raw numbers with the ":R" flag (for example, {{NUMBEROFPAGES}} → 16,748 and {{NUMBEROFPAGES:R}} → 16748). Use "|R" for magic words that require a parameter like PAGESINCATEGORY (for example {{PAGESINCATEGORY:Help}} and {{PAGESINCATEGORY:Help|R}}).

Variable Output Description Versions
Entire wiki
{{NUMBEROFPAGES}} 16,748 Number of wiki pages. 1.7+
{{NUMBEROFARTICLES}} 3,331 Number of pages in content namespaces.
{{NUMBEROFFILES}} 1,047 Number of uploaded files. 1.5+
{{NUMBEROFEDITS}} 137,025 Number of page edits. 1.10+
{{NUMBEROFVIEWS}} Template:NUMBEROFVIEWS Number of page views. Usually useless on a wiki using caching. 1.14+
{{NUMBEROFUSERS}} 23 Number of registered users. 1.7+
{{NUMBEROFADMINS}} 2 Number of users in the sysop group. 1.7+
{{NUMBEROFACTIVEUSERS}} 7 Number of active users, based on the criteria used in Special:Statistics. 1.15+
{{PAGESINCATEGORY:categoryname}}
{{PAGESINCAT:Help}}
31
31
[expensive] Number of pages in the given category (replace "Help" with the relevant category name). 1.13+
{{PAGESINNS:index}}
{{PAGESINNAMESPACE:index}}
not enabled Number of pages in the given namespace (replace index with the relevant namespace index). For instance, {{PAGESINNAMESPACE:14}} will output the number of category pages. {{PAGESINNS:0}} differs from {{NUMBEROFARTICLES}} in that the former includes redirects and disambiguation pages. 1.7+

Page names

Variable Output Description Versions
{{FULLPAGENAME}} Help:Variables Namespace and page title. 1.6+
{{PAGENAME}} Variables Page title.
{{BASEPAGENAME}} Variables Page title excluding the current subpage and namespace ("Title/foo" on "Title/foo/bar").

For more complex splitting, use {{#titleparts: }} from ParserFunctions extension.

1.7+
{{SUBPAGENAME}} Variables The subpage title ("foo" on "Title/foo"). 1.6+
{{SUBJECTPAGENAME}} Help:Variables The namespace and title of the associated content page. 1.7+
{{TALKPAGENAME}} Help talk:Variables The namespace and title of the associated talk page. 1.7+
{{PIPETRICK}} Magic words Performs the pipe trick on the page title. 1.16+

The {{BASEPAGENAME}} and {{SUBPAGENAME}} magic words only work in namespaces that have subpages enabled.

The following are URL-encoded equivalents:

  • {{FULLPAGENAMEE}}
  • {{PAGENAMEE}}
  • {{BASEPAGENAMEE}}
  • {{SUBPAGENAMEE}}
  • {{SUBJECTPAGENAMEE}}
  • {{TALKPAGENAMEE}}
  • {{PIPETRICKE}}

As of 1.15+, these can all take a parameter, allowing specification of the page to be operated on, instead of just the current page:

  • {{PAGENAME:Template:Main Page}}Main Page


Warning: Page titles containing certain characters, such as single quotes (') or asterisks *, may produce unexpected results when handled with these magic words, e.g. {{PAGEINSCATEGORY:{{PAGENAME}}}}.

Namespaces

Variable Output Description Versions
{{NAMESPACE}} Help Name of the page's namespace
{{SUBJECTSPACE}}
{{ARTICLESPACE}}
Help
Help
Name of the associated content namespace 1.7+
{{TALKSPACE}} Help talk Name of the associated talk namespace 1.7+

The following are URL-encoded equivalents:

  • {{NAMESPACEE}}
  • {{SUBJECTSPACEE}}
  • {{TALKSPACEE}}

These can take a page name parameter and will return the namespace of the page name parameter, instead of the current page's:

  • {{NAMESPACE:Template:Main Page}}Template
  • {{SUBJECTSPACE:Template:Main Page}}Template
  • {{TALKSPACE:Template:Main Page}}Template talk

Parser functions

Parser functions are very similar to variables, but take one or more parameters (technically, any magic word that takes a parameter is a parser function), and the name is sometimes prefixed with a hash to distinguish them from templates.

This page only describes parser functions that are integral to the MediaWiki software. Other parser functions may be added by MediaWiki extensions such as the ParserFunctions extension. For those see Help:Extension:ParserFunctions.

URL data

Parser function Input → Output Description Versions
{{localurl:page name}}
{{localurl:page name|query string}}
{{localurl:MediaWiki}} → /wiki/MediaWiki
{{localurl:MediaWiki|printable=yes}} → /index.php?title=MediaWiki&printable=yes
The relative path to the title.
{{fullurl:page name}}
{{fullurl:page name|query_string}}
{{fullurl:interwiki:remote page name|query_string}}
{{fullurl:Category:Top level}} → http://softmc.servotronix.com/wiki/Category:Top_level

{{fullurl:Category:Top level|action=edit}} → http://softmc.servotronix.com/index.php?title=Category:Top_level&action=edit

The absolute path to the title. This will also resolve Interwiki prefixes. 1.5+
{{filepath:file name}}
{{filepath:file name|nowiki}}
{{filepath:Wiki.png}} →
{{filepath:Wiki.png|nowiki}} →
The absolute URL to a media file. 1.12+
{{urlencode:string}} {{urlencode:x y z á é}} → x+y+z+%C3%A1+%C3%A9 The input encoded for use in URLs.
{{anchorencode:string}} {{anchorencode:x y z á é}} → x_y_z_.C3.A1_.C3.A9 The input encoded for use in URL section anchors (after the '#' symbol in a URL).

Namespaces

{{ns:}} returns the localized name for the namespace with that index. {{nse:}} is the URL-encoded equivalent. It does the same, but it replaces spaces with underscores, making it usable in external links.

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}} SoftMC-Wiki {{ns:5}} or {{ns:Project talk}} SoftMC-Wiki 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

Formatting

Usage Input → Output Description Version
{{lc:string}} {{lc:DATA CENTER}} → data center The lowercase input. 1.5+
{{lcfirst:string}} {{lcfirst:DATA CENTER}} → dATA CENTER The input with the very first character lowercase. 1.5+
{{uc:string}} {{uc:text transform}} → TEXT TRANSFORM The uppercase input. 1.5+
{{ucfirst:string}} {{ucfirst:text transform}} → Text transform The input with the very first character uppercase. 1.5+
{{formatnum:unformatted num}}
{{formatnum:formatted num|R}}
{{formatnum:987654321.654321}}
→ 987,654,321.654321
{{formatnum:987,654,321.654321|R}}
→ 987654321.654321
The input with decimal and decimal group separators, and localized digit script, according to the wiki's default locale. The |R parameter can be used to unformat a number, for use in mathematical situations.

{{#dateformat:date}} {{#formatdate:date}} {{#dateformat:date|format}} {{#formatdate:date|format}}

{{#dateformat:25 deC 2009|ymd}}
2009 DeC 25 (your pref), 2009 DeC 25 (default)
{{#formatdate:dec 25,2009|dmy}}
25 Dec 2009 (your pref), 25 Dec 2009 (default)
{{#dateformat:2009-12-25|mdy}}
December 25, 2009 (your pref), December 25, 2009 (default)
{{#formatdate:2009 dec 25|ISO 8601}}
2009-12-25 (your pref), 2009-12-25 (default)
{{#dateformat:25 decEmber|mdy}}
DecEmber 25 (your pref), DecEmber 25 (default)


Note: In the example above, "your pref" refers to your date preference on the current MediaWiki wiki only.

Formats an unlinked date based on user "Date format" preference, and adds metadata tagging it as a formatted date. For logged-out users and those who have not set a date format in their preferences, dates can be given a default: mdy, dmy, ymd, ISO 8601 (all case sensitive). If only the month and day are given, only mdy and dmy are valid. If a format is not specified or is invalid, the input format is used as a default. If the supplied date is not recognized as a valid date (specifically, if it contains any metadata such as from a nested use of these or a similar template), it is rendered unchanged, and no (additional) metadata is generated.

Although the ISO 8601 standard requires that dates be in the Gregorian calendar, the ISO parameter in this function will still format dates that fall outside the usual Gregorian range (e.g. dates prior to 1583). Also, the magic word cannot properly convert between negative years (used with ISO 8601) and years BC or years BCE (used in general writing).

1.15+
{{padleft:xyz|stringlength}}
{{padleft:xyz|strlen|char}}{{padleft:xyz|strlen|string}}
{{padleft:xyz|5}} → 00xyz
{{padleft:xyz|5|_}} → __xyz {{padleft:xyz|5|abc}} → abxyz
Inserts a string of padding characters (character chosen in third parameter; default '0') of a specified length (second parameter) next to a chosen base character or variable (first parameter). The final digits or characters in the base replace the final characters in the padding; i.e. {{padleft:44|3|0}} produces 044. 1.8+
{{padright:xyz|stringlength}}
{{padright:xyz|strlen|char}}{{padright:xyz|strlen|string}}
{{padright:xyz|5}} → xyz00
{{padright:xyz|5|_}} → xyz__ {{padright:xyz|5|abc}} → xyzab
Identical to padleft, but adds padding characters to the right side.
{{plural:2|is|are}} {{plural:1|is|are}} → is
{{plural:2|is|are}} → are
Outputs the correct given pluralization form (parameters except first) depending on the count (first parameter). Plural transformations are used for languages like Russian based on "count mod 10".
{{grammar:N|noun}} Outputs the correct inflected form of the given word described by the inflection code after the colon (language-dependent). Grammar transformations are used for inflected languages like Polish. 1.7+