Modul:WLink: Unterschied zwischen den Versionen
2019-03-25, siehe https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=187023083&oldid=187022999
w>Mabschaaf (2019-01-01; gem. Anfrage Spezial:Diff/186813773/186814496) |
w>NordNordWest (2019-03-25, siehe https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=187023083&oldid=187022999) |
||
| Zeile 1: | Zeile 1: | ||
local WLink = { suite = "WLink", | local WLink = { suite = "WLink", | ||
serial = "2019- | serial = "2019-03-25", | ||
item = 19363224 }; | item = 19363224 }; | ||
--[=[ | --[=[ | ||
| Zeile 32: | Zeile 32: | ||
isTitledLink() | isTitledLink() | ||
isValidLink() | isValidLink() | ||
isValidLinktext() | |||
isWikilink() | isWikilink() | ||
pageLink() | pageLink() | ||
| Zeile 43: | Zeile 44: | ||
-- local globals | -- local globals | ||
local URLutil = false; | local URLutil = false; | ||
local htmlInline = { b = true, | |||
big = true, | |||
code = true, | |||
em = true, | |||
i = true, | |||
kbd = true, | |||
s = true, | |||
samp = true, | |||
small = true, | |||
span = true, | |||
strong = true, | |||
sub = true, | |||
sup = true, | |||
tt = true, | |||
var = true }; | |||
| Zeile 1.190: | Zeile 1.209: | ||
return r; | return r; | ||
end -- WLink.isValidLink() | end -- WLink.isValidLink() | ||
function WLink.isValidLinktext( attempt ) | |||
-- Is attempt a plain inline text? | |||
-- Precondition: | |||
-- attempt -- string, with presumable linktext | |||
-- Postcondition: | |||
-- Returns boolean | |||
local r = true; | |||
local i = attempt:find( "]", 1, true ); | |||
if i then | |||
r = false; | |||
else | |||
r = ( mw.text.unstrip( attempt ) == attempt ); | |||
end | |||
if r then | |||
i = attempt:find( "<", 1, true ); | |||
if i then | |||
local s = mw.ustring.lower( attempt:sub( i ) ); | |||
local sign, skip; | |||
while i and r do | |||
skip, sign = s:match( "^([^<]*< *)(%l[%l%d]*)[ /]*.*>" ); | |||
if sign then | |||
r = htmlInline[ sign ]; | |||
if r then | |||
i = skip:len() + sign:len() + 1; | |||
s = s:sub( i ); | |||
end | |||
else | |||
i = false; | |||
end | |||
end -- while i and r | |||
end | |||
end | |||
if r then | |||
local s = attempt .. " "; | |||
i = s:find( "ISBN ", 1, true ); | |||
if i then | |||
r = not s:match( "ISBN %d[%-%d]+[%dxX]%W" ); | |||
end | |||
if r then | |||
i = s:find( "PMID ", 1, true ); | |||
if i then | |||
r = not s:match( "PMID %d+%W" ); | |||
end | |||
if r then | |||
i = s:find( "RFC ", 1, true ); | |||
if i then | |||
r = not s:match( "RFC [1-6]%d?%d?%d?%W" ); | |||
end | |||
end | |||
end | |||
end | |||
return r or false; | |||
end -- WLink.isValidLinktext() | |||
| Zeile 1.256: | Zeile 1.331: | ||
local slang = p.lang; | local slang = p.lang; | ||
local lead; | local lead; | ||
if p.title:sub( 1, 1 ) == "#" then | |||
p.title = mw.title.getCurrentTitle().text + p.title; | |||
end | |||
if p.ns then | if p.ns then | ||
if not slang then | if not slang then | ||
| Zeile 1.273: | Zeile 1.351: | ||
end | end | ||
if s == "WIKI" then | if s == "WIKI" then | ||
if not site | if not site and | ||
( lead or | ( lead or | ||
( not p.space and | ( not p.space and | ||
| Zeile 1.618: | Zeile 1.696: | ||
p.isValidLink = function ( frame ) | p.isValidLink = function ( frame ) | ||
return Template( frame, "isValidLink" ); | return Template( frame, "isValidLink" ); | ||
end | |||
p.isValidLinktext = function ( frame ) | |||
return Template( frame, "isValidLinktext" ); | |||
end | end | ||
p.isWeblink = function ( frame ) | p.isWeblink = function ( frame ) | ||