Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Iteration/doc: Difference between revisions

From Neodyland Wiki
mNo edit summary
Fix language-code links to use Wikipedia interwiki prefixes
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<includeonly>{{Module rating|release}}{{Module rating|protected}}{{Heavily used module|very|edit=sandbox}}</includeonly>
<includeonly>{{Module rating|release}}{{Module rating|protected}}{{Heavily used module|very|edit=sandbox}}</includeonly>
{{#tag:span|{{0}} The module uses frequently the template {{t|&#61;}} for '''title = "="''' {{0}}|style=border:4px solid #CCC;margin-left:5.2em;background-color:#DFD}}
{{#tag:span|{{0}} The module uses frequently the template {{tlg|code=on|&#61;}} 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 Wikipedia 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 {{#tag:syntaxhighlight|<nowiki>
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 11: Line 11:
•••
•••
•••
•••
{{#if:{{{33|}}} perform an action with parameter 33 }}</nowiki>|lang="text"}}
{{#if:{{{33|}}} perform an action with parameter 33 }}
with the disadvantage that such a construct will fail as soon as there comes a 34{{exp|nd}} parm.
</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 <code>for</code> loops this iterations should be possible, somehow.<br>
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<br>
and got finally from {{Ut|Trappist the monk|+|en}} the helping hint to solve it with a control structure like{{#tag:syntaxhighlight|
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)|lang="text"}}
return table.concat (out)
The functions contained therein are from very simple, just one parameter to pass, <br>
</syntaxhighlight>
to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch<br>
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 always a tuple of e.g. an item and its correlated text needs to be passed. <br>
 
<br>
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 <code>table.insert</code> occurs, when the last element is processed;<br>
 
this performs problems when the last group is incomplete – it should be finished with empty values <br>
''This'' problem is solved differently, for the function <syntaxhighlight lang="lua" inline>attribs</syntaxhighlight> with a primitive workaround.
to trigger the <code>table.insert</code>. The check with <code>table.maxn</code> seems not to work correctly ?<br>
 
''This'' problem is solved differently, for the function "attribs" with a primitive workaround.
== Namespace lists ==
There are special lists for some namespaces:
* {{T\|Filelist|08}} - for items of the [[#Filelist|namespace 6]] (File:)
* {{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}}.


=== File list templates ===
There are currently five templates creating file lists with the function:<syntaxhighlight lang="lua" inline>filelist</syntaxhighlight>
The three "Ifim " templates avoid to display the file itself as an 'other version'. <br>
# {{tlg|code=on|Other versions}} a vertical list (without initial)
There are currently five templates creating file lists with the <code>function:filelist</code>
# {{tlg|code=on|Filelist}} a horizontal list (without initial)
# {{T0|Other versions}} a vertical list (without initial)
# {{tlg|code=on|Derivative versions}} a vertical list
# {{T0|Filelist}} a horizontal list (without initial)
# {{tlg|code=on|Derived from}} a vertical list
# {{T0|Derivative versions}} a vertical list  
# {{tlg|code=on|File}} a horizontal list
# {{T0|Derived from}} a vertical list
All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the {{para|gallery}} option.
# {{T0|File}} a horizontal list
All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the "gallery" option.


=== Other file lists ===
==== Other file lists ====
The <code>function:svglang</code> creates a list of just file_names and language_codes, for  
The function:<syntaxhighlight lang="lua" inline>svglang</syntaxhighlight> creates a list of just file_names and language_codes, for:
#<li value="6"> {{T0|Svg lang}}
#<li value="6"> {{tlg|code=on|Svg lang}}
# {{T0|Lang gallery}}<!-- <br>and ''using'' the <code>file</code> parameter: -->
# {{tlg|code=on|Lang gallery}}<!-- and ''using'' the <code>file</code> parameter: -->
# {{T0|Multilingual SVG diagrams}}
# {{tlg|code=on|Multilingual SVG diagrams}}
Much more is created by the <code>function:ownbased</code> for the template
Much more is created by the function:<syntaxhighlight lang="lua" inline>ownbased</syntaxhighlight> for the template:
#<li value="9">{{T0|Own based}}<br>
#<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.<br>
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.<br>
 
#<li value="10">{{T0|Attribs}}<br>
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.
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>.


#<li value="11">{{T0|Emoji|Emotab}}<br>
==== Variable iterations ====
The template displays a line of SVG emojis;  Unicode characters/emojis can be displayed with the function {{T0|Emoji|Emodis}}.
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}}.


=== Variable iterations ===
==== <syntaxhighlight lang="lua" inline>samefile</syntaxhighlight> function ====
A very simple iteration, useable for everything, is performed by <code>function:iterate</code>  
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!).
:used by e.g. {{T|Image extracted}}, {{T|Image translated}}, <br>
 
More useable is the <code>function:iteration</code> for transclusions of a template with
The function <syntaxhighlight lang="lua" inline>incrhx</syntaxhighlight> increments a hexadecimal number (parm 1) by a decimal number (parm 2).
*a number of positional parameters which can change at each transclusion, and
 
*a number of positional parameters which are the same for all transclusions.
Valid numbers are assumed, no checking occurs!
See template {{T|Iterate}}.
 
The <code>function:loop</code> is used by {{T|Repeat}}.
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


=== Other iterations ===
=== {{T\|Linklist|08}} ===
* {{T\|Userlist|08}}: {{T0|Userlist}} with many formatting parameters
* {{T\|Colorbox|08}}: {{T0|ColorString}} and other color box templates
* {{T\|Legends |08}}: {{T0|Legtab}} combines single {{T0|Legend}}s
* {{T\|Tleparms|08}}: the metatemplate {{T0|Tle}} displays the parameter usage of a template
* {{T\|Navigate|08}}: {{T0|Navcat}} navigates through color categories
* {{T\|Emodis {{0}}|08}}: {{T0|Emoji}} displays (one or many) Unicode characters
* {{T\|Showname|08}}: {{T0|Showname}} helper template, for parameter tests
:The function "{{T\|emodis|08}}" <u>dis</u>plays Unicode characters / <u>emo</u>jis; it can care for newlines, while
:The function "{{T\|emotab|08}}" displays a <u>tab</u>le of files / <u>emo</u>jis.


=== "samefile" function ===
=== {{T\|Templist|08}} ===
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".<br>The ''most standard'' extensions can be abbreviated, e.g. ".j" will be sufficient for ".jpg" (only for lower case!).


== Other iterations ==


The function "'''incrhx'''" increments a hexadecimal number (parm 1) by a decimal number (parm 2).<br>
* {{T\|Langlist|08}}:
Valid numbers are assumed, no checking occurs !<br>
* {{T\|Colorbox|08}}: {{tlg|code=on|ColorString}} and other color box templates
When parameter 2 is preceded by a minus, the first number is ''de''cremented by the second one
* {{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.

Latest revision as of 18:44, 12 August 2026

0 The module uses frequently the template {{=}} for title = "=" 0

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:

{{#if:{{{1|}}} | perform an action with parameter 1 }}
{{#if:{{{2|}}} | perform an action with parameter 2 }}
{{#if:{{{3|}}} | perform an action with parameter 3 }}
{{#if:{{{4|}}} | perform an action with parameter 4 }}
•••
•••
{{#if:{{{33|}}} perform an action with parameter 33 }}

with the disadvantage that such a construct will fail as soon as there comes a 34th parm. I always thought that with Lua and its for 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 User:Trappist the monk the helping hint to solve it with a control structure like:

	local out = {}
	for i, v in ipairs (args) do
		table.insert (out, frame:expandTemplate{ title = title, args = v })
	end
	return table.concat (out)

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 table.insert 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 table.insert. The check with table.maxn seems not to work correctly?

This problem is solved differently, for the function attribs with a primitive workaround.

Namespace lists

edit

There are special lists for some namespaces:

  • Filelist - for items of the namespace 6 (File:)
  • Userlist - for items of the namespace 2 (User:)
  • Linklist - for items of the namespace 0 (main) — not yet
  • Templist - for items of the namespace 10 (Template:) — not yet
  • Cat-list - for items of the namespace 14 (Category:) — not yet
  • Mod-list - for items of the namespace 828 (Module:) — not yet

Filelist

edit

File list templates

edit

The three templates {{Ifim}}, {{Ifim1}} and {{Ifimt}} avoid to display the file itself as an |other version=.

There are currently five templates creating file lists with the function:filelist

  1. {{Other versions}} a vertical list (without initial)
  2. {{Filelist}} a horizontal list (without initial)
  3. {{Derivative versions}} a vertical list
  4. {{Derived from}} a vertical list
  5. {{File}} a horizontal list

All these templates are autoreferencing, and the support also the |gallery= option.

Other file lists

edit

The function:svglang creates a list of just file_names and language_codes, for:

  1. {{Svg lang}}
  2. {{Lang gallery}}
  3. {{Multilingual SVG diagrams}}

Much more is created by the function:ownbased for the template:

  1. {{Own based}}

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.

  1. {{Attribs}}

The template works, whether there is a user assigned for a file, or one filename follows another.

  1. {{Emoji}}

The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function emodis or emotab.

Variable iterations

edit

A very simple iteration, usable for everything, is performed by function:iterate

used by e.g. {{Image extracted}}, {{Image translated}},

More usable is the function:iteration 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 {{Iterate}}. The function:loop is used by {{Repeat}}.

samefile function

edit

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 incrhx 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 decremented by the second one.

Userlist

edit
  • Userlist: {{Userlist}} with many formatting parameters
edit

Templist

edit

Other iterations

edit
  • Langlist:
  • Colorbox: {{ColorString}} and other color box templates
  • Legends : {{Legtab}} combines single {{Legend}}s
  • Tleparms: the metatemplate {{Tle}} displays the parameter usage of a template
  • Navigate: {{Navcat}} navigates through color categories
  • Showname: {{Showname}} helper template, for parameter tests
  • Emodis 0: {{Emoji}} displays (one or many) Unicode characters
The function emodis displays Unicode characters / emojis; it can care for newlines, while
The function emotab displays a table of files / emojis.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.