Module:Infobox mapframe and Module:Infobox mapframe/sandbox: Difference between pages
(Difference between pages)
imported>Hike395 rm controversial warning message |
imported>Hike395 fancy warning for missing coordinates |
||
| Line 1: | Line 1: | ||
-- Defaults | -- Defaults | ||
local DEFAULT_FRAME_WIDTH = "270" | local DEFAULT_FRAME_WIDTH = "270" | ||
| Line 86: | Line 81: | ||
return nil | return nil | ||
end | end | ||
end | |||
-- A local version of yesno() that trims blank space | |||
function util.yesNoBlank(s, default) | |||
local yesno = require('Module:Yesno') | |||
return yesno(mw.text.trim(s or ''), default) | |||
end | |||
-- Another version of yesno() that returns a ternary output, as two booleans | |||
-- It also accepts "none" as an alias for "no" | |||
function util.ternary(flag, other) | |||
other = other or 'other' | |||
flag = flag == 'none' and 'no' or flag | |||
local yesno = require('Module:Yesno') | |||
local yesNoOut = yesno(flag,other) | |||
local yes = (yesNoOut == true) | |||
local no = (yesNoOut == false) | |||
return yes, no | |||
end | end | ||
| Line 91: | Line 104: | ||
-- Check if should be running | -- Check if should be running | ||
local pargs = frame.getParent(frame).args | local pargs = frame.getParent(frame).args | ||
local explicitlyOn = | local explicitlyOn = util.yesNoBlank(pargs.mapframe) -- true or false or nil | ||
if pargs.coordinates == "{{{coordinates}}}" then explicitlyOn = false end | if pargs.coordinates == "{{{coordinates}}}" then explicitlyOn = false end | ||
local onByDefault = (explicitlyOn == nil) and | local onByDefault = (explicitlyOn == nil) and util.yesNoBlank(frame.args.onByDefault, false) -- true or false | ||
return explicitlyOn or onByDefault | return explicitlyOn or onByDefault | ||
end | end | ||
| Line 101: | Line 114: | ||
-- Frame arguments are default values which are overridden by parent values | -- Frame arguments are default values which are overridden by parent values | ||
-- when both are present | -- when both are present | ||
local getArgs = require('Module:Arguments').getArgs | |||
local args = getArgs(frame, {parentFirst = true}) | local args = getArgs(frame, {parentFirst = true}) | ||
| Line 115: | Line 129: | ||
elseif name == "id" or name == "qid" and not fixedArgs.id then | elseif name == "id" or name == "qid" and not fixedArgs.id then | ||
fixedArgs.id = val | fixedArgs.id = val | ||
-- remember whether mapframe was explicitly called | |||
elseif name == "mapframe" then | |||
fixedArgs.explicitlyOn = util.yesNoBlank(val) | |||
-- allow captionstyle to be unprefixed, for compatibility with [[Module:Infobox]] | -- allow captionstyle to be unprefixed, for compatibility with [[Module:Infobox]] | ||
elseif name == "captionstyle" and not fixedArgs.captionstyle then | elseif name == "captionstyle" and not fixedArgs.captionstyle then | ||
| Line 127: | Line 144: | ||
-- infoboxImage will format an image if given wikitext containing an | -- infoboxImage will format an image if given wikitext containing an | ||
-- image, or else pass through the wikitext unmodified | -- image, or else pass through the wikitext unmodified | ||
local infoboxImage = require('Module:InfoboxImage').InfoboxImage | |||
return infoboxImage({ | return infoboxImage({ | ||
args = { | args = { | ||
| Line 132: | Line 150: | ||
} | } | ||
}) | }) | ||
end | |||
function util.getParentTitle() | |||
local frame = mw.getCurrentFrame() | |||
local parent = frame and frame:getParent() | |||
return parent and parent:getTitle() | |||
end | end | ||
| Line 144: | Line 168: | ||
end | end | ||
function util.missingCoordinates(explicitlyOn) | |||
function util. | local parent = util.getParentTitle() | ||
local linkIfExists = require('Module:Link if exists')._main | |||
parent = parent and ' in '..linkIfExists({parent}) or '' | |||
local | return explicitlyOn and util.trackAndWarn('Pages using infobox mapframe with missing coordinates', | ||
local | 'No coordinates are specified or available from Wikidata: no mapframe will be shown'..parent..'.') | ||
or '' | |||
return | end | ||
end | |||
local p = {} | local p = {} | ||
| Line 197: | Line 220: | ||
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage() | local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage() | ||
if not(wikidataId) and not(config.coord) then | if not(wikidataId) and not(config.coord) then | ||
return false, util. | return false, util.missingCoordinates(config.explicitlyOn) | ||
end | end | ||
| Line 204: | Line 227: | ||
local wdCoordinates = util.getStatementValue(util.getBestStatement(wikidataId, 'P625')) | local wdCoordinates = util.getStatementValue(util.getBestStatement(wikidataId, 'P625')) | ||
if not (config.coord or wdCoordinates) then | if not (config.coord or wdCoordinates) then | ||
return false, util. | return false, util.missingCoordinates(config.explicitlyOn) | ||
end | end | ||
| Line 436: | Line 459: | ||
args["frame-long"] = args["frame-long"] or "" | args["frame-long"] = args["frame-long"] or "" | ||
local mf = require('Module:Mapframe') | |||
local mapframe = args.switch and mf.multi(args) or mf._main(args) | local mapframe = args.switch and mf.multi(args) or mf._main(args) | ||
tracking = tracking..((showLine or showShape) and not wikidataProvidesGeo | tracking = tracking..((showLine or showShape) and not wikidataProvidesGeo | ||