Module:Infobox mapframe: திருத்தங்களுக்கு இடையிலான வேறுபாடு

உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
imported>Kanags
சிNo edit summary
imported>Balajijagadesh
சி en:Module:Infobox_mapframe இலிருந்து திருத்தம் இறக்குமதி செய்யப்பட்டன
 
வரிசை 11:
local DEFAULT_GEOMASK_STROKE_COLOR = "#777777"
local DEFAULT_GEOMASK_FILL = "#888888"
local DEFAULT_GEOMASK_FILL_OPACITY = "0.525"
local DEFAULT_SHAPE_STROKE_WIDTH = "32"
local DEFAULT_SHAPE_STROKE_COLOR = "#FF0000"
local DEFAULT_SHAPE_FILL = "#606060"
local DEFAULT_SHAPE_FILL_OPACITY = "0.51"
local DEFAULT_LINE_STROKE_WIDTH = "5"
local DEFAULT_LINE_STROKE_COLOR = "#FF0000"
local DEFAULT_MARKER_COLOR = "#5E74F3"
 
local util = {}
 
function util.noop(info)
local DEFAULT_NOOP_OUTPUT = ""
 
-- uncomment this when debugging
-- DEFAULT_NOOP_OUTPUT = "debug: mapframe no-op: " .. info
-- mw.log(DEFAULT_NOOP_OUTPUT)
 
return DEFAULT_NOOP_OUTPUT
end
 
-- Trim whitespace from args, and remove empty args
function util.trimArgs(argsTable)
local cleanArgs = {}
for key, val in pairs(argsTable) do
வரி 37 ⟶ 48:
end
 
function util.getBestStatement(item_id, property_id)
if not(item_id) or not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
return false
வரி 52 ⟶ 63:
end
 
function util.hasWikidataProperty(item_id, property_id)
return util.getBestStatement(item_id, property_id) and true or false
end
 
function util.getStatementValue(statement)
return statement and statement.mainsnak and statement.mainsnak.datavalue and statement.mainsnak.datavalue.value or nil
end
 
function util.relatedEntity(item_id, property_id)
local value = util.getStatementValue( util.getBestStatement(item_id, property_id) )
return value and value.id or false
end
 
function util.idType(id)
if not id then
return nil
வரி 77 ⟶ 88:
end
 
function util.shouldAutoRun(frame)
 
 
function shouldAutoRun(frame)
-- Check if should be running
local pargs = frame.getParent(frame).args
வரி 88 ⟶ 97:
end
 
function util.argsFromAuto(frame)
-- Get args from the frame (invoke call) and the parent (template call).
-- Frame arguments are default values which are overridden by parent values
-- when both are present
local args = getArgs(frame, {parentFirst = true})
 
-- Discard args not prefixed with "mapframe-", remove that prefix from those that remain
local fixedArgs = {}
வரி 106 ⟶ 115:
elseif name == "id" or name == "qid" and not fixedArgs.id then
fixedArgs.id = val
-- allow captionstyle to be unprefixed, for compatibility with [[Module:Infobox]]
elseif name == "captionstyle" and not fixedArgs.captionstyle then
fixedArgs.captionstyle = val
end
end
return fixedArgs
end
 
 
function util.parseCustomWikitext(customWikitext)
-- infoboxImage will format an image if given wikitext containing an
-- image, or else pass through the wikitext unmodified
return infoboxImage({
args = {
image = customWikitext
}
})
end
 
function util.trackAndWarn(trackingCat, warning)
local title = mw.title.getCurrentTitle()
local results = title and title.namespace == 0 and trackingCat and '[[Category:'..trackingCat..']]' or ''
if warning then
local warn = require('Module:If preview')._warning
results = results..warn({warning})
end
return results
end
 
 
function util.ternary(flag, other)
other = other or 'other'
flag = flag == 'none' and 'no' or flag
local yesNoOut = yesno(flag,other)
local yes = (yesNoOut == true)
local no = (yesNoOut == false)
return yes, no
end
 
local p = {}
 
 
p.autocaption = function(frame)
p._caption = function(args)
if not shouldAutoRun(frame) then return "" end
local args = argsFromAuto(frame)
if args.caption then
return args.caption
elseif args.switcher then
return util.noop("no caption or switcher")
end
local maskItem
local maskType = util.idType(args.geomask)
if maskType == 'item' then
maskItem = args.geomask
elseif maskType == "property" then
maskItem = util.relatedEntity(args.id or mw.wikibase.getEntityIdForCurrentPage(), args.geomask)
end
local maskItemLabel = maskItem and mw.wikibase.getLabel( maskItem )
return maskItemLabel and "Location in "..maskItemLabel or ""
or util.noop("missing maskItemLabel with type " .. (maskType or "nil") .. " and item " .. (maskItem or "nil"))
end
 
function parseCustomWikitext(customWikitext)
-- infoboxImage will format an image if given wikitext containing an
-- image, or else pass through the wikitext unmodified
return infoboxImage({
args = {
image = customWikitext
}
})
end
 
p.auto = function(frame)
if not shouldAutoRun(frame) then return "" end
local args = argsFromAuto(frame)
if args.custom then
return frame:preprocess(parseCustomWikitext(args.custom))
end
local mapframe = p._main(args)
return frame:preprocess(mapframe)
end
 
p.main = function(frame)
local parent = frame.getParent(frame)
local parentArgs = parent.args
local mapframe = p._main(parentArgs)
return frame:preprocess(mapframe)
end
 
--A list of types for objects that are too small to allow Kartographer to take over zoom
வரி 169 ⟶ 186:
 
p._main = function(_config)
-- accumulate tracking cats
local tracking = ''
-- `config` is the args passed to this module
local config = util.trimArgs(_config)
-- allow alias for config.coord
வரி 178 ⟶ 197:
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage()
if not(wikidataId) and not(config.coord) then
return false, util.trackAndWarn('Pages using infobox mapframe with missing coordinates')
return ''
end
 
-- Require coords (specified or from wikidata), so that map will be centred somewhere
-- (P625 = coordinate location)
local hasCoordinateswdCoordinates = hasWikidataPropertyutil.getStatementValue(util.getBestStatement(wikidataId, 'P625') or config.coord)
if not (config.coord or wdCoordinates) then
if not hasCoordinates then
return false, util.trackAndWarn('Pages using infobox mapframe with missing coordinates')
return ''
end
 
வரி 199 ⟶ 218:
args["frame-align"] = "center"
 
