Help:Processing Functions

From Mud and Blood official Wiki
Jump to: navigation, search

This is a set of parser functions that aims to provide for any missing functionality in MediaWiki or its existing repertoire of extensions. These new functions have mostly to do with how a certain piece of input is processed.

There are also a couple of less useful tags in here, but oh well. (to-do: provide usage examples)

This is a custom extension created and maintained by Bersimon.

Character Escaping

All functions in this extension support character escapes as per the table below:

From To From To From To From To
\\ \ \osc { \odc {{ \otc {{{
\0 empty \csc } \cdc }} \ctc }}}
\s space \oss [ \ods [[ \p |
\n new line \css ] \cds ]]

This means that any occurences in the From column are replaced by those in the To column.

The escapes for bracers and brackets may seem to have arbitrary names, but they are easy to remember if you follow this pattern:

(\) + (opening or closing) + (single, double or triple) + (curly bracer or square bracket)

Thus \odc stands for opening double curly bracers and produces {{.




Concatenates all arguments and expands the resulting string. In MediaWiki parlance, expanding means evaluating or parsing an input to execute all parser function calls and replace (expand) templates and variables with their true content.


A simple template call:

{{#parse:\odcVersion\odc}} → {{Version}} → 2.3.1g

Accessing a template argument from the inside of another argument:

{{echo| {{#parse: {{{message|}}} }} | message = Hello universe! }} → Hello universe!

Now in this example, we obtain the result of a failed template call -- which would be a red link to the inexisting template, as seen in this source code here:

{{inexisting}} → <a href="/wiki/index.php?title=Template:Inexisting&action=edit&redlink=1"
class="new" title="Template:Inexisting (page does not exist)">Template:Inexisting</a>

If we use #parse: to escape the result with nowiki tags, we discover that the actual output of the call is not the final HTML markup as you saw, but rather a simpler wiki markup. This reveals the underlying engine of MediaWiki that processes template and function calls—such as #parse: itself—on a first instance, then later processes all wiki markup and turns it into HTML.

Here we use pipes | to split the nowiki tags so that they are not recognized before the parsing is done, otherwise that would just stop the template call from running at all, as in the first example:

{{#parse:<nowiki>{{inexisting}}</nowiki>}} → {{inexisting}}

{{#parse:<|nowiki>{{inexisting}}<|/nowiki>}} → [[:Template:Inexisting]]



Performs any number of searches and replacements on input, then expands the result.



Removes all surrounding spaces, tabs and line breaks from around the input (i.e. from its beginning and end, but not from its middle).



Expands any number of provided tests in succession for as long as each returns a non-empty value. If all tests ran true, their concatenated results are printed. Otherwise, nothing is printed.



Similar to #allof, with the difference that all true tests are printed up to a test that fails, at which point the process will stop.



Expands each test in succession, stopping upon the first one that returns a non-empty value.



Evaluates whether the test outputs anything or it is empty, returning 1 if true and nothing at all if false.

If an optional outputType from the table below is provided, the result is translated differently, as shown:

Type On true On false Type On true On false
default 1 empty bool true false
int 1 0 ab A B
plural 2 1 invert empty -
coin heads tails polar + -
answer yes no

If the outputType is prefixed with an exclamation mark !, the result is inverted.

If an optional inputType is provided, the evaluation criteria will be, instead of an emptyness test, a case-insensitive comparison of the test with either of the possible results, which is then used upon a match and translated according to the outputType.

In this type of reverse operation, there now exists a third possibility where no match is found, in which case, by default, nothing is returned (irrespective of the outputType setting). This can be modified by providing a defaultBehavior string which, if set to T or F (case insensitive), will return true or false translated through the outputType, or if set to anything else, will be used verbatim.

Note: Character escapes are not used in this function.



Returns either 1 or nothing, at random. Useful for employing with an #if function to generate random results. Accepts an optional boolean type from the table above.


  1. Character escapes are not used in this function.
  2. The results are cached with the page and are only refreshed when: a) a new edit is previewed; b) a new edit is submitted; c) the page is purged.


> Simple throw: "{{#coinflip:}}"

Simple throw: "1"
> My coin toss yielded {{#coinflip:coin}}!

My coin toss yielded heads!



Parses a piece of text and substitutes any dice roll references it encounters in d20 or 1d20 format with the requested dice rolls. Accepts a lower or upper case D, any positive dice multiplier and any positive number of sides. The reference cannot contain spaces in it (e.g. don't type 1d 8).

You may make repeated references to the same dice roll with r#, starting with 1 for the first roll. For example:

> {{#diceroll:The vile Troll rolls d10 against you! You've suffered r1 damage!}}

The vile Troll rolls 8 against you! You've suffered 8 damage!

Also performs any amount of simple arithmetic operations (addition +, subtraction -, multiplication *, division /) on the dice results or plain numbers it encounters. Accepts any positive or negative whole numbers, with any amount of space or line breaks inbetween. Please note that divisions by 0 return 0 and are otherwise rounded to whole numbers.

All other text unrecognizable as either a dice roll, a roll reference or an arithmetic operation is left alone. This allows you to feed your whole text to the function and make any amount of operations in a single call. For instance:

> {{#diceroll: Rick rolls 2d20 against the unsuspecting reader's feeble 1d4-3!}}

Rick rolls 33 against the unsuspecting reader's feeble -1!

On this example, a null character escape is used to keep the first dice reference from being parsed:

> {{#diceroll: Mentor takes his d\012 sword and hits the goblin's trembling legs for d12!}}

Mentor takes his d12 sword and hits the goblin's trembling legs for 9!

Note: the results are cached with the page and are only refreshed when: 1) a new edit is previewed; 2) a new edit is submitted; 3) the page is purged.

Personal tools