Modul:Location map: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Pierrewee (bicara | kontrib)
baris 50:Modul
Taylor 49 (bicara | kontrib)
-require('Module:No globals')
 
(32 revisi perantara oleh 7 pengguna tidak ditampilkan)
Baris 1:
require('Modul:No globals')
 
local p = {}
 
local getArgs = require('ModulModule:Arguments').getArgs
 
local function round(n, decimals)
Baris 12 ⟶ 10:
function p.getMapParams(map, frame)
if not map then
error('TheNama namedefinisi ofpeta thelokasi locationyang mapakan definitiondigunakan toharus use must be specifiedditentukan', 2)
end
local moduletitle = mw.title.new('ModulModule:Location map/data/' .. map)
if not moduletitle then
error(string.format('%q isbukan notnama ayang valid nameuntuk fordefinisi apeta location map definitionlokasi', map), 2)
elseif moduletitle.exists then
local mapData = mw.loadData('ModulModule:Location map/data/' .. map)
return function(name, params)
if name == nil then
return 'ModulModule:Location map/data/' .. map
elseif mapData[name] == nil then
return ''
Baris 33 ⟶ 31:
local cache = {}
if type(frame) ~= 'table' or type(frame.expandTemplate) ~= 'function' then
error('AFrame frameharus mustdisediakan besaat providedmenggunakan whenpeta usinglokasi a legacy location maplama')
end
return function(name, params)
Baris 48 ⟶ 46:
end
else
error('UnableTidak todapat findmenemukan thedefinisi specifiedpeta locationlokasi mapyang definitionditentukan. NeitherBaik "Modul:Location map/data/' .. map .. '" normaupun "Templat:Location map ' .. map .. '" existstidak ada', 2)
end
end
Baris 76 ⟶ 74:
if decimal then
if degrees then
error('DecimalDerajat anddesimal dan DMS degrees cannot bothtidak bedapat provideddiberikan foruntuk ' .. direction, 2)
elseif minutes then
error('MinutesMenit canhanya onlydapat bediberikan provideddengan withderajat DMS degrees foruntuk ' .. direction, 2)
elseif seconds then
error('SecondsDetik canhanya onlydapat bediberikan provideddengan withderajat DMS degrees foruntuk ' .. direction, 2)
elseif hemisphere then
error('AHemisfer hemispherehanya candapat onlydiberikan bedengan provided withderajat DMS degrees foruntuk ' .. direction, 2)
end
local retval = tonumber(decimal)
Baris 88 ⟶ 86:
return retval
end
error('The valueNilai "' .. decimal .. '" providedyang fordisediakan untuk ' .. direction .. ' is nottidak validsah', 2)
elseif seconds and not minutes then
error('SecondsDetik weredisediakan provided foruntuk ' .. direction .. ' without minutes alsotanpa beingmenentukan providedmenit', 2)
elseif not degrees then
if minutes then
error('MinutesMenit weredisediakan provided foruntuk ' .. direction .. ' without degrees alsotanpa beingmenentukan providedderajat', 2)
elseif hemisphere then
error('AHemisfer hemispheredisediakan was provided foruntuk ' .. direction .. ' without degrees alsotanpa beingmenentukan providedderajat', 2)
end
return nil
Baris 101 ⟶ 99:
decimal = tonumber(degrees)
if not decimal then
error('TheNilai degree valuederajat "' .. degrees .. '" providedyang fordisediakan untuk ' .. direction .. ' is nottidak validsah', 2)
elseif minutes and not tonumber(minutes) then
error('TheNilai minute valuemenit "' .. minutes .. '" providedyang fordisediakan untuk ' .. direction .. ' is nottidak validsah', 2)
elseif seconds and not tonumber(seconds) then
error('TheNilai second valuedetik "' .. seconds .. '" providedyang fordisediakan untuk ' .. direction .. ' is nottidak validsah', 2)
end
decimal = decimal + (minutes or 0)/60 + (seconds or 0)/3600
Baris 111 ⟶ 109:
local multiplier = hemisphereMultipliers[direction][hemisphere]
if not multiplier then
error('The hemisphereHemisfer "' .. hemisphere .. '" providedyang fordisediakan untuk ' .. direction .. ' is nottidak validsah', 2)
end
decimal = decimal * multiplier
Baris 120 ⟶ 118:
-- Finds a parameter in a transclusion of {{Coord}}.
local function coord2text(para,coord) -- this should be changed for languages which do not use Arabic numerals or the degree sign
local lat, long = mw.ustring.match(coord,'<span class="p%-latitude latitude">([^<]+)</span><span class="p%-longitude longitude">([^<]+)</span>')
if lat then
return tonumber(para == 'longitude' and long or lat)
end
local result = mw.text.split(mw.ustring.match(coord,'%-?[%.%d]+°[NS] %-?[%.%d]+°[EW]') or '', '[ °]')
if para == 'longitude' then result = {result[3], result[4]} end
if not tonumber(result[1]) or not result[2] then return error
mw.log('Malformed coordinates value', 2) end
mw.logObject(para, 'para')
mw.logObject(coord, 'coord')
return error('Kesalahan format nilai koordinat', 2)
end
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
end
Baris 158 ⟶ 165:
end
local width
local default_as_number = tonumber(mw.ustring.match(tostring(args.default_width),"%d*"))
if not args.width then
width = round((args.default_widthdefault_as_number or 240) * (tonumber(map('defaultscale')) or 1))
elseif mw.ustring.sub(args.width, -2) == 'px' then
width = mw.ustring.sub(args.width, 1, -3)
Baris 165 ⟶ 173:
width = args.width
end
local width_as_number = tonumber(mw.ustring.match(tostring(width),"%d*")) or 0;
local retval = args.float == 'center' and '<div class="center">' or ''
if width_as_number == 0 then
-- check to see if width is junk. If it is, then use default calculation
width = round((default_as_number or 240) * (tonumber(map('defaultscale')) or 1))
width_as_number = tonumber(mw.ustring.match(tostring(width),"%d*")) or 0;
end
if args.max_width ~= "" and args.max_width ~= nil then
-- check to see if width bigger than max_width
local max_as_number = tonumber(mw.ustring.match(args.max_width,"%d*")) or 0;
if width_as_number>max_as_number and max_as_number>0 then
width = args.max_width;
end
end
local retval = frame:extensionTag{name = 'templatestyles', args = {src = 'Module:Location map/styles.css'}}
if args.float == 'center' then
retval = retval .. '<div class="center">'
end
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
retval = retval .. '<div class="locmap noviewer thumb '
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'tleft'
Baris 183 ⟶ 207:
retval = retval .. '"><div style="position:relative;width:' .. width .. 'px' .. (args.border ~= 'none' and ';border:1px solid lightgray">' or '">')
else
retval = retval .. '<div class="locmap" style="width:' .. width .. 'px;'
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'float:left;clear:left'
Baris 196 ⟶ 220:
end
local image = getContainerImage(args, map)
local currentTitle = mw.title.getCurrentTitle()
retval = string.format(
'%s[[File:%s|%spx|%s%s]]',
Baris 201 ⟶ 226:
image,
width,
args.alt or ((args.label or mw.title.getCurrentTitle()currentTitle.text) .. ' berlokasi di ' .. map('name')),
args.maplink and ('|link=' .. args.maplink) or ''
)
if args.caption and args.caption ~= '' then
if (currentTitle.namespace == 0) and mw.ustring.find(args.caption, '##') then
retval = retval .. '[[Kategori:Halaman yang menggunakan peta lokasi dengan tanda angka ganda pada keterangannya]]'
end
end
if args.overlay_image then
return retval .. '<div style="position:absolute;top:0;left:0">[[BerkasFile:' .. args.overlay_image .. '|' .. width .. 'px]]</div>'
else
return retval
Baris 219 ⟶ 249:
end
local retval = '</div>'
local currentTitle = mw.title.getCurrentTitle()
if not args.caption or args.border == 'infobox' then
if args.border then
retval = retval .. '<div style="padding-top:0.2em">'
else
retval = retval .. '<div style="font-size:9091%;padding-top:3px">'
end
retval = retval
.. (args.caption or (args.label or mw.title.getCurrentTitle()currentTitle.text) .. ' (' .. map('name') .. ')')
.. '</div>'
elseif args.caption ~= '' then
-- This is not the pipe trick. We're creating a link with no text on purpose, so that CSS can give us a nice image
retval = retval .. '<div class="thumbcaption"><div class="magnify">[[:BerkasFile:' .. getContainerImage(args, map) .. '| ]]</div>' .. args.caption .. '</div>'
end
 
