Bearbeiten von „Modul:WLink“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
local WLink = { suite = "WLink", | local WLink = { suite = "WLink", | ||
serial = " | serial = "2017-10-14" }; | ||
--[=[ | --[=[ | ||
ansiPercent() | ansiPercent() | ||
Zeile 13: | Zeile 12: | ||
getLanguage() | getLanguage() | ||
getNamespace() | getNamespace() | ||
getPlain() | getPlain() | ||
getProject() | getProject() | ||
getTarget() | getTarget() | ||
getTargetPage() | getTargetPage() | ||
getTitle() | getTitle() | ||
getWeblink() | getWeblink() | ||
isBracketedLink() | isBracketedLink() | ||
isBracketedURL() | isBracketedURL() | ||
Zeile 29: | Zeile 25: | ||
isInterwiki() | isInterwiki() | ||
isMedia() | isMedia() | ||
isTitledLink() | isTitledLink() | ||
isValidLink() | isValidLink() | ||
isWikilink() | isWikilink() | ||
wikilink() | wikilink() | ||
failsafe() | failsafe() | ||
Zeile 44: | Zeile 36: | ||
-- local globals | -- local globals | ||
local URLutil = false; | local URLutil = false; | ||
Zeile 84: | Zeile 58: | ||
return URLutil; | return URLutil; | ||
end -- utilURL() | end -- utilURL() | ||
Zeile 232: | 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 240: | 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 326: | 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 405: | 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 422: | Zeile 342: | ||
-- 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 436: | Zeile 355: | ||
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 529: | Zeile 444: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string, with suitable link title | -- Returns string, with suitable link title | ||
return attempt:gsub( "\n", " " ) | |||
:gsub( "%[", "[" ) | |||
:gsub( "%]", "]" ) | |||
:gsub( "|", "|" ); | |||
end -- WLink.getEscapedTitle() | end -- WLink.getEscapedTitle() | ||
Zeile 585: | Zeile 499: | ||
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 680: | Zeile 594: | ||
return r; | return r; | ||
end -- WLink.getNamespace() | end -- WLink.getNamespace() | ||
Zeile 744: | Zeile 620: | ||
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 792: | Zeile 668: | ||
break; -- while true | break; -- while true | ||
end | end | ||
end | end -- while true | ||
return r; | return r; | ||
end -- WLink.getPlain() | end -- WLink.getPlain() | ||
Zeile 815: | Zeile 691: | ||
return r; | return r; | ||
end -- WLink.getProject() | end -- WLink.getProject() | ||
Zeile 986: | Zeile 837: | ||
return r; | return r; | ||
end -- WLink.getWeblink() | end -- WLink.getWeblink() | ||
Zeile 1.142: | Zeile 970: | ||
return r; | return r; | ||
end -- WLink.isMedia() | end -- WLink.isMedia() | ||
Zeile 1.203: | Zeile 1.009: | ||
-- 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.289: | Zeile 1.027: | ||
return ( m == 2 ); | return ( m == 2 ); | ||
end -- WLink.isWikilink() | end -- WLink.isWikilink() | ||
Zeile 1.418: | Zeile 1.038: | ||
-- 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, n, r; | 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.442: | Zeile 1.059: | ||
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.458: | Zeile 1.068: | ||
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.469: | Zeile 1.079: | ||
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.475: | Zeile 1.085: | ||
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.512: | Zeile 1.112: | ||
-- Retrieve versioning and check for compliance | -- Retrieve versioning and check for compliance | ||
-- Precondition: | -- Precondition: | ||
-- assert -- string, with required version | -- assert -- string, with required version, or false | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string with appropriate version, or false | -- 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 | return r | ||
end -- WLink.failsafe() | end -- WLink.failsafe() | ||
Zeile 1.558: | Zeile 1.138: | ||
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.566: | Zeile 1.146: | ||
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.594: | Zeile 1.162: | ||
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.609: | Zeile 1.177: | ||
end | end | ||
else | else | ||
r = string.format( "<span class=\"error\">%s</span>", r ); | |||
end | end | ||
return r; | return r; | ||
Zeile 1.653: | Zeile 1.219: | ||
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.662: | Zeile 1.225: | ||
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.677: | Zeile 1.237: | ||
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.701: | Zeile 1.258: | ||
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.710: | Zeile 1.264: | ||
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.719: | Zeile 1.270: | ||
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 ) |