Zum Inhalt springen

Modul:URLutil: Unterschied zwischen den Versionen

kl
w>PerfektesChaos
(update)
w>PerfektesChaos
(kl)
Zeile 1: Zeile 1:
--[=[ URLutil 2013-04-24
--[=[ URLutil 2013-05-06
Utilities for URL etc. on www.
Utilities for URL etc. on www.
* getAuthority()
* getAuthority()
Zeile 22: Zeile 22:
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.
Other modules can require this module and call functions via an object.
We return an object with small stub functions to call the real ones
so that the functions can be called from templates also.
----
Based upon  w:en:Special:Permalink/542839577?title=Module:IPAddress  2013-03-01
Unit tests at :en:Module:IPAddress/tests
]=]
]=]


Zeile 84: Zeile 77:
         local prot, colon, slashes = url:match( "^%s*([a-zA-Z]*)(:?)(//)" )
         local prot, colon, slashes = url:match( "^%s*([a-zA-Z]*)(:?)(//)" )
         if slashes == "//" then
         if slashes == "//" then
          if colon == ":" then
            if colon == ":" then
              if #prot > 2 then
                if #prot > 2 then
                  return prot:lower() .. "://"
                    return prot:lower() .. "://"
              end
                end
          elseif #prot == 0 then
            elseif #prot == 0 then
              return "//"
                return "//"
          end
            end
         end
         end
     end
     end
Zeile 188: Zeile 181:
URLutil.isMailAddress = function ( s )
URLutil.isMailAddress = function ( s )
     if type( s ) == "string" then
     if type( s ) == "string" then
        s = mw.ustring.match( s, "^%s*[%w%.%%_-]+@([%w%.%%-]+)%s*$" )
        s = mw.ustring.match( s, "^%s*[%w%.%%_-]+@([%w%.%%-]+)%s*$" )
        return URLutil.isDomain( s )
        return URLutil.isDomain( s )
     end
     end
     return false
     return false
Zeile 198: Zeile 191:
URLutil.isMailLink = function ( s )
URLutil.isMailLink = function ( s )
     if type( s ) == "string" then
     if type( s ) == "string" then
        local addr
        local addr
        s, addr = mw.ustring.match( s, "^%s([Mm][Aa][Ii][Ll][Tt][Oo]):(%S[%w%.%%_-]*@[%w%.%%-]+)%s$*" )
        s, addr = mw.ustring.match( s, "^%s([Mm][Aa][Ii][Ll][Tt][Oo]):(%S[%w%.%%_-]*@[%w%.%%-]+)%s$*" )
        if type( s ) == "string" then
        if type( s ) == "string" then
            if s:lower() == "mailto" then
            if s:lower() == "mailto" then
                return URLutil.isMailAddress( addr )
                return URLutil.isMailAddress( addr )
            end
            end
        end
        end
     end
     end
     return false
     return false
Anonymer Benutzer