Mô đun:GoogleMapsLinks
Giao diện
local p = {}
-- note: P17 is the country property ID on wd
local function getP17(qid)
if not qid or qid == '' then return nil end
local ok, entity = pcall(mw.wikibase.getEntity, qid)
if not ok or not entity or not entity.claims or not entity.claims.P17 then
return nil
end
local claim = entity.claims.P17[1]
if claim and claim.mainsnak and claim.mainsnak.datavalue then
return claim.mainsnak.datavalue.value.id
end
return nil
end
local function getCountryQid(listingQid)
local countryQid = nil
if listingQid then
countryQid = getP17(listingQid)
end
if not countryQid then
local pageQid = mw.wikibase.getEntityIdForCurrentPage()
if pageQid then
countryQid = getP17(pageQid)
end
end
return countryQid
end
function p.gmaps(frame)
local args = frame.args
local lat, long = args.lat, args.long
if not lat or not long or lat == '' or long == '' or lat == 'NA' or long == 'NA' then
return ''
end
local gmapParam = args.gmap or 'yes'
if string.lower(gmapParam) == 'no' then return '' end
local countryQid = getCountryQid(args.wikidata)
-- note: Q148 is China, Q884 is SK, Q241 is Iran, Q794 is Cuba
if countryQid == 'Q148' or countryQid == 'Q884' or countryQid == 'Q241' or countryQid == 'Q794' then
return ''
end
return string.format(
' [[File:Google Maps icon (2020).svg|10px|class=listing-sister|link=https://www.google.com/maps/dir/?api=1&destination=%s,%s|Chỉ đường trên Google Maps]]',
lat, long
)
end
return p