Module:Taxobox
Appearance
local p = {}
local infobox = require("Module:Infobox")
local infoboxImage = require("Module:InfoboxImage")
local arguments = require("Module:Arguments")
local ifPreview = require("Module:If preview")
local colors = {
animalia = "ebebd2",
archaea = "c3f5fa",
archaeplastida = "b4fab4",
bacteria = "dcebf5",
eukaryota = "f5d7ff",
fungi = "91fafa",
ichnotaxa = "e6ded6",
["incertae sedis"] = "faf0e6",
SAR = "c8fa50",
ootaxa = "fafadc",
virus = "fafabe",
}
local colorAlts = {
nanoarchaeota = "archaea",
nanarchaeota = "archaea",
korarchaeota = "archaea",
thaumarchaeota = "archaea",
crenarchaeota = "archaea",
euryarchaeota = "archaea",
plantae = "archaeplastida",
viridiplantae = "archaeplastida",
excavata = "eukaryota",
amoebozoa = "eukaryota",
Opisthokonta = "eukaryota",
chromalveolata = "SAR",
viroids = "viruses",
}
-- Gets the background color as a hex code, if possible
local function getColor(args)
if args.color_as or args.colour_as then
return args.color_as or args.colour_as
end
if args.regnum then
local f = mw.ustring.gsub(mw.ustring.lower(args.regnum), "[\]\[]", "") -- catches potential [[ ]] around the input parameter
return colors[colorAlts[f] or f]
end
end
local classification = {
{ arg_name = "superdomain", label = "Superdomain" },
{ arg_name = "domain", label = "Domain" },
{ arg_name = "superregnum", label = "Superkingdom" },
{ arg_name = "regnum", label = "Kingdom" },
{ arg_name = "subregnum", label = "Subkingdom" },
{ arg_name = "superdivisio", label = "Superdivision" },
{ arg_name = "superphylum", label = "Superphylum" },
{ arg_name = "divisio", label = "Division" },
{ arg_name = "phylum", label = "Phylum" },
{ arg_name = "subdivisio", label = "Subdivision" },
{ arg_name = "subphylum", label = "Subphylum" },
{ arg_name = "infraphylum", label = "Infraphylum" },
{ arg_name = "microphylum", label = "Microphylum" },
{ arg_name = "nanophylum", label = "Nanophylum" },
{ arg_name = "superclassis", label = "Superclass" },
{ arg_name = "classis", label = "Class" },
{ arg_name = "subclassis", label = "Subclass" },
{ arg_name = "infraclassis", "Infraclass" },
{ arg_name = "magnordo", label = "Magnorder" },
{ arg_name = "superordo", label = "Superorder" },
{ arg_name = "ordo", label = "Order" },
{ arg_name = "subordo", label = "Suborder" },
{ arg_name = "infraordo", label = "Infraorder" },
{ arg_name = "parvordo", label = "Parvorder" },
{ arg_name = "zoodivisio", label = "Division" },
{ arg_name = "zoosectio", label = "Section" },
{ arg_name = "zoosubsectio", label = "Subsection" },
{ arg_name = "superfamilia", label = "Superfamily" },
{ arg_name = "familia", label = "Family" },
{ arg_name = "subfamilia", label = "Subfamily" },
{ arg_name = "supertribus", label = "Supertribe" },
{ arg_name = "tribus", label = "Tribe" },
{ arg_name = "subtribus", label = "Subtribe" },
{ arg_name = "alliance", label = "''Alliance''" },
{ arg_name = "genus", label = "Genus" },
{ arg_name = "subgenus", label = "Subgenus" },
{ arg_name = "sectio", label = "Section" },
{ arg_name = "subsectio", label = "Subsection" },
{ arg_name = "series", label = "Series" },
{ arg_name = "subseries", label = "Subseries" },
{ arg_name = "species_group", label = "''Species group''" },
{ arg_name = "species_subgroup", label = "''Species subgroup''" },
{ arg_name = "species_complex", label = "''Species complex''" },
{ arg_name = "species", label = "Species" },
{ arg_name = "subspecies", label = "Subspecies" },
{ arg_name = "variety", label = "Variety" }, -- no unranked
{ arg_name = "forma", label = "Form" }, -- no unranked
}
function p.main(frame)
local args = arguments.getArgs(frame)
return p._main(args)
end
local conservation_data = {
["secure"] = ""
}
local function authority_help(args, type)
if args[type] and not args[type .. "_authority"] then
return args[type]
end
if args[type] and args[type .. "_authority"] then
return args[type] .. " (" .. args[type .. "_authority"] .. ")"
end
end
function p._main(args)
local warnings = {}
-- Safely replace spaces in parameters with underscores, removing the original parameter and sending a warning
for k, _ in pairs(args) do
if mw.ustring.find(k, " ") then
local k1 = mw.ustring.gsub(s, " ", "_")
if not args[k1] then
table.insert(warnings, "deprecated parameter \"" .. k .. "\". Please use \"" .. k1 .. "\" instead.")
args[k1] = args[k] -- copy value
args[k] = nil -- empty
else
table.insert(warnings, "found \"" .. k .. "\" and \"" .. k1 .. "\". Using \"" .. k1 .. "\" instead.")
end
end
end
local passing = {}
if args.name then
passing.above = args.name
elseif args.genus or args.species or args.binomial then
local title = mw.title.getCurrentTitle()
local g = mw.ustring.gsub(args.genus or args.species or args.binomial, "'", "")
if title == g or "<abbr title=\"Extinct\" aria-label=\"Extinct\" style=\"border: none; text-decoration: none; cursor: inherit; font-weight: normal; font-style: normal;\">†</abbr>" .. title == g or "†" .. title == g then
passing.above = "''" .. g .. "''"
-- TODO: add {{Italic title}}
end
else
passing.above = mw.title.getCurrentTitle()
end
passing.above = args.name or mw.title.getCurrentTitle()
if args.fossil_range then
passing.subheader = "Temporal range: " .. args.fossil_range
end
local color = getColor(args)
if color then
passing.abovestyle = "background-color: #" .. color
passing.subheaderstyle = "background-color: #" .. color
passing.headerstyle = "background-color: #" .. color
end
if args.image then
passing.image = infoboxImage.InfoboxImage({args = {image = args.image, upright = args.upright or args.image_upright, alt = args.alt or args.image_alt}})
passing.caption = args.caption or args.image_caption
end
if args.image2 then
passing.image2 = infoboxImage.InfoboxImage({args = {image = args.image2, upright = args.upright2 or args.image2_upright, alt = args.alt2 or args.image2_alt}})
passing.caption2 = args.caption2 or args.image2_caption
end
if args.status and args.status_system then
passing.header1 = "[[Conservation status]]"
passing.data2 = "status image goes here"
passing.data3 = args.status .. " (" .. args.status_system .. ")" .. (args.status_ref or "")
end
if args.status and not args.status_system then
table.insert(warnings, "using \"status\" without \"status_system\".")
end
if args.status2 and args.status2_system then
passing.data4 = "other status image goes here"
passing.data5 = args.status2 .. " (" .. args.status_system .. ")" .. (args.status2_ref or "")
end
if args.status2 and not args.status2_system then
table.insert(warnings, "using \"status2\" without \"status2_system\".")
end
passing.header6 = "[[Scientific classification]]"
local i = 7
for _, t in ipairs(classification) do
local k = t.arg_name
local v = t.label
if args["unranked_" .. k] then
passing["label" .. i] = "(unranked)"
passing["data" .. i] = authority_help(args, "unranked_" .. k)
i = i + 1
end
if args[k] then
passing["label" .. i] = v
passing["data" .. i] = authority_help(args, k)
i = i + 1
end
end
if args.binomial then
passing["header" .. i] = "[[Binomial name]]"
passing["data" .. i + 1] = authority_help(args, "binomial")
i = i + 2
end
if args.trinomial then
passing["header" .. i] = "[[Trinomial name]]"
passing["data" .. i + 1] = authority_help(args, "trinomial")
i = i + 2
end
if args.type_genus then
passing["header" .. i] = "[[Type genus]]"
passing["data" .. i + 1] = authority_help(args, "type_genus")
i = i + 2
end
if args.type_species then
passing["header" .. i] = "[[Type species]]"
passing["data" .. i + 1] = authority_help(args, "type_species")
i = i + 2
end
if args.type_strain then
passing["header" .. i] = "[[Type strain]]"
passing["data" .. i] = authority_help(args, "type_strain")
i = i + 2
end
local out = infobox.infobox(passing)
table.insert(warnings, "Help!")
for _, warning in ipairs(warnings) do
local w = ifPreview._warning({warning})
if w and not w == '' then
out = out .. w
end
end
return out
end
return p