Módulo:Marker
Version check
Designación de la versión en Wikidata: 2024-04-19
Este módulo está desactualizado/obsoleto
Uso
This modules creates markers on maps. It's used by the template Marker.Esta documentación está transcluida desde Módulo:Marker/doc.
Los editores pueden experimentar en la zona de pruebas (crear) y en los casos de prueba (crear) del módulo.
Por favor, añade las categorías en la subpágina de documentación. Subpáginas de este módulo.
Los editores pueden experimentar en la zona de pruebas (crear) y en los casos de prueba (crear) del módulo.
Por favor, añade las categorías en la subpágina de documentación. Subpáginas de este módulo.
-- module variable and administration
local mk = {
moduleInterface = {
suite = 'Marker',
serial = '2024-01-03',
item = 40852170
}
}
-- module import
local mi = require( 'Module:Marker utilities/i18n' )
local mu = require( 'Module:Marker utilities' )
local mp = require( 'Module:Marker/Params' )
local cm = require( 'Module:CountryData' )
local wu -- for Module:Wikidata utilities
-- adding from-WD class
local function addWdClass( key )
return mu.addWdClass( mp.wdContent[ key ] )
end
-- taking mp.ynCheckList into account
local function checkYn( args )
local s
for i, key in ipairs( mp.ynCheckList ) do
args[ key ] = args[ key ] or ''
s = mu.yesno( args[ key ] )
if s then -- 'y' or 'n'
args[ key ] = ''
mp.wdContent[ key ] = s == 'y'
elseif args[ key ] ~= '' then
mp.wdContent[ key ] = false
end
end
end
local function initialParametersCheck( frame )
local entity = nil
local wrongQualifier = false
local show = {}
-- checking keys and copying values to args
local args = mu.checkArguments( frame:getParent().args, mp.p )
-- removing control characters
local descrDiv
for key, v in pairs( mp.p ) do
if args[ key ] and args[ key ] ~= '' then
args[ key ], descrDiv = mu.removeCtrls( args[ key ], true )
else
args[ key ] = ''
end
end
-- checking Wikidata entitity
if args.wikidata ~= '' then
wu = require( 'Module:Wikidata utilities' )
-- args.wikidata, entity, wrongQualifier = wu.getEntityId( args.wikidata or '' )
args.wikidata, entity, wrongQualifier = wu.getEntity( args.wikidata or '' )
if wrongQualifier then
mu.addMaintenance( 'wrongQualifier' )
elseif args.wikidata ~= '' then
mu.addMaintenance( 'wikidata' )
end
end
-- checking show parameter
show = mu.getShow( mp.defaultShow, args, mp.show )
-- y/n allow/disallow output
if not mu.isSet( args.nameLocal ) then
args.nameLocal = 'n'
end
checkYn( args )
args.noGpx = mu.yesno( args.noGpx ) == 'y'
args.zoom = math.floor( tonumber( args.zoom ) or mi.defaultZoomLevel )
if args.zoom < 0 or args.zoom > mi.maxZoomLevel then
args.zoom = mi.defaultZoomLevel
end
-- checking coordinates and converting DMS to decimal coordinates if necessary
mu.checkCoordinates( args )
-- removing namespace from category
mu.checkCommonsCategory( args )
for i, param in ipairs( mi.options.parameters ) do
if mu.isSet( args[ param ] ) then
mu.addMaintenance( 'parameterUsed', param )
end
end
if mu.isSet( args.styles ) then
args.styles = mi.nameStyles[ args.styles:lower() ] or args.styles
else
args.styles = nil
end
return args, entity, show
end
-- getting data from Wikidata
local function getDataFromWikidata( args, show, page, country, entity )
if args.wikidata == '' then
return
end
if args.type == '' then
local p31 = wu.getValues( entity, mi.properties.instanceOf, mi.p31Limit )
args.type = mu.typeSearch( p31, entity )
end
args.nameLocal = mp.wdContent.nameLocal or args.nameLocal
mu.getNamesFromWikidata( args, mp.wdContent, page, country, entity )
mu.getCoordinatesFromWikidata( args, mp.wdContent, entity )
mu.getCommonsCategory( args, entity )
if show.name then
mu.getArticleLink( args, entity, page )
end
-- getting more values from Wikidata
local c
for key, value in pairs( mp.wdContent ) do
if not args[ key ] or args[ key ] == '' then
if key == 'image' or key == 'rss' then
args[ key ] = wu.getValue( entity, mp.wd[ key ].p )
elseif value and mp.wd[ key ] and show.name then
c = tonumber( mp.wd[ key ].c ) or 1
c = wu.getValues( entity, mp.wd[ key ].p, c )
args[ key ] = table.concat( c, ', ' )
if args[ key ] ~= '' and mp.wd[ key ].f then
args[ key ] = mp.wd[ key ].f:format( args[ key ] )
end
end
mp.wdContent[ key ] = args[ key ] ~= ''
end
end
end
local function finalParametersCheck( args, show, country, entity )
-- coordinates are neccessary
show.noCoord = args.lat == '' or args.long == ''
if show.noCoord then
show.name = 1
show.poi = false
show.coord = false
mu.addMaintenance( 'missingCoord' )
end
-- image check
if not mp.wdContent.image or mi.options.WDmediaCheck then
mu.checkImage( args, entity )
end
-- status check
mu.checkStatus( args )
-- getting Marker type and group
mu.checkTypeAndGroup( args )
if mi.options.useTypeCateg and args.typeTable then
for i, tp in ipairs( args.typeTable ) do
mu.addMaintenance( 'type', tp )
end
end
-- url check
mu.checkUrl( args )
-- creating givenName, displayName tables
mu.prepareNames( args )
end
local function insertCoordinates( result, args, country, noBrackets )
mu.tableInsert( result, mu.dmsCoordinates( args.lat, args.long,
args.givenName.name, mp.wdContent.lat, country.extra, noBrackets ) )
end
-- distinguishing marker symbols, default: number
local function makeMarkerProperties( args, show )
if args.symbol == '' and show.poi and show.symbol then
args.symbol = mu.getMakiIconId( args.typeTable[ 1 ] ) or ''
end
if args.symbol == '' or args.symbol == 'number' then
args.symbol = '-number-' .. args.group
elseif args.symbol == 'letter' then
args.symbol = '-letter-' .. args.group
elseif args.symbol:len() == 1 and args.symbol:match( '%w' ) then
args.text = args.symbol:upper()
mu.addMaintenance( 'numberUsed' )
elseif args.symbol ~= '' and args.text == '' and mu.getMaki( args.symbol ) then
mu.addIconToMarker( args )
elseif args.symbol ~= '' and not mu.getMaki( args.symbol ) then
args.symbol = 'cross'
args.group = 'error'
args.text = mi.texts.closeX
mu.getColor( args )
mu.addMaintenance( 'unknownIcon' )
end
end
local function makeMarkerAndName( args, show, page, country, entity, frame )
local result = {} -- output string table, wrapper is added later
-- adding status icons
mu.tableInsert( result, mu.makeStatusIcons( args ) )
-- adding marker symbol
if show.poi or mu.isSet( args.copyMarker ) then
makeMarkerProperties( args, show )
table.insert( result, mu.makeMarkerSymbol( args, args.givenName.all, frame ) )
end
-- adding name, airport code, sister-project icons, and coordinate
if show.name then
local r = {}
local nameClass = addWdClass( 'name' )
if not show.noCoord and not show.poi and not show.coord then
nameClass = nameClass .. ' listing-without-marker'
end
if args.displayName.all ~= '' or args.nameExtra ~= '' or args.nameLocal ~= '' then
mu.makeName( r, args, show, page, country, nameClass, addWdClass( 'nameLocal' ) )
elseif args.url ~= '' then
table.insert( r, mu.makeSpan( '[' .. args.url .. ']', 'listing-url' ) )
end
r = table.concat( r, mi.texts.space )
local icons = {}
local onlyWikidata = mi.options.showSisters and not show.nositelinks and
mu.makeSisterIcons( icons, args, page, country, entity )
mu.makeSocial( icons, args, mp.wdContent, args.givenName.name )
if #icons > 0 then
r = r .. ( onlyWikidata and '' or mi.texts.space ) .. table.concat( icons, '' )
end
mu.tableInsert( result, r )
-- adding coordinate if requested and available
if show.coord then
insertCoordinates( result, args, country )
end
-- adding coordinate only
elseif show.coord then
insertCoordinates( result, args, country, true )
end
return table.concat( result, mi.texts.space )
end
local function makeMaintenance( page )
if mi.nsNoMaintenance[ page.namespace ] then
return ''
end
local r= mu.getMaintenance()
if mi.options.usePropertyCateg then
local m = mi.maintenance.properties -- format string
r = r .. ( wu and wu.getCategories( m ) or '' )
.. mu.getCategories( m ) .. cm.getCategories( m )
end
return r
end
-- main marker function
function mk.marker( frame )
mu.initMaintenance()
local page = mu.getPageData()
-- copying frame:getParent().args to template arguments, args, parameter check
-- returning Wikidata entity and display options
local args, mkEntity, show = initialParametersCheck( frame )
show.inline = true
-- getting country-specific technical parameters
local country = cm.getCountryData( mkEntity, nil, args.country )
if country.unknownCountry then
mu.addMaintenance( 'unknownCountry' )
end
-- for map support
country.extra = mi.defaultSiteType
if mu.isSet( country.iso_3166 ) then
country.extra = country.extra .. '_region:' .. country.iso_3166
end
-- add additional parameters
-- associated Wikivoyage page of the location in current Wikivoyage branch
-- possibly modified by mu.getArticleLink()
args.wikiPage = ''
getDataFromWikidata( args, show, page, country, mkEntity )
if args.commonscat ~= '' then
args.commonscat = args.commonscat:gsub( ' ', '_' )
end
-- parameter check after data import from Wikidata
finalParametersCheck( args, show, country, mkEntity )
-- generating output
local result = makeMarkerAndName( args, show, page, country, mkEntity, frame )
-- removing succeeding brackets
result = result:gsub( '%)(</span>)%s*(<span [^>]*>)%(', '%1; %2' )
return mu.makeWrapper( result, args, page, country, show, mp.markerData, 'Marker', frame )
.. makeMaintenance( page )
end
return mk