Jump to content

Module:Conservation status

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jts1882 (talk | contribs) at 15:41, 8 August 2019 (add EPBC). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.main(frame)
    
    local output = "ERROR"
    local status = mw.text.trim(frame:getParent().args[2]) -- needs trim() for unnamed parameters
    local system = mw.text.trim(frame:getParent().args[1])
    system = string.upper(system)
    status = string.upper(status)
    local systemText = ""
    
    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)
       systemText = " [[CNCFlora]]"
    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 == "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]]"
    else

    end
    if output ~= "ERROR" then
    	
   	    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 '! colspan = 2 | <div style = "text-align:center;">[[Conservation status]]</div>' -- header
               .. '\n|-'
               .. '\n| colspan = 2 | <div style = "text-align:center;">' .. output  .. '</div>'
    end
end




       
       
       
--***************************************** IUCN 3.1 **********************************
function p.IUCN31(frame, system, status)
	
	-- | EX = [[file:Status iucn3.1 EX.svg|frameless|link=|alt=]]<br />[[Extinction|Extinct]] {{#if:{{{extinct|}}}|&nbsp;({{{extinct}}}) }} {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List extinct species]] | }}
	-- | EW = [[file:Status iucn3.1 EW.svg|frameless|link=|alt=]]<br />[[Extinct in the Wild]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List extinct in the wild species]] | }}
	-- | CR = [[file:Status iucn3.1 CR.svg|frameless|link=|alt=]]<br />[[Critically endangered species|Critically Endangered]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List critically endangered species]] |}}
	-- | EN = [[file:Status iucn3.1 EN.svg|frameless|link=|alt=]]<br />[[Endangered species|Endangered]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List endangered species]] | }}
	-- | VU = [[file:Status iucn3.1 VU.svg|frameless|link=|alt=]]<br />[[Vulnerable species|Vulnerable]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List vulnerable species]] |}}

    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 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 species|Critically Endangered]]" .. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "EN" then
    	output = p.addImage("Status iucn3.1 EN.svg") .. "[[Endangered species|Endangered]]" .. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn3.1 VU.svg") .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("IUCN Red List vulnerable species")

-- | NT = [[file:Status iucn3.1 NT.svg|frameless|link=|alt=]]<br />[[Near Threatened]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List near threatened species]] | }}
-- | LC = [[file:Status iucn3.1 LC.svg|frameless|link=|alt=]]<br />[[Least Concern]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List least concern species]] |}}
-- | DD = [[file:Status iucn3.1 blank.svg|frameless|link=|alt=]]<br/>[[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|frameless|link=|alt=]]<br />[[Critically endangered]], possibly extinct {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List critically endangered species]] |}}
-- | PEW = [[file:Status iucn3.1 CR.svg|frameless|link=|alt=]]<br />[[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]]|}}
 --}}<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]]"
    	if frame:getParent().args['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status iucn2.3 EX.svg") .. extinct .. p.addCategory("IUCN Red List extinct species")
    elseif status == "EW" then
    	output = p.addImage("Status iucn2.3 EW.svg") .. "[[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 species|Critically Endangered]]" .. p.addCategory("IUCN Red List critically endangered species")
    elseif status == "EN" then
    	output = p.addImage("Status iucn2.3 EN.svg") .. "[[Endangered species|Endangered]]" .. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn2.3 VU.svg") .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("IUCN Red List vulnerable species")
    elseif status == "LR" then
    	output = p.addImage("Status iucn2.3 blank.svg") .. "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]]" .. 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]]" .. 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]]" .. p.addCategory("IUCN Red List least concern species")
    elseif status == "DD" then
    	output = p.addImage("Status iucn2.3 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 iucn2.3 CR.svg") .. "[[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]], 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***************************************
