Difference between revisions of "Link"

From Shihad Wiki
Jump to: navigation, search
(Removing all content from page)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
<small>'''Other languages:''' {{ParserFunctions}}</small>
 
{{h:h}}
 
{{sspp}}
 
{{shortcut|[[WM:PF]]}}
 
{{move|[[mw:Extension:ParserFunctions]]}}
 
{{extension
 
|name        = ParserFunctions
 
|image      =
 
|type        = Parser Extension
 
|maturity    = Stable
 
|mediawiki  = > 1.6.8
 
|version    = N/A
 
|update      = 2006-11-21
 
|description = A collection of [[Help:parser function|parser functions]] such as branching instructions and expression handler and time calculation unit.
 
}}
 
  
{{otheruses4|the MediaWiki extension '''ParserFunctions'''|parser functions in general|Help:Parser function}}
 
 
The [[w:MediaWiki|MediaWiki]] extension '''[[mw:Extension:ParserFunctions|ParserFunctions]]''' is a collection of [[Help:parser function|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:
 
: {{ft|#functionname|<nowiki>argument 1 | argument 2 | argument 3...</nowiki>}}
 
 
==Functions==
 
The extension defines nine functions:
 
<tt>[[#.23expr:|expr]]</tt>,
 
<tt>[[#.23if:|if]]</tt>,
 
<tt>[[#.23ifeq:|ifeq]]</tt>,
 
<tt>[[#.23ifexist:|ifexist]]</tt>,
 
<tt>[[#.23ifexpr:|ifexpr]]</tt>,
 
<tt>[[#.23switch:|switch]]</tt>,
 
<tt>[[#.23time:|time]]</tt>,
 
<tt>[[#.23rel2abs:|rel2abs]]</tt>, and
 
<tt>[[#.23titleparts:|titleparts]]</tt>.
 
 
 
<h3 style="background: beige">#expr:</h3>
 
* syntax: {{ft|#expr|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>
 
* syntax:
 
*: {{ft|#if|<nowiki><condition string> | <code if true></nowiki>}}
 
*: {{ft|#if|<nowiki><condition string> | <code if true> | <code if false></nowiki>}}
 
 
The <code>if</code> 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 <tt>[[#.23ifexpr:|#ifexpr]]</tt>. It is not possible to distinguish between an undefined parameter in a template and a blank one (it is possible with <tt>[[#.23ifexpr:|#ifexpr]]</tt>).
 
 
Examples:
 
* {{ft|#if|<nowiki>foo | do if true | do if false</nowiki>}} = {{#if:foo| do if true | do if false}}
 
* {{ft|#if|<nowiki>0  | do if true | do if false</nowiki>}} = {{#if:0  | do if true | do if false}}
 
* {{ft|#if|<nowiki>    | do if true | do if false</nowiki>}} = {{#if:  | do if true | do if false}}
 
 
<h3 style="background: beige">#ifeq:</h3>
 
* syntax:
 
*: {{ft|#ifeq|<nowiki><text 1> | <text 2> | <code if equal></nowiki>}}
 
*: {{ft|#ifeq|<nowiki><text 1> | <text 2> | <code if equal> | <code if not equal></nowiki>}}
 
 
 
[[Category:Pages to be exported to MediaWiki.org]]
 

Latest revision as of 01:17, 3 March 2008