1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
4
<title>ParserFunctions</title>
5
<link rel="stylesheet" type="text/css" href="../../skins/monobook/main.css" />
8
<div id="globalWrapper"><div style="padding: 0 5px 30px 20px">
9
<h1 class="firstHeading">ParserFunctions</h1>
11
<p>This MediaWiki extension is a collection of parser functions. Parser functions typically have the syntax:</p>
13
<dd>{{#functionname: argument 1 | argument 2 | argument 3...}}</dd>
15
<p>This module defines four functions at present: <tt>expr</tt>, <tt>if</tt>, <tt>ifeq</tt> and <tt>rand</tt>.</p>
16
<table id="toc" class="toc" summary="Contents">
23
<li class='toclevel-1'><a href="#expr"><span class="tocnumber">1</span> <span class="toctext">expr</span></a></li>
24
<li class='toclevel-1'><a href="#if"><span class="tocnumber">2</span> <span class="toctext">if</span></a></li>
25
<li class='toclevel-1'><a href="#ifeq"><span class="tocnumber">3</span> <span class="toctext">ifeq</span></a></li>
26
<li class='toclevel-1'><a href="#ifexpr"><span class="tocnumber">4</span> <span class="toctext">ifexpr</span></a></li>
27
<li class='toclevel-1'><a href="#rand"><span class="tocnumber">5</span> <span class="toctext">rand</span></a></li>
28
<li class='toclevel-1'><a href="#Installation"><span class="tocnumber">6</span> <span class="toctext">Installation</span></a></li>
33
<p><a name="expr" id="expr"></a></p>
35
<p>The <tt>expr</tt> function computes mathematical expressions. The supported operators (roughly in order of precedence) are:</p>
38
<dd>Multiplication</dd>
39
<dt>/ <span style="font-weight: normal">or</span> div</dt>
44
<dd>Subtraction (or negation)</dd>
46
<dd>Modulo, gives the remainder of a division</dd>
48
<dd>Rounds off the number on the left to the specified number of digits after the decimal place, given on the right</dd>
51
<dt><> <span style="font-weight: normal">or</span> != </dt>
58
<dd>Less than or equal to</dd>
60
<dd>Greater than or equal to</dd>
68
<dd>Grouping operators</dd>
70
<p>The boolean operators consider 0 to be false and 1 to be true.</p>
73
{{ #expr: (100 - 32) / 9 * 5 round 0 }}
79
<p>which is 100°F in °C, rounded to the nearest whole number.</p>
80
<p><a name="if" id="if"></a></p>
82
<p>The <tt>if</tt> function is an if-then-else construct. The syntax is:</p>
84
{{ #if: <i><condition></i> | <i><then text></i> | <i><else text></i> }}
86
<p>If the condition is an empty string or consists only of whitespace, then it is considered false, and the <i>else text</i> is returned. Otherwise, the <i>then text</i> is returned. The <i>else text</i> may be omitted, in which case the result will be blank if the condition is false.</p>
87
<p>Note that the <tt>if</tt> function does <b>not</b> 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 <tt>ifeq</tt>. To compare numbers, use <tt>ifexpr</tt>.</p>
88
<p><a name="ifeq" id="ifeq"></a></p>
90
<p><tt>ifeq</tt> compares two strings, and returns another string depending on the result of that comparison. The syntax is:</p>
92
{{ #ifeq: <i><comparison text 1></i> | <i><comparison text 2></i> | <i><equal text></i> | <i><not equal text></i> }}
94
<p><a name="ifexpr" id="ifexpr"></a></p>
96
<p><tt>ifexpr</tt> evaluates a mathematical expression and returns one of two strings depending on the result.</p>
98
{{ #ifexpr: <i><expression></i> | <i><then text></i> | <i><else text></i> }}
100
<p>If the expression evaluates to zero, then the <i>else text</i> is returned, otherwise the <i>then text</i> is returned. Expression syntax is the same as for <tt>expr</tt>.</p>
101
<p><a name="rand" id="rand"></a></p>
103
<p>The <tt>rand</tt> function gives random numbers in a specified range.</p>
105
{{ #rand: <i><minimum></i> | <i><maximum></i> }}
107
<p>The presence of this function does not affect the cache lifetime, so the number displayed will typically only change once per edit.</p>
108
<p><a name="Installation" id="Installation"></a></p>
109
<h2>Installation</h2>
110
<p>Put the following at the end of your LocalSettings.php:</p>
112
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );