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

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., ). Allowing such codes is harmless if an alternative code is also allowed, e.g. "\" for "|".

Table of functions

extension function MediaWiki 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#coordinate1.10+
Counter#+1.15+
Data#dataArchived
Data#sortArchived
DynamicFunctions#argArchived
DynamicFunctions#ipArchived
DynamicFunctions#randArchived
DynamicFunctions#skinArchived
DynamicPageList (third-party)#dpl
ExpandAfter#expandafter (deprecated, see: #tag)Archived
ForeachFunction#foreachxArchived
ForeachFunction#foreachyArchived
HasCategory#ifhascatArchived
HideNamespace#hidens1.15+
HideNamespace#unhidens1.15+
ImageLink#img (old: #imagelink, deprecated)Archived
Infobox Data Capture#dataentryArchived
Infobox Data Capture#listsplitArchived
InterWikiLinkManager#iwlArchived
KeyValue#keyvalue1.16+
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)1.19+
ParserFunctions (extended)#ifexpr (extended)1.19+
ParserFunctions (extended)#min1.19+
ParserFunctions (extended)#max1.19+
ParserFunctions (extended)#if1.19+
ParserFunctions (extended)#ifeq1.19+
ParserFunctions (extended)#ifexist1.19+
ParserFunctions (extended)#rel2abs1.19+
ParserFunctions (extended)#switch1.19+
ParserFunctions (extended)#time1.19+
Pipe Escape#!1.23+
QPoll#qpuserchoice1.23+
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

  • Help:Magic words
  • Category:Parser function extensions
  • Writing parser functions (software development)
  • Extending wiki markup#Parser_functions
  • Sample parser function, from SVN
  • Parser function extensions with documentation on Meta:
    • Extension:Data - requires extra table data_extension in database
    • Extension:DynamicFunctions
    • Help:Extension:ParserFunctions
    • Extension:StringFunctions
    • Extension:VariablesExtension
  • Extension:Winter - "Wiki Interpreter" - Complete programming language which is very similar to native parser functions.
  • Parser functions for Wikibase (the extensions that enables Wikidata): d:Wikidata:How to use data on Wikimedia projects
This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.