Modul:Quickbar Position

Dokumentation für das Modul Quickbar Position[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Verwendung

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

Versionsbezeichnung auf Wikidata: 2023-04-03 Ok!

Benötigte weitere Module

Dieses Modul benötigt folgende weitere Module: Coordinates • Location map/Params • Quickbar Position/i18n • Quickbar Position/Params • Quickbar • GetNumber • Yesno
Hinweise
-- documentation
local QuickbarPosition = {
	suite  = 'Quickbar Position',
	serial = '2023-04-03',
	item   = 96274112
}

-- module import
local cd       = require( 'Module:Coordinates' )
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:Quickbar' )
local gn       = require( 'Module:GetNumber' )
local yn       = require( 'Module:Yesno' )

-- module variable and administration
local qbPosition = {
	moduleInterface = QuickbarPosition
}

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
			qp.lat, qp.long = gn.GetNumber().getCoordinate()
		end
		if qp.lat == 0 or qp.long == 0 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

return qbPosition