Module:Contentious topics/talk notice: Difference between revisions

Content deleted Content added
add
more extensible
Line 2:
local TableTools = require('Module:TableTools')
local yesno = require('Module:Yesno')
local setToList = require('Module:Set to list')
local restrictionsDatabase = mw.loadJsonData("Template:Contentious topics/Additional restrictions.json")
local restrictionsDefinition = mw.loadJsonData("Template:Contentious topics/Restrictions definition.json")
local standardSet = mw.loadJsonData("Template:Contentious topics/Standard set.json")
 
local function collectTopics(args)
Line 38 ⟶ 40:
local topics = collectTopics(args)
local multipleTopics = #topics > 1
local restrictions = {} -- A list of which restrictions are enabled for easier iteration
local restrictionFlags = {} -- Track which restrictions are enabled, as a set
local currentTitleObject = mw.title.getCurrentTitle()
local subjectTitleObject = currentTitleObject.subjectPageTitle
local messageBody
 
--[[
This area sets active restrictions
The end goal is to get the restrictions variable into a nice, neat, sorted list of which restrictions are active
This is a somewhat intense process
--]]
-- Helpers to add a restriction if it's active and hasn't been added yet
local function addRestriction(restriction, topicWide)
if (yesno(args[restriction]) or topicWide) and not restrictionFlags[restriction] then
restrictionFlags[restriction] = true
table.insert(restrictions, restriction)
end
end
local function maybeAddRestriction(restriction) return addRestriction(restriction, false) end
local function alwaysAddRestriction(restriction) return addRestriction(restriction, true) end
 
-- Add the always-available restrictions
for _, restrictionr in ipairs(restrictionsstandardSet) do
maybeAddRestriction("0RR")
maybeAddRestriction("0RR-nocat"r)
end
maybeAddRestriction("1RR")
maybeAddRestriction("1RR-nocat")
maybeAddRestriction("BRD")
maybeAddRestriction("consensus-required")
 
-- Topic-based restrictions
Line 81 ⟶ 84:
 
-- Page protection restriction (if it's defined)
-- todo: Figure this one
local protectionLevels = subjectTitleObject.protectionLevels and subjectTitleObject.protectionLevels["edit"] or {}
for _, prot in ipairs(protectionLevels) do
Line 87 ⟶ 91:
end
end
--clear duplicate restrictions (e.g. 0RR and 1RR; 1RR and 1RR-nocat, etc)
--make sure you handle the case with all revert rules active correctly!
if (restrictionFlags["1RR"] or restrictionFlags["1RR-nocat"]) and (restrictionFlags["0RR"] or restrictionFlags["0RR-nocat"]) then
for _, restriction in ipairs(restrictions) do
 
end
end
restrictions = setToList(restrictionFlags)
 
-- Check whether any of the added restrictions are enabled
Line 106 ⟶ 120:
return def and ('* <b>' .. def .. '</b>\n') or ''
end
--disable 1RR if 0RR is in effect
--clear duplicate restrictions (e.g. 0RR and 1RR; 1RR and 1RR-nocat, etc)
--make sure you handle the case with all revert rules active correctly!
if (restrictionFlags["1RR"] or restrictionFlags["1RR-nocat"]) and (restrictionFlags["0RR"] or restrictionFlags["0RR-nocat"]) then
for _, restriction in ipairs(restrictions) do
 
end
end
messageBody = "<p>'''The [[Wikipedia:Contentious topics|contentious topics]] procedure applies to this "