Help:Parser function: Difference between revisions

Content deleted Content added
Undid revision 259722995 by Happy-melon - this is a copy of the meta:Help:Parser function page; quite different than mw:Help:Magic words
AnomieBOT (talk | contribs)
m Substing templates: {{This is a redirect}}. See User:AnomieBOT/docs/TemplateSubster for info.
 
(14 intermediate revisions by 11 users not shown)
Line 1:
#REDIRECT [[Help:Magic words#Parser functions]]
{{h:h|editor toc}}
{{otheruses4|parser functions in general|the MediaWiki extension '''ParserFunctions'''|Help:ParserFunctions}}
 
{{redirect category shell|{{R to help}}{{R to section}}}}
A '''parser function''' is a [[Help:Template|template]]-like construct which returns a value based on at least one unnamed parameter, separated from the function name by a colon "''':'''"; there may be more parameters which, like those of ordinary templates, are each preceded by "'''|'''". Parser functions differ by a leading [[w:Number sign|hash character]] (#):
 
# <nowiki>{{</nowiki>functionname: argument 1 | argument 2 | argument 3...}}
#* Core parser functions (standardly built into MediaWiki); this is for backwards compatibility
#* Optionally for [[mw:Extension:parser function extensions|parser function extensions]]
# <nowiki>{{</nowiki>#functionname: argument 1 | argument 2 | argument 3...}}
#* By default for parser function extensions, e.g. [[Help:ParserFunctions|ParserFunctions]] extension, to prevent collision with namespaces and interwiki prefixes
 
The distinction with [[help:variable|variable]]s is that the latter do not have any arguments which are separated by a colon.
 
For each language there is a file like MessagesEn.php specifying for each variable and parser function whether the name is case-sensitive.
 
Usually variables are case-sensitive and parser functions are not. To some variables ":R" can be added ("raw" modifier), but, although now a parser function, the name is still case-insensitive. Exceptions are the function names DISPLAYTITLE:, PAGESINNAMESPACE:, PAGESINNS:, and DEFAULTSORT: that are case-sensitive and the variable name CURRENTTIME that is case-insensitive.
 
MediaWiki's core parser functions are listed below and in [[Help:Magic words ]].
 
==Formatting==
 
===LC===
Makes a text lowercase and removes [[help:newlines and spaces|newlines and spaces]] from the start and end.
 
<nowiki>{{lc: AbC dEf }}</nowiki> gives "{{lc: AbC dEf }}".<br />
<nowiki>{{lc: Ä Β Ç }}</nowiki> gives {{lc: Ä Β Ç }}, expected ä β ç.
 
===UC===
Makes a text uppercase and removes newlines and spaces from the start and end.
 
<nowiki>{{uc: AbCdEf }}</nowiki> gives "{{uc: AbCdEf }}".<br />
<nowiki>{{uc:ä β ß}}</nowiki> gives {{uc:ä β ß}}, expected: Ä Β SS. Don't expect too much.
 
===LCFIRST===
Makes the first character lowercase and removes newlines and spaces from the start and end: <nowiki>{{lcfirst: Ab Cd }}</nowiki> gives "{{lcfirst: Ab Cd }}".
 
===UCFIRST===
Makes the first character uppercase and removes newlines and spaces from the start and end: <nowiki>{{ucfirst: aB cD }}</nowiki> gives "{{ucfirst: aB cD }}".
 
===URLENCODE===
Removes [[help:newlines and spaces|newlines and spaces]] from the start and end, and converts the remaining text into URL-friendly format by replacing spaces with "+" and other url formatting characters with their escaped equivalents: <nowiki>{{urlencode:hello world ?&=#/:}}</nowiki> gives {{urlencode:hello world ?&=#/:}}.
 
*{{xpd|urlencode: "#$%&<!---->'()*,;?[]^`{} }}
*{{xpd|urlencode:<}} (with the old preprocessor not the percent code %3C of the symbol itself, but the percent code of the HTML code &amp;lt;)
*{{xpd|urlencode:>}} (with the old preprocessor not the percent code %3E of the symbol itself, but the percent code of the HTML code &amp;gt;)
*{{xpdn|urlencode:|!}} ("|" needs to be given indirectly, using {{tim|!}})
 
NB: For anchors ''within'' a page use [[#ANCHORENCODE|<nowiki>{{anchorencode}}</nowiki>]]
 
===ANCHORENCODE===
For anchors ''within'' a page use <nowiki>{{anchorencode}}</nowiki> instead of <nowiki>{{urlencode}}</nowiki>. The results of a call to <nowiki>{{anchorencode}}</nowiki> are compatible with intra-page references generated for <nowiki>[[#link]]</nowiki>s, while <nowiki>{{urlencode}}</nowiki>-generated values are not necessarily so.
 
Note that (contrary to urlencode) the encoding made by "anchorencode", which uses the dot charactor as a prefix before a byte repesented in hexadecimal, is not fully reversible. "anchorencode" is then NOT suitable for passing query parameters. However the encoding made by "urlencode" (which uses "%" characters) is not compatible with the more restricted character sets allowed in HTML and XML for ids. tHe two encodings also differ in the way they encode the space.
 
Compare:
* <tt><nowiki>#{{anchorencode:Langue française}}</nowiki></tt> ''return:'' "'''#{{anchorencode:Langue française}}'''" ''(valid only for anchors to sections in MediaWiki pages)'', when
* <tt><nowiki>{{urlencode:Langue française}}</nowiki></tt> ''returns:'' "'''{{urlencode:Langue française}}'''" ''(for paths or query parameters in URLs, excluding anchors)''
 
The encoding made by anchorencode is suitable to give anchor names within pages made with MdiaWiki.
 
It is not guaranteed to work with other web sites: if you need to specify an anchor in a page not hosted on a server running MediaWiki, the anchor is not warrantied to work as expected. So, use "anchorencode" only for targetting a MediaWiki web site, such as those from the Xikimedia Foundation projects.
 
==NS==
Gives the namespace name for a given [[Help:Namespace|namespace]] number or name:
 
{| class="wikitable"
! Code<br>with Number !! Code<br>with Name !! Returns<br>with Number !! Returns<br>with Name
|-
| <code>{&#123;ns:-2&#125;}</code>
| <code>{&#123;ns:media}}</code>
| {{ns:-2}}
| {{ns:Media}}
|-
| <code>{&#123;ns:-1&#125;}</code>
| <code>{&#123;ns:special&#125;}</code>
| {{ns:-1}}
| {{ns:Special}}
|-
| <code>{&#123;ns:0&#125;}</code>
| (<small>not applicable</small>)
| {{ns:0}}
| (<small>not applicable</small>)
|-
| <code>{&#123;ns:1&#125;}</code>
| <code>{&#123;ns:talk&#125;}</code>
| {{ns:1}}
| {{ns:Talk}}
|-
| <code>{&#123;ns:2&#125;}</code>
| <code>{&#123;ns:user&#125;}</code>
| {{ns:2}}
| {{ns:User}}
|-
| <code>{&#123;ns:3&#125;}</code>
| <code>{&#123;ns:user_talk&#125;}</code>
| {{ns:3}}
| {{ns:User_talk}}
|-
| <code>{&#123;ns:4&#125;}</code>
| <code>{&#123;ns:project&#125;}</code>
| {{ns:4}}
| {{ns:Project}}
|-
| <code>{&#123;ns:5&#125;}</code>
| <code>{&#123;ns:project_talk&#125;}</code>
| {{ns:5}}
| {{ns:Project_talk}}
|-
| <code>{&#123;ns:6&#125;}</code>
| <code>{&#123;ns:image&#125;}</code>
| {{ns:6}}
| {{ns:Image}}
|-
| <code>{&#123;ns:7&#125;}</code>
| <code>{&#123;ns:image_talk&#125;}</code>
| {{ns:7}}
| {{ns:Image_talk}}
|-
| <code>{&#123;ns:8&#125;}</code>
| <code>{&#123;ns:mediawiki&#125;}</code>
| {{ns:8}}
| {{ns:MediaWiki}}
|-
| <code>{&#123;ns:9&#125;}</code>
| <code>{&#123;ns:mediawiki_talk&#125;}</code>
| {{ns:9}}
| {{ns:MediaWiki_talk}}
|-
| <code>{&#123;ns:10&#125;}</code>
| <code>{&#123;ns:template&#125;}</code>
| {{ns:10}}
| {{ns:Template}}
|-
| <code>{&#123;ns:11&#125;}</code>
| <code>{&#123;ns:template_talk&#125;}</code>
| {{ns:11}}
| {{ns:Template_talk}}
|-
| <code>{&#123;ns:12&#125;}</code>
| <code>{&#123;ns:help&#125;}</code>
| {{ns:12}}
| {{ns:Help}}
|-
| <code>{&#123;ns:13&#125;}</code>
| <code>{&#123;ns:help_talk&#125;}</code>
| {{ns:13}}
| {{ns:Help_talk}}
|-
| <code>{&#123;ns:14&#125;}</code>
| <code>{&#123;ns:category&#125;}</code>
| {{ns:14}}
| {{ns:Category}}
|-
| <code>{&#123;ns:15&#125;}</code>
| <code>{&#123;ns:category_talk&#125;}</code>
| {{ns:15}}
| {{ns:Category_talk}}
|-
! colspan="4" align="center" | Namespaces 100 and higher are customized by each site
|-
| <code>{&#123;ns:100&#125;}</code>
| <code>{&#123;ns:hilfe&#125;}</code>
| {{ns:100}}
| {{ns:Hilfe}}
|-
| <code>{&#123;ns:101&#125;}</code>
| <code>{&#123;ns:hilfe_diskussion&#125;}
| {{ns:101}}
| {{ns:Hilfe_Diskussion}}
|}
 
{{xpdoocc|ns:|ns:12|_talk}}.
 
{{xpdoocc|ns:|SITENAME}}.
 
{{xpdoocc|ns:|ns:8|_talk}}.
 
"<code><nowiki>{{ns:{{ns:8}} talk}}</nowiki></code>" gives "{{ns:{{ns:8}} talk}}" [http://meta.wikimedia.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7Bns%3A%7B%7Bns%3A8%7D%7D%20talk%7D%7D%22].
 
{{xpdoocc|ns:|ns:8|talk}}.
 
See [[Help:Variable]] for more canonical names like "'''<tt>project</tt>'''" and "'''<tt>talk</tt>'''".
 
=== NS:1 ===
 
{{xpdoocc|ns:|ns:0|_talk}}, just as {{xpd|ns:_talk}}. The canonical name for the talk namespace of articles is "'''<tt>talk</tt>'''" and not "'''<tt>_talk</tt>'''". Appending "_talk" to the namespace name works for all but the main namespace.
 
The following constructs work:
*"<code><nowiki>{{ns:{{ns:0}} talk}}</nowiki></code>" gives "{{ns:{{ns:0}} talk}}" [http://meta.wikimedia.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7Bns%3A%7B%7Bns%3A0%7D%7D%20talk%7D%7D%22].
*{{xpd|ns:01}}.
*{{xpd|ns:+1}}.
*{{xpd|ns:TALK}}.
*{{xpdoocc|ns:|ns:1}}.
 
<!-- Please do not change the permanent anchor for
[[m:Help:Parser functions##ns:0 gives null string]]
even if you change the section title.
--><span id="#ns:0 gives null string">
=== ns:0 gives null string ===
</span>
 
{{xpd|ns:0}}, an empty string. This is often handy, and less vulnerable to vandalism by a compromised administrator account than a template '''void''' or similar.
 
The cryptic [[Help:magic words|magic word]] [[Help:magic words#Other|<tt><nowiki>__END__</nowiki></tt>]] is no longer supported. It formerly allowed for trailing whitespace to be included in the page save, but was removed in revision [[rev:19213|19213]].
 
In constructs like <code><nowiki>{{ {{#if: {{{T|}}} | {{{T}}} | ns:0}} }}</nowiki></code>, where parameter '''T''' is
normally the name of a template to be evaluated, but can be undefined or empty, <code><nowiki>{{ns:0}}</nowiki></code>
is then a clean empty string. Without it <code><nowiki>{{}}</nowiki></code> would result in {{}}.
 
"<code><nowiki>{{ {{#if: {{{T|}}} | {{{T}}} | ns:0}} }}</nowiki></code>" gives "{{ {{#if: {{{T|}}} | {{{T}}} | ns:0}} }}"
[http://meta.wikimedia.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7B%20%7B%7B%23if%3A%20%7B%7B%7BT%7C%7D%7D%7D%20%7C%20%7B%7B%7BT%7D%7D%7D%20%7C%20ns%3A0%20%7D%7D%20%7D%7D%22].
 
{{xpdoocc|ns:|ns:0}}, because NS cannot handle an empty <code><nowiki>{{ns:0}}</nowiki></code> argument.
 
=== Empty or invisible section headers. ===
The wikitext line
=== <nowiki>{{ns:0}}</nowiki> ===
creates an entry in the TOC coded in the output HTML as
&lt;li class="toclevel-2">&lt;a href="#">&lt;span class="tocnumber">2.4&lt;/span> &lt;/a>&lt;/li>
attempting but failing to link to the null anchor
&lt;p>&lt;a name="">&lt;/a>&lt;/p>
and with an edit link similar to this:
[&lt;a href="/w/index.php?title=Help:Parser_function&amp;amp;action=edit&amp;amp;section=12">edit&lt;/a>]
The next line is <code><nowiki>=== {{ns:0}} ===</nowiki></code>. Note the edit link to the right.
 
=== {{ns:0}} ===
 
An empty section title (with an edit link to the right) as above is obtained using, in this case, <code><nowiki>=== {{ns:0}} ===</nowiki></code>. This is dubious, but arguably better than using the same trick to get invisble section headers twice on a page. At least <tt><nowiki>/*&#160;{{ns:0}}&#160;*/</nowiki></tt> makes sense in the edit history, if there's only one section using this particular trick.
 
As shown in the table of contents this and similar tricks result in non-functional links. In conjunction with <code><nowiki>__NOTOC__</nowiki></code> it's less harmful, and maybe useful to get edit links for invisible sections with categories and interlanguage links. Other possibilities for different ''invisible'' section headers:
# <code><nowiki>=== __NOTOC__ ===</nowiki></code>
# <code><nowiki>=== ===</nowiki></code>
# <code><nowiki>=== &amp;nbsp; ===</nowiki></code>
# <code><nowiki>=== &amp;#160; ===</nowiki></code>
 
==URLs etc.==
 
{|
| <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! c}}</nowiki><br /><nowiki>{{localurle:a&b! c}}</nowiki></code>
| {{localurl:a&b! c}}<br />{{localurle:a&b! c}}
|-
| <code><nowiki>{{urlencode:a&b! c}}</nowiki></code>
| {{urlencode:a&b! c}}
|-
| <code><nowiki>{{anchorencode:a&b! c}}</nowiki></code>
| {{anchorencode:a&b! c}}
|-
| <code><nowiki>{{fullurl:fullpagename}}</nowiki></code>
| <small>{{fullurl:fullpagename}}</small>
|-
| <code><nowiki>{{fullurl:ab}}</nowiki></code>
| <small>{{fullurl:ab}}</small>
|-
| <code><nowiki>{{fullurl:a b}}</nowiki></code>
| <small>{{fullurl:a b}}</small>
|-
| <code><nowiki>{{fullurl:ab|u=v}}</nowiki></code>
| <small>{{fullurl:ab|u=v}}</small>
|-
| <code><nowiki>{{fullurl:m:a b|u=v}}</nowiki></code>
| <small>{{fullurl:m:a b|u=v}}</small>
|-
| <code><nowiki>{{fullurl:m:ab|u=v}}</nowiki></code>
| <small>{{fullurl:m:ab|u=v}}</small>
|-
| <code><nowiki>{{fullurl:a b|u=v}}</nowiki></code>
| <small>{{fullurl:a b|u=v}}</small>
|-
| <code><nowiki>{{fullurl:a b|u=v w}}</nowiki></code>
| <small>{{fullurl:a b|u=v w}}</small>
|-
| <code><nowiki>{{fullurl:a&b!|u=v}}</nowiki> &#160;</code>
| <small>{{fullurl:a&b!|u=v}}</small>
|-
| <code><nowiki>{{fullurle:a&b!|u=v}}</nowiki>&#160;</code>
| <small>{{fullurle:a&b!|u=v}}</small>
|}
 
Note that with the interwiki prefix the format "wiki/" is used even for edit pages etc., while it does not write the page name in canonical form.
 
For interwiki links localurl and fullurl give the same:
{|
| <code><nowiki>{{localurl:w:a}}</nowiki><br /><nowiki>{{fullurl:w:a}}</nowiki></code>
| {{localurl:w:a}}<br />{{fullurl:w:a}}
|}
 
The parser 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. Leading and trailing spaces are stripped, but all internal spaces are preserved:
<tt><nowiki>{{urlencode:&nbsp;&#160;@&#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.
 
===Example===
Say you want to create a link in a template to the block log for blocked usernames -> "''<nowiki>{{fullurl:Special:Log/block|user=User:{{{1}}} }}</nowiki>''". This won't work with spaces in the name like "Example blocked user" (unless they are manually underlined) as you'd get: "''{{fullurl:Special:Log/block|user=User:Example blocked user}}''", so what you can do is escape it with: "''<nowiki>{{fullurl:Special:Log/block|user=User:{{urlencode:{{{1}}}}} }}</nowiki>''", giving you "''{{fullurl:Special:Log/block|user=User:{{urlencode:Example blocked user}}}}''".
 
:''See also:'' [[bugzilla:5720]]
Also, the magic words for page name like ''<nowiki>{{PAGENAME}} {{FULLPAGENAME}}</nowiki> etc'' all have 'escaped' versions: ''<nowiki>{{PAGENAMEE}} {{FULLPAGENAMEE}}</nowiki> etc''.
 
== #language: ==
<code>{&#123;#language:''code''&#125;}</code> gives the local language name of selected RFC 3066 language codes, otherwise it returns the input value as is. For a complete list see the [http://www.iana.org/assignments/language-subtag-registry IANA registry].
:{{evaldemo|#language:da}}
:{{evaldemo|#language:fo}}
:{{evaldemo|#language:zh}}
:{{evaldemo|#language:zh-min-nan}}
:{{evaldemo|#language:ang}}
:{{evaldemo|#language:tlh}} (missing, incomplete list)
:{{evaldemo|#language:frr}} (missing, introduced 2006)
:{{evaldemo|#language:mw}} (no language code as of 2006)
This function will replace {{tim|n local}} and some of the [[Special:Prefixindex/Template:Lang name -]] templates.
For actually supported alpha2 and alpha3 codes see {{tim|sttnw}}, the 27*26*26 template calls may take some time.
 
==Pages in category==
{| class="wikitable" border="2" cellpadding="4" cellspacing="0"
! Word
! Example
! Example results
! Explanation
|-
| <nowiki>{{PAGESINCATEGORY:category}}</nowiki><br/><nowiki>{{PAGESINCATEGORY:category|R}}</nowiki>
| <code><nowiki>{{PAGESINCATEGORY:User en}}</nowiki></code><br/><code><nowiki>{{PAGESINCATEGORY:User en|R}}</nowiki></code>
| <code>{{PAGESINCATEGORY:User en}}</code><br/><code>{{PAGESINCATEGORY:User en|R}}</code>
| '''[MW1.13+]''' Returns the number of pages in a given category. Including sub-category pages and file description pages.
|-
| <nowiki>{{PAGESINCAT:category}}</nowiki><br/><nowiki>{{PAGESINCAT:category|R}}</nowiki>
| <code><nowiki>{{PAGESINCAT:User en}}</nowiki></code><br/><code><nowiki>{{PAGESINCAT:User en|R}}</nowiki></code>
| <code>{{PAGESINCAT:User en}}</code><br/><code>{{PAGESINCAT:User en|R}}</code>
| '''[MW1.13+]''' Alias of PAGESINCATEGORY.
|}{{-}}
 
==Use of result==
The result, like that of a variable or template, and like a template parameter value, can be used in the following ways:
<pre>
*the name of a template: {{ {{lc:ABC}}}}
*the name of a variable: {{ {{uc:currenttime}}}}
*the name of a parser function: {{ {{uc:lc}}:ABC}}
*the name of a template parameter: {{t2|{{#expr:3-1}}=a}}
*the value of a template parameter: {{t2|{{#expr:3-1}}}}
*a template parameter default value: {{{1|{{#expr:7-2}}}}}
*the name of a switch parameter: {{#switch:2|{{#expr:3-1}}=a}}
*the value of a parser function parameter: {{#ifeq:{{lc:AbC}}|abc|yes}}
*the target or label of an internal link: [[{{lc:ABc}}|{{uc:ABc}}]]
*the target or label of an external link: [http://{{lc:ABc}} {{uc:ABc}}]
</pre>
gives:
*the name of a template: {{ {{lc:ABC}}}}
*the name of a variable: {{ {{uc:currenttime}}}}
*the name of a parser function: {{ {{uc:lc}}:ABC}}
*the name of a template parameter: {{t2|{{#expr:3-1}}=a}}
*the value of a template parameter: {{t2|{{#expr:3-1}}}}
*a template parameter default value: {{{1|{{#expr:7-2}}}}}
*the name of a switch parameter: {{#switch:2|{{#expr:3-1}}=a}}
*the value of a parser function parameter: {{#ifeq:{{lc:AbC}}|abc|yes}}
*the target or label of an internal link: [[{{lc:ABc}}|{{uc:ABc}}]]
*the target or label of an external link: [http://{{lc:ABc}} {{uc:ABc}}]
 
No longer possible with the new preprocessor:
<pre>
*a template parameter definition ( ''name'' = ''value'' ): {{pab|{{lc:AB=CD}}}}
*a switch parameter definition ( ''name'' = ''value'' ): {{#switch:ab|{{lc:AB=CD}}}}
</pre>
gives:
*a template parameter definition ( ''name'' = ''value'' ): {{pab|{{lc:AB=CD}}}}
*a switch parameter definition ( ''name'' = ''value'' ): {{#switch:ab|{{lc:AB=CD}}}}
 
The result cannot be used inside XML-style extension tags:
*<nowiki><math>{{#expr:3-1}} \over 3 </math></nowiki> gives <math>{{#expr:3-1}} \over 3 </math>
 
==Expansion==
The first step in [[Help:Expansion|expanding]] any wikitext is identifying the templates, parser functions, variables and parameters from the braces, pipes and semicolons. For a parser function the next step is expanding the wikitext for the name of the parser function.
 
Suppose for example that it is #ifexpr. Then the next step is expanding the condition. Based on that either the wikitext for the then-part or that for the else-part is expanded.
 
This is illustrated with <nowiki>{{#ifexpr:1|{{ta}}|{{tb}}}} {{#ifexpr:0|{{tc}}|{{td}}}}</nowiki> giving {{#ifexpr:1|{{ta}}|{{tb}}}} {{#ifexpr:0|{{tc}}|{{td}}}}. A page with this wikitext transcludes ta and td only (with the old preprocessor also tb and tc).
 
 
 
==Interpretation of a parser function as a template==
In some cases a "wrong" parser function call is interpreted as a template call, which results in an entry in the [[mw:templatelinks table|templatelinks table]], giving an entry in the list of pages included in a page (on the edit box of the source page) and [[Help:What links here|What links here]] of the target page.
 
This applies e.g. for localurl and fullurl if the parameter is not a valid page name, while "Template:localurl:" and "Template:fullurl:" followed by the parameter is. This is the case if the parameter is a namespace prefix followed by a colon, e.g.:
*<nowiki>{{</nowiki>localurl:Template:}} giving {{localurl:Template:}}
*<nowiki>{{</nowiki>fullurl:Template:}} giving {{fullurl:Template:}}
*<nowiki>{{</nowiki>localurl:Project:}} giving {{localurl:Project:}}
*<nowiki>{{</nowiki>fullurl:Project:}} giving {{fullurl:Project:}}
 
This entry in the templatelinks table occurs even if the result produced is not rendered due to a conditional parser function. This may occur in practice using e.g.:
*<nowiki>{{ #if:{{{1|}}}|..{{ fullurl:Template:{{{1|}}} }}..}}</nowiki>
*<nowiki>{{ #if:{{{1}}}|..{{ fullurl:Template:{{{1}}} }}..}}</nowiki> in the case that the parameter is equal to the empty string; it does not occur if the parameter is undefined, because "Template:fullurl:Template:{{{1}}}" is not a valid page name.
 
Thus the list of templates transcluded in a page may be polluted with the entries of the non-existing template [[Template:fullurl:Template:]] and similarly for other namespace names instead of the second "Template", and for "localurl" instead of "fullurl". A remedy is e.g.:
*<nowiki>{{ #if:{{{1|}}}|..{{ fullurl:Template:{{#if:{{{1}}}|{{{1}}}|[]}} }}..}}</nowiki> because "Template:fullurl:Template:[]" is not a valid page name.
 
See also {{mlm|Help:ParserFunctions|Code_execution|code execution}}.
 
==Substitution==
:''See also: '''[[Help:Substitution]]'''.''
 
Applying "subst:" to a parser function works:
 
<nowiki>{{subst:LC:AbC}}</nowiki> gives abc.
 
Note that substituting a template which uses a parser function does not replace that parser function with its result. For full recursive substitution use [[Special:ExpandTemplates]].
 
==Terminology and history==
Core parser functions were originally collectively unnamed in the MediaWiki codebase, although they were informally referred to simply as "functions" by developers. At some time around February 2006, editors of this documentation labelled them "colon functions", an unusual term which was unknown to the developers and the majority of users. In April 2006, the [[Help:ParserFunctions|ParserFunctions]] extension was introduced, along with a new extension interface allowing efficient addition of arbitrary numbers of these entities, now labelled "parser functions". The syntax for the new parser functions was modelled on that of the old core parser functions, the main difference being the addition of the leading hash "#".
 
In July 2006, the parser function interface was extended to allow old-style hashless functions, and the old core parser functions were converted from using special-case code to the new parser function interface. They were moved to a CoreParserFunctions module. Thus today, there is no difference at all in syntax or functionality between core parser functions and extension parser functions, besides the leading hash convention.
 
Despite this, some users are in the habit of reserving the term "parser function" for members of the ParserFunctions extension. This is confusing and inaccurate -- any extension may define a parser function. The parser function interface has diverse applications. Perhaps it was confusing to call the extension ParserFunctions in the first place, but it was imagined as a fairly general repository of parser functions useful to Wikimedia.
 
==See also==
*[[mw:Manual:Parser functions]]
*[[Help:ParserFunctions]]
*[[Help:Magic words]]
*[[StringFunctions]]
*{{tim|wikivar}}
*[[mw:Manual:Extending_wiki_markup|Adding parser functions]]
*[http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/CoreParserFunctions.php?view=log CoreParserFunctions.php]
*[[mw:PLURAL:|The PLURAL: function]] (also [[Help:Magic_words#Language-dependent_word_conversions|here]])
*Wikipedia: [[w:Category:Parsers|Category:Parsers]], [[w:Category:XML parsers|Category:XML parsers]] and [[w:Category:Templates using ParserFunctions|Category:Templates using ParserFunctions]]
* [[en:User:Cacycle/wikEd|wikEd]], a MediaWiki editor with syntax highlighting for templates and parser functions
 
{{h:f|langs=|enname=parser function}}