Icono de documentación de módulo Documentación del módulo[ver] [editar] [historial] [purgar]

Version check

Designación de la versión en Wikidata: 2024-04-19 Ok!

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.

-- module variable and administration
local mk = {
	moduleInterface = {
		suite  = 'Marker',
		serial = '2024-04-19',
		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

	-- 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.map.defaultSiteType
	if mu.isSet( country.iso_3166 ) then
		country.extra = country.extra .. '_region:' .. country.iso_3166
	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'

	mu.checkStatus( args )
	mu.checkStyles( args )
	-- checking coordinates and converting DMS to decimal coordinates if necessary
	mu.checkCoordinates( args )
	mu.checkZoom( 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

	return args, entity, show, country
end

-- getting data from Wikidata
local function getDataFromWikidata( args, show, page, country, entity )
	local function singleProperty( propDef, maxCount )
		local v = wu.getValues( entity, propDef.p, maxCount )
		if propDef.f then
			for i = 1, #v, 1 do -- formatting
				if mu.isSet( v[ i ] ) then
					v[ i ] = propDef.f:format( v [ i ] )
				end
			end
		end
		return v
	end

	local function getValues( propDef )
		local v
		local maxCount = propDef.c or 1
		local tp = type( propDef.p )
		if tp == 'string' then
			v = singleProperty( propDef, maxCount )
		elseif tp == 'table' then
			for i, sngl in ipairs( propDef.p ) do
				if type( sngl ) == 'table' then
					v = singleProperty( sngl, maxCount )
					if #v > 0 then
						break
					end
				end
			end
		end
		return table.concat( v, ', ' )
	end

	if args.wikidata == '' then
		return
	end

	mu.getTypeFromWikidata( args, entity )

	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 p
	for key, value in pairs( mp.wdContent ) do
		p = mp.wd[ key ]
		if p and not mu.isSet( args[ key ] ) then
			if key == 'image' or key == 'rss' or ( value and show.name ) then
				args[ key ] = getValues( p )
			end
			mp.wdContent[ key ] = args[ key ] ~= ''
		end
	end
end

local function finalParametersCheck( args, show, country, entity )
	-- creating givenName, displayName tables
	mu.prepareNames( args )

	-- 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

	-- getting Marker type, group, and color
	mu.checkTypeAndGroup( args )

	-- image check
	if not mp.wdContent.image or mi.options.WDmediaCheck then 
		mu.checkImage( args, entity )
	end

	mu.checkUrl( args )

	args.commonscat = args.commonscat:gsub( ' ', '_' )
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, 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, country = initialParametersCheck( frame )
	show.inline = true

	-- associated Wikivoyage page of the location in current Wikivoyage branch
	-- possibly modified by mu.getArticleLink()
	args.wikiPage  = ''

	getDataFromWikidata( args, show, page, country, mkEntity )

	-- 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