m (1 revision imported)
 
(No difference)

Latest revision as of 16:10, 18 November 2015

Documentation for this module may be created at Module:Effective protection level/doc

  1. local p = {}
  2.  
  3. -- Returns the permission required to perform a given action on a given title.
  4. -- If no title is specified, the title of the page being displayed is used.
  5. function p._main(action, pagename)
  6. local title
  7. if type(pagename) == 'table' and pagename.prefixedText then
  8. title = pagename
  9. elseif pagename then
  10. title = mw.title.new(pagename)
  11. else
  12. title = mw.title.getCurrentTitle()
  13. end
  14. pagename = title.prefixedText
  15. if action == 'autoreview' then
  16. local level = mw.getCurrentFrame():callParserFunction('PENDINGCHANGELEVEL', pagename)
  17. if level == 'review' then
  18. return 'reviewer'
  19. elseif level ~= '' then
  20. return level
  21. else
  22. return nil -- not '*'. a page not being PC-protected is distinct from it being PC-protected with anyone able to review. also not '', as that would mean PC-protected but nobody can review
  23. end
  24. elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then
  25. error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 )
  26. end
  27. if title.namespace == 8 then -- MediaWiki namespace
  28. return 'sysop'
  29. elseif title.namespace == 2 and title.isSubpage and ( title.contentModel == 'javascript' or title.contentModel == 'css' ) then -- user JS or CSS page
  30. return 'sysop'
  31. end
  32. local level = title.protectionLevels[action] and title.protectionLevels[action][1]
  33. if level == 'sysop' or level == 'editprotected' then
  34. return 'sysop'
  35. elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page
  36. return 'sysop'
  37. elseif level == 'templateeditor' then
  38. return 'templateeditor'
  39. elseif action == 'move' then
  40. local blacklistentry = mw.ext.TitleBlacklist.test('edit', pagename) -- Testing action edit is correct, since this is for the source page. The target page name gets tested with action move.
  41. if blacklistentry and not blacklistentry.params.autoconfirmed then
  42. return 'templateeditor'
  43. elseif title.namespace == 6 then
  44. return 'filemover'
  45. else
  46. return 'autoconfirmed'
  47. end
  48. end
  49. local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename)
  50. if blacklistentry then
  51. return blacklistentry.params.autoconfirmed and 'autoconfirmed' or 'templateeditor'
  52. elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason
  53. return 'autoconfirmed'
  54. elseif level then
  55. return level
  56. elseif action == 'upload' then
  57. return 'autoconfirmed'
  58. elseif action == 'create' and title.namespace % 2 == 0 and title.namespace ~= 118 then -- You need to be registered, but not autoconfirmed, to create non-talk pages other than drafts
  59. return 'user'
  60. else
  61. return '*'
  62. end
  63. end
  64.  
  65. setmetatable(p, { __index = function(t, k)
  66. return function(frame)
  67. return t._main(k, frame.args[1])
  68. end
  69. end })
  70.  
  71. return p

local p = {}

-- Returns the permission required to perform a given action on a given title. -- If no title is specified, the title of the page being displayed is used. function p._main(action, pagename) local title if type(pagename) == 'table' and pagename.prefixedText then title = pagename elseif pagename then title = mw.title.new(pagename) else title = mw.title.getCurrentTitle() end pagename = title.prefixedText if action == 'autoreview' then local level = mw.getCurrentFrame():callParserFunction('PENDINGCHANGELEVEL', pagename) if level == 'review' then return 'reviewer' elseif level ~= then return level else return nil -- not '*'. a page not being PC-protected is distinct from it being PC-protected with anyone able to review. also not , as that would mean PC-protected but nobody can review end elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 ) end if title.namespace == 8 then -- MediaWiki namespace return 'sysop' elseif title.namespace == 2 and title.isSubpage and ( title.contentModel == 'javascript' or title.contentModel == 'css' ) then -- user JS or CSS page return 'sysop' end local level = title.protectionLevels[action] and title.protectionLevels[action][1] if level == 'sysop' or level == 'editprotected' then return 'sysop' elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page return 'sysop' elseif level == 'templateeditor' then return 'templateeditor' elseif action == 'move' then local blacklistentry = mw.ext.TitleBlacklist.test('edit', pagename) -- Testing action edit is correct, since this is for the source page. The target page name gets tested with action move. if blacklistentry and not blacklistentry.params.autoconfirmed then return 'templateeditor' elseif title.namespace == 6 then return 'filemover' else return 'autoconfirmed' end end local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename) if blacklistentry then return blacklistentry.params.autoconfirmed and 'autoconfirmed' or 'templateeditor' elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason return 'autoconfirmed' elseif level then return level elseif action == 'upload' then return 'autoconfirmed' elseif action == 'create' and title.namespace % 2 == 0 and title.namespace ~= 118 then -- You need to be registered, but not autoconfirmed, to create non-talk pages other than drafts return 'user' else return '*' end end

setmetatable(p, { __index = function(t, k) return function(frame) return t._main(k, frame.args[1]) end end })

return p