Hoppa till innehållet

Modul:KML faktaruta

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


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

p = {}

function p.main(entity)
	local p3096 = wikidata({entity = entity, property = 'P3096', raw = 'true', enbarten = 'true', noref = 'true'})
	if p3096 and #p3096 > 0 then
		local siteurl, siteshort, sitetitle = wow(p3096[1].item)
		if siteurl then
			local kml_url = "https://tools.wmflabs.org/wp-world/googlmaps-proxy.php?page=https%3A%2F%2F" .. siteurl .. "%2Fw%2Findex.php%3Ftitle%3D" .. mw.uri.encode( sitetitle, "WIKI" ) .. "%26action=raw&output=classic"
			local a = mw.text.tag('td', {style="border-top:0;"}, '[[Fil:Map-icon.svg|24px|link=]]')
			a = a .. mw.text.tag('td', {style="border-right:solid 1px gray; border-top:0; padding-right:5px;", align="center"}, 'Se kartdata överlagrat på...<br /> [' .. kml_url .. ' Google]')
			a = a .. mw.text.tag('td', {style="border-top:0;"}, '[[' .. siteshort .. sitetitle .. '|Kartdata]]')
			a = mw.text.tag('tr', {}, a)
			a = mw.text.tag('table', {style="line-height:110%; font-size:80%; border:0;"}, a)
			a = mw.text.tag('div', {}, a)
			return a
		end
	else
		return nil
	end
	return nil
end

function wow(qid)
	local sites = {}
	sites[1] = { "svwiki", "sv.wikipedia.org", "" }
	sites[2] = { "enwiki", "en.wikipedia.org", ":en:" }
	sites[3] = { "bnwiki", "bn.wikipedia.org", ":bn:" }
	sites[4] = { "cswiki", "cs.wikipedia.org", ":cs:" }
	sites[5] = { "fawiki", "fa.wikipedia.org", ":fa:" }
	sites[6] = { "frwiki", "fr.wikipedia.org", ":fr:" }
	sites[7] = { "jawiki", "ja.wikipedia.org", ":ja:" }
	sites[8] = { "mlwiki", "ml.wikipedia.org", ":ml:" }
	sites[9] = { "zhwiki", "zh.wikipedia.org", ":zh:" }
	sites[10] = { "commonswiki", "commons.wikimedia.org", "c:" }
	
	local ent = mw.wikibase.getEntityObject(qid)
	if ent and ent.sitelinks then
		for i, j in pairs(sites) do
			if ent.sitelinks[j[1]] then
				return j[2], j[3], ent.sitelinks[j[1]].title
			end
		end
	else
		return nil, nil, nil
	end
	return nil, nil, nil
end

return p