Module:Delink: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
better decoding support
(group the bad characters together)
(better decoding support)
Line 33:
 
local function delinkWikilink(s)
local displayresult = s
-- Deal with the reverse pipe trick.
if mw.ustring.match(sresult, "%[%[|") then
return delinkReversePipeTrick(sresult)
end
sresult = mw.uri.decode(sresult, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
sresult = mw.text.decode(sresult, true) -- decode HTML entities.
-- Check for bad titles. To do this we need to find the
-- title area of the link, i.e. the part before any pipes.
local titlearea
if mw.ustring.match(sresult, "|") then -- Find if we're dealing with a piped link.
titlearea = mw.ustring.match(sresult, "^%[%[(.-)|.*%]%]")
else
titlearea = mw.ustring.match(sresult, "^%[%[(.-)%]%]")
end
-- Check for bad characters.
Line 55 ⟶ 56:
-- Check for categories, interwikis, and files.
local colonprefix = mw.ustring.match(sresult, "%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
if mw.language.isKnownLanguageTag(colonprefix)
or mw.ustring.match(colonprefix, "^[Cc]ategory$")
Line 64 ⟶ 65:
-- Remove the colon if the link is using the [[Help:Colon trick]].
if mw.ustring.match(sresult, "%[%[:") then
sresult = "[[" .. mw.ustring.match(sresult, "%[%[:(.*%]%])")
end
-- Deal with links using the [[Help:Pipe trick]].
if mw.ustring.match(sresult, "^%[%[[^|]*|%]%]") then
return delinkPipeTrick(sresult)
end
-- Find the display area of the wikilink
if mw.ustring.match(result, "|") then -- Find if we're dealing with a piped link.
local display
if result = mw.ustring.match(sresult, "^%[%[.-|(.+)%]%]") then -- Find if we're dealing with a piped link.
display = mw.ustring.match(s, "^%[%[.-|(.+)%]%]")
-- Remove new lines from the display of multiline piped links,
-- where the pipe is before the first new line.
displayresult = mw.ustring.gsub(displayresult, "\n", "")
else
displayresult = mw.ustring.match(sresult, "^%[%[(.-)%]%]")
end
 
return displayresult
end
 
Line 109:
if not url_prefix then
return s
elseend
s = mw.ustring.match(s, "^%[" .. url_prefix .. "(.*)%]") -- Grab all of the text after the URL prefix and before the final square bracket.
s = mw.ustring.match(s, '^.-(["<> ].*)') or "" -- Grab all of the text after the first URL separator character ("<> ).
s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
ss_decoded = mw.text.decode(s, true)
if mw.ustring.match(s_decoded, "%c") then
return s
else
return s_decoded
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu