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 = "2018-01-27", | ||
item = 19363224 }; | item = 19363224 }; | ||
--[=[ | --[=[ | ||
Zeile 17: | Zeile 17: | ||
getProject() | getProject() | ||
getTarget() | getTarget() | ||
getTargetPage() | getTargetPage() | ||
getTitle() | getTitle() | ||
getWeblink() | getWeblink() | ||
isBracketedLink() | isBracketedLink() | ||
isBracketedURL() | isBracketedURL() | ||
Zeile 29: | Zeile 27: | ||
isInterwiki() | isInterwiki() | ||
isMedia() | isMedia() | ||
isTitledLink() | isTitledLink() | ||
isValidLink() | isValidLink() | ||
isWikilink() | isWikilink() | ||
wikilink() | wikilink() | ||
failsafe() | failsafe() | ||
Zeile 44: | Zeile 38: | ||
-- local globals | -- local globals | ||
local URLutil = false; | local URLutil = false; | ||
Zeile 84: | Zeile 60: | ||
return URLutil; | return URLutil; | ||
end -- utilURL() | end -- utilURL() | ||
Zeile 232: | Zeile 190: | ||
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 204: | ||
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 243: | ||
}; | }; | ||
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 327: | ||
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 344: | ||
-- 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 357: | ||
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 446: | ||
-- 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 501: | ||
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 744: | Zeile 660: | ||
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 708: | ||
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 731: | ||
return r; | return r; | ||
end -- WLink.getProject() | end -- WLink.getProject() | ||
Zeile 986: | Zeile 877: | ||
return r; | return r; | ||
end -- WLink.getWeblink() | end -- WLink.getWeblink() | ||
Zeile 1.142: | Zeile 1.010: | ||
return r; | return r; | ||
end -- WLink.isMedia() | end -- WLink.isMedia() | ||
Zeile 1.203: | Zeile 1.049: | ||
-- 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.067: | ||
return ( m == 2 ); | return ( m == 2 ); | ||
end -- WLink.isWikilink() | end -- WLink.isWikilink() | ||
Zeile 1.418: | Zeile 1.078: | ||
-- 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.099: | ||
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.108: | ||
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.119: | ||
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.125: | ||
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.527: | Zeile 1.167: | ||
local vsn = ent:formatPropertyValues( "P348" ); | local vsn = ent:formatPropertyValues( "P348" ); | ||
if type( vsn ) == "table" and | if type( vsn ) == "table" and | ||
type( vsn.value ) == "string" | type( vsn.value) == "string" and | ||
vsn.value ~= "" then | vsn.value ~= "" then | ||
r = vsn.value; | r = vsn.value; | ||
Zeile 1.558: | Zeile 1.198: | ||
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.206: | ||
s = mw.text.trim( v ); | s = mw.text.trim( v ); | ||
end | end | ||
elseif ( k == 2 | elseif ( k == 2 and action == "getNamespaced" ) or | ||
( k == "space" and action == "ansiPercent" ) then | ( k == "space" and action == "ansiPercent" ) 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.223: | ||
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.238: | ||
end | end | ||
else | else | ||
r = string.format( "<span class=\"error\">%s</span>", r ); | |||
end | end | ||
return r; | return r; | ||
Zeile 1.662: | Zeile 1.289: | ||
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.301: | ||
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.322: | ||
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.328: | ||
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.334: | ||
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 ) |