Modul:Location map: Razlika med redakcijama
Izbrisana vsebina Dodana vsebina
m tn v sporočilu napake |
mBrez povzetka urejanja Oznaka: vrnjeno |
||
Vrstica 1:
require('
local p = {}
local getArgs = require('
local function round(n, decimals)
Vrstica 12:
function p.getMapParams(map, frame)
if not map then
error('
end
local moduletitle = mw.title.new('
if not moduletitle then
error(string.format('%q
elseif moduletitle.exists then
local mapData = mw.loadData('
return function(name, params)
if name == nil then
return '
elseif mapData[name] == nil then
return ''
Vrstica 28:
else
return mapData[name]
end▼
end▼
end▼
if params then▼
end▼
end
end
else
error('
end
end
Vrstica 88 ⟶ 71:
return retval
end
error('
elseif seconds and not minutes then
error('Seconds were provided for ' .. direction .. ' without minutes also being provided', 2)
Vrstica 101 ⟶ 84:
decimal = tonumber(degrees)
if not decimal then
error('
elseif minutes and not tonumber(minutes) then
error('
elseif seconds and not tonumber(seconds) then
error('
end
decimal = decimal + (minutes or 0)/60 + (seconds or 0)/3600
Vrstica 111 ⟶ 94:
local multiplier = hemisphereMultipliers[direction][hemisphere]
if not multiplier then
error('
end
decimal = decimal * multiplier
Vrstica 118 ⟶ 101:
end
-- Finds a parameter in a transclusion of {{
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>')
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
mw.log('Malformed coordinates value' mw.logObject(para, 'para')
mw.logObject(coord, 'coord')
return error('Malformed coordinates value', 2)
end
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
end
Vrstica 143 ⟶ 135:
if args.AlternativeMap then
return args.AlternativeMap
elseif args.relief
local digits = mw.ustring.match(args.relief,'^[1-9][0-9]?$') or '1' -- image1 to image99
return map('image1')▼
if map('image' .. digits) ~= '' then
end
end
end
Vrstica 179 ⟶ 173:
end
end
local retval =
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 noresize thumb '
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'tleft'
Vrstica 197 ⟶ 194:
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'
Vrstica 210 ⟶ 207:
end
local image = getContainerImage(args, map)
local currentTitle = mw.title.getCurrentTitle()
retval = string.format(
'%s[[File:%s|%spx|%s%s|class=notpageimage]]',
retval,
image,
width,
args.alt or ((args.label or
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 .. '[[
end
end
if args.overlay_image then
return retval .. '<div style="position:absolute;top:0;left:0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|class=notpageimage]]</div>'
else
return retval
Vrstica 238 ⟶ 236:
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:
end
retval = retval
.. (args.caption or (args.label or
.. '</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">[[:File:' .. getContainerImage(args, map) .. '|class=notpageimage| ]]</div>' .. args.caption .. '</div>'
end
Vrstica 256 ⟶ 254:
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">Show map of ' .. map('name') .. '</span>'
end
Vrstica 267 ⟶ 265:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
retval = retval .. '[[
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
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 .. '[[
▲ 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 a name containing a pipe]]'
▲ end
end
if args.float == 'center' then
Vrstica 287 ⟶ 291:
end
local function markOuterDiv(x, y, imageDiv, labelDiv, label_size)
return mw.html.create('div')
:addClass('od')
:cssText('position:absolute;top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')▼
:addClass('notheme') -- T236137
▲ :cssText('
:node(imageDiv)
:node(labelDiv)
Vrstica 296 ⟶ 302:
local function markImageDiv(mark, marksize, label, link, alt, title)
local builder = mw.html.create('div')
:addClass('id')
:cssText('
:attr('title', title)
if marksize ~= 0 then
builder:wikitext(string.format(
'[[File:%s|%dx%dpx|%s|link=%s%s|class=notpageimage]]',
mark,
marksize,
Vrstica 314 ⟶ 321:
local function markLabelDiv(label, label_size, label_width, position, background, x, marksize)
if tonumber(label_size) == 0 then
return mw.html.create('div'):
end
local builder = mw.html.create('div')
:cssText('
local distance = round(marksize / 2 + 1)
if position == 'top' then -- specified top
builder:addClass('pv'):cssText('bottom:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em
elseif position == 'bottom' then -- specified bottom
builder:addClass('pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em
elseif position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left
builder:
else -- specified right or autodetected to right
builder:
end
builder = builder:tag('div')
:wikitext(label)
if background then
Vrstica 400 ⟶ 401:
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]]
-- if longitude or latitude then
-- error('Coordinates from [[
-- end
longitude = coord2text('longitude', args.coordinates)
Vrstica 414 ⟶ 417:
local value = entity.claims.P625[1].mainsnak.datavalue.value
longitude, latitude = value.longitude, value.latitude
if args.link and (currentTitle.namespace == 0) then
builder:wikitext('[[Category:Location maps with linked markers with coordinates from Wikidata]]')
end
end
Vrstica 421 ⟶ 427:
error('No value was provided for latitude')
end
if currentTitle.namespace > 0 then
▲ local builder = mw.html.create()
builder:wikitext('[[
builder:wikitext('[[
builder:wikitext('[[
builder:wikitext('[[
builder:wikitext('[[
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('[[Category:Location maps with negative degrees and minutes or seconds]]')
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('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if (((tonumber(args.lat_min) or 0) < 0) or ((tonumber(args.lat_sec) or 0) < 0)) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if (((tonumber(args.lon_min) or 0) < 0) or ((tonumber(args.lon_sec) or 0) < 0)) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if args.skew or args.lon_shift or args.markhigh then
Vrstica 440 ⟶ 459:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
local key = (args.skew and 'skew' or '') ..▼
(args.
builder:wikitext('[[
end
end
if map('x') ~= '' then
Vrstica 462 ⟶ 483:
end
mw.logObject(args, 'args')
if currentTitle.namespace == 0 then
local key = currentTitle.prefixedText
builder:wikitext('[[Category:Location maps with marks outside map and outside parameter not set|' .. key .. ' ]]')
end
end
local mark = args.mark or map('mark')
Vrstica 471 ⟶ 494:
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8
local imageDiv = markImageDiv(mark, marksize, args.label or mw.title.getCurrentTitle().text, args.link or '', args.alt, args[2])
local label_size = args.label_size or 91
local labelDiv
if args.label and args.position ~= 'none' then
labelDiv = markLabelDiv(args.label,
end
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv, label_size))
end
|