Module:Sandbox/Stibba0/Wikidata

Revision as of 18:29, 12 December 2018 by imported>Stibba0 (Changed vars to local vars)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Stibba0/Wikidata/doc

local getInformation = function(ID, pID, link) 
	local infoTable = mw.wikibase.getBestStatements(ID, pID)
	local valuesString = ""
	for idx, v in pairs(infoTable) do
		if not( v == nil) then
			if idx > 1 then
				valuesString = valuesString .. "<br>"	
			end
			if not( mw.wikibase.getSitelink( v.mainsnak.datavalue.value.id ) == nil) and link then
				valuesString = valuesString .. "[[" .. mw.wikibase.getSitelink( v.mainsnak.datavalue.value.id ) .. "]]"
			else
				valuesString = valuesString .. mw.wikibase.getLabel( v.mainsnak.datavalue.value.id)	
			end
		end
	end
	return valuesString or ""
end

p = {}

p.getWikidata = function(frame) 
	local entityID = frame.args.entityid
	local first = getInformation(entityID, "P735", false)
	local family = getInformation(entityID, "P734", false)
	local occupation = getInformation(entityID, "P106", true)
	local birthPlace = getInformation(entityID, "P19", true)
	local spouse = getInformation(entityID, "P26", true)
	
	fullTable = "{| class=\"wikitable\" \
		|+ Wikidata for " .. first .. " " .. family .. "\
		|- \
		| Name || " .. first .. " " .. family .. "\
		|- \
		| Place of birth || " .. birthPlace .. "\
		|- \
		| Occupation || " .. occupation .. "\
		|- \
		| Spouse ||" .. spouse .. "\
		|} " 
	
	return fullTable
end


return p