Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
K (35 Versionen von w:Modul:WLink importiert) |
K (35 Versionen von wikivoyage:Modul:WLink importiert) |
||
| (5 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
local WLink = { suite = "WLink", | local WLink = { suite = "WLink", | ||
serial = " | serial = "2016-10-05" }; | ||
--[=[ | --[=[ | ||
ansiPercent() | ansiPercent() | ||
| Zeile 14: | Zeile 11: | ||
getFragment() | getFragment() | ||
getLanguage() | getLanguage() | ||
getNamespace() | getNamespace() | ||
getPlain() | getPlain() | ||
getProject() | getProject() | ||
getTarget() | getTarget() | ||
getTargetPage() | getTargetPage() | ||
getTitle() | getTitle() | ||
getWeblink() | getWeblink() | ||
isBracketedLink() | isBracketedLink() | ||
isBracketedURL() | isBracketedURL() | ||
| Zeile 32: | Zeile 25: | ||
isInterwiki() | isInterwiki() | ||
isMedia() | isMedia() | ||
isTitledLink() | isTitledLink() | ||
isValidLink() | isValidLink() | ||
isWikilink() | isWikilink() | ||
wikilink() | wikilink() | ||
failsafe() | failsafe() | ||
| Zeile 46: | Zeile 35: | ||
-- local globals | -- local globals | ||
local URLutil | local URLutil = false; | ||
| Zeile 132: | Zeile 45: | ||
-- Throws error, if not available | -- Throws error, if not available | ||
if not URLutil then | if not URLutil then | ||
local util = | local lucky, util = pcall( require, "Module:URLutil" ); | ||
if lucky then | |||
if type( util ) == "table" then | |||
URLutil = util.URLutil(); | |||
if type( util ) == "table" then | end | ||
util = "library URLutil invalid"; | util = "library URLutil invalid"; | ||
end | end | ||
| Zeile 147: | Zeile 58: | ||
return URLutil; | return URLutil; | ||
end -- utilURL() | end -- utilURL() | ||
| Zeile 295: | Zeile 188: | ||
r1 = false; | r1 = false; | ||
else | else | ||
r1 = | r1 = r1:gsub( "_", " " ) | ||
:gsub( " ", " " ) | |||
:gsub( " ", " " ) | |||
:gsub( " ", " " ) | |||
:gsub( " ", " " ) | |||
:gsub( " +", " " ); | |||
r1 = mw.text.decode( r1 ); | |||
end | end | ||
end | end | ||
| Zeile 303: | Zeile 202: | ||
local prefix = function ( ask, ahead ) | |||
local prefix = function ( ask ) | |||
-- Interprete prefix of language or project type | -- Interprete prefix of language or project type | ||
-- Precondition: | -- Precondition: | ||
-- ask -- string, with presumable prefix | -- ask -- string, with presumable prefix | ||
-- ahead -- true, if first segment | |||
-- Postcondition: | -- Postcondition: | ||
-- Returns string,string or nil | -- Returns string,string or nil | ||
| Zeile 389: | Zeile 241: | ||
}; | }; | ||
local s = mw.text.trim( ask ); | local s = mw.text.trim( ask ); | ||
if s | if s == "" then | ||
if ahead then | |||
r1 = "lead"; | |||
r2 = true; | |||
end | |||
else | |||
local p; | local p; | ||
s = s:lower(); | s = s:lower(); | ||
| Zeile 468: | Zeile 325: | ||
end | end | ||
else | else | ||
s = string.format( "%%% | s = string.format( "%%%2X", k ); | ||
end | end | ||
r = string.format( "%s%s%s", | r = string.format( "%s%s%s", | ||
| Zeile 476: | Zeile 333: | ||
end | end | ||
end -- for --i | end -- for --i | ||
r = mw.ustring.gsub(r, '^%*', '%%2A') | |||
return r; | return r; | ||
end -- WLink.ansiPercent() | end -- WLink.ansiPercent() | ||
| Zeile 481: | Zeile 339: | ||
function WLink.formatURL( adjust | function WLink.formatURL( adjust ) | ||
-- Create bracketed link, if not yet | -- Create bracketed link, if not yet | ||
-- Precondition: | -- Precondition: | ||
-- adjust -- string, with URL or domain/path or bracketed link | -- adjust -- string, with URL or domain/path or bracketed link | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string, with bracketed link | -- Returns string, with bracketed link | ||
| Zeile 499: | Zeile 356: | ||
host = URLutil.getHost( adjust ); | host = URLutil.getHost( adjust ); | ||
if not host then | if not host then | ||
url = "://" .. adjust | url = "http://" .. adjust; | ||
host = URLutil.getHost( url ); | host = URLutil.getHost( url ); | ||
end | end | ||
| Zeile 583: | Zeile 436: | ||
return r; | return r; | ||
end -- WLink.getBaseTitle() | end -- WLink.getBaseTitle() | ||
function WLink.getEscapedTitle( attempt ) | function WLink.getEscapedTitle( attempt ) | ||
| Zeile 598: | Zeile 449: | ||
:gsub( "|", "|" ); | :gsub( "|", "|" ); | ||
end -- WLink.getEscapedTitle() | end -- WLink.getEscapedTitle() | ||
function WLink.getExtension( attempt ) | function WLink.getExtension( attempt ) | ||
| Zeile 648: | Zeile 497: | ||
r = find( "file" ); | r = find( "file" ); | ||
if not r then | if not r then | ||
local trsl = mw.site.namespaces[ 6 ]; | local trsl = mw.site.namespaces[6]; | ||
r = find( trsl.name ); | r = find( trsl.name ); | ||
if not r then | if not r then | ||
| Zeile 723: | Zeile 572: | ||
return r; | return r; | ||
end -- WLink.getLanguage() | end -- WLink.getLanguage() | ||
| Zeile 807: | Zeile 592: | ||
return r; | return r; | ||
end -- WLink.getNamespace() | end -- WLink.getNamespace() | ||
| Zeile 856: | Zeile 603: | ||
local r = attempt; | local r = attempt; | ||
local i = 1; | local i = 1; | ||
local j, k, n, lean, s, shift | local j, k, n, lean, s, shift, space, suffix; | ||
while ( true ) do | while ( true ) do | ||
j = r:find( "[", i, true ); | j = r:find( "[", i, true ); | ||
| Zeile 871: | Zeile 618: | ||
if k > 1 then | if k > 1 then | ||
n = n - k; | n = n - k; | ||
i = j + k | i = j + k; | ||
j = i - 1; | j = i - 1; | ||
suffix = r:sub( j ); | suffix = r:sub( j ); | ||
| Zeile 895: | Zeile 642: | ||
end | end | ||
else | else | ||
s, shift = extractExtlink( suffix ); | |||
if | if not s then | ||
s = ""; | |||
end | |||
if not shift then | |||
shift = ""; | |||
shift = | |||
end | end | ||
i = i - 1; | i = i - 1; | ||
| Zeile 919: | Zeile 665: | ||
break; -- while true | break; -- while true | ||
end | end | ||
end | end -- while true | ||
return r; | return r; | ||
end -- WLink.getPlain() | end -- WLink.getPlain() | ||
| Zeile 942: | Zeile 688: | ||
return r; | return r; | ||
end -- WLink.getProject() | end -- WLink.getProject() | ||
| Zeile 1.079: | Zeile 800: | ||
end | end | ||
if URLutil.isResourceURL( attempt ) then | if URLutil.isResourceURL( attempt ) then | ||
local site | local site = URLutil.getAuthority( attempt ); | ||
local show; | local show; | ||
if #attempt == #site then | if #attempt == #site then | ||
| Zeile 1.087: | Zeile 807: | ||
show = URLutil.getTop3domain( "//" .. site ); | show = URLutil.getTop3domain( "//" .. site ); | ||
if show then | if show then | ||
local scan = "[%./](%a | local scan = "[%./](%a+)(%.%l%l%.)(%a+)$"; | ||
local search = "." .. show; | local search = "." .. show; | ||
local s1, s2, s3 = search:match( scan ); | local s1, s2, s3 = search:match( scan ); | ||
if s2 then | if s2 then | ||
if not second:find( s2, 1, true ) then | if not second:find( s2, 1, true ) then | ||
show = string.format( "%s%s", | show = string.format( "%s.%s", s2, s3 ); | ||
end | end | ||
else | else | ||
| Zeile 1.104: | Zeile 824: | ||
end | end | ||
end | end | ||
r = string.format( "[%s %s]", attempt, show ); | |||
r = string.format( "[%s %s]", | |||
else | else | ||
r = attempt; | r = attempt; | ||
| Zeile 1.113: | Zeile 830: | ||
return r; | return r; | ||
end -- WLink.getWeblink() | end -- WLink.getWeblink() | ||
| Zeile 1.269: | Zeile 963: | ||
return r; | return r; | ||
end -- WLink.isMedia() | end -- WLink.isMedia() | ||
| Zeile 1.330: | Zeile 1.002: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns boolean | -- Returns boolean | ||
local | local s, r = WLink.getTarget( attempt ); | ||
if r then | if r then | ||
r = true; | |||
end | end | ||
return r; | return r; | ||
end -- WLink.isValidLink() | end -- WLink.isValidLink() | ||
| Zeile 1.374: | Zeile 1.020: | ||
return ( m == 2 ); | return ( m == 2 ); | ||
end -- WLink.isWikilink() | end -- WLink.isWikilink() | ||
| Zeile 1.503: | Zeile 1.031: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns table or false | -- Returns table or false | ||
-- table of assignments with { type, value } | -- table of assignments with { type, value} | ||
-- type is one of "lead", | -- type is one of "lead", | ||
-- "project", "lang", | -- "project", "lang", | ||
-- "ns", "space", "title" | -- "ns", "space", "title" | ||
-- false if nothing found | -- false if nothing found | ||
local s = contentWikilink( attempt | local s = contentWikilink( attempt ); | ||
local got | local got, n, r; | ||
if not s then | if not s then | ||
s = attempt; | s = attempt; | ||
end | end | ||
i = s:find( "|", 1, true ); | i = s:find( "|", 1, true ); | ||
| Zeile 1.527: | Zeile 1.052: | ||
local j, k, o, v; | local j, k, o, v; | ||
r = { title = "" }; | r = { title = "" }; | ||
if n > 4 then | if n > 4 then | ||
k = 4; | k = 4; | ||
else | |||
k = n - 1; | k = n - 1; | ||
end | end | ||
j = k; | j = k; | ||
| Zeile 1.543: | Zeile 1.061: | ||
s = mw.text.trim( got[ i ] ); | s = mw.text.trim( got[ i ] ); | ||
if s ~= "" then | if s ~= "" then | ||
o = mw.site.namespaces[ | o = mw.site.namespaces[ mw.text.trim( got[ i ] ) ]; | ||
if o then | if o then | ||
r.ns = o.id; | r.ns = o.id; | ||
| Zeile 1.554: | Zeile 1.072: | ||
end -- for i | end -- for i | ||
for i = 1, j do | for i = 1, j do | ||
o, v = prefix( got[ i ] ); | o, v = prefix( got[ i ], ( i == 1 ) ); | ||
if o then | if o then | ||
if r[ o ] then | if r[ o ] then | ||
| Zeile 1.560: | Zeile 1.078: | ||
break; -- for i | break; -- for i | ||
else | else | ||
r[ o ] = v; | r[ o ] = v; | ||
end | end | ||
else | else | ||
k = i; | k = i; | ||
break; -- for i | break; -- for i | ||
end | end | ||
end -- for i | end -- for i | ||
for i = k, n do | |||
r.title = r.title .. got[ i ]; | |||
if i < n then | |||
r.title = r.title .. ":"; | |||
end | |||
end -- for i | |||
end | end | ||
if r.lead and | if r.lead and | ||
( r.project or | ( r.project or not r.title or | ||
( not r.lang and r.ns ~= 6 and r.ns ~= 14 ) ) then | ( not r.lang and r.ns ~= 6 and r.ns ~= 14 ) ) then | ||
r.lead = false; | r.lead = false; | ||
| Zeile 1.594: | Zeile 1.102: | ||
function WLink.failsafe( assert ) | |||
-- Retrieve versioning and check for compliance | -- Retrieve versioning and check for compliance | ||
-- Precondition: | -- Precondition: | ||
-- | -- assert -- string, with required version, or false | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string | -- Returns string with appropriate version, or false | ||
local r; | local r; | ||
if | if assert and assert > WLink.serial then | ||
r = false; | |||
else | |||
r = WLink.serial; | |||
end | end | ||
return r | |||
end -- WLink.failsafe() | |||
return r | |||
end -- | |||
| Zeile 1.649: | Zeile 1.131: | ||
local s = false; | local s = false; | ||
local r = false; | local r = false; | ||
local | local space; | ||
for k, v in pairs( frame.args ) do | for k, v in pairs( frame.args ) do | ||
if k == 1 then | if k == 1 then | ||
| Zeile 1.657: | Zeile 1.139: | ||
s = mw.text.trim( v ); | s = mw.text.trim( v ); | ||
end | end | ||
elseif | elseif action == "ansiPercent" and k == "space" then | ||
if v ~= "" then | if v ~= "" then | ||
space = v; | space = v; | ||
end | end | ||
elseif k ~= "template" then | elseif k ~= "template" then | ||
lucky = false; | lucky = false; | ||
| Zeile 1.685: | Zeile 1.155: | ||
if lucky then | if lucky then | ||
if s or lone then | if s or lone then | ||
lucky, r = pcall( WLink[ action ], s, space | lucky, r = pcall( WLink[ action ], s, space ); | ||
else | else | ||
r = "Parameter missing"; | r = "Parameter missing"; | ||
| Zeile 1.700: | Zeile 1.170: | ||
end | end | ||
else | else | ||
r = string.format( "<span class=\"error\">%s</span>", r ); | |||
end | end | ||
return r; | return r; | ||
| Zeile 1.741: | Zeile 1.209: | ||
p.getLanguage = function ( frame ) | p.getLanguage = function ( frame ) | ||
return Template( frame, "getLanguage" ); | return Template( frame, "getLanguage" ); | ||
end | end | ||
p.getNamespace = function ( frame ) | p.getNamespace = function ( frame ) | ||
return tostring( Template( frame, "getNamespace" ) ); | return tostring( Template( frame, "getNamespace" ) ); | ||
end | end | ||
p.getPlain = function ( frame ) | p.getPlain = function ( frame ) | ||
| Zeile 1.756: | Zeile 1.218: | ||
p.getProject = function ( frame ) | p.getProject = function ( frame ) | ||
return Template( frame, "getProject" ); | return Template( frame, "getProject" ); | ||
end | end | ||
p.getTarget = function ( frame ) | p.getTarget = function ( frame ) | ||
| Zeile 1.771: | Zeile 1.230: | ||
p.getWeblink = function ( frame ) | p.getWeblink = function ( frame ) | ||
return Template( frame, "getWeblink" ); | return Template( frame, "getWeblink" ); | ||
end | end | ||
p.isBracketedLink = function ( frame ) | p.isBracketedLink = function ( frame ) | ||
| Zeile 1.795: | Zeile 1.251: | ||
p.isMedia = function ( frame ) | p.isMedia = function ( frame ) | ||
return Template( frame, "isMedia" ); | return Template( frame, "isMedia" ); | ||
end | end | ||
p.isTitledLink = function ( frame ) | p.isTitledLink = function ( frame ) | ||
| Zeile 1.804: | Zeile 1.257: | ||
p.isValidLink = function ( frame ) | p.isValidLink = function ( frame ) | ||
return Template( frame, "isValidLink" ); | return Template( frame, "isValidLink" ); | ||
end | end | ||
p.isWeblink = function ( frame ) | p.isWeblink = function ( frame ) | ||
| Zeile 1.813: | Zeile 1.263: | ||
p.isWikilink = function ( frame ) | p.isWikilink = function ( frame ) | ||
return Template( frame, "isWikilink" ); | return Template( frame, "isWikilink" ); | ||
end | end | ||
p.failsafe = function ( frame ) | p.failsafe = function ( frame ) | ||
local since = frame.args[ 1 ]; | |||
local | |||
if since then | if since then | ||
since = mw.text.trim( since ); | since = mw.text.trim( since ); | ||
| Zeile 1.831: | Zeile 1.272: | ||
end | end | ||
end | end | ||
return | return WLink.failsafe( since ) or ""; | ||
end | end | ||
p.WLink = function () | p.WLink = function () | ||
return WLink; | return WLink; | ||