Module:Contentious topics/talk notice: Difference between revisions

Content deleted Content added
oops
test
Line 38:
local args = require('Module:Arguments').getArgs(frame)
local topics = collectTopics(args)
local multipleTopics = #topics > 1
local restrictions = {}
local currentTitleObject = mw.title.getCurrentTitle()
local subjectTitleObject = currentTitleObject.subjectPageTitle
local messageBody
 
--== Generate the active restrictions==--
-- helper function which add restrictions if active
local function addRestriction(restriction)
if yesno(args[restriction]) then
table.insert(restrictions, restriction)
end
end
 
-- add the always available restrictions, if applicable
addRestriction("0RR")
addRestriction("0RR-nocat")
addRestriction("1RR")
addRestriction("1RR-nocat")
addRestriction("BRD")
addRestriction("consensus-required")
 
-- then check each topic...
for _, topic in ipairs(topics) do
local currentTopicWideRestrictions = restrictionsDatabase["topic-wide"][topic]
--... add anything applicable to the entire topic...
if currentTopicWideRestrictions then
TableTools.merge(currentTopicWideRestrictions, restrictions)
end
--...and add anything available to that topic in particular
local availableTopicRestrictions = restrictionsDatabase["additional-available"][topic]
if availableTopicRestrictions then
for __, availableRestriction in ipairs(availableTopicRestrictions) do
addRestriction(availableRestriction)
end
end
end
 
-- Finally, we automatically detect the protection level of the subject page
local protectionLevel = subjectTitleObject["protectionLevels"] and subjectTitleObject["protectionLevels"]["edit"]
if protectionLevel then
table.insert(restrictions, protectionLevel)
end
--== End generation of active restrictions ==--
--== Start building the banner==--
--=Helper functions and variables=--
-- given a CTOP code, outputs a bullet point explaining the scope of the contentious topic designation
local function makeTopicBulletPoint(code)
return '* <b>' .. frame:expandTemplate{ title = "Contentious topics/list", args = { scope=code } } .. '</b>\n'
end
-- given a restriction code, write a bullet point
-- I suppose this could be abstracted, but I don't think that is worth the effort
local function makeRestrictionBulletPoint(code)
local def = restrictionsDefinition[code]
return def and ('* <b>' .. def .. '</b>\n') or ''
end
-- is this page under any restrictions?
local underRestrictions = #restrictions > 0
-- gets either "article" or "page", as the case may be
local articleOrPage = currentTitleObject:inNamespaces(1) and "article" or "page"
--=End helper functions and variables=--
messageBody = '<p>The [[Wikipedia:Contentious topics|contentious topics]] procedure applies to this '
.. articleOrPage
.. '.'
.. (yesno(args.section) and (' Parts of this ' .. articleOrPage .. ' relate ') or (' This ' .. articleOrPage .. ' relates '))
if multipleTopics then
messageBody = messageBody .. 'to the following contentious topics:</p>\n'
for _, topic in ipairs(topics) do
messageBody = messageBody .. makeTopicBulletPoint(topic, frame)
end
else
messageBody = messageBody .. 'to <b>'
.. frame:expandTemplate{ title = "Contentious topics/list", args = { scope=topics[1] } }
.. '</b>, a contentious topic.</p>'
end
if underRestrictions then
-- we have some active restrictions
-- so first prepend the warning in big bold text
messageBody = '<strong style="text-transform: uppercase;">Warning: active arbitration remedies</strong>'
.. messageBody
.. '<p style="text-decoration:underline;">The following restrictions apply to all editors editing in the topic area:</p>\n'
-- and then append each restriction
for _, restriction in ipairs(restrictions) do
messageBody = messageBody .. makeRestrictionBulletPoint(restriction)
end
end
messageBody = messageBody .. '><p>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. '
.. 'Editors are advised to familiarise themselves with the [[Wikipedia:Contentious topics|contentious topics procedures]] before editing this page.</p>'
.. (yesno(args.section) and '<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>' or '')
 
--== End generation of active restrictions ==--
local messageBox = require('Module:Message box').main( "tmbox" ,
 
{
--== Start building the banner==--
["type"] = underRestrictions and "delete" or "content",
--=Helper functions and variables=--
["small"] = yesno(args.small),
 
["image"] = "[[File:Commons-emblem-"
-- given a CTOP code, outputs a bullet point explaining the scope of the contentious topic designation
.. (underRestrictions and "hand" or "issue")
local function makeTopicBulletPoint(code)
.. ".svg|"
return '* <b>' .. frame:expandTemplate{ title = "Contentious topics/list", args = { scope=code } } .. '</b>\n'
.. (yesno(args.small) and "30" or "40")
end
.. "px]]",
 
["text"] = messageBody
-- given a restriction code, write a bullet point
}
local function makeRestrictionBulletPoint(code)
)
local def = restrictionsDefinition[code]
return def and ('* <b>' .. def .. '</b>\n') or ''
return messageBox
end
 
-- is this page under any restrictions?
local hasRealRestrictions = false
for _, r in ipairs(restrictions) do
if restrictionsDefinition[r] then
hasRealRestrictions = true
break
end
end
 
local underRestrictions = hasRealRestrictions
 
-- gets either "article" or "page", as the case may be
local articleOrPage = currentTitleObject:inNamespaces(1) and "article" or "page"
 
--=End helper functions and variables=--
 
messageBody = '<p>The [[Wikipedia:Contentious topics|contentious topics]] procedure applies to this '
.. articleOrPage
.. '.'
.. (yesno(args.section) and (' Parts of this ' .. articleOrPage .. ' relate ') or (' This ' .. articleOrPage .. ' relates '))
 
if multipleTopics then
messageBody = messageBody .. 'to the following contentious topics:</p>\n'
for _, topic in ipairs(topics) do
messageBody = messageBody .. makeTopicBulletPoint(topic, frame)
end
else
messageBody = messageBody .. 'to <b>'
.. frame:expandTemplate{ title = "Contentious topics/list", args = { scope=topics[1] } }
.. '</b>, a contentious topic.</p>'
end
 
if underRestrictions then
-- we have some active restrictions
messageBody = '<strong style="text-transform: uppercase;">Warning: active arbitration remedies</strong>'
.. messageBody
.. '<p style="text-decoration:underline;">The following restrictions apply to all editors editing in the topic area:</p>\n'
for _, restriction in ipairs(restrictions) do
messageBody = messageBody .. makeRestrictionBulletPoint(restriction)
end
end
 
messageBody = messageBody .. '<p>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. '
.. 'Editors are advised to familiarise themselves with the [[Wikipedia:Contentious topics|contentious topics procedures]] before editing this page.</p>'
.. (yesno(args.section) and '<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>' or '')
 
local messageBox = require('Module:Message box').main( "tmbox" ,
{
["type"] = underRestrictions and "delete" or "content",
["small"] = yesno(args.small),
["image"] = "[[File:Commons-emblem-"
.. (underRestrictions and "hand" or "issue")
.. ".svg|"
.. (yesno(args.small) and "30" or "40")
.. "px]]",
["text"] = messageBody
}
)
 
return messageBox
 
end