Jump to content

Parser function extensions

From wikiNonStop
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Magic words

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

Table of functions

extension function MediaWiki version
built-in lc 1.7+
built-in uc 1.7+
built-in lcfirst 1.7+
built-in ucfirst 1.7+
built-in urlencode 1.7+
built-in anchorencode 1.8+
built-in localurl 1.7+
built-in fullurl 1.7+
built-in #language 1.7+
built-in #special 1.9+
built-in #tag 1.12+
Extension:ParserFunctions (usage ) #expr 1.19+
Extension:ParserFunctions (usage ) #ifexpr 1.19+
Extension:ParserFunctions (usage ) #if 1.19+
Extension:ParserFunctions (usage ) #ifeq 1.19+
Extension:ParserFunctions (usage ) #ifexist 1.19+
Extension:ParserFunctions (usage ) #rel2abs 1.19+
Extension:ParserFunctions (usage ) #titleparts 1.19+
Extension:ParserFunctions (usage ) #switch 1.19+
Extension:ParserFunctions (usage ) #time 1.19+
Extension:AddScriptCss #addscript Archived
Extension:Arrays #arraydefine 1.23+
Extension:Arrays #arraydiff 1.23+
Extension:Arrays #arrayindex 1.23+
Extension:Arrays #arrayintersect 1.23+
Extension:Arrays #arraymerge 1.23+
Extension:Arrays #arrayprint 1.23+
Extension:Arrays #arrayreset 1.23+
Extension:Arrays #arraysearch 1.23+
Extension:Arrays #arraysearcharray 1.23+
Extension:Arrays #arraysize 1.23+
Extension:Arrays #arrayslice 1.23+
Extension:Arrays #arraysort 1.23+
Extension:Arrays #arraytohash 1.23+
Extension:Arrays #arrayunion 1.23+
Extension:Arrays #arrayunique 1.23+
Extension:Arrays #hashtoarray 1.23+
Extension:Attachments #attach 1.31+
Extension:Attachments #exturl 1.31+
Extension:Babel #babel 1.30+
Extension:CSS #css 1.25+
Extension:Coordinate #coordinate Archived
Extension:Counter #+ 1.15+
Extension:Data #data Archived
Extension:Data #sort Archived
Extension:DynamicFunctions #arg Archived
Extension:DynamicFunctions #ip Archived
Extension:DynamicFunctions #rand Archived
Extension:DynamicFunctions #skin Archived
Extension:DynamicPageList (third-party) #dpl Archived
Extension:DynamicPageList3 #dpl 1.39+
Extension:ExpandAfter #expandafter (deprecated , see: #tag) Archived
Extension:ForeachFunction #foreachx Archived
Extension:ForeachFunction #foreachy Archived
Extension:HasCategory #ifhascat Archived
Extension:HideNamespace #hidens Archived
Extension:HideNamespace #unhidens Archived
Extension:ImageLink #img (old: #imagelink, deprecated ) Archived
Extension:Infobox Data Capture #dataentry Archived
Extension:Infobox Data Capture #listsplit Archived
Extension:InterWikiLinkManager #iwl Archived
Extension:KeyValue #keyvalue Archived
Extension:Labeled Section Transclusion #lst 1.25+
Extension:Labeled Section Transclusion #lstx 1.25+
Extension:Labeled Section Transclusion #lsth 1.25+
Extension:LoopFunctions #for 1.23+
Extension:LoopFunctions #foreach 1.25+
Extension:Loops #while 1.25+
Extension:Loops #dowhile 1.25+
Extension:Loops #forargs 1.25+
Extension:Loops #fornumargs 1.25+
Extension:Loops #loop 1.25+
Extension:Maps #geocode 1.27+
Extension:Maps #display_map 1.27+
Extension:Maps #display_point 1.27+
Extension:Maps #coordinates 1.27+
Extension:Maps #distance 1.27+
Extension:MediaFunctions #media.. 1.23+
Extension:PageAfterAndBefore #pagebefore Archived
Extension:PageAfterAndBefore #pageafter Archived
Extension:PageAfterAndBefore #firstpage Archived
Extension:PageAfterAndBefore #lastpage Archived
Extension:PageFunctions #pagetitle Archived
Extension:PageFunctions #pagesubtitle Archived
Extension:PageFunctions #pageexists Archived
Extension:PageFunctions #varset Archived
Extension:PageFunctions #varget Archived
Extension:PageFunctions #varcapset Archived
Extension:PageFunctions #cshow Archived
Extension:PageFunctions #varaset Archived
Extension:PageFunctions #varaget Archived
Extension:ParserFunctions (extended) #expr (extended) Archived
Extension:ParserFunctions (extended) #ifexpr (extended) Archived
Extension:ParserFunctions (extended) #min Archived
Extension:ParserFunctions (extended) #max Archived
Extension:ParserFunctions (extended) #if Archived
Extension:ParserFunctions (extended) #ifeq Archived
Extension:ParserFunctions (extended) #ifexist Archived
Extension:ParserFunctions (extended) #rel2abs Archived
Extension:ParserFunctions (extended) #switch Archived
Extension:ParserFunctions (extended) #time Archived
Extension:Pipe Escape #! 1.23+
Extension:QPoll #qpuserchoice Archived
Extension:RegexTools #regex Archived
Extension:RegexTools #regex_vars Archived
Extension:Scribunto #invoke
Extension:SecureProperties #pg Archived
Extension:SecureProperties #ps Archived
Extension:SecureProperties #pf Archived
Extension:SecureProperties #gg Archived
Extension:SecureProperties #gs Archived
Extension:Semantic MediaWiki #ask 1.27+
Extension:Semantic MediaWiki #concept 1.27+
Extension:Semantic MediaWiki #info 1.27+
Extension:Semantic MediaWiki #show 1.27+
Extension:Semantic MediaWiki #set 1.27+
Extension:StringFunctions #len 1.7+
Extension:StringFunctions #pos 1.7+
Extension:StringFunctions #rpos 1.7+
Extension:StringFunctions #sub 1.7+
Extension:StringFunctions #pad 1.7+
Extension:StringFunctions #replace 1.7+
Extension:StringFunctions #explode 1.7+
Extension:StringFunctions #urlencode 1.7+
Extension:StringFunctions #urldecode 1.7+
Extension:TreeAndMenu #tree 1.23+
Extension:TreeAndMenu #menu 1.23+
Extension:Variables #vardefine 1.29+
Extension:Variables #vardefineecho 1.29+
Extension:Variables #var 1.29+
Extension:Variables #varexists 1.29+
Extension:Variables #var_final 1.29+
Extension:Wikibase Client #property
Extension:Wikibase Client #statements

See also