Module:Conservation status

local p = {}

-- function main() - entry point for template

function p.main(frame)

local system = mw.text.trim(frame:getParent().args[1]) -- needs trim() for unnamed parameters

local status = mw.text.trim(frame:getParent().args[2])

local refs = mw.text.trim(frame:getParent().args[3] or "" )

--TODO add handling of extinct parameter

return '! colspan = 2 |

Conservation status
' -- header row

.. '\n|-'

.. '\n| colspan = 2 |

'

.. p._main(frame, system, status, refs) -- status content

.. '

'

end

-- function status() - entry point for direct invoke testing (assumes table structure and adds cell content)

function p.status(frame)

local system = mw.text.trim(frame.args[1])

local status = mw.text.trim(frame.args[2])

local refs = mw.text.trim(frame.args[3] or "" )

--TODO if system and status then return

return p._main(frame, system, status, refs)

end

function p._main(frame, system, status, refs)

local output = "ERROR"

system = string.upper(system)

status = string.upper(status)

local systemText = ""

--TODO check for system; if none give needs handling with long list of possible statuses to match current system

if system == "IUCN3.1" or system == "IUCN" then

output = p.IUCN31(frame, system, status)

systemText = "IUCN 3.1"

elseif system == "IUCN2.3" then

output = p.IUCN23(frame, system, status)

systemText = "IUCN 2.3"

elseif system == "CNCFLORA" then

--output = p.CNCFlora(frame, system, status)

output = p.UsesIUCN31(frame, system, status) -- uses IUCN3.1 system and criteria (need to block catgories)

systemText = "CNCFlora"

elseif system == "TPWCA" then

output = p.UsesIUCN31(frame, system, status) -- uses IUCN3.1 system and criteria (need to block catgories)

systemText = "TPWCA"

elseif system == "SANBI" or system == "RLSAP" then

output = p.SANBI(frame, system, status)

systemText = "SANBI Red List"

elseif system == "NATURESERVE" or system == "TNC" then

output = p.NatureServe(frame, system, status)

systemText = "NatureServe"

elseif system == "EPBC" then

output = p.EPBC(frame, system, status)

systemText = "EPBC Act"

elseif system == "ESA" then

output = p.ESA(frame, system, status)

systemText = "ESA"

elseif system == "COSEWIC" then

output = p.COSEWIC(frame, system, status)

systemText = "COSEWIC"

elseif system == "DECF" then

output = p.DECF(frame, system, status)

systemText = "DEC"

elseif system == "NSWBCA" then

output = p.NSWBCA(frame, system, status)

systemText = "NSWBCA"

elseif system == "QLDNCA" then

output = p.QLDNCA(frame, system, status)

systemText = "NCA"

elseif system == "CITES" then

output = p.CITES(frame, system, status)

systemText = "CITES"

elseif system == "NZTCS" then

output = p.NZTCS(frame, system, status)

systemText = "NZ TCS"

else

output = p.SystemNotRecognised(frame, system, status)

systemText = "" .. system .. "" -- should this be linked?

end

if output ~= "ERROR" then

