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   und jeder andere Wert, ob positiv oder negativ, immer  :



Ein leerer eingegebener Ausdruck erzeugt eine leere Ausgabe. Ungültige Ausdrücke erzeugen eine von mehreren möglichen Fehlermeldungen, die durch Nutzung der Funktion  abgefangen werden können:



Die Reihenfolge der Additions- und Subtraktionsoperanden vor oder nach einer Zahl ist bedeutend und kann als positiver oder negativer Wert eingesetzt werden anstelle eines Operanden mit fehlerhafter Eingabe:



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 0, which can be obtained using. This is especially important in some languages, where numerals are translated. For example, in Bengali, produces ৩০,০৬১.



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.





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.



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



The last parameter (false) may be omitted:



The function may be nested. To do so, nest the inner #if function in its full form in place of a 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:

You can also use a parameter as the test string in your #if statement. You need to ensure you add the | (pipe symbol) after the name of the variable.


 * 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.



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



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


 * →  (compare to similar example above, without the quotes)
 * →  (compare to similar example above, with  )
 * →  (compare to similar example above, without the quotes)
 * →  (compare to similar example above, with  )

As a practical example, given an existing template  used to set standard short and long sizes, defined as:

the following ensue:


 * → 20
 * → 40
 * → 40

#iferror
Diese Funktion überprüft, ob der eingegebene Ausdruck einen Fehler erzeugt. Die Funktion gibt  aus, wenn der Ausdruck ein HTML-Objekt mit   enthält, wie es z.B. von den Funktionen ,   und   bei Fehlern ausgegeben wird. Auch Vorlagenfehler wie Rekursionsschleifen werden erkannt.



One or both of the return strings can be omitted. If the  string is omitted, the   is returned if it is not erroneous. If the  string is also omitted, an empty string is returned on an error:


 * → &zwnj;
 * → &zwnj;
 * → &zwnj;
 * → &zwnj;
 * → &zwnj;
 * → &zwnj;

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



The  input is evaluated exactly as for   above, with the same operators being available. The output is then evaluated as a boolean expression.

Eine leere Eingabe führt zur Ausgabe :



Wie gesagt führt das Ergebnis Null zur Ausgabe, jeder andere Wert hingegen zur Ausgabe. Es handelt sich also praktisch um eine Kombination von  und  :



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 ).

comparing

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



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



The function evaluates to  if the page exists, whether it contains content, is visibly blank (contains meta-data such as category links or magic words, but no visible content), is blank, or is a redirect. Only pages that are redlinked evaluate to, including if the page used to exist but has been deleted.



The function evaluates to  for system messages that have been customized, and for special pages that are defined by the software.



If a page checks a target using, then that page will appear in the  list for the target page. So if the code  were included live on this page, /Foo will list.

In Wikis, die eine gemeinschaftliche Bilddatenbank nutzen (z.B. Wikimedia Commons), kann  benutzt werden, um zu überprüfen, ob Dateien im lokalen Wiki oder in der externen Bilddatenbank hochgeladen wurden.

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

does not work with interwiki links.

ifexist limits
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  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  (to select links to unexisting pages) or   (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, one can also increase the limit in LocalSettings.php if needed.

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



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

If the  is not specified, the full page name of the page will be used instead:



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



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

Beispiele:




 * 1) switch with partial transclusion tags can effect a configuration file that enables an editor unfamiliar with template coding to view and edit configurable elements.

Default
The  is returned if no   string matches the  :



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



Alternatively, the default result may be explicitly declared with a  string of " ".

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



If the  parameter is omitted and no match is made, no   is returned:



Grouping results
It is possible to have 'fall through' values, where several  strings return the same   string. This minimizes duplication.

Here cases 2, 3 and 4 all return ; cases 6 and 7 both return

Comparison behavior
As with, 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:





A  string may be empty:

Once a match is found, subsequent  are ignored:

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

Beispiel:



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

Replacing #ifeq
can be used to reduce expansion depth.

Zum Beispiel: is equivalent to
 * (i.e. )
 * (i.e. )

