Modül:WLink
local WLink = { suite = "WLink", serial = "2016-10-05" };
--[=[
ansiPercent()
formatURL()
getArticleBase()
getBaseTitle()
getExtension()
getFile()
getFragment()
getLanguage()
getNamespace()
getPlain()
getProject()
getTarget()
getTargetPage()
getTitle()
getWeblink()
isBracketedLink()
isBracketedURL()
isCategorization()
isExternalLink()
isInterlanguage()
isInterwiki()
isMedia()
isTitledLink()
isValidLink()
isWikilink()
wikilink()
failsafe()
]=]
-- local globals
local URLutil = false;
local utilURL = function () -- Attach URLutil library module -- Postcondition: -- Returns table, with URLutil library -- Throws error, if not available if not URLutil then local lucky, util = pcall( require, "Module:URLutil" ); if lucky then if type( util ) == "table" then URLutil = util. URLutil(); end util = "library URLutil invalid"; end if type( URLutil ) ~= "table" then error( util, 0 ); end end return URLutil;
end -- utilURL()
local contentExtlink = function ( attempt ) -- Retrieve span of external link between brackets -- Precondition: -- attempt -- string, with presumable link -- the first char is expected to be "[" -- Postcondition: -- Returns string, number, number -- string including whitespace -- number with index of relevant "[" -- number with index after relevant "]" -- false if nothing found local r1 = false; local r2 = false; local r3 = attempt:find( "]", 2, true ); if r3 then local s = attempt:sub( 2, r3 - 1 ); local i = s:find( "[", 1, true ); if i then r1 = s:sub( i + 1 ); r2 = i; else r1 = s; r2 = 1; end else r3 = false; end return r1, r2, r3;
end -- contentExtlink()
local contentWikilink = function ( attempt ) -- Retrieve span of wikilink between brackets -- Precondition: -- attempt -- string, with presumable link -- the first two chars are expected to be "" -- Postcondition: -- Returns string, number, number -- string including whitespace -- number with index of relevant "" -- number with index after relevant "" -- false if nothing found local r1 = false; local r2 = false; local r3 = attempt:find( "", 3, true ); if r3 then local s = attempt:sub( 3, r3 - 1 ); local i = s:find( "[[", 1, true ); if i then r1 = s:sub( i + 2 ); r2 = i; else r1 = s; r2 = 1; end end return r1, r2, r3;
end -- contentWikilink()
local extractExtlink = function ( attempt ) -- Retrieve external link -- Precondition: -- attempt -- string, with presumable link -- the first char is expected to be "[" -- Postcondition: -- Returns string, string -- first with target and title -- second result false if not titled -- false if nothing found local r1 = false; local r2 = false; local s = contentExtlink( attempt ); if s then local i = s:find( "%s", 1 ); if i then r1 = s:sub( 1, i - 1 ); r2 = mw. text.