Zum Inhalt springen

Modul:URLutil: Unterschied zwischen den Versionen

1.492 Bytes hinzugefügt ,  vor 8 Jahren
2016-03-09
w>PerfektesChaos
(2016-03-06)
w>PerfektesChaos
(2016-03-09)
Zeile 1: Zeile 1:
local URLutil = { suite  = "URLutil",
local URLutil = { suite  = "URLutil",
                   serial = "2016-03-06" };
                   serial = "2016-03-09" };
--[=[
--[=[
Utilities for URL etc. on www.
Utilities for URL etc. on www.
Zeile 14: Zeile 14:
* getRelativePath()
* getRelativePath()
* getScheme()
* getScheme()
* getSortkey()
* getTLD()
* getTLD()
* getTop2domain()
* getTop2domain()
Zeile 35: Zeile 36:
* isWebURL()
* isWebURL()
* wikiEscapeURL()
* wikiEscapeURL()
Only [[dotted decimal]] notation for IPv4 supported.
Only [[dotted decimal]] notation for IPv4 expected.
Does not support dotted hexadecimal, dotted octal, or single-number formats.
Does not support dotted hexadecimal, dotted octal, or single-number formats.
IPv6 URL (bracketed) not yet implemented; might need Wikintax escaping anyway.
IPv6 URL (bracketed) not yet implemented; might need Wikintax escaping anyway.
Zeile 514: Zeile 515:
     return r
     return r
end -- URLutil.getScheme()
end -- URLutil.getScheme()
URLutil.getSortkey = function ( url )
    local r = url
    if type( url ) == "string" then
        local i = url:find( "//" )
        if i then
            local scheme
            if i == 0 then
                scheme = ""
            else
                scheme = url:match( "^%s*([a-zA-Z]*)://" )
            end
            if scheme then
                local s = url:sub( i + 2 )
                local comps, site, m, suffix
                scheme = scheme:lower()
                i      = s:find( "/" )
                if i  and  i > 1 then
                    suffix = s:sub( i + 1 )            -- mw.uri.encode()
                    s      = s:sub( 1,  i - 1 )
                    suffix = suffix:gsub( "#", " " )
                else
                    suffix = ""
                end
                site, m = s:match( "^(.+)(:%d+)$" )
                if not m then
                    site = s
                    m    = 0
                end
                comps = mw.text.split( site:lower(), ".", true )
                r = "///"
                for i = #comps, 2, -1 do
                    r =  string.format( "%s%s.", r, comps[ i ] )
                end -- for --i
                r = string.format( "%s%s %d %s: %s",
                                  r, comps[ 1 ], m, scheme, suffix )
            end
        end
    end
    return r
end -- URLutil.getSortkey()




Zeile 927: Zeile 971:
function p.getScheme( frame )
function p.getScheme( frame )
     return URLutil.getScheme( frame.args[ 1 ] ) or ""
     return URLutil.getScheme( frame.args[ 1 ] ) or ""
end
function p.getSortkey( frame )
    return URLutil.getSortkey( frame.args[ 1 ] ) or ""
end
end
function p.getTLD( frame )
function p.getTLD( frame )
Anonymer Benutzer