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 | <div style = "text-align:center;">[[Conservation status]]</div>' -- header row
           .. '\n|-'
           .. '\n| colspan = 2 | <div style = "text-align:center;">' 
           .. p._main(frame, system, status, refs) -- status content 
           .. '</div>'
        
           
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 Red List|IUCN 3.1]]"
    elseif system == "IUCN2.3" then
       output = p.IUCN23(frame, system, status)
       systemText = "[[IUCN Red List|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 = "[[NTFlora#TPWCA|TPWCA]]"
    elseif system == "SANBI" or system == "RLSAP" then
       output = p.SANBI(frame, system, status)    
       systemText = "[[Red List of South African Plants|SANBI Red List]]"
    elseif system == "NATURESERVE" or system == "TNC" then
       output = p.NatureServe(frame, system, status)
       systemText = "[[NatureServe conservation status|NatureServe]]"
    elseif system == "EPBC" then
       output = p.EPBC(frame, system, status)
       systemText = "[[Environment Protection and Biodiversity Conservation Act 1999|EPBC Act]]"
    elseif system == "ESA" then
       output = p.ESA(frame, system, status)
       systemText = "[[Endangered Species Act|ESA]]"
  	elseif system == "COSEWIC" then
       output = p.COSEWIC(frame, system, status)
       systemText = "[[Committee on the Status of Endangered Wildlife in Canada|COSEWIC]]"
 	elseif system == "DECF" then
       output = p.DECF(frame, system, status)
       systemText = "[[Declared Rare and Priority Flora List|DEC]]"
 	elseif system == "NSWBCA" then
        output = p.NSWBCA(frame, system, status)
 		systemText = "[[Biodiversity Conservation Act 2016 (NSW)|NSWBCA]]"
 	elseif system == "QLDNCA" then
       output = p.QLDNCA(frame, system, status)
       systemText = "[[Nature Conservation Act 1992|NCA]]"
 	elseif system == "CITES" then
       output = p.CITES(frame, system, status)
       --systemText = "[[CITES]]"
 	elseif system == "NZTCS" then
       output = p.NZTCS(frame, system, status)
       systemText = "[[New Zealand Threat Classification System|NZ TCS]]"
    elseif system ~= nil then
       output = p.SystemNotRecognised(frame, system, status)
       systemText = mw.text.trim(frame.args[1])   -- raw system in parameter (not uppercase as system variable )
    else -- no system parameter
    	mw.addWarning ("No conservation system provided")
    end
    if output ~= "ERROR" then
    	--[=[  template code
    	       <small>&nbsp;({{#if:{{{status_text|}}}
    	          |[[{{{status_text|#Conservation status}}}|See text]]   --  links to section in article?
    	          |[[IUCN Red List|IUCN 3.1]]}}){{{3|}}}</small>
        ]=]
        local statusText = frame:getParent().args['status_text']
        --local systemText = " [[IUCN Red List|IUCN 3.1]]"
        if statusText then 
           if statusText == "" then statusText = "#Conservation status" end
    	   systemText = "[[" .. statusText .. "|See text]]"
        end
        if systemText ~= "" then
        	output = output ..  "<small>&nbsp;(" .. systemText .. ")" .. refs .. "</small>" -- "</div>"
        else
        	output = output ..  "<small>&#8239;" .. refs .. "</small>" -- "</div>"
        end
 
        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 = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinction_date'] and frame:getParent().args['extinction_date'] ~= "" then 
    		extinct = extinct .. "&nbsp;(" .. frame:getParent().args['extinction_date'] .. ")" 
    	end
    	output = p.addImage("Status iucn3.1 EX.svg", 'Extinct') .. extinct 
    elseif status == "CR" then
    	output = "[[Critically endangered species|Critically Endangered]]" 
    elseif status == "EN" then	
    	output = "[[Endangered species|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)
	
    local output = system .. ' ' .. status
    if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinction_date'] and frame:getParent().args['extinction_date'] ~= "" then 
    		extinct = extinct .. "&nbsp;(" .. frame:getParent().args['extinction_date'] .. ")" end
    	output = p.addImage("Status iucn3.1 EX.svg", 'Extinct') .. extinct .. p.addCategory("IUCN Red List extinct species")
    elseif status == "EW" then
    	output = p.addImage("Status iucn3.1 EW.svg", 'Extinct in the Wild') .. "[[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') .. "[[Critically endangered species|Critically Endangered]]" .. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "EN" then
    	output = p.addImage("Status iucn3.1 EN.svg", 'Endangered') .. "[[Endangered species (IUCN status)|Endangered]]" .. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn3.1 VU.svg", 'Vulnerable') .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("IUCN Red List vulnerable species")
    elseif status == "NT" then
    	output = p.addImage("Status iucn3.1 NT.svg", 'Near Threatened') .. "[[Near Threatened]]" .. p.addCategory("IUCN Red List near threatened species")
    elseif status == "LC" then
    	output = p.addImage("Status iucn3.1 LC.svg", 'Least Concern') .. "[[Least Concern]]" .. p.addCategory("IUCN Red List least concern species")
    elseif status == "DD" then
    	output = p.addImage("Status iucn3.1 blank.svg", 'Data Deficient') .. "[[Data deficient|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 == "NA" then            -- only used in regional assessments?
    	output =  "''Not applicable''" 
    elseif status == "PE" then
    	output = p.addImage("Status iucn3.1 CR.svg", 'Critically endangered') .. "[[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') .. "[[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]]|}}
 --}}<small>&nbsp;({{#if:{{{status_text|}}}|[[{{{status_text|#Conservation status}}}|See text]]|[[IUCN Red List|IUCN 3.1]]}}){{{3|}}}</small></div><!--
   
 --   local thirdParam = "" --mw.text.trim(frame:getParent().args[3] or "")
 --   local statusText = frame:getParent().args['status_text']
  --  local systemText = " [[IUCN Red List|IUCN 3.1]]"
 --   if statusText then 
 --   	systemText = "[[{{{status_text|#Conservation status}}}|See text]]"
 --   end
 --   output = output ..  "<small>&nbsp;(" .. systemText .. thirdParam .. ")</small></div>"
    return output 
end

-- ********************************* IUCN 2.3 **********************************************
function p.IUCN23(frame, system, status)
	
    local output = system .. ' ' .. status
    if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	local extinctionDate = frame:getParent().args['extinction_date'] or ""
    	if extinctionDate ~= "" then extinct = extinct .. "&nbsp;(" .. frame:getParent().args['extinction_date'] .. ")" end
    	output = p.addImage("Status iucn2.3 EX.svg", 'Extinct') .. extinct .. p.addCategory("IUCN Red List extinct species")
    elseif status == "EW" then
    	output = p.addImage("Status iucn2.3 EW.svg", 'Extinct in the Wild') .. "[[Extinct in the Wild]]" .. p.addCategory("IUCN Red List extinct in the wild species")
    elseif status == "CR" then
    	output = p.addImage("Status iucn2.3 CR.svg", 'Critically Endangered') .. "[[Critically endangered species|Critically Endangered]]" .. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "EN" then
    	output = p.addImage("Status iucn2.3 EN.svg", 'Endangered') .. "[[Endangered species (IUCN status)|Endangered]]" .. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn2.3 VU.svg", 'Vulnerable') .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("IUCN Red List vulnerable species")
    elseif status == "LR" then
    	output = p.addImage("Status iucn2.3 blank.svg", 'Lower risk') .. "Lower risk" .. p.addCategory("Invalid conservation status")
    elseif status == "CD" or status == "LR/CD" then
        output = p.addImage("Status iucn2.3 CD.svg", 'Conservation Dependent') .. "[[Conservation Dependent]]" .. p.addCategory("IUCN Red List conservation dependent species")
    elseif status == "NT" or status == "LR/NT" then
    	output = p.addImage("Status iucn2.3 NT.svg", 'Near Threatened') .. "[[Near Threatened]]" .. p.addCategory("IUCN Red List near threatened species")
    elseif status == "LC" or status == "LR/LC" then
    	output = p.addImage("Status iucn2.3 LC.svg", 'Least Concern') .. "[[Least Concern]]" .. p.addCategory("IUCN Red List least concern species")
    elseif status == "DD" then
    	output = p.addImage("Status iucn2.3 blank.svg", 'Data Deficient') .. "[[Data deficient|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 iucn2.3 CR.svg", 'Critically endangered') .. "[[Critically endangered]], possibly extinct" .. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "PEW" then
    	output = p.addImage("Status iucn2.3 CR.svg", 'Critically endangered') .. "[[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  
 
    return output 
end

--******************************************* CNCFlora***************************************

-- Note: this is not needed if using IUCN 3.1 system and criteria; just use that function with no catgories
-- alternatively rename this function as p.UsesIUCN31()
--function p.CNCFlora(frame, system, status)
function p.UsesIUCN31(frame, system, status)
	

    local output = system .. ' ' .. status
    if status == "EX" then
    	output = p.addImage("Status iucn3.1 EX.svg", 'Extinct') .. "[[Extinction|Extinct]]" --.. p.addCategory("IUCN Red List extinct species")
    elseif status == "EW" then
    	output = p.addImage("Status iucn3.1 EW.svg", 'Extinct in the Wild') .. "[[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') .. "[[Critically endangered species|Critically Endangered]]" --.. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "EN" then
    	output = p.addImage("Status iucn3.1 EN.svg", 'Endangered') .. "[[Endangered species|Endangered]]" --.. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn3.1 VU.svg", 'Vulnerable') .. "[[Vulnerable species|Vulnerable]]" --.. p.addCategory("IUCN Red List vulnerable species")
    elseif status == "NT" then
    	output = p.addImage("Status iucn3.1 NT.svg", 'Near Threatened') .. "[[Near Threatened]]" --.. p.addCategory("IUCN Red List near threatened species")
    elseif status == "LC" then
    	output = p.addImage("Status iucn3.1 LC.svg", 'Least Concern') .. "[[Least Concern]]" --.. p.addCategory("IUCN Red List least concern species")
    elseif status == "DD" then
    	output = p.addImage("Status iucn3.1 blank.svg", 'Data Deficient') .. "[[Data deficient|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') .. "[[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') .. "[[Critically endangered]], possibly extinct in the wild" --.. p.addCategory("IUCN Red List critically endangered species")
    else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
    end  
 
   return output 
end
-- *************** Natureserve/TNC ********************************
function p.NatureServe(frame, system, status)

   local output = system .. ' ' .. status
   if status == "GX" then
    	local extinct = "Presumed [[Extinction|Extinct]]"
    	if frame:getParent().args['extinction_date'] and frame:getParent().args['extinction_date'] ~= "" then extinct = extinct.. "&nbsp;(" .. frame:getParent().args['extinction_date'] .. ")" end
    	output = p.addImage("Status TNC GX.svg", 'Extinct') .. extinct .. p.addCategory("NatureServe presumed extinct species")
   elseif status == "GH" then
    	output = p.addImage("Status TNC GH.svg", 'Possibly Extinct') .. "Possibly [[Extinction|Extinct]]" .. p.addCategory("NatureServe possibly extinct species")
   elseif status == "G1" then
    	output = p.addImage("Status TNC G1.svg", 'Critically Imperiled') .. "Critically Imperiled" .. p.addCategory("NatureServe critically imperiled species")
   elseif status == "G2" then
    	output = p.addImage("Status TNC G2.svg", 'Imperiled') .. "Imperiled" .. p.addCategory("NatureServe imperiled species")
   elseif status == "G3" then
    	output = p.addImage("Status TNC G3.svg", 'Vulnerable') .. "Vulnerable" .. p.addCategory("NatureServe vulnerable species")
   elseif status == "G4" then
    	output = p.addImage("Status TNC G4.svg", 'Apparently Secure') .. "Apparently Secure" .. p.addCategory("NatureServe apparently secure species")
   elseif status == "G5" then
    	output = p.addImage("Status TNC G5.svg", 'Secure') .. "Secure" .. p.addCategory("NatureServe secure species")
   elseif status == "GU" then
    	output = p.addImage("Status TNC blank.svg", 'Unrankable') .. "Unrankable"
   elseif status == "GNR" then
    	output = p.addImage("Status TNC blank.svg", 'Unranked') .. "Unranked"
   elseif status == "TX" then
    	local extinct = "Presumed [[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status TNC TX.svg", 'Extinct') .. extinct .. p.addCategory("NatureServe presumed extinct species")
   elseif status == "TH" then
    	output = p.addImage("Status TNC TH.svg", 'Possibly Extinct') .. "Possibly [[Extinction|Extinct]]" .. p.addCategory("NatureServe possibly extinct species")
   elseif status == "T1" then
    	output = p.addImage("Status TNC T1.svg", 'Critically Imperiled') .. "Critically Imperiled" .. p.addCategory("NatureServe critically imperiled species")
   elseif status == "T2" then
    	output = p.addImage("Status TNC T2.svg", 'Imperiled') .. "Imperiled" .. p.addCategory("NatureServe imperiled species")
   elseif status == "T3" then
    	output = p.addImage("Status TNC T3.svg", 'Vulnerable') .. "Vulnerable" .. p.addCategory("NatureServe vulnerable species")
   elseif status == "T4" then
    	output = p.addImage("Status TNC T4.svg", 'Apparently Secure') .. "Apparently Secure" .. p.addCategory("NatureServe apparently secure species")
   elseif status == "T5" then
    	output = p.addImage("Status TNC T5.svg", 'Secure') .. "Secure" .. p.addCategory("NatureServe secure species")
   elseif status == "TU" then
    	output = p.addImage("Status TNC blank.svg", 'Unrankable') .. "Unrankable"
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end  
   return output 
end

-- ********* EPBC: Environment Protection and Biodiversity Conservation Act 1999 (Australia) ************
function p.SANBI(frame, system, status)

   local output = system .. ' ' .. status
   if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status SANBI EX.svg", 'Extinct') .. extinct --.. p.addCategory("SANBI Red List extinct biota")
   elseif status == "EW" then
    	output = p.addImage("Status SANBI EW.svg", 'Extinct in the Wild') .. "[[Extinct in the Wild]]" --.. p.addCategory("SANBI Red List extinct in the wild biota")
   elseif status == "RE" then
    	output = p.addImage("Status SANBI RE.svg", 'Regionally Extinct') .. "Regionally Extinct" --.. p.addCategory("SANBI Red List regionally extinct biota")
   elseif status == "CR" then
    	output = p.addImage("Status SANBI CR.svg", 'Critically endangered') .. "[[Critically endangered species|Critically endangered]]" --.. p.addCategory("SANBI Red List critically endangered biota")
   elseif status == "EN" then
    	output = p.addImage("Status SANBI EN.svg", 'Endangered') .. "[[Endangered species|Endangered]]" --.. p.addCategory("SANBI Red List endangered biota")
   elseif status == "VU" then
    	output = p.addImage("Status SANBI VU.svg", 'Vulnerable') .. "[[Vulnerable species|Vulnerable]]" --.. p.addCategory("SANBI Red List vulnerable biota")
   elseif status == "NT"  then
    	output = p.addImage("Status SANBI NT.svg", 'Near Threatened') .. "[[Near Threatened]]" --.. p.addCategory("SANBI Red List near threatened biota")
   elseif status == "LC" then
    	output = p.addImage("Status SANBI LC.svg", 'Least Concern') .. "[[Least Concern]]" --.. p.addCategory("SANBI Red List least concern biota")
   elseif status == "RA" then
    	output = p.addImage("Status SANBI Ra.svg", 'Rare') .. "Rare" --  p.addCategory("SANBI Red List rare biota")
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end  
  
   return output 
end
function p.EPBC(frame, system, status)

   local output = system .. ' ' .. status
   if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status EPBC EX.svg", 'Extinct') .. extinct .. p.addCategory("EPBC Act extinct biota")
   elseif status == "EW" then
    	output = p.addImage("Status EPBC EW.svg", 'Extinct in the Wild') .. "[[Extinct in the Wild]]" .. p.addCategory("EPBC Act extinct in the wild biota")
   elseif status == "CR" then
    	output = p.addImage("Status EPBC CR.svg", 'Critically endangered') .. "[[Critically endangered species|Critically endangered]]" .. p.addCategory("EPBC Act critically endangered biota")
   elseif status == "EN" then
    	output = p.addImage("Status EPBC EN.svg", 'Endangered') .. "[[Endangered species|Endangered]]" .. p.addCategory("EPBC Act endangered biota")
   elseif status == "VU" then
    	output = p.addImage("Status EPBC VU.svg", 'Vulnerable') .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("EPBC Act vulnerable biota")
   elseif status == "CD" then
    	output = p.addImage("Status EPBC CD.svg", 'Conservation Dependent') .. "[[Conservation Dependent]]" .. p.addCategory("EPBC Act conservation dependent biota")
   elseif status == "DL"  or status == "DELISTED" then
    	output = p.addImage("Status EPBC DL.svg", 'Delisted') .. "Delisted" 
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end  
  
   return output 
end

-- *************** ESA ********************************
function p.ESA(frame, system, status)

   local output = system .. ' ' .. status
   if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status ESA EX.svg", 'Extinct') .. extinct 
   elseif status == "LE" or status == "E" then
    	output = p.addImage("Status ESA LE.svg", 'Endangered') .. "[[Endangered species|Endangered]]"  .. p.addCategory("ESA endangered species")
   elseif status == "LT" or status == "T" then
    	output = p.addImage("Status ESA LT.svg", 'Threatened') .. "[[Threatened species|Threatened]]"  .. p.addCategory("ESA threatened species")
   elseif status == "DL"  or status == "DELISTED" then
    	output = p.addImage("Status ESA DL.svg", 'Delisted') .. "Delisted" 
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end        

   return output 
end
-- ********** COSEWIC: Committee on the Status of Endangered Wildlife in Canada **************
function p.COSEWIC(frame, system, status)

   local output = system .. ' ' .. status
   if status == "X" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status COSEWIC X.svg", 'Extinct') .. extinct 
   elseif status == "XT" then
   	    output = p.addImage("Status COSEWIC XT.svg", 'Extirpated (Canada)') .. "Extirpated (Canada)"
   elseif status == "E" then
    	output = p.addImage("Status COSEWIC E.svg", 'Endangered') .. "[[Endangered species|Endangered]]" 
   elseif  status == "T" then
    	output = p.addImage("Status COSEWIC T.svg", 'Threatened') .. "[[Threatened species|Threatened]]" 
   elseif  status == "SC" then
    	output = p.addImage("Status COSEWIC SC.svg", 'Special Concern') .. "Special Concern" 
   elseif  status == "DD" then
    	output = p.addImage("Status_COSEWIC_blank.svg", 'Data Deficient') .. "Data Deficient" 
   elseif  status == "NAR" then
    	output = p.addImage("Status COSEWIC NAR.svg", 'Not at risk') .. "[[Least Concern|Not at risk]]" 
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end     
   return output 
end
-- *************** DECF ********************************
function p.DECF(frame, system, status)

   local output = system .. ' ' .. status
   if status == "X" then
    	local extinct = "Declared Rare&nbsp;— Presumed [[Extinction|Extinct]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status DECF X.svg", 'Extinct') .. extinct 
   elseif status == "R" then
    	output = p.addImage("Status DECF R.svg", 'Declared rare') .. "Declared [[Rare species|rare]]" 
   elseif status == "P1"  then
    	output = p.addImage("Status DECF P1.svg", 'Priority One&nbsp;— Poorly Known Taxa') .. "Priority One&nbsp;— Poorly Known Taxa" 
   elseif status == "P2"  then
    	output = p.addImage("Status DECF P2.svg", 'Priority Two&nbsp;— Poorly Known Taxa') .. "Priority Two&nbsp;— Poorly Known Taxa" 
   elseif status == "P3"  then
    	output = p.addImage("Status DECF P3.svg", 'Priority Three&nbsp;— Poorly Known Taxa') .. "Priority Three&nbsp;— Poorly Known Taxa" 
   elseif status == "P4"  then
    	output = p.addImage("Status DECF P4.svg", 'Priority Four&nbsp;— Rare Taxa') .. "Priority Four&nbsp;— Rare Taxa" 
   elseif status == "DL"  or status == "DELISTED" then
    	output = p.addImage("Status DECF DL.svg", 'Delisted') .. "Delisted" 
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end        

   return output 
end



-- *************** QLDNCA (Queensland Nature Conservation Act ********************************
-- https://www.data.qld.gov.au/dataset/conservation-status-of-queensland-wildlife/resource/d20c485d-b5dc-4c07-8304-df6a21783d4b 
function p.QLDNCA(frame, system, status)

   local output = system .. ' ' .. status
   if status == "EX"  then
    	output = "[[Extinct]]" .. p.addCategory("Nature Conservation Act extinct biota")
   elseif status == "EW" or status == "PE"   then  -- PE is the code used but keep EW for compatibility
    	output = "[[Extinct in the Wild]]" .. p.addCategory("Nature Conservation Act extinct in the wild biota")
   elseif status == "CR" then
    	output = "[[Critically endangered species|Critically Endangered]]" .. p.addCategory("Nature Conservation Act critically endangered biota")
   elseif status == "EN" or status == "E"  then
    	output = "[[Endangered species|Endangered]]" .. p.addCategory("Nature Conservation Act endangered biota")
   elseif status == "VU" or status == "V" then
    	output = "[[Vulnerable species|Vulnerable]] " .. p.addCategory("Nature Conservation Act vulnerable biota")
   elseif status == "R" then
    	output = "Rare" .. p.addCategory("Nature Conservation Act rare biota")
   elseif status == "NT" then
    	output = "[[Near Threatened]]" .. p.addCategory("Nature Conservation Act near threatened biota")
   elseif status == "SL" then
    	output = "[[Special Least Concern]]" .. p.addCategory("Nature Conservation Act special least concern biota")
   elseif status == "LC" or status == "C" then
    	output = "[[Least Concern]]" .. p.addCategory("Nature Conservation Act least concern biota")
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end        
   
   return output 
end
-- *************** NSWBCA ********************************
function p.NSWBCA(frame, system, status)
	local output = system .. ' ' .. status
	   if status == "EX"  then
    	output = "[[Extinct]]" 
   elseif status == "EW"  then
    	output = "[[Extinct in the Wild]]" 
   elseif status == "CR" then
    	output = "[[Critically endangered species|Critically Endangered]]" 
   elseif status == "EN" then
    	output = "[[Endangered species|Endangered]]" 
   elseif status == "VU" then
    	output = "[[Vulnerable species|Vulnerable]] " 
--   elseif status == "R" then
--    	output = "Rare" 
--   elseif status == "NT" then
--    	output = "[[Near Threatened]]" 
   elseif status == "LC" then
    	output = "[[Least Concern]]" 
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end  
  	return output
end
-- *************** CITES ********************************
function p.CITES(frame, system, status)
	
   --colours: Animalia 	rgb(235,235,210)	Archaeplastida 	rgb(180,250,180)
   local colour = frame:getParent().args['colour']

   local categoryPrefix = "Taxa"
   --mw.addWarning (tostring(colour))
   if colour == 'rgb(235,235,210)' then categoryPrefix = "Fauna" 
   elseif colour == 'rgb(180,250,180)' then categoryPrefix = "Flora" 
   else  mw.addWarning (tostring(colour))
   end
   
   local output = system .. ' ' .. status
   if status == "CITES_A1" then
    	output = "[[CITES]] Appendix I" .. p.addCategory(categoryPrefix .. " listed on CITES Appendix I")
   elseif status == "CITES_A2" then
    	output = "[[CITES]] Appendix II" .. p.addCategory(categoryPrefix .. " listed on CITES Appendix II")
   elseif status == "CITES_A3" then
    	output = "[[CITES]] Appendix III" .. p.addCategory(categoryPrefix .. " listed on CITES Appendix III")
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end 
   return output 

end

-- *************** NZTCS ********************************
function p.NZTCS(frame, system, status)

   local output = system .. ' ' .. status
   if status == "EX" then
    	local extinct = "[[Extinction|Extinct]]"
    	if frame:getParent().args['extinction_date'] and frame:getParent().args['extinction_date'] ~= "" then 
    		extinct = extinct .. "&nbsp;(" .. frame:getParent().args['extinction_date'] .. ")" 
    	end
    	output = p.addImage("Status 2019 NZTCS EX.svg", "extinct") .. extinct 
   -- Threatened categories 2019 (NC,NE,NV,NI)
   elseif status == "NC" then
    	output = p.addImage("Status 2019 NZTCS NC.svg", "Nationally Critical") .. "Nationally Critical" 
   elseif status == "NE"  then
    	output = p.addImage("Status 2019 NZTCS NE.svg", "Nationally Endangered") .. "Nationally Endangered" 
   elseif status == "NV"  then
    	output = p.addImage("Status 2019 NZTCS NV.svg", "Nationally Vulnerable") .. "Nationally Vulnerable" 
   elseif status == "NI" or status == "ni" then
    	output = p.addImage("Status 2019 NZTCS NI.svg", "Nationally Increasing") .. "Nationally Increasing" 
   -- At Risk categories (2019 version): 
   elseif status == "D" or status == "d" then
    	output = p.addImage("Status 2019 NZTCS D.svg", "Declining") .. "Declining" 
   elseif status == "REL" or status == "Rel" or status == "rel" then
    	output = p.addImage("Status 2019 NZTCS REL.svg", "Relict") .. "Relict" 
   elseif status == "NU" or status == "nu" then
    	output = p.addImage("Status 2019 NZTCS NU.svg",  "Naturally Uncommon") .. "Naturally Uncommon" 
   -- At Risk categories (2008 version): 
   elseif status == "R" or status == "r" then
    	output = p.addImage("Status NZTCS R.svg", "Recovering") .. "Recovering"  -- included in NI in 2019 category

   --- other
   elseif status == "NT" or status == "nt" then
    	output = p.addImage("Status 2019 NZTCS NT.svg", "Not Threatened" ) .. "Not Threatened" 
   elseif status == "DD" or status == "dd" then
    	output = p.addImage("Status 2019 NZTCS DD.svg", "Data Deficit" ) .. "Data Deficit" 
   
   --  Older categories (version 2002): SD,GD,SP,RR
   elseif status == "SD"  then
    	output = p.addImage("Status NZTCS SD.svg", 'Serious Decline') .. "Serious Decline" 
   elseif status == "GD"  then
    	output = p.addImage("Status NZTCS GD.svg", 'Gradual Decline') .. "Gradual Decline" 
   elseif status == "SP"  then
    	output = p.addImage("Status NZTCS SP.svg", 'Sparse') .. "Sparse" 
   elseif status == "RR"  then
    	output = p.addImage("Status NZTCS RR.svg", 'Range Restricted') .. "Range Restricted" 

   -- otherwise invalid conservation status
   else 
    	output = "'''''Invalid status'''''" .. p.addCategory("Invalid conservation status")
   end        
   
   return output 

end


-- *************** functions  for image and category output ********
function p.addImage(file, alt)
    local statusNumber =	mw.getCurrentFrame():getParent().args['number'] or 1
    --mw.addWarning ("statusNo=" .. statusNumber)
    
    if file ~= "" and tonumber(statusNumber)<3 then
    	return "[[File:" .. file .. "|frameless|alt=" .. ( alt or '|link=' ) .. "|class=skin-invert-image]]<br />"
    end
    return ""
end
function p.addCategory(category)
	local ns = mw.title.getCurrentTitle().namespace
    -- ns = 0 -- to test category put on page
	if category ~= "" and ns == 0 then
		return "[[Category:" .. category .. "]]"
    end
    return ""
end


return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.