Changes
Jump to navigation
Jump to search
local template_types = { vandalism = { namespaces = false, -- defaults to all namespaces editLevels = false, -- all edit protection levels moveLevels = false, -- all move protection levels createLevels = false, -- all create protection levels header = false, reason = 'due to [[Wikipedia:Vandalism|vandalism]]', icon_reason = 'due to vandalism', }}
tidy this up and comment it so it will be easier for others to understand
local categories = {
-- The key strings follow this format:
-- type, level, ns, reason, expiry
['edit-autoconfirmed-user-all-all'] = 'Wikipedia semi-protected user and user talk pages',
['edit-autoconfirmed-project-all-all'] = 'Semi-protected project pages',
}
local reasonBehaviors = {
vandalism = 'namespaceFirst',
dispute = 'reasonFirst',
blp = 'reasonFirst',
sock = 'reasonFirst',
office = 'reasonFirst',
}
--[[
-- Not currently used
local error_categories = {
incorrect = 'Wikipedia pages with incorrect protection templates',
template = 'Wikipedia template-protected pages other than templates and modules'
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Define often-used functions as local getArgs = require('Module:Arguments')variables.getArgslocal yesno tconcat = require('Module:Yesno')table.concat
local p = {}
function p.mainmatchNamespace(framens) -- Get data local args = getArgs(frame) local title = p.getTitle(args.page) local protType, protLevel = p.getProtectionStatus(title) local Matches a namespace = p.getNamespace(title) local expiry = p.getExpiry(args.expiry) local reason = p.getReason(args.reason) -- Sort categories and build number to a category link with string that can be passed to the best match categories = p.sortCategories(categories, protType, protLevel, namespace, expiry, reason) local category = categories[1].name category = string.format('[[Category:%s]]', category) -- Find whether we are small or not and output a padlock or a banner as appropriate local isSmall = yesno(args.small, true) if isSmall then return p.exportPadlock() else return namespacep parameter of p.exportBanner() endend function p.parseNamespace(ns) -- The ns variable is the namespace numbergetCategoryName.
if not ns or type(ns) ~= 'number' then
return 'all'
function p.getCategoryName(cats, protType, protLevel, namespace, reason, expiry)
-- Gets a category name from the category table, given a combination of
-- the protection type, the protection level, the namespace number, the
-- reason for protection, and the expiry date.
-- Preprocess parameters
cats = cats or categories
protType = protType or 'all'
protLevel = protLevel or 'all'
namespace = p.parseNamespacematchNamespace(namespace)
reason = reason or 'all'
if not expiry then
end
--[[
-- Define the key table and the order to test it in.
-- This part is a little like playing regex golf - we The idiosyncracies of the old template system have been distilled down to make up a new -- rule for every idiosyncracy two basic behaviors - templates that prioritise matching the reason over -- matching the namespace, and templates that was in prioritise matching the old template system -- namespace over matching the reason.In each case the function tries to local keyTable = {protType-- match specific keys, protLeveland if there is no match, namespaceit proceeds to match -- increasingly generic keys, reason, expiry}until eventually it will match the key -- "all-all-all-all-all". --]] local reasonBehaviors protectionProperties = { vandalism = 'namespaceFirst'protType, dispute = 'reasonFirst'protLevel, blp = 'reasonFirst'namespace, sock = 'reasonFirst'reason, office = 'reasonFirst', expiry}
local reasonBehavior = reasonBehaviors[reason]
local attemptOrder
attemptOrder = {
-- type, level, ns, reason, expiry
-- true corresponds to the original protectionProperties key,
-- and false corresponds to the key "all".
{true, true, true, true, true}, -- 1
{true, true, true, true, false}, -- 2
for i, t in ipairs(attemptOrder) do
local key = {}
for j, useKeyTable useProperty in ipairs(t) do if useKeyTable useProperty then key[j] = keyTableprotectionProperties[j]
else
key[j] = 'all'
end
end
key = table.concattconcat(key, '-')
mw.log(key) -- for debugging
local attempt = cats[key]