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)
return mw.ustring.match(s, "%[%[|(.*)%]%]")
end
 
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
-- If the link isn't a left-hand pipe trick, assume it's a right-hand pipe trick.
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
Line 32 ⟶ 29:
 
local function delinkOne(s)
-- First,Deal checkwith forthe categories,reverse interwikispipe trick, andan easy filescase.
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.
linkarea titlearea= mw.ustring.match(s, "^%[%[(.-)|.*%]%]")
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
-- Deal with links using the left-hand pipe[[Help:Pipe trick, an easy case]].
if mw.ustring.match(s, "[^|].*|%]%]") or mw.ustring.match(s, "%[%[|") then -- Weed out the pipe tricks first.
return delinkPipeTrick(s)
end
-- Find the link area and display area of the wikilink
local-- linkarea,Find the display area of the wikilink
local display = linkarea
if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link.
linkarea, display = mw.ustring.match(s, "^%[%[(.-)|(.+)%]%]")
else
display = mw.ustring.match(s, "^%[%[(.-)%]%]")
-- If the link isn't piped, the display area and the link area are the same.
linkarea = mw.ustring.match(s, "^%[%[(.-)%]%]")
display = linkarea
end
-- Check for bad links
if mw.ustring.match(linkarea, "%[") or mw.ustring.match(linkarea, "%]") then
error("Bad link detected. Bad links are not yet supported.")
end
 
return display
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu