local z = ---- This module implements {{URL}}---- See unit tests at [[Module:URL/testcases]]
function z.enlazar(url, texto)local p = {} --if true then return 'url: ' .. (url or '') .. ' texto: ' .. (texto or '') end if not url or url:matchlocal function safeUri('^%s*$') then return elseif url:findlocal success, uri = pcall('%[') or url:matchfunction('^{{{.*}}}$') then -- Por ejemplo, un parámetro de una plantilla, {{{página web|}}} return url elseif zmw.uri.esValidanew(urls) then urlCorregida = url end) elseif success then urlCorregida = 'http://' .. urlreturn uri
end
end local function extractUrl(args) for name, val in pairs(args) do if texto name ~= 2 and name ~= "msg" then return '[' local url = name .. urlCorregida "=" .. ' ' .. texto val; url = mw.ustring. gsub(url, '^[Hh][Tt]' else textoCorregido = urlCorregida[Tt][Pp]([Ss]?):match('/?)([^http://(.+])') or urlCorregida:match(, '^httpshttp%1://(.+)%3') or urlCorregida -- Eliminar la / al final textoCorregido local uri = textoCorregido:match('safeUri(url); if uri and uri.+)/$') or textoCorregidohost then return url end return '[' .. urlCorregida .. ' ' .. textoCorregido .. ']'end
end
end
function zp._url(url, text, msg) url = mw.text.trim(url or '') text = mw.text.trim(frametext or '') local nomsg = (msg or ''):sub(1,1):lower() == "n" or msg == 'false' -- boolean: true if not frame msg is "false" or not framestarts with n or N if url == '' then if text == '' then if nomsg then return nil else return mw.getCurrentFrame():expandTemplate{ title = 'tlx', args then= { 'URL', "''example.com''", "''optional display text''" } } end else returntext end
end
-- If the URL contains any unencoded spaces, encode them, because MediaWiki will otherwise interpret a space as the end of the URL. url = mw.ustring.gsub(url, '%s', function(s) return zmw.uri.encode(s, 'PATH') end) -- If there is an empty query string or fragment id, remove it as it will cause mw.uri.new to throw an error url = mw.ustring.gsub(url, '#$', '') url = mw.enlazarustring.gsub(frameurl, '%?$', '') -- If it's an HTTP[S] URL without the double slash, fix it. url = mw.ustring.argsgsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?):(/?)([^/])', 'http%1://%3') -- Handle URLs from Wikidata of the format http:// url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?)://', frame'http%1://') local uri = safeUri(url) -- Handle URL's without a protocol and URL's that are protocol-relative, -- e.argsg. www.example.com/foo or www.example.com:8080/foo, and //www.example.com/foo if uri and (not uri.protocol or (uri.protocol and not uri.host)) and url:sub(1, 2) ~= '//' then url = 'http://' .. url uri = safeUri(url) end if text == '' then if uri then if uri.path == '/' then uri.path = '' end local port = '' if uri.port then port = ':' .. uri.port end text = mw.ustring.lower(uri.host or '') .. port .. (uri.relativePath or '') -- Add <wbr> before _/.-# sequences text = mw.ustring.gsub(text,"(/+)","<wbr/>%1") -- This entry MUST be the first. "<wbr/>" has a "/" in it, you know. text = mw.ustring.gsub(text,"(%.+)","<wbr/>%1") -- text = mw.ustring.gsub(text,"(%-+)","<wbr/>%1") -- DISABLED for now text = mw.ustring.gsub(text,"(%#+)","<wbr/>%1") text = mw.ustring.gsub(text,"(_+)","<wbr/>%1") else -- URL is badly-formed, so just display whatever was passed in text = url end end return mw.ustring.format('<span class="url">[2%s %s]</span>', url, text)
end
--[[The main entry point for calling from Template:URL.--]]function zp.url(frame) local templateArgs = frame.args local parentArgs = frame:getParent().args local url = templateArgs[1] or parentArgs[1] local text = templateArgs[2] or parentArgs[2] or '' local msg = templateArgs.enlacePlanomsg or parentArgs.msg or '' -- Ver la plantilla Enlace planourl = url or extractUrl(templateArgs) or extractUrl(parentArgs) or ''-- returnp._url(url, text, msg)--end
-- Ver la función checkurl del módulo de citas[[The entry point for calling from the forked Template:URL2.This function returns no message by default.It strips out wiki-link markup, html tags, and everything after a space.--]]function zp.esValidaurl2(urlframe) return urllocal templateArgs = frame.args local parentArgs = frame:subgetParent().args local url = templateArgs[1] or parentArgs[1,] local text = templateArgs[2] or parentArgs[2) ] or '' -- default to no message local msg =templateArgs.msg or parentArgs.msg or 'no' url = "//" url or extractUrl(templateArgs) or extractUrl(parentArgs) or '' -- strip out html tags and [ ] from url url = (urlor ''):matchgsub( "^<[^/>]*>", ""):gsub("[%[%]]", "" ) -- truncate anything after a space url = url:gsub("%%20", " "):gsub(" .*", "") return p._url(url, text, msg)
end
return zp