Module:Image Wikidata

Útá Wikipedia.

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

local p = {}
local wd = require "Module: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] and mw.text.trim(args[1]) or nil -- si des données sont fournies localement, les utiliser plutôt que les données de Wikidata
	if localdata and (localdata ~= "") then
		if localdata == "-" then
			return nil
		else
			return localdata
		end
	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 == "image" then
		return wd.formatStatement(claim, args)
	end
	if infotype == "légende" 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 "fr")) then
				return wd.formatSnak(j, args)
			end
		end
	end
end

return p