Jump to content

Wikifunctions:MediaWiki parser functions

From Wikifunctions

Functions which have similar semantics to Wikitext parser functions (a.k.a. magic words) and templates used across wikis.

MediaWiki builtins

{{urlencode:x:y/z á é|QUERY}}

(produces x%3Ay%2Fz+%C3%A1+%C3%A9)

{{urlencode:x:y/z á é|WIKI}}

(produces x:y/z_%C3%A1_%C3%A9)

10761

(produces x:y/z%20%C3%A1%20%C3%A9)

{{urlencode:x:y/z á é|PATH}}

(produces x%3Ay%2Fz%20%C3%A1%20%C3%A9)

10608

(matches)

{{anchorencode:x y z á é}}

(produces x_y_z_á_é)

{{formatnum:987654321.654321}}14280
{{formatnum:987654321.654321|NOSEP}}
{{formatnum:৯৮,৭৬,৫৪,৩২১.৬৫৪৩২১|R}}
{{#formatdate:25 dec 2009|ymd}}

(produces 2009 December 25)

{{#formatdate:dec 25,2009|dmy}}

(produces 25 December 2009)

20773

(produces 25 December 2009, not localised)

{{#formatdate:2009-12-25|mdy}}

(produces December 25, 2009)

20782

(produces December 25, 2009, not localised)

{{#formatdate:2009 dec 25|ISO 8601}}

(produces 2009-12-25)

21360

(produces 2009-12-25 but also 2009-1-1)

{{lc:DATA CENTER}}10047
{{lcfirst:DATA center}}
{{uc:text transform}}10018
{{ucfirst:text tRAnSFORM}}
{{padleft:xyz|5|abc}}14770
{{padright:xyz|5|abc}}10108
{{#language:ar|en}}

(converts code for a language to that language's name in some other language)

composition of 860 with 21329

(convert language codes to objects, then use those to look up the name)

{{#bcp47:sr-ec}}
{{#dir:en}}
{{PLURAL:0|is|are}}

(chooses from given list of declensions based on variable)

use the relevant function 11218, 11548, etc.

(chooses from given list of declensions based on variable)

{{GRAMMAR:elative|wiki}}

(looks up the relevant declension for the given case)

19530

(declines any lexeme into the relevant form, as a string, based on the given feature)

{{GENDER:Username|male text|female text|text for unspecified}}

(chooses from given list of declensions based on some editor's gender setting)

19530 if it's encoded that way on Wikidata, else something like 19601

(chooses from Wikidata forms or given list of declensions based on variable)

Extension:ParserFunctions

MediaWikiFunction
{{#expr:}}N/A; rewrite expression as a composition of logical and arithmetic functions, such as 13689 and 19708
{{#if:}}10083
{{#ifeq:}}compose 802 with 866
{{#ifexpr:}}N/A per {{#expr:}}
{{#switch:}}
{{#time:}}
{{#len:}}11040
{{#pos:}}
{{#rpos:}}
{{#sub:}}
{{#count:}}14450
{{#replace:}}
{{#explode:}}
{{#urldecode:}}10774 (imperfect match)

Module:String

These are the alternate string manipulation set used on WMF wikis, where $wgPFEnableStringFunctions is disabled. They mostly cover the same functionality as the ones from ParserExtensions but with different names and/or parameter semantics.

MediaWikiFunction
{{#invoke:String|len|target_string}}11040
{{#invoke:String|sub|target_string|start_index|end_index}}
{{#invoke:String|match|source_string|pattern_string|start_index|match_number|plain_flag|nomatch_output}}
{{#invoke:String|pos|target_string|index_value}}
{{#invoke:String|find|source_string|target_string|start_index|plain_flag}}
{{#invoke:String|replace|source_str|pattern_string|replace_string|replacement_count|plain_flag}}
{{#invoke:String|rep|source|count}}12624
{{#invoke:String|escapePattern|pattern_string}}
{{#invoke:String|count|source_str|pattern_string|plain_flag}}14450
{{#invoke:String|join|separator|string1|string2|...}}12899

Other English Wikipedia templates

MediaWikiFunction
{{ordinal|321}}14531
{{P1|a}}801
{{P1|a|b}}10265, 821, 811
{{P2|a|b}}10298, 822, 16360