Jump to content

Parser function extensions

From mediawiki.org

A "parser function" is a template-like construct that returns a value based on at least one unnamed parameter, separated from the function name by a colon [:]. There may be more parameters, as well; like those of ordinary templates, these additional parameters are each preceded by a "pipe" [|]. In the case of a hash character [#] at the start of the function name (which prevents collision with namespaces and interwiki prefixes), this may or may not be considered part of the name. If it is considered part of the name, the syntax is of the form

{{functionname: argument 1 | argument 2 | argument 3...}}
If the caller has no arguments to provide the parser function, then the form is simply {{functionname:}} or, when a hash character applies (as is normally the case) then the form is {{#functionname:}}. If the trailing colon is not supplied, then functionname is not recognized by the parser.

Arguments cannot directly contain "|" or "}}" except as part of the code of a template call, parser function call, variable, link or image, but they can contain them arbitrarily using a template, e.g., m:Template:!, or a parser function.

The code can specify whether the function name is case-sensitive.

The separation of the arguments from each other is with "|", and from the function name is with the first ":" The expansion of each of these pieces is standard, as in Special:ExpandTemplates (which is a good place to experiment, by the way, if you are learning this stuff) and is beyond the control of the parser function itself.

However, everything else can be different for each parser function, including:

  • whether an argument is just a value, or of the form parname = parvalue, or whatever
  • if applicable, whether parameter names are case-sensitive

Syntax prescribed by a parser function extension

[edit]

In view of the above, it is advantageous to make an extension such that the syntax to be used in an argument does not contain the pipe character "|" or double braces (more specifically, double closing braces "}}" ). This, in spite of the fact that a pipe character would otherwise seem a suitable symbol for, e.g., a choice or union (see, e.g., [1]). Allowing such codes is harmless if an alternative code is also allowed, e.g. "\" for "|".

Table of functions

[edit]
extensionfunctionMediaWiki version
built-inlc1.7+
built-inuc1.7+
built-inlcfirst1.7+
built-inucfirst1.7+
built-inurlencode1.7+
built-inanchorencode1.8+
built-inlocalurl1.7+
built-infullurl1.7+
built-in#language1.7+
built-in#special1.9+
built-in#tag1.12+
ParserFunctions (usage)#expr1.19+
ParserFunctions (usage)#ifexpr1.19+
ParserFunctions (usage)#if1.19+
ParserFunctions (usage)#ifeq1.19+
ParserFunctions (usage)#ifexist1.19+
ParserFunctions (usage)#rel2abs1.19+
ParserFunctions (usage)#titleparts1.19+
ParserFunctions (usage)#switch1.19+
ParserFunctions (usage)#time1.19+
AddScriptCss#addscriptArchived
Arrays#arraydefine1.23+
Arrays#arraydiff1.23+
Arrays#arrayindex1.23+
Arrays#arrayintersect1.23+
Arrays#arraymerge1.23+
Arrays#arrayprint1.23+
Arrays#arrayreset1.23+
Arrays#arraysearch1.23+
Arrays#arraysearcharray1.23+
Arrays#arraysize1.23+
Arrays#arrayslice1.23+
Arrays#arraysort1.23+
Arrays#arraytohash1.23+
Arrays#arrayunion1.23+
Arrays#arrayunique1.23+
Arrays#hashtoarray1.23+
Attachments#attach1.31+
Attachments#exturl1.31+
Babel#babel1.30+
CSS#css1.25+
Coordinate#coordinateArchived
Counter#+1.15+
Data#dataArchived
Data#sortArchived
DynamicFunctions#argArchived
DynamicFunctions#ipArchived
DynamicFunctions#randArchived
DynamicFunctions#skinArchived
DynamicPageList (third-party)#dplArchived
DynamicPageList3#dpl1.39+
ExpandAfter#expandafter (deprecated, see: #tag)Archived
ForeachFunction#foreachxArchived
ForeachFunction#foreachyArchived
HasCategory#ifhascatArchived
HideNamespace#hidensArchived
HideNamespace#unhidensArchived
ImageLink#img (old: #imagelink, deprecated)Archived
Infobox Data Capture#dataentryArchived
Infobox Data Capture#listsplitArchived
InterWikiLinkManager#iwlArchived
KeyValue#keyvalueArchived
Labeled Section Transclusion#lst1.25+
Labeled Section Transclusion#lstx1.25+
Labeled Section Transclusion#lsth1.25+
LoopFunctions#for1.23+
LoopFunctions#foreach1.25+
Loops#while1.25+
Loops#dowhile1.25+
Loops#forargs1.25+
Loops#fornumargs1.25+
Loops#loop1.25+
Maps#geocode1.27+
Maps#display_map1.27+
Maps#display_point1.27+
Maps#coordinates1.27+
Maps#distance1.27+
MediaFunctions#media..1.23+
PageAfterAndBefore#pagebeforeArchived
PageAfterAndBefore#pageafterArchived
PageAfterAndBefore#firstpageArchived
PageAfterAndBefore#lastpageArchived
PageFunctions#pagetitleArchived
PageFunctions#pagesubtitleArchived
PageFunctions#pageexistsArchived
PageFunctions#varsetArchived
PageFunctions#vargetArchived
PageFunctions#varcapsetArchived
PageFunctions#cshowArchived
PageFunctions#varasetArchived
PageFunctions#varagetArchived
ParserFunctions (extended)#expr (extended)Archived
ParserFunctions (extended)#ifexpr (extended)Archived
ParserFunctions (extended)#minArchived
ParserFunctions (extended)#maxArchived
ParserFunctions (extended)#ifArchived
ParserFunctions (extended)#ifeqArchived
ParserFunctions (extended)#ifexistArchived
ParserFunctions (extended)#rel2absArchived
ParserFunctions (extended)#switchArchived
ParserFunctions (extended)#timeArchived
Pipe Escape#!1.23+
QPoll#qpuserchoiceArchived
RegexTools#regexArchived
RegexTools#regex_varsArchived
SecureProperties#pgArchived
SecureProperties#psArchived
SecureProperties#pfArchived
SecureProperties#ggArchived
SecureProperties#gsArchived
Semantic MediaWiki#ask1.27+
Semantic MediaWiki#concept1.27+
Semantic MediaWiki#info1.27+
Semantic MediaWiki#show1.27+
Semantic MediaWiki#set1.27+
StringFunctions#len1.7+
StringFunctions#pos1.7+
StringFunctions#rpos1.7+
StringFunctions#sub1.7+
StringFunctions#pad1.7+
StringFunctions#replace1.7+
StringFunctions#explode1.7+
StringFunctions#urlencode1.7+
StringFunctions#urldecode1.7+
TreeAndMenu#tree1.23+
TreeAndMenu#menu1.23+
Variables#vardefine1.29+
Variables#vardefineecho1.29+
Variables#var1.29+
Variables#varexists1.29+
Variables#var_final1.29+
Wikibase Client#property
Wikibase Client#statements


See also

[edit]
close