Title: Module:Effective protection level - freem URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level Markdown Content: _Documentation for this module may be created at [Module:Effective protection level/doc](https://freemwiki.com/index.php?title=Module:Effective\_protection\_level/doc&action=edit&redlink=1 "Module:Effective protection level/doc (page does not exist)")_ [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-1)local p = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-2)-- Returns the permission required to perform a given action on a given title.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-3)-- If no title is specified, the title of the page being displayed is used.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-4)function p._main(action, pagename)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-5)local title[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-6)if type(pagename) == 'table' and pagename.prefixedText then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-7)title = pagename[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-8)elseif pagename then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-9)title = mw.title.new(pagename)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-10)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-11)title = mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-12)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-13)pagename = title.prefixedText[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-14)if action == 'autoreview' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-15)local level = mw.ext.FlaggedRevs.getStabilitySettings(title)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-16)level = level and level.autoreview[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-17)if level == 'review' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-18)return 'reviewer'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-19)elseif level ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-20)return level[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-21)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-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[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-23)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-24)elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' and action ~= 'undelete' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-25)error( 'First parameter must be one of edit, move, create, upload, undelete, autoreview', 2 )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-26)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-27)if title.namespace == 8 then -- MediaWiki namespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-28)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[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-29)return 'interfaceadmin'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-30)elseif title.baseText == "Gadgets-definition" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-31)return 'interfaceadmin'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-32)else -- any non-JS/CSS MediaWiki page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-33)return 'sysop'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-34)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-35)elseif title.namespace == 2 and title.isSubpage then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-36)if title.contentModel == 'javascript' or title.contentModel == 'css' then -- user JS or CSS page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-37)return 'interfaceadmin'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-38)elseif title.contentModel == 'json' then -- user JSON page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-39)return 'sysop'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-40)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-41)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-42)if action == 'undelete' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-43)return 'sysop'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-44)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-45)local level = title.protectionLevels[action] and title.protectionLevels[action][1][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-46)if level == 'sysop' or level == 'editprotected' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-47)return 'sysop'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-48)elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-49)return 'sysop'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-50)elseif level == 'templateeditor' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-51)return 'templateeditor'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-52)elseif action == 'move' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-53)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.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-54)if blacklistentry and not blacklistentry.params.autoconfirmed then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-55)return 'templateeditor'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-56)elseif title.namespace == 6 then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-57)return 'filemover'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-58)elseif level == 'extendedconfirmed' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-59)return 'extendedconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-60)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-61)return 'autoconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-62)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-63)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-64)local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-65)if blacklistentry then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-66)if not blacklistentry.params.autoconfirmed then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-67)return 'templateeditor'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-68)elseif level == 'extendedconfirmed' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-69)return 'extendedconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-70)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-71)return 'autoconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-72)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-73)elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-74)return 'autoconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-75)elseif level then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-76)return level[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-77)elseif action == 'upload' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-78)return 'autoconfirmed'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-79)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[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-80)if title.namespace == 0 then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-81)return 'autoconfirmed' -- Per [[WP:ACPERM]], you need to be autoconfirmed to create pages in mainspace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-82)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-83)return 'user'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-84)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-85)return '*'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-86)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-87)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-88)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-89)setmetatable(p, { __index = function(t, k)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-90)return function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-91)return t._main(k, frame.args[1])[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-92)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-93)end })[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-94)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3AEffective_protection_level#L-95)return p