Modul:Coordinates: Perbedaan antara revisi

1.329 bita ditambahkan ,  11 bulan yang lalu
tidak ada ringkasan suntingan
(←Membuat halaman berisi '--[[ This module is intended to replace the functionality of {{Coord}} and related templates. It provides several methods, including {{#invoke:Coordinates | coord }} : General function formatting and displaying coordinate values. {{#invoke:Coordinates | dec2dms }} : Simple function for converting decimal degree values to DMS format. {{#invoke:Coordinates | dms2dec }} : Simple function for converting DMS format to decimal degree format. {{#invoke:Coordinates...')
Tidak ada ringkasan suntingan
 
(Satu revisi perantara oleh satu pengguna lainnya tidak ditampilkan)
Baris 16: Baris 16:
]]
]]


require('Module:No globals')
require('strict')


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


local current_page = mw.title.getCurrentTitle()
local current_page = mw.title.getCurrentTitle()
local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' );
local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' );
local coord_link = '//geohack.toolforge.org/geohack.php?pagename=' .. page_name .. '&params='
local coord_link = 'https://geohack.toolforge.org/geohack.php?pagename=' .. page_name .. '&language=id&params='
local templatestyles = 'Module:Coordinates/styles.css'


--[[ Helper function, replacement for {{coord/display/title}} ]]
--[[ Helper function, replacement for {{coord/display/title}} ]]
local function displaytitle(s, notes)
local function displaytitle(coords)
local l = "[[Sistem koordinat geografi|Koordinat]]: " .. s
return mw.getCurrentFrame():extensionTag{
local co = '<span id="coordinates">' .. l .. notes .. '</span>';
name = 'indicator',
return '<span style="font-size: small;">' .. co .. '</span>';
args = { name = 'coordinates' },
end
content = '<span id="coordinates">[[Sistem koordinat geografis|Koordinat]]: ' .. coords .. '</span>'
 
}
--[[ Helper function, Replacement for {{coord/display/inline}} ]]
local function displayinline(s, notes)
return s .. notes
end
end


Baris 69: Baris 66:
local result = ""
local result = ""
for i,v in ipairs(errors) do
for i,v in ipairs(errors) do
local errorHTML = '<strong class="error">Coordinates: ' .. v[2] .. '</strong>'
result = result .. '<strong class="error">Coordinates: ' .. v[2] .. '</strong><br />'
result = result .. errorHTML .. "<br />"
end
end
return result
return result
Baris 110: Baris 106:
end
end


local geodmshtml = '<span class="geo-dms" title="Peta, foto udara, dan data lain mengenai lokasi ini">'
local geodmshtml = '<span class="geo-dms" title="Maps, aerial photos, and other data for this location">'
.. '<span class="latitude">' .. coordinateSpec["dms-lat"] .. '</span> '
.. '<span class="latitude">' .. coordinateSpec["dms-lat"] .. '</span> '
.. '<span class="longitude">' ..coordinateSpec["dms-long"] .. '</span>'
.. '<span class="longitude">' ..coordinateSpec["dms-long"] .. '</span>'
Baris 133: Baris 129:
end
end


local geodechtml = '<span class="geo-dec" title="Peta, foto udara, dan data lain mengenai lokasi ini">'
local geodechtml = '<span class="geo-dec" title="Maps, aerial photos, and other data for this location">'
.. geodeclat .. ' '
.. geodeclat .. ' '
.. geodeclong
.. geodeclong
Baris 157: Baris 153:
end
end


return mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = templatestyles} }
    local stylesheetLink = 'Module:Coordinates' .. ( isSandbox and '/sandbox' or '' ) .. '/styles.css'
      .. '<span class="plainlinks nourlexpansion">'
return mw.getCurrentFrame():extensionTag{
      .. '[' .. coord_link .. uriComponents .. ' ' .. inner .. ']'
name = 'templatestyles', args = { src = stylesheetLink }
      .. '</span>'
} .. '<span class="plainlinks nourlexpansion">[' .. coord_link .. uriComponents ..
' ' .. inner .. ']</span>' .. '[[Category:Pages using gadget WikiMiniAtlas]]'
end
end


Baris 283: Baris 280:
table.insert(errors, {source, "latitude minutes < 0"})
table.insert(errors, {source, "latitude minutes < 0"})
end
end
if lat_s >= 60 then
if lat_s > 60 then
table.insert(errors, {source, "latitude seconds >= 60"})
table.insert(errors, {source, "nilai detik lebih dari 60"})
end
end
if lat_s < 0 then
if lat_s < 0 then
Baris 467: Baris 464:
else
else
-- Error
-- Error
return errorPrinter({{"formatTest", "Unknown argument format"}})
return errorPrinter({{"formatTest", "Unknown argument format"}}) .. '[[Category:Pages with malformed coordinate tags]]'
end
end
result.name = args.name
result.name = args.name
Baris 480: Baris 477:
local ret = specPrinter(args, result)
local ret = specPrinter(args, result)
if #errors > 0 then
if #errors > 0 then
ret = ret .. ' ' .. errorPrinter(errors) .. '[[Kategori:Halaman dengan kesalahan format tag koordinat]]'
ret = ret .. ' ' .. errorPrinter(errors) .. '[[Category:Pages with malformed coordinate tags]]'
end
end
return ret, backward
return ret, backward
Baris 498: Baris 495:
ret = 'Koordinat di Wikidata'
ret = 'Koordinat di Wikidata'
elseif snaktype == 'somevalue' then
elseif snaktype == 'somevalue' then
ret = 'Koordinat di Wikidata disetel ke nilai yang tidak diketahui'
ret = 'Koordinat dari Wikidata tidak dapat dibaca'
elseif snaktype == 'novalue' then
elseif snaktype == 'novalue' then
ret = 'Koordinat di Wikidata disetel tanpa nilai'
ret = 'Koordinat dari Wikidata tidak mengembalikan nilai apapun'
end
end
else
else
-- We have to either import the coordinates to Wikidata or remove them here.
-- We have to either import the coordinates to Wikidata or remove them here.
ret = 'Koordinat tidak ada di Wikidata'
ret = 'Koordinat tidak tersedia di Wikidata'
end
end
end
end
if ret then
if ret then
return string.format('[[Kategori:%s]]', ret)
return string.format('[[Category:%s]]', ret)
else
else
return ''
return ''
Baris 633: Baris 630:
local Display = args.display and args.display:lower() or 'inline'
local Display = args.display and args.display:lower() or 'inline'


