Content deleted Content added
sync |
factor out geohack url generating code |
||
Line 393:
end
return html
-- generate URL of geohack map
local function geohack(input, args, LL, restargs)
-- create geohack link. Example:
-- https://geohack.toolforge.org/geohack.php?pagename=Mount_Whitney¶ms=36.578580925_N_118.29199495_W_type:mountain_region:US-CA_scale:100000_source:NGS▼
local url = ''▼
local namearg = args["name"]▼
url = url..'https://geohack.toolforge.org/geohack.php?'▼
local current_page = mw.title.getCurrentTitle()▼
local pagename = mw.uri.encode( current_page.prefixedText, 'WIKI' )▼
if not empty(pagename) then▼
url = url..'pagename='..pagename..'&'▼
end▼
LL.lat = LL.lat or 0▼
LL.long = LL.long or 0▼
LL.lat = ceil(LL.lat*1000000)/1000000▼
LL.long = ceil(LL.long*1000000)/1000000▼
url = url..'params='..mw.ustring.format('%.6f',LL.lat)..'_N_'▼
if LL.long < 0 then▼
url = url..mw.ustring.format('%.6f',-LL.long)..'_W'▼
else▼
url = url..mw.ustring.format('%.6f',LL.long)..'_E'▼
end▼
for i = restargs,#args do▼
url = url..'_'..args[i]▼
end▼
if not mw.ustring.find(input,"region") and LL.region then▼
url = url..'_region:'..LL.region▼
end▼
if not mw.ustring.find(input,"scale") and▼
not mw.ustring.find(input,"type") and▼
not mw.ustring.find(input,"dim") and LL.prec then▼
url = url..'_dim:'..floor(50*LL.prec+0.5)..'m'▼
end▼
if not empty(namearg) then▼
url = url .. "&title=" .. mw.uri.encode(namearg)▼
end▼
return url
end
Line 401 ⟶ 440:
end
local linktitle = args[2]
▲ local namearg = args["name"]
local rawurl = yesno(args["rawurl"])
local args = split(input,'_')
local LL
local restargs = 1
▲ local current_page = mw.title.getCurrentTitle()
▲ local pagename = mw.uri.encode( current_page.prefixedText, 'WIKI' )
if #args >= 2 and alldigits(args[2]) then
if mw.ustring.sub(args[1],1,1) == 'i' then
Line 436 ⟶ 472:
return linktitle ..warning(LL.err)
end
local url = geohack(input, args, LL, restargs)
▲ -- https://geohack.toolforge.org/geohack.php?pagename=Mount_Whitney¶ms=36.578580925_N_118.29199495_W_type:mountain_region:US-CA_scale:100000_source:NGS
▲ local url = ''
▲ end
▲ url = url..'https://geohack.toolforge.org/geohack.php?'
▲ if not empty(pagename) then
▲ url = url..'pagename='..pagename..'&'
▲ end
▲ LL.lat = LL.lat or 0
▲ LL.long = LL.long or 0
▲ LL.lat = ceil(LL.lat*1000000)/1000000
▲ LL.long = ceil(LL.long*1000000)/1000000
▲ url = url..'params='..mw.ustring.format('%.6f',LL.lat)..'_N_'
▲ if LL.long < 0 then
▲ url = url..mw.ustring.format('%.6f',-LL.long)..'_W'
▲ else
▲ url = url..mw.ustring.format('%.6f',LL.long)..'_E'
▲ end
▲ for i = restargs,#args do
▲ url = url..'_'..args[i]
▲ end
▲ if not mw.ustring.find(input,"region") and LL.region then
▲ url = url..'_region:'..LL.region
▲ end
▲ if not mw.ustring.find(input,"scale") and
▲ not mw.ustring.find(input,"type") and
▲ not mw.ustring.find(input,"dim") and LL.prec then
▲ url = url..'_dim:'..floor(50*LL.prec+0.5)..'m'
▲ end
▲ if not empty(namearg) then
▲ url = url .. "&title=" .. mw.uri.encode(namearg)
▲ end
if not rawurl then
url = '['..url..' '..linktitle..']'
end
return url
|