Wikipedia:Lua/Modul/TemplUtl/en
Wikipedia:Lua Modul TemplUtl en
| Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
| Modul | Deutsch | English
|
Modul: | Dokumentation | |||
TemplUtl – Library module with functions to support template programming.
Functions for templates
- facets
- Split into searchable word tokens (groups öf letters and digits in any scripting, separated by interpunction and special characters)
- Parameters:
- 1
- Text to be splitted
- decode
- (optional); default: HTML entity decoding
%– URL decoding
- Result: splitted string
- 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
- fair
- Decode string
- Parameters:
- 1
- Text
- decode
- (optional); default: HTML entity decoding
%– URL decoding
- Result: decoded string
- 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
- firstbreak
- If the first character of trimmed text is a list symbol
*#;:or table begin or termination then precede a newline - from
- Present the name of the transcluding (template) page as clickable link decorrated with curly brackets
- isRedirect
- Is the transclusion made within a redirect page
- nowiki
- Trim text and replace effective syntax by HTML entities
- Critical characters:
"&'<=>[]{|} - If the first character of trimmed text, also after line break, is a list symbol
*#;:then return it as an HTML entity. - Magic words:
//:,ISBN,PMID,RFC
- Critical characters:
- nowiki1
- If the first character of trimmed text is a list symbol
*#;:then return it as an HTML entity - failsafe
The Failsafe interface is heading for version management of globally distributed Lua modules. It enables modules equipped with this interface to
- ensure, that a library module required by a template or another module available as local copy does support certain functionality, or complain if not.
- administrate global updating and linking of module codes via Wikidata.
The Failsafe interface is present both at template level and for direct Lua access.
The functions in detail are (not all supported yet completely by every library):
| Value | Result | current |
|---|---|---|
nothingfalse
|
local version ID | »2026-07-01« |
| Minimal version | version ID required at least date in ISO format It will be compared whether the current local implementation matches this version or later.
|
|
wikidata
|
version ID of global upstream
|
»2026-04-28« |
item
|
ID of the Wikidata item
|
Q52364930
|
~
|
Corresponding version ID locally and registered at Wikidata
|
»2026-04-28« |
@
|
Is the current (module) page linked correctly with Wikidata item?
|
|
The return value is in template programming empty or under Lua false, otherwis a non-empty string as described.
| ||
Examples (test page)
A test page illustrates practical use.
Functions for Lua modules (API)
All functions described above can be used by other modules:
local lucky, TemplUtl = pcall( require, "Module:TemplUtl" )
if type( TemplUtl ) == "table" then
TemplUtl = TemplUtl()
else
-- error case; TemplUtl contains error message
return "<span class=\"error\">" .. TemplUtl .. "</span>"
end
Subsequently there are available:
- TemplUtl.facets( ask, adjust )
-
- ask – string to be splitted
- adjust – (optional)
%for URL decoding
- 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
0are “yes”. - TemplUtl.fair( ask, adjust )
-
- ask – string to be decoded
- adjust – (optional)
%for URL decoding
- 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)falsefor 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 orwikidataor~for synchronisation
- atleast
- returns: Version ID as string or
false
Usage
General library; no limitations.
Dependencies
No modules.
Installation on other WMF projects
Follow the steps:
- Copy main module
Module:TemplUtlinto 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.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.