Module:Coordinates: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(sandbox sync per TPER at talk, bring #coordinates to module) |
(mal-synced? backout per issue noted at Grade I listed buildings in Dorset, getting "cannot have more than one primary tag per page") |
||
Line 51: | Line 51: | ||
wrappers = 'Template:Coord' |
wrappers = 'Template:Coord' |
||
}) |
}) |
||
return coordinates[funcName](args |
return coordinates[funcName](args) |
||
end |
end |
||
end |
end |
||
Line 309: | Line 309: | ||
parseDec |
parseDec |
||
Transforms decimal format latitude and longitude into the |
Transforms decimal format latitude and longitude into the a |
||
structure to be used in displaying coordinates |
structure to be used in displaying coordinates |
||
]] |
]] |
||
Line 346: | Line 346: | ||
]] |
]] |
||
local function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format ) |
local function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format ) |
||
local coordinateSpec |
local coordinateSpec = {} |
||
⚫ | |||
lat_f = lat_f:upper(); |
lat_f = lat_f:upper(); |
||
Line 353: | Line 354: | ||
-- Check if specified backward |
-- Check if specified backward |
||
if lat_f == 'E' or lat_f == 'W' then |
if lat_f == 'E' or lat_f == 'W' then |
||
local t_d, t_m, t_s, t_f; |
|||
lat_d, long_d, lat_m, long_m, lat_s, long_s, lat_f, long_f, backward = long_d, lat_d, long_m, lat_m, long_s, lat_s, long_f, lat_f, true; |
|||
t_d = lat_d; |
|||
t_m = lat_m; |
|||
t_s = lat_s; |
|||
t_f = lat_f; |
|||
lat_d = long_d; |
|||
lat_m = long_m; |
|||
lat_s = long_s; |
|||
lat_f = long_f; |
|||
long_d = t_d; |
|||
long_m = t_m; |
|||
long_s = t_s; |
|||
long_f = t_f; |
|||
end |
end |
||
Line 387: | Line 400: | ||
end |
end |
||
return coordinateSpec, errors |
return coordinateSpec, errors |
||
end |
end |
||
Line 396: | Line 409: | ||
local function formatTest(args) |
local function formatTest(args) |
||
local result, errors |
local result, errors |
||
local |
local primary = false |
||
local function getParam(args, lim) |
local function getParam(args, lim) |
||
Line 421: | Line 434: | ||
elseif dmsTest(args[4], args[8]) then |
elseif dmsTest(args[4], args[8]) then |
||
-- dms logic |
-- dms logic |
||
result, errors |
result, errors = parseDMS(args[1], args[2], args[3], args[4], |
||
args[5], args[6], args[7], args[8], args.format) |
args[5], args[6], args[7], args[8], args.format) |
||
if args[10] then |
if args[10] then |
||
Line 432: | Line 445: | ||
elseif dmsTest(args[3], args[6]) then |
elseif dmsTest(args[3], args[6]) then |
||
-- dm logic |
-- dm logic |
||
result, errors |
result, errors = parseDMS(args[1], args[2], nil, args[3], |
||
args[4], args[5], nil, args[6], args['format']) |
args[4], args[5], nil, args[6], args['format']) |
||
if args[8] then |
if args[8] then |
||
Line 443: | Line 456: | ||
elseif dmsTest(args[2], args[4]) then |
elseif dmsTest(args[2], args[4]) then |
||
-- d logic |
-- d logic |
||
result, errors |
result, errors = parseDMS(args[1], nil, nil, args[2], |
||
args[3], nil, nil, args[4], args.format) |
args[3], nil, nil, args[4], args.format) |
||
if args[6] then |
if args[6] then |
||
Line 469: | Line 482: | ||
ret = ret .. ' ' .. errorPrinter(errors) .. '[[Category:Pages with malformed coordinate tags]]' |
ret = ret .. ' ' .. errorPrinter(errors) .. '[[Category:Pages with malformed coordinate tags]]' |
||
end |
end |
||
return ret |
return ret |
||
end |
end |
||
Line 615: | Line 628: | ||
end |
end |
||
local contents |
local contents = formatTest(args) |
||
local Notes = args.notes or '' |
local Notes = args.notes or '' |
||
local Display = args.display and args.display:lower() or 'inline' |
local Display = args.display and args.display:lower() or 'inline' |
||
Line 626: | Line 639: | ||
-- Finds whether coordinates are displayed in the title. |
-- Finds whether coordinates are displayed in the title. |
||
return s:find('title') ~= nil or s == 't' or s == 'it' or s == 'ti' |
return s:find('title') ~= nil or s == 't' or s == 'it' or s == 'ti' |
||
end |
|||
local function coord_wrapper(frame, in_args) |
|||
-- Calls the parser function {{#coordinates:}}. |
|||
return mw.getCurrentFrame():callParserFunction('#coordinates', in_args) or '' |
|||
end |
end |
||
Line 641: | Line 649: | ||
.. displaytitle(contents, Notes) |
.. displaytitle(contents, Notes) |
||
.. makeWikidataCategories() |
.. makeWikidataCategories() |
||
end |
|||
if not args.nosave then |
|||
local page_title, count = mw.title.getCurrentTitle(), 1 |
|||
if backward then |
|||
⚫ | |||
while not string.find((args[count-1] or ''), '[EW]') do tmp[count] = (args[count] or ''); count = count+1 end |
|||
tmp.count = count; count = 2*(count-1) |
|||
while count >= tmp.count do table.insert(tmp, 1, (args[count] or '')); count = count-1 end |
|||
for i, v in ipairs(tmp) do args[i] = v end |
|||
else |
|||
while count <= 9 do args[count] = (args[count] or ''); count = count+1 end |
|||
end |
|||
if isInline(Display) and not page_title.isTalkPage and page_title.subpageText ~= 'doc' and page_title.subpageText ~= 'testcases' then args[10] = 'primary' end |
|||
args.notes, args.format, args.display = nil |
|||
text = text .. coord_wrapper(frame, args) |
|||
end |
end |
||
return text |
return text |
||
Line 707: | Line 700: | ||
for i, v in ipairs(frame.args) do |
for i, v in ipairs(frame.args) do |
||
if i ~= 1 then |
if i ~= 1 then |
||
if not mw.ustring.find(frame.args[1], (mw.ustring.match(frame.args[i], '^(.-:)') or '')) then frame.args[1] = mw.ustring.gsub(frame.args[1], '(params=.-)_? ', '%1_'..frame.args[i]..' ') end |
if not mw.ustring.find(frame.args[1], (mw.ustring.match(frame.args[i], '^(.-:)') or '')) then frame.args[1] = mw.ustring.gsub(frame.args[1], '(params=.-)_? ', '%1_'..frame.args[i]..' ', 1) end |
||
end |
end |
||
end |
end |