Module:Taxonbar/whitelist: Difference between revisions

From Azupedia
Jump to navigation Jump to search
Created page with "local p = {} --returns any combination of strict/lax/all acceptable instance-of's, --either as a table for use inside Module:Taxonbar or another module, --or as an ordered list for use in documentation. function p.whitelist( frame ) local listType = frame.args[1] local documentation = frame.args[2] local outList = {} local acceptableInstanceOf_Strict = { --table order == display order 'Q16521', --taxon 'Q310890', --monotypic taxon 'Q47487597', --monotypi..."
 
No edit summary
 
Line 9: Line 9:
local outList = {}
local outList = {}
local acceptableInstanceOf_Strict = { --table order == display order
local acceptableInstanceOf_Strict = { --table order == display order
'Q16521', --taxon
'Q7', --taxon
'Q310890', --monotypic taxon
'Q17440', --monotypic taxon
'Q47487597', --monotypic fossil taxon
'Q22243', --monotypic fossil taxon
'Q2568288', --ichnotaxon
'Q22244', --ichnotaxon
'Q23038290', --fossil taxon
'Q16661', --fossil taxon
'Q59278506', --ootaxon
'Q22246', --ootaxon
'Q98961713', --extinct taxon
'Q16662', --extinct taxon
'Q58051350', --paraphyletic group (subclass of taxon)
'Q109610', --paraphyletic group (subclass of taxon)
}
}
local acceptableInstanceOf_Lax = { --table order == display order
local acceptableInstanceOf_Lax = { --table order == display order
'Q42621', --hybrid
'Q18920', --hybrid
'Q235536', --incertae sedis
'Q22248', --incertae sedis
'Q713623', --clade
'Q7948', --clade
'Q848328', --serotype
'Q22249', --serotype
'Q857968', --candidatus
'Q22251', --candidatus
'Q17487588', --unavailable combination
'Q22252', --unavailable combination
'Q124477390', --taxon hypothesis
'Q22253', --taxon hypothesis
}
}

Latest revision as of 15:05, 28 May 2025

Documentation for this module may be created at Module:Taxonbar/whitelist/doc

local p = {}

--returns any combination of strict/lax/all acceptable instance-of's,
--either as a table for use inside [[Module:Taxonbar]] or another module,
--or as an ordered list for use in documentation.
function p.whitelist( frame )
	local listType = frame.args[1]
	local documentation = frame.args[2]
	local outList = {}
	local acceptableInstanceOf_Strict = { --table order == display order
		'Q7',		--taxon
		'Q17440',		--monotypic taxon
		'Q22243',	--monotypic fossil taxon
		'Q22244',		--ichnotaxon
		'Q16661',	--fossil taxon
		'Q22246',	--ootaxon
		'Q16662',	--extinct taxon
		'Q109610',	--paraphyletic group (subclass of taxon)
	}
	local acceptableInstanceOf_Lax = { --table order == display order
		'Q18920',		--hybrid
		'Q22248',		--incertae sedis
		'Q7948',		--clade
		'Q22249',		--serotype
		'Q22251',		--candidatus
		'Q22252',	--unavailable combination
		'Q22253',	--taxon hypothesis
	}
	
	if listType == 'strict'  then outList = acceptableInstanceOf_Strict
	elseif listType == 'lax' then outList = acceptableInstanceOf_Lax
	else --elseif listType == 'all' then --concatenate strict + lax IIF requested
		local acceptableInstanceOf_All = {}
		local i = 0
		for _, v in pairs( acceptableInstanceOf_Strict ) do
			i = i + 1
			acceptableInstanceOf_All[i] = v
		end
		for _, v in pairs( acceptableInstanceOf_Lax ) do
			i = i + 1
			acceptableInstanceOf_All[i] = v
		end
		outList = acceptableInstanceOf_All
	end
	
	if (documentation == nil) or --module only
	   (documentation and documentation == '')
	then
		local out = {}
		for k, v in pairs( outList ) do
			out[v] = k --output Q# as keys for easier searching within Module:Taxonbar
		end
		return out
		
	elseif (documentation == 'docdoc') then --self-documentation only
		local selfdocout = 'myWhitelist = {\n'
		for k, q in pairs( outList ) do
			selfdocout = selfdocout..'\t\''..q..'\' = '..k..',\n'
		end
		selfdocout = selfdocout..'}'
		local args = { ['lang'] = 'lua',
					   ['code'] = selfdocout }
		out = frame:expandTemplate{ title = 'Syntaxhighlight', args = args }
		return out
		
	else --normal documentation only
		local out = ''
		for _, q in pairs( outList ) do
			local Q = frame:expandTemplate{ title = 'Q', args = { q } }
			out = out..'# '..Q..'\n'
		end
		out = mw.ustring.gsub(out, '%s+$', '')
		return out
	end
	
end

return p