Jump to content

Module:Wikidata2/Aux

Gikan sa Wikipedia, ang gawasnong ensiklopedya

Documentation for this module may be created at Module:Wikidata2/Aux/doc

p = {}

local wikidata = require('Module:Wikidata2').formatStatementsFromLua


function p.data(frame)
	local args = frame.args
	if args[1] == 'ref' then
		local data = wikidata({entityId = args.item, property = args.property, sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518'})
		return data[1].ref
	end
	if args[1] == 'year' then
		local data = wikidata({entityId = args.item, property = args.property, sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', noref='true', modifyqualifiertime = 'Y'})
		return data[1].datum
	end
	if args[1] == 'number' then
		local data = wikidata({entityId = args.item, property = args.property, sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', noref='true'})
		if not data then 
			return nil
		end
		local data2 = tostring(data[1].amount)
		if string.sub(data2, 1, 1) == '+' then
			return string.sub(data2, 2)
		else
			return data2
		end
	end
	if args[1] == 'unit' then
		local data = wikidata({entityId = args.item, property = args.property, sortbytime = 'chronological', enbarten = 'yes', raw = 'true', avoidqualifier='P518', noref='true'})
		if data then
			return data[1].unit
		else
			return nil
		end
	end
	if args[1] == 'kommun' then
		local s = {}
		local data = wikidata({entityId = args.item, property = args.property, noref='true', avoidqualifier='P582', getonly=args.typ, claimindex=args.index})
		return data
	end
	if args[1] == 'bild' then
		local data = wikidata({entityId = args.item, property = 'P18', raw = 'true', noref='true', enbarten = 'true', langpref = 'en'})
		if data and #data > 0 then 
			return data[1].value
		end

	end
	if args[1] == 'bild2' then
		local data = wikidata({entityId = args.item, property = 'P18', raw = 'true', noref='true', enbarten = 'true', langpref = 'en'})
		if data and #data > 1 then 
			return data[2].value
		end

	end
	if args[1] == 'bildtext' then
		local data = wikidata({entityId = args.item, property = 'P18', raw = 'true', noref='true', enbarten = 'true', langpref = 'sv'})
		if #data > 0 then
			data = data[1]
			if data then
				return data.bildtext
			end
		end
	
	end
	if args[1] == 'bildtext2' then
		local data = wikidata({entityId = args.item, property = 'P18', raw = 'true', noref='true', enbarten = 'true', langpref = 'sv'})
		if #data > 1 then
			data = data[2]
			if data then
				return data.bildtext
			end
		end
	end
	return nil
end

return p