--[=[ template code

 ({{#if:{{{status_text|}}}

|{{{status_text -- links to section in article?

|IUCN 3.1}}){{{3|}}}

]=]

local statusText = frame:getParent().args['status_text']

--local systemText = " IUCN 3.1"

if statusText then

if statusText == "" then statusText = "#Conservation status" end

systemText = "See text"

end

output = output .. " (" .. systemText .. ")" .. refs .. "" -- "

"

return output

end

end

--[[ OTHER SYSTEMS

Territory Parks and Wildlife Conservation Act 2000 (TPWCA)

]]

function p.SystemNotRecognised(frame, system, status)

local output = system .. ' ' .. status

if status == "EX" then

local extinct = "Extinct"

if frame:getParent().args['extinct'] then extinct = " (" .. frame:getParent().args['extinct'] .. ")" end

output = p.addImage("Status iucn3.1 EX.svg") .. extinct

elseif status == "CR" then

output = "Critically Endangered"

elseif status == "EN" then

output = "Endangered"

elseif status == "NT" then

output = "Near Threatened"

else

output = status

end

return output .. p.addCategory("Taxoboxes with an unrecognised status system")

end

--***************************************** IUCN 3.1 **********************************

function p.IUCN31(frame, system, status)

-- | EX = file:Status iucn3.1 EX.svg
Extinct {{#if:{{{extinct|}}}| ({{{extinct}}}) }} {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List extinct species | }}

-- | EW = file:Status iucn3.1 EW.svg
Extinct in the Wild {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List extinct in the wild species | }}

-- | CR = file:Status iucn3.1 CR.svg
Critically Endangered {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List critically endangered species |}}

-- | EN = file:Status iucn3.1 EN.svg
Endangered {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List endangered species | }}

-- | VU = file:Status iucn3.1 VU.svg
Vulnerable {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List vulnerable species |}}

local output = system .. ' ' .. status

if status == "EX" then

local extinct = "Extinct"

if frame:getParent().args['extinct'] then extinct = " (" .. frame:getParent().args['extinct'] .. ")" end

output = p.addImage("Status iucn3.1 EX.svg") .. extinct .. p.addCategory("IUCN Red List extinct species")

elseif status == "EW" then

output = p.addImage("Status iucn3.1 EW.svg") .. "Extinct in the Wild" .. p.addCategory("IUCN Red List extinct in the wild species")

elseif status == "CR" then

output = p.addImage("Status iucn3.1 CR.svg") .. "Critically Endangered" .. p.addCategory("IUCN Red List critically endangered species")

elseif status == "EN" then

output = p.addImage("Status iucn3.1 EN.svg") .. "Endangered" .. p.addCategory("IUCN Red List endangered species")

elseif status == "VU" then

output = p.addImage("Status iucn3.1 VU.svg") .. "Vulnerable" .. p.addCategory("IUCN Red List vulnerable species")

-- | NT = file:Status iucn3.1 NT.svg
Near Threatened {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List near threatened species | }}

-- | LC = file:Status iucn3.1 LC.svg
Least Concern {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List least concern species |}}

-- | DD = file:Status iucn3.1 blank.svg
Data Deficient {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List data deficient species |}}

-- | NE = Not evaluated

-- | NR = Not recognized

-- | PE = file:Status iucn3.1 CR.svg
Critically endangered, possibly extinct {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List critically endangered species |}}

-- | PEW = file:Status iucn3.1 CR.svg
Critically endangered, possibly extinct in the wild {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:IUCN Red List critically endangered species|}}

elseif status == "NT" then

output = p.addImage("Status iucn3.1 NT.svg") .. "Near Threatened" .. p.addCategory("IUCN Red List near threatened species")

elseif status == "LC" then

output = p.addImage("Status iucn3.1 LC.svg") .. "Least Concern" .. p.addCategory("IUCN Red List least concern species")

elseif status == "DD" then

output = p.addImage("Status iucn3.1 blank.svg") .. "Data Deficient" .. p.addCategory("IUCN Red List data deficient species")

elseif status == "NE" then

output = "Not evaluated"

elseif status == "NR" then

output = "Not recognized"

elseif status == "PE" then

output = p.addImage("Status iucn3.1 CR.svg") .. "Critically endangered, possibly extinct" .. p.addCategory("IUCN Red List critically endangered species")

elseif status == "PEW" then

output = p.addImage("Status iucn3.1 CR.svg") .. "Critically endangered, possibly extinct in the wild" .. p.addCategory("IUCN Red List critically endangered species")

else

-- | Invalid status{{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:Invalid conservation status|}}

output = "Invalid status" .. p.addCategory("Invalid conservation status")

end

-- | Invalid status{{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | Category:Invalid conservation status|}}

--}} ({{#if:{{{status_text|}}}|{{{status_text|IUCN 3.1}}){{{3|}}}