Difference between revisions of "Help:Variable"

From Web
Jump to navigation Jump to search
m (1 revision(s))
(No difference)

Revision as of 18:33, 18 November 2006

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.
{{SERVER}} //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
{{urlencode:a&b!}} a%26b%21
{{fullurl:fullpagename}} //web.ing.unimo.it/wiki/index.php/Fullpagename
{{fullurl:a&b!|u=v}}  //web.ing.unimo.it/wiki/index.php?title=A%26b!&u=v
{{fullurle:a&b!|u=v}} //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}}
//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:

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.


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: "//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 "//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
{{FULLPAGENAME}} Help:Variable {{FULLPAGENAMEE}} Help:Variable
    {{REVISIONID}} 1683
{{TALKPAGENAME}} Help talk:Variable {{SUBJECTPAGENAME}} Help:Variable
{{TALKPAGENAMEE}} Help_talk:Variable {{SUBJECTPAGENAMEE}} Help:Variable
{{BASEPAGENAME}} Variable {{SUBPAGENAME}} 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

{{CURRENTTIMESTAMP}} 20221208174709

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: (( 20221208174709 - 20221208174709 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.

0=Sunday, 1=Monday, .. 6=Saturday.
is the number of the current week (1-53) according to ISO 8601 with no leading zero.
adds a leading zero to days 1...9, this allows to construct the ISO date formats like 2022-12-08T17:47Z.
is the genitive grammatical form of the month name (used in Finnish Template:Unclear and in Slovenian).
see Help:Article count and Special:Statistics..


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:

20221208174709 - stays a variable on pages including the template
20060526024210 - became a substituted constant in the template
20221208174709 - 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:
PAGESINNS 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 100, 101, 102, 103, etc.

Examples of combinations

[[{{NAMESPACE}} talk:{{PAGENAME}}]]
Help talk:Variable
{{fullurl:{{NAMESPACE}} talk:{{PAGENAME}}}}

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}} = 814 with a "raw" format are always handled as variable, {{NUMBEROFPAGES:R|Para|meter}} = 814.
  2. Other variables like {{CURRENTDAYNAME}} = Thursday 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
  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