Module:Iteration/doc: Difference between revisions
From Neodyland Wiki
More actions
m format |
Fix language-code links to use Wikipedia interwiki prefixes |
||
| (33 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
<includeonly> | <includeonly>{{Module rating|release}}{{Module rating|protected}}{{Heavily used module|very|edit=sandbox}}</includeonly> | ||
{{#tag:span|{{0}} The module uses frequently the template {{tlg|code=on|=}} for '''title = "="''' {{0}}|style=border:4px solid #CCC;margin-left:5.2em;background-color:#DFD}} | |||
This module contains the functions for different templates, solving their '''iteration problem''' | This module contains the functions for different templates, solving their '''iteration problem''' | ||
The MediaWiki template coding does not support the repetitive processing of a parameter set, which leads often to a very primitive and long chain of parameter checks in the kind of:<syntaxhighlight lang="text"> | |||
{{#if:{{{1|}}} | perform an action with parameter 1 }} | {{#if:{{{1|}}} | perform an action with parameter 1 }} | ||
{{#if:{{{2|}}} | perform an action with parameter 2 }} | {{#if:{{{2|}}} | perform an action with parameter 2 }} | ||
| Line 9: | Line 11: | ||
••• | ••• | ||
••• | ••• | ||
{{#if:{{{33|}}} perform an action with parameter 33 }}</ | {{#if:{{{33|}}} perform an action with parameter 33 }} | ||
with the disadvantage that such a construct will fail as soon as there comes a | </syntaxhighlight>with the disadvantage that such a construct will fail as soon as there comes a {{Ordinal|34}} parm. | ||
I always thought that with Lua and its < | I always thought that with Lua and its <syntaxhighlight lang="lua" inline>for</syntaxhighlight> loops this iterations should be possible, somehow. After long searching without any success and without an idea how to perform it, I asked at several forums and got finally from {{Ut|Trappist the monk|+|w:en}} the helping hint to solve it with a control structure like:<syntaxhighlight lang="lua"> | ||
After long searching without any success and without an idea how to perform it, I asked at several forums | |||
and got finally from {{Ut|Trappist the monk|+|en}} the helping hint to solve it with a control structure like | |||
local out = {} | local out = {} | ||
for i, v in ipairs (args) do | for i, v in ipairs (args) do | ||
table.insert (out, frame:expandTemplate{ title = title, args = v }) | table.insert (out, frame:expandTemplate{ title = title, args = v }) | ||
end | end | ||
return table.concat (out) | return table.concat (out) | ||
</syntaxhighlight> | |||
The functions contained therein are from very simple, just one parameter to pass, to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch when always a tuple of e.g. an item and its correlated text needs to be passed. | |||
When there are tuples, triples etc., the <syntaxhighlight lang="lua" inline>table.insert</syntaxhighlight> occurs, when the last element is processed; this performs problems when the last group is incomplete – it should be finished with empty values to trigger the <syntaxhighlight lang="lua" inline>table.insert</syntaxhighlight>. The check with <syntaxhighlight lang="lua" inline>table.maxn</syntaxhighlight> seems not to work correctly? | |||
When there are tuples, triples etc., the < | |||
this performs problems when the last group is incomplete – it should be finished with empty values | |||
to trigger the < | |||
=== | ''This'' problem is solved differently, for the function <syntaxhighlight lang="lua" inline>attribs</syntaxhighlight> with a primitive workaround. | ||
#<li value="6"> {{ | == Namespace lists == | ||
# {{ | There are special lists for some namespaces: | ||
* {{T\|Filelist|08}} - for items of the [[#Filelist|namespace 6]] (File:) | |||
#<li value=" | * {{T\|Userlist|08}} - for items of the [[#Userlist|namespace 2]] (User:) | ||
* {{T\|Linklist|08}} - for items of the namespace <s>0</s> (main) — ''not yet'' | |||
* {{T\|Templist|08}} - for items of the namespace <s>10</s> (Template:) — ''not yet'' | |||
* {{T\|Cat-list|08}} - for items of the namespace <s>14</s> (Category:) — ''not yet'' | |||
* {{T\|Mod-list|08}} - for items of the namespace <s>828</s> (Module:) — ''not yet'' | |||
=== {{T\|Filelist|08}} === | |||
==== File list templates ==== | |||
The three templates {{tlg|code=on|Ifim}}, {{tlg|code=on|Ifim1}} and {{tlg|code=on|Ifimt}} avoid to display the file itself as an {{para|other version}}. | |||
There are currently five templates creating file lists with the function:<syntaxhighlight lang="lua" inline>filelist</syntaxhighlight> | |||
# {{tlg|code=on|Other versions}} a vertical list (without initial) | |||
# {{tlg|code=on|Filelist}} a horizontal list (without initial) | |||
# {{tlg|code=on|Derivative versions}} a vertical list | |||
# {{tlg|code=on|Derived from}} a vertical list | |||
# {{tlg|code=on|File}} a horizontal list | |||
All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the {{para|gallery}} option. | |||
==== Other file lists ==== | |||
The function:<syntaxhighlight lang="lua" inline>svglang</syntaxhighlight> creates a list of just file_names and language_codes, for: | |||
#<li value="6"> {{tlg|code=on|Svg lang}} | |||
# {{tlg|code=on|Lang gallery}}<!-- and ''using'' the <code>file</code> parameter: --> | |||
# {{tlg|code=on|Multilingual SVG diagrams}} | |||
Much more is created by the function:<syntaxhighlight lang="lua" inline>ownbased</syntaxhighlight> for the template: | |||
#<li value="9">{{tlg|code=on|Own based}} | |||
which will handle in the ''majority of cases'' just one file, but can serve an unlimited number. | which will handle in the ''majority of cases'' just one file, but can serve an unlimited number. | ||
This list can be controlled by the user to be displayed either horizontally or vertically. | |||
#<li value="10">{{tlg|code=on|Attribs}} | |||
The template works, whether there is a user assigned for a file, or one filename follows another. | |||
#<li value="11">{{tlg|code=on|Emoji}} | |||
The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function <syntaxhighlight lang="lua" inline>emodis</syntaxhighlight> or <syntaxhighlight lang="lua" inline>emotab</syntaxhighlight>. | |||
==== Variable iterations ==== | |||
A very simple iteration, usable for everything, is performed by function:<syntaxhighlight lang="lua" inline>iterate</syntaxhighlight> | |||
:used by e.g. {{tlg|code=on|Image extracted}}, {{tlg|code=on|Image translated}}, | |||
More usable is the function:<syntaxhighlight lang="lua" inline>iteration</syntaxhighlight> for transclusions of a template with: | |||
*a number of positional parameters which can change at each transclusion, and | |||
*a number of positional parameters which are the same for all transclusions. | |||
See template {{tlg|code=on|Iterate}}. | |||
The function:<syntaxhighlight lang="lua" inline>loop</syntaxhighlight> is used by {{tlg|code=on|Repeat}}. | |||
==== <syntaxhighlight lang="lua" inline>samefile</syntaxhighlight> function ==== | |||
When the ''name'' of one of the files is the ''same'' as the first one, it is enough to reference it with its ''extension'' after a dot, e.g. just ".jpeg". The ''most standard'' extensions can be abbreviated, e.g. ".j" will be sufficient for ".jpg" (only for lower case!). | |||
The function <syntaxhighlight lang="lua" inline>incrhx</syntaxhighlight> increments a hexadecimal number (parm 1) by a decimal number (parm 2). | |||
Valid numbers are assumed, no checking occurs! | |||
When parameter 2 is preceded by a minus, the first number is ''de''cremented by the second one. | |||
=== {{T\|Userlist|08}} === | |||
* {{T\|Userlist|08}}: {{tlg|code=on|Userlist}} with many formatting parameters | |||
=== {{T\|Linklist|08}} === | |||
=== {{T\|Templist|08}} === | |||
== Other iterations == | |||
* {{T\|Langlist|08}}: | |||
* {{T\|Colorbox|08}}: {{tlg|code=on|ColorString}} and other color box templates | |||
* {{T\|Legends |08}}: {{tlg|code=on|Legtab}} combines single {{tlg|code=on|Legend}}s | |||
* {{T\|Tleparms|08}}: the metatemplate {{tlg|code=on|Tle}} displays the parameter usage of a template | |||
* {{T\|Navigate|08}}: {{tlg|code=on|Navcat}} navigates through color categories | |||
* {{T\|Showname|08}}: {{tlg|code=on|Showname}} helper template, for parameter tests | |||
* {{T\|Emodis {{0}}|08}}: {{tlg|code=on|Emoji}} displays (one or many) Unicode characters | |||
:The function <syntaxhighlight lang="lua" inline>emodis</syntaxhighlight> <u>dis</u>plays Unicode characters / <u>emo</u>jis; it can care for newlines, while | |||
:The function <syntaxhighlight lang="lua" inline>emotab</syntaxhighlight> displays a <u>tab</u>le of files / <u>emo</u>jis. | |||