local TemplateData = --[==[ improve template:TemplateData ]
local Config = local Data = local Permit = ") then r = k else i, k = Data.source:find(seek, k) end end -- while i return rend -- 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 r1 = values if type(elements.scroll)
"string" then local s = type(elements.maxcolumns) r2 = r2 or r2["column-width"] = elements.minwidth if s
"number" then s = tostring(elements.maxcolumns) r2["column-count"] = s end if type(Config.selMultClm)
"string" then local src = Config.stylesMultClm .. "/styles.css" r4 = TemplateData.frame :extensionTag("templatestyles", nil,) end end elseif elements and elements ~= "" then r1 = elements end elseif s
"number" then r1 = table.insert(r1,) end return r1, r2, r3, r4end -- facilities
local function factory(adapt) -- Retrieve localized text from system message -- Parameter: -- adapt -- string, message ID after "templatedata-" -- Returns string, with localized text local o = mw.message.new("templatedata-" .. adapt) if Foreign then o:inLanguage(Data.slang) end return o:plainend -- factory
local function faculty(adjust) -- Test template arg for boolean -- adjust -- string or nil -- Returns boolean local s = type(adjust) local r if s
"boolean" then r = adjust else r = false end return rend -- faculty
local function failures -- Retrieve error collection and category -- Returns string local r if Data.scream then local e = mw.html.create("span") :addClass("error") :wikitext(Data.scream) r = tostring(e) mw.addWarning("TemplateData
" .. Data.scream) if Config.strange then r = string.format("%s", r, Config.strange) end else r = "" end return rend -- failures
local function fair(adjust) -- Reduce text to one line of plain text, or noexport wikitext blocks -- adjust -- string -- Returns string, with adjusted text local f = function (a) return a:gsub("%s*\n%s*", " ") :gsub("%s%s+", " ") end local tags = local r = adjust local i, j, k, s, tag for m = 1, 2 do tag = tags[m ] if r:find(tag.start, 1, true) then s = r r = "" i = 1 tag.l = true j, k = s:find(tag.start, i, true) while j do if j > 1 then r = r .. f(s:sub(i, j - 1)) end i = k + 1 j, k = s:find(tag.stop, i, true) if j then if m
1 then r = f(r) end end -- for m if tags[2 ].l then r = r:gsub("
local function fancy(advance, alert) -- Present JSON source -- Parameter: -- advance -- true, for nice -- alert -- true, for visible -- Returns string local r if Data.source then local support = Config.jsonDebug local css if advance then css = r = if alert then r.class(support) end r = TemplateData.frame:callParserFunction("#tag", r) else css = if alert then css.resize = "vertical" else css.display = "none" end r = mw.html.create("pre") :addClass(support) :css(css) :wikitext(mw.text.encode(Data.source)) r = tostring(r) end r = "\n".. r else r = "" end return rend -- fancy
local function faraway(alternatives) -- Retrieve best language version from multilingual text -- Parameter: -- alternatives -- table, to be evaluated -- Returns -- 1 -- string, with best match -- 2 -- table of other versions, if any local n = 0 local variants = local r1, r2 for k, v in pairs(alternatives) do if type(v)
"string" then k = k:lower variants[k ] = v n = n + 1 end end end -- for k, v if n > 0 then local Multilingual = Fetch("Multilingual", true) if Multilingual and type(Multilingual.i18n)
1 then r1 = v elseif Data.slang
lang=%s
", "Invalid", k)) end end -- for k, v end end return r1, r2end -- farawaylocal function fashioned(about, asked, assign) -- Create description head -- Parameter: -- about -- table, supposed to contain description -- asked -- true, if mandatory description -- assign --
local function fatten(access) -- Create table row for sub-headline -- Parameter: -- access -- string, with name -- Returns
"string" then td:cssText(param.style) end end s = fashioned(param, false, headline) if s then headline = s else headline:wikitext(sort) end td:node(headline) r:node(td) return rend -- fatten
local function fathers -- Merge params with inherited values local n = 0 local p = Data.params local t = Data.tree.params local p2, t2 for k, v in pairs(Data.heirs) do n = n + 1 end -- for k, v for i = 1, n do if Data.heirs then for k, v in pairs(Data.heirs) do if v and not Data.heirs[v ] then n = n - 1 t[k ].inherits = nil Data.heirs[k ] = nil p2 = t2 = if p[v ] then for k2, v2 in pairs(p[v ]) do p2[k2 ] = v2 end -- for k2, v2 if p[k ] then for k2, v2 in pairs(p[k ]) do if type(v2) ~= "nil" then p2[k2 ] = v2 end end -- for k2, v2 end p[k ] = p2 for k2, v2 in pairs(t[v ]) do t2[k2 ] = v2 end -- for k2, v2 for k2, v2 in pairs(t[k ]) do if type(v2) ~= "nil" then t2[k2 ] = v2 end end -- for k2, v2 t[k ] = t2 else Fault("No params[] inherits " .. v) end end end -- for k, v end end -- i = 1, n if n > 0 then local s -- The following could be made more efficient by iterating through Data.heirs *backwards*, -- and breaking as soon as a match is found for k, v in pairs(Data.heirs) do if v then if s then s = string.format("%s | %s", s, k) else s = "Circular inherits: " .. k end end end -- for k, v Fault(s) endend -- fathers
local function favorize -- Local customization issues local boole = local l, cx = pcall(mw.loadData, TemplateData.frame:getTitle .. "/config") local scripting, style TemplateData.ltr = not mw.language.getContentLanguage:isRTL if TemplateData.ltr then scripting = "left" else scripting = "right" end boole["margin-" .. scripting ] = "3em" Permit.boole = Permit.css = for k, v in pairs(Permit.colors) do if k
"fg" then style = "color" else style = "background-color" end Permit.css[k ] = Permit.css[k ][style ] = "#" .. v end -- for k, v if type(cx)
"table" then if type(cx.permit.boole)
"table" then Permit.boole[false ] = cx.permit.boole[false ] end if type(cx.permit.boole[true ])
"table" then for k, v in pairs(cx.permit.css) do if type(v)
"string" or s
local function feasible(all, at, about) -- Deal with suggestedvalues within parameter -- Parameter: -- all -- parameter details -- .default -- .type -- 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 -- 1: mw.html object
"string" then s = mw.text.trim(e.code) if s
"string" then s = mw.text.trim(e) if s
"number" then 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 else Fault(string.format("params.%s.suggestedvalues %s", at, "NOT AN ARRAY")) end if v then local code, d, k, less, story, swift, t, u r1 = mw.html.create("ul") r2 = for i = 1, #v do u = mw.html.create("li") e = v[i ] table.insert(r2, e.code) story = false less = (e.less
"string" then support = e.support elseif s
"" then scream = "EMPTY" elseif s:find("[%[%]|%<%>]") then scream = "BAD PAGE" else support = s end end if scream then s = string.format("params.%s.%s[%d].support %s", at, "suggestedvalues", i, scream) Fault(s) else swift = string.format("%s", support, swift) end end if all.type:sub(1, 5)
e.code then local rooms = local ns = rooms[all.type:sub(6, 9) ] or 0 t = mw.title.makeTitle(ns, swift) if t and t.exists then swift = string.format("%s", t.prefixedText, swift) end end if e.code
"string" then u:addClass(e.class) elseif s
"table" then u:css(e.css) else s = string.format("params.%s.%s[%d].css INVALID", at, "suggestedvalues", i) Fault(s) end end if e.style then if type(e.style)
"wiki-file-name" and not e.icon then e.icon = e.code end if e.label then s = type(e.label) if s
"" then s = string.format("params.%s.%s[%d].label %s", at, "suggestedvalues", i, "EMPTY") Fault(s) else story = s end elseif s
"string" then t = mw.title.makeTitle(6, e.icon) if t and t.file.exists then local g = mw.html.create("span") s = string.format("16px", t.prefixedText) g:attr("role", "presentation") :wikitext(s) s = tostring(g) end end if not s and not less and e.label then s = mw.ustring.char(0x2013) end if s then d = mw.html.create("span") :wikitext(s) if TemplateData.ltr then if not less then d:css("margin-left", "0.5em") end if story then d:css("margin-right", "0.5em") end else if not less then d:css("margin-right", "0.5em") end if story then d:css("margin-left", "0.5em") end end u:node(d) end if story then u:wikitext(story) end r1:newline :node(u) end -- for i end if not r1 and v ~= false then Fault(string.format("params.%s.suggestedvalues INVALID", at)) r1 = mw.html.create("code") :addClass("error") :wikitext("INVALID") end return r1, r2end -- feasible
local function feat -- Check and store parameter sequence if Data.source then local i = 0 local s for k, v in pairs(Data.tree.params) do if i
"table" then if type(v.label)
"" then s = k end else s = k end if given[s ] then if given[s ]
local function feature(access) -- Create table row for parameter, check and display violations -- Parameter: -- access -- string, with name -- Returns
for k, v in pairs(param) do if v
-- label sort = param.label or access if sort:match("^%d+$") then begin:attr("data-sort-value", string.format("%05d", tonumber(sort))) end begin:css("font-weight", "bold") :wikitext(sort)
-- name and aliases code:css("font-size", "92%") :css("white-space", "nowrap") :wikitext(access) if not fine(access) then code:addClass("error") Fault(string.format("Bad ID params.%s
", access)) legal = false begin:attr("data-sort-value", " " .. sort) end code = mw.html.create("td") :addClass(styles .. "name") :node(code) if access:match("^%d+$") then code:attr("data-sort-value", string.format("%05d", tonumber(access))) end if type(param.aliases)
"string" then if not fine(v) then lapsus = true code:node(mw.html.create("span") :addClass("error") :css("font-style", "italic") :wikitext("string")) :wikitext(s) else syn = mw.html.create("span") :addClass(styles .. "alias") :css("white-space", "nowrap") :wikitext(s) code:node(syn) end else lapsus = true code:node(mw.html.create("code") :addClass("error") :wikitext(type(v))) end end -- for k, v if lapsus then s = string.format("params.%s
.aliases", access) Fault(factory("invalid-value"):gsub("$1", s)) legal = false end end
-- description etc. s = fashioned(param) if s then desc:node(s) end if param.style then s = type(param.style) if s
"string" then desc:cssText(param.style) end end if param.suggestedvalues or param.default or param.example or param.autovalue then local details = local dl = mw.html.create("dl") local dd, section, show for i = 1, #details do s = details[i ] show = param[s ] if show then dd = mw.html.create("dd") section = factory("doc-param-" .. s) if param.type
"0" or show
true then dd:node(mw.html.create("code") :wikitext(show)) :wikitext(" ") end if type(boole.show)
"string" then dd:wikitext(boole.suffix) end if boole.lead
"suggestedvalues" then 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 dd:wikitext(show) end dl:node(mw.html.create("dt") :wikitext(section)) :node(dd) end end -- i = 1, #details desc:node(dl) end
-- type if type(param.type)
"" then param.type = false end end if param.type then s = Permit.types[param.type ] typed = mw.html.create("td") :addClass(styles .. "type") if s then if s
%s
.type", access) Fault(factory("invalid-value"):gsub("$1", s)) legal = false end else typed = mw.html.create("td") :wikitext(factory("doc-param-type-unknown")) Data.params[access ].type = "unknown" if param.default then Data.params[access ].default = nil Fault("Default value requires type
") legal = false end end typed:addClass("navigation-not-searchable") -- status if param.required then mode = 1 if param.autovalue then Fault(string.format("autovalued %s
required", access)) legal = false end if param.default then Fault(string.format("Defaulted %s
required", access)) legal = false end if param.deprecated then Fault(string.format("Required deprecated %s
", access)) legal = false end elseif param.deprecated then mode = 4 elseif param.suggested then mode = 2 else mode = 3 end status = ranking[mode ] ranking = factory("doc-param-status-" .. status) if mode1 or mode
"string" then ranking:tag("br") ranking:wikitext(param.deprecated) end if param.suggested and mode
%s
", access) Fault(s) legal = false end end eager:attr("data-sort-value", tostring(mode)) :node(ranking) :addClass(string.format("%sstatus-%s %s", styles, status, "navigation-not-searchable"))--
local function features -- Create