Modul:WLink: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
update
wp>PerfektesChaos (fix?) |
wp>PerfektesChaos (update) |
||
Zeile 1: | Zeile 1: | ||
--[=[ 2014- | --[=[ 2014-05-01 | ||
WLink | WLink | ||
]=] | ]=] | ||
Zeile 57: | Zeile 57: | ||
r2 = 1; | r2 = 1; | ||
end | end | ||
else | |||
r3 = false; | |||
end | end | ||
return r1, r2; | return r1, r2, r3; | ||
end -- contentExtlink() | end -- contentExtlink() | ||
Zeile 170: | Zeile 172: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string, encoded | -- Returns string, encoded | ||
local k; | |||
local r = attempt; | local r = attempt; | ||
for i = #attempt, 1, -1 do | |||
k = attempt:byte( i, i ); | |||
if k <= 32 or k > 126 then | |||
r = string.format( "%s%%%2X%s", | |||
attempt:sub( 1, i - 1 ), | |||
k, | |||
r:sub( 1, i + 1 ) ); | |||
end | |||
end -- for --i | |||
return r; | return r; | ||
end -- WLink.ansiPercent() | end -- WLink.ansiPercent() | ||
Zeile 198: | Zeile 209: | ||
-- false if no extension found | -- false if no extension found | ||
local r = false; | local r = false; | ||
local s, m = WLink.getTargetPage( attempt ); | |||
if not s then | |||
s = attempt; | |||
m = 2; | |||
end | |||
if m == 2 then | |||
s = s:match( "%.(%a+)$" ); | |||
if s then | |||
r = s:lower(); | |||
end | |||
elseif s:upper():match( "[%./](PDF)%A?" ) then | |||
r = "pdf"; | |||
end | |||
return r; | return r; | ||
end -- WLink.getExtension() | end -- WLink.getExtension() | ||
Zeile 342: | Zeile 366: | ||
-- attempt -- string, with presumable link somewhere | -- attempt -- string, with presumable link somewhere | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string, with first detected link target | -- Returns string, number | ||
-- string, with first detected link target | |||
-- number, with number of brackets, if found | |||
-- false if nothing found | -- false if nothing found | ||
local | local r1 = false; | ||
local i = attempt:find( "[", 1, true ); | local r2 = false; | ||
local i = attempt:find( "[", 1, true ); | |||
if i then | if i then | ||
local m; | |||
if | r1 = attempt:sub( i ); | ||
if r1:byte( 2, 2 ) == 91 then | |||
m = 2; | |||
r1 = extractWikilink( r1 ); | |||
else | else | ||
m = 1; | |||
r1 = extractExtlink( r1 ); | |||
end | |||
if r1 then | |||
r2 = m; | |||
end | end | ||
else | else | ||
r1 = attempt:match( "%A?([hf]t?tps?://%S+)%s?" ); | |||
if | if r1 then | ||
if | if utilURL().isResourceURL( r1 ) then | ||
r2 = 0; | |||
else | |||
r1 = false; | |||
end | end | ||
else | else | ||
r1 = false; | |||
end | end | ||
end | end | ||
return | return r1, r2; | ||
end -- WLink.getTarget() | end -- WLink.getTarget() | ||
Zeile 375: | Zeile 410: | ||
-- Returns string, with first detected linked page | -- Returns string, with first detected linked page | ||
-- false if nothing found | -- false if nothing found | ||
local | local r1, r2 = WLink.getTarget( attempt ); | ||
if | if r1 then | ||
local i = | local i = r1:find( "#", 1, true ); | ||
if i then | if i then | ||
if i == 1 then | if i == 1 then | ||
r1 = false; | |||
else | else | ||
r1 = mw.text.trim( r1:sub( 1, i - 1 ) ); | |||
end | end | ||
end | end | ||
end | end | ||
return | return r1, r2; | ||
end -- WLink.getTargetPage() | end -- WLink.getTargetPage() | ||
Zeile 426: | Zeile 461: | ||
-- Returns boolean | -- Returns boolean | ||
local r = false; | local r = false; | ||
local i = attempt:find( "[", 1, true ); | |||
if i then | |||
local s = attempt:sub( i ); | |||
if s:byte( 2, 2 ) == 91 then | |||
s = extractWikilink( s ); | |||
else | |||
s = extractExtlink( s ); | |||
end | |||
if s then | |||
r = true; | |||
end | |||
end | |||
return r; | return r; | ||
end -- WLink.isBracketedLink() | end -- WLink.isBracketedLink() | ||
Zeile 449: | Zeile 496: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns boolean | -- Returns boolean | ||
local r = | local s, r = WLink.getTarget( attempt ); | ||
if r then | |||
r = ( r < 2 ); | |||
end | |||
return r; | return r; | ||
end -- WLink.isExternalLink() | end -- WLink.isExternalLink() | ||
Zeile 486: | Zeile 536: | ||
-- Returns boolean | -- Returns boolean | ||
local r = false; | local r = false; | ||
local i = attempt:find( "[", 1, true ); | |||
if i then | |||
local c; | |||
local s = attempt:sub( i ); | |||
if s:byte( 2, 2 ) == 91 then | |||
s = extractWikilink( s ); | |||
c = "|"; | |||
else | |||
s = extractExtlink( s ); | |||
c = "%s"; | |||
end | |||
if s then | |||
if s:find( c, 2 ) then | |||
r = true; | |||
end | |||
end | |||
end | |||
return r; | return r; | ||
end -- WLink.isTitledLink() | end -- WLink.isTitledLink() | ||
Zeile 497: | Zeile 564: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns boolean | -- Returns boolean | ||
local r = | local s, r = WLink.getTarget( attempt ); | ||
if r then | |||
r = true; | |||
end | |||
return r; | return r; | ||
end -- WLink. | end -- WLink.isValidLink() | ||
Zeile 521: | Zeile 579: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns boolean | -- Returns boolean | ||
local | local s, m = WLink.getTarget( attempt ); | ||
return | return ( m == 2 ); | ||
end -- WLink.isWikilink() | end -- WLink.isWikilink() | ||