解析器函数扩展
此頁面已过时。 |
“解析器函数”是一种模板式的构造,它根据至少一个未命名参数返回一个值,该参数与函数名之间用冒号 [:] 分隔。也可能有更多的参数;像普通模板一样,这些额外的参数每个前面都由一个“管道”符号 [|] 引导。如果函数名以井号字符 [#] 开头(这可以防止与命名空间和跨维基前缀发生冲突),这个字符可能或可能不被视为名称的一部分。如果它被视为名称的一部分,那么语法形式如下:
- {{functionname: argument 1 | argument 2 | argument 3...}}
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 "|".
函數列表
扩展 | 函數 | MediaWiki版本 |
---|---|---|
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+ |
解析器函數 (usage ) | #expr | 1.19+ |
解析器函數 (usage ) | #ifexpr | 1.19+ |
解析器函數 (usage ) | #if | 1.19+ |
解析器函數 (usage ) | #ifeq | 1.19+ |
解析器函數 (usage ) | #ifexist | 1.19+ |
解析器函數 (usage ) | #rel2abs | 1.19+ |
解析器函數 (usage ) | #titleparts | 1.19+ |
解析器函數 (usage ) | #switch | 1.19+ |
解析器函數 (usage ) | #time | 1.19+ |
AddScriptCss | #addscript | Archived |
数组 | #arraydefine | 1.23+ |
数组 | #arraydiff | 1.23+ |
数组 | #arrayindex | 1.23+ |
数组 | #arrayintersect | 1.23+ |
数组 | #arraymerge | 1.23+ |
数组 | #arrayprint | 1.23+ |
数组 | #arrayreset | 1.23+ |
数组 | #arraysearch | 1.23+ |
数组 | #arraysearcharray | 1.23+ |
数组 | #arraysize | 1.23+ |
数组 | #arrayslice | 1.23+ |
数组 | #arraysort | 1.23+ |
数组 | #arraytohash | 1.23+ |
数组 | #arrayunion | 1.23+ |
数组 | #arrayunique | 1.23+ |
数组 | #hashtoarray | 1.23+ |
Attachments | #attach | 1.31+ |
Attachments | #exturl | 1.31+ |
巴別 | #babel | 1.30+ |
CSS | #css | 1.25+ |
Coordinate | #coordinate | Archived |
Counter | #+ | 1.15+ |
Data | #data | Archived |
Data | #sort | Archived |
DynamicFunctions | #arg | Archived |
DynamicFunctions | #ip | Archived |
DynamicFunctions | #rand | Archived |
DynamicFunctions | #skin | Archived |
DynamicPageList (第三方) | #dpl | Archived |
DynamicPageList3 | #dpl | 1.39+ |
ExpandAfter | #expandafter (deprecated , see: #tag) | Archived |
ForeachFunction | #foreachx | Archived |
ForeachFunction | #foreachy | Archived |
HasCategory | #ifhascat | Archived |
HideNamespace | #hidens | Archived |
HideNamespace | #unhidens | Archived |
ImageLink | #img (old: #imagelink, deprecated ) | Archived |
Infobox Data Capture | #dataentry | Archived |
Infobox Data Capture | #listsplit | Archived |
InterWikiLinkManager | #iwl | Archived |
KeyValue | #keyvalue | Archived |
標記式章節嵌入 | #lst | 1.25+ |
標記式章節嵌入 | #lstx | 1.25+ |
標記式章節嵌入 | #lsth | 1.25+ |
LoopFunctions | #for | 1.23+ |
LoopFunctions | #foreach | 1.25+ |
迴圈 | #while | 1.25+ |
迴圈 | #dowhile | 1.25+ |
迴圈 | #forargs | 1.25+ |
迴圈 | #fornumargs | 1.25+ |
迴圈 | #loop | 1.25+ |
地圖 | #geocode | 1.27+ |
地圖 | #display_map | 1.27+ |
地圖 | #display_point | 1.27+ |
地圖 | #coordinates | 1.27+ |
地圖 | #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) | Archived |
ParserFunctions (extended) | #ifexpr (extended) | Archived |
ParserFunctions (extended) | #min | Archived |
ParserFunctions (extended) | #max | Archived |
ParserFunctions (extended) | #if | Archived |
ParserFunctions (extended) | #ifeq | Archived |
ParserFunctions (extended) | #ifexist | Archived |
ParserFunctions (extended) | #rel2abs | Archived |
ParserFunctions (extended) | #switch | Archived |
ParserFunctions (extended) | #time | Archived |
Pipe Escape | #! | 1.23+ |
QPoll | #qpuserchoice | Archived |
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+ |
变量 | #vardefine | 1.29+ |
变量 | #vardefineecho | 1.29+ |
变量 | #var | 1.29+ |
变量 | #varexists | 1.29+ |
变量 | #var_final | 1.29+ |
Wikibase客户端 | #property | |
Wikibase客户端 | #statements |
參見
- Help:魔术字
- 分类:解析器函数扩展
- Writing parser functions (software development)
- Parser functions for Wikibase (the extensions that enables Wikidata): d:Wikidata:How to use data on Wikimedia projects