Jump to content

Module:Sandbox/Tom.Reding/Tools

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tom.Reding (talk | contribs) at 17:11, 13 June 2018 (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 = {}

local function copyTable(inTable)
	if type(inTable) ~= 'table' then return inTable end
	local outTable = setmetatable({}, getmetatable(inTable))
	for key, value in pairs (inTable) do outTable[copyTable(key)] = copyTable(value) end
	return outTable
end

function p.istaxon(frame)
	local resolve = require( 'Module:ResolveEntityId' )
	local parentArgs = copyTable(frame:getParent().args)
	local title = mw.getCurrentFrame():getParent().args[1]
	local qid = resolve._entityid(frame, title)
	local item = mw.wikibase.getEntity(qid)
	local acceptable = {
	   ['Q16521'] = 'taxon',
	   ['Q310890'] = 'monotypic taxon',
	   ['Q2568288'] = 'ichnotaxon',
	   ['Q23038290'] = 'fossil taxon',
	   ['Q47487597'] = 'monotypic fossil taxon',
	}
	if item then
		for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance of
			local instanceOf = instanceOfState.mainsnak.datavalue.value.id
			if acceptable[instanceOf] then
				return title .. ' == taxon'
			end
		end
	else
		return title ..  ': Wikidata item not found'
	end
end

return p