|
|
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)', |
| | } |
| | |
| | local nskeys = { |
| | [2] = 'user', |
| | [3] = 'user', |
| | [4] = 'project', |
| | [6] = 'file', |
| | [10] = 'template', |
| | [12] = 'project', |
| | [14] = 'category', |
| | [100] = 'portal', |
| } | | } |
|
| |
|
Line 95: |
Line 106: |
| end | | end |
|
| |
|
| function p.matchCategory(cats, protType, protLevel, namespace, expiry, reason) | | function p.parseNamespace(ns) |
| local function isValidCat(t) | | -- The ns variable is the namespace number. |
| --[[
| | if not ns or type(ns) ~= 'number' then |
| -- Does a first parse over the categories, removing any that explicitly
| | return 'all' |
| -- 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 | | end |
| | | local nskey = nskeys[ns] |
| -- Remove invalid cats.
| | if not nskey and ns % 2 == 1 then |
| local sortCats = {} | | nskey = 'talk' |
| for i, t in ipairs(cats) do | | else |
| if isValidCat(t) then
| | nskey = 'all' |
| sortCats[#sortCats + 1] = t
| |
| end | |
| end | | end |
| | return nskey |
| | end |
|
| |
|
| -- Sort the remaining cats.
| | function p.matchCategory(cats, protType, protLevel, namespace, expiry, reason) |
| -- The categories which are left either explicitly name the right parameter,
| | local nskey = p.parseNamespace(namespace) |
| -- 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 | | end |
|
| |
|
| return p | | return p |