Modul:URLutil: Unterschied zwischen den Versionen
+ getTLD() getTop2domain() + Gerrit:63406 +kl. Verbesserungen
w>PerfektesChaos (kl) |
w>PerfektesChaos (+ getTLD() getTop2domain() + Gerrit:63406 +kl. Verbesserungen) |
||
| Zeile 1: | Zeile 1: | ||
--[=[ URLutil 2013-05- | --[=[ URLutil 2013-05-19 | ||
Utilities for URL etc. on www. | Utilities for URL etc. on www. | ||
* getAuthority() | * getAuthority() | ||
| Zeile 5: | Zeile 5: | ||
* getPort() | * getPort() | ||
* getScheme() | * getScheme() | ||
* getTLD() | |||
* getTop2domain() | |||
* isAuthority() | * isAuthority() | ||
* isDomain() | * isDomain() | ||
| Zeile 33: | Zeile 35: | ||
URLutil.getAuthority = function ( url ) | URLutil.getAuthority = function ( url ) | ||
if type( url ) == "string" then | if type( url ) == "string" then | ||
local host, colon, port = mw.ustring.match( url .. "/", "^%s*%w*:?//([%w.%%-]+)(:?)([%d]*)/" ) | local host, colon, port = mw.ustring.match( url .. "/", "^%s*%w*:?//([%w%.%%-]+)(:?)([%d]*)/" ) | ||
if URLutil.isHost( host ) then | if URLutil.isHost( host ) then | ||
host = mw.ustring.lower( host ) | host = mw.ustring.lower( host ) | ||
| Zeile 88: | Zeile 90: | ||
return false | return false | ||
end -- URLutil.getScheme() | end -- URLutil.getScheme() | ||
URLutil.getTLD = function ( url ) | |||
local host = URLutil.getHost( url ) | |||
if host then | |||
host = mw.ustring.match( host, "[%w]+%.([a-z][a-z]+)$" ) | |||
return host or false | |||
end | |||
return false | |||
end -- URLutil.getTLD() | |||
URLutil.getTop2domain = function ( url ) | |||
local host = URLutil.getHost( url ) | |||
if host then | |||
host = mw.ustring.match( "." .. host, | |||
"(%.[%w%%]+%.[a-z][a-z]+)$" ) | |||
if host then | |||
return mw.ustring.sub( host, 2 ) | |||
end | |||
end | |||
return false | |||
end -- URLutil.getTop2domain() | |||
| Zeile 192: | Zeile 219: | ||
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 | ||
| Zeile 226: | Zeile 253: | ||
URLutil.isProtocolDialog = function ( prot ) | URLutil.isProtocolDialog = function ( prot ) | ||
return isProtocolAccepted( prot, " mailto irc ircs telnet " ) | return isProtocolAccepted( prot, " mailto irc ircs ssh telnet " ) | ||
end -- URLutil.isProtocolDialog() | end -- URLutil.isProtocolDialog() | ||
| Zeile 233: | Zeile 260: | ||
URLutil.isProtocolWiki = function ( prot ) | URLutil.isProtocolWiki = function ( prot ) | ||
return isProtocolAccepted( prot, | return isProtocolAccepted( prot, | ||
" ftp git http https nntp svn worldwind " ) | " ftp ftps git http https nntp sftp svn worldwind " ) | ||
end -- URLutil.isProtocolWiki() | end -- URLutil.isProtocolWiki() | ||
| Zeile 315: | Zeile 342: | ||
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.getTLD( frame ) | |||
return URLutil.getTLD( frame.args[ 1 ] ) or "" | |||
end | |||
function p.getTop2domain( frame ) | |||
return URLutil.getTop2domain( frame.args[ 1 ] ) or "" | |||
end | end | ||
function p.isAuthority( frame ) | function p.isAuthority( frame ) | ||