Help:Magic words

From FamilySearch Wiki

(Difference between revisions)
m (Corrected link)
Line 1: Line 1:
 +
<br>{{Contributor Help badge}}<br><br>
 +
 +
 
'''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 [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]].  
 
'''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 [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]].  
  
Line 24: Line 27:
 
''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.''  
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;" rules="all"
+
{| 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" | Word  
 
! bgcolor="#a7c1f2" | Word  
Line 70: Line 73:
 
''For documentation, refer to the {{mw|Help:Magic words#Variables|Variables}} section of the MediaWiki page.''  
 
''For documentation, refer to the {{mw|Help:Magic words#Variables|Variables}} section of the MediaWiki page.''  
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin: 1em 1em 1em 0pt; border: 1px solid rgb(170, 170, 170); border-collapse: collapse; empty-cells: show;" rules="all"
+
{| 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" | Variable  
Line 119: Line 122:
 
The above can all take a parameter, to operate on a page other than the current page.  
 
The above can all take a parameter, to operate on a page other than the current page.  
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin: 1em 1em 1em 0pt; border: 1px solid rgb(170, 170, 170); border-collapse: collapse; empty-cells: show;" rules="all"
+
{| 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" | Variable  
Line 172: Line 175:
 
=== Metadata  ===
 
=== Metadata  ===
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;" rules="all"
+
{| 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" | Parser function  
Line 194: Line 197:
 
=== Formatting  ===
 
=== Formatting  ===
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;" rules="all"
+
{| 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" | Parser function  
Line 229: Line 232:
 
=== Paths  ===
 
=== Paths  ===
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;" rules="all"
+
{| 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" | Parser function  
Line 263: Line 266:
 
These are covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}. Some parameters are optional.  
 
These are covered at the {{mw|Help:Extension:ParserFunctions|extension documentation page}}. Some parameters are optional.  
  
{| width="100%" cellspacing="4" cellpadding="3" border="2" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;" rules="all"
+
{| 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" | Parser function  
Line 290: Line 293:
 
|}
 
|}
  
For the use of these functions in tables, see [[wikipedia:Conditional%20tables|Conditional tables]].  
+
For the use of these functions in tables, see [[wikipedia:Conditional tables|Conditional tables]].  
  
 
== See also  ==
 
== See also  ==

Revision as of 20:22, 19 April 2011


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




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:

Contents

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.

Behavior switches

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

Word Description
__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)
__TOC__ (places a table of contents at the word's position)
__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)
__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}} 613906 (latest revision to current page)
{{REVISIONDAY}}, {{REVISIONDAY2}}, {{REVISIONMONTH}}, {{REVISIONYEAR}}, {{REVISIONTIMESTAMP}}, {{REVISIONUSER}} 19, 19, 04, 2011, 20110419202233, Evancol (date, time, editor at last edit)
{{CURRENTYEAR}}, {{CURRENTMONTH}}, {{CURRENTMONTHNAME}}, {{CURRENTMONTHABBREV}}, {{CURRENTDAY}}, {{CURRENTDAY2}}, {{CURRENTDOW}}, {{CURRENTDAYNAME}}, {{CURRENTTIME}}, {{CURRENTHOUR}}, {{CURRENTWEEK}}, {{CURRENTTIMESTAMP}} 2014, 07, July, Jul, 12, 12, 6, Saturday, 02:29, 02, 28, 20140712022900 (current date/time variables)
{{LOCALYEAR}} 2014 etc. (as above, based on site's local time)
{{NUMBEROFPAGES}}, {{NUMBEROFARTICLES}}, {{NUMBEROFFILES}}, {{NUMBEROFEDITS}}, {{NUMBEROFVIEWS}}, {{NUMBEROFUSERS}}, {{NUMBEROFADMINS}}, {{NUMBEROFACTIVEUSERS}} 153,506, 78,920, 31,618, 1,792,511, 503,900,408, 150,561, 48, 330 (statistics on FamilySearch Wiki; add :R to return numbers without commas)

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