function p.CNCFlora(frame, system, status)
	

    local output = system .. ' ' .. status
    if status == "EX" then
    	output = p.addImage("Status iucn3.1 EX.svg") .. "[[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]]" --.. p.addCategory("IUCN Red List extinct in the wild species")
    elseif status == "CR" then
    	output = p.addImage("Status iucn3.1 CR.svg") .. "[[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 species|Endangered]]" --.. p.addCategory("IUCN Red List endangered species")
    elseif status == "VU" then
    	output = p.addImage("Status iucn3.1 VU.svg") .. "[[Vulnerable species|Vulnerable]]" --.. p.addCategory("IUCN Red List vulnerable 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 
    	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['extinct'] then extinct = "&nbsp;(" .. frame:getParent().args['extinct'] .. ")" end
    	output = p.addImage("Status TNC GX.svg") .. extinct .. p.addCategory("NatureServe presumed extinct species")
   elseif status == "GH" then
    	output = p.addImage("Status TNC GH.svg") .. "Possibly [[Extinction|Extinct]]" .. p.addCategory("NatureServe possibly extinct species")
   elseif status == "G1" then
    	output = p.addImage("Status TNC G1.svg") .. "Critically Imperiled" .. p.addCategory("NatureServe critically imperiled species")
   elseif status == "G2" then
    	output = p.addImage("Status TNC G2.svg") .. "Imperiled" .. p.addCategory("NatureServe imperiled species")
   elseif status == "G3" then
    	output = p.addImage("Status TNC G3.svg") .. "Vulnerable" .. p.addCategory("NatureServe vulnerable species")
   elseif status == "G4" then
    	output = p.addImage("Status TNC G4.svg") .. "Apparently Secure" .. p.addCategory("NatureServe apparently secure species")
   elseif status == "G5" then
    	output = p.addImage("Status TNC G5.svg") .. "Secure" .. p.addCategory("NatureServe secure species")
   elseif status == "GU" then
    	output = p.addImage("Status TNC blank.svg") .. "Unrankable"
   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 .. p.addCategory("NatureServe presumed extinct species")
   elseif status == "TH" then
    	output = p.addImage("Status TNC TH.svg") .. "Possibly [[Extinction|Extinct]]" .. p.addCategory("NatureServe possibly extinct species")
   elseif status == "T1" then
    	output = p.addImage("Status TNC T1.svg") .. "Critically Imperiled" .. p.addCategory("NatureServe critically imperiled species")
   elseif status == "T2" then
    	output = p.addImage("Status TNC T2.svg") .. "Imperiled" .. p.addCategory("NatureServe imperiled species")
   elseif status == "T3" then
    	output = p.addImage("Status TNC T3.svg") .. "Vulnerable" .. p.addCategory("NatureServe vulnerable species")
   elseif status == "T4" then
    	output = p.addImage("Status TNC T4.svg") .. "Apparently Secure" .. p.addCategory("NatureServe apparently secure species")
   elseif status == "T5" then
    	output = p.addImage("Status TNC T5.svg") .. "Secure" .. p.addCategory("NatureServe secure species")
   elseif status == "TU" then
    	output = p.addImage("Status TNC blank.svg") .. "Unrankable"
   else 
    	output = "'''''Invalid status'''''" --.. p.addCategory("")
   end  
   return output 
end

-- ********* EPBC: Environment Protection and Biodiversity Conservation Act 1999 (Australia) ************
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 .. p.addCategory("EPBC Act extinct biota")
   elseif status == "EW" then
    	output = p.addImage("Status EPBC EW.svg") .. "[[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 species|Critically endangered]]" .. p.addCategory("EPBC Act critically endangered biota")
   elseif status == "EN" then
    	output = p.addImage("Status EPBC EN.svg") .. "[[Endangered species|Endangered]]" .. p.addCategory("EPBC Act endangered biota")
   elseif status == "VU" then
    	output = p.addImage("Status EPBC VU.svg") .. "[[Vulnerable species|Vulnerable]]" .. p.addCategory("EPBC Act vulnerable biota")
   elseif status == "CD" then
    	output = p.addImage("Status EPBC CD.svg") .. "[[Conservation Dependent]]" .. p.addCategory("EPBC Act conservation dependent biota")
   elseif status == "DL"  or status == "DELISTED" then
    	output = p.addImage("Status EPBC DL.svg") .. "Delisted" 
    	
   else 
    	output = "'''''Invalid status'''''" --.. p.addCategory("")
   end  
  
   return output 
end
--[=[
| EPBC = {{#switch:{{uc:{{{2}}}}}
 | EX = [[file:Status EPBC EX.svg|frameless|link=|alt=]]<br />[[Extinction|Extinct]] {{#if:{{{extinct|}}}|&nbsp;({{{extinct}}}) }} {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act extinct biota]] |}}
 | EW = [[file:Status EPBC EW.svg|frameless|link=|alt=]]<br />[[Extinct in the Wild]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act extinct in the wild biota]]|}}
 | CR = [[file:Status EPBC CR.svg|frameless|link=|alt=]]<br />[[Critically endangered species|Critically endangered]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act critically endangered biota]] |}}
 | EN = [[file:Status EPBC EN.svg|frameless|link=|alt=]]<br />[[Endangered species|Endangered]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act endangered biota]]|}}
 | VU = [[file:Status EPBC VU.svg|frameless|link=|alt=]]<br />[[Vulnerable species|Vulnerable]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act vulnerable biota]] |}}
 | CD = [[file:Status EPBC CD.svg|frameless|link=|alt=]]<br />[[Conservation Dependent]] {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:EPBC Act conservation dependent biota]] |}}
 | DL
 | DELISTED = [[file:Status EPBC DL.svg|frameless|link=|alt=]]<br />Delisted
 | '''''Invalid status''''' {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:Invalid conservation status]]|}}
}}<small>&nbsp;({{#if:{{{status_text|}}}|[[{{{status_text|#Conservation status}}}|See text]]|[[Environment Protection and Biodiversity Conservation Act 1999|EPBC Act]]}}){{{3|}}}</small></div><!--
]=]

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

   local output = system .. ' ' .. status
   
   return output 
end
-- *************** COSEWIC ********************************
function p.COSEWIC(frame, system, status)

   local output = system .. ' ' .. status
   
   return output 
end
-- *************** DECF ********************************
function p.DECF(frame, system, status)

   local output = system .. ' ' .. status
   
   return output 
end



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

   local output = system .. ' ' .. status
   
   return output 

end
-- *************** CITES ********************************
function p.CITES(frame, system, status)

   local output = system .. ' ' .. status
   
   return output 

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

   local output = system .. ' ' .. status
   
   return output 

end


-- *************** functions  for image and category output ********
function p.addImage(file)
    if file ~= "" then
    	return "[[File:" .. file .. "|frameless|link=|alt=]]<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