Help:Extension:ParserFunctions/de

Die Erweiterung ParserFunctions bietet elf zusätzliche Funktionen, um die "Magic words" zu ergänzen, die es in MediaWiki bereits gibt. Alle Funktionen, die diese Erweiterung unterstützt, haben folgende Form:
 *  

#expr
Diese Funktion berechnet einen mathematischen Ausdruck und gibt den errechneten Wert aus.


 *  

Die verfügbaren Operatoren sind rechts aufgelistet, in der Reihenfolge des Rangs. Siehe für nähere Details über die Funktion der einzelnen Operatoren. Genauigkeit und Format des ausgegebenen Ergebnisses hängen vom Betriebssystem des Wikiservers sowie dem Zahlenformat der eingestellten Sprache ab.

Bei Nutzung der ergibt 0 immer falsch und jeder andere Wert, ob positiv oder negativ, immer wahr:


 *   → 
 *   → 

Ein leerer eingegebener Ausdruck erzeugt eine leere Ausgabe. Ungültige Ausdrücke erzeugen verschiedene Fehlermeldungen, welche durch Nutzung der Funktion #iferror abgefangen werden können:


 *   →  
 *  </tt> → 
 *  </tt> → 

The order of addition and subtraction operands before or after a number is meaningful, and may be treated as a positive or negative value instead of as an operand with an erroneous input:


 *  </tt> → 
 *  </tt> → 
 *  </tt> → 
 *  </tt> → 

Note, if using the output of magic words, you must raw format them in order to remove commas, and translate the numerals. For example results in , where we want  which can be obtained by. This is especially important in some languages, where numerals are translated. For example, in Bengali, produces ৩০,০৬১.


 *  </tt> →  
 *  </tt> → 

Runden
Rounds off the number on the left to a multiple of 1/10 raised to a power, with the exponent equal to the truncated value of the number given on the right.

To round up or down use unary  or   respectively.

#if
This function evaluates a test string and determines whether or not it is empty. A test string containing only white space is considered to be empty.


 *  </tt>


 *  </tt>

This function first tests whether the first parameter is not empty. If the first parameter is not empty the function displays the second argument. If the first parameter is empty or contains only whitespace characters (spaces, newlines, etc.) it displays the third argument.


 *  </tt> → 
 *  </tt> → 
 *  </tt> → 
 *  </tt> → 

The test string is always interpreted as pure text, so mathematical expressions are not evaluated:


 *  </tt> → 
 *  </tt> → 

Either or both the return values may be omitted:


 * <tt> </tt> →  
 * <tt> </tt> →  
 * <tt> </tt> →  

The function may be nested. To do so, nest the inner #if function in its full form in place of the third parameter of the enclosing #if function. A depth of at least seven levels of nesting is possible, although that may depend on the wiki or a memory limit.
 * Example:

See Help:Parser functions in templates for more examples of this parser function.

#ifeq
This parser function compares two strings and determines whether they are identical.


 * <tt> </tt>

If both strings are valid numerical values, the strings are compared numerically:


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 

