Module:Infobox mapframe: Difference between revisions

no edit summary
(Created page with "local mf = require('Module:Mapframe') local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local infoboxImage = require('Module:InfoboxImage').InfoboxImage -- Defaults local DEFAULT_FRAME_WIDTH = "270" local DEFAULT_FRAME_HEIGHT = "200" local DEFAULT_ZOOM = 10 local DEFAULT_GEOMASK_STROKE_WIDTH = "1" local DEFAULT_GEOMASK_STROKE_COLOR = "#777777" local DEFAULT_GEOMASK_FILL = "#888888" local DEFAULT_GEOMASK_FILL_OPACITY = "0.5" local...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 38: Line 38:


function getBestStatement(item_id, property_id)
function getBestStatement(item_id, property_id)
if not(item_id) or not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
if not(item_id) or not(mw..isValidEntityId(item_id)) or not(mw..entityExists(item_id)) then
return false
return false
end
end
local statements = mw.wikibase.getBestStatements(item_id, property_id)
local statements = mw..getBestStatements(item_id, property_id)
if not statements or #statements == 0 then
if not statements or #statements == 0 then
return false
return false
Line 145: Line 145:
maskItem = args.geomask
maskItem = args.geomask
elseif maskType == "property" then
elseif maskType == "property" then
maskItem = relatedEntity(args.id or mw.wikibase.getEntityIdForCurrentPage(), args.geomask)
maskItem = relatedEntity(args.id or mw..getEntityIdForCurrentPage(), args.geomask)
end
end
local maskItemLabel = maskItem and mw.wikibase.getLabel( maskItem )
local maskItemLabel = maskItem and mw..getLabel( maskItem )
return maskItemLabel and "Location in "..maskItemLabel or ""
return maskItemLabel and "Location in "..maskItemLabel or ""
end
end
Line 182: Line 182:
local config = trimArgs(_config)
local config = trimArgs(_config)
-- Require wikidata item, or specified coords
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage()
if not(wikidataId) and not(config.coord) then
return ''
end


-- Require coords (specified or from wikidata), so that map will be centred somewhere
-- Require coords (specified or from wikidata), so that map will be centred somewhere
Line 262: Line 257:
local maskItems = {}
local maskItems = {}
local maskItemId = relatedEntity(wikidataId, "P276") or  relatedEntity(wikidataId, "P131")  
local maskItemId = relatedEntity(wikidataId, "P276") or  relatedEntity(wikidataId, "P131")  
local maskLabel = mw.wikibase.getLabel(maskItemId)
local maskLabel = mw..getLabel(maskItemId)
while maskItemId and maskLabel and mw.text.trim(maskLabel) ~= "" do
while maskItemId and maskLabel and mw.text.trim(maskLabel) ~= "" do
table.insert(maskLabels, maskLabel)
table.insert(maskLabels, maskLabel)
table.insert(maskItems, maskItemId)
table.insert(maskItems, maskItemId)
maskItemId = maskItemId and relatedEntity(maskItemId, "P131")
maskItemId = maskItemId and relatedEntity(maskItemId, "P131")
maskLabel = maskItemId and mw.wikibase.getLabel(maskItemId)
maskLabel = maskItemId and mw..getLabel(maskItemId)
end
end
if #maskLabels > 1 then
if #maskLabels > 1 then
Line 285: Line 280:
if #maskItems > 1 then
if #maskItems > 1 then
for i, item in ipairs(maskItems) do
for i, item in ipairs(maskItems) do
table.insert(maskLabels, mw.wikibase.getLabel(item))
table.insert(maskLabels, mw..getLabel(item))
end
end
args.switch = table.concat(maskLabels, "###")
args.switch = table.concat(maskLabels, "###")