Module:IUCN status
Appearance
local p = {}
-- Data table for colors, full names, standardized display, and wiki article links
local status_data = {
ex = { long = "Extinct", bg = "#000", fg = "#F66", display = "EX", link = "Extinction" },
ew = { long = "Extinct in the Wild", bg = "#000", fg = "#FFF", display = "EW", link = "Extinct in the wild" },
cr = { long = "Critically Endangered", bg = "#C33", fg = "#FEE", display = "CR", link = "Critically endangered" },
en = { long = "Endangered", bg = "#B40", fg = "#FED", display = "EN", link = "Endangered species" },
vu = { long = "Vulnerable", bg = "#937006", fg = "#FFE", display = "VU", link = "Vulnerable species" },
nt = { long = "Near Threatened", bg = "#073", fg = "#EFE", display = "NT", link = "Near-threatened species" },
lc = { long = "Least Concern", bg = "#066", fg = "#EFF", display = "LC", link = "Least-concern species" },
dd = { long = "Data Deficient", is_gray = true, display = "DD", link = "Data deficient" },
re = { long = "Regionally Extinct", bg = "#000", fg = "#FFF", display = "RE", link = "Regionally extinct" },
na = { long = "Not Applicable", is_gray = true, display = "NA", link = false },
ne = { long = "Not Evaluated", is_gray = true, display = "NE", link = "Not evaluated" },
-- Tags (PE and PEW should match CR)
pe = { long = "Critically Endangered (Possibly Extinct)", bg = "#C33", fg = "#FEE", display = "CR (PE)", link = "Critically endangered (possibly extinct)" },
pew = { long = "Critically Endangered (Possibly Extinct in the Wild)", bg = "#C33", fg = "#FEE", display = "CR (PEW)", link = "Critically endangered (possibly extinct in the wild)" },
-- Legacy categories
["lr/cd"] = { long = "Lower Risk/conservation dependent", bg = "#073", fg = "#EFE", display = "LR/cd", link = "Conservation-dependent species" }, -- should match NT
}
-- aliases
status_data["cr(pe)"] = status_data.pe
status_data["cr(pew)"] = status_data.pew
status_data["lr/nt"] = status_data.nt
status_data["lr/lc"] = status_data.lc
function p.main(frame)
local args = frame:getParent().args
local raw_input = mw.text.trim(args[1] or "")
local code = string.lower(raw_input):gsub("%s+", "")
local id = mw.text.trim(args[2] or "")
local option = mw.text.trim(args[3] or args.class or args.option or frame.args[3] or frame.args.class or frame.args.option or "")
local year = mw.text.trim(args.year or "")
local label = mw.text.trim(args.label or "")
local category = ""
local data = status_data[code]
-- Handle unknown codes
if not data then
data = { long = raw_input, bg = "#048", fg = "#fff", display = raw_input, link = false }
if code ~= "nr" and code ~= "" then
category = "[[Category:IUCN status templates with invalid parameters]]"
end
end
-- 1. Build the Status Badge
local title = "IUCN Red List: " .. (code == "nr" and "(taxon not recognized)" or data.long)
local display_text = (code == "nr") and ("(" .. raw_input .. ")") or data.display
local padding = "0 1pt;"
if string.find(option, "3") then
padding = "2px;"
display_text = " " .. display_text .. " "
end
local style = data.is_gray and "color: #666;" or string.format("background-color: %s; color: %s;", data.bg, data.fg)
style = style .. " padding: " .. padding
local res = string.format("'''<span style=\"%s\" title=\"%s\">%s</span>'''", style, title, display_text)
-- 2. Apply Wiki Link (if link is valid)
local link = args.link or data.link
if mw.title.new(link or '') then
res = string.format("[[%s|%s]]", link, res)
end
-- 3. Build the URL/Reference (option includes 1)
if string.find(option, "1") and id ~= "" then
local url_path = id:find("/") and "species/" or "details/"
local clean_id = id:find("/") and id or (id .. "/0")
local link_text = "IUCN"
if label ~= "" then link_text = label
elseif year ~= "" then link_text = "IUCN " .. year end
local url = string.format("https://www.iucnredlist.org/%s%s", url_path, clean_id)
res = res .. string.format('<sup> <span class="plainlinks" title="IUCN Red List assessment">[%s %s]</span></sup>', url, link_text)
end
return res .. category
end
return p