Anonymous user
Module:Delink: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
deal with most bad links
(move the colon trick processing to earlier in the chain) |
(deal with most bad links) |
||
Line 2:
p = {}
local function delinkReversePipeTrick(s)
local function delinkPipeTrick(s)
local linkarea, display = "", ""
-- Deal with the left-hand pipe trick, an easy case.▼
if mw.ustring.match(s, "%[%[|") then▼
▲ return mw.ustring.match(s, "%[%[|(.*)%]%]")
▲ end
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
Line 32 ⟶ 29:
local function delinkOne(s)
--
▲ if mw.ustring.match(s, "%[%[|") then
return delinkReversePipeTrick(s)
end▼
-- 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(s, "|") then -- Find if we're dealing with a piped link.
else
titlearea = mw.ustring.match(s, "^%[%[(.-)%]%]")
end
-- Clear the title of the fragment (the section link).
if not mw.title.makeTitle("", titlearea) then
return s -- If it's not a valid link, return the whole string.
end
-- Check for categories, interwikis, and files.
local colonprefix = mw.ustring.match(s, "%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
if mw.language.isKnownLanguageTag(colonprefix)
Line 46 ⟶ 61:
end
if mw.ustring.match(s, "[^|].*|%]%]") or mw.ustring.match(s, "%[%[|") then
return delinkPipeTrick(s)
end
if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link.
else
display = mw.ustring.match(s, "^%[%[(.-)%]%]")
▲ linkarea = mw.ustring.match(s, "^%[%[(.-)%]%]")
▲ display = linkarea
▲ end
end
return display
end
|