کاربر ناشناس
پودمان:Location map: تفاوت میان نسخهها
implement changes by User:Hike395 requested by User:Jonesey95 on the talk page
جز (۱ نسخه واردشده) |
(implement changes by User:Hike395 requested by User:Jonesey95 on the talk page) |
||
خط ۴: | خط ۴: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local function round(n, decimals) | local function round(n, decimals) | ||
local pow = 10^(decimals or 0) | local pow = 10^(decimals or 0) | ||
خط ۲۸: | خط ۲۸: | ||
else | else | ||
return mapData[name] | return mapData[name] | ||
end | end | ||
end | end | ||
else | else | ||
error('Unable to find the specified location map definition | error('Unable to find the specified location map definition: "Module:Location map/data/' .. map .. '" does not exist', 2) | ||
end | end | ||
end | end | ||
خط ۱۲۰: | خط ۱۰۳: | ||
-- Finds a parameter in a transclusion of {{Coord}}. | -- 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 function coord2text(para,coord) -- this should be changed for languages which do not use Arabic numerals or the degree sign | ||
local result = mw.text.split(mw.ustring.match(coord,'%-?[%.%d]+°[NS] %-?[%.%d]+°[EW]') or '', '[ °]') | 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 para == 'longitude' then result = {result[3], result[4]} end | ||
خط ۲۱۵: | خط ۱۹۳: | ||
end | end | ||
local image = getContainerImage(args, map) | local image = getContainerImage(args, map) | ||
local currentTitle = mw.title.getCurrentTitle() | |||
retval = string.format( | retval = string.format( | ||
'%s[[File:%s|%spx|%s%s]]', | '%s[[File:%s|%spx|%s%s]]', | ||
خط ۲۲۰: | خط ۱۹۹: | ||
image, | image, | ||
width, | width, | ||
args.alt or ((args.label or | args.alt or ((args.label or currentTitle.text) .. ' is located in ' .. map('name')), | ||
args.maplink and ('|link=' .. args.maplink) or '' | args.maplink and ('|link=' .. args.maplink) or '' | ||
) | ) | ||
if args.caption and args.caption ~= '' then | if args.caption and args.caption ~= '' then | ||
if mw.ustring.find(args.caption, '##') then | if (currentTitle.namespace == 0) and mw.ustring.find(args.caption, '##') then | ||
retval = retval .. '[[Category:Pages using location map with a double number sign in the caption]]' | retval = retval .. '[[Category:Pages using location map with a double number sign in the caption]]' | ||
end | end | ||
خط ۲۴۳: | خط ۲۲۲: | ||
end | end | ||
local retval = '</div>' | local retval = '</div>' | ||
local currentTitle = mw.title.getCurrentTitle() | |||
if not args.caption or args.border == 'infobox' then | if not args.caption or args.border == 'infobox' then | ||
if args.border then | if args.border then | ||
خط ۲۵۱: | خط ۲۳۰: | ||
end | end | ||
retval = retval | retval = retval | ||
.. (args.caption or (args.label or | .. (args.caption or (args.label or currentTitle.text) .. ' (' .. map('name') .. ')') | ||
.. '</div>' | .. '</div>' | ||
elseif args.caption ~= '' then | elseif args.caption ~= '' then | ||
خط ۲۷۲: | خط ۲۵۱: | ||
end | end | ||
mw.logObject(args, 'args') | mw.logObject(args, 'args') | ||
retval = retval .. '[[ | if currentTitle.namespace == 0 then | ||
retval = retval .. '[[Category:Location maps with removed parameters|caption_undefined]]' | |||
end | |||
end | end | ||
if map('skew') ~= '' or map('lat_skew') ~= '' or map('crosses180') ~= '' or map('type') ~= '' then | if map('skew') ~= '' or map('lat_skew') ~= '' or map('crosses180') ~= '' or map('type') ~= '' then | ||
mw.log('Removed parameter used in map definition ' .. map()) | mw.log('Removed parameter used in map definition ' .. map()) | ||
local key = (map('skew') ~= '' and 'skew' or '') .. | if currentTitle.namespace == 0 then | ||
local key = (map('skew') ~= '' and 'skew' or '') .. | |||
(map('lat_skew') ~= '' and 'lat_skew' or '') .. | (map('lat_skew') ~= '' and 'lat_skew' or '') .. | ||
(map('crosses180') ~= '' and 'crosses180' or '') .. | (map('crosses180') ~= '' and 'crosses180' or '') .. | ||
(map('type') ~= '' and 'type' or '') | (map('type') ~= '' and 'type' or '') | ||
retval = retval .. '[[Category:Location maps with removed parameters|' .. key .. ' ]]' | |||
end | |||
end | end | ||
if string.find(map('name'), '|', 1, true) then | if string.find(map('name'), '|', 1, true) then | ||
mw.log('Pipe used in name of map definition ' .. map()) | mw.log('Pipe used in name of map definition ' .. map()) | ||
retval = retval .. '[[ | if currentTitle.namespace == 0 then | ||
retval = retval .. '[[Category:Location maps with a name containing a pipe]]' | |||
end | |||
end | end | ||
if args.float == 'center' then | if args.float == 'center' then | ||
خط ۳۰۵: | خط ۲۹۰: | ||
if marksize ~= 0 then | if marksize ~= 0 then | ||
builder:wikitext(string.format( | builder:wikitext(string.format( | ||
'[[ | '[[File:%s|%dx%dpx|%s|link=%s%s]]', | ||
mark, | mark, | ||
marksize, | marksize, | ||
خط ۳۹۲: | خط ۳۷۷: | ||
return table.concat(outputs, '#PlaceList#') .. '#PlaceList#' | return table.concat(outputs, '#PlaceList#') .. '#PlaceList#' | ||
end | end | ||
local x, y, longitude, latitude | local x, y, longitude, latitude | ||
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude') | longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude') | ||
خط ۴۱۳: | خط ۳۹۰: | ||
end | end | ||
local builder = mw.html.create() | |||
local currentTitle = mw.title.getCurrentTitle() | |||
if args.coordinates then | if args.coordinates then | ||
-- Temporarily removed to facilitate infobox conversion. See [[Wikipedia:Coordinates in infoboxes]] | -- Temporarily removed to facilitate infobox conversion. See [[Wikipedia:Coordinates in infoboxes]] | ||
خط ۴۲۷: | خط ۴۰۶: | ||
local value = entity.claims.P625[1].mainsnak.datavalue.value | local value = entity.claims.P625[1].mainsnak.datavalue.value | ||
longitude, latitude = value.longitude, value.latitude | longitude, latitude = value.longitude, value.latitude | ||
end | |||
if args.link and (currentTitle.namespace == 0) then | |||
builder:wikitext('[[Category:Location maps with linked markers with coordinates from Wikidata]]') | |||
end | end | ||
end | end | ||
خط ۴۳۴: | خط ۴۱۶: | ||
error('No value was provided for latitude') | error('No value was provided for latitude') | ||
end | end | ||
if currentTitle.namespace > 0 then | |||
if (not args.lon_deg) ~= (not args.lat_deg) then | |||
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Degrees]]') | |||
elseif (not args.lon_min) ~= (not args.lat_min) then | |||
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Minutes]]') | |||
elseif (not args.lon_sec) ~= (not args.lat_sec) then | |||
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Seconds]]') | |||
elseif (not args.lon_dir) ~= (not args.lat_dir) then | |||
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Hemisphere]]') | |||
elseif (not args.long) ~= (not args.lat) then | |||
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Decimal]]') | |||
end | |||
end | end | ||
if args.skew or args.lon_shift or args.markhigh then | if args.skew or args.lon_shift or args.markhigh then | ||
خط ۴۵۳: | خط ۴۳۶: | ||
end | end | ||
mw.logObject(args, 'args') | mw.logObject(args, 'args') | ||
local key = (args.skew and 'skew' or '') .. | if currentTitle.namespace == 0 then | ||
local key = (args.skew and 'skew' or '') .. | |||
(args.lon_shift and 'lon_shift' or '') .. | |||
(args.markhigh and 'markhigh' or '') | |||
builder:wikitext('[[Category:Location maps with removed parameters|' .. key ..' ]]') | |||
end | |||
end | end | ||
if map('x') ~= '' then | if map('x') ~= '' then | ||
خط ۴۷۵: | خط ۴۶۰: | ||
end | end | ||
mw.logObject(args, 'args') | mw.logObject(args, 'args') | ||
local key = frame:preprocess('{{FULLPAGENAME}}') | if currentTitle.namespace == 0 then | ||
local key = frame:preprocess('{{FULLPAGENAME}}') | |||
builder:wikitext('[[Category:Location maps with marks outside map and outside parameter not set|' .. key .. ' ]]') | |||
end | |||
end | end | ||
local mark = args.mark or map('mark') | local mark = args.mark or map('mark') | ||
خط ۵۰۶: | خط ۴۹۳: | ||
args = getArgs(frame, {wrappers = 'Template:Location map', valueFunc = p.valueFunc}) | args = getArgs(frame, {wrappers = 'Template:Location map', valueFunc = p.valueFunc}) | ||
end | end | ||
if args.useWikidata == nil then | if args.useWikidata == nil then | ||
args.useWikidata = true | args.useWikidata = true |