Module:Effective protection level
Jump to navigation
Jump to search
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.ext.FlaggedRevs.getStabilitySettings(title)
17 level = level and level.autoreview
18 if level == 'review' then
19 return 'reviewer'
20 elseif level ~= '' then
21 return level
22 else
23 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
24 end
25 elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' and action ~= 'undelete' then
26 error( 'First parameter must be one of edit, move, create, upload, undelete, autoreview', 2 )
27 end
28 if title.namespace == 8 then -- MediaWiki namespace
29 if title.text:sub(-3) == '.js' or title.text:sub(-4) == '.css' or title.contentModel == 'javascript' or title.contentModel == 'css' then -- site JS or CSS page
30 return 'interfaceadmin'
31 else -- any non-JS/CSS MediaWiki page
32 return 'sysop'
33 end
34 elseif title.namespace == 2 and title.isSubpage then
35 if title.contentModel == 'javascript' or title.contentModel == 'css' then -- user JS or CSS page
36 return 'interfaceadmin'
37 elseif title.contentModel == 'json' then -- user JSON page
38 return 'sysop'
39 end
40 end
41 if action == 'undelete' then
42 return 'sysop'
43 end
44 local level = title.protectionLevels[action] and title.protectionLevels[action][1]
45 if level == 'sysop' or level == 'editprotected' then
46 return 'sysop'
47 elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page
48 return 'sysop'
49 elseif level == 'templateeditor' then
50 return 'templateeditor'
51 elseif action == 'move' then
52 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.
53 if blacklistentry and not blacklistentry.params.autoconfirmed then
54 return 'templateeditor'
55 elseif title.namespace == 6 then
56 return 'filemover'
57 elseif level == 'extendedconfirmed' then
58 return 'extendedconfirmed'
59 else
60 return 'autoconfirmed'
61 end
62 end
63 local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename)
64 if blacklistentry then
65 if not blacklistentry.params.autoconfirmed then
66 return 'templateeditor'
67 elseif level == 'extendedconfirmed' then
68 return 'extendedconfirmed'
69 else
70 return 'autoconfirmed'
71 end
72 elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason
73 return 'autoconfirmed'
74 elseif level then
75 return level
76 elseif action == 'upload' then
77 return 'autoconfirmed'
78 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
79 return 'user'
80 else
81 return '*'
82 end
83 end
84
85 setmetatable(p, { __index = function(t, k)
86 return function(frame)
87 return t._main(k, frame.args[1])
88 end
89 end })
90
91 return p