#time
Dies Parserfunktion nimmt ein Datum und/oder eine Zeit (im Gregorianischen Kalender) und formatiert es gemäß der gegebenen Syntax. Eine Datum/Zeit-Einheit kann bestimmt werden, der Standardwert ist der Wert des [[Special:MyLanguage/Help:Magic words#Date and time|magischen Worts]  – d.h. die Zeit, als die Seite zuletzt in HTML übersetzt wurde.



Die Liste der gültigen Formate ist der Tabelle rechts zu entnehmen. Jedes Zeichen im formatierten String, das nicht erkannt wird, wird unverändert ausgegeben; dies betrifft auch Leerzeichen (das System braucht diese nicht für das Interpretieren des Codes). Es gibt zwei Wege, Zeichen innerhalb des Formatierungs-Strings zu umgehen: Zusätzlich wird der Digraph  als einzelnes buchstäbliches "x" interpretiert.
 * 1) Ein linksseitiger Schrägstrich (Backslash) wird als einzelnes buchstäbliches Zeichen interpretiert
 * 2) Zeichen innerhalb doppelten Anführungszeichen werden als buchstäbliche Zeichen interpretiert und die Anführungszeichen entfernt.



Die  kann in jedem von der PHP strtotime Funktion akzeptierten Format sein. Sowohl absolute (z.B. ) als auch relative (z.b.  ) Zeiten werden akzeptiert.

→ '''

→ '''

→ '''

Der Sprachcode in ISO 639-3 (?) erlaubt die Anzeige der Zeichenkette in der gewählten Sprache → '''

→ '''

→  

Unix Zeitstempel können in Datumsrechnungen verwendet werden, indem ein  Symbol vorangestellt wird.

→ '''

→ '''

Es können vollständige oder Teile von absoluten Datumsangaben angegeben werden, die Funktion "füllt" die fehlenden Datumsteile mit den aktuellen Werten:



Mit MediaWiki r86805 - Code Review wird eine 4-stellige Zahl immer als Jahr interpretiert, nie als Stunden und Minuten:

→ '''

Eine sechsstellige Zahl wird wenn möglich als Stunden, Minuten und Sekunden interpretiert, aber andernfalls als Fehler (nicht z.B. als Jahr und Monat):

→ ''' Die Eingabe wird als Zeit behandelt statt Jahr- & Monats-Code.

→ ''' Obwohl 19:60:09 keine gültige Zeitangabe ist, wird 196009 nicht als September 1960 interpretiert.

Die Funktion erbringt eine gewisse Menge an Daten-Rechnungen:



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

Zeitzonenprobleme
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, except that it uses the local time of the wiki (as set in ) when no date is given.



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



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


 * →  See also.
 * →  See also.

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


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

Before processing, the pagename parameter is HTML-decoded: if it contains some standard HTML character entities, they will be converted to plain characters (internally encoded with UTF-8, i.e. the same encoding as in the MediaWiki source page using this parser function).


 * For example, any occurence of,  , or   in pagename will be replaced by.
 * No other conversion from HTML to plain text is performed, so HTML tags are left intact at this initial step even if they are invalid in page titles.

Then the decoded pagename is canonicalized into a standard page title supported by MediaWiki, as much as possible:


 * 1) All underscores are automatically replaced with spaces:
 * →  Not bah_boo, despite the underscore in the original.
 * 1) 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:
 * 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:
 * 1) The list of substrings is not cleaned up hierarchically (unlike with the   and   relative path segments are left intact by #titleparts):
 * 2) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) The list of substrings is not cleaned up hierarchically (unlike with the   and   relative path segments are left intact by #titleparts):
 * 2) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).

{{ | 1 = Certain characters that are illegal in a page title will cause #titleparts to not parse the string:


 * → {{#titleparts: {one/two} | 1 | 1 }}. Does not produce the expected: {one
 * → {{#titleparts: page/123 | 1 | 2 }}. Does not work because brackets are illegal in page titles and this parser function does not process links embedded in its input pagename parameter, even when they use the MediaWiki syntax, or any other HTML or MediaWiki tags.
 * → "{{#titleparts: red/#00FF00/blue| 1 | 3 }}". Does not work because "#" is also illegal in page titles.

}}

{{ {{TNTN|Warning}}| 1 = 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. }}

Substitution
Parser functions can be substituted by prefixing the hash character with :


 * → the code   will be inserted in the wikitext since the page exists.

Substitution does not work within, you can use &hellip;  for this purpose.

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.


 * → foofoo
 * → foofoo

But this method allows the rendering of only one whitespace, since the parser reduce multiple spaces to a single one.


 * →  foofoo 

In this example, the  style is used to force the whitespace to be preserved by the browser, but even with it the spaces are not shown. This happens because the spaces are stripped by the software, before being sent to the browser.

It is possible to workaround this behavior replacing whitespaces with  (breakable space) or   (non-breakable space), since they are not modified by the software:


 * →  foofoo 
 * → foofoo

Siehe auch

 * Help:Calculation (on Meta)
 * on Meta
 * on Meta
 * Module:String obsoleting Extension:StringFunctions
 * Module:String obsoleting Extension:StringFunctions
 * Module:String obsoleting Extension:StringFunctions