Modul:URLutil: Unterschied zwischen den Versionen
2018-09-20 Spezial:Diff/181074195/next
K (1 Version importiert: lua) |
de>NordNordWest (2018-09-20 Spezial:Diff/181074195/next) |
||
Zeile 1: | Zeile 1: | ||
local URLutil = { suite = "URLutil", | local URLutil = { suite = "URLutil", | ||
serial = "2018- | serial = "2018-09-20", | ||
item = 10859193 } | item = 10859193 } | ||
--[=[ | --[=[ | ||
Utilities for URL etc. on www. | Utilities for URL etc. on www. | ||
* encode() | |||
* getAuthority() | * getAuthority() | ||
* getFragment() | * getFragment() | ||
Zeile 37: | Zeile 38: | ||
* isWebURL() | * isWebURL() | ||
* wikiEscapeURL() | * wikiEscapeURL() | ||
* failsafe() | |||
Only [[dotted decimal]] notation for IPv4 expected. | 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. | ||
Zeile 189: | Zeile 191: | ||
return r | return r | ||
end -- getHash() | end -- getHash() | ||
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 909: | Zeile 939: | ||
since = false | since = false | ||
if type( item ) == "number" and item > 0 then | if type( item ) == "number" and item > 0 then | ||
local ent = mw.wikibase. | local ent = mw.wikibase.getEntity( string.format( "Q%d", | ||
item ) ) | |||
if type( ent ) == "table" then | if type( ent ) == "table" then | ||
local vsn = ent:formatPropertyValues( "P348" ) | local vsn = ent:formatPropertyValues( "P348" ) | ||
if type( vsn ) == "table" and | if type( vsn ) == "table" and | ||
type( vsn.value) == "string" and | type( vsn.value ) == "string" and | ||
vsn.value ~= "" then | vsn.value ~= "" then | ||
r = vsn.value | r = vsn.value | ||
Zeile 937: | Zeile 967: | ||
local p = {} | local p = {} | ||
function p.encode( frame ) | |||
return URLutil.encode( frame.args[ 1 ] or "", | |||
frame.args[ 2 ] ) | |||
end | |||
function p.getAuthority( frame ) | function p.getAuthority( frame ) | ||
return URLutil.getAuthority( frame.args[ 1 ] ) or "" | return URLutil.getAuthority( frame.args[ 1 ] ) or "" |