Jump to content

Module:Protection banner: Difference between revisions

add half-finished category sorting code
(finish list of categories)
(add half-finished category sorting code)
Line 287: Line 287:
end
end
end
end
function p.matchCategory(cats, protType, protLevel, namespace, expiry, reason)
local function isValidCat(t)
--[[
-- Does a first parse over the categories, removing any that explicitly
-- name a wrong parameter. This accounts for the majority of all of the
-- categories.
--
-- We check the parameters most likely to be wrong first. This saves on
-- table lookups, which shoud make the function faster.
--]]
local testType, testLevel, testNs, testExpiry, testReason
testReason = t.reason
if testReason and testReason ~= reason then
return false
end
testNs = t.namespace
if testNs and not testNs[namespace] then
return false
end
testExpiry = t.expiry
if testExpiry and testExpiry ~= expiry then
return false
end
testLevel = t.level
if testLevel and testLevel ~= protLevel then
return false
end
testType = t.type
if testType and testType ~= protType then
return false
end
return true
end
-- Remove invalid cats.
local sortCats = {}
for i, t in ipairs(cats) do
if isValidCat(t) then
sortCats[#sortCats + 1] = t
end
end
-- Sort the remaining cats.
-- The categories which are left either explicitly name the right parameter,
-- or implicitly allow all values for that parameter.
table.sort(sortCats, function (t1, t2)
local type1 = t1.type
local type2 = t2.type
local level1 = t1.level
local level2 = t2.level
local ns1 = t1.namespace
local ns2 = t2.namespace
local exp1 = t1.expiry
local exp2 = t2.expiry
local reason1 = t1.reason
local reason2 = t2.reason
local score1 = 0
local score2 = 0
end)
end


return p
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.