Módulo:Marker
Version check
Designación de la versión en Wikidata: 2022-07-03
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 = '2022-05-14',
item = 40852170
}
}
-- module import
-- require( 'Module:No globals' )
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 = require( 'Module:Wikidata utilities' )
local function checkYn( keys, args )
local s
for _, key in ipairs( keys ) 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 initialParameterCheck( 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 )
-- remove control characters
for key, _ in pairs( mp.p ) do
if args[ key ] then
args[ key ], _ = mu.removeCtrls( args[ key ], true )
else
args[ key ] = ''
end
end
-- checking show and format parameters
if mu.isSet( args.show ) then
show = mu.getShow( mp.defaultShow, args.show, mp.show )
if show.noname then
show.noname = nil
show.name = nil
end
if not show.poi and not show.coord then
mu.addMaintenance( mi.maintenance.showNoneUsed )
end
else
show.poi = true
show.name = true
if args.format:match( mp.allowedFormats ) then
show.name = nil
mu.addMaintenance( mi.maintenance.poiMode )
elseif mu.isSet( args.format ) then
mu.addMaintenance( mi.maintenance.unknownFormat )
end
end
-- checking Wikidata entitity
-- args.wikidata, entity, wrongQualifier = wu.getEntityId( args.wikidata or '' )
args.wikidata, entity, wrongQualifier = wu.getEntity( args.wikidata or '' )
if wrongQualifier then
mu.addMaintenance( mi.maintenance.wrongQualifier )
elseif args.wikidata ~= '' then
mu.addMaintenance( mi.maintenance.wikidata )
end
-- treatment of social media services
if args.wikidata ~= '' and show.socialmedia then
for _, value in ipairs( mp.socialMedia ) do
args[ value ] = 'y'
end
end
-- y/n allow/disallow output
if not mu.isSet( args.nameLocal ) then
args.nameLocal = 'n'
end
checkYn( mp.ynCheckList, 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 )
-- remove namespace from category
mu.checkCommonsCategory( args )
for _, param in ipairs( mi.maintenance.parameters ) do
if mu.isSet( args[ param ] ) then
mu.addMaintenance( mw.ustring.format( mi.maintenance.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 ] = mw.ustring.format( mp.wd[ key ].f, args[ key ] )
end
end
mp.wdContent[ key ] = args[ key ] ~= ''
end
end
end
local function finalParameterCheck( args, show, country, entity )
-- coordinates are neccessary
show.noCoord = args.lat == '' or args.long == ''
if show.noCoord then
show.name = ''
show.poi = false
show.coord = false
mu.addMaintenance( mi.maintenance.missingCoord )
end
-- image check
if not mp.wdContent.image or mi.options.WDmediaCheck then
args.image = mu.checkImage( args.image, entity )
end
-- status check
mu.checkStatus( args )
-- getting Marker type and group
mu.checkTypeAndGroup( args )
if mi.options.useTypeCateg and args.typeTable then
for _, aType in ipairs( args.typeTable ) do
mu.addMaintenance( mw.ustring.format( mi.maintenance.type, aType ) )
end
end
-- url check
args.url = mu.checkUrl( args.url )
-- checking name existence, splitting name and link from [[link|name]]
if args.name == '' then
args.name = mi.maintenance.missingName
mu.addMaintenance( mi.maintenance.missingNameMsg )
end
if args.name:find( '<', 1, true ) or args.name:find( '{{', 1, true ) or
args.alt:find( '<', 1, true ) or args.alt:find( '{{', 1, true ) then
mu.addMaintenance( mi.maintenance.malformedName )
end
args.alt = mu.removeStars( args.alt )
args.nameExtra = mu.removeStars( args.nameExtra )
args.givenName = mu.getName( args.alt, args.wikiPage )
args.displayName = mu.getName( args.name, args.wikiPage )
if not args.givenName.exists then
args.givenName = args.displayName
end
if args.nameLocal ~= '' and args.givenName.name == args.nameLocal then
args.nameLocal = ''
end
if args.symbol == '' and show.poi and show.symbol then
args.symbol = mu.getMakiIconName( args.type ) or ''
end
end
-- distinguishing marker symbols, default: number
local function makeMarkerProperties( args )
args.useIcon = false -- true: add pushpin symbol
args.color = ''
args.color, args.group = mu.getColor( args.group )
args.symbol = args.symbol:lower()
local m
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( mi.maintenance.numberUsed )
elseif args.symbol ~= '' and args.text == '' and mu.getMaki( args.symbol ) then
-- check if MAKI icon is available
m = mu.getMaki( args.symbol )
if m and mu.isSet( m.im ) then
args.text = mw.ustring.format( '[[File:%s|x14px|link=|class=noviewer]]',
m.im )
else
-- fallback if no image is available
args.text = args.symbol:sub( 1, 1 ):upper()
args.useIcon = true
end
elseif args.symbol ~= '' and not mu.getMaki( args.symbol ) then
args.symbol = 'cross'
args.color, args.group = mu.getColor( 'error' )
args.text = mi.maintenance.closeX
mu.addMaintenance( mi.maintenance.unknownIcon )
end
end
local function makeName( result, args, show, page, country )
local tag
if args.displayName.all ~= '' or args.nameExtra ~= '' or args.nameLocal ~= '' then
local s
if args.url ~= '' and args.displayName.pageTitle == '' then
s = '[' .. args.url .. ' '
.. mu.replaceBrackets( args.displayName.name ) .. ']'
else
s = args.displayName.all
end
if args.nameExtra ~= '' then
s = s .. ' ' .. args.nameExtra
end
-- supporting right-to-left wikis
if s ~= '' then
tag = mw.html.create( 'bdi' )
:attr( 'id', 'vCard_' .. mw.uri.anchorEncode( args.givenName.name ) )
:attr( 'class', 'p-name fn org listing-name'
.. mu.addWdClass( mp.wdContent.name ) )
:cssText( args.styles )
:wikitext( s )
if not show.noCoord and not show.poi and not show.coord then
tag:addClass( 'listing-without-marker' )
end
table.insert( result, tostring( tag ) )
end
if args.nameLocal ~= '' then
tag = mw.html.create( 'span' )
:attr( 'class', 'listing-name-local wv-foreign-lang'
.. ' wv-foreign-lang-' .. country.lang
.. ' wv-foreign-dir-' .. ( country.isRTL and 'rtl' or 'ltr' )
.. mu.addWdClass( mp.wdContent.nameLocal ) )
:wikitext( '(' .. mu.languageSpan( args.nameLocal,
mi.texts.hintName, page, country ) .. ')' )
table.insert( result, tostring( tag ) )
end
if args.url ~= '' and args.displayName.pageTitle ~= '' then
-- both article and web links
tag = mw.html.create( 'span' )
:addClass( 'listing-url' )
:wikitext( mw.ustring.format( mi.icons.internet, args.url ) )
table.insert( result, tostring( tag ) )
end
elseif args.url ~= '' then
tag = mw.html.create( 'span' )
:addClass( 'listing-url' )
:wikitext( '[' .. args.url .. ']' )
table.insert( result, tostring( tag ) )
end
end
local function makeNameAndAdditions( result, args, show, page, country, entity )
local s = ''
-- adding name, airport code and sister-project icons
if show.name then
makeName( result, args, show, page, country )
if mi.options.showSisters then
s, _ = mu.makeSisterIcons( args, page, country, entity )
end
s = s .. mu.makeSocial( args, mp.wdContent, args.givenName.name )
mu.tableInsert( result, s )
-- adding airport code and coordinate if requested and available
s = {}
if not show.noairport and args.type == mi.airportType then
mu.tableInsert( s, mu.makeAirport( args, mp.wdContent ) )
end
if show.coord then
table.insert( s, mu.dmsCoordinates( args.lat, args.long,
args.givenName.name, mp.wdContent.lat, country.extra ) )
end
if #s > 0 then
s = '<span class="listing-parenthesis">(</span>'
.. table.concat( s, '<span class="listing-delimiter">, ​</span>' )
.. '<span class="listing-parenthesis">)</span>'
table.insert( result, s )
end
-- adding coordinate only
elseif show.coord then
table.insert( result, mu.dmsCoordinates( args.lat, args.long,
args.givenName.name, mp.wdContent.lat, country.extra ) )
end
end
-- main marker function
function mk.marker( frame )
mu.initMaintenance( mi.moduleNames.marker )
local page = mu.getPageData()
-- copying frame:getParent().args to template arguments, args, parameter check
-- returning Wikidata entity and display options
local args, mkEntity, show = initialParameterCheck( frame )
show.inline = true
-- get country-specific technical parameters
local country = cm.getCountryData( mkEntity, nil, args.country )
if country.unknownCountry then
mu.addMaintenance( mi.maintenance.unknownCountry )
end
-- for map support
country.extra = mi.defaultSiteType
if country.iso_3166 and 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
finalParameterCheck( args, show, country, mkEntity )
-- generating output
local result = {} -- output string table, wrapper is added later
-- adding status icons
mu.tableInsert( result, mu.makeStatusIcons( args ) )
-- adding marker symbol
makeMarkerProperties( args )
if show.poi or mu.isSet( args.copyMarker ) then
table.insert( result, mu.makeMarkerSymbol( args, args.givenName.all, frame, show ) )
end
makeNameAndAdditions( result, args, show, page, country, mkEntity )
result = mu.makeWrapper( result, args, page, country, show, mp.markerData, 'Marker', frame )
local ns = page.namespace
if ns ~= 4 and ns ~= 10 and ns ~= 828 then
result = result .. mu.getMaintenance()
if mi.options.usePropertyCateg then
local m = mi.maintenance.properties -- format string
result = result .. wu.getCategories( m )
.. mu.getCategories( m ) .. cm.getCategories( m )
end
end
return result
end
return mk