Help:Variable

From Meta, a Wikimedia project coordination wiki
(Redirected from Variables)
Jump to: navigation, search
Comment

See Help:Magic words on www.mediawiki.org for more information. The page here is currently kept for things not yet merged to www.mediawiki.org and for documentation specific to the Wikimedia Foundation.


MediaWiki Handbook: Contents, Readers, Editors, Moderators, System admins +/-

A variable can be considered a predefined template without parameters. See also Help:Parser function.

This is a list of variables that can be used in the wikitext. The way they are rendered vary with time (directly depending on time, or e.g. for number of articles, depending on the creation of other articles), on the project (it changes when the wikitext is copied), or on the page in which it occurs (it changes when the wikitext is copied, when the page is renamed, and when the page is included in another page).

On the left is the variable, on the right how it is rendered at this time, in this project, on this page.

The names of the variables form part of the set of so-called "magic words" the system uses.

With Special:ExpandTemplates one can view the value of a variable, or more generally, the expanded wikitext a variable or a wikitext with variables and/or template calls produces, as intermediate step toward rendering.

Constants

{{SITENAME}} Meta
{{SERVER}} //meta.wikimedia.org
{{SERVERNAME}} meta.wikimedia.org
{{CONTENTLANGUAGE}} en code of the site's default interface language ($wgLanguageCode)

Depending on page

{{NAMESPACE}} and {{NAMESPACEE}} return an empty string in the article namespace {{ns:0}}, see above and NS:0.

PAGENAMEE displays the page title in the form that is used in URLs, i.e. with underscores for spaces, and percent-encoding for special characters, and is therefore used for constructing URLs incl. query strings.

For example, on Template talk:!, SUBJECTPAGENAMEE would produce Template:%21. Don't encode PAGENAMEE etc. again, i.e. don't use it in the first parameter of fullurl: and similar parser functions, {{urlencode:%21}} = %2521 probably won't work as expected. Query strings  in PURL redirections are an exception.

The "EE" encoding examples shown above for this page are not very interesting, only TALKPAGENAMEE and TALKSPACEE differ from TALKPAGENAME and TALKSPACE. See Help:Link and Help:Magic words for other examples.

In a subpage, [[../]] renders as a link to the parent page. For example, on m:Link/a/b it gives an internal link to m:Link/a, see Help:Link#Subpage feature.

"{{REVISIONID}}" → "5321461" [1] showing the current unique revision number of a saved page as used for diffs in the page history is in essence useless, it can't be substituted and also doesn't work in preview.

Varying with time

See also: :en:Category:Date-computing templates

Time

The time in UTC. Note that if the page was displayed by the same user and has not changed (page 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}} 26 Displays the current day in numeric form.
{{CURRENTDAY2}} 26 [MW1.6+] Same as {{CURRENTDAY}}, but with leading zero (01 .. 31).
{{CURRENTDAYNAME}} Saturday Name of the day in the language of the project or English.
{{CURRENTDOW}} 6 Same as {{CURRENTDAYNAME}}, but as a number (0=Sunday, 1=Monday...).
{{CURRENTMONTH}} 07 The number 01 .. 12 of the month.
{{CURRENTMONTHABBREV}} Jul [MW1.5+] Same as {{CURRENTMONTH}}, but in abbreviated form as Jan .. Dec.
{{CURRENTMONTHNAME}} July Same as {{CURRENTMONTH}}, but in named form January .. December.
{{CURRENTTIME}} 04:47 The current time (00:00 .. 23:59).
{{CURRENTHOUR}} 04 The current hour (00 .. 23).
{{CURRENTWEEK}} 30 Number of the current week (1-53) according to ISO 8601 with no leading zero.
{{CURRENTYEAR}} 2014 Returns the current year.
{{CURRENTTIMESTAMP}} 20140726044714 [MW1.7+] ISO 8601 time stamp.

Local time

