Help:Parser function: Difference between revisions

Content deleted Content added
m moved Help:Colon function to Help:Parser function: new name of master page
update from Meta
Line 1:
{{h:h|editor toc}}
A "'''colonparser function'''" is a [[Help:Template#Predefined_templates|predefined template]]-like withconstruct onewhich parameter, or in other words,returns a [[help:variable|variable]]value withbased aon parameter.at Theleast parameter isone unnamed andparameter, separated from the function name by thea symbolcolon "''':'''", (unlike regularordinary templates, which useusing "'''|'''"). Thus the syntax is:
 
:<nowiki>{{</nowiki>functionname: argument 1 | argument 2 | argument 3...}}
Thus the syntax is:
 
or
:<nowiki>{{</nowiki> ''function name'' : ''parameter value''<nowiki> }}</nowiki>
 
:<nowiki>{{</nowiki>#functionname: argument 1 | argument 2 | argument 3...}}
The function name is not case-sensitive.
 
The function name is not case-sensitive. Further parameters (if any, depending on the function) are separated by "'''|'''".
 
Core parser functions are built into MediaWiki. For backwards compatibility, they typically have no leading hash character. Extension parser functions, such as those provided by the [[ParserFunctions]] extension, typically have a leading hash character "#" to prevent collision with namespaces and interwiki prefixes.
 
MediaWiki's core parser functions are listed below.
 
==Formatting==
Line 27 ⟶ 33:
===UCFIRST===
Makes the first character uppercase: <nowiki>{{ucfirst:aB cD}}</nowiki> gives {{ucfirst:aB cD}}.
 
===URLENCODE===
Converts the 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 ?&=#/:}}.
 
==NS==
Line 59 ⟶ 68:
Please note that <code><nowiki>{{ns:{{ns:0}}}}</nowiki></code> fails: {{ns:{{ns:0}}}}. NS cannot handle an empty <code><nowiki>{{ns:0}}</nowiki></code> argument.
 
=== Empty section title===
==== {{ns:0}} ====
 
An empty section title like 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 invisibleinvisble 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:
Line 70 ⟶ 78:
# <code><nowiki>=== &amp;#160; ===</nowiki></code>
 
== #exprlanguage: ==
<code>{&#123;#language: ''code''&#125;}</code> gives the 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].
Parser function #expr converts a string containing a numeric or boolean expression into its value. See also [[Help:Calculation]].
:{{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.
 
==ParameterGeneral expressionfeatures==
The parameter value can be an expression involving (possibly multilevel): concatenation, applying a template, parser function, or colonparser function, or using a variable.
 
Examples:
Line 80 ⟶ 99:
*using {{tim|x3}}, <nowiki>{{#expr:{{x3|1}}/3}}</nowiki> gives {{#expr:111/3}}
 
===Substitution===
 
:''See also: '''[[Help:Substitution]]'''.''
 
Applying "subst:" to a colonparser function works:
 
<nowiki>{{subst:LC:AbC}}</nowiki> gives abc.
 
Note that unless a technique like [[Help:Substitution#Optional substitution|optional recursive substitution]]
is used, substituting a template which uses a colonparser function does not replace that colonparser function with its result.
 
===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 [[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===
*[[Help:Magic words]]
*[[ParserFunctions]]
*{{tim|colon function}}
*{{tim|wikivar}}
 
{{h:f|langs=|enname=colonparser function}}