“Module:Location map”与“Module:Location map/sandbox”:页面之间的差异
外观
(页面间差异)
删除的内容 添加的内容
小 已更改“Module:Location map”的保护设置:高風險模板([编辑=仅允许模板编辑员](无限期)[移动=仅允许模板编辑员](无限期)) |
无编辑摘要 |
||
| 第12行: | 第12行: | ||
function p.getMapParams(map, frame) |
function p.getMapParams(map, frame) |
||
if not map then |
if not map then |
||
error('要使用的位置图 |
error('必须指定要使用的位置图定义名称', 2) |
||
end |
end |
||
local moduletitle = mw.title.new('Module:Location map/data/' .. map) |
local moduletitle = mw.title.new('Module:Location map/data/' .. map) |
||
if not moduletitle then |
if not moduletitle then |
||
error(string.format('%q |
error(string.format('%q不是有效的位置图定义名称', map), 2) |
||
elseif moduletitle.exists then |
elseif moduletitle.exists then |
||
local mapData = mw.loadData('Module:Location map/data/' .. map) |
local mapData = mw.loadData('Module:Location map/data/' .. map) |
||
| 第48行: | 第48行: | ||
end |
end |
||
else |
else |
||
error('找不到指定的位置图 |
error('找不到指定的位置图定义:“Module:Location map/data/' .. map .. '”和“Template:Location map ' .. map .. '”都不存在', 2) |
||
end |
end |
||
end |
end |
||
| 第74行: | 第74行: | ||
local function decdeg(degrees, minutes, seconds, hemisphere, decimal, direction) |
local function decdeg(degrees, minutes, seconds, hemisphere, decimal, direction) |
||
local dir_name = (direction == 'latitude' and '纬度' or '经度') |
|||
if decimal then |
if decimal then |
||
if degrees then |
if degrees then |
||
error('十进制度数和度分秒格式不能同时为' .. dir_name .. '提供', 2) |
|||
error('Decimal and DMS degrees cannot both be provided for ' .. direction, 2) |
|||
elseif minutes then |
elseif minutes then |
||
error('分只能在度分秒格式中为' .. dir_name .. '提供', 2) |
|||
error('Minutes can only be provided with DMS degrees for ' .. direction, 2) |
|||
elseif seconds then |
elseif seconds then |
||
error('秒只能在度分秒格式中为' .. dir_name .. '提供', 2) |
|||
error('Seconds can only be provided with DMS degrees for ' .. direction, 2) |
|||
elseif hemisphere then |
elseif hemisphere then |
||
error('半球(N/S/E/W)只能在度分秒格式中为' .. dir_name .. '提供', 2) |
|||
error('A hemisphere can only be provided with DMS degrees for ' .. direction, 2) |
|||
end |
end |
||
local retval = tonumber(decimal) |
local retval = tonumber(decimal) |
||
| 第88行: | 第89行: | ||
return retval |
return retval |
||
end |
end |
||
error(' |
error('为' .. dir_name .. '提供的值“' .. decimal .. '”无效', 2) |
||
elseif seconds and not minutes then |
elseif seconds and not minutes then |
||
error(' |
error('为' .. dir_name .. '提供了秒但没有同时提供分', 2) |
||
elseif not degrees then |
elseif not degrees then |
||
if minutes then |
if minutes then |
||
error(' |
error('为' .. dir_name .. '提供了分但没有同时提供度', 2) |
||
elseif hemisphere then |
elseif hemisphere then |
||
error(' |
error('为' .. dir_name .. '提供了半球(N/S/E/W)但没有同时提供度', 2) |
||
end |
end |
||
return nil |
return nil |
||
| 第101行: | 第102行: | ||
decimal = tonumber(degrees) |
decimal = tonumber(degrees) |
||
if not decimal then |
if not decimal then |
||
error('为' .. |
error('为' .. dir_name .. '提供的度数值“' .. degrees .. '”无效', 2) |
||
elseif minutes and not tonumber(minutes) then |
elseif minutes and not tonumber(minutes) then |
||
error('为' .. |
error('为' .. dir_name .. '提供的分值“' .. minutes .. '”无效', 2) |
||
elseif seconds and not tonumber(seconds) then |
elseif seconds and not tonumber(seconds) then |
||
error('为' .. |
error('为' .. dir_name .. '提供的秒值“' .. seconds .. '”无效', 2) |
||
end |
end |
||
decimal = decimal + (minutes or 0)/60 + (seconds or 0)/3600 |
decimal = decimal + (minutes or 0)/60 + (seconds or 0)/3600 |
||
| 第111行: | 第112行: | ||
local multiplier = hemisphereMultipliers[direction][hemisphere] |
local multiplier = hemisphereMultipliers[direction][hemisphere] |
||
if not multiplier then |
if not multiplier then |
||
error('为' .. |
error('为' .. dir_name .. '提供的半球“' .. hemisphere .. '”无效', 2) |
||
end |
end |
||
decimal = decimal * multiplier |
decimal = decimal * multiplier |
||
| 第127行: | 第128行: | ||
if para == 'longitude' then result = {result[3], result[4]} end |
if para == 'longitude' then result = {result[3], result[4]} end |
||
if not tonumber(result[1]) or not result[2] then |
if not tonumber(result[1]) or not result[2] then |
||
mw.log(' |
mw.log('坐标值格式错误') |
||
mw.logObject(para, 'para') |
mw.logObject(para, 'para') |
||
mw.logObject(coord, 'coord') |
mw.logObject(coord, 'coord') |
||
return error(' |
return error('坐标值格式错误', 2) |
||
end |
end |
||
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]] |
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]] |
||
| 第152行: | 第153行: | ||
if args.AlternativeMap then |
if args.AlternativeMap then |
||
return args.AlternativeMap |
return args.AlternativeMap |
||
elseif args.relief |
elseif args.relief then |
||
local digits = mw.ustring.match(args.relief,'^[1-9][0-9]?$') or '1' -- image1 to image99 |
|||
return map('image1') |
|||
if map('image' .. digits) ~= '' then |
|||
else |
|||
return map('image' .. digits) |
|||
end |
|||
end |
end |
||
return map('image') |
|||
end |
end |
||
| 第193行: | 第196行: | ||
end |
end |
||
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then |
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then |
||
retval = retval .. '<div class="locmap |
retval = retval .. '<div class="locmap noresize thumb ' |
||
if args.float == '"left"' or args.float == 'left' then |
if args.float == '"left"' or args.float == 'left' then |
||
retval = retval .. ' |
retval = retval .. 'floatleft' |
||
elseif args.float == '"center"' or args.float == 'center' or args.float == '"none"' or args.float == 'none' then |
elseif args.float == '"center"' or args.float == 'center' or args.float == '"none"' or args.float == 'none' then |
||
retval = retval .. 'tnone' |
retval = retval .. 'tnone' |
||
else |
else |
||
retval = retval .. ' |
retval = retval .. 'floatright' |
||
end |
end |
||
retval = retval .. '"><div class="thumbinner" style="width:' .. (width + 2) .. 'px' |
retval = retval .. '"><div class="thumbinner" style="width:' .. (width + 2) .. 'px' |
||
| 第224行: | 第227行: | ||
local currentTitle = mw.title.getCurrentTitle() |
local currentTitle = mw.title.getCurrentTitle() |
||
retval = string.format( |
retval = string.format( |
||
'%s[[File:%s|%spx|%s%s|class=notpageimage]]', |
'%s[[File:%s|%spx|%s%s|class=notpageimage noviewer]]', |
||
retval, |
retval, |
||
image, |
image, |
||
| 第233行: | 第236行: | ||
if args.caption and args.caption ~= '' then |
if args.caption and args.caption ~= '' then |
||
if (currentTitle.namespace == 0) and mw.ustring.find(args.caption, '##') then |
if (currentTitle.namespace == 0) and mw.ustring.find(args.caption, '##') then |
||
retval = retval .. '[[Category: |
retval = retval .. '[[Category:说明文字带有两个井号的位置图]]' |
||
end |
end |
||
end |
end |
||
if args.overlay_image then |
if args.overlay_image then |
||
return retval .. '<div style="position:absolute;top:0;left:0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|class=notpageimage]]</div>' |
return retval .. '<div style="position:absolute;top:0;left:0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|class=notpageimage noviewer]]</div>' |
||
else |
else |
||
return retval |
return retval |
||
| 第263行: | 第266行: | ||
elseif args.caption ~= '' then |
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 |
-- 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) .. ' |
retval = retval .. '<div class="thumbcaption"><div class="magnify">[[:File:' .. getContainerImage(args, map) .. '| ]]</div>' .. args.caption .. '</div>' |
||
end |
end |
||
| 第274行: | 第277行: | ||
retval = retval .. '</div></div>' |
retval = retval .. '</div></div>' |
||
if args.caption_undefined then |
if args.caption_undefined then |
||
mw.log('使用了已 |
mw.log('使用了已弃用的参数caption_undefined。') |
||
local parent = frame:getParent() |
local parent = frame:getParent() |
||
if parent then |
if parent then |
||
mw.log(' |
mw.log('父模板是' .. parent:getTitle()) |
||
end |
end |
||
mw.logObject(args, 'args') |
mw.logObject(args, 'args') |
||
if currentTitle.namespace == 0 then |
if currentTitle.namespace == 0 then |
||
retval = retval .. '[[Category: |
retval = retval .. '[[Category:使用已弃用参数的位置图|caption_undefined]]' |
||
end |
end |
||
end |
end |
||
| 第291行: | 第294行: | ||
(map('crosses180') ~= '' and 'crosses180' or '') .. |
(map('crosses180') ~= '' and 'crosses180' or '') .. |
||
(map('type') ~= '' and 'type' or '') |
(map('type') ~= '' and 'type' or '') |
||
retval = retval .. '[[Category: |
retval = retval .. '[[Category:使用已弃用参数的位置图|' .. key .. ' ]]' |
||
end |
end |
||
end |
end |
||
| 第297行: | 第300行: | ||
mw.log('Pipe used in name of map definition ' .. map()) |
mw.log('Pipe used in name of map definition ' .. map()) |
||
if currentTitle.namespace == 0 then |
if currentTitle.namespace == 0 then |
||
retval = retval .. '[[Category: |
retval = retval .. '[[Category:地图名称包含管道符的位置图]]' |
||
end |
end |
||
end |
end |
||
| 第306行: | 第309行: | ||
end |
end |
||
local function markOuterDiv(x, y, imageDiv, labelDiv) |
local function markOuterDiv(x, y, imageDiv, labelDiv, label_size) |
||
return mw.html.create('div') |
return mw.html.create('div') |
||
:addClass('od |
:addClass('od') |
||
:addClass('notheme') -- T236137 |
|||
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%') |
|||
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%;font-size:' .. label_size .. '%') |
|||
:node(imageDiv) |
:node(imageDiv) |
||
:node(labelDiv) |
:node(labelDiv) |
||
| 第321行: | 第325行: | ||
if marksize ~= 0 then |
if marksize ~= 0 then |
||
builder:wikitext(string.format( |
builder:wikitext(string.format( |
||
'[[File:%s|%dx%dpx|%s|link=%s%s|class=notpageimage]]', |
'[[File:%s|%dx%dpx|%s|link=%s%s|class=notpageimage noviewer]]', |
||
mark, |
mark, |
||
marksize, |
marksize, |
||
| 第338行: | 第342行: | ||
end |
end |
||
local builder = mw.html.create('div') |
local builder = mw.html.create('div') |
||
:cssText(' |
:cssText('width:' .. label_width .. 'em') |
||
local distance = round(marksize / 2 + 1) |
local distance = round(marksize / 2 + 1) |
||
if position == 'top' then -- specified top |
if position == 'top' then -- specified top |
||
| 第421行: | 第425行: | ||
-- if longitude or latitude then |
-- if longitude or latitude then |
||
-- error(' |
-- error('来自[[Module:Coordinates]]的坐标和单独提供的坐标不能同时存在') |
||
-- end |
-- end |
||
longitude = coord2text('longitude', args.coordinates) |
longitude = coord2text('longitude', args.coordinates) |
||
| 第433行: | 第437行: | ||
end |
end |
||
if args.link and (currentTitle.namespace == 0) then |
if args.link and (currentTitle.namespace == 0) then |
||
builder:wikitext('[[Category: |
builder:wikitext('[[Category:坐标来自维基数据且带有链接标记的位置图]]') |
||
end |
end |
||
end |
end |
||
if not longitude then |
if not longitude then |
||
error(' |
error('未提供经度值') |
||
elseif not latitude then |
elseif not latitude then |
||
error(' |
error('未提供纬度值') |
||
end |
end |
||
if currentTitle.namespace > 0 then |
if currentTitle.namespace > 0 then |
||
| 第453行: | 第457行: | ||
builder:wikitext('[[Category:位置图的经度与纬度精度不同|小数]]') |
builder:wikitext('[[Category:位置图的经度与纬度精度不同|小数]]') |
||
end |
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:使用负度数和正分秒的位置图]]') |
|||
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:使用负度数和正分秒的位置图]]') |
|||
end |
|||
if (((tonumber(args.lat_min) or 0) < 0) or ((tonumber(args.lat_sec) or 0) < 0)) then |
|||
builder:wikitext('[[Category:使用负度数和正分秒的位置图]]') |
|||
end |
|||
if (((tonumber(args.lon_min) or 0) < 0) or ((tonumber(args.lon_sec) or 0) < 0)) then |
|||
builder:wikitext('[[Category:使用负度数和正分秒的位置图]]') |
|||
end |
end |
||
if args.skew or args.lon_shift or args.markhigh then |
if args.skew or args.lon_shift or args.markhigh then |
||
mw.log('调用时使用了已 |
mw.log('调用时使用了已弃用参数。') |
||
local parent = frame:getParent() |
local parent = frame:getParent() |
||
if parent then |
if parent then |
||
mw.log(' |
mw.log('父模板是' .. parent:getTitle()) |
||
end |
end |
||
mw.logObject(args, 'args') |
mw.logObject(args, 'args') |
||
| 第465行: | 第481行: | ||
(args.lon_shift and 'lon_shift' or '') .. |
(args.lon_shift and 'lon_shift' or '') .. |
||
(args.markhigh and 'markhigh' or '') |
(args.markhigh and 'markhigh' or '') |
||
builder:wikitext('[[Category: |
builder:wikitext('[[Category:使用已弃用参数的位置图|' .. key ..' ]]') |
||
end |
end |
||
end |
end |
||
| 第479行: | 第495行: | ||
end |
end |
||
if (x < 0 or x > 100 or y < 0 or y > 100) and not args.outside then |
if (x < 0 or x > 100 or y < 0 or y > 100) and not args.outside then |
||
mw.log(' |
mw.log('标记位于地图边界之外且未设置outside参数。x = ' .. x .. ', y = ' .. y) |
||
local parent = frame:getParent() |
local parent = frame:getParent() |
||
if parent then |
if parent then |
||
mw.log(' |
mw.log('父模板是' .. parent:getTitle()) |
||
end |
end |
||
mw.logObject(args, 'args') |
mw.logObject(args, 'args') |
||
if currentTitle.namespace == 0 then |
if currentTitle.namespace == 0 then |
||
local key = currentTitle.prefixedText |
local key = currentTitle.prefixedText |
||
builder:wikitext('[[Category: |
builder:wikitext('[[Category:标记超出地图范围且未设置outside参数的位置图|' .. key .. ' ]]') |
||
end |
end |
||
end |
end |
||
| 第496行: | 第512行: | ||
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8 |
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 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 |
local labelDiv |
||
if args.label and args.position ~= 'none' then |
if args.label and args.position ~= 'none' then |
||
labelDiv = markLabelDiv(args.label, |
labelDiv = markLabelDiv(args.label, label_size, args.label_width or 6, args.position, args.background, x, marksize) |
||
end |
end |
||
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv)) |
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv, label_size)) |
||
end |
end |
||
| 第511行: | 第528行: | ||
end |
end |
||
return retval |
return retval |
||
end |
|||
function p.infobox_pushpin_map(frame) |
|||
--This function is designed to be invoked from an infobox template |
|||
--* Some parameters (generally starting with "pushpin_") are meant to be exposed as parameters |
|||
-- in the outer infobox, settable by editors |
|||
--* Others are meant to be "hidden" (e.g., only set inside the infobox template code) |
|||
-- First get the combined arguments from both parent and invocation frame |
|||
local raw_args = getArgs(frame) |
|||
--If no map is supplied, return. |
|||
if not raw_args['pushpin_map'] then |
|||
return |
|||
end |
|||
--If no coordinates supplied, return. |
|||
if not raw_args['coordinates'] then |
|||
return |
|||
end |
|||
-- Now get arguments from just the invocation frame |
|||
local frame_args = getArgs(frame,{frameOnly=true}) |
|||
-- parsed_args will have the resulting merged parameters |
|||
local parsed_args = {} |
|||
-- Parse the arguments |
|||
parsed_args[1] = raw_args['pushpin_map'] |
|||
parsed_args.float = frame_args.float or 'center' |
|||
parsed_args.border = frame_args.border or 'infobox' |
|||
parsed_args.default_width = frame_args.default_width |
|||
parsed_args.max_width = frame_args.max_width |
|||
parsed_args.coordinates = raw_args['coordinates'] |
|||
parsed_args.caption = raw_args['pushpin_caption'] |
|||
parsed_args.relief = raw_args['pushpin_relief'] |
|||
parsed_args.label = raw_args['pushpin_label'] |
|||
parsed_args.label_size = raw_args['pushpin_label_size'] |
|||
parsed_args.position = raw_args['pushpin_label_position'] |
|||
parsed_args.mark = raw_args['pushpin_mark'] |
|||
parsed_args.marksize = raw_args['pushpin_mark_size'] |
|||
parsed_args.alt = raw_args['pushpin_alt'] |
|||
parsed_args.background = raw_args['pushpin_background'] |
|||
parsed_args.width = raw_args['pushpin_map_size'] |
|||
local map = {} |
|||
local caption_list = {} |
|||
for mapname in string.gmatch(parsed_args[1], '[^#]+') do |
|||
map[#map + 1] = p.getMapParams(mw.ustring.gsub(mapname, '^%s*(.-)%s*$', '%1'), frame) |
|||
end |
|||
if parsed_args['caption'] then |
|||
for caption in mw.text.gsplit(parsed_args['caption'], '##', true) do |
|||
caption_list[#caption_list + 1] = caption |
|||
end |
|||
end |
|||
if #map == 1 then |
|||
map = map[1] |
|||
if not parsed_args.caption then |
|||
parsed_args.caption = 'Location within ' .. map('name') |
|||
end |
|||
end |
|||
if type(map) == 'table' then |
|||
mw.log('----') |
|||
mw.logObject(map) |
|||
if #caption_list > #map then |
|||
error(string.format('提供了%d个说明文字,但只提供了%d个地图', #caption_list, #map)) |
|||
elseif not parsed_args.caption then |
|||
-- Set a default caption for each of the multiple maps |
|||
for i=1, #map do |
|||
caption_list[#caption_list + 1] = 'Location within '.. map[i]('name') |
|||
end |
|||
end |
|||
local outputs = {} |
|||
parsed_args.autoSwitcherLabel = true |
|||
for k,v in ipairs(map) do |
|||
parsed_args.caption = caption_list[k] |
|||
outputs[k] = p.main(frame, parsed_args, v) |
|||
end |
|||
return '<div class="switcher-container">' .. table.concat(outputs) .. '</div>' |
|||
else |
|||
return p.top(frame, parsed_args, map) .. tostring( p.mark(frame, parsed_args, map) ) .. p.bottom(frame, parsed_args, map) |
|||
end |
|||
end |
end |
||
| 第546行: | 第649行: | ||
local altmaps = switcherSeparate(args.AlternativeMap) |
local altmaps = switcherSeparate(args.AlternativeMap) |
||
if #altmaps > #map then |
if #altmaps > #map then |
||
error(string.format('%d |
error(string.format('提供了%d个自定义地图图像,但只提供了%d个地图', #altmaps, #map)) |
||
end |
end |
||
local overlays = switcherSeparate(args.overlay_image) |
local overlays = switcherSeparate(args.overlay_image) |
||
if #overlays > #map then |
if #overlays > #map then |
||
error(string.format('%d |
error(string.format('提供了%d个叠加图像,但只提供了%d个地图', #overlays, #map)) |
||
end |
end |
||
if #caption_list > #map then |
if #caption_list > #map then |
||
error(string.format('%d |
error(string.format('提供了%d个说明文字,但只提供了%d个地图', #caption_list, #map)) |
||
end |
end |
||
local outputs = {} |
local outputs = {} |
||