Розширення функцій парсеру

From mediawiki.org
This page is a translated version of the page Parser function extensions and the translation is 62% complete.

"Функція парсеру" — це схожа на шаблон конструкція, що повертає значення відповідно до хоча б одного параметра, від'єднаного від назви функції двокрапкою [:]. Може бути і більше одного параметра; як і в звичайних шаблонах, ці параметри мають бути розділені "лінією" [|]. У випадку символа решітки [#] перед назвою функції (що запобігає зіткненню з просторами імен та префіксами інтервікі), це може або не може вважатися частиною назви. Якщо він вважається частиною назви, синтаксис буде таким

{{functionname: argument 1 | argument 2 | argument 3...}}
Якщо викликач не має параметрів щоб забезпечити функцію парсеру, тоді синтаксис є просто {{назвафункції:}}, якщо застосовується символ решітки (як це зазвичай буває) тоді синтаксис є {{#назвафункції:}}. Якщо після назви функції немає двокрапки, тоді назвафункції не розпізнається парсером.

Параметри не можуть напряму містити "|" або "}}", якщо це не є частиною кода виклику шаблона, виклику функції, змінної, посилання або зображення, але вони можуть містити їх довільно використавши шаблон, наприклад, m:Template:!, або функцію парсеру.

Код може вказувати, чи назва функції чутлива до регістру.

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+
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 (third-party) #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+
Розширення:Мапи #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) 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 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+
Variables #vardefine 1.29+
Variables #vardefineecho 1.29+
Variables #var 1.29+
Variables #varexists 1.29+
Variables #var_final 1.29+
Розширення:Клієнт Wikibase #property
Розширення:Клієнт Wikibase #statements


Див. також