Baris 237 ⟶ 267:
retval = retval .. '<span class="switcher-label" style="display:none">' .. args.switcherLabel .. '</span>'
elseif args.autoSwitcherLabel then
retval = retval .. '<span class="switcher-label" style="display:none">ShowTampilkan map ofpeta ' .. map('name') .. '</span>'
end
Baris 248 ⟶ 278:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
retval = retval .. '[[Category:Location maps with possible errors|Page using removed parameter]]'
retval = retval .. '[[Kategori:Peta lokasi dengan parameter yang dihapus|caption_undefined]]'
end
end
if map('skew') ~= '' or map('lat_skew') ~= '' or map('crosses180') ~= '' or map('type') ~= '' then
mw.log('Removed parameter used in map definition ' .. map())
if currentTitle.namespace == 0 then
retval = retval .. '[[Category:Location maps with possible errors|Map using removed parameter]]'
local key = (map('skew') ~= '' and 'skew' or '') ..
(map('lat_skew') ~= '' and 'lat_skew' or '') ..
(map('crosses180') ~= '' and 'crosses180' or '') ..
(map('type') ~= '' and 'type' or '')
retval = retval .. '[[Kategori:Peta lokasi dengan parameter yang dihapus|' .. key .. ' ]]'
end
end
if string.find(map('name'), '|', 1, true) then
mw.log('Pipe used in name of map definition ' .. map())
if currentTitle.namespace == 0 then
retval = retval .. '[[Category:Location maps with possible errors|Name containing pipe]]'
retval = retval .. '[[Kategori:Peta lokasi dengan nama yang mengandung pipa]]'
end
end
if args.float == 'center' then
Baris 266 ⟶ 306:
local function markOuterDiv(x, y, imageDiv, labelDiv)
return mw.html.create('div')
:addClass('od')
:cssText('position:absolute;top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')
:node(imageDiv)
:node(labelDiv)
Baris 273 ⟶ 314:
local function markImageDiv(mark, marksize, label, link, alt, title)
local builder = mw.html.create('div')
:addClass('id')
:cssText('position:absolute;left:-' .. round(marksize / 2) .. 'px;top:-' .. round(marksize / 2) .. 'px;line-height:0')
:cssText('left:-' .. round(marksize / 2) .. 'px;top:-' .. round(marksize / 2) .. 'px')
:attr('title', title)
if marksize ~= 0 then
builder:wikitext(string.format(
'[[BerkasFile:%s|%dx%dpx|%s|link=%s%s]]',
mark,
marksize,
Baris 291 ⟶ 333:
local function markLabelDiv(label, label_size, label_width, position, background, x, marksize)
if tonumber(label_size) == 0 then
return mw.html.create('div'):cssTextaddClass('font-size:0%;position:absolutel0'):wikitext(label)
end
local builder = mw.html.create('div')
:cssText('font-size:' .. label_size .. '%;line-height:110%;position:absolute;width:' .. label_width .. 'em')
local distance = round(marksize / 2 + 1)
local spanCss
if position == 'top' then -- specified top
builder:addClass('pv'):cssText('bottom:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em;text-align:center')
elseif position == 'bottom' then -- specified bottom
builder:addClass('pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em;text-align:center')
elseif position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left
builder:cssTextaddClass('toppl'):-0.75em;cssText('right:' .. distance .. 'px;text-align:right')
spanCss = 'float:right'
else -- specified right or autodetected to right
builder:cssTextaddClass('toppr'):-0.75em;cssText('left:' .. distance .. 'px;text-align:left')
spanCss = 'float:left'
end
builder = builder:tag('spandiv')
:cssText('padding:1px')
:cssText(spanCss)
:wikitext(label)
if background then
Baris 337 ⟶ 374:
function p.mark(frame, args, map)
if not args then
args = getArgs(frame, {wrappers = 'TemplatTemplate:Location map~'})
end
local mapnames = {}
if not map then
mapif = p.getMapParams(args[1], frame)then
map = {}
for mapname in mw.text.gsplit(args[1], '#', true) do
map[#map + 1] = p.getMapParams(mw.ustring.gsub(mapname, '^%s*(.-)%s*$', '%1'), frame)
mapnames[#mapnames + 1] = mapname
end
if #map == 1 then map = map[1] end
else
map = p.getMapParams('World', frame)
args[1] = 'World'
end
end
if type(map) == 'table' then
local outputs = {}
local oldargs = args[1]
for k,v in ipairs(map) do
args[1] = mapnames[k]
outputs[k] = tostring(p.mark(frame, args, v))
end
args[1] = oldargs
return table.concat(outputs, '#PlaceList#') .. '#PlaceList#'
end
local x, y, longitude, latitude
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude')
latitude = decdeg(args.lat_deg, args.lat_min, args.lat_sec, args.lat_dir, args.lat, 'latitude')
if args.excludefrom then
-- If this mark is to be excluded from certain maps entirely (useful in the context of multiple maps)
for exclusionmap in mw.text.gsplit(args.excludefrom, '#', true) do
-- Check if this map is excluded. If so, return an empty string.
if args[1] == exclusionmap then
return ''
end
end
end
local builder = mw.html.create()
local currentTitle = mw.title.getCurrentTitle()
if args.coordinates then
-- Temporarily removed to facilitate infobox conversion. See [[Wikipedia:Coordinates in infoboxes]]
Baris 359 ⟶ 429:
local value = entity.claims.P625[1].mainsnak.datavalue.value
longitude, latitude = value.longitude, value.latitude
end
if args.link and (currentTitle.namespace == 0) then
builder:wikitext('[[Kategori:Peta lokasi menggunakan penanda tertaut dengan koordinat dari Wikidata]]')
end
end
if not longitude then
error('NoTidak valueada wasnilai providedyang fordiberikan longitudeuntuk garis bujur')
elseif not latitude then
error('NoTidak valueada wasnilai providedyang fordiberikan latitudeuntuk garis lintang')
end
if currentTitle.namespace > 0 then
local builder = mw.html.create()
if (not args.lon_deg) ~= (not args.lat_deg) then
builder:wikitext('[[CategoryKategori:LocationPeta mapslokasi withdengan differentpresisi longitudegaris andbujur latitudedan precisionsgaris lintang yang berbeda|DegreesDerajat]]')
elseif (not args.lon_min) ~= (not args.lat_min) then
builder:wikitext('[[CategoryKategori:LocationPeta mapslokasi withdengan differentpresisi longitudegaris andbujur latitudedan precisionsgaris lintang yang berbeda|MinutesMenit]]')
elseif (not args.lon_sec) ~= (not args.lat_sec) then
builder:wikitext('[[CategoryKategori:LocationPeta mapslokasi withdengan differentpresisi longitudegaris andbujur latitudedan precisionsgaris lintang yang berbeda|SecondsDetik]]')
elseif (not args.lon_dir) ~= (not args.lat_dir) then
builder:wikitext('[[CategoryKategori:LocationPeta mapslokasi withdengan differentpresisi longitudegaris andbujur latitudedan precisionsgaris lintang yang berbeda|HemisphereHemisfer]]')
elseif (not args.long) ~= (not args.lat) then
builder:wikitext('[[CategoryKategori:LocationPeta mapslokasi withdengan differentpresisi longitudegaris andbujur latitudedan precisionsgaris lintang yang berbeda|DecimalDesimal]]')
end
end
if ((tonumber(args.lat_deg) or 0) < 0) and ((tonumber(args.lat_min) or 0) ~= 0 or (tonumber(args.lat_sec) or 0) ~= 0 or (args.lat_dir and args.lat_dir ~='')) then
builder:wikitext('[[Kategori:Peta lokasi dengan derajat dan menit atau detik negatif]]')
end
if ((tonumber(args.lon_deg) or 0) < 0) and ((tonumber(args.lon_min) or 0) ~= 0 or (tonumber(args.lon_sec) or 0) ~= 0 or (args.lon_dir and args.lon_dir ~= '')) then
builder:wikitext('[[Kategori:Peta lokasi dengan derajat dan menit atau detik negatif]]')
end
if (((tonumber(args.lat_min) or 0) < 0) or ((tonumber(args.lat_sec) or 0) < 0)) then
builder:wikitext('[[Kategori:Peta lokasi dengan derajat dan menit atau detik negatif]]')
end
if (((tonumber(args.lon_min) or 0) < 0) or ((tonumber(args.lon_sec) or 0) < 0)) then
builder:wikitext('[[Kategori:Peta lokasi dengan derajat dan menit atau detik negatif]]')
end
if args.skew or args.lon_shift or args.markhigh then
Baris 385 ⟶ 471:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
builder:wikitext('[[Category:Location maps with possible errors|Page using removed parameter]]')
local key = (args.skew and 'skew' or '') ..
(args.lon_shift and 'lon_shift' or '') ..
(args.markhigh and 'markhigh' or '')
builder:wikitext('[[Kategori:Peta lokasi dengan parameter yang dihapus|' .. key ..' ]]')
end
end
if map('x') ~= '' then
Baris 404 ⟶ 495:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
builder:wikitext('[[Category:Location maps with possible errors|Outside flag not set with mark outside map]]')
local key = currentTitle.prefixedText
builder:wikitext('[[Kategori:Peta lokasi dengan tanda di luar peta dan parameter luar tidak diatur|' .. key .. ' ]]')
end
end
local mark = args.mark or map('mark')
Baris 414 ⟶ 508:
local labelDiv
if args.label and args.position ~= 'none' then
labelDiv = markLabelDiv(args.label, args.label_size or 9091, args.label_width or 6, args.position, args.background, x, marksize)
end
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv))
Baris 430 ⟶ 524:
 
function p.main(frame, args, map)
local caption_list = {}
if not args then
args = getArgs(frame, {wrappers = 'TemplatTemplate:Location map', valueFunc = p.valueFunc})
end
if args.useWikidata == nil then
Baris 440 ⟶ 535:
map = {}
for mapname in string.gmatch(args[1], '[^#]+') do
map[#map + 1] = p.getMapParams(mw.ustring.gsub(mapname, '^%s*(.-)%s*$', '%1'), frame)
end
if args['caption'] then
if args['caption'] == "" then
while #caption_list < #map do
caption_list[#caption_list + 1] = args['caption']
end
else
for caption in mw.text.gsplit(args['caption'], '##', true) do
caption_list[#caption_list + 1] = caption
end
end
end
if #map == 1 then map = map[1] end
Baris 450 ⟶ 556:
local altmaps = switcherSeparate(args.AlternativeMap)
if #altmaps > #map then
error(string.format('%d AlternativeMapsAlternatifMaps were provideddisediakan, buttetapi onlyhanya peta %d maps wereyang provideddisediakan', #altmaps, #map))
end
local overlays = switcherSeparate(args.overlay_image)
if #overlays > #map then
error(string.format('%d overlay_images were provideddisediakan, buttetapi onlyhanya peta %d maps wereyang provideddisediakan', #overlays, #map))
end
if #caption_list > #map then
error(string.format('%d captions disediakan, tetapi hanya peta %d yang disediakan', #caption_list, #map))
end
local outputs = {}
Baris 461 ⟶ 570:
args.AlternativeMap = altmaps[k]
args.overlay_image = overlays[k]
args.caption = caption_list[k]
outputs[k] = p.main(frame, args, v)
end