Changes

Jump to: navigation, search

Help:Variable

18,525 bytes added, 14:09, 5 July 2006
==Variable in the form of a template call== restored, updated
{{H:h|editor toc}}
A '''variable''' can be considered a [[Help:Template#Predefined_templates|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 "[[Help:Magic words|magic words]]" the system uses.

==Constants depending on parameters==

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

{|
| <code>{&#123;ns:-2&#125;} {&#123;ns:Media}}</code>
| {{ns:-2}} {{ns:Media}}
|-
| <code>{&#123;ns:-1&#125;} {&#123;ns:Special&#125;}</code>
| {{ns:-1}} {{ns:Special}}
|-
| <code>{&#123;ns:0&#125;} &#160; </code> (<small> main namespace </small>)
| {{ns:0}} (<small> empty string </small>)
|-
| <code>{&#123;ns:1&#125;}&#160; {&#123;ns:Talk&#125;}</code>
| {{ns:1}} {{ns:Talk}}
|-
| <code>{&#123;ns:2&#125;}&#160; {&#123;ns:User&#125;}</code>
| {{ns:2}} {{ns:User}}
|-
| <code>{&#123;ns:3&#125;}&#160; {&#123;ns:User_talk&#125;}</code>
| {{ns:3}} {{ns:User_talk}}
|-
| <code>{&#123;ns:4&#125;}&#160; {&#123;ns:Project&#125;}</code>
| {{ns:4}} {{ns:Project}}
|-
| <code>{&#123;ns:5&#125;}&#160; {&#123;ns:Project_talk&#125;}</code>
| {{ns:5}} {{ns:Project_talk}}
|-
| <code>{&#123;ns:6&#125;}&#160; {&#123;ns:Image&#125;}</code>
| {{ns:6}} {{ns:Image}}
|-
| <code>{&#123;ns:7&#125;}&#160; {&#123;ns:Image_talk&#125;}</code>
| {{ns:7}} {{ns:Image_talk}}
|-
| <code>{&#123;ns:8&#125;}&#160; {&#123;ns:MediaWiki&#125;}</code>
| {{ns:8}} {{ns:MediaWiki}}
|-
| <code>{&#123;ns:9&#125;} {&#123;ns:MediaWiki_talk&#125;}</code>
| {{ns:9}} {{ns:MediaWiki_talk}}
|-
| <code>{&#123;ns:10&#125;} {&#123;ns:Template&#125;}</code>
| {{ns:10}} {{ns:Template}}
|-
| <code>{&#123;ns:11&#125;} {&#123;ns:Template_talk&#125;}</code>
| {{ns:11}} {{ns:Template_talk}}
|-
| <code>{&#123;ns:12&#125;} {&#123;ns:Help&#125;}</code>
| {{ns:12}} {{ns:Help}}
|-
| <code>{&#123;ns:13&#125;} {&#123;ns:Help_talk&#125;}</code>
| {{ns:13}} {{ns:Help_talk}}
|-
| <code>{&#123;ns:14&#125;} {&#123;ns:Category&#125;}</code>
| {{ns:14}} {{ns:Category}}
|-
| <code>{&#123;ns:15&#125;} {&#123;ns:Category_talk&#125;}</code>
| {{ns:15}} {{ns:Category_talk}}
|-
| <code>{&#123;ns:100&#125;} {&#123;ns:102&#125;}</code>, etc.
| {{ns:100}} {{ns:102}} (''customized''&#160;)
|-
| <code>{&#123;ns:101&#125;} {&#123;ns:103&#125;}</code>, etc.
| {{ns:101}} {{ns:103}}
|-
| <code><nowiki>{{SITENAME}}</nowiki></code>
| {{SITENAME}}
|-
| <code><nowiki>{{SERVER}}</nowiki></code>
| {{SERVER}}
|-
| <code><nowiki>{{SERVERNAME}}</nowiki></code>
| {{SERVERNAME}}
|-
| <code><nowiki>{{localurl:fullpagename}}</nowiki></code>
| {{localurl:fullpagename}}
|-
| <code><nowiki>{{localurl:page|query=x}}</nowiki></code>
| {{localurl:page|query=x}}
|-
| <code><nowiki>{{localurl:a&b!}}</nowiki><br /><nowiki>{{localurle:a&b!}}</nowiki></code>
| {{localurl:a&b!}}<br />{{localurle:a&b!}}
|-
| <code><nowiki>{{urlencode:a&b!}}</nowiki>
| {{urlencode:a&b!}}
|-
| <code><nowiki>{{fullurl:fullpagename}}</nowiki></code>
| <small>{{fullurl:fullpagename}}</small>
|-
| colspan="2" | <code><nowiki>{{fullurl:a&b!|u=v}}</nowiki> &#160;</code><small>{{fullurl:a&b!|u=v}}</small><br /><code><nowiki>{{fullurle:a&b!|u=v}}</nowiki>&#160;</code><small>{{fullurle:a&b!|u=v}}</small>
|}

The colon function <tt>localurl:<tt> replaces spaces by underscores and special characters by escape codes, e.g. {&#123;localurl:a !&#125;} gives {{localurl: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 <tt>fullurl:</tt> constructs, <code><nowiki>{{fullurl:page}}</nowiki></code> is a shorthand for <code><nowiki>{{SERVER}}{{localurl:page}}</nowiki></code>.

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

Note that <tt>fullurl:</tt> and <tt>localurl:</tt> don't encode special characters and spaces in the optional ''query-string'' parameter. At least for spaces this will result in broken URLs:<br />
<tt><nowiki>{{fullurl:m:Special:Contributions|target=Jimbo Wales&limit=10}}</nowiki></tt><br />
{{fullurl:m:Special:Contributions|target=Jimbo Wales&limit=10}}

With <tt><nowiki>target={{urlencode:Jimbo Wales}}&amp;limit=10</nowiki></tt> as ''query-string'' it works&#58;<br />
{{fullurl:m:Special:Contributions|target={{urlencode:Jimbo Wales}}&limit=10}}

The new <tt>urlencode:</tt> encodes spaces as "'''<tt>+</tt>'''", not "'''<tt>_</tt>'''" or the generally supported "'''<tt>%20</tt>'''", this might have interesting effects, take care. Trailing spaces are stripped, leading spaces respected:
<tt><nowiki>{{urlencode:&nbsp;&#160;@&#160;!&nbsp;&#160;}}</nowiki></tt> yields '''{{urlencode: @ ! }}'''.
<!-- weird nbsp #160 mixture works with Netscape navigator 2.02 -->

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

==Depending on page==

{| class="wikitable"
|-
|<code><nowiki>{{PAGENAME}}</nowiki> </code>||{{PAGENAME}}||<code><nowiki>{{PAGENAMEE}}</nowiki> </code>||{{PAGENAMEE}}
|-
|<code><nowiki>{{NAMESPACE}}</nowiki> </code>||{{NAMESPACE}}||<code><nowiki>{{NAMESPACEE}}</nowiki> </code>||{{NAMESPACEE}}
|-
|<code><nowiki>{{FULLPAGENAME}}</nowiki> </code>||{{FULLPAGENAME}}||<code><nowiki>{{FULLPAGENAMEE}}</nowiki> </code>||{{FULLPAGENAMEE}}
|-
|&#160;||&#160;<!-- intentionally empty -->
|<code><nowiki>{{REVISIONID}}</nowiki> </code>||{{REVISIONID}}
|-
|<code><nowiki>{{TALKSPACE}}</nowiki> </code>||{{TALKSPACE}}||<code><nowiki>{{SUBJECTSPACE}}</nowiki> </code>||{{SUBJECTSPACE}}
|-
|<code><nowiki>{{TALKSPACEE}}</nowiki> </code>||{{TALKSPACEE}}||<code><nowiki>{{SUBJECTSPACEE}}</nowiki> </code>||{{SUBJECTSPACEE}}
|-
|<code><nowiki>{{TALKPAGENAME}}</nowiki></code>||{{TALKPAGENAME}}||<code><nowiki>{{SUBJECTPAGENAME}}</nowiki> </code>||{{SUBJECTPAGENAME}}
|-
|<code><nowiki>{{TALKPAGENAMEE}}</nowiki></code>||{{TALKPAGENAMEE}}||<code><nowiki>{{SUBJECTPAGENAMEE}}</nowiki> </code>||{{SUBJECTPAGENAMEE}}
|-
|<code><nowiki>{{ARTICLESPACE}}</nowiki> </code>||{{ARTICLESPACE}}||<code><nowiki>{{ARTICLEPAGENAME}}</nowiki></code>||{{ARTICLEPAGENAME}}
|-
|<code><nowiki>{{ARTICLESPACEE}}</nowiki> </code>||{{ARTICLESPACEE}}||<code><nowiki>{{ARTICLEPAGENAMEE}}</nowiki></code>||{{ARTICLEPAGENAMEE}}
|-
|<code><nowiki>{{BASEPAGENAME}}</nowiki> </code>||{{BASEPAGENAME}}||<code><nowiki>{{SUBPAGENAME}}</nowiki> </code>||{{SUBPAGENAME}}
|-
|<code><nowiki>{{BASEPAGENAMEE}}</nowiki> </code>||{{BASEPAGENAMEE}}||<code><nowiki>{{SUBPAGENAMEE}}</nowiki> </code>||{{SUBPAGENAMEE}}
|}

For the rendering on page A, these variables depend on page A, even if page A contains the variable due to [[help:template|inclusion]] of page B. Variables in the [[Help:Category#Sort_key|sort key]] of a category tag refer to the page with the tag, not the category page where it takes effect.

<nowiki>{{NAMESPACE}}</nowiki> and <nowiki>{{NAMESPACEE}}</nowiki> return an empty string in the article namespace <nowiki>{{ns:0}}</nowiki>,
see above and [[Help:Colon function#NS:0|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 [[m:Template talk:!|Template talk:!]], SUBJECTPAGENAMEE would produce <tt>Template:%21</tt>.
Don't encode PAGENAMEE etc. again, i.e. don't use it in the first parameter of '''fullurl:''' and similar colon functions,
<nowiki>{{urlencode:%21}}</nowiki> = {{urlencode:%21}} probably won't work as expected. <small>''Query strings''&#160; in [[purlnet:|PURL]] redirections are an exception.</small>

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, <tt><nowiki>[[../]]</nowiki></tt> 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]].

{{evaldemo|REVISIONID|s==}} showing the '''current''' unique revision number of a saved page as used for [[Help:diff|diff]]s in the [[Help:page history|page history]] is in essence [[mediazilla:6181|useless]], it can't be substituted and also doesn't work in preview.

==Varying with time==
{|
|<code><nowiki>{{CURRENTYEAR}}</nowiki> </code>
|{{CURRENTYEAR}}
| &#160;
|<code><nowiki>{{CURRENTMONTH}}</nowiki> </code>
|{{CURRENTMONTH}}
|-
|<code><nowiki>{{CURRENTMONTHNAME}}</nowiki> </code>
|{{CURRENTMONTHNAME}}
| &#160;
|<code><nowiki>{{CURRENTMONTHABBREV}}</nowiki> </code>
|{{CURRENTMONTHABBREV}}
|-
|<code><nowiki>{{CURRENTMONTHNAMEGEN}}</nowiki> </code>
|{{CURRENTMONTHNAMEGEN}}
| &#160;
|<code><nowiki>{{CURRENTWEEK}}</nowiki> </code>
|{{CURRENTWEEK}}
|-
|<code><nowiki>{{CURRENTDAY}}</nowiki> </code>
|{{CURRENTDAY}}
| &#160;
|<code><nowiki>{{CURRENTDAY2}}</nowiki> </code>
|{{CURRENTDAY2}}
|-
|<code><nowiki>{{CURRENTDAYNAME}}</nowiki> </code>
|{{CURRENTDAYNAME}}
| &#160;
|<code><nowiki>{{CURRENTDOW}}</nowiki> </code>
|{{CURRENTDOW}}
|-
|<code><nowiki>{{CURRENTTIME}}</nowiki> </code>
|{{CURRENTTIME}}
| &#160;
|<code><nowiki>{{CURRENTVERSION}}</nowiki> </code>
|{{CURRENTVERSION}}
|-
|<code><nowiki>{{CURRENTTIMESTAMP}}</nowiki> </code>
|colspan="3"|{{CURRENTTIMESTAMP}}
|-
|<code><nowiki>{{NUMBEROFADMINS}}</nowiki> </code>
|{{NUMBEROFADMINS}}
| &#160;
|<code><nowiki>{{NUMBEROFADMINS:R}}</nowiki> </code>
|{{NUMBEROFADMINS:R}}
|-
|<code><nowiki>{{NUMBEROFARTICLES}}</nowiki> </code>
|{{NUMBEROFARTICLES}}
| &#160;
|<code><nowiki>{{NUMBEROFARTICLES:R}}</nowiki> </code>
|{{NUMBEROFARTICLES:R}}
|-
|<code><nowiki>{{NUMBEROFFILES}}</nowiki> </code>
|{{NUMBEROFFILES}}
| &#160;
|<code><nowiki>{{NUMBEROFFILES:R}}</nowiki> </code>
|{{NUMBEROFFILES:R}}
|-
|<code><nowiki>{{NUMBEROFPAGES}}</nowiki> </code>
|{{NUMBEROFPAGES}}
| &#160;
|<code><nowiki>{{NUMBEROFPAGES:R}}</nowiki> </code>
|{{NUMBEROFPAGES:R}}
|-
|<code><nowiki>{{NUMBEROFUSERS}}</nowiki> </code>
|{{NUMBEROFUSERS}}
| &#160;
|<code><nowiki>{{NUMBEROFUSERS:R}}</nowiki> </code>
|{{NUMBEROFUSERS:R}}
|}

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 <tt>CURRENT</tt> variable directly or indirectly is suspicious. There can be critical races near <tt>hh:mm:'''59'''</tt>.
The following code to determine the minute can produce spurious results if the timestamp changes during the evaluation:
<small><tt><nowiki>{{#expr:(( {{CURRENTTIMESTAMP}}-{{CURRENTTIMESTAMP}} mod 100)/100) mod 100}}</nowiki></tt></small> = {{#expr: (( {{CURRENTTIMESTAMP}} - {{CURRENTTIMESTAMP}} mod 100)/100) mod 100}}<br />
''This is actually an intermittent bug with MOD depending on the size (not the value) of CURRENTTIMESTAMP, see'' {{tim|CURRENTMINUTE}}.

;CURRENTDOW :0=Sunday, 1=Monday, .. 6=Saturday.
;CURRENTWEEK :is the number of the current week (1-53) according to [[w:ISO 8601|ISO 8601]] with no leading zero.
;CURRENTDAY2 :adds a leading zero to days 1...9, this allows to construct the ISO date formats like <tt>{{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY2}}'''T'''{{CURRENTTIME}}'''Z'''</tt>.
;CURRENTMONTHNAMEGEN :is the genitive grammatical form of the month name (used in Finnish {{unclear}}).<!-- I didn't find it in languageFi.php -->
;NUMBEROFARTICLES :see [[Help:Article count]] and [[Special:Statistics]].<!-- and [[mw:Help:$wgUseCommaCount|$wgUseCommaCount]] -->.

===Substitution===

:''Main article: '''[[Help:Substitution]]'''''

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

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

=== New NUMBEROF syntax ===

The "old" (for some weeks) syntax was {&#123;<small>&#160;</small>NUMBEROF''item''<tt>'''|'''</tt>R<small>&#160;</small>&#125;} to get the "raw" number without fancy comma separators.
The new syntax is {&#123;<small>&#160;</small>NUMBEROF''item''<tt>''':'''</tt>R<small>&#160;</small>&#125;} 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 [[Help:What links here|What links here]]&#58;
:NUMBEROF [[Special:Whatlinkshere/Template:NUMBEROFADMINS|ADMINS]], [[Special:Whatlinkshere/Template:NUMBEROFARTICLES|ARTICLES]], [[Special:Whatlinkshere/Template:NUMBEROFFILES|FILES]], [[Special:Whatlinkshere/Template:NUMBEROFPAGES|PAGES]], [[Special:Whatlinkshere/Template:NUMBEROFUSERS|USERS]].
:PAGESINNS [[Special:Whatlinkshere/Template:PAGESINNS:0|0]], [[Special:Whatlinkshere/Template:PAGESINNS:1|1]], [[Special:Whatlinkshere/Template:PAGESINNS:2|2]], [[Special:Whatlinkshere/Template:PAGESINNS:3|3]], [[Special:Whatlinkshere/Template:PAGESINNS:4|4]], [[Special:Whatlinkshere/Template:PAGESINNS:5|5]], [[Special:Whatlinkshere/Template:PAGESINNS:6|6]], [[Special:Whatlinkshere/Template:PAGESINNS:7|7]], [[Special:Whatlinkshere/Template:PAGESINNS:8|8]], [[Special:Whatlinkshere/Template:PAGESINNS:9|9]], [[Special:Whatlinkshere/Template:PAGESINNS:10|10]], [[Special:Whatlinkshere/Template:PAGESINNS:11|11]], [[Special:Whatlinkshere/Template:PAGESINNS:12|12]], [[Special:Whatlinkshere/Template:PAGESINNS:100|100]], [[Special:Whatlinkshere/Template:PAGESINNS:101|101]], [[Special:Whatlinkshere/Template:PAGESINNS:102|102]], [[Special:Whatlinkshere/Template:PAGESINNS:103|103]], etc.

==Examples of combinations==

;<code><nowiki>{{fullurl:{{FULLPAGENAME}}|</nowiki>action=edit<nowiki>}}</nowiki></code>
:{{fullurl:{{FULLPAGENAME}}|action=edit}}
: &#160;
;<code><nowiki>{{fullurl:w:en:Special:Whatlinkshere|target={{NAMESPACE}}:Contents}}</nowiki></code>
:{{fullurl:w:en:Special:Whatlinkshere|target={{NAMESPACE}}:Contents}}
: &#160;
;<code><nowiki>{{fullurl:m:Special:Whatlinkshere|target={{FULLPAGENAME}}}}</nowiki></code>
:{{fullurl:m:Special:Whatlinkshere|target={{FULLPAGENAME}}}}
: &#160;
;<code><nowiki>{{fullurl:{{FULLPAGENAME}}|</nowiki>action=edit<nowiki>}}</nowiki></code>
:{{fullurl:{{FULLPAGENAME}}|action=edit}}
: &#160;
;<code><nowiki>[[{{NAMESPACE}} talk:{{PAGENAME}}]]</nowiki></code>
:[[{{NAMESPACE}} talk:{{PAGENAME}}]]
: &#160;
;<code><nowiki>{{fullurl:{{NAMESPACE}} talk:{{PAGENAME}}}}</nowiki></code>
:{{fullurl:{{NAMESPACE}} talk:{{PAGENAME}}}}
: &#160;

The old form <code><nowiki>{{SERVER}}{{localurl:</nowiki></code>''page''<small>&#160;</small><code>&#125;}</code> is in essence the same as
<code><nowiki>{{fullurl:</nowiki></code>''page''<small>&#160;</small><code>&#125;}</code> 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:

#Variables like {&#123;NUMBEROFPAGES:R&#125;} = {{NUMBEROFPAGES:R}} with a "raw" format are always handled as variable, {&#123;NUMBEROFPAGES:R|Para|meter&#125;}&#160;= {{NUMBEROFPAGES:R|Para|meter}}.
#Other variables like {&#123;CURRENTDAYNAME&#125;} = {{CURRENTDAYNAME}} are handled as template for given parameter(s), {&#123;CURRENTDAYNAME|x&#125;}&#160;= {{CURRENTDAYNAME|x}}.
#Colon functions like {&#123;lc: Lower Case&#125;} = {{lc: Lower Case}} ignore extraneous parameters, {&#123;lc:&#160;Lower|Case&#125;}&#160;= {{lc: Lower|Case}}.
#Colon function ns (e.g. {&#123;ns: 1&#125;} = {{ns: 1}}) 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:
#:{&#123;ns: 1234&#125;}&#160;= {{ns: 1234}}
#:{&#123;ns: t|abc&#125;}&#160;= {{ns: t|abc}}
#:{&#123;ns: CURRENTDAYNAME&#125;}&#160;= {{ns: CURRENTDAYNAME}}.
#Colon functions like fullurl don't support the <tt>../</tt> 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:
#:{&#123;fullurl:../a&#125;}&#160;= {{fullurl:../a}}.
#: The cases #2, #4, and #5 resulting in template calls are probably related.

==See also==
*[[Help:Colon function]]
*[[Help:Substitution]] - on applying "subst" to a variable or to a template using a variable
*[http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/includes/MagicWord.php MagicWord.php]

{{h:f|enname=Variable}}
Anonymous user

Navigation menu