Module:Portal: Difference between revisions

Content deleted Content added
rename tracking cat
simplify tracking logic
Line 50:
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
 
-- List of non-talk namespaces which should not be tracked (Talk pages are never tracked)
local badNamespaces = {'user','template','draft'}
 
-- Check whether to do tracking in this namespace
-- Returns true unless the page is one of the banned namespaces
local function checkTrackingNamespacecheckTracking(title)
local thisPage = title or mw.title.getCurrentTitle()
returnif not( (thisPage.namespace == 1) --isTalkPage Talkthen
return false
or (thisPage.namespace == 2) -- User
end
or (thisPage.namespace == 3) -- User talk
local ns = thisPage.nsText:lower()
or (thisPage.namespace == 5) -- Wikipedia talk
for _, v in ipairs(badNamespaces) do
or (thisPage.namespace == 7) -- File talk
if ns == v then
or (thisPage.namespace == 11) -- Template talk
return false
or (thisPage.namespace == 15) -- Category talk
end
or (thisPage.namespace == 101) -- Portal talk
end
or (thisPage.namespace == 109) -- Book talk
return true
or (thisPage.namespace == 118) -- Draft
or (thisPage.namespace == 119) -- Draft talk
or (thisPage.namespace == 829)) -- Module talk
end
 
-- Check whether to do tracking on this pagename
-- Returns false if the page title matches one of the banned strings
-- Otherwise returns true
local function checkTrackingPagename(title)
local thisPage = title or mw.title.getCurrentTitle()
local thisPageLC = mw.ustring.lower(thisPage.text)
return not( mw.ustring.match(thisPageLC, "/archive")
or mw.ustring.match(thisPageLC, "/doc")
or mw.ustring.match(thisPageLC, "/sandbox")
or mw.ustring.match(thisPageLC, "/test"))
end
 
--Check if page should be category tracked
--Arguments:
-- title (optional): mw.title.Title object to evaluate. Defaults to current page
--Returns:
-- bool whether page should be tracked
local function checkTracking(title)
title = title or mw.title.getCurrentTitle()
return checkTrackingNamespace(title) and checkTrackingPagename(title)
end