Wikipedia:Lua/Modul/TemplUtl/en
Erscheinungsbild
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
Weiterleitung der Diskussionsseite fehlt
TemplUtl
– Library module with functions to support template programming.
Functions for templates
[Am Gwëntext werkeln]- faculty
- Boolean choice (yes/no) for parameter values depending on page language
- Parameters:
- 1
- Parameter value to be analysed
- Space characters will be ignored, upcased/downcased letters not significant; two interpretations:
- empty,
0
,false
,n
,no
,off
,0000
,-
plus local language: Germannein
1
,true
,y
,yes
,on
;0101
(boolean OR concatenation) plus local language: Germanja
,j
- empty,
- 2
- Behaviour if value 1 not recognized.
- (optional)
1
– “yes” (default)0
– “no”
- Result:
- empty for “no”
- not empty (
1
) for “yes”
- Test page with example results.
- Project and page language specific adaption (non-English)
- failure
- Format error message; in edit preview of source text editing will be repeated and linked on page head
- Parameters:
- 1
- error message
- 2
- Visibility of error message on presentation
- (optional)
0
– “invisible” (default)1
– “visible”
- Result: HTML element
- fake
- Simulating a template transclusion; will vanish from Special:Unusedtemplates (especially for substituting templates, and any auxilary template pages like test, maintenance, editnotice, preload and more, wich are never transcluded by regular means).
- 1
- Title or name of template (not current page, would cause transclusion loop)
- fakes
- Like fake for entire series
- 1 2 3 4 5 6 7 8 9 …
- Title or name or name part of one template, any number
- prefix
- (optional) Will be prepended each name part
- list
- (optional)
1
– Link each entry; as bulleted list
- failsafe
- Version ID (local):
2022-05-16
- Optional parameter:
1
– Minimum version orwikidata
or~
{{#invoke:TemplUtl|failsafe}}
yields2022-05-16
- With a parameter as ISO date it is compared whether the current module satisfies this version or later.
{{#invoke:TemplUtl|failsafe|2001-01-01}}
returns: »2022-05-16
«{{#invoke:TemplUtl|failsafe|2099-01-01}}
returns: »« – (empty), if minimal version condition not matched
- If keyword is
wikidata
, result is version ID registered on Wikidata (2022-05-16
) or local if not found there. - If keyword is
~
, result is empty if local and Wikidata version are the same: ().
- Returns:
- Empty, if minimal version condition not matched, or
~
and local version is synchronized. - Version ID if no parameter, or if
wikidata
, or local if not found there, or not synchronized.
- Empty, if minimal version condition not matched, or
Examples (test page)
[Am Gwëntext werkeln]A test page illustrates practical use.
Functions for Lua modules (API)
[Am Gwëntext werkeln]All functions described above can be used by other modules:
local lucky, TemplUtl = pcall( require, "Module:TemplUtl" )
if type( TemplUtl ) == "table" then
TemplUtl = TemplUtl.TemplUtl()
else
-- error case; TemplUtl contains error message
return "<span class=\"error\">" .. TemplUtl .. "</span>"
end
Subsequently there are available:
- TemplUtl.faculty( analyze, another, frame )
-
- analyze – string, number, boolean, nil; what is to be analysed
- another – (optional) string, number, boolean; fallback if analyze not recognized
- frame – (optional) object; if ready to hand
- Returns:
true
, if “yes”, elsefalse
- Numbers other than
0
are “yes”. - TemplUtl.fake( access )
-
- access – (optional) string, boolean, nil; name of template
- TemplUtl.fakes( array, frame, ahead, answer )
-
- array – table; with template title strings at numerical elements
- frame – (optional) object; if available
- ahead – (optional) string, nil; prepended begin if title
- answer – (optional) true, nil; create bulleted list of links
- Returns: string, if answer
- TemplUtl.failure( alert, always )
-
- analyze – string; error message
- always – (optional) boolean; visibility of error message on presentation
- Returns: string, even empty
- TemplUtl.feasible( address )
- Does this describe an URL beginning?
- address – string; what to inspect, URL presumed
- Returns:
true
, if URL beginning (even protocol relative). - TemplUtl.feed( area, ahead, at, after )
- Detect next free
|
oder}}
.- area – string; what is to be searched
- Should contain template transclusion only, to avoid outer matches.
- ahead – string; opening element, or
false
- One of
[ [[ {{ {{{
orfalse
- One of
- at – number; byte position in area, where to start
- after –
true
, if only to search for}}
- Note: For the transclusion begin found by .find() the adjacent termination can be retrieved, or when
{{
is provided for ahead.
- area – string; what is to be searched
- Returns two values:
- number; byte position in area
- before
|
or}}
– may be at end of area. - position to continue search; ahead has been closed.
- before
true
, if search to be continued at number.
- number; byte position in area
- TemplUtl.feeder( area, at )
- Retrieve all parameters of a template transclusion.
- area – string; what is to be searched
- at – (optional) number; byte position in area, byte position in area, where to start
- Returns two values:
- table; parameter value assignments
- [0] – template, page, parser function name
- [1] … – unnamed parameters
- ["name"] … – named parameters
- string; error message, if any, else
nil
- table; parameter value assignments
- HTML comments won’t be returned.
- TemplUtl.fetch( area, ask )
- Find assignment of a named template parameter.
- area – string; what is to be searched
- Should contain template transclusion only, to avoid outer matches.
- ask – string; name of parameter
- area – string; what is to be searched
- Returns: string, with trimmed parameter value, or
nil
. - TemplUtl.find( area, access, at, alter )
- Find next occurrence of a template.
- area – string; what is to be searched
- access – string; trimmed (template) title
- at – (optional) number; ustring position in area, if not
1
- alter – (optional) string; lowercase namespace pattern, no colon (
:
)""
for article (main spave)false
for template
- Returns: number, ustring position of
{{
in area, orfalse
. - TemplUtl.flat( area )
- Remove syntax elements that hide effective syntax only (HTML comments,
nowiki pre syntaxhighlight
).- area – string; what is to be searched
- Returns: string, with area reduced by masking text syntax.
- TemplUtl.failsafe( atleast )
- Versioning interface
- atleast
optional
nil or minimum version orwikidata
or~
for synchronisation
- atleast
- returns: Version ID as string or
false
Usage
[Am Gwëntext werkeln]General library; no limitations.
Dependencies
[Am Gwëntext werkeln]No modules.
Installation on other WMF projects
[Am Gwëntext werkeln]Follow the steps:
- Copy main module
Module:TemplUtl
into your project.- If possible keep the name
TemplUtl
. - If another name is required due to conflict or naming convention or non-latin script then choose a different one.
- If possible keep the name
- Register this module at d:Q52364930.
- Check whether your language is covered by: commons:Data:I18n/01.tab
- Ready.
- Consider translation of doc page.