Modul:URLutil: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=173391765&oldid=173390181
K (1 Version) |
wp>Septembermorgen (https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=173391765&oldid=173390181) |
||
Zeile 1: | Zeile 1: | ||
--[=[ | local URLutil = { suite = "URLutil", | ||
serial = "2018-01-24", | |||
item = 10859193 } | |||
--[=[ | |||
Utilities for URL etc. on www. | Utilities for URL etc. on www. | ||
* getAuthority() | * getAuthority() | ||
* getFragment() | |||
* getHost() | * getHost() | ||
* getLocation() | |||
* getNormalized() | |||
* getPath() | |||
* getPort() | * getPort() | ||
* getQuery() | |||
* getQueryTable() | |||
* getRelativePath() | |||
* getScheme() | * getScheme() | ||
* getSortkey() | |||
* getTLD() | * getTLD() | ||
* getTop2domain() | * getTop2domain() | ||
Zeile 12: | Zeile 22: | ||
* isDomain() | * isDomain() | ||
* isDomainExample() | * isDomainExample() | ||
* isDomainInt() | |||
* isHost() | * isHost() | ||
* isIP() | * isIP() | ||
Zeile 19: | Zeile 30: | ||
* isMailAddress() | * isMailAddress() | ||
* isMailLink() | * isMailLink() | ||
* isProtocolDialog() | * isProtocolDialog() | ||
* isProtocolWiki() | * isProtocolWiki() | ||
Zeile 27: | Zeile 37: | ||
* isWebURL() | * isWebURL() | ||
* wikiEscapeURL() | * wikiEscapeURL() | ||
Only [[dotted decimal]] notation for IPv4 | 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 34: | Zeile 44: | ||
local decodeComponentProtect = { F = "\"#%<>[\]^`{|}", | |||
P = "\"#%<>[\]^`{|}/?", | |||
Q = "\"#%<>[\]^`{|}&=+;", | |||
X = "\"#%<>[\]^`{|}&=+;/?" } | |||
local decodeComponentEscape = function ( averse, adapt ) | |||
return adapt == 20 or adapt == 127 or | |||
decodeComponentProtect[ averse ]:find( string.char( adapt ), | |||
1, | |||
true ) | |||
end -- decodeComponentEscape() | |||
local decodeComponentML = function ( ask ) | |||
local i = 1 | |||
local j, n, s | |||
while ( i ) do | |||
i = ask:find( "&#[xX]%x%x+;", i ) | |||
if i then | |||
j = ask:find( ";", i + 3, true ) | |||
s = ask:sub( i + 2, j - 1 ):upper() | |||
n = s:byte( 1, 1 ) | |||
if n == 88 then | |||
n = tonumber( s:sub( 2 ), 16 ) | |||
elseif s:match( "^%d+$" ) then | |||
n = tonumber( s ) | |||
else | |||
n = false | |||
end | |||
if n then | |||
if n >= 128 then | |||
s = string.format( "&#%d;", n ) | |||
elseif decodeComponentEscape( "X", n ) then | |||
s = string.format( "%%%02X", n ) | |||
else | |||
s = string.format( "%c", n ) | |||
end | |||
j = j + 1 | |||
if i == 1 then | |||
ask = s .. ask:sub( j ) | |||
else | |||
ask = string.format( "%s%s%s", | |||
ask:sub( 1, i - 1 ), | |||
s, | |||
ask:sub( j ) ) | |||
end | |||
end | |||
i = i + 1 | |||
end | end | ||
end | end -- while i | ||
return | return ask | ||
end -- | end -- decodeComponentML() | ||
local decodeComponentPercent = function ( ask, averse ) | |||
local i = 1 | |||
local j, k, m, n | |||
while ( i ) do | |||
i = ask:find( "%%[2-7]%x", i ) | |||
if i then | |||
j = i + 1 | |||
k = j + 1 | |||
n = ask:byte( k, k ) | |||
k = k + 1 | |||
m = ( n > 96 ) | |||
if m then | |||
n = n - 32 | |||
m = n | |||
end | |||
if n > 57 then | |||
n = n - 55 | |||
else | |||
n = n - 48 | |||
end | |||
n = ( ask:byte( j, j ) - 48 ) * 16 + n | |||
if decodeComponentEscape( averse, n ) then | |||
if m then | |||
ask = string.format( "%s%c%s", | |||
ask:sub( 1, j ), | |||
m, | |||
ask:sub( k ) ) | |||
end | |||
elseif i == 1 then | |||
ask = string.format( "%c%s", n, ask:sub( k ) ) | |||
else | |||
ask = string.format( "%s%c%s", | |||
ask:sub( 1, i - 1 ), | |||
n, | |||
ask:sub( k ) ) | |||
end | |||
i = j | |||
end | |||
end -- while i | |||
return ask | |||
end -- decodeComponentPercent() | |||
local getTopDomain = function ( url, mode ) | local getTopDomain = function ( url, mode ) | ||
local | local r = URLutil.getHost( url ) | ||
if | if r then | ||
local pattern = "[%w%%]+%.[ | local pattern = "[%w%%%-]+%.%a[%w%-]*%a)$" | ||
if mode == 3 then | if mode == 3 then | ||
pattern = "[%w%%]+%." .. pattern | pattern = "[%w%%%-]+%." .. pattern | ||
end | end | ||
r = mw.ustring.match( "." .. r, "%.(" .. pattern ) | |||
if | if not r then | ||
r = false | |||
end | end | ||
else | |||
r = false | |||
end | end | ||
return | return r | ||
end -- getTopDomain() | end -- getTopDomain() | ||
local getHash = function ( url ) | |||
local r = url:find( "#", 1, true ) | |||
if r then | |||
local i = url:find( "&#", 1, true ) | |||
if i then | |||
local s | |||
while ( i ) do | |||
s = url:sub( i + 2 ) | |||
if s:match( "^%d+;" ) or s:match( "^x%x+;" ) then | |||
r = url:find( "#", i + 4, true ) | |||
if r then | |||
i = url:find( "&#", i + 4, true ) | |||
else | |||
i = false | |||
end | |||
else | |||
r = i + 1 | |||
i = false | |||
end | |||
end -- while i | |||
end | |||
end | |||
return r | |||
end -- getHash() | |||
URLutil.getAuthority = function ( url ) | URLutil.getAuthority = function ( url ) | ||
local r | |||
if type( url ) == "string" then | if type( url ) == "string" then | ||
local | local colon, host, port | ||
local pattern = "^%s*%w*:?//([%w%.%%-]+)(:?)([%d]*)/" | local pattern = "^%s*%w*:?//([%w%.%%_-]+)(:?)([%d]*)/" | ||
local i = | local s = mw.text.decode( url ) | ||
local i = s:find( "#", 6, true ) | |||
if i then | if i then | ||
s = | s = s:sub( 1, i - 1 ) .. "/" | ||
else | else | ||
s = | s = s .. "/" | ||
end | end | ||
host, colon, port = mw.ustring.match( s, pattern ) | host, colon, port = mw.ustring.match( s, pattern ) | ||
Zeile 85: | Zeile 209: | ||
if colon == ":" then | if colon == ":" then | ||
if port:find( "^[1-9]" ) then | if port:find( "^[1-9]" ) then | ||
r = ( host .. ":" .. port ) | |||
end | end | ||
elseif #port == 0 then | elseif #port == 0 then | ||
r = host | |||
end | end | ||
end | end | ||
else | |||
r = false | |||
end | end | ||
return | return r | ||
end -- URLutil.getAuthority() | end -- URLutil.getAuthority() | ||
URLutil.getFragment = function ( url, decode ) | |||
local r | |||
if type( url ) == "string" then | |||
local i = getHash( url ) | |||
if i then | |||
r = mw.text.trim( url:sub( i ) ):sub( 2 ) | |||
if type( decode ) == "string" then | |||
local encoding = mw.text.trim( decode ) | |||
local launch | |||
if encoding == "%" then | |||
launch = true | |||
elseif encoding == "WIKI" then | |||
r = r:gsub( "%.(%x%x)", "%%%1" ) | |||
:gsub( "_", " " ) | |||
launch = true | |||
end | |||
if launch then | |||
r = mw.uri.decode( r, "PATH" ) | |||
end | |||
end | |||
else | |||
r = false | |||
end | |||
else | |||
r = nil | |||
end | |||
return r | |||
end -- URLutil.getFragment() | |||
URLutil.getHost = function ( url ) | URLutil.getHost = function ( url ) | ||
local | local r = URLutil.getAuthority( url ) | ||
if | if r then | ||
r = mw.ustring.match( r, "^([%w%.%%_%-]+):?[%d]*$" ) | |||
end | end | ||
return | return r | ||
end -- URLutil.getHost() | end -- URLutil.getHost() | ||
URLutil.getLocation = function ( url ) | |||
local r | |||
if type( url ) == "string" then | |||
r = mw.text.trim( url ) | |||
if r == "" then | |||
r = false | |||
else | |||
local i | |||
i = getHash( r ) | |||
if i then | |||
if i == 1 then | |||
r = false | |||
else | |||
r = r:sub( 1, i - 1 ) | |||
end | |||
end | |||
end | |||
else | |||
r = nil | |||
end | |||
return r | |||
end -- URLutil.getLocation() | |||
URLutil.getNormalized = function ( url ) | |||
local r | |||
if type( url ) == "string" then | |||
r = mw.text.trim( url ) | |||
if r == "" then | |||
r = false | |||
else | |||
r = decodeComponentML( r ) | |||
end | |||
else | |||
r = false | |||
end | |||
if r then | |||
local k = r:find( "//", 1, true ) | |||
if k then | |||
local j = r:find( "/", k + 2, true ) | |||
local sF, sP, sQ | |||
if r:find( "%%[2-7]%x" ) then | |||
local i = getHash( r ) | |||
if i then | |||
sF = r:sub( i + 1 ) | |||
r = r:sub( 1, i - 1 ) | |||
if sF == "" then | |||
sF = false | |||
else | |||
sF = decodeComponentPercent( sF, "F" ) | |||
end | |||
end | |||
i = r:find( "?", 1, true ) | |||
if i then | |||
sQ = r:sub( i ) | |||
r = r:sub( 1, i - 1 ) | |||
sQ = decodeComponentPercent( sQ, "Q" ) | |||
end | |||
if j then | |||
if #r > j then | |||
sP = r:sub( j + 1 ) | |||
sP = decodeComponentPercent( sP, "P" ) | |||
end | |||
r = r:sub( 1, j - 1 ) | |||
end | |||
elseif j then | |||
local n = #r | |||
if r:byte( n, n ) == 35 then -- '#' | |||
n = n - 1 | |||
r = r:sub( 1, n ) | |||
end | |||
if n > j then | |||
sP = r:sub( j + 1 ) | |||
end | |||
r = r:sub( 1, j - 1 ) | |||
end | |||
r = mw.ustring.lower( r ) .. "/" | |||
if sP then | |||
r = r .. sP | |||
end | |||
if sQ then | |||
r = r .. sQ | |||
end | |||
if sF then | |||
r = string.format( "%s#%s", r, sF ) | |||
end | |||
end | |||
r = r:gsub( " ", "%%20" ) | |||
:gsub( "%[", "%%5B" ) | |||
:gsub( "|", "%%7C" ) | |||
:gsub( "%]", "%%5D" ) | |||
:gsub( "%<", "%%3C" ) | |||
:gsub( "%>", "%%3E" ) | |||
end | |||
return r | |||
end -- URLutil.getNormalized() | |||
URLutil.getPath = function ( url ) | |||
local r = URLutil.getRelativePath( url ) | |||
if r then | |||
local s = r:match( "^([^%?]*)%?" ) | |||
if s then | |||
r = s | |||
end | |||
s = r:match( "^([^#]*)#" ) | |||
if s then | |||
r = s | |||
end | |||
end | |||
return r | |||
end -- URLutil.getPath() | |||
URLutil.getPort = function ( url ) | URLutil.getPort = function ( url ) | ||
local r = URLutil.getAuthority( url ) | |||
if | if r then | ||
r = r:match( ":([1-9][0-9]*)$" ) | |||
if | if r then | ||
r = tonumber( r ) | |||
else | |||
r = false | |||
end | end | ||
end | end | ||
return | return r | ||
end -- URLutil.getPort() | end -- URLutil.getPort() | ||
URLutil.getQuery = function ( url, key, separator ) | |||
local r = URLutil.getLocation( url ) | |||
if r then | |||
r = r:match( "^[^%?]*%?(.+)$" ) | |||
if r then | |||
if type( key ) == "string" then | |||
local single = mw.text.trim( key ) | |||
local sep = "&" | |||
local s, scan | |||
if type( separator ) == "string" then | |||
s = mw.text.trim( separator ) | |||
if s:match( "^[&;,/]$" ) then | |||
sep = s | |||
end | |||
end | |||
s = string.format( "%s%s%s", sep, r, sep ) | |||
scan = string.format( "%s%s=([^%s]*)%s", | |||
sep, key, sep, sep ) | |||
r = s:match( scan ) | |||
end | |||
end | |||
if not r then | |||
r = false | |||
end | |||
end | |||
return r | |||
end -- URLutil.getQuery() | |||
URLutil.getQueryTable = function ( url, separator ) | |||
local r = URLutil.getQuery( url ) | |||
if r then | |||
local sep = "&" | |||
local n, pairs, s, set | |||
if type( separator ) == "string" then | |||
s = mw.text.trim( separator ) | |||
if s:match( "^[&;,/]$" ) then | |||
sep = s | |||
end | |||
end | |||
pairs = mw.text.split( r, sep, true ) | |||
n = #pairs | |||
r = { } | |||
for i = 1, n do | |||
s = pairs[ i ] | |||
if s:find( "=", 2, true ) then | |||
s, set = s:match( "^([^=]+)=(.*)$" ) | |||
if s then | |||
r[ s ] = set | |||
end | |||
else | |||
r[ s ] = false | |||
end | |||
end -- for i | |||
end | |||
return r | |||
end -- URLutil.getQueryTable() | |||
URLutil.getRelativePath = function ( url ) | |||
local r | |||
if type( url ) == "string" then | |||
local s = url:match( "^%s*[a-zA-Z]*://(.*)$" ) | |||
if s then | |||
s = s:match( "[^/]+(/.*)$" ) | |||
else | |||
local x | |||
x, s = url:match( "^%s*(/?)(/.*)$" ) | |||
if x == "/" then | |||
s = s:match( "/[^/]+(/.*)$" ) | |||
end | |||
end | |||
if s then | |||
r = mw.text.trim( s ) | |||
elseif URLutil.isResourceURL( url ) then | |||
r = "/" | |||
else | |||
r = false | |||
end | |||
else | |||
r = nil | |||
end | |||
return r | |||
end -- URLutil.getRelativePath() | |||
URLutil.getScheme = function ( url ) | URLutil.getScheme = function ( url ) | ||
local r | |||
if type( url ) == "string" then | if type( url ) == "string" then | ||
local | local pattern = "^%s*([a-zA-Z]*)(:?)(//)" | ||
local prot, colon, slashes = url:match( pattern ) | |||
r = false | |||
if slashes == "//" then | if slashes == "//" then | ||
if colon == ":" then | if colon == ":" then | ||
if #prot > 2 then | if #prot > 2 then | ||
r = prot:lower() .. "://" | |||
end | end | ||
elseif #prot == 0 then | elseif #prot == 0 then | ||
r = "//" | |||
end | end | ||
end | end | ||
else | |||
r = nil | |||
end | end | ||
return | 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() | |||
URLutil.getTLD = function ( url ) | URLutil.getTLD = function ( url ) | ||
local | local r = URLutil.getHost( url ) | ||
if | if r then | ||
r = mw.ustring.match( r, "%w+%.(%a[%w%-]*%a)$" ) | |||
if not r then | |||
r = false | |||
end | |||
end | end | ||
return | return r | ||
end -- URLutil.getTLD() | end -- URLutil.getTLD() | ||
Zeile 162: | Zeile 577: | ||
URLutil.isAuthority = function ( s ) | URLutil.isAuthority = function ( s ) | ||
local r | |||
if type( s ) == "string" then | if type( s ) == "string" then | ||
local | local pattern = "^%s*([%w%.%%_-]+)(:?)(%d*)%s*$" | ||
local host, colon, port = mw.ustring.match( s, pattern ) | |||
if colon == ":" then | if colon == ":" then | ||
port = port:match( "^[1-9][0-9]*$" ) | port = port:match( "^[1-9][0-9]*$" ) | ||
if type( port ) ~= "string" then | if type( port ) ~= "string" then | ||
r = false | |||
end | end | ||
elseif port ~= "" then | elseif port ~= "" then | ||
r = false | |||
end | end | ||
r = URLutil.isHost( host ) | |||
else | |||
r = nil | |||
end | end | ||
return | return r | ||
end -- URLutil.isAuthority() | end -- URLutil.isAuthority() | ||
Zeile 180: | Zeile 599: | ||
URLutil.isDomain = function ( s ) | URLutil.isDomain = function ( s ) | ||
local r | |||
if type( s ) == "string" then | if type( s ) == "string" then | ||
local scan = "^%s*([%w%.%%_-]+%w)%.(%a[%w-]*%a)%s*$" | |||
local scope | |||
s, scope = mw.ustring.match( s, scan ) | |||
if type( s ) == "string" then | if type( s ) == "string" then | ||
if mw.ustring.find( s, "^%w" ) then | if mw.ustring.find( s, "^%w" ) then | ||
if mw.ustring.find( s, "..", 1, true ) then | if mw.ustring.find( s, "..", 1, true ) then | ||
r = false | |||
else | else | ||
r = true | |||
end | end | ||
end | end | ||
end | end | ||
else | |||
r = nil | |||
end | end | ||
return | return r | ||
end -- URLutil.isDomain() | end -- URLutil.isDomain() | ||
Zeile 213: | Zeile 637: | ||
return r | return r | ||
end -- URLutil.isDomainExample() | end -- URLutil.isDomainExample() | ||
URLutil.isDomainInt = function ( url ) | |||
-- Internationalized Domain Name (Punycode) | |||
local r = URLutil.getHost( url ) | |||
if r then | |||
if r:match( "^[!-~]+$" ) then | |||
local s = "." .. r | |||
if s:find( ".xn--", 1, true ) then | |||
r = true | |||
else | |||
r = false | |||
end | |||
else | |||
r = true | |||
end | |||
end | |||
return r | |||
end -- URLutil.isDomainInt() | |||
Zeile 273: | Zeile 717: | ||
return ( tonumber( n ) < 256 ) | return ( tonumber( n ) < 256 ) | ||
end | end | ||
local r = false | |||
if type( s ) == "string" then | if type( s ) == "string" then | ||
local p1, p2, p3, p4 = s:match( "^%s*([1-9][0-9]?[0-9]?)%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%s*$" ) | local p1, p2, p3, p4 = s:match( "^%s*([1-9][0-9]?[0-9]?)%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%s*$" ) | ||
if p1 and p2 and p3 and p4 then | if p1 and p2 and p3 and p4 then | ||
r = legal( p1 ) and legal( p2 ) and legal( p3 ) and legal( p4 ) | |||
end | end | ||
end | end | ||
return | return r | ||
end -- URLutil.isIPv4() | end -- URLutil.isIPv4() | ||
Zeile 352: | Zeile 797: | ||
return false | return false | ||
end -- isProtocolAccepted() | end -- isProtocolAccepted() | ||
Zeile 378: | Zeile 816: | ||
local scheme = URLutil.getScheme( url ) | local scheme = URLutil.getScheme( url ) | ||
if scheme then | if scheme then | ||
local s = " // http:// https:// ftp:// " | local s = " // http:// https:// ftp:// sftp:// " | ||
s = s:find( " " | s = s:find( string.format( " %s ", scheme ) ) | ||
if s then | if s then | ||
if URLutil.getAuthority( url ) then | if URLutil.getAuthority( url ) then | ||
if not url:match( "%S%s+%S" ) then | if not url:match( "%S%s+%S" ) then | ||
return true | local s1, s2 = url:match( "^([^#]+)(#.*)$" ) | ||
if s2 then | |||
if url:match( "^%s*[a-zA-Z]*:?//(.+)/" ) then | |||
return true | |||
end | |||
else | |||
return true | |||
end | |||
end | end | ||
end | end | ||
Zeile 397: | Zeile 842: | ||
local s = URLutil.getAuthority( url ) | local s = URLutil.getAuthority( url ) | ||
local pat = "[%[|%]" .. | local pat = "[%[|%]" .. | ||
mw.ustring.char( 8201, 45, 8207, 8234, 45, 8239, 8288 ) | mw.ustring.char( 8201, 45, 8207, | ||
8234, 45, 8239, | |||
8288 ) | |||
.. "]" | .. "]" | ||
if s:find( "@" ) | if s:find( "@" ) | ||
Zeile 446: | Zeile 893: | ||
return url | return url | ||
end -- URLutil.wikiEscapeURL() | end -- URLutil.wikiEscapeURL() | ||
function URLutil.failsafe( assert ) | |||
-- Retrieve versioning and check for compliance | |||
-- Precondition: | |||
-- assert -- string, with required version or "wikidata", | |||
-- or false | |||
-- Postcondition: | |||
-- Returns string with appropriate version, or false | |||
local since = assert | |||
local r | |||
if since == "wikidata" then | |||
local item = URLutil.item | |||
since = false | |||
if type( item ) == "number" and item > 0 then | |||
local ent = mw.wikibase.getEnt( string.format( "Q%d", | |||
item ) ) | |||
if type( ent ) == "table" then | |||
local vsn = ent:formatPropertyValues( "P348" ) | |||
if type( vsn ) == "table" and | |||
type( vsn.value) == "string" and | |||
vsn.value ~= "" then | |||
r = vsn.value | |||
end | |||
end | |||
end | |||
end | |||
if not r then | |||
if not since or since <= URLutil.serial then | |||
r = URLutil.serial | |||
else | |||
r = false | |||
end | |||
end | |||
return r | |||
end -- URLutil.failsafe() | |||
Zeile 453: | Zeile 937: | ||
local p = {} | local p = {} | ||
function p.getAuthority( frame ) | function p.getAuthority( frame ) | ||
return URLutil.getAuthority( frame.args[ 1 ] ) or "" | return URLutil.getAuthority( frame.args[ 1 ] ) or "" | ||
end | |||
function p.getFragment( frame ) | |||
local r = URLutil.getFragment( frame.args[ 1 ], frame.args[ 2 ] ) | |||
if r then | |||
r = "#" .. r | |||
else | |||
r = "" | |||
end | |||
return r | |||
end | end | ||
function p.getHost( frame ) | function p.getHost( frame ) | ||
return URLutil.getHost( frame.args[ 1 ] ) or "" | return URLutil.getHost( frame.args[ 1 ] ) or "" | ||
end | |||
function p.getLocation( frame ) | |||
return URLutil.getLocation( frame.args[ 1 ] ) or "" | |||
end | |||
function p.getNormalized( frame ) | |||
return URLutil.getNormalized( frame.args[ 1 ] ) or "" | |||
end | |||
function p.getPath( frame ) | |||
return URLutil.getPath( frame.args[ 1 ] ) or "" | |||
end | end | ||
function p.getPort( frame ) | function p.getPort( frame ) | ||
return URLutil.getPort( frame.args[ 1 ] ) or "" | return URLutil.getPort( frame.args[ 1 ] ) or "" | ||
end | |||
function p.getQuery( frame ) | |||
local r | |||
local key = frame.args[ 2 ] | |||
if key then | |||
key = mw.text.trim( key ) | |||
if key == "" then | |||
key = nil | |||
end | |||
end | |||
r = URLutil.getQuery( frame.args[ 1 ], key, frame.args[ 3 ] ) | |||
if r then | |||
if not key then | |||
r = "?" .. r | |||
end | |||
else | |||
r = "" | |||
end | |||
return r | |||
end | |||
function p.getRelativePath( frame ) | |||
return URLutil.getRelativePath( frame.args[ 1 ] ) or "" | |||
end | end | ||
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 ) | ||
Zeile 485: | Zeile 1.009: | ||
function p.isDomainExample( frame ) | function p.isDomainExample( frame ) | ||
return URLutil.isDomainExample( frame.args[ 1 ] ) and "1" or "" | return URLutil.isDomainExample( frame.args[ 1 ] ) and "1" or "" | ||
end | |||
function p.isDomainInt( frame ) | |||
return URLutil.isDomainInt( frame.args[ 1 ] ) and "1" or "" | |||
end | end | ||
function p.isHost( frame ) | function p.isHost( frame ) | ||
Zeile 506: | Zeile 1.033: | ||
function p.isMailLink( frame ) | function p.isMailLink( frame ) | ||
return URLutil.isMailLink( frame.args[ 1 ] ) and "1" or "" | return URLutil.isMailLink( frame.args[ 1 ] ) and "1" or "" | ||
end | end | ||
function p.isProtocolDialog( frame ) | function p.isProtocolDialog( frame ) | ||
Zeile 530: | Zeile 1.054: | ||
function p.wikiEscapeURL( frame ) | function p.wikiEscapeURL( frame ) | ||
return URLutil.wikiEscapeURL( frame.args[ 1 ] ) | return URLutil.wikiEscapeURL( frame.args[ 1 ] ) | ||
end | |||
p.failsafe = function ( frame ) | |||
local s = type( frame ) | |||
local since | |||
if s == "table" then | |||
since = frame.args[ 1 ] | |||
elseif s == "string" then | |||
since = frame | |||
end | |||
if since then | |||
since = mw.text.trim( since ) | |||
if since == "" then | |||
since = false | |||
end | |||
end | |||
return URLutil.failsafe( since ) or "" | |||
end | end | ||
function p.URLutil() | function p.URLutil() |