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 09:30, 7 August 2019 (format output to insert table rows). 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)
    
    if system == "IUCN3.1" or system == "IUCN" then
       output = p.IUCN31(system, status)
    end
    if output ~= "ERROR" then
    	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
function p.IUCN31(system, status)
	
	-- | EN = [[file:Status iucn3.1 EN.svg|frameless|link=|alt=]]<br />[[Endangered species|Endangered]] 
	-- {{#ifeq: {{NAMESPACEE}} | {{ns: 0}} | [[Category:IUCN Red List endangered species]] | }}
    local output = system .. ' ' .. status
    if status == "EN" then
    	output = p.addImage("Status iucn3.1 EN.svg") .. "[[Endangered species|Endangered]]"
    	          .. p.addCategory("IUCN Red List endangered species")
    end
    return output
end
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