Module:Delink: Difference between revisions
en>Mr. Stradivarius (move cat/interwiki/file check earlier to the start of the processing chain) |
en>Mr. Stradivarius (move the colon trick processing to earlier in the chain) |
||
Line 14: | Line 14: | ||
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]]. | -- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]]. | ||
-- First, | -- First, remove the text before the first colon, if any. | ||
if mw.ustring.match(s, ":") then | if mw.ustring.match(s, ":") then | ||
s = mw.ustring.match(s, "%[%[.-:(.*)|%]%]") | |||
-- If there are no colons, grab all of the text apart from the square brackets and the pipe. | -- If there are no colons, grab all of the text apart from the square brackets and the pipe. | ||
else | else | ||
Line 40: | Line 31: | ||
end | end | ||
local function delinkOne( | local function delinkOne(s) | ||
-- First, check for categories, interwikis, and files. | -- First, check for categories, interwikis, and files. | ||
local colonprefix = mw.ustring.match( | local colonprefix = mw.ustring.match(s, "%[%[(.-):.*%]%]") or "" -- Get the text before the first colon. | ||
if mw.language.isKnownLanguageTag(colonprefix) | if mw.language.isKnownLanguageTag(colonprefix) | ||
or mw.ustring.match(colonprefix, "^[Cc]ategory$") | or mw.ustring.match(colonprefix, "^[Cc]ategory$") | ||
Line 49: | Line 40: | ||
return "" | return "" | ||
end | end | ||
if mw.ustring.match( | |||
return delinkPipeTrick( | -- Remove the colon if the link is using the [[Help:Colon trick]]. | ||
if mw.ustring.match(s, "%[%[:") then | |||
s = "[[" .. mw.ustring.match(s, "%[%[:(.*%]%])") | |||
end | |||
if mw.ustring.match(s, "[^|].*|%]%]") or mw.ustring.match(s, "%[%[|") then -- Weed out the pipe tricks first. | |||
return delinkPipeTrick(s) | |||
end | end | ||
-- Find the link area and display area of the wikilink | -- Find the link area and display area of the wikilink | ||
local linkarea, display | local linkarea, display | ||
if mw.ustring.match( | if mw.ustring.match(s, "|") then -- Find if we're dealing with a piped link. | ||
linkarea, display = mw.ustring.match( | linkarea, display = mw.ustring.match(s, "^%[%[(.-)|(.+)%]%]") | ||
else | else | ||
-- If the link isn't piped, the display area and the link area are the same. | -- If the link isn't piped, the display area and the link area are the same. | ||
linkarea = mw.ustring.match( | linkarea = mw.ustring.match(s, "^%[%[(.-)%]%]") | ||
display = linkarea | display = linkarea | ||
end | end |