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

Content deleted Content added
save a WIP
sync – trying to debug Special:Permalink/1286083691
Tag: Reverted
Line 8:
local categoryDatabase = mw.loadJsonData("Template:Contentious topics/Category database.json")
 
local function collectTopics(args, sectionParameter)
local seen = {}
local completeTopicstopics = {}
 
local partialTopics = {}
local function add(value)
if value then
value = mw.text.trim(value)
if value ~= '' and not seen[value] then
local key = args seen[value .. '-section'] or= sectionParametertrue
if key then table.insert(topics, value)
table.insert(partialTopics, value, key)
else
table.insert(completeTopics, value)
end
seen[value] = true
end
end
Line 39 ⟶ 33:
add(args['topic' .. i])
end
 
return completeTopics, partialTopicstopics
end
 
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
local completeTopics, partialTopicstopics = collectTopics(args, sectionParameter)
local sectionParameter = 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 sectionParametersection = yesno(args.section) or yesno(args.relatedcontent) -- whether we are a section
--[[
Line 92 ⟶ 84:
 
-- Topic-based restrictions
for _, topic in ipairs (completeTopicstopics) do
local topicWide = restrictionsDatabase["topic-wide"][topic]
if topicWide then
for _, restriction in ipairs(topicWide) do
Line 99 ⟶ 91:
end
end
 
end
for _, topic in ipairs(topics) do
local additional = restrictionsDatabase["additional-available"][topic]
if additional then
Line 108 ⟶ 98:
end
end
local always = restrictionsDatabase["topic-wide"][topic]
if always then
for _, restriction in ipairs(always) do
maybeAddRestriction(restriction)
end
end
end
Line 159 ⟶ 143:
-- 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, )
--[[ 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 ''
elseifelse section then
-- we have some partial sections, so we check whether this is one of them
if partialTopics[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 196 ⟶ 165:
--[[
Place into an error categoriescategory if not given a contentious topic code
--]]
if numberOfTopics#topics == 0 then
-- No contentious topic codes
if numberOfTopics == 0 then
addCategory(categoryDatabase['no-topic'])
end
Line 207 ⟶ 175:
--]]
messageBody = '<b>The [[Wikipedia:Contentious topics|contentious topics]] procedure applies to this '
.. articleOrPage .. '.</b>'
-- .. (section and (' Parts of this ' .. articleOrPage .. ' relate ') or (' This ' .. articleOrPage .. ' relates '))
 
-- .. (section and (' Parts of this ' .. articleOrPage .. ' relate ') or (' This ' .. articleOrPage .. ' relates '))
if numberOfTopics#topics > 1 then
if numberOfTopics == 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 249 ⟶ 191:
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 273 ⟶ 214:
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]], '
.. '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.'
.. '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
--[[
 
if underRestrictions then
if args['placed-date'] then
Line 291 ⟶ 230:
end
end
]]--
--]][[
Now build some further information collapse boxes
We get the content of each collapse box from Wikipedia:Contentious topics/[Topic]/Further information
--]]
-- Now build the messageBox
Line 313 ⟶ 258:
-- Hard code for [[WP:BER]]
if TableTools.inArray(completeTopicstopics, "a-i") then
addCategory("Wikipedia pages subject to the extended confirmed restriction related to the Arab-Israeli conflict")
end