Local time depends on the local timezone of the wiki, not the time zone in the user preferences. These should generally use {{#time:}} if ParserFunctions are installed, but the following legacy variables are also available from MediaWiki 1.8+.

Word Example Explanation
{{LOCALDAY}} 26 Displays the local day of the month in numeric form.
{{LOCALDAY2}} 26 Same as {{LOCALDAY}}, but with a leading zero (01 .. 31).
{{LOCALDAYNAME}} Saturday Name of the day in the language of the project or English.
{{LOCALDOW}} 6 Same as {{LOCALDAYNAME}}, but as a number (0=Sunday, 1=Monday...).
{{LOCALMONTH}} 07 The number 01 .. 12 of the month.
{{LOCALMONTHABBREV}} Jul Same as {{LOCALMONTH}}, but in abbreviated form as Jan .. Dec.
{{LOCALMONTHNAME}} July Same as {{LOCALMONTH}}, but in named form as January .. December.
{{LOCALTIME}} 04:47 The local time (00:00 .. 23:59).
{{LOCALHOUR}} 04 The local hour (00 .. 23).
{{LOCALWEEK}} 30 Number of the local week (1-53) according to ISO 8601 with no leading zero.
{{LOCALYEAR}} 2014 Returns the local year.
{{LOCALTIMESTAMP}} 20140726044714 ISO 8601 time stamp.

Because of the way MediaWiki and most browsers cache HTML pages, time variables which change more often than once a day will typically show the time the page was last cached, rather than the current time.

Statistics

See Statistics.

Substitution

Main article: Help:Substitution

When {{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}} is included and thereby substituted, the timestamp of doing that is put in the wikitext, and similarly for other variables. Examples:

{{CURRENTTIMESTAMP}}
20140726044714 - stays a variable on pages including the template
{{subst:CURRENTTIMESTAMP}}
20060526024210 - became a substituted constant in the template
{{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}}
20140726044714 - becomes a constant at the time of its inclusion

Templates with the "includeonly subst magic" must also be subst-ed.

Other

Word Example Example results Explanation
{{PAGESINCATEGORY:category}}
{{PAGESINCATEGORY:category|R}}
{{PAGESINCATEGORY:User en}}
{{PAGESINCATEGORY:User en|R}}
3,599
3599
[MW1.13+] Returns the number of pages in a given category.
{{PAGESINCAT:category}}
{{PAGESINCAT:category|R}}
{{PAGESINCAT:User en}}
{{PAGESINCAT:User en|R}}
3,599
3599
[MW1.13+] Alias of PAGESINCATEGORY.

Examples of combinations with parser functions

{{fullurl:{{FULLPAGENAME}}|action=edit}}
//meta.wikimedia.org/w/index.php?title=Help:Variable&action=edit
 
{{fullurl:w:en:Special:Whatlinkshere|target={{NAMESPACE}}:Contents}}
//en.wikipedia.org/wiki/en:Special:Whatlinkshere?target=Help:Contents
 
{{fullurl:m:Special:Whatlinkshere|target={{FULLPAGENAME}}}}
//meta.wikimedia.org/w/index.php?title=Special:Whatlinkshere&target=Help:Variable
 
[[{{NAMESPACE}} talk:{{PAGENAME}}]]
Help talk:Variable
 
{{fullurl:{{NAMESPACE}} talk:{{PAGENAME}}}}
//meta.wikimedia.org/wiki/Help_talk:Variable
 

The old form {{SERVER}}{{localurl:page }} does not always work:

{{SERVER}}{{localurl:Wikipedia:Category }} gives //meta.wikimedia.org//en.wikipedia.org/wiki/Category

Apart from those problems it is in essence the same as {{fullurl:page }} in recent (1.5+) versions of the software.

In a template, for a link to a page which depends on a template parameter, the external link style is used even for internal links, to avoid that the system links to the edit page even if the page exists. To construct the external link, variables can also be useful.

Variable in the form of a template call

If the syntax of a template call with parameters is applied with the name of a variable, depending on the variable the parameters are either ignored or cause the variable to be interpreted as a (non-existing) template:

  1. Variables like {{NUMBEROFPAGES:R}} = 5137398 with a "raw" format are always handled as variable, {{NUMBEROFPAGES:R|Para|meter}} = 5137398.
  2. Other variables like {{CURRENTDAYNAME}} = Saturday are handled as template for given parameter(s), {{CURRENTDAYNAME|x}} = Template:CURRENTDAYNAME.
  3. Parser functions like {{lc: Lower Case}} = lower case ignore extraneous parameters, {{lc: Lower|Case}} = lower.
  4. Parser function ns (e.g. {{ns: 1}} = Talk) gives an empty string for a non-applicable numerical parameter value, and evaluates in the case of a non-numerical parameter value as template (the template name being the whole text until "|" or "}}"):
    {{ns: 1234}} =
    {{ns: t|abc}} = Template:Ns: t
  5. Parser functions like fullurl don't support the ../ notation, and in namespaces supporting subpages this has odd effects: like above, they evaluate such an invalid parameter value as template, see Link/a and Link/a/b. Here it just renders the wikitext:
    {{fullurl:../a}} = Template:Fullurl:../a.
    The cases #2, #4, and #5 resulting in template calls are probably related.


See also

In the case of transclusion from an image page on Commons to the corresponding page on another project, the variables refer to the page on Commons, see Tst.png.

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
Reading
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
Editing
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
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 · Embed page
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Languages: English  · العربية · català · Deutsch · Esperanto · français · italiano · 日本語 · 中文