memory alpha
Module documentation ()

This module provides a way to retrieve the group required to perform a given action on a page.

Usage

Warning: This module will use up to four expensive parser function calls each time it is ran. It should only be used if the exact effective protection level is necessary. Otherwise, consider using title.protectionLevels instead.

From other modules

To load this module:

local effectiveProtectionLevel = require('Module:Effective protection level')._main

From wikitext

{{#invoke:Effective protection level|action|title}}

Parameters

This module accepts two parameters, which are the same whether invoked in wikitext or through another module. The first is a string containing the action to check, which must be "edit", "create", "move", "upload", or "undelete". The second is optional, and can either be the name of the page to check, or a title returned from the mw.title functions. If the second parameter is omitted, the page being displayed is the one checked against.

Return value

The return value is a string containing the name of the group required to perform the given action. The following are possible return values:

If * is returned, an error has occurred.

Module source

local p = {}

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
	local blacklistentry
	if action == 'move' then
		blacklistentry = mw.ext.TitleBlacklist.test('edit', title.prefixedText)
	else
		blacklistentry = mw.ext.TitleBlacklist.test(action, title.prefixedText)
	end
	if action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' and action ~= 'undelete' then
		error('First parameter must be edit, move, create, upload, or undelete', 2)
	end
	if title.namespace == 8 then
		if
			title.rootText == 'Conversiontable' or
			title.contentModel == 'javascript' or
			title.contentModel == 'css' or
			title.contentModel == 'sanitized-css' or
			title.text:sub(7) == 'Custom-' or
			title.text:sub(11) == 'Editnotice-' or
			title.text:sub(7) == 'Gadget-' or
			title.text:sub(8) == 'Gadgets-' or
			title.text:sub(4) == 'Tag-' or
			title.text == 'Anonnotice' or
			title.text == 'Blockedtext' or
			title.text == 'Blog-empty-user-blog' or
			title.text == 'Categoryblacklist' or
			title.text == 'Community-to-do-list' or
			title.text == 'Communitypage-policy-module-link-page-name' or
			title.text == 'Communitypage-subheader-welcome' or
			title.text == 'Communitypage-tasks-header-welcome' or
			title.text == 'Copyrightwarning' or
			title.text == 'Createpage-with-video' or
			title.text == 'Deletereason-dropdown' or
			title.text == 'Description' or
			title.text == 'Editor-template-list' or
			title.text == 'Edittools' or
			title.text == 'Edittools-upload' or
			title.text == 'Filedelete-reason-dropdown' or
			title.text == 'Global-navigation-local-search-placeholder' or
			title.text == 'ImportJS' or
			title.text == 'Ipboptions' or
			title.text == 'Ipbreason-dropdown' or
			title.text == 'Licenses' or
			title.text == 'Mainpage' or
			title.text == 'Moveddeleted-notice' or
			title.text == 'Newarticletext' or
			title.text == 'Noarticletext' or
			title.text == 'Pageimages-blacklist' or
			title.text == 'Pageimages-denylist' or
			title.text == 'Photosblacklist' or
			title.text == 'ProfileTags' or
			title.text == 'Protect-dropdown' or
			title.text == 'Recentchangestext' or
			title.text == 'Scribunto-doc-page-does-not-exist' or
			title.text == 'Sidebar' or
			title.text == 'Sitenotice' or
			title.text == 'Sitenotice id' or
			title.text == 'Smw allows pattern' or
			title.text == 'Talkpageheader' or
			title.text == 'Talkpagetext' or
			title.text == 'Titleblacklist' or
			title.text == 'TitleBlacklist' or
			title.text == 'Uploadtext' or
			title.text == 'Userrights-groups-help' or
			title.text == 'Wiki-description-site-meta' or
			title.text == 'Wiki-navigation'
		then
			return 'sysop'
		else
			return 'staff'
		end
	elseif
		(title.namespace == 2) and
		(title.isSubpage) and
		(title.contentModel == 'javascript' or title.contentModel == 'css' or title.contentModel == 'json')
	then
		return 'staff'
	end
	if blacklistentry and not blacklistentry.params.autoconfirmed then
		return 'sysop'
	end
	if action == 'move' then
		if title.namespace == 6 then
			return 'content-moderator'
		elseif title.namespace == 14 then
			return 'sysop'
		end
	end
	if action == 'undelete' then
		return 'content-moderator'
	end
	local level = title.protectionLevels[action] and title.protectionLevels[action][1]
	local cascade = title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1]
	if (level == 'sysop') or (cascade) then
		return 'content-moderator'
	elseif (level == 'autoconfirmed') or (blacklistentry and blacklistentry.params.autoconfirmed) then
		return 'autoconfirmed'
	end
	if action == 'edit' or action == 'move' or action == 'upload' or action == 'create' then
		return 'emailconfirmed'
	end
	return '*'
end

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

return p