Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
convert categories back to a flat table scheme |
add namespace parser |
||
Line 43: | Line 43: | ||
['pc-autoconfirmed-all-all-all'] = 'Wikipedia pending changes protected pages (level 1)', |
['pc-autoconfirmed-all-all-all'] = 'Wikipedia pending changes protected pages (level 1)', |
||
['pc-reviewer-all-all-all'] = 'Wikipedia pending changes protected pages (level 2)', |
['pc-reviewer-all-all-all'] = 'Wikipedia pending changes protected pages (level 2)', |
||
} |
|||
⚫ | |||
[2] = 'user', |
|||
[3] = 'user', |
|||
[4] = 'project', |
|||
[6] = 'file', |
|||
[10] = 'template', |
|||
[12] = 'project', |
|||
[14] = 'category', |
|||
[100] = 'portal', |
|||
} |
} |
||
Line 95: | Line 106: | ||
end |
end |
||
function p.parseNamespace(ns) |
|||
⚫ | |||
-- The ns variable is the namespace number. |
|||
local function isValidCat(t) |
|||
if not ns or type(ns) ~= 'number' then |
|||
--[[ |
|||
⚫ | |||
-- 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 |
|||
⚫ | |||
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 |
|||
⚫ | |||
end |
end |
||
local nskey = nskeys[ns] |
|||
if not nskey and ns % 2 == 1 then |
|||
-- Remove invalid cats. |
|||
nskey = 'talk' |
|||
⚫ | |||
else |
|||
for i, t in ipairs(cats) do |
|||
nskey = 'all' |
|||
if isValidCat(t) then |
|||
sortCats[#sortCats + 1] = t |
|||
end |
|||
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 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 |
end |
||