Jump to content

Module:Taxonbar/whitelist

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tom.Reding (talk | contribs) at 16:18, 20 August 2023 (Create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

-- returns any combination of strict/lax/all acceptable instance-of's,
-- either for use inside [[Module:Taxonbar]] or another module,
-- or for use in documentation as an ordered list
function p.whitelist( listType, documentation )
	local acceptableInstanceOf_Strict = {
		['Q16521'] = 'taxon',
		['Q310890'] = 'monotypic taxon',
		['Q98961713'] = 'extinct taxon',
		['Q2568288'] = 'ichnotaxon',
		['Q23038290'] = 'fossil taxon',
		['Q47487597'] = 'monotypic fossil taxon',
		['Q58051350'] = 'paraphyletic group', --subclass of taxon
		['Q59278506'] = 'ootaxon',
	}
	local acceptableInstanceOf_Lax = {
		['Q42621'] = 'hybrid',
		['Q235536'] = 'incertae sedis',
		['Q713623'] = 'clade',
		['Q848328'] = 'serotype',
		['Q857968'] = 'candidatus',
		['Q17487588'] = 'unavailable combination',
	}
	local acceptableInstanceOf_All = {} --create IFF requested
	if listType == 'all' then
		for k, v in pairs( acceptableInstanceOf_Strict ) do
			acceptableInstanceOf_All[k] = v
		end
		for k, v in pairs( acceptableInstanceOf_Lax ) do
			acceptableInstanceOf_All[k] = v
		end
	end
	
	if (documentation == nil) or --module-use only; order & format irrelevant
	   (documentation and documentation == '') then
		local out = {}
		if listType == 'strict'  then out = acceptableInstanceOf_Strict
		elseif listType == 'lax' then out = acceptableInstanceOf_Lax
		elseif listType == 'all' then out = acceptableInstanceOf_All
		end
		return out
	else
		local displayOrder_Strict = {
			'Q16521',		--taxon
			'Q310890',		--monotypic taxon
			'Q47487597',	--monotypic fossil taxon
			'Q2568288',		--ichnotaxon
			'Q23038290',	--fossil taxon
			'Q59278506',	--ootaxon
			'Q98961713',	--extinct taxon
			'Q58051350',	--paraphyletic group
		}
		local displayOrder_Lax = {
			'Q42621',		--hybrid
			'Q235536',		--incertae sedis
			'Q713623',		--clade
			'Q848328',		--serotype
			'Q857968',		--candidatus
			'Q17487588',	--unavailable combination
		}
		local displayOrder_All = {} --create IFF requested
		if listType == 'all' then
			--concatenate strict + lax display order tables
			local i = 0
			for _, v in pairs( displayOrder_Strict ) do
				i = i + 1
				displayOrder_All[i] = v
			end
			for _, v in pairs( displayOrder_Lax ) do
				i = i + 1
				displayOrder_All[i] = v
			end
		end
		
		local outOrder = {}
		if listType == 'strict'  then outOrder = displayOrder_Strict
		elseif listType == 'lax' then outOrder = displayOrder_Lax
		elseif listType == 'all' then outOrder = displayOrder_All
		end
		
		local out = ''
		for _, Q in pairs( outOrder ) do
			out = out..'# {{Q|'..Q..'}}\n'
		end
		return out
	end
	
end

return p