Module:Format TemplateData explained

local TemplateData = --[==[ improve template:TemplateData ]

]local Failsafe = 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 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 if type(Config.stylesMultClm)

"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

"string" then s = mw.text.trim(about) if s ~= "" then r1 = table.insert(r1,) 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

"string" then r = mw.text.trim(adjust) r = (r ~= "" and r ~= "0") elseif 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 = r .. s:sub(i, j - 1) end i = k + 1 j, k = s:find(tag.start, i, true) else Fault("missing " .. tag.stop) end end -- while j r = r .. s:sub(i) elseif m

1 then r = f(r) end end -- for m if tags[2 ].l then r = r:gsub(".*", "") end return rend -- fair

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 v = mw.text.trim(v) if v ~= "" and type(k)

"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)

"function" then local show, slang = Multilingual.i18n(variants) if show then r1 = show variants[slang ] = nil r2 = variants end end if not r1 then Foreign for k, v in pairs(variants) do if n

1 then r1 = v elseif Data.slang

k then variants[k ] = nil r1 = v r2 = variants end end -- for k, v end if r2 and Multilingual then for k, v in pairs(r2) do if v and not Multilingual.isLang(k, true) then Fault(string.format("%s lang=%s", "Invalid", k)) end end -- for k, v end end return r1, r2end -- faraway

local function fashioned(about, asked, assign) -- Create description head -- Parameter: -- about -- table, supposed to contain description -- asked -- true, if mandatory description -- assign -- , if to be equipped -- Returns , with head, or nil local para = assign or mw.html.create("div") local plus, r if about and about.description then if type(about.description)

"string" then para:wikitext(about.description) else para:wikitext(about.description[1 ]) plus = mw.html.create("ul") plus:css("text-align", "left") for k, v in pairs(about.description[2 ]) do plus:node(mw.html.create("li") :node(mw.html.create("code") :wikitext(k)) :node(mw.html.create("br")) :wikitext(fair(v))) end -- for k, v if Config.loudly then plus = mw.html.create("div") :css("background-color", "#" .. Config.debugmultilang) :node(plus) else plus:addClass("templatedata-maintain") :css("display", "none") end end elseif Config.solo and asked then para:addClass("error") :wikitext(Config.solo) Data.less = true else para = false end if para then if plus then r = mw.html.create("div") :node(para) :node(plus) else r = para end end return rend -- fashioned

local function fatten(access) -- Create table row for sub-headline -- Parameter: -- access -- string, with name -- Returns local param = Data.tree.params[access ] local sub, sort = access:match("(=+)%s*(%S.*)$") local headline = mw.html.create(string.format("h%d", #sub)) local r = mw.html.create("tr") local td = mw.html.create("td") :attr("colspan", "5") :attr("data-sort-value", "!" .. sort) local s if param.style then s = type(param.style) if s

"table" then td:css(param.style) elseif s

"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 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

"tableheadbg" then k = "tablehead" end 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 local c, s if type(cx.permit)

"table" then if type(cx.permit.boole)

"table" then if type(cx.permit.boole[true ])

"table" then Permit.boole[false ] = cx.permit.boole[false ] end if type(cx.permit.boole[true ])

"table" then Permit.boole[true ] = cx.permit.boole[true ] end end if type(cx.permit.css)

"table" then for k, v in pairs(cx.permit.css) do if type(v)

"table" then Permit.css[k ] = v end end -- for k, v end end for k, v in pairs(Config.basicCnf) do s = type(cx[k ]) if s

"string" or s

"table" then Config[v ] = cx[k ] end end -- for k, v end if type(Config.subpage) ~= "string" or type(Config.suffix) ~= "string" then local got = mw.message.new("templatedata-doc-subpage") local suffix if got:isDisabled then suffix = "doc" else suffix = got:plain end if type(Config.subpage) ~= "string" then Config.subpage = string.format("/%s$", suffix) end if type(Config.suffix) ~= "string" then Config.suffix = string.format("%%s/%s", suffix) end endend -- favorize

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