Extension:Parser function extensions

From MediaWiki.org
Jump to: navigation, search

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 | edit source]

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 | edit source]

extension function
built-in lc
built-in uc
built-in lcfirst
built-in ucfirst
built-in urlencode
built-in anchorencode
built-in localurl
built-in fullurl
built-in #language
built-in #special
built-in #tag
ParserFunctions (usage) #expr
ParserFunctions (usage) #ifexpr
ParserFunctions (usage) #if
ParserFunctions (usage) #ifeq
ParserFunctions (usage) #ifexist
ParserFunctions (usage) #rel2abs
ParserFunctions (usage) #titleparts
ParserFunctions (usage) #switch
ParserFunctions (usage) #time
Maps #geocode
Maps #display_map
Maps #display_point
Maps #coordinates
Maps #distance
AddScriptCss #addscript
CSS #css
Coordinate #coordinate
Counter #+
Data #data
Data #sort
DynamicFunctions #arg
DynamicFunctions #ip
DynamicFunctions #rand
DynamicFunctions #skin
DynamicPageList #dpl
ExpandAfter #expandafter (deprecated, see: #tag)
ForeachFunction #foreachx
ForeachFunction #foreachy
HasCategory #ifhascat
HideNamespace #hidens
HideNamespace #unhidens
ImageLink #img (old: #imagelink, deprecated)
Infobox Data Capture #dataentry
Infobox Data Capture #listsplit
InterWikiLinkManager #iwl
Labeled Section Transclusion #lst
Labeled Section Transclusion #lstx
Labeled Section Transclusion #lsth
LoopFunctions #for
LoopFunctions #foreach
Loops #while
Loops #dowhile
Loops #forargs
Loops #fornumargs
Loops #loop
MediaFunctions #media..
PageAfterAndBefore #pagebefore
PageAfterAndBefore #pageafter
PageAfterAndBefore #firstpage
PageAfterAndBefore #lastpage
PageFunctions #pagetitle
PageFunctions #pagesubtitle
PageFunctions #pageexists
PageFunctions #varset
PageFunctions #varget
PageFunctions #varcapset
PageFunctions #cshow
PageFunctions #varaset
PageFunctions #varaget
ParserFunctions (extended) #expr (extended)
ParserFunctions (extended) #ifexpr (extended)
ParserFunctions (extended) #min
ParserFunctions (extended) #max
ParserFunctions (extended) #if
ParserFunctions (extended) #ifeq
ParserFunctions (extended) #ifexist
ParserFunctions (extended) #rel2abs
ParserFunctions (extended) #switch
ParserFunctions (extended) #time
Pipe Escape #!
QPoll #qpuserchoice
RegexTools #regex
RegexTools #regex_vars
Secure Properties #pg
Secure Properties #ps
Secure Properties #pf
Secure Properties #gg
Secure Properties #gs
Semantic MediaWiki #ask
Semantic MediaWiki #concept
Semantic MediaWiki #info
Semantic MediaWiki #show
Semantic MediaWiki #set
StringFunctions #len
StringFunctions #pos
StringFunctions #rpos
StringFunctions #sub
StringFunctions #pad
StringFunctions #replace
StringFunctions #explode
StringFunctions #urlencode
StringFunctions #urldecode
Tree and Menu #tree
Tree and Menu #menu
VariablesExtension #vardefine
VariablesExtension #var
Language: English  • 日本語

See also[edit | edit source]