Extension:Parser function extensions

From MediaWiki.org
Jump to navigation Jump to search

Other languages:
English • ‎русский • ‎日本語

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...}}

Note: 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]

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

See also[edit]