Module:Protected edit request/active: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
handle new method of calling
m Protected "Module:Protected edit request/active": High-risk template or module: 300 transclusions (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))
 
(41 intermediate revisions by 14 users not shown)
Line 1:
require('Module:No globalsstrict')
 
local yesno, makeMessageBox -- passed in from Module:Protected edit request
local makeToolbar = require('Module:Toolbar')._main
local getPagetype = require('Module:Pagetype')._main
local effectiveProtectionLevel = require('Module:Effective protection level').main_main
 
----------------------------------------------------------------------
Line 28 ⟶ 29:
function title.getProtectionLevelText(protectionLevel)
-- Gets the text to use in anchors and urn links.
local levels = {unprotected = 'editunprotected', autoconfirmed = 'editsemiprotected', extendedconfirmed = 'editextendedprotected', templateeditor = 'edittemplateprotected', sysop = 'editprotected', interfaceadmin = 'editinterfaceprotected'}
return levels[protectionLevel]
end
Line 35 ⟶ 36:
local success, obj = pcall(mw.title.new, ...)
if not (success and obj) then return end
title.init(obj)
return obj
end
 
function title.init(obj)
-- Add a protectionLevel property.
obj.protectionLevel = effectiveProtectionLevel(nil, obj.exists and 'edit' or 'create', obj)
if obj.protectionLevel == '*' then
-- Make unprotected pages return "unprotected".
Line 44 ⟶ 49:
-- If we just need to be registered, pretend we need to be autoconfirmed, since it's the closest thing we have.
obj.protectionLevel = 'autoconfirmed'
elseif obj.protectionLevel == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages, since templateeditors can do both.
obj.protectionLevel = 'templateeditor'
end
 
Line 96 ⟶ 98:
-- as the detection may be inaccurate for cascade-protected and title-blacklisted pages as of Nov 2013.
local protectionLinkText = title.getProtectionLevelText(boxProtectionLevel)
return mw.ustring.format('[urn:x-wp-%s:%s <span></span>]', protectionLinkText, self:urlEncode())
end
 
Line 103 ⟶ 105:
return title.new(self.prefixedText .. '/' .. subpage)
end
 
function obj:getSandboxTitle()
return obj
if self.isSubpage and self.contentModel == 'sanitized-css' then
local success2, obj2 = pcall(mw.title.makeTitle, self.namespace, self.baseText .. '/sandbox/' .. self.subpageText)
if success2 and obj2 then
title.init(obj2)
return obj2
end
end
return self:getSubpageTitle('sandbox')
end
end
 
Line 280 ⟶ 291:
function blurb:makeProtectionText()
local boxProtectionLevel = self.boxProtectionLevel
local levels = {unprotected['*'] = 'unprotected', autoconfirmed = 'semi-protected', extendedconfirmed = 'extended-confirmed-protected', templateeditor = 'template-protected', sysop = 'fully protected', interfaceadmin = 'interface-protected'}
for level, protectionText in pairs(levels) do
if level == boxProtectionLevel then
Line 286 ⟶ 297:
end
end
error('Unknown protection level ' .. boxProtectionLevel)
end
 
