Help:ParserFunctions: Difference between revisions

Content deleted Content added
Tim Starling (talk | contribs)
new extension
 
m Reverted changes by 146.0.216.80 (talk) to last version by Sakura emad
Tag: Rollback
 
(643 intermediate revisions by more than 100 users not shown)
Line 1:
{{MovedToMediaWiki|Help:Extension:ParserFunctions}}
This MediaWiki extension is a collection of parser functions. Parser functions have been around for a while, but the ability to put them in extensions only arose with MediaWiki 1.6. They typically have the syntax:
{{languages}}
 
:<nowiki>{{</nowiki>functionname: argument 1 | argument 2 | argument 3...}}
 
Because of the presence of the colon, they compete for namespace with interwiki links and article namespaces, not with templates. Functions which existed before this module was created include LOCALURL, NS and GRAMMAR.
 
Three functions are defined at present: <tt>expr</tt>, <tt>if</tt> and <tt>ifeq</tt>.
 
== expr ==
 
The <tt>expr</tt> function computes mathematical expressions. The supported operators (roughly in order of precedence) are:
 
; * : Multiplication
; / : Division
; + : Addition
; - : Subtraction (or negation)
; mod : Modulo, gives the remainder of a division
; round : Rounds off the number on the left to the specified number of digits after the decimal place, given on the right
; = : Numerical equality
; and : Logical AND
; or : Logical OR
; not : Logical NOT
; ( ) : Grouping operators
 
The boolean operators consider 0 to be false and 1 to be true.
 
Example:
 
<nowiki>{{expr: (100 - 32) / 9 * 5 round 0}}</nowiki>
 
gives:
 
{{expr: (100 - 32) / 9 * 5 round 0}}
 
which is 100&deg;F in &deg;C, rounded to the nearest whole number.
 
== if ==
 
The <tt>if</tt> function is an if-then-else construct. The syntax is:
 
<nowiki>{{</nowiki>if: ''&lt;condition> | ''&lt;then text>'' | ''&lt;else text>'' }}
 
If the condition is 0 or an empty string (ignoring leading and trailing space), 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.
 
== ifeq ==
 
<tt>ifeq</tt> takes 4 parameters:
 
# The first string to compare
# The second string to compare
# The text to return if they are equal
# The text to return if they are not equal