<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikem.org/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AURL</id>
	<title>Module:URL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikem.org/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AURL"/>
	<link rel="alternate" type="text/html" href="https://wikem.org/w/index.php?title=Module:URL&amp;action=history"/>
	<updated>2026-04-16T10:03:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://wikem.org/w/index.php?title=Module:URL&amp;diff=20345&amp;oldid=prev</id>
		<title>Ostermayer: Created page with &quot;-- -- This module implements {{URL}} -- -- See unit tests at Module:URL/tests  local p = {}   function trim(s)     return (mw.ustring.gsub(s, &quot;^%s*(.-)%s*$&quot;, &quot;%1&quot;)) end  f...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wikem.org/w/index.php?title=Module:URL&amp;diff=20345&amp;oldid=prev"/>
		<updated>2014-04-27T11:22:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-- -- This module implements {{URL}} -- -- See unit tests at &lt;a href=&quot;/w/index.php?title=Module:URL/tests&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module:URL/tests (page does not exist)&quot;&gt;Module:URL/tests&lt;/a&gt;  local p = {}   function trim(s)     return (mw.ustring.gsub(s, &amp;quot;^%s*(.-)%s*$&amp;quot;, &amp;quot;%1&amp;quot;)) end  f...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This module implements {{URL}}&lt;br /&gt;
--&lt;br /&gt;
-- See unit tests at [[Module:URL/tests]]&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
 &lt;br /&gt;
function trim(s)&lt;br /&gt;
    return (mw.ustring.gsub(s, &amp;quot;^%s*(.-)%s*$&amp;quot;, &amp;quot;%1&amp;quot;))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function safeUri(s)&lt;br /&gt;
    local success, uri = pcall(function()&lt;br /&gt;
        return mw.uri.new(s)&lt;br /&gt;
    end)&lt;br /&gt;
    if success then&lt;br /&gt;
        return uri&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._url(url, text)&lt;br /&gt;
    url = trim(url or '')&lt;br /&gt;
    text = trim(text or '')&lt;br /&gt;
    &lt;br /&gt;
    if url == '' then&lt;br /&gt;
        if text == '' then&lt;br /&gt;
            return mw.getCurrentFrame():expandTemplate{ title = 'tlx', args = { 'URL', &amp;quot;''example.com''&amp;quot;, &amp;quot;''optional display text''&amp;quot; } }&lt;br /&gt;
        else&lt;br /&gt;
            return text&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- If the URL contains any unencoded spaces, encode them, because MediaWiki will otherwise interpret a space as the end of the URL.&lt;br /&gt;
    url = mw.ustring.gsub(url, '%s', function(s) return mw.uri.encode(s, 'PATH') end)&lt;br /&gt;
    &lt;br /&gt;
    -- If there is an empty query string or fragment id, remove it as it will cause mw.uri.new to throw an error&lt;br /&gt;
    url = mw.ustring.gsub(url, '#$', '')&lt;br /&gt;
    url = mw.ustring.gsub(url, '%?$', '')&lt;br /&gt;
    &lt;br /&gt;
    -- If it's an HTTP[S] URL without the double slash, fix it.&lt;br /&gt;
    url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?):(/?)([^/])', 'http%1://%3')&lt;br /&gt;
&lt;br /&gt;
    -- Handle URLs from Wikidata of the format http&amp;amp;#58;//&lt;br /&gt;
    url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?)&amp;amp;#58;//', 'http%1://')&lt;br /&gt;
    &lt;br /&gt;
    local uri = safeUri(url)&lt;br /&gt;
    &lt;br /&gt;
    -- Handle URL's without a protocol and URL's that are protocol-relative, &lt;br /&gt;
    -- e.g. www.example.com/foo or www.example.com:8080/foo, and //www.example.com/foo&lt;br /&gt;
    if uri and (not uri.protocol or (uri.protocol and not uri.host)) and url:sub(1, 2) ~= '//' then&lt;br /&gt;
        url = 'http://' .. url&lt;br /&gt;
        uri = safeUri(url)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if text == '' then&lt;br /&gt;
        if uri then&lt;br /&gt;
            if uri.path == '/' then uri.path = '' end&lt;br /&gt;
            &lt;br /&gt;
            local port = ''&lt;br /&gt;
            if uri.port then port = ':' .. uri.port end&lt;br /&gt;
            &lt;br /&gt;
            text = mw.ustring.lower(uri.host or '') .. port .. (uri.relativePath or '')&lt;br /&gt;
        else -- URL is badly-formed, so just display whatever was passed in&lt;br /&gt;
            text = url&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return mw.ustring.format('&amp;lt;span class=&amp;quot;url&amp;quot;&amp;gt;[%s %s]&amp;lt;/span&amp;gt;', url, text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.url(frame)&lt;br /&gt;
    local templateArgs = frame.args&lt;br /&gt;
    local url = templateArgs[1] or ''&lt;br /&gt;
    local text = templateArgs[2] or ''&lt;br /&gt;
    return p._url(url, text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Ostermayer</name></author>
	</entry>
</feed>