Wikifunctions:MediaWiki parser functions
![]() |
This page is currently a draft. More information pertaining to this may be available on the talk page. Translation admins: Normally, drafts should not be marked for translation. |
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 |
— |
{{urlencode:x:y/z á é|WIKI}}
(produces |
URI percent encode (Z10761): encodes certain characters using URI percent encoding syntax
(produces |
{{urlencode:x:y/z á é|PATH}}
(produces |
encode URI component (Z10608): Description missing
(matches) |
{{anchorencode:x y z á é}}
(produces |
— |
{{formatnum:987654321.654321}} | display natural number (Z14280): Uses the language to determine which formatting function to use. |
{{formatnum:987654321.654321|NOSEP}} | — |
{{formatnum:৯৮,৭৬,৫৪,৩২১.৬৫৪৩২১|R}} | — |
{{#formatdate:25 dec 2009|ymd}}
(produces |
— |
{{#formatdate:dec 25,2009|dmy}}
(produces |
date (enwiki) (Z20773): A date in the dmy format
(produces |
{{#formatdate:2009-12-25|mdy}}
(produces |
date (enwiki, mdy) (Z20782): Displays a date in the mdy format in english
(produces |
{{#formatdate:2009 dec 25|ISO 8601}}
(produces |
format date (YMD, hyphen-delimited, unpadded) (Z21360): Description missing
(produces |
{{lc:DATA CENTER}} | to lowercase (Z10047): Convert a string to lowercase letters |
{{lcfirst:DATA center}} | — |
{{uc:text transform}} | to uppercase (Z10018): Convert a string to uppercase letters |
{{ucfirst:text tRAnSFORM}} | — |
{{padleft:xyz|5|abc}} | pad string with leading characters to specified length (Z14770): add specified characters at the start until the string is of the required length |
{{padright:xyz|5|abc}} | string end padding (Z10108): Add string end padding |
{{#language:ar|en}}
(converts code for a language to that language's name in some other language) |
composition of language tag to language (Z860): Converts BCP 47 language tag to Z60/Natural language object with linguonym for language in target language (Z21329): Description missing
(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 English count plurality (Z11218): takes a natural number and the plural and singular cases of a count noun and returns the correct plurality, French regular plural (Z11548): returns the regular plural of a noun in French, etc.
(chooses from given list of declensions based on variable) |
{{GRAMMAR:elative|wiki}}
(looks up the relevant declension for the given case) |
first text of lexeme matching grammatical features (Z19530): Description missing
(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) |
first text of lexeme matching grammatical features (Z19530): Description missing if it's encoded that way on Wikidata, else something like N-ifs (Z19601): An if statement any amount of times, with a matching list of options, and a final default. See triple ifs (Z19565) for a clearer way to input 2 conditions, and built-in Z802 for 1 condition.
(chooses from Wikidata forms or given list of declensions based on variable) |
Extension:ParserFunctions
MediaWiki | Function |
---|---|
{{#expr:}} | N/A; rewrite expression as a composition of logical and arithmetic functions, such as less than (natural numbers) (Z13689): returns true if the first is strictly less than the second and divide rational numbers (Z19708): Description missing |
{{#if:}} | is string blank (Z10083): Checks if a string just contains whitespaces |
{{#ifeq:}} | compose If (Z802): depending on whether the condition is true will return one or the other value with string equality (Z866): True if the first string and the second string are the same |
{{#ifexpr:}} | N/A per {{#expr:}} |
{{#switch:}} | — |
{{#time:}} | — |
{{#len:}} | string length (Z11040): Return the length of this string |
{{#pos:}} | — |
{{#rpos:}} | — |
{{#sub:}} | — |
{{#count:}} | count substrings (Z14450): returns the number of times a substring occurs in a string |
{{#replace:}} | — |
{{#explode:}} | — |
{{#urldecode:}} | URI percent decode (Z10774): decodes a percent-encoded input string (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.
MediaWiki | Function |
---|---|
{{#invoke:String|len|target_string}} | string length (Z11040): Return the length of this string |
{{#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}} | Replicate string n-times (Z12624): Replicates a string n times: (e.g. f("a",5) -> "aaaaa") |
{{#invoke:String|escapePattern|pattern_string}} | — |
{{#invoke:String|count|source_str|pattern_string|plain_flag}} | count substrings (Z14450): returns the number of times a substring occurs in a string |
{{#invoke:String|join|separator|string1|string2|...}} | join list of strings with delimiter (Z12899): returns string composed of list elements separated by a given delimiter |