Module:Coordinates Explained

--coord }} : General function formatting and displayingcoordinate values.

: Simple function for converting decimaldegree values to DMS format.

: Simple function for converting DMS formatto decimal degree format.

: Export the link used to reach the tools

require('strict')

local math_mod = require("Module:Math")local coordinates = ;local isSandbox = mw.getCurrentFrame:getTitle:find('sandbox', 1, true);

local current_page = mw.title.getCurrentTitlelocal page_name = mw.uri.encode(current_page.prefixedText, 'WIKI');local coord_link = 'https://geohack.toolforge.org/geohack.php?pagename=' .. page_name .. '&params='

--Helper function, replacement for local function displaytitle(coords) return mw.getCurrentFrame:extensionTagend

--Helper function, used in detecting DMS formatting local function dmsTest(first, second) if type(first) ~= 'string' or type(second) ~= 'string' then return nil end local s = (first .. second):upper return s:find('^[NS][EW]$') or s:find('^[EW][NS]$')end

--local function makeInvokeFunc(funcName) return function (frame) local args = require('Module:Arguments').getArgs(frame,) return coordinates[funcName](args, frame) endend

--Helper function, handle optional args. local function optionalArg(arg, supplement) return arg and arg .. supplement or end

--Formats any error messages generated for displaylocal function errorPrinter(errors) local result = "" for i,v in ipairs(errors) do result = result .. 'Coordinates: ' .. v[2] .. '
' end return resultend

--Determine the required CSS class to display coordinates

Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himselfdefault is the mode as specificied by the user when calling the templatemode is the display mode (dec or dms) that we will need to determine the css class for

local function displayDefault(default, mode) if default

"" then default = "dec" end

if default

mode then return "geo-default" else return "geo-nondefault" endend

--specPrinter

Output formatter. Takes the structure generated by either parseDecor parseDMS and formats it for inclusion on Wikipedia.

local function specPrinter(args, coordinateSpec) local uriComponents = coordinateSpec["param"] if uriComponents

"" then -- RETURN error, should never be empty or nil return "ERROR param was empty" end if args["name"] then uriComponents = uriComponents .. "&title=" .. mw.uri.encode(coordinateSpec["name"]) end

local geodmshtml = '

' .. '' .. coordinateSpec["dms-lat"] .. ' ' .. '' ..coordinateSpec["dms-long"] .. '' .. ''

local lat = tonumber(coordinateSpec["dec-lat"]) or 0 local geodeclat if lat < 0 then -- FIXME this breaks the pre-existing precision geodeclat = tostring(coordinateSpec["dec-lat"]):sub(2) .. "°S" else geodeclat = (coordinateSpec["dec-lat"] or 0) .. "°N" end

local long = tonumber(coordinateSpec["dec-long"]) or 0 local geodeclong if long < 0 then -- FIXME does not handle unicode minus geodeclong = tostring(coordinateSpec["dec-long"]):sub(2) .. "°W" else geodeclong = (coordinateSpec["dec-long"] or 0) .. "°E" end

local geodechtml = '

' .. geodeclat .. ' ' .. geodeclong .. ''

local geonumhtml = '

' .. coordinateSpec["dec-lat"] .. '; ' .. coordinateSpec["dec-long"] .. ''

local inner = '

' .. geodmshtml .. '' .. '&#xfeff; / &#xfeff;' .. ''

if not args["name"] then inner = inner .. geodechtml .. '

&#xfeff; / ' .. geonumhtml .. '
' else inner = inner .. '' .. geodechtml .. '&#xfeff; / ' .. geonumhtml .. '' .. '&#xfeff; (' .. args["name"] .. ')