Yardım:Fonksiyonlar

MalatyaSozluk.com - Malatya'nın Yaşayan Ansiklopedisi

<languages/> <translate> The <tvar name=1>Şablon:Ll</tvar> extension provides eleven additional [[<tvar name=3>Special:MyLanguage/Parser functions</tvar>|parser functions]] to supplement the "{{<tvar name=2>ll|Help:Magic words#Parser functions</tvar>|magic words}}", which are already present in MediaWiki.</translate> <translate> (It may be configured to provide additional parser functions for string handling; these string functions are documented {{<tvar name=ext-sf>ll|Extension:StringFunctions#Functions</tvar>|elsewhere}}.)</translate> <translate> All the parser functions provided by this extension take the form:</translate>

{{<translate> #functionname: argument 1 | argument 2 | argument 3 ... </translate>}}

Şablon:PD Help Page

#expr

Şablon:See also

Şablon:Hl1 | <translate> Type</translate> Şablon:Hl1 | <translate> Operators</translate>
Şablon:Hl2 | <translate> Grouping (parentheses)</translate> ( )
Şablon:Hl2 | <translate> Numbers</translate> 1234.5   e (2.718)   pi (3.142)
Şablon:Hl2 | <translate> binary operator</translate> e   <translate> unary</translate> +,-
Şablon:Hl2 | <translate> Unary</translate> not ceil trunc floor abs exp ln sin cos tan acos asin atan
Şablon:Hl2 rowspan="3" | <translate> Binary</translate> ^
* / div mod
+ -
Şablon:Hl2 | <translate> Round</translate> round
Şablon:Hl2 rowspan="3" | <translate> Logic</translate> = != <> > < >= <=
and
or

<translate> This function evaluates a mathematical expression and returns the calculated value.</translate> <translate> This function is also available in <tvar name=1>Şablon:Ll</tvar> via the <tvar name=expr>mw.ext.ParserFunctions.expr</tvar> function.</translate>

{{#expr: <translate> expression</translate> }}

<translate> The available operators are listed to the right, in order of precedence. See [[<tvar name=1>m:Special:MyLanguage/Help:Calculation</tvar>|Help:Calculation]] for more details of the function of each operator. The accuracy and format of the result returned will vary depending on the operating system of the server running the wiki and the number format of the site language.

When evaluating using boolean algebra, zero evaluates to false, and any nonzero value, positive or negative, evaluates to true: </translate>

<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1
<syntaxhighlight lang="moin" inline>0</syntaxhighlight> → 0
<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1
<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1
<syntaxhighlight lang="moin" inline>0</syntaxhighlight> → 0

<translate> An empty input expression returns an empty string. Invalid expressions return one of several error messages, which can be caught using the <tvar name=iferror>#iferror</tvar> function: </translate>

<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline>İfade hatası: + için eksik terim.</syntaxhighlight> → İfade hatası: + için eksik terim.
<syntaxhighlight lang="moin" inline>İfade hatası: = için eksik terim.</syntaxhighlight> → İfade hatası: = için eksik terim.
<syntaxhighlight lang="moin" inline>İfade hatası: Tanınmayan "foo" kelimesi.</syntaxhighlight> → İfade hatası: Tanınmayan "foo" kelimesi.

<translate> 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: </translate>

<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1
<syntaxhighlight lang="moin" inline>-1</syntaxhighlight> → -1
<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1
<syntaxhighlight lang="moin" inline>-1</syntaxhighlight> → -1

<translate> Note, if using the output of magic words, you must raw-format them in order to remove commas and translate the numerals.</translate> <translate> For example, <tvar name=1>{{NUMBEROFUSERS}}</tvar> results in <tvar name=2>3</tvar>, where we want <tvar name=3>3</tvar>, which can be obtained using <tvar name=4>{{Şablon:Ll:{{NUMBEROFUSERS}}|R}}</tvar>.</translate> <translate> This is especially important in some languages, where numerals are translated.</translate> <translate> For example, in Bengali, <tvar name=1>{{NUMBEROFUSERS}}</tvar> produces <tvar name=bengali>৩০,০৬১</tvar>.</translate>

<syntaxhighlight lang="moin" inline>103</syntaxhighlight> → 103
<syntaxhighlight lang="moin" inline>103</syntaxhighlight> → 103

Şablon:Warning Şablon:Tip

<translate>

Rounding

[<tvar name=php>https://php.net/function.round</tvar> 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 <tvar name=ceil>ceil</tvar> or <tvar name=floor>floor</tvar> respectively. </translate>

Şablon:Hl1 | <translate> Test case</translate> Şablon:Hl1 | <translate> Result</translate> Şablon:Hl1 | <translate> Method of rounding</translate>
{{#expr: 1/3 round 5 }} 0.33333 <translate> Final digit is < 5, so no apparent rounding occurs</translate> (0.333333… → 0.33333)
{{#expr: 1/6 round 5 }} 0.16667 <translate> Final digit is ≥ 5, so it is rounded up</translate> (0.166666… → 0.16667)
{{#expr: 8.99999/9 round 5 }} 1 <translate> Again, the result is rounded up on the last digit, which results in additional rounding</translate> (0.999998… → 1.00000 → 1)
{{#expr: 1234.5678 round -2 }} 1200 <translate> Rounded to nearest 100 because negative values round to the left of the decimal point</translate>
{{#expr: 1234.5678 round 2 }} 1234.57 <translate> Rounded to nearest 100th because positive values round to the right of the decimal point</translate>
{{#expr: 1234.5678 round 2.3 }} 1234.57 <translate> Decimals in the rounding index make no difference in the rounded result</translate>
{{#expr: trunc 1234.5678 }} 1234 <translate> Decimal portion truncated (chopped off)</translate>
colspan=3 Şablon:Hl2 | <translate> Rounding to the nearest integer</translate>
{{#expr: 1/3 round 0 }} 0 <translate> Down to the nearest integer, which is zero</translate>
{{#expr: 1/2 round 0 }} 1 <translate> Up to the nearest integer, which is one</translate>
{{#expr: 3/4 round 0 }} 1 <translate> Up to the nearest integer, which is one</translate>
{{#expr: -1/3 round 0 }} -0 <translate> Up to the nearest integer, which is zero</translate>
{{#expr: -1/2 round 0 }} -1 <translate> Down to the nearest integer, which is negative one</translate>
{{#expr: -3/4 round 0 }} -1 <translate> Down to the nearest integer, which is negative one</translate>
colspan=3 Şablon:Hl2 | <translate> Rounding up or down with ceil and floor</translate>
{{#expr: ceil(1/3) }} 1 <translate> Up to the next larger integer, which is one</translate>
{{#expr: floor(1/3) }} 0 <translate> Down to the next smaller integer, which is zero</translate>
{{#expr: ceil(-1/3) }} -0 <translate> Up to the next larger integer, which is zero</translate>
{{#expr: floor(-1/3) }} -1 <translate> Down to the next smaller integer, which is negative one</translate>
{{#expr: ceil 1/3 }} 0.33333333333333 <translate> Not rounded, since 1 already is an integer</translate>
Şablon:Warning

<translate>

Strings

Expressions only work with number-like values, they cannot compare strings or characters. <tvar name=ifeq>#ifeq</tvar> can be used instead. </translate>

<syntaxhighlight lang="moin" inline>İfade hatası: Tanınmayan """ noktalama karakteri.</syntaxhighlight> → İfade hatası: Tanınmayan """ noktalama karakteri.
<syntaxhighlight lang="moin" inline>İfade hatası: Tanınmayan "a" kelimesi.</syntaxhighlight> → İfade hatası: Tanınmayan "a" kelimesi.
<syntaxhighlight lang="moin" inline>1</syntaxhighlight> → 1

#if

<translate> 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. </translate>

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

<translate> 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. </translate>

<syntaxhighlight lang="moin" inline>no</syntaxhighlight> → no
<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
{{#if:      | yes | no}}no
{{#if:

| yes | no}}
no

<translate> The test string is always interpreted as pure text, so mathematical expressions are not evaluated (see <tvar name=1>#ifexpr</tvar> for that): </translate>

<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes

<translate> The last parameter (false) may be omitted: </translate>

<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline></syntaxhighlight> →

<translate> The function may be nested. To do so, nest the inner <tvar name=1>#if</tvar> function in its full form in place of a parameter of the enclosing <tvar name=1>#if</tvar> function. Up to seven levels of nesting is possible, although that may depend on the wiki or a memory limit. </translate>

Şablon:Tmpl

<translate> You can also use a parameter as the test string in your <tvar name=2>#if</tvar> statement. You need to ensure you add the <tvar name=1>|</tvar> (pipe symbol) after the name of the variable.</translate> <translate> (So that if the parameter does not have a value, it evaluates to an empty string instead of the string "<tvar name=1>{{{1}}}</tvar>".)</translate>

Şablon:Tmpl

<translate> See <tvar name=1>Şablon:Ll</tvar> for more examples of this parser function. </translate>

Şablon:Anchor

#ifeq

<translate> This parser function compares two input strings, determines whether they are identical, and returns one of two strings based on the result.</translate> <translate> If more comparisons and output strings are required, consider using <tvar name=switch>#switch</tvar>.</translate>

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

<translate> If both strings are valid numerical values, the strings are compared numerically: </translate>

<syntaxhighlight lang="moin" inline>equal</syntaxhighlight> → equal
<syntaxhighlight lang="moin" inline>equal</syntaxhighlight> → equal
<syntaxhighlight lang="moin" inline>equal</syntaxhighlight> → equal
<syntaxhighlight lang="moin" inline>equal</syntaxhighlight> → equal

<translate> Otherwise, the comparison is made as text; this comparison is case-sensitive: </translate>

<syntaxhighlight lang="moin" inline>not equal</syntaxhighlight> → not equal
<syntaxhighlight lang="moin" inline>not equal</syntaxhighlight> → not equal
<syntaxhighlight lang="moin" inline>not equal</syntaxhighlight> → not equal  <translate> (compare to similar example above, without the quotes)</translate>
<syntaxhighlight lang="moin" inline>not equal</syntaxhighlight> → not equal  <translate> (compare to similar example above, with <tvar name=expr>#expr</tvar> returning a valid number first)</translate>

<translate> As a practical example, consider an existing {{<tvar name=help-templates>ll|Help:Templates</tvar>|template}} Template:Timer using the parser to choose between two standard times, short and long.</translate> <translate> It takes the parameter as the first input to compare against the string "short" – there is no convention for the order, but it is simpler to read if the parameter goes first.</translate> <translate> The template code is defined as:</translate>

<syntaxhighlight lang="moin" inline>40</syntaxhighlight>

<translate> the following ensue: </translate>

<syntaxhighlight lang="moin" inline>Şablon:Timer</syntaxhighlight> → 20
<syntaxhighlight lang="moin" inline>Şablon:Timer</syntaxhighlight> → 40
<syntaxhighlight lang="moin" inline>Şablon:Timer</syntaxhighlight> → 40

Şablon:Warning

Şablon:Warning

#iferror

<translate> This function takes an input string and returns one of two results; the function evaluates to <tvar name=true>true</tvar> if the input string contains an HTML object with <tvar name=error>class="error"</tvar>, as generated by other parser functions such as <tvar name=expr>#expr</tvar>, <tvar name=time>#time</tvar> and <tvar name=rel2abs>#rel2abs</tvar>, [[<tvar name=templates>Special:MyLanguage/Help:Templates</tvar>|template]] errors such as loops and recursions, and other "failsoft" parser errors. </translate>

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

<translate> 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: </translate>

<syntaxhighlight lang="moin" inline>correct</syntaxhighlight> → correct
<syntaxhighlight lang="moin" inline>error</syntaxhighlight> → error
<syntaxhighlight lang="moin" inline>3</syntaxhighlight> → 3
<syntaxhighlight lang="moin" inline>error</syntaxhighlight> → error
<syntaxhighlight lang="moin" inline>3</syntaxhighlight> → 3
<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline>correct</syntaxhighlight> → correct
<syntaxhighlight lang="moin" inline>error</syntaxhighlight> → error

Some errors may cause a tracking category to be added, using {{#iferror:}} will not suppress the addition of the category.

#ifexpr

<translate> This function evaluates a mathematical expression and returns one of two strings depending on the boolean value of the result: </translate>

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

<translate> The expression input is evaluated exactly as for <tvar name=expr>#expr</tvar> above, with the same operators being available. The output is then evaluated as a boolean expression.

An empty input expression evaluates to <tvar name=false>false</tvar>: </translate>

<syntaxhighlight lang="moin" inline>no</syntaxhighlight> → no

<translate> As mentioned above, zero evaluates to <tvar name=false>false</tvar> and any nonzero value evaluates to <tvar name=true>true</tvar>, so this function is equivalent to one using <tvar name=ifeq>#ifeq</tvar> and <tvar name=expr>#expr</tvar> only: </translate>

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

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

<syntaxhighlight lang="moin" inline>İfade hatası: Beklenmedik = operatörü.</syntaxhighlight> → İfade hatası: Beklenmedik = operatörü.

<translate> comparing </translate>

<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes

<translate> Either or both of the return values may be omitted; no output is given when the appropriate branch is left empty: </translate>

<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline>no</syntaxhighlight> → no
<syntaxhighlight lang="moin" inline></syntaxhighlight> →

Boolean operators of equality or inequality operators are supported.

<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline>no</syntaxhighlight> → no
<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes
<syntaxhighlight lang="moin" inline>yes</syntaxhighlight> → yes

Şablon:Warning

Şablon:Anchor

#ifexist

<translate> This function takes an input string, interprets it as a page title, and returns one of two values depending on whether or not the page exists on the local wiki. </translate>

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

<translate> The function evaluates to true if the page exists, whether it contains content, is visibly blank (contains meta-data such as category links or {{<tvar name=help-magic>ll|Help:Magic words</tvar>|magic words}}, but no visible content), is blank, or is a {{<tvar name=help-redirects>ll|Help:Redirects</tvar>|redirect}}. Only pages that are redlinked evaluate to false, including if the page used to exist but has been deleted. </translate>

{{#ifexist: Yardım:Fonksiyonlar | exists | doesn't exist }}exists
{{#ifexist: XXYardım:FonksiyonlarXX | exists | doesn't exist }}doesn't exist

<translate> The function evaluates to true for {{<tvar name=system>ll|Help:System message</tvar>|system messages}} that have been customized, and for {{<tvar name=special>ll|Help:Special pages</tvar>|special pages}} that are defined by the software. </translate>

{{#ifexist: Özel:İzlemeListesi | exists | doesn't exist }}exists
{{#ifexist: Özel:CheckUser | exists | doesn't exist }}doesn't exist <translate> (because the <tvar name=1>Şablon:Ll</tvar> extension is not installed on this wiki)</translate>
<syntaxhighlight lang="moin" inline>doesn't exist</syntaxhighlight> → doesn't exist <translate> (because MediaWiki:Copyright has not been customized)</translate>

<translate> If a page checks a target using <tvar name=ifexist>#ifexist:</tvar>, then that page will appear in the <tvar name=spec-wth>Özel:SayfayaBağlantılar</tvar> list for the target page. So if the code <tvar name=code1>{{#ifexist</tvar>:Foo <tvar name=code2>}}</tvar> were included live on this page (<tvar name=fullpagename1>Yardım:Fonksiyonlar</tvar>), [[<tvar name=wth>Özel:SayfayaBağlantılar</tvar>/Foo]] will list <tvar name=fullpagename2>Yardım:Fonksiyonlar</tvar>.

On wikis using a shared media repository, <tvar name=ifexist>#ifexist:</tvar> can be used to check if a file has been uploaded to the repository but not to the wiki itself: </translate>

{{#ifexist: Dosya:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Image:Example.png | exists | doesn't exist }}doesn't exist
{{#ifexist: Ortam:Example.png | exists | doesn't exist }}doesn't exist

<translate> If a local description page has been created for the file, the result is exists for all of the above.

<tvar name=ifexist>#ifexist:</tvar> does not work with interwiki links.

ifexist limits

</translate> <translate> <tvar name=1>#ifexist:</tvar> is considered an "expensive parser function"; only a limited number of which can be included on any one page (including functions inside transcluded templates).</translate> <translate> When this limit is exceeded, any further <tvar name=1>#ifexist:</tvar> functions automatically return false, whether the target page exists or not, and the page is categorized into <tvar name=2>Category:Çok fazla zengin derleyici fonksiyonu çağrısına sahip sayfalar</tvar>.</translate> <translate> The name of the {{<tvar name=1>ll|Help:Tracking categories</tvar>|tracking category}} may vary depending on the content language of your wiki.</translate>

<translate> 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).</translate> <translate> Furthermore, since the number of expensive parser functions that can be used on a single page is controlled by <tvar name=1>Şablon:Ll</tvar>, one can also increase the limit in LocalSettings.php if needed.</translate>

<translate>

ifexist and wanted pages

</translate> <translate> A page that does not exist and is tested for using <tvar name=1>#ifexist</tvar> will end up on the [[<tvar name=2>Special:MyLanguage/Manual:WantedPages</tvar>|Wanted Pages]].</translate> <translate> See <tvar name=1>Şablon:Phab</tvar> for the reason, and w:Template:Linkless exists for a workaround.</translate>

#rel2abs

<translate> This function converts a relative file path into an absolute filepath. </translate>

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

<translate> Within the <tvar name=1>path</tvar> input, the following syntax is valid: </translate>

  • . → <translate> the current level</translate>
  • .. → <translate> go up one level</translate>
  • /foo → <translate> go down one level into the subdirectory <tvar name=1>/foo</tvar></translate>

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

{{#rel2abs: /quok | Yardım:Foo/bar/baz }}Yardım:Foo/bar/baz/quok
{{#rel2abs: ./quok | Yardım:Foo/bar/baz }}Yardım:Foo/bar/baz/quok
{{#rel2abs: ../quok | Yardım:Foo/bar/baz }}Yardım:Foo/bar/quok
{{#rel2abs: ../. | Yardım:Foo/bar/baz }}Yardım:Foo/bar

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

{{#rel2abs: ../quok/. | Yardım:Foo/bar/baz }}Yardım:Foo/bar/quok
{{#rel2abs: ../../quok | Yardım:Foo/bar/baz }}Yardım:Foo/quok
{{#rel2abs: ../../../quok | Yardım:Foo/bar/baz }}quok
{{#rel2abs: ../../../../quok | Yardım:Foo/bar/baz }}Hata: Yolda geçersiz derinlik: "Yardım:Foo/bar/baz/../../../../quok" (kök düğümünün üstünde bir düğüme erişmeye çalıştı)

<translate> For a similar group of functions see also [[<tvar name=1>Special:MyLanguage/Help:Magic words#URL data</tvar>|Help:Magic words#URL data]].</translate> <translate> Built-in parser functions include: <tvar name=1>'localurl:', 'fullurl:', 'anchorencode:'</tvar> etc.</translate>

#switch

<translate> See also:</translate> w:Help:Switch parser function

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

Şablon:Pre

<translate> Examples: </translate>

<syntaxhighlight lang="moin" inline>Baz</syntaxhighlight> → Baz
<syntaxhighlight lang="moin" inline>Foo</syntaxhighlight> → Foo
<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight> → Bar

<translate> <tvar name=1>#switch</tvar> with partial transclusion tags can affect a configuration file that enables an editor unfamiliar with template coding to view and edit configurable elements.

Default

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

<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight> → Bar

<translate> In this syntax, the default result must be the last parameter and must not contain a raw equals sign (an equals sign without <tvar name=1>{{}}</tvar>).</translate> <translate> If it does, it will be treated as a case comparison, and no text will display if no cases match.</translate> <translate> This is because the default value has not been defined (is empty).</translate> <translate> If a case matches however, its associated string will be returned.</translate>

<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline></syntaxhighlight> →
<syntaxhighlight lang="moin" inline>Foo</syntaxhighlight> → Foo

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

Şablon:Pre

<translate> Default results declared in this way may be placed anywhere within the function: </translate>

<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight> → Bar

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

<syntaxhighlight lang="moin" inline></syntaxhighlight> →

<translate>

Grouping results

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

Şablon:Pre

<translate> Here cases 2, 3 and 4 all return result234; cases 6 and 7 both return result67.</translate> <translate> The "<tvar name=1>#default = </tvar>" in the last parameter may be omitted in the above case.</translate>

<translate>

Use with parameters

</translate> <translate> The function may be used with parameters as the test string.</translate> <translate> In this case, it is not necessary to place the pipe after the parameter name, because it is very unlikely that you will choose to set a case to be the string "<tvar name=1>{{{parameter name}}}</tvar>".</translate> (<translate> This is the value the parameter will default to if the pipe is absent and the parameter doesn't exist or have a value.</translate> <translate> See <tvar name=1>Şablon:Ll</tvar>.</translate>)

<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight>

<translate> In the above case, if <tvar name=1>{{{1}}}</tvar> equals <tvar name=2>foo</tvar>, the function will return <tvar name=3>Foo</tvar>.</translate> <translate> If it equals <tvar name=1>baz</tvar>, the function will return <tvar name=2>Baz</tvar>.</translate> <translate> If the parameter is empty or does not exist, the function will return <tvar name=1>Bar</tvar>.</translate>

<translate> As in the section above, cases can be combined to give a single result. </translate>

<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight>

<translate> Here, if <tvar name=1>{{{1}}}</tvar> equals <tvar name=2>foo</tvar>, <tvar name=3>zoo</tvar> or <tvar name=4>roo</tvar>, the function will return <tvar name=5>Foo</tvar>.</translate> <translate> If it equals <tvar name=1>baz</tvar>, the function will return <tvar name=2>Baz</tvar>.</translate> <translate> If the parameter is empty or does not exist, the function will return <tvar name=1>Bar</tvar>.</translate>

<translate> Additionally, the default result can be omitted if you do not wish to return anything if the test parameter value does not match any of the cases. </translate>

<syntaxhighlight lang="moin" inline></syntaxhighlight>

<translate> In this case, the function returns an empty string unless <tvar name=1>{{{1}}}</tvar> exists and equals <tvar name=2>foo</tvar> or <tvar name=3>bar</tvar>, in which case it returns <tvar name=4>Foo</tvar> or <tvar name=5>Bar</tvar>, respectively.

This has the same effect as declaring the default result as empty. </translate>

<syntaxhighlight lang="moin" inline></syntaxhighlight>

<translate> If for some reason you decide to set a case as "<tvar name=1>{{{parameter name}}}</tvar>", the function will return that case's result when the parameter doesn't exist or doesn't have a value.</translate> <translate> The parameter would have to exist and have a value other than the string "<tvar name=1>{{{parameter name}}}</tvar>" to return the function's default result.</translate>

<translate> (when <tvar name=1>{{{1}}}</tvar> doesn't exist or is empty):</translate>
<syntaxhighlight lang="moin" inline>Foo</syntaxhighlight> → Foo
<translate> (when <tvar name=1>{{{1}}}</tvar> has the value "test"):</translate>
<syntaxhighlight lang="moin" inline>Foo</syntaxhighlight> → Bar
<translate> (when <tvar name=1>{{{1}}}</tvar> has the value "<tvar name=2>{{{1}}}</tvar>"):</translate>
<syntaxhighlight lang="moin" inline>Foo</syntaxhighlight> → Foo


<translate> In this hypothetical case, you would need to add the pipe to the parameter (<tvar name=1>{{{1|}}}</tvar>).

Comparison behavior

As with <tvar name=ifeq>#ifeq</tvar>, 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: </translate>

<syntaxhighlight lang="moin" inline>three</syntaxhighlight> → three
<syntaxhighlight lang="moin" inline>one</syntaxhighlight> → one
<syntaxhighlight lang="moin" inline>two</syntaxhighlight> → two
<syntaxhighlight lang="moin" inline>hundred</syntaxhighlight> → hundred
<syntaxhighlight lang="moin" inline>A</syntaxhighlight> → A
<syntaxhighlight lang="moin" inline>C</syntaxhighlight> → C

<translate> A case string may be empty: </translate>

<syntaxhighlight lang="moin" inline>Nothing</syntaxhighlight> → Nothing

<translate> Once a match is found, subsequent cases are ignored: </translate>

<syntaxhighlight lang="moin" inline>Bar</syntaxhighlight> → Bar

Şablon:Warning

<translate>

Raw equal signs

"Case" strings cannot contain raw equals signs. To work around this, use the <tvar name=1>[[Special:MyLanguage/Help:Magic words#Other|Şablon:((=Şablon:))]]</tvar> magic word, create a template <tvar name=tpl>Şablon:Tl</tvar> containing a single equals sign: <tvar name=code1>=</tvar>, or replace equals sign with HTML code <tvar name=code2>&#61;</tvar>.

Example: </translate>

<translate> You type</translate> <translate> You get</translate>
<syntaxhighlight lang=moin>

template </syntaxhighlight>

template
<syntaxhighlight lang=moin>

html </syntaxhighlight>

html

Şablon:Note

<translate>

Replacing #ifeq

#switch can be used to reduce [[<tvar name=help>Special:MyLanguage/Help:Expansion depth</tvar>|expansion depth]].

For example: </translate>

  • <syntaxhighlight lang="wikitext" inline>branch4</syntaxhighlight>

<translate> is equivalent to </translate>

  • <syntaxhighlight lang="wikitext" inline>branch4</syntaxhighlight>

<translate> i.e. deep nesting, linear: </translate>

<syntaxhighlight lang="wikitext"> branch4 </syntaxhighlight>

<translate> On the other hand, the switch replacement could be complicated/impractical for IFs nested in both branches (shown with alternatives of indentation, indented on both sides), making full symmetrical tree: </translate>

<syntaxhighlight lang="wikitext"> branch1ebranch1e3ebranch1e3e7t </syntaxhighlight>

Şablon:Anchor

#time

<translate> 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 [[<tvar name=magic>Special:MyLanguage/Help:Magic words#Date and time</tvar>|magic word]] <tvar name=currenttimestamp><syntaxhighlight lang="moin" inline>20240508130542</syntaxhighlight></tvar> – that is, the time the page was last rendered into HTML. </translate>

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

<translate> The list of accepted formatting codes is given in the table to the right.</translate> <translate> 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).</translate> <translate> There are also two ways to escape characters within the formatting string:</translate>

<translate>

  1. A backslash followed by a formatting character is interpreted as a single literal character</translate>

<translate>

  1. Characters enclosed in double quotes are considered literal characters, and the quotes are removed.

In addition, the digraph <tvar name=1>xx</tvar> is interpreted as a single literal "<tvar name=2>x</tvar>".

As the list of formatting codes continues to evolve (with the support of new calendars, or of new date fields computed and formatted differently), you should escape all literal characters (not just ASCII letters currently used by formatting codes) that need to be passed through unaltered. </translate>

<translate> Unfortunately, for now, the ASCII single quote is still not recognized as a simple alternative for marking literal text to the currently supported ASCII double quotes (for example, double quotes are mandatory for in other uses like the delimitation of string values in JSON, C, C++...) and backslashes (which have to be escaped as well in string constants used by many languages, including JSON, C, C++, PHP, JavaScript, Lua).</translate> <translate> So you still cannot embed any literal double quote without escaping it with a backslash (or you can use other curly, angular or square quotation marks instead).</translate>

<syntaxhighlight lang="moin" inline>2024-05-08</syntaxhighlight> → 2024-05-08
<syntaxhighlight lang="moin" inline>2024 05 08</syntaxhighlight> → 2024 05 08
<syntaxhighlight lang="moin" inline>2024 (24UTCpmWed, 08 May 2024 13:05:42 +0000)</syntaxhighlight> → 2024 (24UTCpmWed, 08 May 2024 13:05:42 +0000)
<syntaxhighlight lang="moin" inline>2024 (year)</syntaxhighlight> → 2024 (year)
<syntaxhighlight lang="moin" inline>05'42"</syntaxhighlight> → 05'42"

<translate> The date/time object can be in any format accepted by PHP's <tvar name=strtotime>strtotime()</tvar> function.</translate> <translate> Absolute (e.g. <tvar name=1>20 December 2000</tvar>), relative (e.g. <tvar name=2>+20 hours</tvar>), and combined times (e.g. <tvar name=3>30 July +1 year</tvar>) are accepted.</translate>

<syntaxhighlight lang="moin" inline>Wed, 08 May 2024 13:05:42 +0000</syntaxhighlight> → Wed, 08 May 2024 13:05:42 +0000
<syntaxhighlight lang="moin" inline>Wed, 08 May 2024 15:05:42 +0000</syntaxhighlight> → Wed, 08 May 2024 15:05:42 +0000
<syntaxhighlight lang="moin" inline>Wed, 08 May 2024 15:05:42 +0000</syntaxhighlight> → Wed, 08 May 2024 15:05:42 +0000
<syntaxhighlight lang="moin" inline>Wed, 20 Dec 2000 00:00:00 +0000</syntaxhighlight> → Wed, 20 Dec 2000 00:00:00 +0000
<syntaxhighlight lang="moin" inline>Wed, 20 Dec 2000 00:00:00 +0000</syntaxhighlight> → Wed, 20 Dec 2000 00:00:00 +0000
<syntaxhighlight lang="moin" inline>Wed, 20 Dec 2000 00:00:00 +0000</syntaxhighlight> → Wed, 20 Dec 2000 00:00:00 +0000
<syntaxhighlight lang="moin" inline>Hata: Geçersiz saat.</syntaxhighlight> → Hata: Geçersiz saat.

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

<syntaxhighlight lang="moin" inline>28 februari 1988</syntaxhighlight> → 28 februari 1988
<syntaxhighlight lang="moin" inline>середа</syntaxhighlight> → середа
<syntaxhighlight lang="moin" inline>20 czerwca 2010</syntaxhighlight> → 20 czerwca 2010

<translate> The <tvar name=1>local</tvar> parameter specifies if the date/time object refers to the local timezone or to UTC.

This is a boolean parameters: its value is determined by casting the value of the argument (see the [<tvar name=url>https://php.net/language.types.boolean#language.types.boolean.casting</tvar> official PHP documentation] for details on how string are cast to boolean values). </translate>

Şablon:Note

<translate> See the following examples for details: </translate>

<syntaxhighlight lang="moin" inline>2024 maggio 08 13:05:42</syntaxhighlight> → 2024 maggio 08 13:05:42
<syntaxhighlight lang="moin" inline>2024 maggio 08 13:05:42</syntaxhighlight> → 2024 maggio 08 13:05:42
<syntaxhighlight lang="moin" inline>2024 Mayıs 08 15:05:42</syntaxhighlight> → 2024 Mayıs 08 15:05:42
<syntaxhighlight lang="moin" inline>2024 Mayıs 08 15:05:42</syntaxhighlight> → 2024 Mayıs 08 15:05:42
<syntaxhighlight lang="moin" inline>2019-05-16T15:05:43+00:00</syntaxhighlight> → 2019-05-16T15:05:43+00:00
<syntaxhighlight lang="moin" inline>2019-05-16T15:05:43+00:00</syntaxhighlight> → 2019-05-16T15:05:43+00:00
<syntaxhighlight lang="moin" inline>2019-05-16T15:05:43+00:00</syntaxhighlight> → 2019-05-16T15:05:43+00:00

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

<syntaxhighlight lang="moin" inline>1715173542</syntaxhighlight> → 1715173542
{{#time: r | @1715173542 }}Wed, 08 May 2024 13:05:42 +0000

Şablon:Warning

Şablon:Warning

<translate> 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: </translate>

<syntaxhighlight lang="moin" inline>2024</syntaxhighlight> → 2024

Şablon:Warning

<translate> A four-digit number is always interpreted as a year, never as hours and minutes:[1] </translate>

<syntaxhighlight lang="moin" inline>1959 05 08 00:00:00</syntaxhighlight> → 1959 05 08 00:00:00

<translate> 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): </translate>

<syntaxhighlight lang="moin" inline>2024 05 08 19:59:09</syntaxhighlight> → 2024 05 08 19:59:09 <translate> Input is treated as a time rather than a year+month code.</translate>
<syntaxhighlight lang="moin" inline>Hata: Geçersiz saat.</syntaxhighlight> → Hata: Geçersiz saat. <translate> Although 19:60:09 is not a valid time, 196009 is not interpreted as September 1960.</translate>

<translate> The function performs a certain amount of date mathematics: </translate>

<syntaxhighlight lang="moin" inline>31 Aralık 2007</syntaxhighlight> → 31 Aralık 2007
<syntaxhighlight lang="moin" inline>Hata: Geçersiz saat.</syntaxhighlight> → Hata: Geçersiz saat.
<syntaxhighlight lang="moin" inline>29 Şubat</syntaxhighlight> → 29 Şubat
<syntaxhighlight lang="moin" inline>01 Mart</syntaxhighlight> → 01 Mart
<syntaxhighlight lang="moin" inline>2024-Nisan</syntaxhighlight> → 2024-Nisan

<translate> The total length of the format strings of the calls of <tvar name=time>#time</tvar> is limited to 6000 characters[2].

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: </translate>

  • <syntaxhighlight lang="moin" inline>9:05 AM</syntaxhighlight> → 9:05 AM

<translate> However, India is on a +5.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: </translate>

  • <syntaxhighlight lang="moin" inline>1:05 PM</syntaxhighlight> → 1:05 PM

<translate> To workaround this issue, simply convert the time into minutes or seconds, like this: </translate>

  • <syntaxhighlight lang="moin" inline>6:35 PM</syntaxhighlight> → 6:35 PM
  • <syntaxhighlight lang="moin" inline>6:35 PM</syntaxhighlight> → 6:35 PM

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

#timel

<translate> This function is identical to <tvar name=time>{{#time: ... }}</tvar>, when the <tvar name=2>local</tvar> parameter is set to <tvar name=3>true</tvar>, so it always uses the local time of the wiki (as set in <tvar name=1>Şablon:Ll</tvar>).

Syntax of the function is: </translate>

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

Şablon:Note

Dosya:Time-Timel.png
<translate> Example of the use of #time and #timel parser functions from a server where the timezone is not UTC</translate>

<translate> For instance, see the following examples: </translate>

<syntaxhighlight lang="moin" inline>2024-05-08T13:05:42+00:00</syntaxhighlight> → 2024-05-08T13:05:42+00:00
<syntaxhighlight lang="moin" inline>2024-05-08T13:05:42+00:00</syntaxhighlight> → 2024-05-08T13:05:42+00:00
<syntaxhighlight lang="moin" inline>2024-05-08T13:05:42+00:00</syntaxhighlight> → 2024-05-08T13:05:42+00:00
<syntaxhighlight lang="moin" inline>2024-05-08T13:05:42+00:00</syntaxhighlight> → 2024-05-08T13:05:42+00:00
Dosya:Maldiskusjon Sommertid–Wikipedia.jpg
<translate> Warning Example from <tvar name=no-wp>https://no.wikipedia.org/wiki/Maldiskusjon:Sommertid</tvar></translate>

Şablon:Warning

Şablon:-

Şablon:Anchor

#titleparts

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

Şablon:Tmpl

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

{{#titleparts: Tartışma:Foo/bar/baz/quok }}Tartışma:Foo/bar/baz/quok
{{#titleparts: Tartışma:Foo/bar/baz/quok | 1 }}Tartışma:Foo See also {{Şablon:Ll}}.
{{#titleparts: Tartışma:Foo/bar/baz/quok | 2 }}Tartışma:Foo/bar
{{#titleparts: Tartışma:Foo/bar/baz/quok | 2 | 2 }}bar/baz
{{#titleparts: Tartışma:Foo/bar/baz/quok | | 2 }}bar/baz/quok
{{#titleparts: Tartışma:Foo/bar/baz/quok | | 5 }}

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

{{#titleparts: Tartışma:Foo/bar/baz/quok | -1 }}Tartışma:Foo/bar/baz <translate> Strips one segment from the end of the string.</translate> <translate> See also <tvar name=1>{{BASEPAGENAME}}</tvar>.</translate>
{{#titleparts: Tartışma:Foo/bar/baz/quok | -4 }} <translate> Strips all 4 segments from the end of the string</translate>
{{#titleparts: Tartışma:Foo/bar/baz/quok | -5 }} <translate> Strips 5 segments from the end of the string (more than exist)</translate>
{{#titleparts: Tartışma:Foo/bar/baz/quok | | -1 }} quok <translate> Returns last segment.</translate> <translate> See also <tvar name=1>{{SUBPAGENAME}}</tvar>.</translate>
{{#titleparts: Tartışma:Foo/bar/baz/quok | -1 | 2 }} bar/baz <translate> Strips one segment from the end of the string, then returns the second segment and beyond</translate>
{{#titleparts: Tartışma:Foo/bar/baz/quok | -1 | -2 }} baz <translate> Start copying at the second last element; strip one segment from the end of the string</translate>

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

<translate> For example, any occurrence of <tvar name=q1>&quot;</tvar>, <tvar name=q2>&#34;</tvar>, or <tvar name=q3>&#x22;</tvar> in pagename will be replaced by <tvar name=q>"</tvar>.</translate>
<translate> 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.</translate>

Şablon:Tip

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

  1. <translate> All underscores are automatically replaced with spaces:</translate>
    {{#titleparts: Tartışma:Foo/bah_boo|1|2}}bah boo <translate> Not bah_boo, despite the underscore in the original.</translate>
  2. <translate> The string is split a maximum of 25 times; further slashes are ignored and the 25th element will contain the rest of the string.</translate> <translate> The string is also limited to 255 characters, as it is treated as a [[<tvar name=1>Special:MyLanguage/Manual:Page table#Schema summary</tvar>|page title]]:</translate>
    {{#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
    <translate> 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:</translate>
    {{#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. <translate> 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).</translate>
    {{#titleparts: talk:a/b/c }}Tartışma:A/b/c

Şablon:Warning

Şablon:Warning

Şablon:Warning

Şablon:Warning

<translate>

StringFunctions

All of these functions (<tvar name=1>len, pos, rpos, sub, replace, explode</tvar>) are [[<tvar name=2>Special:Code/MediaWiki/50997</tvar>|integrated]] from the <tvar name=3>StringFunctions</tvar> extension, but are only available if an administrator sets <tvar name=4><syntaxhighlight lang=php inline>$wgPFEnableStringFunctions = true;</syntaxhighlight></tvar> in <tvar name=5>LocalSettings.php</tvar>.

All of these functions operate in O(n) time complexity, making them safe against DoS attacks. </translate>

Şablon:Note

#len

Şablon:Note

<translate> The <tvar name=1>#len</tvar> function returns the length of the given string.</translate> <translate> The syntax is:</translate>

{{#len:string}}

<translate> The return value is always a number of characters in the source string (after expansions of template invocations, but before conversion to HTML).</translate> <translate> If no string is specified, the return value is zero.</translate>

Şablon:Note

#pos

Şablon:Note

<translate> The <tvar name=1>#pos</tvar> function returns the position of a given search term within the string.</translate> <translate> The syntax is:</translate>

{{#pos:string|<translate> search term</translate>|offset}}

<translate> The <tvar name=1>offset</tvar> parameter, if specified, tells a starting position where this function should begin searching.

If the search term is found, the return value is a zero-based integer of the first position within the string.

If the search term is not found, the function returns an empty string. </translate>

Şablon:Note

#rpos

Şablon:Note

<translate> The <tvar name=1>#rpos</tvar> function returns the last position of a given search term within the string.</translate> <translate> The syntax is:</translate>

{{#rpos:string|<translate> search term</translate>}}

<translate> If the search term is found, the return value is a zero-based integer of its last position within the string.

If the search term is not found, the function returns -1. </translate>

Şablon:Tip

Şablon:Note

#sub

Şablon:Note

<translate> The <tvar name=1>#sub</tvar> function returns a substring from the given string.</translate> <translate> The syntax is:</translate>

{{#sub:string|start|length}}

<translate> The <tvar name=1>start</tvar> parameter, if positive (or zero), specifies a zero-based index of the first character to be returned. </translate>

<translate> Example:</translate> <translate> <tvar name=1>{{#sub:Icecream|3}}</tvar> returns <tvar name=2>cream</tvar>.</translate>

<translate> <tvar name=1>{{#sub:Icecream|0|3}}</tvar> returns <tvar name=2>Ice</tvar>.

If the <tvar name=1>start</tvar> parameter is negative, it specifies how many characters from the end should be returned. </translate>

<translate> Example:</translate> <translate> <tvar name=1>{{#sub:Icecream|-3}}</tvar> returns <tvar name=2>eam</tvar>.</translate>

<translate> The <tvar name=1>length</tvar> parameter, if present and positive, specifies the maximum length of the returned string. </translate>

<translate> Example:</translate> <translate> <tvar name=1>{{#sub:Icecream|3|3}}</tvar> returns <tvar name=2>cre</tvar>.</translate>

<translate> If the <tvar name=1>length</tvar> parameter is negative, it specifies how many characters will be omitted from the end of the string. </translate>

<translate> Example:</translate> <translate> <tvar name=1>{{#sub:Icecream|3|-3}}</tvar> returns <tvar name=2>cr</tvar>.</translate>

<translate> If the <tvar name=1>start</tvar> parameter is negative, it specifies how many characters from the end should be returned.</translate> <translate> The <tvar name=1>length</tvar> parameter, if present and positive, specifies the maximum length of the returned string from the starting point.</translate>

<translate> Example:</translate> <translate> <tvar name=1>{{#sub:Icecream|-3|2}}</tvar> returns <tvar name=2>ea</tvar>.</translate>

Şablon:Note

#count

Şablon:Note

<translate> The <tvar name=1>#count</tvar> function returns the number of times a given substring appears within the provided text. </translate>

{{#count:string|substring}}

#replace

Şablon:Note

<translate> The <tvar name=1>#replace</tvar> function returns the given string with all occurrences of a search term replaced with a replacement term. </translate>

{{#replace:string|search term|replacement term}}

<translate> If the <tvar name=1>search term</tvar> is unspecified or empty, a single space will be searched for.

If the <tvar name=1>replacement term</tvar> is unspecified or empty, all occurrences of the <tvar name=2>search term</tvar> will be removed from the string. </translate>

Şablon:Note

<translate> Case-insensitive replace</translate>

<translate> Currently the syntax doesn't provide a switch to toggle case-sensitivity setting.</translate> <translate> But you may make use of [[<tvar name=1>Special:MyLanguage/Help:Magic_words#Formatting</tvar>|magic words of formatting]] as a workaround.</translate> <translate> (e.g. {{<tvar name=3>tmpl|0=Şablon:((lc:$1Şablon:))</tvar>|your_string_here}})</translate> <translate> For example, if you want to remove the word "<tvar name=1>Category:</tvar>" from the string regardless of its case, you may type:</translate>

{{#replace:{{lc:{{{1}}}}}|category:|}}

<translate> But the disadvantage is that the output will become all lower-case.</translate> <translate> If you want to keep the casing after replacement, you have to use multiple nesting levels (i.e. multiple replace calls) to achieve the same thing.</translate>

#explode

Şablon:Note

<translate> The <tvar name=1>#explode</tvar> function splits the given string into pieces and then returns one of the pieces.</translate> <translate> The syntax is:</translate>

{{#explode:string|delimiter|position|limit}}

<translate> The <tvar name=1>delimiter</tvar> parameter specifies a string to be used to divide the <tvar name=2>string</tvar> into pieces.</translate> <translate> This <tvar name=1>delimiter</tvar> string is then not part of any piece, and when two <tvar name=1>delimiter</tvar> strings are next to each other, they create an empty piece between them.</translate> <translate> If this parameter is not specified, a single space is used.</translate> <translate> The <tvar name=1>limit</tvar> parameter is available in ParserFunctions only, not the standalone StringFunctions version, and allows you to limit the number of parts returned, with all remaining text included in the final part.</translate>

<translate> The <tvar name=1>position</tvar> parameter specifies which piece is to be returned.</translate> <translate> Pieces are counted from 0.</translate> <translate> If this parameter is not specified, the first piece is used (piece with number 0).</translate> <translate> When a negative value is used as <tvar name=1>position</tvar>, the pieces are counted from the end.</translate> <translate> In this case, piece number -1 means the last piece.</translate> <translate> Examples:</translate>

  • {{#explode:And if you tolerate this| |2}} <translate> returns</translate> you
  • {{#explode:String/Functions/Code|/|-1}} <translate> returns</translate> Code
  • {{#explode:Split%By%Percentage%Signs|%|2}} <translate> returns</translate> Percentage
  • {{#explode:And if you tolerate this thing and expect no more| |2|3}} <translate> returns</translate> you tolerate this thing and expect no more

<translate> The return value is the position-th piece. If there are fewer pieces than the position specifies, an empty string is returned. </translate>

Şablon:Note

#urldecode

<translate> <tvar name=1>#urldecode</tvar> converts the escape characters from an 'URL encoded' string back to readable text. The syntax is: </translate>

{{#urldecode:<translate> value</translate>}}

<translate> Notes:

  • This function works by directly exposing PHP's <tvar name=1>urldecode()</tvar> function.
  • A character-code-reference can be found [<tvar name=2>http://www.w3schools.com/tags/ref_urlencode.asp</tvar> at www.w3schools.com].
  • The opposite, <tvar name=3>urlencode</tvar>, has been integrated into MediaWiki as of version 1.18; for examples, see {{<tvar name=4>ll|Help:Magic words#URL data</tvar>|Help:Magic Words}}.
  • urldecode was merged from Stringfunctions in 2010, by commit <tvar name=5>1b75afd18d3695bdb6ffbfccd0e4aec064785363</tvar>

Limits

This module defines three global settings: </translate>

<translate> These are used to limit some parameters of some functions to ensure the functions operate in O(n) time complexity, and are therefore safe against DoS attacks. </translate>

$wgStringFunctionsLimitSearch

<translate> This setting is used by <tvar name=1>#pos</tvar>, <tvar name=2>#rpos</tvar>, <tvar name=3>#replace</tvar>, and <tvar name=4>#explode</tvar>. All these functions search for a substring in a larger string while they operate, which can run in O(n*m) and therefore make the software more vulnerable to DoS attacks. By setting this value to a specific small number, the time complexity is decreased to O(n).

This setting limits the maximum allowed length of the string being searched for.

The default value is 30 multibyte characters. </translate>

$wgStringFunctionsLimitReplace

<translate> This setting is used by <tvar name=1>#replace</tvar>. This function replaces all occurrences of one string for another, which can be used to quickly generate very large amounts of data, and therefore makes the software more vulnerable to DoS attacks. This setting limits the maximum allowed length of the replacing string.

The default value is 30 multibyte characters.

General points

Substitution

Parser functions can be [[<tvar name=help>Special:MyLanguage/Help:Substitution</tvar>|substituted]] by prefixing the hash character with <tvar name=subst>subst:</tvar>: </translate>

{{subst:#ifexist: Yardım:Fonksiyonlar | [[Yardım:Fonksiyonlar]] | Yardım:Fonksiyonlar }} → <translate> the code <tvar name=1>[[Yardım:Fonksiyonlar]]</tvar> will be inserted in the wikitext since the page <tvar name=2>Yardım:Fonksiyonlar</tvar> exists.</translate>

Şablon:Warning

<translate> Substitution does not work within <tvar name=code1>Şablon:Ll</tvar>; you can use <tvar name=code2>Şablon:((subst:#tag:ref|Şablon:))</tvar> for this purpose.

Redirects

Especially <tvar name=time>{{#time:…|now-…}}</tvar> could be handy in {{<tvar name=redirects>ll|Help:Redirects</tvar>|redirects}} to pages including dates, but this does not work.

Escaping pipe characters in tables

</translate> <translate> Parser functions will mangle {{<tvar name=help-tables>ll|Help:Tables</tvar>|wikitable}} syntax and pipe characters (<tvar name=pipe>|</tvar>), treating all the raw pipe characters as parameter dividers.</translate> <translate> To avoid this, most wikis used a template <tvar name=template>Şablon:!</tvar> with its contents only a raw pipe character (<tvar name=pipe>|</tvar>), since MW 1.24 a {{<tvar name=help-magic>ll|Help:Magic words#Other|{{!}}</tvar> magic word}} replaced this kludge.</translate> <translate> 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.</translate> <translate> It will then be interpreted as a table row or column separator.</translate> <translate> Alternatively, raw HTML table syntax can be used, although this is less intuitive and more error-prone.</translate>

<translate> You can also escape the pipe character for display as a plain, uninterpreted character using an HTML entity: <tvar name=entity>&#124;</tvar> . </translate>

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

<translate>

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. </translate>

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

<translate> To prevent the trimming of then and else parts, see <tvar name=1>m:Template:If</tvar>. Some people achieve this by using <tvar name=2><Şablon:Ll> </nowiki></tvar> instead of spaces. </translate>

<syntaxhighlight lang="moin" inline>foobarfoo</syntaxhighlight> → foobarfoo
<syntaxhighlight lang="xml" inline>foo bar foo</syntaxhighlight> → foo bar foo

<translate> However, this method can be used to render a single whitespace character only, since the parser squeezes multiple whitespace characters in a row into one. </translate>

<syntaxhighlight lang="html">foo bar foo</syntaxhighlight> foo bar foo

<translate> 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: </translate>

<syntaxhighlight lang="html" inline>foo bar foo</syntaxhighlight> → foo bar foo
<syntaxhighlight lang="html" inline>foo   bar   foo</syntaxhighlight> → foo   bar   foo

Beware that not all parameters are created equal. In ParserFunctions, whitespace at the beginning and end is always stripped. In templates, whitespace at the beginning and end is stripped for named parameters and named unnamed parameters but not from unnamed parameters:

fooŞablon:TlxfoofooŞablon:1xfoo
fooŞablon:TlxfoofooŞablon:1xfoo
fooŞablon:TlxfoofooŞablon:1xfoo

<translate>

See also

</translate>

<translate>

</translate>

<translate>

References

</translate> Şablon:Reflist

[[Category:Extension help{{#translation:}}|ParserFunctions]] [[Category:Magic words{{#translation:}}]]

  1. Prior to <tvar name=1>Şablon:Rev</tvar> in 2011 this was not the case.
  2. ParserFunctions.php at phabricator.wikimedia.org