Otherwise the comparison is made as text; this comparison is case sensitive:


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> →   (compare to similar example above, without the quotes)
 * <tt> </tt> →   (compare to similar example above, with <tt>#expr</tt>)

As a practical example, given an existing template <tt>Template:Size</tt> used to set standard short and long sizes, defined as:

the following ensue:


 * <tt> </tt> → 20
 * <tt> </tt> → 40
 * <tt> </tt> → 40

#iferror
Diese Funktion überprüft, ob der eingegebene Ausdruck einen Fehler erzeugt. Die Funktion gibt <tt>true</tt> aus, wenn der Ausdruck ein HTML-Objekt mit <tt>class="error"</tt> enthält, wie es z.B. von den Funktionen <tt>#expr</tt>, <tt>#time</tt> und <tt>#rel2abs</tt> bei Fehlern ausgegeben wird. Auch Vorlagenfehler wie Rekursionsschleifen werden erkannt.


 * <tt> </tt>

Die Ausgabe-Parameter können auch weggelassen werden. Wenn der Parameter für "kein Fehler" weggelassen wird, wird der zu überprüfende Ausdruck ausgegeben, sofern er keinen Fehler enthält. Wenn der Ausdruck für "Fehler" ebenfalls weggelassen wird, wird bei einem Fehler nichts ausgegeben.


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → &zwnj;
 * <tt> </tt> → 

#ifexpr
Diese Funktion berechnet einen mathematischen Ausdruck und gibt – abhängig vom Wahrheitswert des Ergebnisses – einen von zwei Werten aus.


 * <tt> </tt>

Für den Ausdruck gelten dabei dieselben Regeln wie bei <tt>#expr</tt>. Nach der Berechnung überprüft die Funktion, ob das Ergebnis ungleich Null ist.

Eine leere Eingabe führt zur Ausgabe <tt>false</tt>:


 * <tt> </tt> → 

Wie gesagt führt das Ergebnis Null zur Ausgabe <tt>false</tt>, jeder andere Wert hingegen zur Ausgabe <tt>true</tt>. Es handelt sich also praktisch um eine Kombination von <tt>#ifeq</tt> und <tt>#expr</tt>:


 * <tt> </tt>

except for an empty or wrong input expression (an error message is treated as an empty string; it is not equal to zero, so we get <tt>value if true</tt>).
 * <tt> </tt> →  

comparing
 * <tt> </tt> →  

Die Parameter können auch weggelassen werden, in diesem Fall wird nichts ausgegeben:


 * <tt> </tt> → 
 * <tt> </tt> →  
 * <tt> </tt> →  
 * <tt> </tt> →  
 * <tt> </tt> →  
 * <tt> </tt> →  

#ifexist
Diese Funktion überprüft, ob eine bestimmte Seite im Wiki existiert, und gibt je nachdem einen von zwei Parametern aus.


 * <tt> </tt>

Die Funktion überprüft nur, ob die Seite existiert, und nicht, ob sie irgendeine Form von Inhalt enthält. Auch Weiterleitungen werden als existente Seiten gewertet. Gelöschte Seiten gelten als nicht existent.


 * <tt> </tt> → 
 * <tt> </tt> → 

MediaWiki-Systemnachrichten gelten so lange als nicht existent, bis sie bearbeitet werden. Auch die Existenz von Spezialseiten kann überprüft werden.


 * <tt> </tt> → 
 * <tt> </tt> →
 * <tt> </tt> →

Wenn eine Seite A die Existenz einer Seite B mittels <tt>#ifexist:</tt> überprüft, taucht Seite A auf der Spezialseite |Links auf diese Seite für Seite B auf. Wenn also im Artikel <tt>Bla</tt> der Code <tt> </tt> steht, wird auf Spezial:Linkliste/Blubb die Seite <tt>Bla</tt> aufgelistet.

In Wikis, die eine gemeinschaftliche Bilddatenbank nutzen (z.B. Wikimedia Commons), kann <tt>#ifexist:</tt> benutzt werden, um zu überprüfen, ob Dateien im lokalen Wiki oder in der externen Bilddatenbank hochgeladen wurden.
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 

Wenn die lokale Bildbeschreibungsseite angelegt wurde, ist das Resultat für all diese Tests <tt>existiert</tt>.

<tt>#ifexist:</tt> does not work with interwiki links.

ifexist limits
<tt>#ifexist:</tt> is considered an "expensive parser function"; only a limited number of which can be included on any one page (including functions inside transcluded templates). When this limit is exceeded, any further <tt>#ifexist:</tt> functions automatically return false, whether the target page exists or not, and the page is categorized into Category:. The name of the tracking category may vary depending on the content language of your wiki.

For some use cases it is possible to emulate the ifexist effect with css, by using the selectors <tt>a.new</tt> (to select links to unexisting pages) or <tt>a:not(.new)</tt> (to select links to existing pages). Furthermore, since the number of expensive parser functions that can be used on a single page is controlled by $wgExpensiveParserFunctionLimit, one can also increase the limit in LocalSettings.php if needed.

#rel2abs
This function converts a relative file path into an absolute filepath.


 * <tt> </tt>
 * <tt> </tt>

Within the <tt>path</tt> input, the following syntax is valid:
 * → the current level
 * → "go up one level"
 * → "go down one level into the subdirectory /foo"

If the <tt>base path</tt> is not specified, the full page name of the page will be used instead:


 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''

Invalid syntax, such as <tt>/.</tt> or <tt>/./</tt>, is ignored. Since no more than two consecutive full stops are permitted, sequences such as these can be used to separate successive statements:


 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''

#switch
This function compares one input value against several test cases, returning an associated string if a match is found.

Examples:


 * <tt> </tt> →   
 * <tt> </tt> →   
 * <tt> </tt> →   


 * 1) switch allows an editor to add information in one template and this information will be visible in several other templates which all have different formatting.