args["frame-coord"] = config["frame-coordinates"] or config["frame-coord"] or ""
-- Note: config["coordinates"] or config["coord"] should not be used for the alignment of the frame;
-- see talk page ( https://en.wikipedia.org/wiki/Special:Diff/876492931 )
 
-- deprecated lat and long parameters
args["frame-lat"] = config["frame-lat"] or config["frame-latitude"] or ""
args["frame-long"] = config["frame-long"] or config["frame-longitude"] or ""
 
-- if zoom isn't specified from config:, first check wikidata
local zoom = config.zoom or util.getStatementValue(util.getBestStatement(wikidataId, 'P6592'))
if not zoom then
-- Calculate zoom from length or area (converted to km or km2)
வரி 218 ⟶ 237:
area_ha=config.area_ha, area_acre=config.area_acre,
type=config.type, population=config.population,
viewport_px=math.min(args["frame-width"],args["frame-height"])}),
latitude=wdCoordinates and wdCoordinates.latitude})
end
args.zoom = zoom or DEFAULT_ZOOM
வரி 224 ⟶ 244:
-- Use OSM relation ID if available; otherwise use geoshape if that is available
-- (geoshape is required for defunct entities, which are outside OSM's scope)
local hasOsmRelationId = util.hasWikidataProperty(wikidataId, 'P402') -- P402 is OSM relation ID
local hasGeoshape = util.hasWikidataProperty(wikidataId, 'P3896') -- P3896 is geoshape
local wikidataProvidesGeo = hasOsmRelationId or hasGeoshape
local shouldShowPointMarker;
 
-- determine marker argument value, determine whether to show marker
local pointValueforcePoint, suppressPoint = util.ternary(config.point)
local forceMarker, suppressMarker = util.ternary(config.marker,true)
if pointValue == 'none' then
pointValue = 'no'
end
pointValue = yesno(pointValue,'other')
local markerValue = config.marker
if markerValue == 'none' then
markerValue = 'no'
end
markerValue = yesno(markerValue,true)
 
forcePoint = forcePoint or forceMarker
if pointValue == true then
suppressPoint = suppressPoint or suppressMarker
shouldShowPointMarker = true
 
elseif pointValue == false then
local showMarker = not suppressPoint and (forcePoint or not wikidataProvidesGeo or config.coord)
shouldShowPointMarker = false
else
-- wikidata = "yes" turns on both shape and line
shouldShowPointMarker = not(wikidataProvidesGeo) or markerValue or config.coord
-- wikidata = "no" turns off both shape and line
end
-- otherwise show both if wikidata provides geo
local forceWikidata, suppressWikidata = util.ternary(config.wikidata)
local showShape = not suppressWikidata and (forceWikidata or wikidataProvidesGeo or not config.coord)
local showLine = showShape
 
-- determine shape parameter value, determine whether to show or suppress shape
-- also determine whether to invert shape
local shapeValueforceShape, suppressShape = util.ternary(config.shape)
showShape = wikidataId and not suppressShape and (forceShape or showShape)
if shapeValue == 'none' then
shapeValue = 'no'
end
shapeValue = yesno(shapeValue,'other')
 
local forceShape = shapeValue == true and wikidataProvidesGeo
local suppressShape = shapeValue == false
local shapeType = config.shape == 'inverse' and 'shape-inverse' or 'shape'
 
-- determine line parameter value, determine whether to show or suppress line
local lineValueforceLine, suppressLine = util.ternary(config.line)
showLine = wikidataId and not suppressLine and (forceLine or showLine)
if lineValue == 'none' then
lineValue = 'no'
end
local lineValue = yesno(lineValue,'other')
 
local maskItem
local forceLine = lineValue == true and wikidataProvidesGeo
local suppressLine = lineValue == false
 
-- determine whether to use wikidata (independent of shape/line)
local maskItem
local useWikidata = wikidataId -- by default, if wikidata is supplied, use wikidata
-- But do not use wikidata when local coords are specified (and not turned off), unless explicitly set
if useWikidata and config.coord and shouldShowPointMarker then
useWikidata = yesno(config.wikidata,true)
end
-- Switcher
if config.switcher == "zooms" then
வரி 293 ⟶ 289:
local maskLabels = {}
local maskItems = {}
local maskItemId = util.relatedEntity(wikidataId, "P276") or util.relatedEntity(wikidataId, "P131")
local maskLabel = mw.wikibase.getLabel(maskItemId)
while maskItemId and maskLabel and mw.text.trim(maskLabel) ~= "" do
table.insert(maskLabels, maskLabel)
table.insert(maskItems, maskItemId)
maskItemId = maskItemId and util.relatedEntity(maskItemId, "P131")
maskLabel = maskItemId and mw.wikibase.getLabel(maskItemId)
end
வரி 326 ⟶ 322:
-- resolve geomask item id (if not using geomask switcher)
if not maskItem then --
local maskType = util.idType(config.geomask)
if maskType == 'item' then
maskItem = config.geomask
elseif maskType == "property" then
maskItem = util.relatedEntity(wikidataId, config.geomask)
end
end
வரி 340 ⟶ 336:
-- and if the object size inferred from its type is not too small
-- then let Kartographer "take over" zoom
if (forceLineshowLine or forceShapeshowShape) orand (useWikidatawikidataProvidesGeo and not (suppressShape and suppressLine)))maskItem
and wikidataProvidesGeonot config.zoom and not maskItem(config.type and not tinyType[config.zoomtype]) then
and not (config.type and tinyType[config.type]) then
args.zoom = nil
end
 
