Module:Utilitaire Wikidata

De Lagny-sur-Marne Wiki
Révision datée du 19 avril 2015 à 07:09 par Zolo (discussion)
Aller à : navigation, rechercher

La documentation pour ce module peut être créée à Module:Utilitaire Wikidata/doc

-- Module de requêtes Wikidata de plus haut niveau que Module:Wikidata
local p = {}
local wikidata = require "Module:Wikidata"

local function keydate (event)
	if type(event) ~= 'string' then
		return error('event should be string starting with P or S')
	end
	if string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé)
		return  wikidata.getTheDate{property = 'P793', targetvalue = event, addcat = true, item = item}
	elseif string.sub(event, 1, 1) == 'P'  then -- on demande une propriété
		return wikidata.formatAndCat{property = event, item = item}
	else
		return error('event should be string starting with P or S')
	end
end

function p.keydate(events)
	if type(event) == nil then
		return nil
	end
	if type(events) == 'string' then
		return keydate(event)
	elseif type(events) == 'table' then
		for i, j in pairs(events) do
			local val = keydate(j)
			if val then
				return val
			end
		end
	end
end

function p.formatAndCat(args)
	return wikidata.formatAndCat(args)
end

return p