Modul:Marker

![]() | Dieses Modul wird auf vielen Seiten benutzt, und Änderungen werden projektweit sofort wahrgenommen. Bitte teste Änderungen vorher im /Sandkasten oder in deinem Benutzernamensraum. Die getestete Änderung sollte dann in einem einzigen Edit auf dieser Seite eingefügt werden. Bitte diskutiere Änderungen zuerst auf der Diskussionsseite bevor du sie implementierst. |
![]() | Dieses Modul ist getestet und für den projektweiten Gebrauch geeignet. Es kann in Vorlagen benutzt und auf Hilfeseiten erläutert werden. Entwicklungen an dem Modul sollten auf Marker/Test und die Anwendung auf der Spielwiese getestet werden, da wiederholte Trial-and-Error-Edits die Resourcen stark belasten können. |
![]() | Dieses Modul benutzt die Wikidata-Eigenschaften:
|
Dieses Modul enthält Funktionen zur Darstellung von Karten-Markern. Die Funktionen des Moduls werden nicht direkt aufgerufen, sondern über die Vorlage {{Marker}}.
Versionsbezeichnung auf Wikidata: 2023-05-26
Funktionen
function mk.marker( frame )
Die Funktion prüft die Parameter der Vorlage {{Marker}} und führt die Markerdarstellung aus. Die möglichen Parameter sind in der Vorlage {{Marker}} beschrieben. Im Projektnamensraum befindet sich die technische Dokumentation.
Benötigte weitere Module
Dieses Modul benötigt folgende weitere Module: CountryData • Marker/Params • Marker utilities • Marker utilities/i18n • Wikidata utilitiesHinweise
- Die obige Dokumentation wurde aus der Seite Modul:Marker/Doku eingefügt. (bearbeiten | Versionsgeschichte) Die Kategorien für dieses Modul sollten in der Dokumentation eingetragen werden. Die Interwiki-Links sollten auf Wikidata eingepflegt werden.
- Liste der Unterseiten
-- module variable and administration
local mk = {
moduleInterface = {
suite = 'Marker',
serial = '2023-05-26',
item = 40852170
}
}
-- module import
-- require( 'strict' )
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
local function checkYn( keys, args )
local s
for i, 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
local descrDiv
for key, v in pairs( mp.p ) do
if args[ key ] then
args[ key ], descrDiv = mu.removeCtrls( args[ key ], true )
else
args[ key ] = ''
end
end
-- checking show parameter
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
-- 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( 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 i, value in ipairs( mp.socialMedia ) do
args[ value ] = 'y'
end
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 i, 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
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( mw.ustring.format( mi.maintenance.type, tp ) )
end
end
-- url check
mu.checkUrl( args )
-- 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
mu.removeStars( args, { 'alt', '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
end
-- distinguishing marker symbols, default: number
local function makeMarkerProperties( args, show )
args.useIcon = false -- true: add pushpin symbol
args.symbol = args.symbol:lower()
if args.symbol == '' and show.poi and show.symbol then
args.symbol = mu.getMakiIconId( args.type ) 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( mi.maintenance.numberUsed )
elseif args.symbol ~= '' and args.text == '' and mu.getMaki( args.symbol ) then
-- check if MAKI icon is available
local m = mu.getMakiIconId( args.symbol )
if m then
args.text = mw.ustring.format( '[[File:%s|x14px|link=|class=noviewer]]',
mu.getMaki( m ).im )
else
-- fallback if no image is available
mu.addMaintenance( mi.maintenance.missingMakiImg )
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.group = 'error'
args.text = mi.maintenance.closeX
mu.addMaintenance( mi.maintenance.unknownIcon )
end
mu.getColor( args )
end
local function makeName( result, args, show, page, country )
local tag
if args.displayName.all ~= '' or args.nameExtra ~= '' or args.nameLocal ~= '' then
local s, t
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
t = mw.uri.anchorEncode( args.givenName.name ):gsub( '&', '&' )
:gsub( ''', "'" )
tag = mw.html.create( 'bdi' )
:attr( 'id', 'vCard_' .. t )
: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 = tostring( mw.html.create( 'span' )
:addClass( 'listing-name-local' .. mu.addWdClass( mp.wdContent.nameLocal ) )
:wikitext( mu.languageSpan( args.nameLocal, mi.texts.hintName, page,
country, '' ) )
)
table.insert( result, tag )
end
if args.url ~= '' and args.displayName.pageTitle ~= '' then
-- both article and web links
tag = mu.addLinkIcon( 'listing-url', args.url, mi.iconTitles.internet,
'internet' )
table.insert( result, 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 = ''
local rMarker = {}
-- adding name, airport code and sister-project icons
if show.name then
makeName( rMarker, args, show, page, country )
s = table.concat( rMarker, ' ' )
local icons = {}
local onlyWikidata = mi.options.showSisters and
mu.makeSisterIcons( icons, args, page, country, entity )
mu.makeSocial( icons, args, mp.wdContent, args.givenName.name )
if #icons > 0 then
s = s .. ( onlyWikidata and '' or ' ' ) .. table.concat( icons, '' )
end
mu.tableInsert( result, s )
-- adding airport code and coordinate if requested and available
s = {}
mu.tableInsert( s, mu.makeAirport( args, show, mp.wdContent ) )
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 listing-parenthesis-start">(</span>'
.. table.concat( s, '<span class="listing-delimiter">, ​</span>' )
.. '<span class="listing-parenthesis listing-parenthesis-end">)</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
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( 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 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
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, show )
mu.setCopyMarker( args, show )
if show.poi or mu.isSet( args.copyMarker ) then
table.insert( result, mu.makeMarkerSymbol( args, args.givenName.all, frame ) )
end
makeNameAndAdditions( result, args, show, page, country, mkEntity )
return mu.makeWrapper( result, args, page, country, show, mp.markerData, 'Marker', frame )
.. makeMaintenance( page )
end
return mk