Mòdul:Imatge Wikidata

Un article de Wikipèdia, l'enciclopèdia liura.

La documentacion d'utilizacion d'aquel modul se pòt crear a Mòdul:Imatge Wikidata/ús

local p = {}
local wd = require "Mòdul:Wikidata"

function p.main(frame) -- mêmes arguments que Wikidata + argument "info", mettre "image" pour avoir le nom du fichier et "légende" pour avoir la légende
	local infotype = frame.args.info
	local args = frame:getParent().args
	local localdata = args[1] -- si des données sont fournies localement, les utiliser plutôt que les données de Wikidata
	if localdata and (localdata ~= "") then
		return localdata
	end
	args.numval = 1
	if (not args.property) or (args.property == "") then
		args.property = "P18"
	end
	local claims = wd.getClaims(args)
	if not claims then
		return nil
	end
	local claim = claims[1]
	if infotype == "imatge" then
		return wikidata.formatStatement(claim, args)
	end
	if infotype == "legenda" then
		local captions = wd.getQualifiers(claim, {"P2096"}, args)
		if not captions then
			return nil
		end
		for i, j in pairs(captions) do
			if j.datavalue.value and (j.datavalue.value.language == (args.lang or "oc")) then
				return wd.formatSnak(j, args)
			end
		end
	end
end

return p