Modul:Homokozó/tdombos/cim

A Wikipédiából, a szabad enciklopédiából

Homokozó/tdombos/cim[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local wd -- lazily loaded Module:Wikidata
local entityId -- manually given entity id
local entity -- entity object

function getProp(prop,qualprop,entityId,format)
	if not entity then
		entity = mw.wikibase.getEntity(entityId)
	end
	local s = entity:getBestStatements(prop)
	if  s and #s>0 then
		if qualprop and s[1].qualifiers and s[1].qualifiers[qualprop] then
			local snak = s[1].qualifiers[qualprop][1]
			if format == 'noformat' then 

				return mw.wikibase.renderSnak( snak )
			else
				return mw.wikibase.formatValue( snak )
			end
		elseif not qualprop then 
			local snak = s[1]
if format == 'noformat' then

  				return mw.wikibase.renderSnak( snak )

else

return mw.wikibase.formatValue( snak )

end

		end
	end
	return nil
end

function p.main(frame)
	local args = getArgs(frame)
	if args.entityId and args.entityId ~= '' then
		entityId = args.entityId
	end
	if args[2] and args[2] ~= '' then
		prop = args[2]
	end
	if args[1] == 'zip' then
		qualprop= 'P281'
		out = getProp(prop,qualprop,entityId)
	elseif args[1] == 'streetnum' then
		qualprop= 'P969'
		out = getProp(prop,qualprop,entityId)
		if not out then
			out = getProp(prop,'P669',entityId)
			num = getProp(prop,'P670',entityId)
			if num then
				out = out .." "..num.."."
			end
		end
	elseif args[1] == 'country' then
		qualprop= 'P17'
		out = getProp(prop,qualprop,entityId,'noformat')
		if not out then
			if not entity then
				entity = mw.wikibase.getEntity(entityId)
			end
			local s = entity:getBestStatements(prop)
			if s and #s>0 then
				city = "Q" .. s[1].mainsnak.datavalue.value["numeric-id"]
				out = getProp(qualprop,nil,city,'noformat')
			end
		end
	end
	return out
end

return p