44 private $userGroupManager;
47 private $languageConverter;
50 private $groupPermissionsLookup;
64 parent::__construct(
'Listgrouprights' );
65 $this->nsInfo = $nsInfo;
66 $this->userGroupManager = $userGroupManager;
68 $this->groupPermissionsLookup = $groupPermissionsLookup;
80 $out->addModuleStyles(
'mediawiki.special' );
81 $this->
addHelpLink(
'Help:User_rights_and_groups' );
83 $out->wrapWikiMsg(
"<div class=\"mw-listgrouprights-key\">\n$1\n</div>",
'listgrouprights-key' );
86 Xml::openElement(
'table', [
'class' =>
'wikitable mw-listgrouprights-table' ] ) .
88 Xml::element(
'th',
null, $this->
msg(
'listgrouprights-group' )->text() ) .
89 Xml::element(
'th',
null, $this->
msg(
'listgrouprights-rights' )->text() ) .
94 $addGroups = $config->get( MainConfigNames::AddGroups );
95 $removeGroups = $config->get( MainConfigNames::RemoveGroups );
96 $groupsAddToSelf = $config->get( MainConfigNames::GroupsAddToSelf );
97 $groupsRemoveFromSelf = $config->get( MainConfigNames::GroupsRemoveFromSelf );
98 $allGroups = array_merge(
99 $this->userGroupManager->listAllGroups(),
100 $this->userGroupManager->listAllImplicitGroups()
107 foreach ( $allGroups as $group ) {
108 $permissions = $this->groupPermissionsLookup->getGrantedPermissions( $group );
109 $groupname = ( $group ==
'*' )
113 $groupnameLocalized =
$lang->getGroupName( $groupname );
116 ?: Title::makeTitleSafe(
NS_PROJECT, $groupname );
118 if ( $group ==
'*' || !$grouppageLocalizedTitle ) {
120 $grouppage = htmlspecialchars( $groupnameLocalized );
122 $grouppage = $linkRenderer->makeLink(
123 $grouppageLocalizedTitle,
128 $groupWithParentheses = $this->
msg(
'parentheses' )->rawParams( $group )->escaped();
129 $groupname =
"<br /><code>$groupWithParentheses</code>";
131 if ( $group ===
'user' ) {
133 $grouplink =
'<br />' . $linkRenderer->makeKnownLink(
135 $this->
msg(
'listgrouprights-members' )->text()
137 } elseif ( !in_array( $group, $config->get( MainConfigNames::ImplicitGroups ) ) ) {
138 $grouplink =
'<br />' . $linkRenderer->makeKnownLink(
140 $this->
msg(
'listgrouprights-members' )->text(),
142 [
'group' => $group ]
149 $revoke = $this->groupPermissionsLookup->getRevokedPermissions( $group );
150 $addgroups = $addGroups[$group] ?? [];
151 $removegroups = $removeGroups[$group] ?? [];
152 $addgroupsSelf = $groupsAddToSelf[$group] ?? [];
153 $removegroupsSelf = $groupsRemoveFromSelf[$group] ?? [];
156 $out->addHTML( Html::rawElement(
'tr', [
'id' => $id ],
"
157 <td>$grouppage$groupname$grouplink</td>
159 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
160 $addgroupsSelf, $removegroupsSelf ) .
166 $this->outputNamespaceProtectionInfo();
169 private function outputNamespaceProtectionInfo() {
171 $namespaceProtection = $this->
getConfig()->get( MainConfigNames::NamespaceProtection );
173 if ( count( $namespaceProtection ) == 0 ) {
177 $header = $this->
msg(
'listgrouprights-namespaceprotection-header' )->text();
179 Html::element(
'h2', [
186 $this->
msg(
'listgrouprights-namespaceprotection-namespace' )->text()
191 $this->
msg(
'listgrouprights-namespaceprotection-restrictedto' )->text()
195 ksort( $namespaceProtection );
196 $validNamespaces = $this->nsInfo->getValidNamespaces();
197 foreach ( $namespaceProtection as $namespace => $rights ) {
198 if ( !in_array( $namespace, $validNamespaces ) ) {
203 $namespaceText = $this->
msg(
'blanknamespace' )->text();
205 $namespaceText = $this->languageConverter->convertNamespace( $namespace );
213 $linkRenderer->makeLink(
217 [
'namespace' => $namespace ]
223 if ( !is_array( $rights ) ) {
224 $rights = [ $rights ];
227 foreach ( $rights as $right ) {
229 Html::rawElement(
'li', [], $this->
msg(
230 'listgrouprights-right-display',
234 [
'class' =>
'mw-listgrouprights-right-name' ],
261 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
263 foreach ( $permissions as $permission ) {
265 if ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) {
266 $r[] = $this->
msg(
'listgrouprights-right-display',
268 '<span class="mw-listgrouprights-right-name">' . $permission .
'</span>'
272 foreach ( $revoke as $permission ) {
273 $r[] = $this->
msg(
'listgrouprights-right-revoked',
275 '<span class="mw-listgrouprights-right-name">' . $permission .
'</span>'
282 $allGroups = $this->userGroupManager->listAllGroups();
286 'removegroup' => $remove,
287 'addgroup-self' => $addSelf,
288 'removegroup-self' => $removeSelf
291 foreach ( $changeGroups as $messageKey => $changeGroup ) {
293 if ( $changeGroup ===
true ) {
296 $r[] = $this->
msg(
'listgrouprights-' . $messageKey .
'-all' )->escaped();
297 } elseif ( is_array( $changeGroup ) ) {
298 $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
299 if ( count( $changeGroup ) ) {
301 foreach ( $changeGroup as $group ) {
306 $r[] = $this->
msg(
'listgrouprights-' . $messageKey,
307 $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
315 return '<ul><li>' . implode(
"</li>\n<li>", $r ) .
'</li></ul>';
A class containing constants representing the names of configuration variables.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
This special page lists all defined user groups and the associated rights.
__construct(NamespaceInfo $nsInfo, UserGroupManager $userGroupManager, LanguageConverterFactory $languageConverterFactory, GroupPermissionsLookup $groupPermissionsLookup)
execute( $par)
Show the special page.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getContentLanguage()
Shortcut to get content language.
static getGroupPage( $group)
Gets the title of a page describing a particular user group.
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
static getRightDescription( $right)
Get the description of a given right.
static closeElement( $element)
Shortcut to close an XML element.
static openElement( $element, $attribs=null)
This opens an XML element.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
if(!isset( $args[0])) $lang