Module:Sandbox/Rich Farmbrough/cross-namespace

Revision as of 22:30, 12 January 2016 by imported>Rich Farmbrough
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Rich Farmbrough/cross-namespace/doc

local p = {}

function p.test(frame)
   if (not isRedirect()) then return "[[Category:Pages incorrectly tagged as cross-namespace redirects]]" end
   local tospace   = ""    
   __, tospace     =  mw.string.find (mw.string.lower(getContent()), "#redirect:?\s*\[\[(talk|(portal|template....)([_ ]+talk))?:")

   if (tospace=="") then tospace="article space" end
--   else  tospace   = mw.string.lower (tospace) end

   local fromspace = ""
   fromspace       = mw.string.find (PageTitle(), "#redirect:?\s*\[\[(talk|(portal|template....)([_ ]+talk)?:")

   if (fromspace=="") then fromspace="article space " 
   else fromspace  = mw.string.lower(fromspace) end

   if (fromspace == tospace) then return "[{Category:Pages incorrectly tagged as cross-namespace redirects]] .. fromspace .. tospace" end

-- Maybe
-- rv = [[Category:Redirects from " .. fromspace .. " page to " .. tospace .. " page]]
-- and check cat exists - if not add a tracking cat.
-- Or
   rv = "[[Category:Cross-namespace redirects from " .. fromspace .. "pages]][[Category:Cross-namespace redirects to " .. tospace .. " pages]]"
-- Or both
   return  rv
end

return p