Help:Magic words

From FamilySearch Wiki

(Difference between revisions)
(Formatting)
(Behavior switches)
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''Magic words''' (which include '''parser functions''', '''variables''' and '''behavior switches''')  are features of [[FamilySearch Wiki:wikitext|wikitext]] that enable various instructions to be given to the [[Help:MediaWiki|MediaWiki]] software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in [[FamilySearch Wiki:Templates|templates]].
+
{{Help article}}
  
A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to following pages on the MediaWiki site:
+
:''Much of the information on this page explains options for users who wish to create [[Help:Templates|templates]] with advanced features. Most users will only be interested in some of the behavior switches listed below.''
*'''{{mw|Help:Magic words}}''' for all standard magic words, including the "standard" parser functions
+
*'''{{mw|Help:Extension:ParserFunctions}}''' for some additional parser functions, including conditional expressions
+
  
==General information==
 
There are three types of magic words:
 
*'''Behavior switches:''' uppercase words surrounded by double underscores, e.g. <tt><nowiki>__NOTOC__</nowiki></tt>, or keywords using parser function syntax
 
*'''Variables:''' uppercase words surrounded by double braces, e.g. <tt><nowiki>{{PAGENAME}}</nowiki></tt> (thus resembling [[Help:Templates|templates]])
 
*'''Parser functions:''' keywords (some beginning #) in double braces with parameters after a colon, e.g. <tt><nowiki>{{#expr:2+2}}</nowiki></tt>
 
  
Some magic words are case-insensitive, but not all. Whitespace is stripped from the start and end of keywords and parameters, as in template syntax.
+
'''Magic words''' (which include parser functions, variables and behavior switches) are features of [[Help:Wiki markup|wikitext]] that enable various instructions to be given to the [http://wikimediafoundation.org/wiki/MediaWiki MediaWiki] software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in [[FamilySearch Wiki:Templates|templates]].  
  
Page-dependent magic words will affect or return data about the ''current'' page, even if the word is added through a transcluded template or included system message.
+
A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to following pages on the MediaWiki site:
  
It is possible to [[Help:Substitution|substitute]] parser functions and variables in the same way that templates are substituted (using the <tt>subst:</tt> keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.
+
*{{mw|Help:Magic words}} for all standard magic words, including the "standard" parser functions
 +
*{{mw|Help:Extension:ParserFunctions}} for some additional parser functions, including conditional expressions
 +
 
 +
== General information  ==
 +
 
 +
There are three types of magic words:
 +
 
 +
::'''Behavior switches''' - uppercase words surrounded by double underscores, e.g. <tt><nowiki>__NOTOC__</nowiki></tt>, or keywords using parser function syntax
 +
 
 +
::'''Variables''' - uppercase words surrounded by double braces, e.g. <tt><nowiki>{{PAGENAME}}</nowiki></tt> (thus resembling [[Help:Templates|templates]])
 +
 
 +
::'''Parser functions''' - keywords (some beginning #) in double braces with parameters after a colon, e.g. <tt><nowiki>{{#expr:2+2}}</nowiki></tt>
 +
 
 +
 
 +
Some magic words are case-insensitive, but not all. Whitespace is stripped from the start and end of keywords and parameters, as in template syntax. Page-dependent magic words will affect or return data about the ''current'' page, even if the word is added through a transcluded template or included system message. It is possible to [[Help:Substitution|substitute]] parser functions and variables in the same way that templates are substituted (using the <tt>subst:</tt> keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.  
 +
 
 +
__TOC__
  
 
== Behavior switches  ==
 
== Behavior switches  ==
Line 21: Line 30:
 
''For documentation, refer to the {{mw|Help:Magic words#Behavior switches|Behavior Switches}} section of the MediaWiki page.''  
 
''For documentation, refer to the {{mw|Help:Magic words#Behavior switches|Behavior Switches}} section of the MediaWiki page.''  
  
{| {{prettytable}}
+
{| style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; margin: 1em 1em 1em 0px; border-collapse: collapse; empty-cells: show; border-top: #aaaaaa 1px solid; border-right: #aaaaaa 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 
|-
 
|-
!{{Hl2}}| Word
+
! bgcolor="#a7c1f2" | Word  
!{{Hl2}}| Description
+
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <nowiki>__TOC__</nowiki>
 +
| (places a table of contents at the word's position)
 
|-
 
|-
 
| <nowiki>__NOTOC__</nowiki>  
 
| <nowiki>__NOTOC__</nowiki>  
Line 31: Line 43:
 
| <nowiki>__FORCETOC__</nowiki>  
 
| <nowiki>__FORCETOC__</nowiki>  
 
| (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
 
| (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
|-
 
| <nowiki>__TOC__</nowiki>
 
| (places a table of contents at the word's position)
 
 
|-
 
|-
 
| <nowiki>__NOEDITSECTION__</nowiki>  
 
| <nowiki>__NOEDITSECTION__</nowiki>  
Line 43: Line 52:
 
| <nowiki>__NONEWSECTIONLINK__</nowiki>  
 
| <nowiki>__NONEWSECTIONLINK__</nowiki>  
 
| (removes the "+" link on "Talk" pages)
 
| (removes the "+" link on "Talk" pages)
 +
|-
 +
| <nowiki>__</nowiki>NORICHEDITOR<nowiki>__</nowiki>
 +
| (prevents the [[Help:The Editing Tool (FCK Editor)|FCK editor]] from being used to edit a page)
 
|-
 
|-
 
| <nowiki>__NOGALLERY__</nowiki>  
 
| <nowiki>__NOGALLERY__</nowiki>  
Line 63: Line 75:
 
|}
 
|}
  
==Variables==
+
== Variables ==
''For documentation, refer to the {{mw|Help:Magic words#Variables|Variables}} section of the MediaWiki page.''
+
*<tt><nowiki>{{FULLPAGENAME}}</nowiki></tt> ([[Help:Page name|page title]] including [[help:namespace|namespace]])
+
*<tt><nowiki>{{PAGENAME}}</nowiki></tt> (page title excluding namespace)
+
*<tt><nowiki>{{BASEPAGENAME}}</nowiki></tt> (page title excluding [[Help:Subpages|subpage]] and namespace)
+
*<tt><nowiki>{{SUBPAGENAME}}</nowiki></tt> (subpage part of title)
+
*<tt><nowiki>{{SUBJECTPAGENAME}}</nowiki></tt> (associated non-talk page)
+
*<tt><nowiki>{{TALKPAGENAME}}</nowiki></tt> (associated talk page)
+
*<tt><nowiki>{{NAMESPACE}}</nowiki></tt> (namespace of current page)
+
*<tt><nowiki>{{SUBJECTSPACE}}, {{ARTICLESPACE}}</nowiki></tt> (associated non-talk namespace)
+
*<tt><nowiki>{{TALKSPACE}}</nowiki></tt> (associated talk namespace)
+
* <tt><nowiki>{{FULLPAGENAMEE}}, {{NAMESPACEE}}</nowiki></tt> etc. (URL-encoded equivalents)
+
  
The above can all take a parameter, to operate on a page other than the current page.
+
''For documentation, refer to the {{mw|Help:Magic words#Variables|Variables}} section of the MediaWiki page.''
  
*<tt><nowiki>{{SITENAME}}</nowiki></tt> ({{SITENAME}})
+
{| style="border-bottom: rgb(170,170,170) 1px solid; border-left: rgb(170,170,170) 1px solid; margin: 1em 1em 1em 0pt; border-collapse: collapse; empty-cells: show; border-top: rgb(170,170,170) 1px solid; border-right: rgb(170,170,170) 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
*<tt><nowiki>{{SERVER}}</nowiki></tt> ({{SERVER}})
+
|-
*<tt><nowiki>{{SERVERNAME}}</nowiki></tt> ({{SERVERNAME}})
+
! bgcolor="#a7c1f2" | Variable
*<tt><nowiki>{{SCRIPTPATH}}</nowiki></tt> ({{SCRIPTPATH}})
+
! bgcolor="#a7c1f2" | Output
*<tt><nowiki>{{CURRENTVERSION}}</nowiki></tt> (current MediaWiki version)
+
! bgcolor="#a7c1f2" | Description
*<tt><nowiki>{{REVISIONID}}</nowiki></tt> (latest revision to current page)
+
|-
*<tt><nowiki>{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}}</nowiki></tt> (date, time, editor at last edit)
+
| <nowiki>{{FULLPAGENAME}}</nowiki>  
 +
| {{FULLPAGENAME}}  
 +
| (page title including [[Help:Namespace|namespace]])
 +
|-
 +
| <nowiki>{{PAGENAME}}</nowiki>  
 +
| {{PAGENAME}}  
 +
| (page title excluding namespace)
 +
|-
 +
| <nowiki>{{BASEPAGENAME}}</nowiki>  
 +
| {{BASEPAGENAME}}  
 +
| (page title excluding [[Help:Subpages|subpage]] and namespace)
 +
|-
 +
| <nowiki>{{SUBPAGENAME}}</nowiki>  
 +
| {{SUBPAGENAME}}  
 +
| (subpage part of title)
 +
|-
 +
| <nowiki>{{SUBJECTPAGENAME}}</nowiki>  
 +
| {{SUBJECTPAGENAME}}  
 +
| (associated non-talk page)
 +
|-
 +
| <nowiki>{{TALKPAGENAME}}</nowiki>  
 +
| {{TALKPAGENAME}}
 +
| (associated talk page)
 +
|-
 +
| <nowiki>{{NAMESPACE}}</nowiki>  
 +
| {{NAMESPACE}}
 +
| (namespace of current page)
 +
|-
 +
| <nowiki>{{SUBJECTSPACE}}, {{ARTICLESPACE}}</nowiki>  
 +
| {{SUBJECTSPACE}}<br>{{ARTICLESPACE}}  
 +
| (associated non-talk namespace)
 +
|-
 +
| <nowiki>{{TALKSPACE}}</nowiki>
 +
| {{TALKSPACE}}  
 +
| (associated talk namespace)
 +
|-
 +
| <nowiki>{{FULLPAGENAMEE}}, {{NAMESPACEE}}</nowiki>  
 +
| {{FULLPAGENAME}},<br>{{NAMESPACEE}}
 +
| etc. (URL-encoded equivalents)
 +
|}
  
*<tt><nowiki>{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}}</nowiki></tt> (current date/time variables)
+
The above can all take a parameter, to operate on a page other than the current page.  
*<tt><nowiki>{{LOCALYEAR}}</nowiki></tt> etc. (as above, based on site's local time)
+
  
*<tt><nowiki>{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}}</nowiki></tt> (statistics on FamilySearch Wiki; add <tt>:R</tt> to return numbers without commas)
+
{| style="border-bottom: rgb(170,170,170) 1px solid; border-left: rgb(170,170,170) 1px solid; margin: 1em 1em 1em 0pt; border-collapse: collapse; empty-cells: show; border-top: rgb(170,170,170) 1px solid; border-right: rgb(170,170,170) 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 +
|-
 +
! bgcolor="#a7c1f2" | Variable
 +
! bgcolor="#a7c1f2" | Output
 +
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <nowiki>{{SITENAME}}</nowiki>
 +
| {{SITENAME}}
 +
| Site name
 +
|-
 +
| <nowiki>{{SERVER}}</nowiki>
 +
| {{SERVER}}
 +
| Server
 +
|-
 +
| <nowiki>{{SERVERNAME}}</nowiki>
 +
| {{SERVERNAME}}
 +
| Server name
 +
|-
 +
| <nowiki>{{SCRIPTPATH}}</nowiki>
 +
| {{SCRIPTPATH}}
 +
| Script path
 +
|-
 +
| <nowiki>{{CURRENTVERSION}}</nowiki>
 +
| {{CURRENTVERSION}}
 +
| (current MediaWiki version)
 +
|-
 +
| <nowiki>{{REVISIONID}}</nowiki>
 +
| {{REVISIONID}}
 +
| (latest revision to current page)
 +
|-
 +
| <nowiki>{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}}</nowiki>
 +
| {{REVISIONDAY}}, {{REVISIONDAY2}},<br>{{REVISIONMONTH}}, {{REVISIONYEAR}},<br>{{REVISIONTIMESTAMP}}, {{REVISIONUSER}}
 +
| (date, time, editor at last edit)
 +
|-
 +
| <nowiki>{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}}</nowiki>
 +
| {{CURRENTYEAR}}, {{CURRENTMONTH}}<br>{{CURRENTMONTHNAME}}<br>{{CURRENTMONTHABBREV}}, {{CURRENTDAY}}<br>{{CURRENTDAY2}}, {{CURRENTDOW}}<br>{{CURRENTDAYNAME}}, {{CURRENTTIME}}<br>{{CURRENTHOUR}}, {{CURRENTWEEK}}<br>{{CURRENTTIMESTAMP}}
 +
| (current date/time variables)
 +
|-
 +
| <nowiki>{{LOCALYEAR}}</nowiki>
 +
| {{LOCALYEAR}}
 +
| etc. (as above, based on site's local time)
 +
|-
 +
| <nowiki>{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}}</nowiki>  
 +
| {{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}<br>{{NUMBEROFFILES}}, {{NUMBEROFEDITS}}<br>{{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}<br>{{NUMBEROFADMINS}}<br>{{NUMBEROFACTIVEUSERS}}
 +
| (statistics on FamilySearch Wiki; add <tt>:R</tt> to return numbers without commas)
 +
|-
 +
| <nowiki>{{CURRENTMONTHNAMEGEN}}</nowiki>
 +
| {{CURRENTMONTHNAMEGEN}}
 +
| See notes below.
 +
|}
  
==Parser functions==
+
{{Note|'''Notes''':<br><br>
''These are documented at the {{mw|Help:Magic words|main documentation page}} unless otherwise stated.''
+
 
===Metadata===
+
*NUMBEROFARTICLES is the number of pages in the main namespace which contain a link and are not a redirect, in other words number of articles, stubs containing a link, and disambiguation pages.
*<tt><nowiki>{{PAGESIZE:</nowiki>''page name''<nowiki>}}</nowiki></tt> (size of page in bytes)
+
 
*<tt><nowiki>{{PROTECTIONLEVEL:</nowiki>''action''<nowiki>}}</nowiki></tt> (protection level for given action on the current page)
+
*CURRENTMONTHNAMEGEN is the genitive (possessive) grammatical form of the month name, as used in some languages; CURRENTMONTHNAME is the nominative (subject) form, as usually seen in English.
*<tt><nowiki>{{PAGESINCATEGORY:</nowiki>''categoryname''<nowiki>}}</nowiki></tt> (number of pages in the given [[Help:Categories|category]])
+
 
*<tt><nowiki>{{NUMBERINGROUP:</nowiki>''groupname''<nowiki>}}</nowiki></tt> (number of users in a specific [[Help:User rights|group]])
+
*In languages where it makes a difference, you can use constructs like <nowiki>{{grammar:case|word}}</nowiki> to convert a word from the nominative case to some other case. For example, <nowiki>{{grammar:genitive|{{CURRENTMONTHNAME}}}}</nowiki> means the same as <nowiki>{{CURRENTMONTHNAMEGEN}}</nowiki>. <!-- Is there a reference for this, other than the source code (for example, phase3/languages/Lnaguage*.php) ? -->}}
 +
 
 +
 
 +
=== Namespaces ===
 +
 
 +
{| style="border-bottom: rgb(170,170,170) 1px solid; border-left: rgb(170,170,170) 1px solid; margin: 1em 1em 1em 0pt; border-collapse: collapse; empty-cells: show; border-top: rgb(170,170,170) 1px solid; border-right: rgb(170,170,170) 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="45%"
 +
|-
 +
! bgcolor="#a7c1f2" | Variable
 +
! bgcolor="#a7c1f2" | Output
 +
|-
 +
| <nowiki>{{ns:1}}</nowiki>
 +
| {{ns:1}}
 +
|-
 +
| <nowiki>{{ns:2}}</nowiki>
 +
| {{ns:2}}
 +
|-
 +
| <nowiki>{{ns:3}}</nowiki>
 +
| {{ns:3}}
 +
|-
 +
| <nowiki>{{ns:4}}</nowiki>
 +
| {{ns:4}}
 +
|-
 +
| <nowiki>{{ns:5}}</nowiki>
 +
| {{ns:5}}
 +
|-
 +
| <nowiki>{{ns:6}}</nowiki>
 +
| {{ns:6}}
 +
|-
 +
| <nowiki>{{ns:7}}</nowiki>
 +
| {{ns:7}}
 +
|-
 +
| <nowiki>{{ns:8}}</nowiki>
 +
| {{ns:8}}
 +
|-
 +
| <nowiki>{{ns:9}}</nowiki>
 +
| {{ns:9}}
 +
|-
 +
| <nowiki>{{ns:10}}</nowiki>
 +
| {{ns:10}}
 +
|-
 +
| <nowiki>{{ns:11}}</nowiki>
 +
| {{ns:11}}
 +
|-
 +
| <nowiki>{{ns:12}}</nowiki>
 +
| {{ns:12}}
 +
|-
 +
| <nowiki>{{ns:13}}</nowiki>
 +
| {{ns:13}}
 +
|-
 +
| <nowiki>{{ns:14}}</nowiki>
 +
| {{ns:14}}
 +
|-
 +
| <nowiki>{{ns:15}}</nowiki>
 +
| {{ns:15}}
 +
|}
 +
 
 +
== Parser functions ==
 +
 
 +
''These are documented at the {{mw|Help:Magic words|main documentation page}} unless otherwise stated.''  
 +
 
 +
=== Metadata ===
 +
 
 +
{| style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; margin: 1em 1em 1em 0px; border-collapse: collapse; empty-cells: show; border-top: #aaaaaa 1px solid; border-right: #aaaaaa 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 +
|-
 +
! bgcolor="#a7c1f2" | Parser function
 +
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <tt><nowiki>{{PAGESIZE:</nowiki>''page name''<nowiki>}}</nowiki></tt>  
 +
| (size of page in bytes)
 +
|-
 +
| <tt><nowiki>{{PROTECTIONLEVEL:</nowiki>''action''<nowiki>}}</nowiki></tt>  
 +
| (protection level for given action on the current page)
 +
|-
 +
| <tt><nowiki>{{PAGESINCATEGORY:</nowiki>''categoryname''<nowiki>}}</nowiki></tt>  
 +
| (number of pages in the given [[Help:Categories|category]])
 +
|-
 +
| <tt><nowiki>{{NUMBERINGROUP:</nowiki>''groupname''<nowiki>}}</nowiki></tt>  
 +
| (number of users in a specific [[Help:User rights|group]])
 +
|}
 +
 
 +
Add <tt>|R</tt> to return numbers without commas.
 +
 
 +
=== Formatting  ===
 +
 
 +
{| style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; margin: 1em 1em 1em 0px; border-collapse: collapse; empty-cells: show; border-top: #aaaaaa 1px solid; border-right: #aaaaaa 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 +
|-
 +
! bgcolor="#a7c1f2" | Parser function
 +
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <tt><nowiki>{{lc:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (convert to lower case)
 +
|-
 +
| <tt><nowiki>{{lcfirst:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (convert first character to lower case)
 +
|-
 +
| <tt><nowiki>{{uc:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (convert to upper case)
 +
|-
 +
| <tt><nowiki>{{ucfirst:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (convert first character to upper case)
 +
|-
 +
| <tt><nowiki>{{formatnum:</nowiki>''unformatted&nbsp;num''<nowiki>}}</nowiki></tt>
 +
| (format a number with comma separators; add <tt><nowiki>|</nowiki>R</tt> to unformat a number)
 +
|-
 +
| <tt><nowiki>{{#formatdate:</nowiki>''date''<nowiki>}}</nowiki></tt>
 +
| (formats a date according to user preferences; a default can be given as a second parameter for users without date preference); however, please note that the community voted against the concept of date-autoformatting in the {{wpd|User:Ryan_Postlethwaite/Draft_RfC#Autoformatting|March 2009 RfC}}, and that there is considerable opposition to the use of this parser function.
 +
|-
 +
| <tt><nowiki>{{padleft:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{padright:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt>
 +
| (pad with zeros to the right or left; an alternative padding string can be given as a third parameter)
 +
|-
 +
| <tt><nowiki>{{plural:</nowiki>''n''<nowiki>|</nowiki>''is''<nowiki>|</nowiki>''are''<nowiki>}}</nowiki></tt>
 +
| (produces alternative text according to whether ''n'' is greater than 1)
 +
|-
 +
| <tt><nowiki>{{#time: format string | date/time object }}</nowiki></tt>
 +
| (for date/time formatting; also <tt>#timel</tt> for local time. Covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}.)
 +
|}
 +
 
 +
=== Paths  ===
 +
 
 +
{| style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; margin: 1em 1em 1em 0px; border-collapse: collapse; empty-cells: show; border-top: #aaaaaa 1px solid; border-right: #aaaaaa 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 +
|-
 +
! bgcolor="#a7c1f2" | Parser function
 +
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>|</nowiki>''query string''<nowiki>}}</nowiki></tt>
 +
| (relative path to the title)
 +
|-
 +
| <tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>|</nowiki>''query_string''<nowiki>}}</nowiki></tt>
 +
| (absolute path to the title)
 +
|-
 +
| <tt><nowiki>{{filepath:</nowiki>''file name''<nowiki>}}</nowiki></tt>
 +
| (absolute URL to a media file)
 +
|-
 +
| <tt><nowiki>{{urlencode:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (input encoded for use in URLs)
 +
|-
 +
| <tt><nowiki>{{anchorencode:</nowiki>''string''<nowiki>}}</nowiki></tt>
 +
| (input encoded for use in URL section anchors)
 +
|-
 +
| <tt><nowiki>{{ns:</nowiki>''n''<nowiki>}}</nowiki></tt>
 +
| (name for the [[Help:Namespace|namespace]] with index ''n''; use <tt><nowiki>{{nse:}}</nowiki></tt> for URL-encoded equivalent)
 +
|-
 +
| <tt><nowiki>{{#rel2abs:</nowiki> ''path'' <nowiki>}}</nowiki></tt>
 +
| (converts a relative file path to absolute; see the {{mw|Help:Extension:ParserFunctions|extension documentation}})
 +
|-
 +
| <tt><nowiki>{{#titleparts:</nowiki> ''pagename'' <nowiki>|</nowiki> ''number of segments to return'' <nowiki>|</nowiki> ''first segment to return'' <nowiki>}}</nowiki></tt>
 +
| (splits title into parts; see the {{mw|Help:Extension:ParserFunctions|extension documentation}})
 +
|}
 +
 
 +
=== Conditional expressions  ===
 +
 
 +
These are covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}. Some parameters are optional.
 +
 
 +
{| style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; margin: 1em 1em 1em 0px; border-collapse: collapse; empty-cells: show; border-top: #aaaaaa 1px solid; border-right: #aaaaaa 1px solid" border="2" rules="all" cellspacing="4" cellpadding="3" width="100%"
 +
|-
 +
! bgcolor="#a7c1f2" | Parser function
 +
! bgcolor="#a7c1f2" | Description
 +
|-
 +
| <tt><nowiki>{{#expr:</nowiki> ''expression'' <nowiki>}}</nowiki></tt>
 +
| (evaluates the given expression; see [[Help:Calculation]])
 +
|-
 +
| <tt><nowiki>{{#if:</nowiki> ''test string'' <nowiki>|</nowiki> ''value if non-empty'' <nowiki>|</nowiki> ''value if empty'' <nowiki>}}</nowiki></tt>
 +
| (selects one of two values based on whether the test string is empty)
 +
|-
 +
| <tt><nowiki>{{#ifeq:</nowiki> ''string 1'' <nowiki>|</nowiki> ''string 2'' <nowiki>|</nowiki> ''value if equal'' <nowiki>|</nowiki> ''value if unequal'' <nowiki>}}</nowiki></tt>
 +
| (selects one of two values based on whether the test strings are equal – numerically if applicable)
 +
|-
 +
| <tt><nowiki>{{#iferror:</nowiki> ''test string'' <nowiki>|</nowiki> ''value if error'' <nowiki>|</nowiki> ''value if correct'' <nowiki>}}</nowiki></tt>
 +
| (selects value based on whether the test string generates a parser error)
 +
|-
 +
| <tt><nowiki>{{#ifexpr:</nowiki> ''expression'' <nowiki>|</nowiki> ''value if true'' <nowiki>|</nowiki> ''value if false'' <nowiki>}}</nowiki></tt>
 +
| (selects value based on evaluation of expression)
 +
|-
 +
| <tt><nowiki>{{#ifexist:</nowiki> ''page title'' <nowiki>|</nowiki> ''value if exists'' <nowiki>|</nowiki> ''value if doesn't exist'' <nowiki>}}</nowiki></tt>
 +
| (selects value depending on whether a page title exists)
 +
|-
 +
| <tt><nowiki>{{#switch:</nowiki> ''test'' <nowiki>|</nowiki> ''case1'' = ''value for case 1'' <nowiki>|</nowiki> ... <nowiki>|</nowiki> ''default'' <nowiki>}}</nowiki></tt>
 +
| (provides alternatives based on the value of the test string)
 +
|}
  
Add <tt>|R</tt> to return numbers without commas.
+
For the use of these functions in tables, see [[wikipedia:Conditional tables|Conditional tables]].  
  
===Formatting===
+
== See also  ==
*<tt><nowiki>{{lc:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert to lower case)
+
*<tt><nowiki>{{lcfirst:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert first character to lower case)
+
*<tt><nowiki>{{uc:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert to upper case)
+
*<tt><nowiki>{{ucfirst:</nowiki>''string''<nowiki>}}</nowiki></tt> (convert first character to upper case)
+
*<tt><nowiki>{{formatnum:</nowiki>''unformatted&nbsp;num''<nowiki>}}</nowiki></tt> (format a number with comma separators; add <tt><nowiki>|</nowiki>R</tt> to unformat a number)
+
*<tt><nowiki>{{#formatdate:</nowiki>''date''<nowiki>}}</nowiki></tt> (formats a date according to user preferences; a default can be given as a second parameter for users without date preference); however, please note that the community voted against the concept of date-autoformatting in the {{wpd|User:Ryan_Postlethwaite/Draft_RfC#Autoformatting|March 2009 RfC}}, and that there is considerable opposition to the use of this parser function.
+
*<tt><nowiki>{{padleft:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{padright:xyz|</nowiki>''stringlength''<nowiki>}}</nowiki></tt> (pad with zeros to the right or left; an alternative padding string can be given as a third parameter)
+
*<tt><nowiki>{{plural:</nowiki>''n''|''is''<nowiki>|</nowiki>''are''<nowiki>}}</nowiki></tt> (produces alternative text according to whether ''n'' is greater than 1)
+
*<tt><nowiki>{{#time: format string | date/time object }}</nowiki></tt> (for date/time formatting; also <tt>#timel</tt> for local time. Covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}.)
+
  
===Paths===
+
{{Contributor Help badge}}  
*<tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{localurl:</nowiki>''page name''<nowiki>|</nowiki>''query string''<nowiki>}}</nowiki></tt> (relative path to the title)
+
*<tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>}}</nowiki></tt>, <tt><nowiki>{{fullurl:</nowiki>''page name''<nowiki>|</nowiki>''query_string''<nowiki>}}</nowiki></tt> (absolute path to the title)
+
*<tt><nowiki>{{filepath:</nowiki>''file name''<nowiki>}}</nowiki></tt> (absolute URL to a media file)
+
*<tt><nowiki>{{urlencode:</nowiki>''string''<nowiki>}}</nowiki></tt> (input encoded for use in URLs)
+
*<tt><nowiki>{{anchorencode:</nowiki>''string''<nowiki>}}</nowiki></tt> (input encoded for use in URL section anchors)
+
*<tt><nowiki>{{ns:</nowiki>''n''<nowiki>}}</nowiki></tt> (name for the [[Help:Namespace|namespace]] with index ''n''; use <tt><nowiki>{{nse:}}</nowiki></tt> for URL-encoded equivalent)
+
*<tt><nowiki>{{#rel2abs:</nowiki> ''path'' <nowiki>}}</nowiki></tt> (converts a relative file path to absolute; see the {{mw|Help:Extension:ParserFunctions|extension documentation}})
+
*<tt><nowiki>{{#titleparts:</nowiki> ''pagename'' | ''number of segments to return'' | ''first segment to return'' <nowiki>}}</nowiki></tt> (splits title into parts; see the {{mw|Help:Extension:ParserFunctions|extension documentation}})
+
  
===Conditional expressions===
+
*{{mw|Internationalisation}}  
These are covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}. Some parameters are optional.
+
*{{mw|Manual:Extending_wiki_markup|Adding parser functions}}  
*<tt><nowiki>{{#expr:</nowiki> ''expression'' <nowiki>}}</nowiki></tt> (evaluates the given expression; see [[Help:Calculation]])
+
*[http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/CoreParserFunctions.php?view=log CoreParserFunctions.php]
*<tt><nowiki>{{#if:</nowiki> ''test string'' | ''value if non-empty'' | ''value if empty'' <nowiki>}}</nowiki></tt> (selects one of two values based on whether the test string is empty)
+
*{{wpd|User:Cacycle/wikEd|wikEd}}, a MediaWiki editor with syntax highlighting for templates and parser functions
*<tt><nowiki>{{#ifeq:</nowiki> ''string 1'' <nowiki>|</nowiki> ''string 2'' <nowiki>|</nowiki> ''value if equal'' <nowiki>|</nowiki> ''value if unequal'' <nowiki>}}</nowiki></tt> (selects one of two values based on whether the test strings are equal – numerically if applicable)
+
*<tt><nowiki>{{#iferror:</nowiki> ''test string'' <nowiki>|</nowiki> ''value if error'' <nowiki>|</nowiki> ''value if correct'' <nowiki>}}</nowiki></tt> (selects value based on whether the test string generates a parser error)
+
*<tt><nowiki>{{#ifexpr:</nowiki> ''expression'' <nowiki>|</nowiki> ''value if true'' <nowiki>|</nowiki> ''value if false'' <nowiki>}}</nowiki></tt> (selects value based on evaluation of expression)
+
*<tt><nowiki>{{#ifexist:</nowiki> ''page title'' | ''value if exists'' | ''value if doesn't exist'' <nowiki>}}</nowiki></tt> (selects value depending on whether a page title exists)
+
*<tt><nowiki>{{#switch:</nowiki> ''test'' | ''case1'' = ''value for case 1'' | ... | ''default'' <nowiki>}}</nowiki></tt> (provides alternatives based on the value of the test string)
+
  
For the use of these functions in tables, see [[Wikipedia:Conditional tables|Conditional tables]].
+
{{Contributor help-navbox}} {{Editing help}}
  
==See also==
+
__NORICHEDITOR__
*{{mw|Internationalisation}}
+
*{{mw|Manual:Extending_wiki_markup|Adding parser functions}}
+
*[http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/CoreParserFunctions.php?view=log CoreParserFunctions.php]
+
* {{wpd|User:Cacycle/wikEd|wikEd}}, a MediaWiki editor with syntax highlighting for templates and parser functions
+
  
 
[[Category:Help|{{PAGENAME}}]]
 
[[Category:Help|{{PAGENAME}}]]

Revision as of 21:47, 29 August 2012

Help-content.png This help article will guide you as you edit in the Wiki. See Contributor Help for more help articles.


Much of the information on this page explains options for users who wish to create templates with advanced features. Most users will only be interested in some of the behavior switches listed below.


Magic words (which include parser functions, variables and behavior switches) are features of wikitext that enable various instructions to be given to the MediaWiki software (for example, to suppress or position the table of contents), or else serve to produce variable output, as is often required in templates.

A quick reference for magic words can be found on this page. For more complete and updated documentation, refer to following pages on the MediaWiki site:

General information

There are three types of magic words:

Behavior switches - uppercase words surrounded by double underscores, e.g. __NOTOC__, or keywords using parser function syntax
Variables - uppercase words surrounded by double braces, e.g. {{PAGENAME}} (thus resembling templates)
Parser functions - keywords (some beginning #) in double braces with parameters after a colon, e.g. {{#expr:2+2}}


Some magic words are case-insensitive, but not all. Whitespace is stripped from the start and end of keywords and parameters, as in template syntax. Page-dependent magic words will affect or return data about the current page, even if the word is added through a transcluded template or included system message. It is possible to substitute parser functions and variables in the same way that templates are substituted (using the subst: keyword). This causes their current value (as evaluated at the time of substitution) to be written into the wikitext.

Contents


Behavior switches

For documentation, refer to the mw:Behavior Switches section of the MediaWiki page.

Word Description
__TOC__ (places a table of contents at the word's position)
__NOTOC__ (can appear anywhere in the wikitext; suppresses the table of contents)
__FORCETOC__ (can appear anywhere in the wikitext; makes a table of contents appear in its normal position above the first header)
__NOEDITSECTION__ (hides the section edit links beside headings)
__NEWSECTIONLINK__ (adds a "+" link for adding a new section on a non-"Talk" page)
__NONEWSECTIONLINK__ (removes the "+" link on "Talk" pages)
__NORICHEDITOR__ (prevents the FCK editor from being used to edit a page)
__NOGALLERY__ (on a category page, replaces thumbnails with normal links)
__HIDDENCAT__ (on a category page, makes it a hidden category)
__INDEX__ (tells search engines to index the page)
__NOINDEX__ (tells search engines not to index the page)
{{DISPLAYTITLE:title}} (changes the displayed form of the page title)
{{DEFAULTSORT:sortkey}} (sets a default category sort key)

Variables

For documentation, refer to the mw:Variables section of the MediaWiki page.

Variable Output Description
{{FULLPAGENAME}} Help:Magic words (page title including namespace)
{{PAGENAME}} Magic words (page title excluding namespace)
{{BASEPAGENAME}} Magic words (page title excluding subpage and namespace)
{{SUBPAGENAME}} Magic words (subpage part of title)
{{SUBJECTPAGENAME}} Help:Magic words (associated non-talk page)
{{TALKPAGENAME}} Help talk:Magic words (associated talk page)
{{NAMESPACE}} Help (namespace of current page)
{{SUBJECTSPACE}}, {{ARTICLESPACE}} Help
Help
(associated non-talk namespace)
{{TALKSPACE}} Help talk (associated talk namespace)
{{FULLPAGENAMEE}}, {{NAMESPACEE}} Help:Magic words,
Help
etc. (URL-encoded equivalents)

The above can all take a parameter, to operate on a page other than the current page.

Variable Output Description
{{SITENAME}} FamilySearch Wiki Site name
{{SERVER}} https://familysearch.org Server
{{SERVERNAME}} familysearch.org Server name
{{SCRIPTPATH}} /learn/wiki/en Script path
{{CURRENTVERSION}} 1.17.1 (current MediaWiki version)
{{REVISIONID}} 1104996 (latest revision to current page)
{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}} 29, 29,
08, 2012,
20120829214755, Lotje2
(date, time, editor at last edit)
{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}} 2014, 04
April
Apr, 21
21, 1
Monday, 17:05
17, 17
20140421170548
(current date/time variables)
{{LOCALYEAR}} 2014 etc. (as above, based on site's local time)
{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}} 149,976, 77,777
30,706, 1,690,260
474,700,135, 150,561
45
381
(statistics on FamilySearch Wiki; add :R to return numbers without commas)
{{CURRENTMONTHNAMEGEN}} April See notes below.


Namespaces

Variable Output
{{ns:1}} Talk
{{ns:2}} User
{{ns:3}} User talk
{{ns:4}} FamilySearch Wiki
{{ns:5}} FamilySearch Wiki talk
{{ns:6}} File
{{ns:7}} File talk
{{ns:8}} MediaWiki
{{ns:9}} MediaWiki talk
{{ns:10}} Template
{{ns:11}} Template talk
{{ns:12}} Help
{{ns:13}} Help talk
{{ns:14}} Category
{{ns:15}} Category talk

Parser functions

These are documented at the mw:main documentation page unless otherwise stated.

Metadata

Parser function Description
{{PAGESIZE:page name}} (size of page in bytes)
{{PROTECTIONLEVEL:action}} (protection level for given action on the current page)
{{PAGESINCATEGORY:categoryname}} (number of pages in the given category)
{{NUMBERINGROUP:groupname}} (number of users in a specific group)

Add |R to return numbers without commas.

Formatting

Parser function Description
{{lc:string}} (convert to lower case)
{{lcfirst:string}} (convert first character to lower case)
{{uc:string}} (convert to upper case)
{{ucfirst:string}} (convert first character to upper case)
{{formatnum:unformatted num}} (format a number with comma separators; add |R to unformat a number)
{{#formatdate:date}} (formats a date according to user preferences; a default can be given as a second parameter for users without date preference); however, please note that the community voted against the concept of date-autoformatting in the March 2009 RfC, and that there is considerable opposition to the use of this parser function.
{{padleft:xyz|stringlength}}, {{padright:xyz|stringlength}} (pad with zeros to the right or left; an alternative padding string can be given as a third parameter)
{{plural:n|is|are}} (produces alternative text according to whether n is greater than 1)
{{#time: format string | date/time object }} (for date/time formatting; also #timel for local time. Covered at the mw:extension documentation page.)

Paths

Parser function Description
{{localurl:page name}}, {{localurl:page name|query string}} (relative path to the title)
{{fullurl:page name}}, {{fullurl:page name|query_string}} (absolute path to the title)
{{filepath:file name}} (absolute URL to a media file)
{{urlencode:string}} (input encoded for use in URLs)
{{anchorencode:string}} (input encoded for use in URL section anchors)
{{ns:n}} (name for the namespace with index n; use {{nse:}} for URL-encoded equivalent)
{{#rel2abs: path }} (converts a relative file path to absolute; see the mw:extension documentation)
{{#titleparts: pagename | number of segments to return | first segment to return }} (splits title into parts; see the mw:extension documentation)

Conditional expressions

These are covered at the mw:extension documentation page. Some parameters are optional.

Parser function Description
{{#expr: expression }} (evaluates the given expression; see Help:Calculation)
{{#if: test string | value if non-empty | value if empty }} (selects one of two values based on whether the test string is empty)
{{#ifeq: string 1 | string 2 | value if equal | value if unequal }} (selects one of two values based on whether the test strings are equal – numerically if applicable)
{{#iferror: test string | value if error | value if correct }} (selects value based on whether the test string generates a parser error)
{{#ifexpr: expression | value if true | value if false }} (selects value based on evaluation of expression)
{{#ifexist: page title | value if exists | value if doesn't exist }} (selects value depending on whether a page title exists)
{{#switch: test | case1 = value for case 1 | ... | default }} (provides alternatives based on the value of the test string)

For the use of these functions in tables, see Conditional tables.

See also

Help-content.png Questions?
Visit the Wiki Contributor Help Forum to receive help with contributing to the Wiki.