Module:Storm categories/demo: Difference between revisions

Content deleted Content added
m top: Post-move cleanup, replaced: Tropical cyclone categories → Storm categories (4)
Switching to note-style legends
Line 16:
TableTools.removeDuplicates(customKeys)
 
function inlineWarningtableEmpty(details, icon_table)
for k, v in pairs(_table) do
return mw.html.create("span")
return false
:css("color", "darkred")
end
:wikitext("(")
return true
:node(
mw.html.create("span")
:attr("title", details)
:css("text-decoration", "underline")
:css("text-decoration-style", "dotted")
:wikitext(icon or "!")
)
:wikitext(")")
end
 
function p.demo(frame)
local outlegend = mw.html.createsetmetatable({}, { refgroupname = "table" })
local errors = setmetatable({}, { refgroupname = "E" })
local warnings = setmetatable({}, { refgroupname = "W" })
function buildReflist(_group)
group = _group or legend
return frame:expandTemplate{ title = 'reflist', args = {
group = getmetatable(group)["refgroupname"]
} }
end
function createLegend(details, _group)
hash = string.sub(mw.hash.hashValue("md5", details), 0, 8)
group = _group or legend
if group[hash] == nil then
group[hash] = frame:extensionTag{
-- <ref name="hash">details</ref>
name = 'ref',
content = mw.ustring.gsub(details, "%[%[File:([^%|]+)[^%]]*%]%]", "[[:File:%1]]"),
args = {
name = hash,
group = getmetatable(group)["refgroupname"]
}
}
end
-- <ref name="hash"/>
return frame:extensionTag{ name = 'ref', args = {
name = hash,
group = getmetatable(group)["refgroupname"]
} }
end
local categoryTable = mw.html.create("table")
:addClass("wikitable")
:addClass("sortable")
:attr("style", "width: 100%")
categoryTable
out
:node(
mw.html.create("tr")
Line 60 ⟶ 86:
:attr("data-sort-type", "number"))
)
local legends = {}
for name, cat in TableTools.sortedPairs(cats) do
Line 71 ⟶ 95:
:wikitext(actualIcon)
if cat["icon"] ~= nil and actualIcon ~= cat["icon"] then
icon:wikitext(
createLegend("Overriden from original icon (" .. cat["icon"] .. ")")
:wikitext(" ")
:node()
mw.html.create("span")
:css("text-decoration", "underline")
:css("text-decoration-style", "dotted")
:attr("title", "Overriden from original icon (" .. cat["icon"] .. ")")
:wikitext("*")
)
legends["*"] = "Overriden from original icon."
end
Line 92 ⟶ 109:
if actualColor ~= cat["color"] then
color:wikitext(createLegend(
"Overriden from original color ({{color box|#"
:node(
mw.html.create( cat["spancolor")]
.. "}} #"
:css("text-decoration", "underline")
.. cat["color"]
:css("text-decoration-style", "dotted")
.. ")"
:attr("title", "Overriden from original color (#" .. cat["color"] .. ")")
))
:wikitext("**")
)
legends["**"] = "Overriden from original color."
end
Line 108 ⟶ 123:
if catColorBlackRatio == "?" or catColorLinkRatio == "?" or catColorVisitedLinkRatio == "?" then
color:wikitext(
createLegend("This color must be a hexadecimal color.", errors)
:wikitext(" ")
)
:node(inlineWarning("This color must be a hexadecimal color.", "E"))
legends["E"] = "Not a valid hexadecimal color code."
else
if catColorBlackRatio < 4.5 then
color:wikitext(
createLegend("This color has [[MOS:COLOR|contrast issues]] with black (not WCAG 2.0 AA-compatible). It will be unusable on all infoboxes and storm season summaries.", errors)
:wikitext(" ")
)
:node(inlineWarning("This color has contrast issues with black (not WCAG 2.0 AA-compatible).", "C"))
legends["C"] = "Color has contrast issues with black."
end
if catColorLinkRatio < 4.5 then
color:wikitext(
createLegend("This color has [[MOS:COLOR|contrast issues]] with links (not WCAG 2.0 AA-compatible). It should not be used in conjunction with a link.", warnings)
:wikitext(" ")
)
:node(inlineWarning("This color has contrast issues with links (not WCAG 2.0 AA-compatible).", "L"))
legends["L"] = "Color has contrast issues with links (#0645ad)."
end
if catColorVisitedLinkRatio < 4.5 then
color:wikitext(
createLegend("This color has [[MOS:COLOR|contrast issues]] with visited links (not WCAG 2.0 AA-compatible with #0b0080). It should not be used in conjunction with a visited link.", warnings)
:wikitext(" ")
)
:node(inlineWarning("This color has contrast issues with visited links (not WCAG 2.0 AA-compatible).", "V"))
end
legends["V"] = "Color has contrast issues with visited links (#0b0080)."
if actualCat == "c0c0c0" and cat[sortkey] ~= 0 then
color:wikitext(
createLegend("This category is using a color reserved specifically for the \"unknown\" category.", warnings)
)
end
end
Line 205 ⟶ 221:
for _, _row in TableTools.sortedPairs(rows) do
outcategoryTable:node(_row)
end
end
Line 243 ⟶ 259:
:wikitext("''<span style=\"color:gray\">not available</span>''"))
end
outcategoryTable:node(row)
end
end
out = ""
local legendsCompiled = mw.html.create("ul")
if not tableEmpty(errors) then
local showLegend = false
out = out
legendsCompiled
.. tostring(mw.html.create("h4"):wikitext("Error"))
:css("list-style-icon", "none")
.. tostring(mw.html.create("p"):wikitext("This table contains errors than need to be addressed immediately, as it may cause errors on a large amount of pages."))
:css("list-style-type", "none")
.. buildReflist(errors)
for legend, details in TableTools.sortedPairs(legends) do
end
showLegend = true
if not tableEmpty(legend) then
legendsCompiled:node(
out = out
mw.html.create("li")
.. tostring(mw.html.create("h4"):wikitext("Legend"))
-- en dash
.. buildReflist(legend)
:wikitext("'''" .. legend .. "''' – " .. details)
end
)
out = out .. tostring(categoryTable)
if not tableEmpty(warnings) then
out = out
.. tostring(mw.html.create("h4"):wikitext("Warnings"))
.. tostring(mw.html.create("p"):wikitext("This table contains warnings than should be addressed. Please note that some warnings cannot be fully addressed without consensus on related WikiProjects."))
.. buildReflist(warnings)
end
return mw.text.trim(out)
return (showLegend and tostring(legendsCompiled) or "") .. tostring(out)
end