Extension:Loops/de
Loops Freigabestatus: stabil |
|
---|---|
Einbindung | Parser-Funktion |
Beschreibung | Fügt Parserfunktionen hinzu, die Schleifen durchführen |
Autor(en) | |
Letzte Version | 0.5.2 (2019-08-05) |
MediaWiki | 1.34+ |
PHP | 5.6+ |
Datenbankänderungen | Nein |
Lizenz | Keine Lizenz angegeben |
Herunterladen | README RELEASE-NOTES |
Beispiel | sandbox.semantic-mediawiki.org |
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Übersetze die Loops-Erweiterung, wenn sie auf translatewiki.net verfügbar ist | |
Probleme | Offene Aufgaben · Einen Fehler melden |
Die Loops-Erweiterung bietet Parserfunktionen , um Schleifen durchzuführen.
Aktuell wird diese Erweiterung auf einer Basisebene von MGChecker gewartet.
Verwendung
#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.
{{#while: | <condition text> | <block statement> }}
- Beispiele
Dieser Wiki-Markup:
{{#vardefine: i | 0 }}{{#while: | {{#ifexpr: {{#var: i }} < 5 | true }} | <nowiki /> * {{#var: i }}{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }} }}
ergibt folgendes:
- 0
- 1
- 2
- 3
- 4
{{#while}}
kann auch in einer Vorlage verwendet werden, um ein nummeriertes Array zu simulieren.
Falls die Seite "Template:Loops Test" folgendes beinhaltet
{{#vardefine: i | 0 }}{{#while: | {{{arg{{#var: i }} |}}} | <nowiki /> * {{{arg{{#var: i }} }}}{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }} }}
Dann wird der Wiki-Markup
{{Loops Test |arg0=null |arg1=eins |arg2=zwei |arg3=drei |arg4=vier }}
folgendes erzeugen:
- null
- eins
- zwei
- drei
- vier
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  
) will prevent further stripping (hence the <nowiki>
tags in the above examples).
#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.
#loop
{{#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 Variables extension'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.
#loop
should have the best performance since there is no condition which has to be expanded and validated for each cycle.- Beispiele
Der folgende Code:
{{#loop: varname | 4 | 4 | <nowiki /> * Dies ist Runde {{#var: varname }} und wir haben noch {{#expr: 7 - {{#var: varname }} }} vor uns }}
erzeugt folgendes:
- Dies ist Runde 4 und wir haben noch 3 vor uns
- Dies ist Runde 5 und wir haben noch 2 vor uns
- Dies ist Runde 6 und wir haben noch 1 vor uns
- Dies ist Runde 7 und wir haben noch 0 vor uns
#forargs
(experimentell)
{{#forargs}}
soll in Vorlagen verwendet werden.
It takes arguments that are passed to the template and puts them in variables accessible by Variables extension'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.
- Beispiel
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
(experimental)
{{#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.
- Beispiele
If "Template:Loops Test" is edited to contain:
{{#fornumargs: number | value | <nowiki /> * {{#var: number }} = {{#var: value }} }}
then
{{Loops Test | Apricot | B = Bolognese | Caramel slice | 5 = Eclair }}
will result in
- 1 = Apricot
- 2 = Caramel slice
- 5 = Eclair
Installation
- <translate> [[<tvar name=2>Special:ExtensionDistributor/Loops/de</tvar>|Download]] and move the extracted <tvar name=name>
Loops/de
</tvar> folder to your <tvar name=ext>extensions/
</tvar> directory.</translate>
<translate> Developers and code contributors should install the extension [[<tvar name=git>Special:MyLanguage/Download from Git</tvar>|from Git]] instead, using:</translate>cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Loops%2Fde - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
wfLoadExtension( 'Loops/de' );
- Konfiguriere nach Bedarf.
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
Konfiguration
These configuration variables have to be set in the LocalSettings.php
file after the inclusion of this extension.
$egLoopsCountLimit
- 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:}}
parser functions.
$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 do not work without it being installed. To enable the#fornumargs
and#forargs
functions only, one can use:
$egLoopsEnabledFunctions = array_diff(
$egLoopsEnabledFunctions, [
'forargs', 'fornumargs'
]
);
Siehe auch
- Erweiterung:LoopFunctions - Eine weitere Erweiterung für Schleifen
- Module:Loops
File:OOjs UI icon information-progressive.svg | <translate> This extension is included in the following wiki farms/hosts and/or packages:</translate>
<translate> This is not an authoritative list.</translate> <translate> Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here.</translate> <translate> Always check with your wiki farms/hosts or bundle to confirm.</translate> |