Modul:URLutil: Unterschied zwischen den Versionen
2018-09-20 Spezial:Diff/181074195/next
w>Schniggendiller (c/p aus https://de.wikipedia.beta.wmflabs.org/w/index.php?title=Modul:URLutil&oldid=21865 (Spezial:PermaLink/179745316#1× C&P Modul mit 700.000 Einbindungen)) |
w>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 190: | 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 915: | Zeile 944: | ||
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 938: | 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 "" | ||