Extension:Loops

What can this extension do?
While and do-while loops similar to those used in programming languages.

Syntax
For technical reasons, the preprocessor in v1.12alpha and later handles the first parameter differently than the rest, so it's ignored for the #while and #dowhile parser functions in order for them to work. See bug 12842.

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

Examples
Note: The following examples use the VariablesExtension.

The wiki markup:

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

then the wiki-markup

produces


 * zero
 * one
 * two
 * three
 * four

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

#foreachnamedarg (Experimental)
{ {#foreachnamedarg}} 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.

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

Example
If the page "Template:Loops Test" contains

then the wiki markup

produces


 * 1 = val1
 * 5 = val5
 * ument = value

This parser function only deals with named arguments. Numbered arguments are ignored.

Download instructions
Please cut and paste the code found below and place it in. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation
As of v0.2.0 this extension requires VariablesExtension to be installed. Once that is installed, Loops is installed by adding the following to LocalSettings.php:

ExtLoops::$maxLoops
This parameter set the maximum number of loops a page is allowed to perform. Setting it to a negative value lets the loops run within the limits of php's environment. This parameter does not affect { {#foreachnamedarg:}}.