解析器函数扩展
Appearance
此页面已过时。 |
“解析器函数”是一种类模板式的构思,它会根据一个以上的未命名参数返回一个值,该参数与函数名之间以冒号[:]分隔。 也可能是有更多的参数;就像普通模板一样,这些额外的参数每个前面都由一个“管道”符号[|]引导。 如果函数名以井号字符[#]开头(这可以避免与命名空间或跨维基的前缀相抵触),这个字符可能会也可能不会被视为是名称的一部分。 如果它被视为名称的一部分,其语法的形式如下:
- {{functionname: argument 1 | argument 2 | argument 3...}}
若调用者提供给解析函数的是没有参数,则其形式单纯为{{functionname:}};或是,当需使用井号符号(是正常的情况)时,则形式为 {{#functionname:}}。若是末尾未提供冒号,则解析器将无法识别functionname。
参数不能直接包含有"|"或"}}",除非作为模板调用、解析器函数调用、变量、链接、或图片...的代码的一部分,但参数却可使用模板(例如m:Template:!)或解析器函数来任意包含这些元素。
代码可指定函数名称是否区分大小写。
参数彼此之间的分隔是使用"|"符号、而与函数名称之间的分隔则是使用第一个":"。这些片段的展开机制是遵循标准规范,如同在Special:ExpandTemplates的情形一样(顺带一提,若您正在学习相关知识,此处是绝佳的实验场地),其运作方式不受解析器函数本身的控制。
然而,其余所有的设定皆可针对每个解析器函数个别调整,包括:
- 参数是否仅是一个值,或以“参数名称”=“参数值”等形式,或其他任何形式
- 若适用,参数名称是否区分大小写
由解析器函数扩展所规定的语法
鉴于上述情况,制作一个扩展以确保参数中所使用的语法“不会”包含管道符号"|"或是双花括号(更具体地说,是闭合的双花括号 "}}")是有好处的。 尽管如此,管道符号本应是表示选择或联合等概念的合适符号(请参见,例如 [1])。 允许此类的代码是无害的,只要同时允许替代的代码,例如将"\"用于"|"。
函数列表
| 扩展 | 函数 | 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+ |
| 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 |
| 数组 | #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(巴别) | #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 |
| 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) | 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 |
| Scribunto | #invoke | |
| SecureProperties | #pg | Archived |
| SecureProperties | #ps | Archived |
| SecureProperties | #pf | Archived |
| SecureProperties | #gg | Archived |
| SecureProperties | #gs | Archived |
| Semantic MediaWiki(语义 MediaWiki) | #ask | 1.27+ |
| Semantic MediaWiki(语义 MediaWiki) | #concept | 1.27+ |
| Semantic MediaWiki(语义 MediaWiki) | #info | 1.27+ |
| Semantic MediaWiki(语义 MediaWiki) | #show | 1.27+ |
| Semantic MediaWiki(语义 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+ |
| Wikibase Client(Wikibase客户端) | #property | |
| Wikibase Client(Wikibase客户端) | #statements |
参见
- 帮助:魔术字
- 分类:解析器函数扩展
- Writing parser functions (software development)
- Parser functions for Wikibase (the extensions that enables Wikidata): d:Wikidata:How to use data on Wikimedia projects