Module:Coordinates: Difference between revisions
No edit summary Tags: Manual revert Reverted |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[ | --[[ | ||
This module is intended to replace the functionality of {{Coord}} and related | This module is intended to replace the functionality of {{Coord}} and related | ||
templates. | templates. It provides several methods, including | ||
{{#invoke:Coordinates | coord }} : General function formatting and displaying | {{#invoke:Coordinates | coord }} : General function formatting and displaying | ||
Line 93: | Line 93: | ||
specPrinter | specPrinter | ||
Output formatter. | Output formatter. Takes the structure generated by either parseDec | ||
or parseDMS and formats it for inclusion on Wikipedia. | or parseDMS and formats it for inclusion on Wikipedia. | ||
]] | ]] | ||
Line 256: | Line 256: | ||
table.insert(errors, {source, "longitude degrees < 0 with hemisphere flag"}) | table.insert(errors, {source, "longitude degrees < 0 with hemisphere flag"}) | ||
end | end | ||
end | end | ||
Line 329: | Line 319: | ||
local mode = coordinates.determineMode( lat, long ); | local mode = coordinates.determineMode( lat, long ); | ||
coordinateSpec["dms-lat"] = convert_dec2dms( lat, "N", "S", mode) | coordinateSpec["dms-lat"] = convert_dec2dms( lat, "N", "S", mode) | ||
coordinateSpec["dms-long"] = convert_dec2dms( long, "E", "W", mode) | coordinateSpec["dms-long"] = convert_dec2dms( long, "E", "W", mode) | ||
if format then | if format then | ||
Line 380: | Line 370: | ||
coordinateSpec["dms-lat"] = lat_d.."°"..optionalArg(lat_m,"′") .. optionalArg(lat_s,"″") .. lat_f | coordinateSpec["dms-lat"] = lat_d.."°"..optionalArg(lat_m,"′") .. optionalArg(lat_s,"″") .. lat_f | ||
coordinateSpec["dms-long"] = long_d.."°"..optionalArg(long_m,"′") .. optionalArg(long_s,"″") .. long_f | coordinateSpec["dms-long"] = long_d.."°"..optionalArg(long_m,"′") .. optionalArg(long_s,"″") .. long_f | ||
coordinateSpec["dec-lat"] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) | coordinateSpec["dec-lat"] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) | ||
coordinateSpec["dec-long"] = convert_dms2dec(long_f, long_d, long_m, long_s) | coordinateSpec["dec-long"] = convert_dms2dec(long_f, long_d, long_m, long_s) | ||
if format then | if format then | ||
Line 420: | Line 410: | ||
return errorPrinter(errors); | return errorPrinter(errors); | ||
end | end | ||
-- formatting for geohack | -- formatting for geohack | ||
result.param = table.concat({ | result.param = table.concat({ | ||
math.abs(tonumber(args[1])), | math.abs(tonumber(args[1])), | ||
Line 480: | Line 468: | ||
end | end | ||
return ret, backward | return ret, backward | ||
end | end | ||
Line 533: | Line 479: | ||
negative_suffix | precision }} | negative_suffix | precision }} | ||
decimal_coordinate is converted to DMS format. | decimal_coordinate is converted to DMS format. If positive, the positive_suffix | ||
is appended (typical N or E), if negative, the negative suffix is appended. | is appended (typical N or E), if negative, the negative suffix is appended. The | ||
specified precision is one of 'D', 'DM', or 'DMS' to specify the level of detail | specified precision is one of 'D', 'DM', or 'DMS' to specify the level of detail | ||
to use. | to use. | ||
Line 597: | Line 543: | ||
... | ... | ||
Refer to {{coord}} documentation page for many additional parameters and | |||
configuration options. | |||
]] | ]] | ||
coordinates.coord = makeInvokeFunc('_coord') | coordinates.coord = makeInvokeFunc('_coord') | ||
function coordinates._coord(args) | function coordinates._coord(args) | ||
local contents, backward = formatTest(args) | local contents, backward = formatTest(args) | ||
local Notes = args.notes or '' | local Notes = args.notes or '' | ||
Line 638: | Line 560: | ||
-- 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 | end | ||
Line 654: | Line 571: | ||
text = text .. '<span class="geo-inline-hidden noexcerpt">' .. contents .. Notes .. '</span>' | text = text .. '<span class="geo-inline-hidden noexcerpt">' .. contents .. Notes .. '</span>' | ||
end | end | ||
text = text .. displaytitle(contents .. Notes | text = text .. displaytitle(contents .. Notes) | ||
end | end | ||
return text | return text | ||
end | |||
--[[ | |||
link | |||
Simple function to export the coordinates link for other uses. | |||
Usage: | |||
{{#invoke:Coordinates | link }} | |||
]] | |||
function coordinates.link(frame) | |||
return coord_link; | |||
end | end | ||
Line 678: | Line 594: | ||
Extracts a single value from a transclusion of {{Coord}}. | Extracts a single value from a transclusion of {{Coord}}. | ||
Usage: | Usage: | ||
Line 713: | Line 628: | ||
Injects some text into the Geohack link of a transclusion of {{Coord}} (if that text isn't already in the transclusion). Outputs the modified transclusion of {{Coord}}. | Injects some text into the Geohack link of a transclusion of {{Coord}} (if that text isn't already in the transclusion). Outputs the modified transclusion of {{Coord}}. | ||
Usage: | Usage: | ||
{{#invoke:Coordinates | coordinsert | {{Coord}} | parameter:value | parameter:value | … }} | {{#invoke:Coordinates | coordinsert | {{Coord}} | parameter:value | parameter:value | … }} | ||
]] | ]] | ||
function coordinates.coordinsert(frame) | function coordinates.coordinsert(frame) | ||
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 | 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]..' ') | frame.args[1] = mw.ustring.gsub(frame.args[1], '(params=.-)_? ', '%1_'..frame.args[i]..' ') | ||
end | end | ||
Line 736: | Line 643: | ||
end | end | ||
if frame.args.name then | if frame.args.name then | ||
if not mw.ustring.find(frame.args[1], '<span class="vcard">') then | if not mw.ustring.find(frame.args[1], '<span class="vcard">') then | ||
local namestr = frame.args.name | local namestr = frame.args.name | ||
frame.args[1] = mw.ustring.gsub( | frame.args[1] = mw.ustring.gsub( | ||
Line 745: | Line 650: | ||
'%1<span class="vcard">%2<span style="display:none"> (<span class="fn org">' .. namestr .. '</span>)</span></span>%3' | '%1<span class="vcard">%2<span style="display:none"> (<span class="fn org">' .. namestr .. '</span>)</span></span>%3' | ||
) | ) | ||
frame.args[1] = mw.ustring.gsub( | frame.args[1] = mw.ustring.gsub( | ||
frame.args[1], | frame.args[1], | ||
Line 754: | Line 658: | ||
end | end | ||
frame.args[1] = mw.ustring.gsub( | frame.args[1] = mw.ustring.gsub( | ||
frame.args[1], | frame.args[1], |