This MediaWiki extension is a collection of parser functions. Parser functions typically have the syntax:
This module defines four functions at present: expr, if, ifeq and rand.
Contents |
The expr function computes mathematical expressions. The supported operators (roughly in order of precedence) are:
The boolean operators consider 0 to be false and 1 to be true.
Example:
{{ #expr: (100 - 32) / 9 * 5 round 0 }}
gives:
38
which is 100°F in °C, rounded to the nearest whole number.
The if function is an if-then-else construct. The syntax is:
{{ #if: <condition> | <then text> | <else text> }}
If the condition is an empty string or consists only of whitespace, then it is considered false, and the else text is returned. Otherwise, the then text is returned. The else text may be omitted, in which case the result will be blank if the condition is false.
Note that the if function does not support "=" signs or mathematical expressions. {{#if: 1 = 2|yes|no}} will return "yes", because the string "1 = 2" is not blank. It is intended as an "if defined" structure. To compare strings, use ifeq. To compare numbers, use ifexpr.
ifeq compares two strings, and returns another string depending on the result of that comparison. The syntax is:
{{ #ifeq: <comparison text 1> | <comparison text 2> | <equal text> | <not equal text> }}
ifexpr evaluates a mathematical expression and returns one of two strings depending on the result.
{{ #ifexpr: <expression> | <then text> | <else text> }}
If the expression evaluates to zero, then the else text is returned, otherwise the then text is returned. Expression syntax is the same as for expr.
The rand function gives random numbers in a specified range.
{{ #rand: <minimum> | <maximum> }}
The presence of this function does not affect the cache lifetime, so the number displayed will typically only change once per edit.
Put the following at the end of your LocalSettings.php:
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );