Help:Extension:ParserFunctions/ja

The extension provides eleven additional parser functions to supplement the "magic words", which are already present in MediaWiki. (It may be configured to provide additional parser functions for string handling; these string functions are documented .) All the parser functions provided by this extension take the form:

#expr
この関数は、数式を計算してその計算結果を返します. This function is also available in Scribunto via the  function.



The available operators are listed to the right, in order of precedence. See 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, zero evaluates to , and any nonzero value, positive or negative, evaluates to  :



空の入力式は空の文字列を返します. 無効な式はいくつかのエラー メッセージのうちのいずれかを返します. このエラーは  関数を使用して捕捉できます:



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:



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



丸め
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.

切り上げや切り捨てを行なうには、それぞれ単項の  と   を使用してください.

Strings
Expressions only work with number-like values, they cannot compare strings or characters. can be used instead.



#if
この関数はテスト文字列を評価し、それが空であるかどうかを判定します. 空白のみを含むテスト文字列は空であると見做されます.





この関数は、初めに最初の引数が空でないか確かめます. 最初の引数が空でない場合、2 番目の引数を表示します. 最初の引数が空または空白文字（空白、改行等）のみを含む場合、3 番目の引数を表示します.



テスト文字列は常に純粋なテキストとして評価されます. そのため数式は評価されません:



最後の引数（偽）は省略可能です:



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. Up to seven levels of nesting is possible, although that may depend on the wiki or a memory limit.
 * Example:


 * 1) if 文において引数をテスト文字列として用いることも可能です. 変数名の後には |（パイプ記号）を追加する必要があります.


 * Example

このパーサー関数の他の例については Help:Parser functions in templates/ja を参照してください.

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



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



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


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

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

the following ensue:


 * → 20
 * → 40
 * → 40

#iferror
この関数は入力文字列を取り、2つの結果から1つを返します. この関数は、  や   や   のような他のパーサー関数、ループや再帰のようなテンプレートエラー、その他の「フェースソフト」なパーサーエラーによって作られた   を含む HTML オブジェクトが入力文字列に含まれていた場合に   と評価します.



返値の文字列の一方または両方が省略できます. もし  の文字列が省略されていた場合、エラーがないのであれば   が返されます. の文字列も省略されていた場合は、エラー時にから文字列が返されます.


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

#ifexpr
This function evaluates a mathematical expression and returns one of two strings depending on the boolean value of the result:



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

An empty input expression evaluates to :



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



except for an empty or wrong input expression (an error message is treated as an empty string; it is not equal to zero, so we get ).

comparing

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



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



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



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



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

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

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

does not work with interwiki links.

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  functions automatically return false, whether the target page exists or not, and the page is categorized into Category:. The name of the tracking category may vary depending on the content language of your wiki.

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

#rel2abs
この関数は相対ファイル パスを絶対ファイル パスに変換します.



部分では、以下の構文を使用できます:
 * → 現在の階層
 * → 「1 つ上の階層に移動」
 * → 「下位ディレクトリ /foo に 1 階層移動」

を指定していない場合は、ページの完全なページ名が代わりに使用されます:



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



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

例:




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

既定
The  is returned if no   string matches the  :



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



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

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



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



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

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

比較の挙動
As with, the comparison is made numerically if both the comparison string and the case string being tested are numeric; or as a case-sensitive string otherwise:





A  string may be empty:

Once a match is found, subsequent  are ignored:

生の等号
"Case" strings cannot contain raw equals signs. To work around this, create a template = containing a single equals sign:.

例:



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

#ifeqの置換
can be used to reduce expansion depth.

例えば: は、以下と同等です i.e.

#time
このパーサ機能は日あるいは時間 (グレゴリア暦) を取って指定の文法どおりにフォーマットします. 日・時間のオブジェクトを特定する方法は; 既定値は マジックワード  –  HTMLにページが表示された日時.



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



The  can be in any format accepted by PHP's strtotime function. Both absolute (eg ) and relative (eg  ) times are accepted.

→ '''

→ '''

→ '''

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

→ '''

→  

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

→ '''

→ '''

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:



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

→ '''

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

→ ''' Input is treated as a time rather than a year+month code.

→ ''' 19:60:09 は有効な時刻ではないにもかかわらず、196009 は1960年9月とは解釈されません.

The function performs a certain amount of date mathematics:



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

タイムゾーンの問題点
There is a bug in this #time parser function (more specifically in PHP DateTime) that does not allow the passing-in of non-integers as relative time zone offsets. This issue does not apply when using an on-the-hour time zone, such as EDT. For example:

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

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

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



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



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


 * →  See also.
 * →  See also.

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


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

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


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

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


 * 1) All underscores are automatically replaced with spaces:
 * →  Not bah_boo, despite the underscore in the original.
 * 1) The string is split a maximum of 25 times; further slashes are ignored and the 25th element will contain the rest of the string. The string is also limited to 255 characters, as it is treated as a page title:
 * If for whatever reason you needed to push this function to its limit, although very unlikely, it is possible to bypass the 25 split limit by nesting function calls:
 * 1) The list of substrings is not cleaned up hierarchically (unlike with the   and   relative path segments are left intact by #titleparts):
 * 2) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) The list of substrings is not cleaned up hierarchically (unlike with the   and   relative path segments are left intact by #titleparts):
 * 2) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).
 * 1) Finally the first substring is capitalized according to the capitalization settings of the local wiki (if that substring also starts by a local namespace name, that namespace name is also normalized).

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


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

}}

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

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


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

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

リダイレクト
Especially   could be handy in redirects to pages including dates, but this does not work.

表内でのパイプ記号のエスケープ
Parser functions will mangle wikitable syntax and pipe characters, treating all the raw pipe characters as parameter dividers. To avoid this, most wikis used a template    :! with its contents only a raw pipe character, since MW 1.24 a   magic word replaced this kludge. 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.

パイプ記号は、プレーンな (解釈されない) 文字としてエスケープすることもできます. これには HTML エンティティ  を使用します.

空白類の除去
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.



then 部分および else 部分での空白の除去を回避する方法は、m:Template:If を参照してください. 空白の代わりに &lt; nowiki &gt; &lt; /nowiki &gt; を使用することもできます.


 * → foofoo
 * → foofoo

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.


 * →  foofoo 

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

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


 * →  foofoo 
 * → foofoo

関連項目

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