Default
The <tt>default result</tt> is returned if no <tt>case</tt> string matches the <tt>comparison string</tt>:


 * <tt> </tt> →   

In this syntax, the default result must be the last parameter and must not contain a raw equals sign.


 * <tt> </tt> →   
 * <tt> </tt> →   

Alternatively, the default result may be explicitly declared with a <tt>case</tt> string of "<tt>#default</tt>".

Default results declared in this way may be placed anywhere within the function:


 * <tt> </tt> →   

If the <tt>default</tt> parameter is omitted and no match is made, no <tt>result</tt> is returned:


 * <tt> </tt> →   

Grouping results
It is possible to have 'fall through' values, where several <tt>case</tt> strings return the same <tt>result</tt> string. This minimizes duplication.

Here cases 2, 3 and 4 all return <tt>result2</tt>; cases 6 and 7 both return <tt>result4</tt>

Comparison behavior
As with <tt>#ifeq</tt>, the comparison is made numerically if both the comparison string and the case string being tested are numeric; or as a case-sensitive string otherwise:


 * <tt> </tt> → 
 * <tt> </tt> → 


 * <tt> </tt> → 
 * <tt> </tt> → 

A <tt>case</tt> string may be empty:
 * <tt> </tt> → 

Once a match is found, subsequent <tt>cases</tt> are ignored:
 * <tt> </tt> → 

Raw equal signs
"Case" strings cannot contain raw equals signs. To work around this, create a template = containing a single equals sign: <tt>=</tt>.

Example:


 * <tt> </tt> → 

For a simple real life example of the use of this function, check. Two complex examples can be found at and Template:BOTREQ.

Replacing #ifeq
can be used to reduce expansion depth.

For example: is equivalent to
 * (i.e. )
 * (i.e. )

#time
This parser function takes a date and/or time (in the Gregorian calendar) and formats it according to the syntax given. A date/time object can be specified; the default is the value of the magic word <tt> </tt> – that is, the time the page was last rendered into HTML.


 * <tt> </tt>
 * <tt> </tt>
 * <tt> </tt>

The list of accepted formatting codes is given in the table to the right. Any character in the formatting string that is not recognized is passed through unaltered; this applies also to blank spaces (the system does not need them for interpreting the codes). There are also two ways to escape characters within the formatting string: In addition, the digraph <tt>xx</tt> is interpreted as a single literal "x".
 * 1) A backslash followed by a formatting character is interpreted as a single literal character
 * 2) Characters enclosed in double quotes are considered literal characters, and the quotes are removed.


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 

The <tt>date/time object</tt> can be in any format accepted by PHP's strtotime function. Both absolute (eg <tt>20 December 2000</tt>) and relative (eg <tt>+20 hours</tt>) times are accepted.

<tt> </tt> → '''

<tt> </tt> → '''

<tt> </tt> → '''

The language code in ISO 639-3 (?) allows the string to be displayed in the chosen language <tt> </tt> → '''

<tt> </tt> → '''

<tt> </tt> → ''' '''

If you've calculated a Unix timestamp, you may use it in date calculations by pre-pending an <tt>@</tt> symbol.

<tt> </tt> → '''

<tt> </tt> → '''

Full or partial absolute dates can be specified; the function will "fill in" parts of the date that are not specified using the current values:


 * <tt> </tt> → '''

With MediaWiki r86805 - Code Review, a four-digit number is always interpreted as a year, never as hours and minutes:

<tt> </tt> → '''

A six-digit number is interpreted as hours, minutes and seconds if possible, but otherwise as an error (not, for instance, a year and month):

<tt> </tt> → ''' Input is treated as a time rather than a year+month code.

<tt> </tt> → ''' Although 19:60:09 is not a valid time, 196009 is not interpreted as September 1960.

The function performs a certain amount of date mathematics:


 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''
 * <tt> </tt> → '''