if not maskItem and not showShape and not showLine and not showMarker then
return false, util.trackAndWarn('Pages using infobox mapframe with no geometry','No geometry specified for mapframe')
end
-- Keep track of arg numbering
வரி 370 ⟶ 369:
args["frame-lat"] = nil
args["frame-long"] = nil
local maskArea = util.getStatementValue( util.getBestStatement(maskItem, 'P2046') )
end
incrementArgNumber()
வரி 383 ⟶ 382:
-- Shape (or shape-inverse)
if showShape then
if forceShape or (useWikidata and not suppressShape) then
args["type"..argNumber] = shapeType
if hasGeoshape and not hasOsmRelationId then
args["from"..argNumber] = string.sub( util.getStatementValue( util.getBestStatement(wikidataId, 'P3896') ), 6)
elseif config.id then
args["id"..argNumber] = config.id
வரி 398 ⟶ 397:
-- Line
if showLine then
if forceLine or (useWikidata and not suppressLine) then
args["type"..argNumber] = "line"
if hasGeoshape and not hasOsmRelationId then
args["from"..argNumber] = string.sub( util.getStatementValue( util.getBestStatement(wikidataId, 'P3896') ), 6)
elseif config.id then
args["id"..argNumber] = config.id
வரி 410 ⟶ 409:
end
 
-- Point marker
if shouldShowPointMarkershowMarker then
args["type"..argNumber] = "point"
if config.id then args["id"..argNumber] = config.id end
வரி 419 ⟶ 418:
incrementArgNumber()
end
 
-- if Wikidata doesn't link to OSM and the map has no mask or point,
-- then center the map on the coordinates either from the infobox or from wikidata
if not maskItem and not showMarker and not wikidataProvidesGeo then
if config.coord then
args["frame-coord"] = args["frame-coord"] or config.coord
else
args["frame-lat"] = args["frame-lat"] or wdCoordinates.latitude
args["frame-long"] = args["frame-long"] or wdCoordinates.longitude
end
tracking = tracking..util.trackAndWarn('Pages using infobox mapframe with forced centering')
end
 
-- protect against nil frame arguments
args["frame-coord"] = args["frame-coord"] or ""
args["frame-lat"] = args["frame-lat"] or ""
args["frame-long"] = args["frame-long"] or ""
 
local mapframe = args.switch and mf.multi(args) or mf._main(args)
tracking = tracking..((showLine or showShape) and not wikidataProvidesGeo
local tracking = hasOsmRelationId and '' or '[[Category:Infobox mapframe without OSM relation ID on Wikidata]]'
and util.trackAndWarn('Pages using infobox mapframe without shape links in Wikidata')
return mapframe .. tracking
or '')
return true, mapframe.. tracking
end
 
-- Entry points
 
p.main = function(frame)
local parent = frame.getParent(frame)
local parentArgs = parent.args
local _, mapframe = p._main(parentArgs)
return frame:preprocess(mapframe)
end
 
p.auto = function(frame)
if not util.shouldAutoRun(frame) then
return util.noop("auto should not autorun")
end
local args = util.argsFromAuto(frame)
if args.custom then
return frame:preprocess(util.parseCustomWikitext(args.custom))
end
local _, mapframe = p._main(args)
return frame:preprocess(mapframe)
end
 
p.autocaption = function(frame)
if not util.shouldAutoRun(frame) then
return util.noop("autocaption should not autorun")
end
local args = util.argsFromAuto(frame)
local caption = p._caption(args)
return caption
end
 
p.autoWithCaption = function(frame)
if not util.shouldAutoRun(frame) then
return util.noop("autoWithCaption should not autorun")
end
local args = util.argsFromAuto(frame)
local wikitext
local caption
local ok
if args.custom then
ok = true
wikitext = util.parseCustomWikitext(args.custom)
else
ok, wikitext = p._main(args)
end
if not ok then return wikitext end
wikitext = frame:preprocess(wikitext)
caption = p._caption(args)
local data = mw.html.create():wikitext(wikitext)
data:tag('div')
:addClass('infobox-caption')
:cssText(args.captionstyle)
:wikitext(caption)
return tostring(data)
end
return p
"https://tamilar.wiki/w/Module:Infobox_mapframe" இலிருந்து மீள்விக்கப்பட்டது