Content deleted Content added
HouseBlaster (talk | contribs) refactor |
HouseBlaster (talk | contribs) save a WIP |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 4:
local yesno = require('Module:Yesno')
local checkForUnknownParameters = require('Module:Check for unknown parameters')._check
local messageBoxModule = require('Module:Message box')
local categoryDatabase = mw.loadJsonData("Template:Contentious topics/Category database.json")
local restrictionsDatabase = mw.loadJsonData("Template:Contentious topics/Additional restrictions.json")
Line 17 ⟶ 18:
local function collectTopics(args, sectionParameter)
local partialTopics = {}
local ECR = {}
local i = 2 -- initialize index
local keepGoing = true -- whether to keep checking for more CTOPs
if TableTools.inArray(restrictionsDatabase['topic-wide'][value] or {}, 'ECR') then
if yesno(scope, nil) then
ECR[value] = true
else
ECR[value] = scope
end
end
end
local function add(value)
if value then
value = mw.ustring.lower(mw.text.trim(value))
value = callFromListTemplate(value, 'canonical') -- normalize to the canonical name after we find the applicableSection
local applicableSection = args[value .. '-section'] or sectionParameter
addECR(value, applicableSection)
if value ~= '' and not
if applicableSection then
partialTopics[value] = applicableSection
else
-- first we clear the partialTopics value
-- this code is needed for articles which are e.g. entirely Eastern Europe but partially [[WP:APL]]
partialTopics[value] = nil
-- then we add it to the list of completeTopics
table.insert(completeTopics, value)
end
seen[value] = true
keepGoing = true
end
end
end
add(args[1])
add(args.topic1)
end
function p.main(frame)
-- process the input
local args = require('Module:Arguments').getArgs(frame)
-- check whether we are sections all the way down
local sectionParameter = yesno(args.section, args.section) or yesno(args.relatedcontent, args.relatedcontent)
-- set the topic variables:
--* completeTopics is a sequence for each topic applying the the entire article
--* partialTopics is a table with topics as keys and scope as values
--* active topics subject to ECR as keys, the scope (nil for the entire article, true for an unspecified scope) as the value
-- and then declare a bunch more variables which will be needed later
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 underRestrictions -- a boolean for whether there are any active restrictions
local articleOrPage -- the string "article" (if a mainspace article) or "page" (if not)
local numberOfCompleteTopics = #completeTopics -- the number of complete topics
local numberOfPartialTopics = TableTools.size(partialTopics) -- the number of partial topics (not a sequence, so we have to use TableTools.size)
local numberOfTopics = numberOfCompleteTopics + numberOfPartialTopics -- total number of topics
local section = sectionParameter or numberOfPartialTopics > 0 -- whether any topics apply to parts of the article
local messageBody -- the text within the message box
local messageBox -- the message box itself
local unknownParameterCheck -- the result of [[Module:Check for unknown parameters]]
local unknownParameterTable -- the table to pass to the [[Module:Check for unknown parameters]] call
local categories = '' -- initialize categories
local manualRestrictions = false -- have we set any restrictions via |parameters? Set to true when |parameters are processed
--[[
Line 93 ⟶ 113:
--]]
local function maybeAddRestriction(restriction)
if yesno(args[restriction]) then
Line 112 ⟶ 132:
end
end
end
restrictionFlags[restriction] = true
else
restrictionFlags[restriction] = nil
end
if protectionLevel then
-- we have a |protection=foo parameter, and the page is protected
if restrictionFlags["ECR"] then
-- handle ECR with protection correctly
end
manualRestrictions = true
Line 170 ⟶ 190:
addCategory(categoryDatabase['protection-error'])
end
--]]
-- if 0RR, then clear 1RR
if restrictionFlags["0RR"] then
Line 188 ⟶ 208:
-- and finally, convert our set to a list to make it easy to work with
--[[
Restrictions are now all set. Here, we add additional helper functions and variables necessary for generating the banner
--]]
local function addToMessage(s)
Line 208 ⟶ 228:
end
local function
return callFromListTemplate(code, 'subtopic')
end
Line 215 ⟶ 235:
local function getSupertopic(code)
return callFromListTemplate(code, 'supertopic')
end
local function makeSubtopicCompleteBlurb(code)
local topicSubpage = callFromListTemplate(code, 'topic-subpage')
return '<b>' .. '[[' .. topicSubpage ..'|'
.. mw.ustring.gsub(topicSubpage, 'Wikipedia:Contentious topics/', '')
.. ']]</b>.'
end
Line 220 ⟶ 248:
-- the scope is either a string representing the exact scope of the topic
-- and is nil if it applies to the entire page or unspecified parts of the page
addToMessage('* <b>' .. topicBlurb .. '</b>')
end
-- Makes a restriction bullet point
--[[
Line 262 ⟶ 291:
--]]
-- if there's only one topic, we make a short blurb
Line 279 ⟶ 308:
theCTOP = completeTopics[1]
end
local
if
addToMessage(' to <b>' ..
else
addToMessage(' to <b>' .. getTopicBlurb(theCTOP) .. '</b>, a contentious topic.')
end
else
-- there is more than one topic, so we have to do some more processing
-- we handle the cases for partialTopics and completeTopics completely seperately
if numberOfCompleteTopics ~= 0 then
-- if there are any complete topics, insert text about them
addToMessage(' The entire ' .. articleOrPage .. ' relates to ')
if numberOfCompleteTopics > 1 then
-- we either loop through adding bullet points
addToMessage('the following contentious topics:\n')
for _, topic in ipairs(completeTopics) do
makeTopicBulletPoint(topic, nil)
end
else
-- or we do it once
-- TODO: refactor makeTopicBulletPoint into a more versitile function, allowing it to be called here
addToMessage('<b>')
local superTopic = getSupertopic(completeTopics[1])
if superTopic ~= '' then
addToMessage(getSubtopicBlurb(completeTopics[1]) .. '</b>, part of the contentious topic designation for ' .. makeSubtopicCompleteBlurb(completeTopics[1]))
else
addToMessage(getTopicBlurb(completeTopics[1]) .. '</b>, a contentious topic.
end
end
end
if numberOfPartialTopics ~= 0 then
-- if there are any partial topics, insert text about them. Note that this runs regardless of whether there are any completeTopics
addToMessage('<p>')
if numberOfCompleteTopics ~= 0 then
Line 324 ⟶ 360:
-- There's only one topic and scope, so this loop only runs once
for topic, scope in pairs(partialTopics) do
if superTopic ~= '' then
addToMessage('<b>' .. getSubtopicBlurb(topic) .. '</b>')
else
addToMessage('<b>' .. getTopicBlurb(topic) .. '</b>')
end
if yesno(scope, nil) == nil then
-- the scope is not a boolean value, so we have a free-text explanation of the applicable parts
addToMessage(', in particular the parts about <b>' .. scope .. '</b>')
end
addToMessage('. This is a subtopic of ' .. makeSubtopicCompleteBlurb(topic) .. '</p>')
else
addToMessage('.</p>')
Line 340 ⟶ 380:
end
-- restrictions are all added to the banner text. Here we specify a date placed and a tracking category if not but we have manual restrictions
if args['placed-date'] then
addToMessage('<p>Restrictions placed: ' .. require('Module:Format time')._main{args['placed-date']} .. '</p>')
elseif manualRestrictions then
addCategory(categoryDatabase['no-date'])
end
end
addToMessage(' Editors are advised to familiarise themselves with the [[Wikipedia:Contentious topics|contentious topics procedures]] before editing this page.')
Line 377 ⟶ 423:
addToMessage('<p>Editors who repeatedly or seriously fail to adhere to the [[WP:Five pillars|purpose of Wikipedia]], '
.. 'any expected [[WP:Etiquette|standards of behaviour]], '
end
Line 383 ⟶ 429:
addToMessage('<p>If it is unclear which parts of the page are related to this contentious topic, '
.. 'the content in question should be marked within the wiki text by an invisible comment. '
end
-- Now build the messageBox
["image"] = "[[File:Commons-emblem-"
.. (underRestrictions and "hand" or "issue")
.. ".svg|40px]]",
["text"] = messageBody
})
-- If ECR is enabled, prepend the ECR warning
if restrictionFlags["ECR"] then
-- Hard code for [[WP:BER]]
if TableTools.inArray(completeTopics, "a-i") then
Line 419 ⟶ 449:
addCategory("Wikipedia pages subject to the extended confirmed restriction related to the Arab-Israeli conflict")
end
-- Then build the ECR box
messageBox = messageBoxModule.main("tmbox", {
["class"] = "nonextendedconfirmed-show ECR-edit-request-warning",
["style"] = "background: var(--background-color-destructive-subtle, #ffe9e5); border-color: var(--border-color-destructive, #f54739); color: var(--color-base, #202122);",
["image"] = "[[File:Commons-emblem-hand.svg|40px]]"
}).. messageBox
end
Line 450 ⟶ 487:
addKnownParameter('relatedcontent')
addKnownParameter('section')
-- then add all of the partialTopics section parameters
for code, _ in pairs(partialTopics) do
Line 477 ⟶ 513:
end
end
|