Jump to content

Module:Taxobox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SWinxy (talk | contribs) at 22:28, 23 August 2022 (Simplify color generation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local infobox = require("Module:Infobox")
local infoboxImage = require("Module:InfoboxImage")
local arguments = require("Module:Arguments")
local error = require("Module:Error")

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

local function getColor(args)
	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 = {
	["unranked_superdomain"] = "(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 passing = {}
	
	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 .. ")"
	end
	if args.status and not args.status_system then
		error.error({"Infobox:Taxobox: using \"status\" without \"status_system\""})
	end
	
	
	passing.header4 = "[[Scientific classification]]"
	
	return infobox.infobox(passing)
end

return p