Help: Variables: Difference between revisions

From A Wiki of Ice and Fire
Jump to: navigation, search
No edit summary
 
Mordin999 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{PD Help Page}}
'''Variables''' are a type of '''Magic words''' a strings of text that Wiki software associates with a return value or function. There are three general types of magic words:
MediaWiki knows some defined variables which can be used in texts. They are rendered differently depending on the time, the site and the page. Their syntax is similar to templates. If you want a page to show always the current time, you use <code><nowiki>{{CURRENTTIME}}</nowiki></code>. To distinguish variables from templates, most variables are capitalized.


<center>
*'''Variables''': these are uppercase words surrounded by double braces, ''e.g.'' '''<code><nowiki>{{FOO}}</nowiki></code>'''. As such, they look a lot like [[Help:Templates|templates]]. Note that templates use pre set ''parameters'', that are parsed and cashed once you save the page, not each time you load it.
{| {{Prettytable}}
*'''Behavior switches''': these are uppercase words surrounded by double underscores, ''e.g.'' '''__FOO__''' used for adjusting the layout or behavior of the page and can often be used to specify desired omissions and inclusions in the content.
*'''Parser functions''': very similar to variables, but take one or more parameters. See also [http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions Help:Extension:ParserFunctions] which offers great functionality for constructing advance templates.
 
 
Here are some useful magic words, for a full list see [http://www.mediawiki.org/wiki/Help:Magic_words Help:Magic words]
 
{| class="wikitable"
|-
|-
!{{Hl3}}|'''Description'''
! style="background:#A7C1F2" width=150px| Word
!{{Hl3}}|'''You type'''
! style="background:#A7C1F2" | Description
!{{Hl3}}|'''You get'''
|-
|-
! {{Hl2}} colspan="3" | '''Date & Wiki variables'''
| <code><nowiki>__NOTOC__</nowiki></code>
| Hides the table of contents (TOC).
|-
|-
| Current month
| <code><nowiki>__FORCETOC__</nowiki></code>
|<nowiki>{{CURRENTMONTH}}</nowiki>  
| Forces the table of content to appear at its normal position (above the first header).
|{{CURRENTMONTH}}
|-
|-
| Current month
| <code><nowiki>__TOC__</nowiki></code>
|<nowiki>{{CURRENTMONTHNAME}}</nowiki>
| Places a table of contents at the word's current position (overriding <code><nowiki>__NOTOC__</nowiki></code>). If this is used multiple times, the table of contents will appear at the first word's position. It is possible to suppress the auto-generated section numbers, if the proper class exists locally at [[MediaWiki:Common.css]], defined as <code>.tocnumber { display: none; }</code>.
|{{CURRENTMONTHNAME}}
|}
 
{| class="wikitable" width=100%
|-
|-
| Genitive form<br>of current month name
! style="background:#A7C1F2" width=150px | Variable
|<nowiki>{{CURRENTMONTHNAMEGEN}}</nowiki>
! style="background:#A7C1F2" | Output
|{{CURRENTMONTHNAMEGEN}}
! style="background:#A7C1F2" | Description
|-
|-
| Abbreviated month name
| <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
|<nowiki>{{CURRENTMONTHABBREV}}</nowiki>
| {{FULLPAGENAME}}
|{{CURRENTMONTHABBREV}}
| Namespace and page title.
|-
|-
|Day of the month
| <code><nowiki>{{PAGENAME}}</nowiki></code>
|<nowiki>{{CURRENTDAY}}</nowiki>
| {{PAGENAME}}
|{{CURRENTDAY}}
| Page title.
|-
|Day of the week
|<nowiki>{{CURRENTDOW}}</nowiki>
|{{CURRENTDOW}}
|-
|Day of the week
|<nowiki>{{CURRENTDAYNAME}}</nowiki>
|{{CURRENTDAYNAME}}
|-
| Week
|<nowiki>{{CURRENTWEEK}}</nowiki>
|{{CURRENTWEEK}}
|-
| Year
|<nowiki>{{CURRENTYEAR}}</nowiki>
|{{CURRENTYEAR}}
|-
| current time
|<nowiki>{{CURRENTTIME}}</nowiki>
|{{CURRENTTIME}}
|-
| numbers of articles in this Wiki
|<nowiki>{{NUMBEROFARTICLES}}</nowiki>
|{{NUMBEROFARTICLES}}
|-
| numbers of uploaded files
|<nowiki>{{NUMBEROFFILES}}</nowiki>
|{{NUMBEROFFILES}}
|-
! {{Hl2}} colspan="3" | '''Namespaces'''
|-
|
|<nowiki>{{ns:-2}} or {{ns:Media}}</nowiki>
|{{ns:-2}}
|-
|
|<nowiki>{{ns:-1}} or {{ns:Special}}</nowiki>
|{{ns:-1}}
|-
|
|<nowiki>{{ns:1}} or {{ns:Talk}}</nowiki>
| {{ns:1}}
|-
|
| <nowiki>{{ns:2}} or {{ns:User}}</nowiki>
| {{ns:2}}
|-
|
| <nowiki>{{ns:3}} or {{ns:User_talk}}</nowiki>
| {{ns:3}}
|-
|
| <nowiki>{{ns:4}} or {{ns:Project}}</nowiki>
| {{ns:4}}
|-
|
| <nowiki>{{ns:5}} or {{ns:Project_talk}}</nowiki>
| {{ns:5}}
|-
|
| <nowiki>{{ns:6}} or {{ns:Image}}</nowiki>
| {{ns:6}}
|-
|
| <nowiki>{{ns:7}} or {{ns:Image_talk}}</nowiki>
| {{ns:7}}
|-
|
| <nowiki>{{ns:8}} or {{ns:MediaWiki}}</nowiki>
| {{ns:8}}
|-
|
| <nowiki>{{ns:9}} or {{ns:MediaWiki_talk}}</nowiki>
| {{ns:9}}
|-
|-
|
| <code><nowiki>{{BASEPAGENAME}}</nowiki></code>
| <nowiki>{{ns:10}} or {{ns:Template}}</nowiki>
| {{BASEPAGENAME}}
| {{ns:10}}
| Page title excluding the current subpage and namespace ("Title/foo" on "Title/foo/bar").
For more complex splitting, use <code><nowiki>{{</nowiki>#titleparts<nowiki>}}</nowiki></code> from [http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23titleparts ParserFunctions extension].
|-
|-
|
| <code><nowiki>{{SUBPAGENAME}}</nowiki></code>
| <nowiki>{{ns:11}} or {{ns:Template_talk}}</nowiki>
| {{SUBPAGENAME}}
| {{ns:11}}
| The subpage title ("foo" on "Title/foo").
|-
|-
|
| <code><nowiki>{{SUBJECTPAGENAME}}</nowiki></code>
| <nowiki>{{ns:12}} or {{ns:Help}}</nowiki>
| {{SUBJECTPAGENAME}}
| {{ns:12}}
| The namespace and title of the associated subject page.
|-
|-
|
| <code><nowiki>{{TALKPAGENAME}}</nowiki></code>
| <nowiki>{{ns:13}} or {{ns:Help_talk}}</nowiki>
| {{TALKPAGENAME}}
| {{ns:13}}
| The namespace and title of the associated talk page.
|-
|
| <nowiki>{{ns:14}} or {{ns:Category}}</nowiki>
| {{ns:14}}
|-
|
| <nowiki>{{ns:15}} or {{ns:Category_talk}}</nowiki>
| {{ns:15}}
|-
! {{Hl2}} colspan="3" | '''Server specific'''
|-
| Sitename
| <nowiki>{{SITENAME}}</nowiki>
| {{SITENAME}}
|-
| Servername
| <nowiki>{{SERVERNAME}}</nowiki>
| {{SERVERNAME}}
|-
| Server
| <nowiki>{{SERVER}}</nowiki>
| {{SERVER}}
|-
|-
| Script path
| <nowiki>{{SCRIPTPATH}}</nowiki>
| {{SCRIPTPATH}}
|-
| Local part of the URL<br>
| <nowiki>{{localurl:pagename}}</nowiki>
| {{localurl:pagename}}
|-
|
| <nowiki>{{localurl:pagename|</nowiki>''query string''<nowiki>}}</nowiki>
| {{localurl:pagename|''query string''}}
|-
! {{Hl2}} colspan="3" | '''Page related'''
|-
| Pagename
| <nowiki>{{PAGENAME}}</nowiki>
| {{PAGENAME}}
|-
| Pagename<br>(URL encoded)
| <nowiki>{{PAGENAMEE}}</nowiki>
| {{PAGENAMEE}}
|-
| Namespace
| <nowiki>{{NAMESPACE}}</nowiki>
| {{NAMESPACE}}
|-
| Revision ID
| <nowiki>{{REVISIONID}}</nowiki>
| {{REVISIONID}}
|}
|}
</center>
==External links==
{{meta|Help:Variable}}


{{Languages|Help:Variables}}


{{Template:WikiHelpNav}}
[[Category:Help|Variables]]
[[Category:Help|Variables]]

Latest revision as of 07:25, 4 February 2012

Variables are a type of Magic words a strings of text that Wiki software associates with a return value or function. There are three general types of magic words:

  • Variables: these are uppercase words surrounded by double braces, e.g. {{FOO}}. As such, they look a lot like templates. Note that templates use pre set parameters, that are parsed and cashed once you save the page, not each time you load it.
  • Behavior switches: these are uppercase words surrounded by double underscores, e.g. __FOO__ used for adjusting the layout or behavior of the page and can often be used to specify desired omissions and inclusions in the content.
  • Parser functions: very similar to variables, but take one or more parameters. See also Help:Extension:ParserFunctions which offers great functionality for constructing advance templates.


Here are some useful magic words, for a full list see Help:Magic words

Word Description
__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. It is possible to suppress the auto-generated section numbers, if the proper class exists locally at MediaWiki:Common.css, defined as .tocnumber { display: none; }.
Variable Output Description
{{FULLPAGENAME}} Help:Variables Namespace and page title.
{{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.

{{SUBPAGENAME}} Variables The subpage title ("foo" on "Title/foo").
{{SUBJECTPAGENAME}} Help:Variables The namespace and title of the associated subject page.
{{TALKPAGENAME}} Help talk:Variables The namespace and title of the associated talk page.