Modul:Quickbar Position

Aus Wikivoyage
Zur Navigation springen Zur Suche springen
Template-info.png Dokumentation für das Modul Quickbar Position[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Das Modul wird von der Vorlage {{Quickbar position}} benutzt. Die Parameter sind dort beschrieben.

Versionsbezeichnung auf WikiData: 2020-10-23

Benötigte weitere Module

Dieses Modul benötigt folgende weitere Module: Coordinates • Failsafe • Location map/Params • Quickbar Position/i18n • Quickbar Position/Params • Quickbar2 • Wikidata2 • Yesno
Hinweise
-- documentation
local QuickbarPosition = {
	suite  = 'Quickbar Position',
	serial = '2020-10-23',
	item   = 96274112
}

-- module import
local cd       = require( 'Module:Coordinates' )
local fs       = require( 'Module:Failsafe' )
local lp       = mw.loadData( 'Module:Location map/Params' )
local qi       = mw.loadData( 'Module:Quickbar Position/i18n' )
local qp       = require( 'Module:Quickbar Position/Params' )
local quickbar = require( 'Module:Quickbar2' )
local wd       = require( 'Module:Wikidata2' )
local yn       = require( 'Module:Yesno' )

-- module variable
local qbPosition = {}

local function checkParams( args )
	local titleObj = mw.title.getCurrentTitle()
	local mismatch = {}
	for key, value in pairs( args ) do
		if qp[ key ] then
			if ( value or '' ) ~= '' then
				qp[ key ] = value
				if key == 'name' and ( args.label or '' ) == '' then
					qp.label = value
				end
			end
		else
			table.insert( mismatch, key )
		end
	end
	if qp.name == '' then
		qp.name = titleObj.text
	end
	if qp.label == '' then
		qp.label = titleObj.subpageText
	end
	qp.noCoordError = yn( qp.noCoordError, false )
	if #mismatch == 0 then
		return ''
	else
		return mw.ustring.format( qi.unknownParams, table.concat( mismatch, ', ' ) )
	end
end

function qbPosition.position( frame )
	local errors = checkParams( frame:getParent().args )
	if errors ~= '' then
		return errors
	end

	local function toDec( coord, dir )
		local result = cd.toDec( coord, dir, 6 )
		return result.error == 0 and result.dec or ''
	end

	local result
	if qp[ 1 ] ~= '' then
		return quickbar.theader( qp.colSpan, qp.header, qp.rowClass ) ..
			quickbar.trImage( qp.rowClass, qp[ 1 ], qp.colSpan )
	else
		if qp.map == '' then
			return qi.unknownMap
		end
		if qp.lat ~= '' and qp.long ~= '' then
			qp.lat = toDec( qp.lat, 'lat' )
			qp.long = toDec( qp.long, 'long' )
		end
		if qp.lat == '' or qp.long == '' then
			result = wd.getCoordinates()
			if result.errCode == 1 then
				qp.lat = result.lat
				qp.long = result.long
			end
		end
		if qp.lat == '' or qp.long == '' then
			return qp.noCoordError and '' or qi.unknownCoord
		end
		local args = {}
		for key, value in pairs( qp ) do
			if lp.locationMap[ key ] then
				args[ key ] = value
			end
		end
		return quickbar.theader( qp.colSpan, qp.header, qp.rowClass ) ..
			quickbar.locmap( qp.colSpan, { args = args }, qp.rowClass )
	end
end

-- module administration
function qbPosition.QuickbarPosition()
	return QuickbarPosition
end

function qbPosition.failsafe( version )
	return fs._failsafe( version, QuickbarPosition ) or ''
end

return qbPosition