The total length of the format strings of the calls of  is limited to 6000 characters.

Time Zone issue
There is a bug in this #time parser function (more specifically in PHP DateTime) that does not allow the passing-in of non-integers as relative time zone offsets. This issue does not apply when using an on-the-hour time zone, such as EDT. For example:

However, Venezuela is on a -4.5 hours time offset from UTC, and thus using its time zone will not normally allow the correct calculation of a relative time zone offset. Here's what happens: To workaround this issue, simply convert the time into minutes or seconds, like this:

(Tim Starling, the developer of this function, provided the exact syntax for this solution.)

#timel
This function is identical to <tt> </tt>, except that it uses the local time of the wiki (as set in ) when no date is given.


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 

#titleparts
This function separates a pagetitle into segments based on slashes, then returns some of those segments as output.


 * <tt> </tt>

If the <tt>number of segments</tt> parameter is not specified, it defaults to "0", which returns all the segments from first segment (included). If the <tt>first segment</tt> parameter is not specified or is "0", it defaults to "1":


 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 
 * <tt> </tt> → 

Negative values are accepted for both values. Negative values for <tt>number of segments</tt> effectively 'strips' segments from the end of the string. Negative values for <tt>first segment</tt> translates to "start with this segment counting from the right":


 * <tt> </tt> →  Strips one segment from the end of the string. See also.
 * <tt> </tt> →   Strips all 4 segments from the end of the string
 * <tt> </tt> →   Strips 5 segments from the end of the string (more than exist)
 * <tt> </tt> →   Returns last segment. See also.
 * <tt> </tt> →   Strips one segment from the end of the string, then returns the second segment and beyond
 * <tt> </tt> →   Start copying at the second last element; strip one segment from the end of the string

The string is split a maximum of 25 times; further slashes are ignored and the 25th element will contain the rest of the string. The string is also limited to 255 characters, as it is treated as a page title:


 * <tt> </tt> → 

If for whatever reason you needed to push this function to its limit, although very unlikely, it is possible to bypass the 25 split limit by nesting function calls:


 * <tt> </tt> → 

You can use #titleparts as a small "string parser & converter", but consider that it returns the first substring capitalized.


 * <tt> </tt> → 
 * <tt> </tt> → 


 * If lower case is needed, use lc: function to control output.
 * <tt> </tt> → 


 * You can prepend a 'dummy' slash at the beginning of the string to get the correct first substring capitalization (uppercase or lowercase). Use |2 instead of |1 for <tt>first segment to return</tt>.
 * <tt> </tt> → 
 * <tt> </tt> → 

Certain characters that are illegal in a page title will cause #titleparts to not parse the string.
 * <tt> </tt> → . Does not produce the expected: {one


 * <tt> </tt> → 

This function does not degrade gracefully if your input exceeds 255 characters. If the inputted string is 256 characters long or more, this function will simply toss the string back at you.

Strings parsing
An extension is available for additional string parsing, see Extension:StringFunctions.

Substitution
Parser functions can be substituted by prefixing the hash character with <tt>subst:</tt>:


 * <tt> </tt> → the code <tt>    </tt> will be inserted in the wikitext since the page  exists.

Redirects
Especially   could be handy in redirects to pages including dates, but this does not work.

Escaping pipe characters in tables
Parser functions will mangle wikitable syntax and pipe characters, treating all the raw pipe characters as parameter dividers. To avoid this, most wikis create the template    :! with its contents only a raw pipe character  or use the   magic word which is available since MW 1.24. This 'hides' the pipe from the MediaWiki parser, ensuring that it is not considered until after all the templates and variables on a page have been expanded. It will then be interpreted as a table row or column separator. Alternatively, raw HTML table syntax can be used, although this is less intuitive and more error-prone.

You can also escape the pipe character for display as a plain, uninterpreted character using an HTML entity:.

Stripping whitespace
Whitespace, including newlines, tabs, and spaces, is stripped from the beginning and end of all the parameters of these parser functions. If this is not desirable, comparison of strings can be done after putting them in quotation marks.





For preventing trimming then- and else-parts, see m:Template:If. Some people use also &lt; nowiki &gt; &lt; /nowiki &gt; instead of spaces.