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: 2021-01-28
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/Maki icons • Marker utilities/i18n • PageData • Wikidata utilities • YesnoHinweise
- 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
-- documentation
local Marker = {
suite = 'Marker',
serial = '2021-01-28',
item = 40852170
}
-- module import
require( 'Module:No globals' )
local mi = require( 'Module:Marker utilities/i18n' )
local mm = require( 'Module:Marker utilities/Maki icons' )
local mu = require( 'Module:Marker utilities' )
local mp = require( 'Module:Marker/Params' )
local cm = require( 'Module:CountryData' )
local pd = require( 'Module:PageData' )
local yn = require( 'Module:Yesno' )
local wu = require( 'Module:Wikidata utilities' )
-- module variable
local mk = {}
local function checkYn( keys, args )
local s = ''
for i, key in ipairs( keys ) do
if not args[ key ] then
args[ key ] = ''
end
s = yn( args[ key ], nil )
if s ~= nil then -- then args.url is boolean
args[ key ] = ''
mp.wdContent[ key ] = s
elseif args[ key ] ~= '' then
mp.wdContent[ key ] = false
end
end
end
local function initialParameterCheck( templateArgs )
local entity = nil
local wrongQualifier = false
local args = {}
local show = {}
mu.checkArguments( templateArgs, mp.p )
-- checking keys and copying values to args
local value
for key, validKeys in pairs( mp.p ) do
value = mu.getArgument( templateArgs, validKeys )
if value then
value, _ = mu.removeCtrls( value, true )
args[ key ] = value
else
args[ key ] = ''
end
end
-- checking format and show parameters
if args.show and args.show ~= '' then
show = mu.getShow( mp.defaultShow, args.show, mp.show )
if show.noname then
show.noname = nil
show.name = nil
else
show.name = ''
end
if not next( show ) then
show.name = ''
end
else
if not args.format:match( mp.formats.allowed ) then
if args.format ~= '' then
mu.addMaintenance( mi.maintenance.unknownFormat )
end
args.format = mp.formats.default
end
if args.format == mp.formats.poiMode then
mu.addMaintenance( mi.maintenance.poiMode )
end
for key, value in ipairs( { 'poi', 'name', 'coord' } ) do
show[ value ] = args.format:match( mp.formats[ value ] )
end
end
-- checking Wikidata entitity
args.wikidata, entity, wrongQualifier = wu.getEntityId( 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 ] = true
end
end
-- y/n allow/disallow output
checkYn( mp.ynCheckList, args )
args.noGpx = yn( args.noGpx, false )
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 )
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 = true
mu.getNamesFromWikidata( args, mp.wdContent, page, country, entity )
-- for future use: eventually add it to Module:Marker utilities
-- if mp.wdContent.nameLocal then
-- mu.addMaintenance( mi.maintenance.localNameFromWD )
-- end
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
end
-- image check
if not mp.wdContent.image or mi.options.WDmediaCheck then
args.image = mu.checkImage( args.image, entity )
end
-- getting Marker type and group
args.type, args.group = mu.checkTypeAndGroup( args.type, args.group )
args.groupTranslated = mu.translateGroup( args.group )
-- 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.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()
if args.symbol == 'letter' then
args.symbol = '-letter-' .. args.group
elseif args.symbol == '' or args.symbol == 'number' then
args.symbol = '-number-' .. 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 mm[ args.symbol ] and args.text == '' then
-- check if MAKI icon is available
if mm[ args.symbol ].im ~= '' then
args.text = mw.ustring.format( '[[File:%s|x14px|link=|class=noviewer]]',
mm[ args.symbol ].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 mm[ 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 )
local tag
if args.displayName.all ~= '' or args.nameExtra ~= '' then
local style
if args.styles ~= '' then
style = mi.nameStyles[ args.styles:lower() ];
if not style then
style = args.styles
end
end
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
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( style )
:wikitext( s )
table.insert( result, tostring( tag ) )
if args.url ~= '' and args.displayName.pageTitle ~= '' then
-- both article and web links
tag = mw.html.create( 'span' )
:addClass( 'listing-url' )
:wikitext( '['.. args.url .. ' ' .. mi.icons.internet .. ']' )
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 )
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( 'Marker' )
local page = pd.getPageData()
-- copying frame:getParent().args to template arguments, args, parameter check
-- returning Wikidata entity and display options
local args, mkEntity, show = initialParameterCheck( frame:getParent().args )
show.inline = true
-- get country-specific technical parameters
local country = cm.getCountryData( mkEntity, nil )
-- 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 = ''
args.nameLocal = '' -- possible future feature
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 marker symbol
makeMarkerProperties( args )
if show.poi then
table.insert( result, mu.makeMarkerSymbol( args, args.givenName.all, frame ) )
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
local m = mi.maintenance.properties
return result .. mu.getMaintenance() .. wu.getCategories( m )
.. mu.getCategories( m ) .. cm.getCategories( m )
else
return result
end
end
-- module administration
function mk.getModuleInterface()
return Marker
end
function mk.failsafe( version )
return wu._failsafe( version, Marker ) or ''
end
return mk