Modul:TemplateData: Unterschied zwischen den Versionen
2023-01-07
K (1 Version von w:Modul:TemplateData importiert) |
(2023-01-07) |
||
| Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = " | serial = "2023-01-07", | ||
item = 46997995 } | item = 46997995 } | ||
--[==[ | --[==[ | ||
| Zeile 11: | Zeile 11: | ||
local Config = { | local Config = { | ||
-- multiple option names mapped into unique internal fields | -- multiple option names mapped into unique internal fields | ||
basicCnf = { catProblem | basicCnf = { catProblem = "strange", | ||
classNoNumTOC = "suppressTOCnum", | classMultiColumns = "selMultClm", | ||
classTable | classNoNumTOC = "suppressTOCnum", | ||
cssParWrap | classTable = "classTable", | ||
cssParams | cssParWrap = "cssTabWrap", | ||
docpageCreate = "suffix", | cssParams = "cssTable", | ||
docpageDetect = "subpage", | docpageCreate = "suffix", | ||
helpBoolean | docpageDetect = "subpage", | ||
helpContent | helpAliases = "supportAliases", | ||
helpDate | helpBoolean = "support4boolean", | ||
helpFile | helpContent = "support4content", | ||
helpFormat | helpDate = "support4date", | ||
helpLine | helpFile = "support4wiki-file-name", | ||
helpNumber | helpFormat = "supportFormat", | ||
helpPage | helpLine = "support4line", | ||
helpString | helpNumber = "support4number", | ||
helpTemplate | helpPage = "support4wiki-page-name", | ||
helpURL | helpString = "support4string", | ||
helpUser | helpTemplate = "support4wiki-template-name", | ||
msgDescMiss | helpURL = "support4url", | ||
tStylesTOCnum = "stylesTOCnum" }, | helpUser = "support4wiki-user-name", | ||
msgDescMiss = "solo", | |||
tStylesMultiColumns = "stylesMultClm", | |||
tStylesTOCnum = "stylesTOCnum" }, | |||
classTable = { "wikitable" }, -- classes for params table | classTable = { "wikitable" }, -- classes for params table | ||
debugmultilang = "C0C0C0", | debugmultilang = "C0C0C0", | ||
| Zeile 68: | Zeile 71: | ||
} | } | ||
local Permit = { | local Permit = { | ||
builder = { after | builder = { after = "block", | ||
align | align = "block", | ||
block | block = "block", | ||
compressed | compressed = "block", | ||
dense | dense = "block", | ||
grouped | grouped = "inline", | ||
half | half = "inline", | ||
indent | indent = "block", | ||
inline | inline = "inline", | ||
last | last = "block", | ||
lead | lead = "block", | ||
newlines | newlines = "*", | ||
spaced | spaced = "inline" }, | ||
colors = { tableheadbg = "B3B7FF", | colors = { bg = "FFFFFF", | ||
fg = "000000", | |||
tableheadbg = "B3B7FF", | |||
required = "EAF3FF", | required = "EAF3FF", | ||
suggested = "FFFFFF", | suggested = "FFFFFF", | ||
| Zeile 97: | Zeile 102: | ||
style = "string table", | style = "string table", | ||
suggested = "boolean", | suggested = "boolean", | ||
suggestedvalues = "string table number", | suggestedvalues = "string table number boolean", | ||
type = "string" }, | type = "string" }, | ||
root = { description = "string table I18N", | root = { description = "string table I18N", | ||
| Zeile 239: | Zeile 244: | ||
return r | return r | ||
end -- facet() | end -- facet() | ||
local function facilities( apply ) | |||
-- Retrieve details of suggestedvalues | |||
-- Parameter: | |||
-- apply -- table, with plain or enhanced values | |||
-- .suggestedvalues -- table|string|number, or more | |||
-- Returns | |||
-- 1 -- table, with suggestedvalues | |||
-- 2 -- table, with CSS map, or not | |||
-- 3 -- string, with class, or not | |||
-- 4 -- string, with templatestyles, or not | |||
local elements = apply.suggestedvalues | |||
local s = type( elements ) | |||
local r1, r2, r3, r4 | |||
if s == "table" then | |||
local values = elements.values | |||
if type( values ) == "table" then | |||
r1 = values | |||
if type( elements.scroll ) == "string" then | |||
r2 = r2 or { } | |||
r2.height = apply.scroll | |||
r2.overflow = "auto" | |||
end | |||
if type( elements.minwidth ) == "string" then | |||
local s = type( elements.maxcolumns ) | |||
r2 = r2 or { } | |||
r2["column-width"] = elements.minwidth | |||
if s == "string" or | |||
s == "number" then | |||
s = tostring( elements.maxcolumns ) | |||
r2["column-count"] = s | |||
end | |||
if type( Config.selMultClm ) == "string" then | |||
r3 = Config.selMultClm | |||
end | |||
mw.log("facilities()",Config.stylesMultClm) | |||
if type( Config.stylesMultClm ) == "string" then | |||
local src = Config.stylesMultClm .. "/styles.css" | |||
r4 = TemplateData.frame | |||
:extensionTag( "templatestyles", | |||
nil, | |||
{ src = src } ) | |||
mw.log(r4) | |||
end | |||
end | |||
elseif elements and elements ~= "" then | |||
r1 = elements | |||
end | |||
elseif s == "string" then | |||
s = mw.text.trim( about ) | |||
if s ~= "" then | |||
r1 = { } | |||
table.insert( r1, | |||
{ code = s } ) | |||
end | |||
elseif s == "number" then | |||
r1 = { } | |||
table.insert( r1, | |||
{ code = tostring( elements ) } ) | |||
end | |||
return r1, r2, r3, r4 | |||
end -- facilities() | |||
| Zeile 609: | Zeile 678: | ||
local l, cx = pcall( mw.loadData, | local l, cx = pcall( mw.loadData, | ||
TemplateData.frame:getTitle() .. "/config" ) | TemplateData.frame:getTitle() .. "/config" ) | ||
local scripting | local scripting, style | ||
TemplateData.ltr = not mw.language.getContentLanguage():isRTL() | TemplateData.ltr = not mw.language.getContentLanguage():isRTL() | ||
if TemplateData.ltr then | if TemplateData.ltr then | ||
| Zeile 628: | Zeile 697: | ||
k = "tablehead" | k = "tablehead" | ||
end | end | ||
Permit.css[ k ] = { [ | if k == "fg" then | ||
style = "color" | |||
else | |||
style = "background-color" | |||
end | |||
Permit.css[ k ] = { } | |||
Permit.css[ k ][ style ] = "#" .. v | |||
end -- for k, v | end -- for k, v | ||
if type( cx ) == "table" then | if type( cx ) == "table" then | ||
| Zeile 651: | Zeile 726: | ||
for k, v in pairs( Config.basicCnf ) do | for k, v in pairs( Config.basicCnf ) do | ||
s = type( cx[ k ] ) | s = type( cx[ k ] ) | ||
mw.log(k, v,s ) | |||
if s == "string" or s == "table" then | if s == "string" or s == "table" then | ||
Config[ v ] = cx[ k ] | Config[ v ] = cx[ k ] | ||
| Zeile 676: | Zeile 752: | ||
local function feasible( | local function feasible( all, at, about ) | ||
-- Deal with suggestedvalues within parameter | -- Deal with suggestedvalues within parameter | ||
-- Parameter: | -- Parameter: | ||
-- | -- all -- parameter details | ||
-- . | -- .default | ||
-- .type | -- .type | ||
-- at -- string, with parameter name | -- at -- string, with parameter name | ||
-- about -- suggestedvalues -- table, | |||
-- value and possibly description | |||
-- table may have elements: | |||
-- .code -- mandatory | |||
-- .label -- table|string | |||
-- .support -- table|string | |||
-- .icon -- string | |||
-- .class -- table|string | |||
-- .css -- table | |||
-- .style -- string | |||
-- .less -- true: suppress code | |||
-- Returns | -- Returns | ||
-- 1: mw.html object | -- 1: mw.html object <ul> | ||
-- 2: sequence table with values, or nil | -- 2: sequence table with values, or nil | ||
local | local h = { } | ||
local e, r1, r2, s, v | |||
local e, r1, r2, v | if #about > 0 then | ||
for i = 1, #about do | |||
e = about[ i ] | |||
s = type( e ) | |||
if s == "table" then | |||
if type( e.code ) == "string" then | |||
s = mw.text.trim( e.code ) | |||
if s == "" then | if s == "" then | ||
e = nil | e = nil | ||
else | else | ||
e | e.code = s | ||
end | end | ||
else | else | ||
s = string.format( "params.%s.%s[%d] | e = nil | ||
s = string.format( "params.%s.%s[%d] %s", | |||
at, | |||
"suggestedvalues", | |||
i, | |||
"MISSING 'code:'" ) | |||
end | |||
elseif s == "string" then | |||
s = mw.text.trim( e ) | |||
if s == "" then | |||
e = nil | |||
s = string.format( "params.%s.%s[%d] EMPTY", | |||
at, "suggestedvalues", i ) | at, "suggestedvalues", i ) | ||
Fault( s ) | Fault( s ) | ||
e = | else | ||
e = { code = s } | |||
end | end | ||
if e then | elseif s == "number" then | ||
e = { code = tostring( e ) } | |||
else | |||
s = string.format( "params.%s.%s[%d] INVALID", | |||
at, "suggestedvalues", i ) | |||
Fault( s ) | |||
e = false | |||
end | |||
if e then | |||
v = v or { } | |||
table.insert( v, e ) | |||
if h[ e.code ] then | |||
s = string.format( "params.%s.%s REPEATED %s", | |||
at, | |||
"suggestedvalues", | |||
e.code ) | |||
Fault( s ) | |||
else | |||
h[ e.code ] = true | |||
end | end | ||
end -- for i | end | ||
end -- for i | |||
else | |||
Fault( string.format( "params.%s.suggestedvalues %s", | |||
at, "NOT AN ARRAY" ) ) | |||
end | end | ||
if v then | if v then | ||
local d, less, story, swift, t, u | local code, d, k, less, story, swift, t, u | ||
r1 = mw.html.create( "ul" ) | r1 = mw.html.create( "ul" ) | ||
r2 = { } | r2 = { } | ||
| Zeile 801: | Zeile 875: | ||
end | end | ||
end | end | ||
if | if all.type:sub( 1, 5 ) == "wiki-" and | ||
swift == e.code then | swift == e.code then | ||
local rooms = { file = 6, | local rooms = { file = 6, | ||
temp = 10, | temp = 10, | ||
user = 2 } | user = 2 } | ||
local ns = rooms[ | local ns = rooms[ all.type:sub( 6, 9 ) ] or 0 | ||
t = mw.title.makeTitle( ns, swift ) | t = mw.title.makeTitle( ns, swift ) | ||
if t and t.exists then | if t and t.exists then | ||
| Zeile 813: | Zeile 887: | ||
end | end | ||
end | end | ||
if e.code == all.default then | |||
k = 800 | |||
else | |||
k = 300 | |||
end | |||
code = mw.html.create( "code" ) | |||
:css( "font-weight", tostring( k ) ) | |||
:css( "white-space", "nowrap" ) | |||
:wikitext( swift ) | |||
u:node( code ) | |||
end | end | ||
if e.class then | if e.class then | ||
| Zeile 849: | Zeile 930: | ||
end | end | ||
end | end | ||
if | if all.type == "wiki-file-name" and not e.icon then | ||
e.icon = e.code | e.icon = e.code | ||
end | end | ||
| Zeile 915: | Zeile 996: | ||
end -- for i | end -- for i | ||
end | end | ||
if not r1 then | if not r1 and v ~= false then | ||
Fault( string.format( "params.%s.suggestedvalues INVALID", at ) ) | Fault( string.format( "params.%s.suggestedvalues INVALID", at ) ) | ||
r1 = mw.html.create( "code" ) | r1 = mw.html.create( "code" ) | ||
| Zeile 1.060: | Zeile 1.141: | ||
:wikitext( s ) | :wikitext( s ) | ||
else | else | ||
if Config.supportAliases then | |||
s = string.format( "[[%s|%s]]", | |||
Config.supportAliases, | |||
mw.text.nowiki( s ) ) | |||
end | |||
syn = mw.html.create( "span" ) | syn = mw.html.create( "span" ) | ||
:addClass( styles .. "alias" ) | :addClass( styles .. "alias" ) | ||
| Zeile 1.135: | Zeile 1.221: | ||
end | end | ||
elseif s == "suggestedvalues" then | elseif s == "suggestedvalues" then | ||
local | local v, css, class, ts = facilities( param ) | ||
if v then | |||
local ul | |||
ul, v = feasible( param, access, v ) | |||
if v then | |||
dd:newline() | |||
:node( ul ) | |||
if css then | |||
dd:css( css ) | |||
if class then | |||
dd:addClass( class ) | |||
end | |||
if ts then | |||
dd:newline() | |||
dd:node( ts ) | |||
end | |||
end | |||
Data.params[ access ].suggestedvalues = v | |||
end | |||
end | |||
else | else | ||
dd:wikitext( show ) | dd:wikitext( show ) | ||
| Zeile 1.196: | Zeile 1.298: | ||
end | end | ||
end | end | ||
typed:addClass( "navigation-not-searchable" ) | |||
-- status | -- status | ||
if param.required then | if param.required then | ||
| Zeile 1.240: | Zeile 1.343: | ||
eager:attr( "data-sort-value", tostring( mode ) ) | eager:attr( "data-sort-value", tostring( mode ) ) | ||
:node( ranking ) | :node( ranking ) | ||
:addClass( string.format( "%sstatus-%s", | :addClass( string.format( "%sstatus-%s %s", | ||
styles, status ) ) | styles, status, | ||
"navigation-not-searchable" ) ) | |||
-- <tr> | -- <tr> | ||
| Zeile 1.280: | Zeile 1.384: | ||
tbl:css( Config.cssTable ) | tbl:css( Config.cssTable ) | ||
end | end | ||
tr:node( mw.html.create( "th" ) | tr:addClass( "navigation-not-searchable" ) | ||
:node( mw.html.create( "th" ) | |||
:attr( "colspan", "2" ) | :attr( "colspan", "2" ) | ||
:css( Permit.css.tablehead ) | :css( Permit.css.tablehead ) | ||
| Zeile 1.487: | Zeile 1.592: | ||
if r:find( "<", 1, true ) then | if r:find( "<", 1, true ) then | ||
local Text = Fetch( "Text" ) | local Text = Fetch( "Text" ) | ||
r = | r = r:gsub( "<br */?>", "\r\n" ) | ||
:gsub( "<sup>2</sup>", "²" ) | |||
:gsub( "<sup>3</sup>", "³" ) | |||
r = Text.getPlain( r ) | |||
end | end | ||
if r:find( "[", 1, true ) then | if r:find( "[", 1, true ) then | ||
| Zeile 1.903: | Zeile 2.011: | ||
end | end | ||
end | end | ||
toc:css( "margin-top", "0.5em" ) | toc:addClass( "navigation-not-searchable" ) | ||
:css( "margin-top", "0.5em" ) | |||
:wikitext( "__TOC__" ) | :wikitext( "__TOC__" ) | ||
if Data.sibling then | if Data.sibling then | ||
| Zeile 1.960: | Zeile 2.069: | ||
end | end | ||
r:node( mw.html.create( "p" ) | r:node( mw.html.create( "p" ) | ||
:addClass( "navigation-not-searchable" ) | |||
:wikitext( show .. ": " ) | :wikitext( show .. ": " ) | ||
:node( e ) ) | :node( e ) ) | ||
| Zeile 1.983: | Zeile 2.093: | ||
Data.div = mw.html.create( "div" ) | Data.div = mw.html.create( "div" ) | ||
:addClass( "mw-templatedata-doc-wrap" ) | :addClass( "mw-templatedata-doc-wrap" ) | ||
if Permit.css.bg then | |||
Data.div:css( Permit.css.bg ) | |||
end | |||
if Permit.css.fg then | |||
Data.div:css( Permit.css.fg ) | |||
end | |||
focus() | focus() | ||
if Data.tag then | if Data.tag then | ||
| Zeile 2.266: | Zeile 2.382: | ||
return TemplateData | return TemplateData | ||
end | end | ||
setmetatable( p, { __call = function ( func, ... ) | |||
setmetatable( p, nil ) | |||
return Failsafe | |||
end } ) | |||
return p | return p | ||