Modul:URLutil: Unterschied zwischen den Versionen
https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=173391765&oldid=173390181
w>Schniggendiller (c/p von https://de.wikipedia.beta.wmflabs.org/w/index.php?title=Modul:URLutil&oldid=21714 (Spezial:PermaLink/172473158#Frohes Neues; zweimal klein)) |
w>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", | local URLutil = { suite = "URLutil", | ||
serial = "2018-01- | serial = "2018-01-24", | ||
item = 10859193 } | |||
--[=[ | --[=[ | ||
Utilities for URL etc. on www. | Utilities for URL etc. on www. | ||
Zeile 822: | Zeile 823: | ||
local s1, s2 = url:match( "^([^#]+)(#.*)$" ) | local s1, s2 = url:match( "^([^#]+)(#.*)$" ) | ||
if s2 then | if s2 then | ||
if url:match( "^%s*[a-zA-Z]*://(.+)/" ) then | if url:match( "^%s*[a-zA-Z]*:?//(.+)/" ) then | ||
return true | return true | ||
end | end | ||
Zeile 892: | 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 1.017: | Zeile 1.055: | ||
return URLutil.wikiEscapeURL( frame.args[ 1 ] ) | return URLutil.wikiEscapeURL( frame.args[ 1 ] ) | ||
end | end | ||
p.failsafe = function ( frame ) | |||
return URLutil. | 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() |