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 08:53, 7 August 2019 (add functionality for one system and value). 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 status = frame:getParent().args[2]
    local system = frame:getParent().args[1]
    system = string.upper(system)
    status = string.upper(status)
    
    if system == "IUCN3.1" or system == "IUCN" then
       return p.IUCN31(system, status)
    end

    return system .. ' ' .. status
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 = ""
    if status == "EN" then
    	output = "[[file:Status iucn3.1 EN.svg|frameless|link=|alt=]]<br />[[Endangered species|Endangered]]"
    	          .. p.addCategory("IUCN Red List endangered species")
    	return output
    end
    return system .. ' ' .. status
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