Extension:Loops

This page is a translated version of the page Extension:Loops and the translation is 83% complete.
Other languages:
Deutsch • ‎English • ‎Türkçe • ‎中文 • ‎日本語
MediaWiki manüel uzantıları
OOjs UI icon advanced.svg
Loops
Sürüm durumu: kararlı
Uygulama Ayrıştırıcı işlevi
Açıklama Döngüleri gerçekleştirmek için ayrıştırıcı işlevleri sağlar
Yazar(lar)
En son sürüm 0.5.2 (2019-08-05)
MediaWiki 1.34+
PHP 5.6+
Veritabanı değişiklikleri Hayır
Lisans GNU Genel Kamu Lisansı 2.0 veya üstü
İndir
README
RELEASE-NOTES
Örnek sandbox.semantic-mediawiki.org
  • $egLoopsEnabledFunctions
  • $egLoopsCountLimit
Translatewiki.net adresinde mevcutsa, Loops uzantısını çevirin

Kullanım ve sürüm matrisini kontrol edin.

Sorunlar Açık görevler · Hata bildir

Loops uzantısı, döngüleri gerçekleştirmek için ayrıştırıcı işlevleri sağlar. Şu anda sürüm 1.0.0, çok fazla döngüye sahip sayfalar için uzantı kayıtı, izleme kategorileri ve gerilemeleri önlemek için Parser tests içeren geliştirme aşamasındadır. Aşağıdaki belgeler, en son kararlı sürüm olan v0.5.2 hedeflemektedir.

Kullanım

Aşağıdaki örnekler Variables uzantısını ve bazı durumlarda da ParserFunctions uzantısını kullanır.

#while

{{#while}}, koşul işaretlemesi boşluk olmayan olarak değerlendirildiği sürece bir döngü gerçekleştirir (yani belirli bir viki biçimlendirme blok ifadesini tekrar tekrar ayrıştırır).

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

Viki işaretlemesi:

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

aşağıdakine üretir:

  • 0
  • 1
  • 2
  • 3
  • 4

{{#while}}, numaralandırılmış bir diziyi simüle etmek için bir şablonda da kullanılabilir. "Şablon:Döngüler Testi" sayfası şunu içeriyorsa:

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

sonra viki biçimlendirmesi

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

üretir

  • 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).

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

Note: 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.

Examples

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 (experimental)

{{#forargs}} is to be used in templates. 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.

Example

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.

Examples

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

Some of the parser functions provided by this extension require the ParserFunctions as well as the Variables extension to be installed first.

Configuration

These configuration variables have to be set in the "LocalSettings.php" file after the inclusion of this extension.

ExtLoops::$maxLoops ($egLoopsCountLimit in the forthcoming 1.0.0 release)
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'
        ]
    );

See also