https://www.dhammawiki.com/index.php?title=Module:Effective_protection_level&feed=atom&action=historyModule:Effective protection level - Revision history2024-03-28T10:14:52ZRevision history for this page on the wikiMediaWiki 1.35.0https://www.dhammawiki.com/index.php?title=Module:Effective_protection_level&diff=23718&oldid=prevWikiSysop: 1 revision imported2017-10-03T17:48:51Z<p>1 revision imported</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
-- Returns the permission required to perform a given action on a given title.<br />
-- If no title is specified, the title of the page being displayed is used.<br />
function p._main(action, pagename)<br />
local title<br />
if type(pagename) == 'table' and pagename.prefixedText then<br />
title = pagename<br />
elseif pagename then<br />
title = mw.title.new(pagename)<br />
else<br />
title = mw.title.getCurrentTitle()<br />
end<br />
pagename = title.prefixedText<br />
if action == 'autoreview' then<br />
local level = mw.ext.FlaggedRevs.getStabilitySettings(title)<br />
level = level and level.autoreview<br />
if level == 'review' then<br />
return 'reviewer'<br />
elseif level ~= '' then<br />
return level<br />
else<br />
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<br />
end<br />
elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then<br />
error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 )<br />
end<br />
if title.namespace == 8 then -- MediaWiki namespace<br />
return 'sysop'<br />
elseif title.namespace == 2 and title.isSubpage and ( title.contentModel == 'javascript' or title.contentModel == 'css' ) then -- user JS or CSS page<br />
return 'sysop'<br />
end<br />
local level = title.protectionLevels[action] and title.protectionLevels[action][1]<br />
if level == 'sysop' or level == 'editprotected' then<br />
return 'sysop'<br />
elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page<br />
return 'sysop'<br />
elseif level == 'templateeditor' then<br />
return 'templateeditor'<br />
elseif action == 'move' then<br />
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.<br />
if blacklistentry and not blacklistentry.params.autoconfirmed then<br />
return 'templateeditor'<br />
elseif title.namespace == 6 then<br />
return 'filemover'<br />
elseif level == 'extendedconfirmed' then<br />
return 'extendedconfirmed'<br />
else<br />
return 'autoconfirmed'<br />
end<br />
end<br />
local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename)<br />
if blacklistentry then<br />
if not blacklistentry.params.autoconfirmed then<br />
return 'templateeditor'<br />
elseif level == 'extendedconfirmed' then<br />
return 'extendedconfirmed'<br />
else<br />
return 'autoconfirmed'<br />
end<br />
elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason<br />
return 'autoconfirmed'<br />
elseif level then<br />
return level<br />
elseif action == 'upload' then<br />
return 'autoconfirmed'<br />
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<br />
return 'user'<br />
else<br />
return '*'<br />
end<br />
end<br />
<br />
setmetatable(p, { __index = function(t, k)<br />
return function(frame)<br />
return t._main(k, frame.args[1])<br />
end<br />
end })<br />
<br />
return p</div>WikiSysop