Difference between revisions of "Link"

From Shihad Wiki
Jump to: navigation, search
Line 33: Line 33:
  
  
<h3 style="background: beige">#expr:</h3>
+
<h3 style="background: blue">#expr:</h3>
* syntax: {{ft|#expr|expression}}
+
* syntax: {{ft|#News|expression}}
 
 
The <tt>expr</tt> function computes mathematical expressions based on permutations of numbers (or [[variable]]s/[[parameter]]s that translate to numbers) and operators. It does not recognize strings (use <tt>[[#.23ifeq:|ifeq]]</tt> below instead). The accuracy and format of numeric results varies with the server's operating system.
 
 
 
Operators are listed below. In a complex expression, operators are evaluated from left to right with the following precedence (explained in more detail in [[Help:Calculation]]):
 
# grouping (parentheses);
 
# unary (+/- signs and NOT);
 
# multiplicative (*, /, div, mod);
 
# additive (+ and -);
 
# round;
 
# comparative (=, !=, &lt;, &gt;, etc.);
 
# logical AND;
 
# logical OR.
 
 
 
When evaluating as boolean, "0" is considered false and any other non-space value is true (boolean true is represented as "{{#expr: 30 and 7}}").
 
 
 
Decimal numbers use "." as a decimal point (<code>[[Help:Magic words#Formatting|formatnum:]]</code> can be used to change the decimal point to a comma for the appropriate locales). Scientific notation with <tt>E</tt> plus exponent is not yet supported on input for expressions, but used on output (see [[Help:Calculation]]).
 
 
 
{| class="prettytable"
 
! Operator
 
! Operation
 
! Example
 
! Result
 
|-
 
| rowspan="2" colspan="2" align="center"| ''none''
 
| {{ft|#expr|123456789012345}}
 
| {{#expr:123456789012345}}
 
|-
 
| {{ft|#expr|0.000001}}
 
| {{#expr:0.000001}}
 
|-
 
!colspan="4"| Arithmetic
 
|-
 
! +
 
| Unary positive sign
 
| {{ft|#expr|+30 * +7}}
 
| {{#expr:+30 * +7}}
 
|-
 
!-
 
| Unary negative sign
 
| {{ft|#expr|-30 * -7}}
 
| {{#expr:-30 * -7}}
 
|-
 
! *
 
| Multiplication
 
| {{ft|#expr|30 * 7}}
 
| {{#expr:30 * 7}}
 
|-
 
! /<br />div
 
| Division
 
| {{ft|#expr|30 / 7}}<br />{{ft|#expr|30 div 7}}
 
| {{#expr:30 / 7}}<br />{{#expr:30 div 7}}
 
|-
 
! <tt>+</tt>
 
| Addition
 
| {{ft|#expr|30 + 7}}
 
| {{#expr:30 + 7}}
 
|-
 
! <tt>-</tt>
 
| Subtraction
 
| {{ft|#expr|30 - 7}}
 
| {{#expr:30 - 7}}
 
|-
 
!colspan="4"| Logic
 
|-
 
! not
 
| Unary NOT<br />logical NOT
 
| {{ft|#expr|not 0 * 7}}<br />{{ft|#expr|not 30 + 7}}
 
| {{#expr: not 0 * 7}}<br />{{#expr:not 30+7}}
 
|-
 
! and
 
| Logical AND
 
|
 
{{ft|#expr|4 &lt; 5 and 4 mod 2}}
 
|{{#expr: 4<5 and 4 mod 2}}
 
|-
 
! or
 
| Logical OR
 
|
 
{{ft|#expr|4 &lt; 5 or 4 mod 2}}
 
|{{#expr: 4<5 or 4 mod 2}}
 
|-
 
!colspan="4"| Comparison
 
|-
 
! =
 
| Equality (numerical & logical)
 
| {{ft|#expr|<nowiki>30 = 7</nowiki>}}
 
| {{#expr:30 = 7}}
 
|-
 
! &lt;&gt;<br />!=
 
| Inequality, logical exclusive or
 
| {{ft|#expr|30 &lt;&gt; 7}}<br />{{ft|#expr|<nowiki>1 != 0</nowiki>}}
 
| {{#expr:30 <> 7}}<br />{{#expr:1 != 0}}
 
|-
 
! &lt;
 
| Less than
 
|
 
{{ft|#expr|30 &lt; 7}}
 
|{{#expr: 30 < 7}}
 
|-
 
! &gt;
 
| Greater than
 
|
 
{{ft|#expr|30 &gt; 7}}
 
|{{#expr: 30 > 7}}
 
|-
 
! &lt;=
 
| Less than or equal to
 
|
 
{{ft|#expr|<nowiki>30 &lt;= 7</nowiki>}}
 
|{{#expr: 30 <= 7}}
 
|-
 
! &gt;=
 
| Greater than or equal to
 
|
 
{{ft|#expr|<nowiki>30 &gt;= 7</nowiki>}}
 
|{{#expr: 30 >= 7}}
 
|-
 
!colspan="4"| Other
 
|-
 
! ( )
 
| Grouping operators
 
| {{ft|#expr|(30 + 7) * 7 }}
 
| {{#expr:(30 + 7) * 7 }}
 
|-
 
! mod
 
| "Modulo" truncates the numbers to whole numbers, divides the left number by the right, and returns the remainder that could not be divided.<br />Note: ''div'' and ''mod'' are different from all programming languages.
 
| {{ft|#expr|30 mod 7}}<br />{{ft|#expr|-8 mod -3}}<br />{{ft|#expr|8 mod 2.7}}<br />
 
| {{#expr:30 mod 7}}<br />{{#expr:-8 mod -3}}<br />{{#expr:8 mod 2.7}}<br />
 
|-
 
! round
 
| Rounds off the number on the left to the power of 1/10 given on the right.
 
| {{ft|#expr|30 / 7 round 4}}<br />{{ft|#expr|30 / 7 round 1}}<br />{{ft|#expr|1911 round -2}}<br />{{ft|#expr|-2.5 round 0}}
 
| {{#expr: 30 / 7 round 4}}<br />{{#expr:30 / 7 round 1}}<br />{{#expr:1911 round -2}}<br />{{#expr:-2.5 round 0}}
 
|}
 
  
 
<h3 style="background: beige">#if:</h3>
 
<h3 style="background: beige">#if:</h3>

Revision as of 01:57, 2 March 2008

Other languages: Template:ParserFunctions Template:H:h Template:Sspp Template:Shortcut Template:Move Template:Extension

Template:Otheruses4

The MediaWiki extension ParserFunctions is a collection of parser functions (note the difference between the name of the collection, and the general term). These parser functions have a hash character in front of the function name, so they typically have the syntax:

Template:Ft

Functions

The extension defines nine functions: expr, if, ifeq, ifexist, ifexpr, switch, time, rel2abs, and titleparts.


#expr:

#if:

The if function is an if-then-else construct. The condition is always true unless it is empty or whitespace-only. The code in the second argument is parsed if the condition is true, and the third argument is parsed if the condition is false (either or both may be blank, and the code-if-false argument can be omitted entirely).

The condition is evaluated as text, so mathematical expressions will always evaluate as true; to use expressions as conditions, see #ifexpr. It is not possible to distinguish between an undefined parameter in a template and a blank one (it is possible with #ifexpr).

Examples:

#ifeq: