Open main menu

Extension:Loops/ja

English  • Deutsch • 日本語 • 中文
MediaWiki 拡張機能マニュアル
OOjs UI icon advanced.svg
Loops
リリースの状態: 安定
実装 パーサー関数
説明 Provides parser functions for performing loops
作者 David M. Sledge (talk), Daniel Werner
最新バージョン 0.5.0 (2014-04-22)
MediaWiki 1.19 以降
PHP 5.3 以降
データベースの変更 いいえ
ライセンス GNU General Public License 2.0 以降
ダウンロード
README
RELEASE-NOTES
translatewiki.net で翻訳を利用できる場合は、Loops 拡張機能の翻訳にご協力ください
使用状況とバージョン マトリクスを確認してください。

The Loops extension provides parser functions for performing loops.

使用法Edit

#whileEdit

{{#while}} performs a loop (i.e. it repeatedly parses a given wiki markup block statement) so long as the condition mark-up evaluates to non-whitespace.

{{
  #while:
  | <condition text>
  | <block statement>
}}

Edit

注記: The following examples use the VariablesExtension.

The wiki markup:

{{ #vardefine: i | 0 }}{{
  #while:
  | {{ #ifexpr: {{ #var: i }} < 5 | true }}
  |<nowiki/>
* {{ #var: i }}{{ #vardefine: i | {{ #expr: {{ #var: i }} + 1 }} }}
}}

produces the following:

  • 0
  • 1
  • 2
  • 3
  • 4

{{#while}} can also be used in a template to simulate a numbered array. If the page "Template:Loops Test" contains

{{
  #vardefine: i | 0
}}{{
  #while:
  | {{{ arg{{#var: i }} |}}}
  |<nowiki/>
* {{{ arg{{#var: i }} }}}{{
    #vardefine: i
    | {{ #expr: {{ #var: i }} + 1 }}
  }}
}}

then the wiki-markup

{{Loops Test
|arg0=zero
|arg1=one
|arg2=two
|arg3=three
|arg4=four
}}

produces

  • zero
  • one
  • two
  • three
  • four

It's important to note that whitespace, including newlines, tabs, and spaces, is stripped from the beginning and end of all the arguments of these parser functions. If this is not desirable, adding any non-whitespace characters (including the HTML encoding for a whitespace character &#32;) will prevent further stripping (hence the <nowiki/> tags in the above examples).

#dowhileEdit

{{#dowhile}} performs exactly like {{#while}}, with the exception that the block statement is guaranteed to be parsed and displayed (if it results in displayable text) at least once. This is done before the condition text is evaluated.

#loopEdit

{{
  #loop: <variable name>
  | <starting value>
  | <number of loops to be performed>
  | <wiki markup>
}}

{{#loop}} repeatedly parses and displays <wiki markup> a number of times equal to the absolute value of <number of loops to be performed>. <Starting value> is placed in a variable (accessible by VariablesExtension's {{#var:}} parser function) using the name <variable name>. After each loop, the variable is incremented by one if <number of loops to be performed> is positive, or decremented by one if <number of loops to be performed> is negative.

注記: From all loop functions, #loop should have the best performance since there is no condition which has to be expanded and validated for each cycle.

Edit

The following code:

{{#loop: varname
  | 4
  | 4
  | <nowiki/>
* This is round {{#var:varname}} and we have {{#expr: 7- {{#var:varname}}}} more to go
}}

produces

  • This is round 4 and we have 3 more to go
  • This is round 5 and we have 2 more to go
  • This is round 6 and we have 1 more to go
  • This is round 7 and we have 0 more to go

#forargs (実験的)Edit

{{#forargs}} is to be used in templates. It takes arguments that are passed to the template and puts them in variables accessible by VariablesExtension's {{#var:}} parser function.

{{
  #forargs: <prefix>
  | <key>
  | <value>
  | <block statement>
}}

This function iterates through each argument whose name begins with <prefix>. With each iteration it puts the argument name minus <prefix> into <key> as if calling {{#vardefine: <key> }}. It then takes the value of the argument and puts it into <value> in a similar method. The block statement is then expanded. The block statement may contain {{#var: <key> }} and {{#var: <value> }} to access the stored arguments.

Edit

If the page "Template:Loops Test" contains

{{
  #forargs: arg
  | key
  | value
  | <nowiki/>
* {{#var: key}} = {{#var: value}}
}}

then the wiki markup

{{Loops Test
| arg1=val1
| spam=spammity
| arg5=val5
| argument=value
}}

produces

  • 1 = val1
  • 5 = val5
  • ument = value

#fornumargs (実験的)Edit

{{
  #fornumargs: <key>
  | <value>
  | <block statement>
}}

{{#fornumargs}} performs similarly to {{#forargs}} with two major differences: It doesn't take a prefix argument, and it only works on numbered arguments whether they're explicitly numbered:

{{Template | 1=one | 2=two }}

or implicitly numbered:

{{Template | one | two }}

Mixing these methods in a single template call may cause values to get overwritten, so be careful.

Edit

TBD

インストールEdit

  • ダウンロードして、ファイルを extensions/ フォルダー内の Loops という名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php の末尾に追加します:
    require_once "$IP/extensions/Loops/Loops.php";
    
  •   完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

ConfigurationEdit

These configuration variables have to be set in the LocalSettings file after inclusion of Loops.

ExtLoops::$maxLoops
This parameter sets the maximum number of loops a page is allowed to perform (default 100). Setting it to -1 lets the loops run within the limits of phps environment. This parameter affects neither the {{#forargs:}} nor {{#fornumargs:}}.
$egLoopsEnabledFunctions
Configuration variable (array) to define which Loops functions should be enabled. By default, all functions are enabled if the Variables extension is installed as well. If the Variables extension is not installed, #loop, #forargs and #fornumargs will be disabled since they don't work without. To enable the fornumargs and forargs functions only, one can use:
$egLoopsEnabledFunctions = array_diff( $egLoopsEnabledFunctions, array( 'forargs', 'fornumargs' ) );

関連項目Edit

English  • Deutsch • 日本語 • 中文