-- it and ti are short for inline,title and title,inline
local function isInline(s)
local function isInline(s)
-- Finds whether coordinates are displayed inline.
-- Finds whether coordinates are displayed inline.
Baris 649: Baris 647:
local text = ''
local text = ''
if isInline(Display) then
if isInline(Display) then
text = text .. displayinline(contents, Notes)
text = text .. '<span class="geo-inline">' .. contents .. Notes .. '</span>'
end
end
if isInTitle(Display) then
if isInTitle(Display) then
text = text
-- Add to output since indicator content is invisible to Lua later on
.. displaytitle(contents, Notes)
if not isInline(Display) then
.. makeWikidataCategories(args.qid)
text = text .. '<span class="geo-inline-hidden noexcerpt">' .. contents .. Notes .. '</span>'
end
text = text .. displaytitle(contents .. Notes) .. makeWikidataCategories(args.qid)
end
end
if not args.nosave then
if not args.nosave then
Baris 687: Baris 687:


]]
]]
function coordinates.coord2text(frame)
function coordinates._coord2text(coord,type)
if frame.args[1] == '' or frame.args[2] == '' or not frame.args[2] then return nil end
if coord == '' or type == '' or not type then return nil end
frame.args[2] = mw.text.trim(frame.args[2])
type = mw.text.trim(type)
if frame.args[2] == 'lat' or frame.args[2] == 'long' then
if type == 'lat' or type == 'long' then
local result, negative = mw.text.split((mw.ustring.match(frame.args[1],'[%.%d]+°[NS] [%.%d]+°[EW]') or ''), ' ')
local result, negative = mw.text.split((mw.ustring.match(coord,'[%.%d]+°[NS] [%.%d]+°[EW]') or ''), ' ')
if frame.args[2] == 'lat' then
if type == 'lat' then
result, negative = result[1], 'S'
result, negative = result[1], 'S'
else
else
Baris 701: Baris 701:
return result[1]
return result[1]
else
else
return mw.ustring.match(frame.args[1], 'params=.-_'..frame.args[2]..':(.-)[ _]')
return mw.ustring.match(coord, 'params=.-_' .. type .. ':(.-)[ _]')
end
end
end
function coordinates.coord2text(frame)
return coordinates._coord2text(frame.args[1],frame.args[2])
end
end


Baris 719: Baris 723:
]]
]]
function coordinates.coordinsert(frame)
function coordinates.coordinsert(frame)
-- for the 2nd or later integer parameter (the first is the coord template, as above)
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 we cannot find in the coord_template the i_th coordinsert parameter e.g. region
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
-- find from the params= up to the first possibly-present underscore
-- and append the i_th coordinsert parameter and a space
-- IDK why we're adding a space but it does seem somewhat convenient
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
Baris 727: Baris 736:
end
end
if frame.args.name then
if frame.args.name then
-- if we can't find the vcard class
if not mw.ustring.find(frame.args[1], '<span class="vcard">') then
if not mw.ustring.find(frame.args[1], '<span class="vcard">') then
-- take something that looks like a coord template and add the vcard span with class and fn org class
local namestr = frame.args.name
local namestr = frame.args.name
frame.args[1] = mw.ustring.gsub(frame.args[1],
frame.args[1] = mw.ustring.gsub(
frame.args[1],
'(<span class="geo%-default">)(<span[^<>]*>[^<>]*</span><span[^<>]*>[^<>]*<span[^<>]*>[^<>]*</span></span>)(</span>)',
'(<span class="geo%-default">)(<span[^<>]*>[^<>]*</span><span[^<>]*>[^<>]*<span[^<>]*>[^<>]*</span></span>)(</span>)',
'%1<span class="vcard">%2<span style="display:none">&#xfeff; (<span class="fn org">' .. namestr .. '</span>)</span></span>%3')
'%1<span class="vcard">%2<span style="display:none">&#xfeff; (<span class="fn org">' .. namestr .. '</span>)</span></span>%3'
frame.args[1] = mw.ustring.gsub(frame.args[1], '(&params=[^&"<>%[%] ]*) ', '%1&title=' .. mw.uri.encode(namestr) .. ' ')
)
-- then find anything from coordinates parameters to the 'end' and attach the title parameter
frame.args[1] = mw.ustring.gsub(
frame.args[1],
'(&params=[^&"<>%[%] ]*) ',
'%1&title=' .. mw.uri.encode(namestr) .. ' '
)
end
end
end
end
-- replace the existing indicator with a new indicator using the modified content
frame.args[1] = mw.ustring.gsub(
frame.args[1],
'(<span class="geo%-inline[^"]*">(.+)</span>)\127[^\127]*UNIQ%-%-indicator%-%x+%-%-?QINU[^\127]*\127',
function (inline, coord) return inline .. displaytitle(coord) end
)
return frame.args[1]
return frame.args[1]
end
end


return coordinates
return coordinates