Hilfe:Erweiterung:ParserFunctions

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Help:Extension:ParserFunctions and the translation is 49% complete.

Other languages:
العربية • ‎български • ‎বাংলা • ‎català • ‎Deutsch • ‎Zazaki • ‎English • ‎español • ‎suomi • ‎français • ‎galego • ‎italiano • ‎日本語 • ‎한국어 • ‎Lëtzebuergesch • ‎मराठी • ‎polski • ‎پښتو • ‎português • ‎português do Brasil • ‎русский • ‎svenska • ‎தமிழ் • ‎ไทย • ‎Türkçe • ‎Tiếng Việt • ‎中文

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:

{{#Funktionsname: Parameter 1 | Parameter 2 | Parameter 3 ... }}

#expr

Art Operatoren
Gruppieren (Klammern) ( )
Zahlen 1234.5   e (2.718)   pi (3.142)
Binärer Operator e   unäre +,-
Unäre Operatoren not ceil trunc floor abs exp ln sin cos tan acos asin atan
Binäre Operatoren ^
* / div mod
+ -
Runden round
Logische Operatoren = != <> > < >= <=
and
or

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

{{#expr: Ausdruck }}

Die verfügbaren Operatoren sind rechts aufgelistet, in der Reihenfolge des Rangs. Siehe Hilfe:Rechnen 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 Booleschen Algebra ergibt 0 immer falsch und jeder andere Wert, ob positiv oder negativ, immer wahr:

{{#expr: 1 and -1 }}1
{{#expr: 1 and 0 }}0
{{#expr: 1 or -1 }}1
{{#expr: -1 or 0 }}1
{{#expr: 0 or 0 }}0

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

{{#expr: }}
{{#expr: 1+ }}Expression error: Missing operand for +.
{{#expr: 1 foo 2 }}Expression error: Unrecognized word "foo".

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:

{{#expr: +1 }}1
{{#expr: -1 }}-1
{{#expr: + 1 }}1
{{#expr: - 1 }}-1

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

{{#expr:{{NUMBEROFUSERS}}+100}}102.377
{{#expr:{{formatnum:{{NUMBEROFUSERS}}|R}}+100}}2377460
Achtung! Warnung: The operator mod gives wrong results for some values of the second argument:
{{#expr: 123 mod (2^64-1)}}Division by zero. (erzeugt einen leeren String; sollte eigentlich 123 ergeben)
Sollen Rechnungen auf Basis von Datumsangaben angestellt werden (z.B. um zu testen, ob das aktuelle Datum und die Zeit nach einem anderen Datum und einer Zeit liegen), sollte die Zeit zuerst in die Anzahl der Sekunden nach 1. Jänner 1970 mit {{#time: xNU }} umgerechnet werden, danach können Daten einfach als Zahlen addiert und subtrahiert werden.

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 ceil or floor respectively.

Testfall Resultat Rundungsmethode
{{#expr: 1/3 round 5 }} 0.33333 Die endgültige Zahl ist <5, deshalb erscheint keine sichtbare Rundung
{{#expr: 1/6 round 5 }} 0.16667 Die endgültige Zahl ist >=5, deshalb wird sie aufgerundet
{{#expr: 8.99999/9 round 5 }} 1 Das Ergebnis wird noch einmal in der letzten Ziffer aufgerundet, was zusätzliche Rundung ergibt
{{#expr: 1234.5678 round -2 }} 1200 Gerundet auf die nächsten 100, da negative Werte links vom Dezimalkomma (hier Punkt) runden
{{#expr: 1234.5678 round 2 }} 1234.57 Gerundet auf die nächsten 100, da positive Werte rechts vom Dezimalkomma (hier Punkt) runden
{{#expr: 1234.5678 round 2.3 }} 1234.57 Dezimalstellen in der Rundungsangabe ergeben keinen Unterschied im gerundeten Ergebnis
{{#expr: trunc 1234.5678 }} 1234 Dezimalstellen abgeschnitten
Auf die nächste Ganzzahl (integer) runden
{{#expr: 1/3 round 0 }} 0 Abrunden auf die nächste Ganzzahl, hier Null
{{#expr: 1/2 round 0 }} 1 Aufrunden auf die nächste Ganzzahl, hier Eins
{{#expr: 3/4 round 0 }} 1 Aufrunden auf die nächste Ganzzahl, hier Eins
{{#expr: -1/3 round 0 }} 0 Aufrunden auf die nächste Ganzzahl, hier Null
{{#expr: -1/2 round 0 }} -1 Abrunden auf die nächste Ganzzahl, hier -1
{{#expr: -3/4 round 0 }} -1 Abrunden auf die nächste Ganzzahl, hier -1
Auf- oder Ab-Runden mit ceil und floor
{{#expr: ceil(1/3) }} 1 Aufrunden auf die nächste größere Ganzzahl, hier 1
{{#expr: floor(1/3) }} 0 Abrunden auf die nächste kleinere Ganzzahl, hier Null
{{#expr: ceil(-1/3) }} 0 Aufrunden auf die nächstgrößere Ganzzahl, hier Null
{{#expr: floor(-1/3) }} -1 Abrunden auf die nächst kleinere Ganzzahl, hier -1
{{#expr: ceil 1/3 }} 0.33333333333333 Nicht gerundet, da 1 schon eine Ganzzahl ist
Achtung! Warnung: Wird interpretiert als (ceil 1)/3, nicht ceil(1/3), wie man erwarten würde

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

{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}
{{#if: first parameter | second parameter | third parameter }}

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.

{{#if: | yes | no}}no
{{#if: string | yes | no}}yes
{{#if:      | yes | no}}no
{{#if:


| yes | no}}
no

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

{{#if: 1==2 | yes | no }}yes
{{#if: 0 | yes | no }}yes

The last parameter (false) may be omitted:

{{#if: foo | yes }}yes
{{#if: | yes }}
{{#if: foo | | no}}

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: {{#if: test string | value if test string is not empty | {{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }} }}

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 {{#if:{{{1|}}}|You entered text in variable 1|There is no text in variable 1}}

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.

{{#ifeq: string 1 | string 2 | value if identical | value if different }}

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

{{#ifeq: 01 | 1 | equal | not equal}}equal
{{#ifeq: 0 | -0 | equal | not equal}}equal
{{#ifeq: 1e3 | 1000 | equal | not equal}}equal
{{#ifeq: {{#expr:10^3}} | 1000 | equal | not equal}}equal


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

{{#ifeq: foo | bar | equal | not equal}}not equal
{{#ifeq: foo | Foo | equal | not equal}}not equal
{{#ifeq: "01" | "1" | equal | not equal}}not equal  (compare to similar example above, without the quotes)
{{#ifeq: 10^3 | 1000 | equal | not equal}}not equal  (compare to similar example above, with #expr)

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

{{#ifeq: {{{1|}}} | short | 20 | 40}}

the following ensue:

{{size|short}}20
{{size|20}}40
{{size}}40
Achtung! Warnung: Numerical comparisons with #ifeq and #switch are not equivalent to comparisons with #expr:
{{#ifeq: 12345678901234567 | 12345678901234568 | equal | not equal}}not equal
{{#switch: 12345678901234567 | 12345678901234568 = equal | not equal}}not equal

because PHP compares two numbers of type integer, whereas:

{{#ifexpr: 12345678901234567 = 12345678901234568 | equal | not equal}}equal

because MediaWiki converts literal numbers in expressions to type float, which, for large integers like these, involves rounding.

Achtung! Warnung: Tags and parser functions inside parser tags (such as <nowiki>) are temporarily replaced by a unique code. This affects comparisons:
{{#ifeq: <nowiki>foo</nowiki> | <nowiki>foo</nowiki> | equal | not equal}}not equal
{{#ifeq: <math>foo</math> | <math>foo</math> | equal | not equal}}not equal
{{#ifeq: {{#tag:math|foo}} | {{#tag:math|foo}} | equal | not equal}}not equal
{{#ifeq: [[foo]] | [[foo]] | equal | not equal}}equal

If the strings to be compared are given as equal calls to the same template containing such tags, then the condition is true, but in the case of two templates with identical content containing such tags it is false.

Achtung! Warnung:

Be careful when comparing against the current page title using the page name magic words. These magic words convert special characters into numeric HTML entities. This may result in misleading results. For example, if you are on a page titled "L'Aquila"...

{{#ifeq: L'Aquila | {{FULLPAGENAME}} | equal | not equal}}not equal[dubious ]

To work around this, apply the magic word to both parameters:

{{#ifeq: {{FULLPAGENAME: L'Aquila}} | {{FULLPAGENAME}} | equal | not equal}}equal

#iferror

This function takes an input string and returns one of two results; the function evaluates to true if the input string contains an HTML object with class="error", as generated by other parser functions such as #expr, #time and #rel2abs, template errors such as loops and recursions, and other "failsoft" parser errors.

{{#iferror: test string | value if error | value if correct }}

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

{{#iferror: {{#expr: 1 + 2 }} | error | correct }}correct
{{#iferror: {{#expr: 1 + X }} | error | correct }}error
{{#iferror: {{#expr: 1 + 2 }} | error }}3
{{#iferror: {{#expr: 1 + X }} | error }}error
{{#iferror: {{#expr: 1 + 2 }} }}3
{{#iferror: {{#expr: 1 + X }} }}
{{#iferror: {{#expr: . }} | error | correct }}correct
{{#iferror: <strong class="error">a</strong> | error | correct }}error

#ifexpr

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

{{#ifexpr: expression | value if true | value if false }}

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

An empty input expression evaluates to false:

{{#ifexpr: | yes | no}}no

As mentioned above, zero evaluates to false and any nonzero value evaluates to true, so this function is equivalent to one using #ifeq and #expr only:

{{#ifeq: {{#expr: expression }} | 0 | value if false | value if true }}

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 value if true).

{{#ifexpr: = | yes | no }}Expression error: Unexpected = operator.

comparing

{{#ifeq: {{#expr: = }} | 0 | no | yes }}yes

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

{{#ifexpr: 1 > 0 | yes }}yes
{{#ifexpr: 1 < 0 | yes }}
{{#ifexpr: 0 = 0 | yes }}yes
{{#ifexpr: 1 > 0 | | no}}
{{#ifexpr: 1 < 0 | | no}}no
{{#ifexpr: 1 > 0 }}

#ifexist

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

{{#ifexist: page title | value if exists | value if doesn't exist }}

The function evaluates to true 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 false, including if the page used to exist but has been deleted.

{{#ifexist: Help:Extension:ParserFunctions/de | exists | doesn't exist }}exists
{{#ifexist: XXHelp:Extension:ParserFunctions/deXX | exists | doesn't exist }}doesn't exist

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

{{#ifexist: Special:Watchlist | exists | doesn't exist }}exists
{{#ifexist: Special:CheckUser | exists | doesn't exist }}exists (weil die Erweiterung CheckUser in diesem Wiki installiert ist)
{{#ifexist: MediaWiki:Copyright | exists | doesn't exist }}exists (weil MediaWiki:Copyright bearbeitet wurde)

If a page checks a target using #ifexist:, then that page will appear in the Special:WhatLinksHere list for the target page. So if the code {{#ifexist:Foo}} were included live on this page (Help:Extension:ParserFunctions/de), Special:WhatLinksHere/Foo will list Help:Extension:ParserFunctions/de.

On wikis using a shared media repository, #ifexist: can be used to check if a file has been uploaded to the repository, but not to the wiki itself:

{{#ifexist: File:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Image:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Media:Example.png | exists | doesn't exist }}exists

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

#ifexist: does not work with interwiki links.

ifexist limits

#ifexist: 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 #ifexist: functions automatically return false, whether the target page exists or not, and the page is categorized into Category:Pages with too many expensive parser function calls. 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 a.new (to select links to unexisting pages) or a:not(.new) (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.

{{#rel2abs: path }}
{{#rel2abs: path | base path }}

Within the path input, the following syntax is valid:

  • . → the current level
  • .. → "go up one level"
  • /foo → "go down one level into the subdirectory /foo"

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

{{#rel2abs: /quok | Help:Foo/bar/baz }}Help:Foo/bar/baz/quok
{{#rel2abs: ./quok | Help:Foo/bar/baz }}Help:Foo/bar/baz/quok
{{#rel2abs: ../quok | Help:Foo/bar/baz }}Help:Foo/bar/quok
{{#rel2abs: ../. | Help:Foo/bar/baz }}Help:Foo/bar

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:

{{#rel2abs: ../quok/. | Help:Foo/bar/baz }}Help:Foo/bar/quok
{{#rel2abs: ../../quok | Help:Foo/bar/baz }}Help:Foo/quok
{{#rel2abs: ../../../quok | Help:Foo/bar/baz }}quok
{{#rel2abs: ../../../../quok | Help:Foo/bar/baz }}Error: Invalid depth in path: "Help:Foo/bar/baz/../../../../quok" (tried to access a node above the root node).

#switch

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

{{#switch: comparison string
 | case = result
 | case = result
 | ...
 | case = result
 | default result
}}

Beispiele:

{{#switch: baz | foo = Foo | baz = Baz | Bar }}Baz
{{#switch: foo | foo = Foo | baz = Baz | Bar }}Foo
{{#switch: zzz | foo = Foo | baz = Baz | Bar }}Bar

#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.][clarification needed][examples needed]

Default

The default result is returned if no case string matches the comparison string:

{{#switch: test | foo = Foo | baz = Baz | Bar }}Bar

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

{{#switch: test | Bar | foo = Foo | baz = Baz }} →
{{#switch: test | foo = Foo | baz = Baz | B=ar }} →

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

{{#switch: comparison string
 | case = result
 | case = result
 | ...
 | case = result
 | #default = default result
}}

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

{{#switch: test | foo = Foo | #default = Bar | baz = Baz }}Bar

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

{{#switch: test | foo = Foo | baz = Baz }}

Grouping results

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

{{#switch: comparison string
 | case1 = result1
 | case2 
 | case3 
 | case4 = result234
 | case5 = result5
 | case6 
 | case7 = result67
 | #default = default result
}}

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

Comparison behavior

As with #ifeq, 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:

{{#switch: 0 + 1 | 1 = one | 2 = two | three}} → three
{{#switch: {{#expr: 0 + 1}} | 1 = one | 2 = two | three}} → one
{{#switch: a | a = A | b = B | C}} → A
{{#switch: A | a = A | b = B | C}} → C

A case string may be empty:

{{#switch: | = Nothing | foo = Foo | Something }}Nothing

Once a match is found, subsequent cases are ignored:

{{#switch: b | f = Foo | b = Bar | b = Baz | }}Bar
Achtung! Warnung: Numerical comparisons with #switch and #ifeq are not equivalent with comparisons in expressions (see also above):
{{#switch: 12345678901234567 | 12345678901234568 = A | B}} → B
{{#ifexpr: 12345678901234567 = 12345678901234568 | A | B}} → A

Raw equal signs

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

Beispiel:

{{#switch: 1=2
 | 1=2 = raw
 | 1<nowiki>=</nowiki>2 = nowiki
 | 1&#61;2 = html
 | 1{{=}}2 = template
 | default
}}html

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

Replacing #ifeq

#switch can be used to reduce expansion depth.

Zum Beispiel:

  • {{#switch:{{{1}}} |condition1=branch1 |condition2=branch2 |condition3=branch3 |branch4}}

is equivalent to

  • {{#ifeq:{{{1}}}|condition1 |branch1 |{{#ifeq:{{{1}}}|condition2 |branch2 |{{#ifeq:{{{1}}}|condition3 |branch3 |branch4}}}}}}
(i.e. {{#ifeq:{{{1}}}|condition1 |<!--then-->branch1 |<!--else-->{{#ifeq:{{{1}}}|condition2 |<!--then-->branch2 |<!--else-->{{#ifeq:{{{1}}}|condition3 |<!--then-->branch3 |<!--else-->branch4}}}}}})

#time

Code Beschreibung Current output
(Purge this page's cache to update)
Jahr
Y Jahreszahl mit 4 Stellen 2015
y Jahreszahl mit 2 Stellen 15
L 1 für ein Schaltjahr, 0 für andere Jahre. 0
o ¹ ISO-8601 Jahr für die bezeichnete Woche. ² 2015 ³

¹ Erfordert PHP 5.1.0 oder neuer und rev:45208.
² Dies hat denselben Wert wie Y, außer wenn die ISO Wochennummer (W) zum letzten oder nächsten Jahr gehört, dann wird dieses Jahr stattdessen verwendet.
³ Gibt buchstäblich o aus, wenn ¹ nicht erfüllt ist.

Monat
n Monatszahl ohne führende Null. 5
m Monatszahl mit führender Null. 05
M Abkürzung des Monatsnamens in der Seitensprache. Mai
F Vollständiger Monatsname in der Seitensprache. Mai
xg Gibt den vollständigen Monatsnamen in der Genitiv-Form der Seitensprache aus, der zwischen Genitiv- und Nominativ-Formen unterscheidet. Diese Option ist für viele slawische Sprachen wie Polnisch, Russisch, Weißrussisch, Tschechisch, Slowakisch, Slowenisch, Ukrainisch usw. nützlich. Für Polnisch:

(Nominativ)

{{#time:d F Y|20 June 2010|pl}} → 20 czerwiec 2010

(Genitiv)

{{#time:d xg Y|20 June 2010|pl}} → 20 czerwca 2010

Woche
W ISO 8601 Wochennummer mit führender Null. 22
Tag
j Tag des Monats ohne führende Null. 28
d Tag des Monats mit führender Null. 28
z Tag des Jahres (Jänner&nbps;1 = 0).
Note Note: Um den ISO Tag des Jahres zu erhalten, muss 1 addiert werden.
147
D Abkürzung für den Wochentag. Selten internationalisiert. Do
l Vollständiger Wochentagsname. Selten internationalisiert. Donnerstag
N ISO 8601 Wochentag (Montag = 1, Sonntag = 7). 4
w Ziffer des Wochentags (Sonntag = 0, Samstag = 6). 4
Stunde
a "am" am Morgen (00:00:00 → 11:59:59), "pm" ab Mittag (12:00:00 → 23:59:59). pm
A Schreibweise in Großbuchstaben von a oberhalb. PM
g Stunde im 12-Stunden-Format ohne führende Null. 11
h Stunde im 12-Stunden-Format mit führender Null. 11
G Stunde im 24-Stunden-Format ohne führende Null. 23
H Stunde im 24-Stunden-Format mit führender Null. 23
Minuten und Sekunden
i Minuten nach der Stunde mit führender Null. 12
s Sekunden nach der Minute mit führender Null. 28
U Sekunden seit 1. Jänner 1970 00:00:00 GMT. 1432854748
Zeitzone (nach 1.22wmf2)
e Zeitzonen-Identifikator. UTC
I Ob das Datum sich in der Sommerzeit (Zeitumstellung) befindet. 0
O Unterschied zur Greenwich Zeit (GMT) +0000
P Unterschied zur Greenwich Zeit (GMT), mit Doppelpunkt +00:00
T Zeitzonen-Abkürzung. UTC
Z Zeitzonen-Abweichung in Sekunden. 0
Sonstiges
t Anzahl der Tage im aktuellen Monat. 31
c ISO 8601 formatiertes Datum, entspricht Y-m-d"T"H:i:s+00:00. 2015-05-28T23:12:28+00:00
r RFC 5322 formatiertes Datum, entspricht D, j M Y H:i:s +0000, mit Wochentagsnamen und Monatsnamen nicht internationalisiert. Thu, 28 May 2015 23:12:28 +0000
Nicht-Gregorianische Kalender
Islamisch
xmj Tag des Monats. 9
xmF Vollständiger Monatsname. Schaʿban
xmn Monatszahl. 8
xmY Vollständiges Jahr. 1436
Iranisch (Jalaly)
xij Tag des Monats. 7
xiF Vollständiger Monatsname. Khordad
xin Monatszahl. 3
xiY Vollständiges Jahr. 1394
xiy Jahreszahl mit 2 Stellen. 94
Hebräisch
xjj Tag des Monats. 10
xjF Vollständiger Monatsname. Sivan
xjt Anzahl der Tage im Monat. 30
xjx Genitivform des Monatsnamen. Sivan
xjn Monatszahl. 9
xjY Vollständiges Jahr. 5775
Thai solar
xkY Full year in Thai solar calendar.
Note Hinweis: For years before 1941 the dates in Jan-Mar range are not calculated properly.
2558
Minguo/Juche year
xoY Vollständiges Jahr. 104
Japanese nengo
xtY Vollständiges Jahr. 平成27
Flags
xn Format the next numeric code as a raw ASCII number. In the Hindi language, {{#time:H, xnH}} produces ०६, 06.
xN Like xn, but as a toggled flag, which endures until the end of the string or until the next appearance of xN in the string.
xr Format the next number as a roman numeral. Only works for numbers up to 10,000
(upto 3,000 in pre MediaWiki 1.20).
{{#time:xrY}} → MMXV
xh Format the next number as a Hebrew numeral. {{#time:xhY}} → ב'ט"ו

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] {{CURRENTTIMESTAMP}} – d.h. die Zeit, als die Seite zuletzt in HTML übersetzt wurde.

{{#time: format string }}
{{#time: format string | date/time object }}
{{#time: format string | date/time object | language code }}

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:

  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.

Zusätzlich wird der Digraph xx als einzelnes buchstäbliches "x" interpretiert.

{{#time: Y-m-d }}2015-05-28
{{#time: [[Y]] m d }}2015 05 28
{{#time: [[Y (year)]] }}2015 (15UTCpmThu, 28 May 2015 23:12:28 +0000)
{{#time: [[Y "(year)"]] }}2015 (year)
{{#time: i's" }}12'28"

Die Datum/Zeit-Einheit kann in jedem von der PHP strtotime() Funktion akzeptierten Format sein. Sowohl absolute (z.B. 20 December 2000) als auch relative (z.b. +20 hours) Zeiten werden akzeptiert.

{{#time: r|now}}Thu, 28 May 2015 23:12:29 +0000
{{#time: r|+2 hours}}Fri, 29 May 2015 01:12:29 +0000
{{#time: r|now + 2 hours}}Fri, 29 May 2015 01:12:29 +0000

Der Sprachcode in ISO 639-3 (?) erlaubt die Anzeige der Zeichenkette in der gewählten Sprache {{#time:d F Y|1988-02-28|nl}}28 februari 1988
{{#time:l|now|uk}}четвер
{{#time:d xg Y|20 June 2010|pl}}20 czerwca 2010

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

{{#time: U | now }}1432854749
{{#time: r|@1432854748}}Thu, 28 May 2015 23:12:28 +0000

Achtung! Warnung: Die gültige Zeitspanne umfasst 1. Jänner 0111 → 31. Dezember 9999. Für die Jahre 100 bis 110 ist die Ausgabe inkonsitetn und Schaltjahre werden wie die Jahre 100–100: r, D, l und U interpretieren diese Jahre als 2000-2010.

{{#time: d F Y | 29 Feb 0100 }}01 März 0100
(korrekt, kein Schaltjahr), aber
{{#time: r | 29 Feb 0100 }}Mon, 01 Mar 0100 00:00:00 +0000 (falsch, auch wenn 100 als 2000 interpretiert wird, da dies ein Schaltjahr ist)
{{#time: d F Y | 15 April 10000 }}Error: Invalid time.
{{#time: r | 10000-4-15 }}Sat, 15 Apr 2000 10:00:00 +0000

Jahreszahlen 0-99 werden als 2000-2069 und 1970-1999 interpretiert, außer sie werden im 4-Ziffernformat mit führender Null geschrieben:
{{#time: d F Y | 1 Jan 6 }}01 Januar 2006
{{#time: d F Y | 1 Jan 06 }}01 Januar 2006
{{#time: d F Y | 1 Jan 006 }}01 Januar 2006
{{#time: d F Y | 1 Jan 0006 }}01 Januar 0006 (4-digit format)

Der Wochentag wird ausgegeben für die Jahre 100-110 und ab 1753, für die Jahre 111-1752 zeigt die r-Ausgabe "Unbekannt" und die l-Ausgabe "<>". Als Folge davon wird die r-Ausgabe für diese Jahre nicht als Eingabe akzeptiert.

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

{{#time: Y | January 1 }}2015
Achtung! Warnung: Diese Ausfüllfunktion ist inkonsistent, manche Teile werden mit aktuellen Werten gefüllt, andere nicht:

{{#time: Y m d H:i:s | June }}2015 06 28 00:00:00 Zeigt den Tagesbeginn, aber den aktuellen Tag des Monats und das aktuelle Jahr. {{#time: Y m d H:i:s | 2003 }}2003 05 28 00:00:00 Zeigt den Tagesbeginn, aber den aktuellen Tag des Jahres.

Mit MediaWiki r86805 - Code Review wird eine 4-stellige Zahl immer als Jahr interpretiert, nie als Stunden und Minuten:
{{#time: Y m d H:i:s | 1959 }}1959 05 28 00:00:00

Eine sechsstellige Zahl wird wenn möglich als Stunden, Minuten und Sekunden interpretiert, aber andernfalls als Fehler (nicht z.B. als Jahr und Monat):
{{#time: Y m d H:i:s | 195909 }}2015 05 28 19:59:09 Die Eingabe wird als Zeit behandelt statt Jahr- & Monats-Code.
{{#time: Y m d H:i:s | 196009 }}Error: Invalid time. 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:

{{#time: d F Y | January 0 2008 }}31 Dezember 2007
{{#time: d F | January 32 }}Error: Invalid time.
{{#time: d F | February 29 2008 }}29 Februar
{{#time: d F | February 29 2007 }}01 März
{{#time:Y-F|now -1 months}}2015-April

Die Gesamtlänge der Formatierungszeichenkette der Funktion #time ist auf 6000 Zeichen beschränkt [1].

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:

  • {{#time:g:i A | -4 hours }} ==> 7:12 PM

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:

  • {{#time:g:i A | -4.5 hours }} ==> 8:12 AM

To workaround this issue, simply convert the time into minutes or seconds, like this:

  • {{#time:g:i A | -270 minutes }} ==> 6:42 PM
  • {{#time:g:i A | -16200 seconds }} ==> 6:42 PM

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

#timel

This function is identical to {{#time: ... }}, except that it uses the local time of the wiki (as set in $wgLocaltimezone) when no date is given.

{{#time: Y-m-d }}2015-05-28
{{#timel: Y-m-d }}2015-05-28
{{#time: Y F d H:i:s}}2015 Mai 28 23:12:28
{{#timel: Y F d H:i:s}}2015 Mai 28 23:12:28


#titleparts

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

{{#titleparts: pagename | number of segments to return | first segment to return }}

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":

{{#titleparts: Talk:Foo/bar/baz/quok }}Talk:Foo/bar/baz/quok
{{#titleparts: Talk:Foo/bar/baz/quok | 1 }}Talk:Foo See also {{ROOTPAGENAME}}.
{{#titleparts: Talk:Foo/bar/baz/quok | 2 }}Talk:Foo/bar
{{#titleparts: Talk:Foo/bar/baz/quok | 2 | 2 }}bar/baz
{{#titleparts: Talk:Foo/bar/baz/quok | | 2 }}bar/baz/quok

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":

{{#titleparts: Talk:Foo/bar/baz/quok | -1 }}Talk:Foo/bar/baz Strips one segment from the end of the string. See also {{BASEPAGENAME}}.
{{#titleparts: Talk:Foo/bar/baz/quok | -4 }}Strips all 4 segments from the end of the string
{{#titleparts: Talk:Foo/bar/baz/quok | -5 }}Strips 5 segments from the end of the string (more than exist)
{{#titleparts: Talk:Foo/bar/baz/quok | | -1 }}quok Returns last segment. See also {{SUBPAGENAME}}.
{{#titleparts: Talk:Foo/bar/baz/quok | -1 | 2 }}bar/baz Strips one segment from the end of the string, then returns the second segment and beyond
{{#titleparts: Talk:Foo/bar/baz/quok | -1 | -2 }}baz 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 &quot;, &#34;, or &#x22; 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.
Some magic keywords or parser functions of MediaWiki (such as {{PAGENAME}} and similar) are known to return strings that are needlessly HTML-encoded, even if their own input parameter was not HTML-encoded:

The titleparts parser function can then be used as a workaround, to convert these returned strings so that they can be processed correctly by some other parser functions also taking a page name in parameter (such as {{PAGESINCAT:}} but which are still not working properly with HTML-encoded input strings.

For example, if the current page is Category:Côte-d'Or, then:

  • {{#ifeq: {{FULLPAGENAME}} | Category:Côte-d'Or | 1 | 0 }}, and {{#ifeq: {{FULLPAGENAME}} | Category:Côte-d&apos;Or | 1 | 0 }} are both returning 1; (the #ifeq parser function does perform the HTML-decoding of its input parameters).
  • {{#switch: {{FULLPAGENAME}} | Category:Côte-d'Or = 1 | #default = 0 }}, and {{#switch: {{FULLPAGENAME}} | Category:Côte-d&apos;Or = 1 | #default = 0 }} are both returning 1; (the #switch parser function does perform the HTML-decoding of its input parameters).
  • {{#ifexist: {{FULLPAGENAME}} | 1 | 0 }}, {{#ifexist: Category:Côte-d'Or | 1 | 0 }}, or even {{#ifexist: Category:Côte-d&apos;Or | 1 | 0 }} will all return 1 if that category page exists (the #ifexist parser function does perform the HTML-decoding of its input parameters);
  • {{PAGESINCAT: Côte-d'Or }} will return a non-zero number, if that category contains pages or subcategories, but:
  • {{PAGESINCAT: {{CURRENTPAGENAME}} }}, may still unconditionally return 0, just like:
  • {{PAGESINCAT: {{PAGENAME|Category:Côte-d'Or}} }}
  • {{PAGESINCAT: {{PAGENAME|Category:Côte-d&apos;Or}} }}

The reason of this unexpected behavior is that, with the current versions of Mediawiki, there are two caveats:

  • {{FULLPAGENAME}}, or even {{FULLPAGENAME|Côte-d'Or}} may return the actually HTML-encoded string Category:Côte-d&apos;Or and not the expected Category:Côte-d'Or, and that:
  • {{PAGESINCAT: Côte-d&apos;Or }} unconditionally returns 0 (the PAGESINCAT magic keyword does not perform any HTML-decoding of its input parameter).

The simple workaround using titleparts (which will continue to work if the two caveats are fixed in a later version of MediaWiki) is:

  • {{PAGESINCAT: {{titleparts: {{CURRENTPAGENAME}} }} }}
  • {{PAGESINCAT: {{titleparts: {{PAGENAME|Category:Côte-d'Or}} }} }}
  • {{PAGESINCAT: {{titleparts: {{PAGENAME|Category:Côte-d&apos;Or}} }} }}, that all return the actual number of pages in the same category.

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:
    {{#titleparts: Talk:Foo/bah_boo|1|2}}bah boo Not bah_boo, despite the underscore in the original.
  2. 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:
    {{#titleparts: a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/aa/bb/cc/dd/ee | 1 | 25 }}y/z/aa/bb/cc/dd/ee
    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:
    {{#titleparts: {{#titleparts: a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/aa/bb/cc/dd/ee| 1 | 25 }} | 1 | 2}}z
  3. The list of substrings is not cleaned up hierarchically (unlike with the {{PAGENAME}} magic keyword, the ./ and ../ relative path segments are left intact by #titleparts):
    {{#titleparts: ../c/d }}../c/d
    {{PAGENAME: ../c/d }} → '
  4. 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).
    {{#titleparts: talk:a/b/c }}Talk:A/b/c
Achtung! Warnung: You can use #titleparts as a small "string parser and converter", but consider that it returns the first substring capitalized:
{{#titleparts: one/two/three/four|1|1 }}One
{{#titleparts: one/two/three/four|1|2 }}two

If lower case is needed, use lc: function to control output:

{{lc: {{#titleparts: one/two/three/four|1|1 }} }}one

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 first segment to return:

{{#titleparts: /one/two/three/four|1|2 }}one
{{#titleparts: /One/two/three/four|1|2 }}One
Achtung! Warnung: Certain characters that are illegal in a page title will cause #titleparts to not parse the string:
{{#titleparts: {one/two} | 1 | 1 }}{one/two}. Does not produce the expected: {one
{{#titleparts: [[page]]/123 | 1 | 2 }}page/123. 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.
Achtung! Warnung: 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.


General points

Substitution

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

{{subst:#ifexist: Help:Extension:ParserFunctions/de | [[Help:Extension:ParserFunctions/de]] | Help:Extension:ParserFunctions/de }} → the code [[Help:Extension:ParserFunctions/de]] will be inserted in the wikitext since the page Help:Extension:ParserFunctions/de exists.
Achtung! Warnung: The results of substituted parser functions are undefined if the expressions contain unsubstituted volatile code such as variables or other parser functions. For consistent results, all the volatile code in the expression to be evaluated must be substituted. See Help:Substitution.

Substitution does not work within <ref></ref>, you can use {{subst:#tag:ref|}} for this purpose.

Redirects

Especially {{#time:…|now-…}} 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 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: &#124; .

Beschreibung You type You get
Escaping pipe character as table row/column separator
{{!}}
|
Escaping pipe character as a plain character
&#124;
|


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.

{{#ifeq: foo           |           foo | equal | not equal }}equal
{{#ifeq: "foo          " | "          foo" | equal | not equal }}not equal

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

foo{{#if:|| bar }}foofoobarfoo
foo{{#if:||<nowiki></nowiki> bar <nowiki></nowiki>}}foofoo bar foo

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

<span style="white-space: pre;">foo{{#if:||<nowiki></nowiki>      bar      <nowiki></nowiki>}}foo</span>foo bar foo

In this example, the white-space: pre 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 &#32; (breakable space) or &nbsp; (non-breakable space), since they are not modified by the software:

<span style="white-space: pre;">foo{{#if:||&#32;&#32;&#32;bar&#32;&#32;&#32;}}foo</span>foo bar foo
foo{{#if:||&nbsp;&nbsp;&nbsp;bar&nbsp;&nbsp;&nbsp;}}foofoo   bar   foo

Siehe auch