Module:Delink: Difference between revisions

en>Mr. Stradivarius
(deal with categories/interwikis and the colon trick)
en>Mr. Stradivarius
(move cat/interwiki/file check earlier to the start of the processing chain)
Line 16: Line 16:
     -- First, we check whether or not there are colons in the link, and trim it accordingly.
     -- First, we check whether or not there are colons in the link, and trim it accordingly.
     if mw.ustring.match(s, ":") then
     if mw.ustring.match(s, ":") then
        -- If the link contains a colon, it could be a category or an interwiki,
        -- or it could use the [[Help:Colon trick]].
       
        -- Check for categories and interwikis.
        local colonprefix = mw.ustring.match(s, "%[%[(.-):.*|%]%]") or "" -- Get the text before the first colon.
        if mw.language.isKnownLanguageTag(colonprefix) or mw.ustring.match(colonprefix, "^[Cc]ategory$") then
            s = ""
              
              
         -- Check for the colon trick.
         -- Check for the [[Help:Colon trick]].
         elseif mw.ustring.match(s, "%[%[:") then
         if mw.ustring.match(s, "%[%[:") then
             s = mw.ustring.match(s, "%[%[:.-:(.*)|%]%]")
             s = mw.ustring.match(s, "%[%[:.-:(.*)|%]%]")
          
          
Line 48: Line 41:


local function delinkOne(text)
local function delinkOne(text)
    -- First, check for categories, interwikis, and files.
    local colonprefix = mw.ustring.match(text, "%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
    if mw.language.isKnownLanguageTag(colonprefix)
    or mw.ustring.match(colonprefix, "^[Cc]ategory$")
    or mw.ustring.match(colonprefix, "^[Ff]ile$")
    or mw.ustring.match(colonprefix, "^[Ii]mage$") then
        return ""
    end
     if mw.ustring.match(text, "[^|].*|%]%]") or mw.ustring.match(text, "%[%[|") then -- Weed out the pipe tricks first.
     if mw.ustring.match(text, "[^|].*|%]%]") or mw.ustring.match(text, "%[%[|") then -- Weed out the pipe tricks first.
         return delinkPipeTrick(text)
         return delinkPipeTrick(text)