Modul:URLutil: Unterschied zwischen den Versionen
Inhalt gelöscht Inhalt hinzugefügt
ICON (Diskussion | Beiträge) Die Seite wurde neu angelegt: „local URLutil = { suite = "URLutil", serial = "2018-01-24", item = 10859193 } --[=[ Utilities for URL etc. on www. * get…“ |
w>XanonymusX 2022-04-05 |
||
Zeile 1:
local URLutil = { suite = "URLutil",
serial = "
item = 10859193 }
--[=[
Utilities for URL etc. on www.
* decode()
* encode()
* getAuthority()
* getFragment()
Zeile 24 ⟶ 26:
* isDomainInt()
* isHost()
* isHostPathResource()
* isIP()
* isIPlocal()
Zeile 37 ⟶ 40:
* isWebURL()
* wikiEscapeURL()
* failsafe()
Only [[dotted decimal]] notation for IPv4 expected.
Does not support dotted hexadecimal, dotted octal, or single-number formats.
IPv6 URL (bracketed) not yet implemented; might need Wikintax escaping anyway.
]=]
local Failsafe = URLutil
Zeile 46 ⟶ 51:
local decodeComponentProtect = { F = "\"#%<>[\]^`{|}",
P = "\"#%<>[\]^`{|}/?",
Q = "\"#%<>[\]^`{|}&=+;,",
X = "\"#%<>[\]^`{|}&=+;,/?" }
Zeile 123 ⟶ 128:
end
n = ( ask:byte( j, j ) - 48 ) * 16 + n
if
ask:sub( i + 3, i + 5 ) == "%27" then
j = i + 6
while ( ask:sub( j, j + 2 ) == "%27" ) do
j = j + 3
end -- while "%27"
elseif decodeComponentEscape( averse, n ) then
if m then
ask = string.format( "%s%c%s",
Zeile 189 ⟶ 200:
return r
end -- getHash()
URLutil.decode = function ( url, enctype )
local r, s
if type( enctype ) == "string" then
s = mw.text.trim( enctype )
if s == "" then
s = false
else
s = s:upper()
end
end
r = mw.text.encode( mw.uri.decode( url, s ) )
if r:find( "[%[|%]]" ) then
local k
r, k = r:gsub( "%[", "[" )
:gsub( "|", "|" )
:gsub( "%]", "]" )
end
return r
end -- URLutil.decode()
URLutil.encode = function ( url, enctype )
local k, r, s
if type( enctype ) == "string" then
s = mw.text.trim( enctype )
if s == "" then
s = false
else
s = s:upper()
end
end
r = mw.uri.encode( url, s )
k = r:byte( 1, 1 )
if -- k == 35 or -- #
k == 42 or -- *
k == 58 or -- :
k == 59 then -- ;
r = string.format( "%%%X%s", k, r:sub( 2 ) )
end
if r:find( "[%[|%]]" ) then
r, k = r:gsub( "%[", "%5B" )
:gsub( "|", "%7C" )
:gsub( "%]", "%5D" )
end
return r
end -- URLutil.encode()
Zeile 601 ⟶ 662:
local r
if type( s ) == "string" then
local scan = "^%s*([%w%.%%_-]
local scope
s, scope = mw.ustring.match( s, scan )
Zeile 663 ⟶ 724:
return URLutil.isDomain( s ) or URLutil.isIP( s )
end -- URLutil.isHost()
URLutil.isHostPathResource = function ( s )
local r = URLutil.isResourceURL( s )
if not r and s then
r = URLutil.isResourceURL( "//" .. mw.text.trim( s ) )
end
return r
end -- URLutil.isHostPathResource()
Zeile 842 ⟶ 913:
local s = URLutil.getAuthority( url )
local pat = "[%[|%]" ..
mw.ustring.char(
8201, 45, 8207,
8234, 45, 8239,
8288 )
Zeile 875 ⟶ 947:
URLutil.isWebURL = function ( url )
if URLutil.getScheme( url ) and URLutil.getAuthority( url ) then
if not url:
not url:find( "''", 1, true ) then
return true
end
Zeile 896 ⟶ 969:
-- Retrieve versioning and check for compliance
-- Precondition:
--
-- or wikidata|item|~|@ or false
-- Postcondition:
-- Returns string -- with
-- false -- if appropriate
-- 2020-08-17
local since = atleast
local last = ( since == "~" )
local linked = ( since == "@" )
local link = ( since == "item" )
local r
if last or link or linked or since == "wikidata" then
local item =
since = false
if type( item ) == "number" and item > 0 then
local
if link then
else
if type( vsn ) == "table" and
type( vsn.value ) == "string" and
vsn.value ~= "" then
if last and vsn.value == Failsafe.serial then
r = false
elseif linked then
if mw.title.getCurrentTitle().prefixedText
== mw.wikibase.getSitelink( suited ) then
r = false
else
r = suited
end
else
r = vsn.value
end
end
end
end
end
end
if
if not since or since <=
r =
else
r = false
Zeile 929 ⟶ 1.023:
end
return r
end --
local function Template( frame, action, amount )
-- Run actual code from template transclusion
-- Precondition:
-- frame -- object
-- action -- string, with function name
-- amount -- number, of args if > 1
-- Postcondition:
-- Return string or not
local n = amount or 1
local v = { }
local r, s
for i = 1, n do
s = frame.args[ i ]
if s then
s = mw.text.trim( s )
if s ~= "" then
v[ i ] = s
end
end
end -- for i
if v[ 1 ] then
r = URLutil[ action ]( v[ 1 ], v[ 2 ], v[ 3 ] )
end
return r
end -- Template()
local p = {}
function p.decode( frame )
return Template( frame, "decode", 2 ) or ""
end
function p.encode( frame )
return Template( frame, "encode", 2 ) or ""
end
function p.getAuthority( frame )
return
end
function p.getFragment( frame )
local r =
if r then
r = "#" .. r
Zeile 950 ⟶ 1.076:
end
function p.getHost( frame )
return
end
function p.getLocation( frame )
return
end
function p.getNormalized( frame )
return
end
function p.getPath( frame )
return
end
function p.getPort( frame )
return
end
function p.getQuery( frame )
local r = Template( frame, "getQuery", 3 )
if r then
if key == ""
key = nil
end
end
if not key then
r = "?" .. r
Zeile 984 ⟶ 1.109:
end
function p.getRelativePath( frame )
return
end
function p.getScheme( frame )
return
end
function p.getSortkey( frame )
return
end
function p.getTLD( frame )
return
end
function p.getTop2domain( frame )
return
end
function p.getTop3domain( frame )
return
end
function p.isAuthority( frame )
return
end
function p.isDomain( frame )
return
end
function p.isDomainExample( frame )
return
end
function p.isDomainInt( frame )
return
end
function p.isHost( frame )
return
end
function p.isHostPathResource( frame )
return Template( frame, "isHostPathResource" ) and "1" or ""
end
function p.isIP( frame )
return
end
function p.isIPlocal( frame )
return
end
function p.isIPv4( frame )
return
end
function p.isIPv6( frame )
return
end
function p.isMailAddress( frame )
return
end
function p.isMailLink( frame )
return
end
function p.isProtocolDialog( frame )
return
end
function p.isProtocolWiki( frame )
return
end
function p.isResourceURL( frame )
return
end
function p.isSuspiciousURL( frame )
return
end
function p.isUnescapedURL( frame )
return
end
function p.isWebURL( frame )
return
end
function p.wikiEscapeURL( frame )
return
end
p.failsafe = function ( frame )
Zeile 1.069 ⟶ 1.197:
end
end
return
end
function p.URLutil()
| |||