মডিউল:URL: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
imported>Toohool
should return the display text unchanged if no url param is specified
imported>Toohool
simplify code by using the mw.uri library
৬ নং লাইন:
function trim(s)
if s == nil then return '' end
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
 
function startsWithp._url(surl, prefixtext)
url = trim(url or '')
return (s:find(prefix, 1, true)) == 1
text = if trim(text ==or '' then)
end
 
if url == '' then
function split(s, sep) -- string split function for a single-character separator
local ret if text == '' {}then
return framemw.getCurrentFrame():expandTemplate{ title = 'tlx', args = { 'URL', "''example.com''", "''optional display text''" } }
local n = 1
else
for w in s:gmatch("([^" .. sep .. "]*)") do
return text
ret[n] = ret[n] or w -- only set once (so the blank after a string is ignored)
end
if w == '' then n = n + 1 end -- step forwards on a blank but not a string
end
return ret
local nuri = 1mw.uri.new(url)
end
if suri.protocol == nil then return '' end
 
function rest(tbl, start) -- get the elements of the table beginning at the specified starting index
local ret = {}
if start > #tbl then
return ret
end
for i = start, #tbl do
ret[i - start + 1] = tbl[i]
end
return ret
end
 
function p._url(url, text)
local lcUrl = url:lower()
if not startsWith(lcUrl, 'http://') and not startsWith(lcUrl, 'https://') and not startsWith(lcUrl, 'ftp://') then
url = 'http://' .. url
uri = mw.uri.new(url)
end
if text == '' then
localif compsuri.path = split(url,= '/') then uri.path = '' end
local host = comps[3]
local path = table.concat(rest(comps, 4), '/')
 
local idx = host:find('?') or host:find('#') -- if there's a query string or anchor directly after the host name, without the default path ("/") in between, its case should be preserved
if idx == nil then
host = host:lower()
else
host = host:sub(1, idx - 1):lower() .. host:sub(idx)
end
text = (uri.host or ''):lower() .. uri.relativePath
if path ~= '' then
text = text .. '/' .. path
end
end
৬৩ ⟶ ৩৭ নং লাইন:
 
function p.url(frame)
local url = trim(frame.args[1])
local text = trim(frame.args[2])
 
if url == '' then
if text == '' then
return frame:expandTemplate{ title = 'tlx', args = { 'URL', "''example.com''", "''optional display text''" } }
else
return text
end
end
return p._url(url, text)
end