~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to docs/ParserFunctions-documentation.html

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
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">
3
 
<head>
4
 
<title>ParserFunctions</title>
5
 
<link rel="stylesheet" type="text/css" href="../../skins/monobook/main.css" />
6
 
</head>
7
 
<body>
8
 
<div id="globalWrapper"><div style="padding: 0 5px 30px 20px">
9
 
<h1 class="firstHeading">ParserFunctions</h1>
10
 
 
11
 
<p>This MediaWiki extension is a collection of parser functions. Parser functions typically have the syntax:</p>
12
 
<dl>
13
 
<dd>{{#functionname: argument 1 | argument 2 | argument 3...}}</dd>
14
 
</dl>
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">
17
 
<tr>
18
 
<td>
19
 
<div id="toctitle">
20
 
<h2>Contents</h2>
21
 
</div>
22
 
<ul>
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>
29
 
</ul>
30
 
</td>
31
 
</tr>
32
 
</table>
33
 
<p><a name="expr" id="expr"></a></p>
34
 
<h2>expr</h2>
35
 
<p>The <tt>expr</tt> function computes mathematical expressions. The supported operators (roughly in order of precedence) are:</p>
36
 
<dl>
37
 
<dt>*&#160;</dt>
38
 
<dd>Multiplication</dd>
39
 
<dt>/ <span style="font-weight: normal">or</span> div</dt>
40
 
<dd>Division</dd>
41
 
<dt>+&#160;</dt>
42
 
<dd>Addition</dd>
43
 
<dt>-&#160;</dt>
44
 
<dd>Subtraction (or negation)</dd>
45
 
<dt>mod&#160;</dt>
46
 
<dd>Modulo, gives the remainder of a division</dd>
47
 
<dt>round&#160;</dt>
48
 
<dd>Rounds off the number on the left to the specified number of digits after the decimal place, given on the right</dd>
49
 
<dt>=&#160;</dt>
50
 
<dd>Equality</dd>
51
 
<dt>&lt;&gt; <span style="font-weight: normal">or</span>&#160;!=&#160;</dt>
52
 
<dd>Inequality</dd>
53
 
<dt>&lt;&#160;</dt>
54
 
<dd>Less than</dd>
55
 
<dt>&gt;&#160;</dt>
56
 
<dd>Greater than</dd>
57
 
<dt>&lt;=&#160;</dt>
58
 
<dd>Less than or equal to</dd>
59
 
<dt>&gt;=&#160;</dt>
60
 
<dd>Greater than or equal to</dd>
61
 
<dt>and&#160;</dt>
62
 
<dd>Logical AND</dd>
63
 
<dt>or&#160;</dt>
64
 
<dd>Logical OR</dd>
65
 
<dt>not&#160;</dt>
66
 
<dd>Logical NOT</dd>
67
 
<dt>( )&#160;</dt>
68
 
<dd>Grouping operators</dd>
69
 
</dl>
70
 
<p>The boolean operators consider 0 to be false and 1 to be true.</p>
71
 
<p>Example:</p>
72
 
<pre>
73
 
{{ #expr: (100 - 32) / 9 * 5 round 0 }}
74
 
</pre>
75
 
<p>gives:</p>
76
 
<pre>
77
 
38
78
 
</pre>
79
 
<p>which is 100°F in °C, rounded to the nearest whole number.</p>
80
 
<p><a name="if" id="if"></a></p>
81
 
<h2>if</h2>
82
 
<p>The <tt>if</tt> function is an if-then-else construct. The syntax is:</p>
83
 
<pre>
84
 
{{ #if: <i>&lt;condition&gt;</i> | <i>&lt;then text&gt;</i> | <i>&lt;else text&gt;</i> }}
85
 
</pre>
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>
89
 
<h2>ifeq</h2>
90
 
<p><tt>ifeq</tt> compares two strings, and returns another string depending on the result of that comparison. The syntax is:</p>
91
 
<pre>
92
 
{{ #ifeq: <i>&lt;comparison text 1&gt;</i> | <i>&lt;comparison text 2&gt;</i> | <i>&lt;equal text&gt;</i> | <i>&lt;not equal text&gt;</i> }}
93
 
</pre>
94
 
<p><a name="ifexpr" id="ifexpr"></a></p>
95
 
<h2>ifexpr</h2>
96
 
<p><tt>ifexpr</tt> evaluates a mathematical expression and returns one of two strings depending on the result.</p>
97
 
<pre>
98
 
{{ #ifexpr: <i>&lt;expression&gt;</i> | <i>&lt;then text&gt;</i> | <i>&lt;else text&gt;</i> }}
99
 
</pre>
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>
102
 
<h2>rand</h2>
103
 
<p>The <tt>rand</tt> function gives random numbers in a specified range.</p>
104
 
<pre>
105
 
{{ #rand: <i>&lt;minimum&gt;</i> | <i>&lt;maximum&gt;</i> }}
106
 
</pre>
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>
111
 
<pre>
112
 
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
113
 
</pre>
114
 
</div></div>
115
 
</body>
116
 
</html>