Help:Variable

From Web
Jump to: navigation, search

Template:H:h A variable can be considered a predefined template.

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.

Constants depending on parameters

Most of the following "constants" are in fact parser functions also known as predefined templates, and might change, e.g. if the {{SERVERNAME}} is changed. They are listed here for historical reasons:

{{ns:-2}} {{ns:Media}} Media Media
{{ns:-1}} {{ns:Special}} Special Special
{{ns:0}}   ( main namespace ) ( empty string )
{{ns:1}}  {{ns:Talk}} Talk Talk
{{ns:2}}  {{ns:User}} User User
{{ns:3}}  {{ns:User_talk}} User talk User talk
{{ns:4}}  {{ns:Project}} Web Web
{{ns:5}}  {{ns:Project_talk}} Web talk Web talk
{{ns:6}}  {{ns:Image}} File File
{{ns:7}}  {{ns:Image_talk}} File talk File talk
{{ns:8}}  {{ns:MediaWiki}} MediaWiki MediaWiki
{{ns:9}} {{ns:MediaWiki_talk}} MediaWiki talk MediaWiki talk
{{ns:10}} {{ns:Template}} Template Template
{{ns:11}} {{ns:Template_talk}} Template talk Template talk
{{ns:12}} {{ns:Help}} Help Help
{{ns:13}} {{ns:Help_talk}} Help talk Help talk
{{ns:14}} {{ns:Category}} Category Category
{{ns:15}} {{ns:Category_talk}} Category talk Category talk
{{ns:100}} {{ns:102}}, etc. (customized )
{{ns:101}} {{ns:103}}, etc.
{{SITENAME}} Web
{{SERVER}} https://web.ing.unimo.it
{{SERVERNAME}} web.ing.unimo.it
{{localurl:fullpagename}} /wiki/index.php/Fullpagename
{{localurl:page|query=x}} /wiki/index.php?title=Page&query=x
{{localurl:a&b!}}
{{localurle:a&b!}}
/wiki/index.php/A%26b!
/wiki/index.php/A%26b!
{{urlencode:a&b!}} a%26b%21
{{fullurl:fullpagename}} https://web.ing.unimo.it/wiki/index.php/Fullpagename
{{fullurl:a&b!|u=v}}  https://web.ing.unimo.it/wiki/index.php?title=A%26b!&u=v
{{fullurle:a&b!|u=v}} https://web.ing.unimo.it/wiki/index.php?title=A%26b!&u=v

The parser function localurl: replaces spaces by underscores and special characters by escape codes, e.g. {{localurl:a !}} gives /wiki/index.php/A_!. The main purpose was to create a link to a given page in external link style in the same project or a project which uses the same string in the URL between the server name and the page name. This function is now better served by less verbose fullurl: constructs, {{fullurl:page}} is a shorthand for {{SERVER}}{{localurl:page}}.

Both fullurle: and localurle: performed additional character escaping on the resulting link, but no example is known where that still has any additional effect.

Note that fullurl: and localurl: don't encode special characters and spaces in the optional query-string parameter. At least for spaces this will result in broken URLs:
{{fullurl:m:Special:Contributions|target=Jimbo Wales&limit=10}}
https://web.ing.unimo.it/wiki/index.php?title=M:Special:Contributions&target=Jimbo Wales&limit=10

With target={{urlencode:Jimbo Wales}}&limit=10 as query-string it works:
https://web.ing.unimo.it/wiki/index.php?title=M:Special:Contributions&target=Jimbo+Wales&limit=10

The new urlencode: encodes spaces as "+", not "_" or the generally supported "%20", this might have interesting effects, take care. Trailing spaces are stripped, leading spaces respected: {{urlencode:  @ !  }} yields %40+%21.

For obvious reasons encoding "}}" or "|" cannot work directly. Don't encode "=", "&", or ";" in structured query-strings unless you really want it.

Example

Say you want to create a link in a template to the block log for blocked usernames -> "{{fullurl:Special:Log/block|user=User:{{{1}}} }}". This won't work with spaces in the name like "Willy on Wheels" (unless they are manually underlined) as you'd get: "https://web.ing.unimo.it/wiki/index.php?title=Special:Log/block&user=User:Willy on Wheels", so what you can do is escape it with: "{{fullurl:Special:Log/block|user=User:{{urlencode:{{{1}}}}} }}", giving you "https://web.ing.unimo.it/wiki/index.php?title=Special:Log/block&user=User:Willy+on+Wheels"

Also, the magic words for page name like {{PAGENAME}} {{FULLPAGENAME}} etc all have 'escaped' versions: {{PAGENAMEE}} {{FULLPAGENAMEE}} etc.

Depending on page

{{PAGENAME}} Variable {{PAGENAMEE}} Variable
{{NAMESPACE}} Help {{NAMESPACEE}} Help
{{FULLPAGENAME}} Help:Variable {{FULLPAGENAMEE}} Help:Variable
    {{REVISIONID}} 1682
{{TALKSPACE}} Help talk {{SUBJECTSPACE}} Help
{{TALKSPACEE}} Help_talk {{SUBJECTSPACEE}} Help
{{TALKPAGENAME}} Help talk:Variable {{SUBJECTPAGENAME}} Help:Variable
{{TALKPAGENAMEE}} Help_talk:Variable {{SUBJECTPAGENAMEE}} Help:Variable
{{ARTICLESPACE}} Help {{ARTICLEPAGENAME}} Help:Variable
{{ARTICLESPACEE}} Help {{ARTICLEPAGENAMEE}} Help:Variable
{{BASEPAGENAME}} Variable {{SUBPAGENAME}} Variable
{{BASEPAGENAMEE}} Variable {{SUBPAGENAMEE}} Variable

For the rendering on page A, these variables depend on page A, even if page A contains the variable due to inclusion of page B. Variables in the sort key of a category tag refer to the page with the tag, not the category page where it takes effect.

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

Template:Evaldemo 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

{{CURRENTYEAR}} 2019   {{CURRENTMONTH}} 07
{{CURRENTMONTHNAME}} July   {{CURRENTMONTHABBREV}} Jul
{{CURRENTMONTHNAMEGEN}} July   {{CURRENTWEEK}} 30
{{CURRENTDAY}} 23   {{CURRENTDAY2}} 23
{{CURRENTDAYNAME}} Tuesday   {{CURRENTDOW}} 2
{{CURRENTTIME}} 08:20   {{CURRENTVERSION}} 1.31.0
{{CURRENTTIMESTAMP}} 20190723082046
{{CURRENTHOUR}} 08
{{NUMBEROFADMINS}} 4   {{NUMBEROFADMINS:R}} 4
{{NUMBEROFARTICLES}} 148   {{NUMBEROFARTICLES:R}} 148
{{NUMBEROFFILES}} 406   {{NUMBEROFFILES:R}} 406
{{NUMBEROFPAGES}} 804   {{NUMBEROFPAGES:R}} 804
{{NUMBEROFUSERS}} 295   {{NUMBEROFUSERS:R}} 295

Time variables which change more often than once a day are generally useful only as curiosities. Because of the way article HTML is cached, these variables may be wrong by up to 24 hours, and so are not a reliable way to tell the user the current time.

Please note that a template using more than one CURRENT variable directly or indirectly is suspicious. There can be critical races near hh:mm:59. The following code to determine the minute can produce spurious results if the timestamp changes during the evaluation: {{#expr:(( {{CURRENTTIMESTAMP}}-{{CURRENTTIMESTAMP}} mod 100)/100) mod 100}} = {{#expr: (( 20190723082046 - 20190723082046 mod 100)/100) mod 100}}
This is actually an intermittent bug with MOD depending on the size (not the value) of CURRENTTIMESTAMP, see Template:Tim.

CURRENTDOW 
0=Sunday, 1=Monday, .. 6=Saturday.
CURRENTWEEK 
is the number of the current week (1-53) according to ISO 8601 with no leading zero.
CURRENTDAY2 
adds a leading zero to days 1...9, this allows to construct the ISO date formats like 2019-07-23T08:20Z.
CURRENTMONTHNAMEGEN 
is the genitive grammatical form of the month name (used in Finnish Template:Unclear and in Slovenian).
NUMBEROFARTICLES 
see Help:Article count and Special: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}}
20190723082046 - stays a variable on pages including the template
{{subst:CURRENTTIMESTAMP}}
20060526024210 - became a substituted constant in the template
{{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}}
20190723082046 - becomes a constant at the time of its inclusion

New NUMBEROF syntax

The "old" (for some weeks) syntax was {{ NUMBEROFitem|R }} to get the "raw" number without fancy comma separators. The new syntax is {{ NUMBEROFitem:R }} with a colon to get the "raw" number of whatever. This also affects the new magic words PAGESINNS and PAGESINNAMESPACE, now disabled by default.

Using the old format will (try to) include a corresponding template. Because the "old" feature is in fact rather new it might be possible to fix the syntax using What links here:
NUMBEROF ADMINS, ARTICLES, FILES, PAGES, USERS.
PAGESINNS 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 100, 101, 102, 103, etc.

Examples of combinations

{{fullurl:{{FULLPAGENAME}}|action=edit}}
https://web.ing.unimo.it/wiki/index.php?title=Help:Variable&action=edit
 
{{fullurl:w:en:Special:Whatlinkshere|target={{NAMESPACE}}:Contents}}
https://web.ing.unimo.it/wiki/index.php?title=W:en:Special:Whatlinkshere&target=Help:Contents
 
{{fullurl:m:Special:Whatlinkshere|target={{FULLPAGENAME}}}}
https://web.ing.unimo.it/wiki/index.php?title=M:Special:Whatlinkshere&target=Help:Variable
 
{{fullurl:{{FULLPAGENAME}}|action=edit}}
https://web.ing.unimo.it/wiki/index.php?title=Help:Variable&action=edit
 
[[{{NAMESPACE}} talk:{{PAGENAME}}]]
Help talk:Variable
 
{{fullurl:{{NAMESPACE}} talk:{{PAGENAME}}}}
https://web.ing.unimo.it/wiki/index.php/Help_talk:Variable
 

The old form {{SERVER}}{{localurl:page }} 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}} = 804 with a "raw" format are always handled as variable, {{NUMBEROFPAGES:R|Para|meter}} = 804.
  2. Other variables like {{CURRENTDAYNAME}} = Tuesday 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 a non-numerical parameter value as template, even if it has the name of a variable:
    {{ns: 1234}} =
    {{ns: t|abc}} = Template:Ns: t
    {{ns: CURRENTDAYNAME}} = Template:Ns: CURRENTDAYNAME.
  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

Template:H:f