Line 309 ⟶ 321:
table.insert(tbargs, title:makeWhatLinksHereLink('links'))
-- Sandbox links.
local sandboxTitle = title:getSubpageTitlegetSandboxTitle('sandbox')
if sandboxTitle and sandboxTitle.exists then
table.insert(tbargs, sandboxTitle:makeViewLink('sandbox'))
Line 325 ⟶ 337:
if title.namespace == 10 or title.namespace == 828 then -- Only add the transclusion count link for templates and modules.
local tclink = mw.uri.new{
host = 'toolstemplatecount.wmflabstoolforge.org',
path = '/templatecount/index.php',
query = {
lang = 'en',
Line 426 ⟶ 438:
else
local userText
local responseTemplate
if boxProtectionLevel == 'autoconfirmed' then
if boxProtectionLevel == 'extendedconfirmed' then
userText = '[[Wikipedia:User access levels#Extended confirmed users|extended confirmed]] user'
responseTemplate = blurb.makeTemplateLink('EEp')
elseif boxProtectionLevel == 'autoconfirmed' then
userText = '[[Wikipedia:User access levels#Autoconfirmed|autoconfirmed]] user'
responseTemplate = blurb.makeTemplateLink('ESp')
elseif boxProtectionLevel == 'interfaceadmin' then
userText = '[[Wikipedia:User access levels#Interface administrators|interface administrator]]'
responseTemplate = blurb.makeTemplateLink('EIp')
else
userText = 'user'
responseTemplate = blurb.makeTemplateLink('ESp')
end
local answeredPara = blurb.makeParaText('answered', 'no')
Line 436 ⟶ 457:
.. "This is so that inactive or completed requests don't needlessly fill up the edit requests category. "
.. 'You may also wish to use the %s template in the response.'
smallText = mw.ustring.format(stringToFormat, userText, answeredPara, blurb.makeTemplateLink('ESp')responseTemplate)
end
 
if not isPlural then
local title = titles[1]
if title.namespace == 10 or title.namespace == 828 then
local sandboxTitle = title:getSubpageTitle('sandbox')
if sandboxTitle and sandboxTitle.exists then
smallText = smallText .. ' Consider making changes first to the '
.. sandboxTitle:makeViewLink(title.pagetype .. "'s sandbox")
local testcasesTitle = title:getSubpageTitle('testcases')
if testcasesTitle and testcasesTitle.exists then
smallText = smallText .. ' and ' .. testcasesTitle:makeViewLink('test them thoroughly here')
end
smallText = smallText .. ' before submitting an edit request.'
end
end
end
if hasNonInterfacePage then
smallText = smallText .. ' To request that a page be protected or unprotected, make a [[Wikipedia:Requests for page protection|protection request]].'
end
if boxProtectionLevel == 'sysop' or boxProtectionLevel == 'templateeditor' or boxProtectionLevel == 'interfaceadmin' then
smallText = smallText .. ' When the request has been completed or denied, please add the ' .. blurb.makeParaText('answered', 'yes') .. ' parameter to deactivate the template.'
end
Line 460 ⟶ 497:
 
----------------------------------------------------------------------
-- Subclass of Module:Protected edit request's box class for active boxes
-- Additional box class definition
----------------------------------------------------------------------
 
local box = {}
box.__index = box
 
function box.new(protectionType, args)
-- In the inheritance system used here, an object's metatable is its class, and a class's metatable is its superclass
local obj = getmetatable(box).new(protectionType, args)
setmetatable(obj, box)
local boxProtectionLevels = {semi = 'autoconfirmed', extended = 'extendedconfirmed', template = 'templateeditor', full = 'sysop', interface = 'interfaceadmin'}
obj.boxProtectionLevel = boxProtectionLevels[protectionType]
obj.demo = yesno(args.demo)
-- Set dependent objects.
obj.titles = titleTable.new(args)
if not yesno(args.force) and obj.titles:hasSameProperty('sameProtectionStatus', function (title) return title.protectionLevel end) and obj.titles[1].protectionLevel ~= 'unprotected' then
obj.boxProtectionLevel = obj.titles[1].protectionLevel
end
obj.blurb = blurb.new(obj.titles, obj.boxProtectionLevel)
return obj
end
 
function box:setImage()
Line 469 ⟶ 523:
local boxProtectionLevel = self.boxProtectionLevel
local padlock
if boxProtectionLevel == 'sysop' and not titles:hasNonTemplateOrModule() then
padlock = 'PadlockFull-redprotection-shackle.svg'
elseif boxProtectionLevel == 'sysopinterfaceadmin' then
padlock = 'PadlockInterface-protection-shackle.svg '
elseif boxProtectionLevel == 'templateeditor' then
padlock = 'PadlockTemplate-pinkprotection-shackle.svg'
elseif boxProtectionLevel == 'autoconfirmed' then
padlock = 'PadlockSemi-silverprotection-shackle.svg'
elseif boxProtectionLevel == 'extendedconfirmed' then
padlock = 'Extended-protection-shackle.svg'
else
padlock = 'Padlock-bronze-open.svg'
Line 485 ⟶ 541:
self:setArg('smallimage', smallPadlock)
self:setArg('image', largePadlock)
end
 
function box:buildUrnLinks()
local ret = {}
local boxProtectionLevel = self.boxProtectionLevel
for titleObj in self.titles:titleIterator() do
table.insert(ret, titleObj:makeUrnLink(boxProtectionLevel))
end
return mw.ustring.format('<span class="plainlinks" style="display:none">%s</span>', table.concat(ret))
end
 
function box:setBlurbText()
local blurbText =self:setArg('text', self.blurb:export() .. self:buildUrnLinks())
self:setArg('text', blurbText)
end
 
Line 497 ⟶ 561:
self:setArg('class', 'editrequest')
self:setArg('id', title.getProtectionLevelText(self.boxProtectionLevel)) -- for anchor. yes, this leads to multiple elements with the same ID. we should probably fix this at some point
return self.makeMessageBox('tmbox', self.tmboxArgs)
end
 
Line 508 ⟶ 572:
local protectionCats = {
autoconfirmed = 'Wikipedia semi-protected edit requests',
extendedconfirmed = 'Wikipedia extended-confirmed-protected edit requests',
templateeditor = 'Wikipedia template-protected edit requests',
sysop = 'Wikipedia fully protected edit requests',
interfaceadmin = 'Wikipedia interface-protected edit requests'
}
addCat(protectionCats[boxProtectionLevel])
Line 516 ⟶ 582:
end
return table.concat(cats)
end
 
function box:exportUrnLinks()
local ret = {}
local boxProtectionLevel = self.boxProtectionLevel
for titleObj in self.titles:titleIterator() do
table.insert(ret, titleObj:makeUrnLink(boxProtectionLevel))
end
return mw.ustring.format('<span class="plainlinks" style="display:none">%s</span>', table.concat(ret))
end
 
function box:setArg(key, value)
-- This sets a value to be passed to tmbox.
if key then
self.tmboxArgs[key] = value
end
end
 
function box:export()
iflocal nottitle = self.titles.currentTitle.isTalkPage and not self.demo then
if not title.isTalkPage and not self.demo and not yesno(self.args.skiptalk) then
return '<span class="error">Error: Protected edit requests can only be made on the talk page.</span>[[Category:Non-talk pages requesting an edit to a protected page]]'
return '<span class="error">Error: Protected edit requests can only be made on the talk page.</span>[[Category:Non-talk pages with an edit request template]]'
end
local ret = {}
table.insert(ret, self:exportRequestTmbox())
table.insert(ret, self:exportUrnLinks())
if not self.demo then
table.insert(ret, self:exportRequestCategories())
Line 551 ⟶ 601:
----------------------------------------------------------------------
 
return function(superclass, protectionTypeyn, args, yesno, makeMessageBoxmb)
yesno = yn
local obj = superclass.new(protectionType, args)
makeMessageBox = mb
local boxProtectionLevels = {semi = 'autoconfirmed', template = 'templateeditor', full = 'sysop'}
return setmetatable(box, superclass)
obj.boxProtectionLevel = boxProtectionLevels[protectionType]
obj.demo = yesno(args.demo)
-- Set dependent objects.
obj.titles = titleTable.new(args)
if not yesno(args.force) and obj.titles:hasSameProperty('sameProtectionStatus', function (title) return title.protectionLevel end) and obj.titles[1].protectionLevel ~= 'unprotected' then
obj.boxProtectionLevel = obj.titles[1].protectionLevel
end
obj.blurb = blurb.new(obj.titles, obj.boxProtectionLevel)
obj.makeMessageBox = makeMessageBox
setmetatable(obj, {
__index = function(_, k)
if box[k] ~= nil then
return box[k]
else
return superclass[k]
end
end
})
end