Module:Contentious topics/talk notice/sandbox: Difference between revisions

Content deleted Content added
save a WIP
save a WIP
Line 8:
local categoryDatabase = mw.loadJsonData("Template:Contentious topics/Category database.json")
 
local function collectTopics(args, sectionParameter)
local seen = {}
local completeTopics = {}
Line 17:
value = mw.text.trim(value)
if value ~= '' and not seen[value] then
iflocal key = args[value .. '-section'] thenor sectionParameter
if key then
table.insert(partialTopics, value, args[value .. '-section']key)
else
table.insert(completeTopics, value)
Line 38 ⟶ 39:
add(args['topic' .. i])
end
 
return completeTopics, partialTopics
end
Line 44 ⟶ 45:
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
local sectionsectionParameter = yesno(args.section) or yesno(args.relatedcontent) -- whether we are a section
local completeTopics, partialTopics = collectTopics(args, sectionParameter)
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 section = sectionParameter or #partialTopics > 0 -- whether any topics apply to parts of the article
local underRestrictions -- a boolean for whether there are any active restrictions
local articleOrPage -- the string "article" (if a mainspace page) or "page" (if not)
local protectionLevel -- the edit protection level
local numberOfTopics -- positive int which represents the number of topics
local messageBody -- the text within the message box
local messageBox -- the message box itself
local categories = '' -- initialize categories
local manualRestrictions = false -- have we set any restrictions via |parameters?
local section = yesno(args.section) or yesno(args.relatedcontent) -- whether we are a section
--[[
Here we figure out if any of the topics apply to only part of the page
--]]
for _, topic in iparis(topics) do
-- this assigns nil if the -section parameter is not given
-- which does not change the table at all
partialTopics[topic .. '-section'] = sectionBlurb
if not partialTopics[topic .. '-section'] then
table.insert(completeTopics, topic)
end
end
--[[
Line 117 ⟶ 108:
end
end
local always = restrictionsDatabase["topic-wide"][topic]
if always then
for _, restriction in ipairs(always) do
maybeAddRestriction(restriction)
end
end
end
Line 162 ⟶ 159:
-- Check whether any of the added restrictions are enabled
underRestrictions = #restrictions > 0 or args.other
-- total number of topics applicable
numberOfTopics = #partialTopics + #completeTopics
-- Determines whether we should use the string "article" or "page"
local articleOrPage = currentTitleObject:inNamespaces(1) and "article" or "page"
 
 
--[[ Makes a bullet point for a given contentious topic
local function makeTopicBulletPoint(code, )
topicBlurb = frame:expandTemplate{ title = "Contentious topics/list", args = { scope=code } }
if topicBlurb == '' then
addCategory(categoryDatabase['bad-topic'])
return ''
elseelseif section then
-- we have some partial sections, so we check whether this is one of them
if not partialTopics[topic .. '-section'code] then
if yesno(partialTopics[code], false) then
-- not given any explicit detail about what applies to the contentious topic, so we specify nothing in particular
return '* <b><span style="text-decoration:underline;">Parts relate to</span> ' .. topicBlurb '</b>\n'
else
-- we are told exactly what parts of the article apply
return '* <b>' .. partialTopics[code] .. ' relate to ' .. topicBlurb '</b>\n'
end
else
return '* <b>' .. topicBlurb .. '</b>\n'
end
end
--]]
-- Makes a restriction bullet point
Line 184 ⟶ 196:
--[[
Place into an error category if not given a contentious topic codecategories
--]]
-- No contentious topic codes
if #topicsnumberOfTopics == 0 then
addCategory(categoryDatabase['no-topic'])
end
Line 194 ⟶ 207:
--]]
messageBody = '<b>The [[Wikipedia:Contentious topics|contentious topics]] procedure applies to this ' .. articleOrPage .. '.</b>'
.. articleOrPage .. '.</b>'
-- .. (section and (' Parts of this ' .. articleOrPage .. ' relate ') or (' This ' .. articleOrPage .. ' relates '))
 
if #topicsnumberOfTopics >== 1 then
if section then
for topic, part in pairs(partialTopics) do
-- there's only one item, so this one runs once
messageBody = messageBody .. ' Parts of this ' .. articleOrPage
.. (yesno(part, false) and '' or (' about <b>' .. part .. '</b>'))
.. ' relate to <b>'
.. frame:expandTemplate {
title = "Contentious topics/list",
args = { scope = topic }
}
.. '</b>, a contentious topic.'
end
else
messageBody = messageBody .. ' This ' .. articleOrPage ' relates to <b>'
.. frame:expandTemplate {
title = "Contentious topics/list",
args = { scope = completeTopics[1] }
}
.. '</b>, a contentious topic.</p>'
end
else
-- LOOP FOR MULTIPLE TOPICS
end
--[[
if numberOfTopics > 1 then
messageBody = messageBody .. 'to the following contentious topics:\n'
for _, topic in ipairs(topics) do
Line 210 ⟶ 249:
messageBody = messageBody .. 'to <b>'
.. topicBlurb
.. '</b>, a contentious topic.</p>'
else
addCategory(categoryDatabase['bad-topic'])
end
end
--]]
 
if underRestrictions then
messageBody = '<p style="margin-top:0"><strong style="text-transform: uppercase;">Warning: active arbitration remedies</strong></p>'
Line 233 ⟶ 273:
if not yesno(args.brief) then
messageBody = messageBody .. ' Editors who repeatedly or seriously fail to adhere to the [[WP:Five pillars|purpose of Wikipedia]], '
.. 'any expected [[WP:Etiquette|standards of behaviour]], '
.. 'or any [[WP:List of policies|normal editorial process]] may be blocked or restricted by an administrator.'
end
if section then
messageBody = messageBody .. '<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. '
.. 'If no comment is present, please ask an administrator for assistance. If in doubt it is better to assume that the content is covered.</p>'
end
Line 271 ⟶ 313:
-- Hard code for [[WP:BER]]
if TableTools.inArray(topicscompleteTopics, "a-i") then
addCategory("Wikipedia pages subject to the extended confirmed restriction related to the Arab-Israeli conflict")
end