Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / specials / SpecialListgrouprights.php
blob3309682a7821d44a30482a8ea9412e9e26b0e7cf
1 <?php
2 /**
3 * Implements Special:Listgrouprights
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * This special page lists all defined user groups and the associated rights.
26 * See also @ref $wgGroupPermissions.
28 * @ingroup SpecialPage
29 * @author Petr Kadlec <mormegil@centrum.cz>
31 class SpecialListGroupRights extends SpecialPage {
33 /**
34 * Constructor
36 function __construct() {
37 parent::__construct( 'Listgrouprights' );
40 /**
41 * Show the special page
43 public function execute( $par ) {
44 global $wgImplicitGroups;
45 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
46 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
48 $this->setHeaders();
49 $this->outputHeader();
51 $out = $this->getOutput();
52 $out->addModuleStyles( 'mediawiki.special' );
54 $out->addHTML(
55 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
56 '<tr>' .
57 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
58 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
59 '</tr>'
62 $allGroups = array_unique( array_merge(
63 array_keys( $wgGroupPermissions ),
64 array_keys( $wgRevokePermissions ),
65 array_keys( $wgAddGroups ),
66 array_keys( $wgRemoveGroups ),
67 array_keys( $wgGroupsAddToSelf ),
68 array_keys( $wgGroupsRemoveFromSelf )
69 ) );
70 asort( $allGroups );
72 foreach ( $allGroups as $group ) {
73 $permissions = isset( $wgGroupPermissions[$group] )
74 ? $wgGroupPermissions[$group]
75 : array();
76 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
77 ? 'all'
78 : $group;
80 $msg = $this->msg( 'group-' . $groupname );
81 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
83 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
84 $grouppageLocalized = !$msg->isBlank() ?
85 $msg->text() :
86 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
88 if ( $group == '*' ) {
89 // Do not make a link for the generic * group
90 $grouppage = htmlspecialchars( $groupnameLocalized );
91 } else {
92 $grouppage = Linker::link(
93 Title::newFromText( $grouppageLocalized ),
94 htmlspecialchars( $groupnameLocalized )
98 if ( $group === 'user' ) {
99 // Link to Special:listusers for implicit group 'user'
100 $grouplink = '<br />' . Linker::linkKnown(
101 SpecialPage::getTitleFor( 'Listusers' ),
102 $this->msg( 'listgrouprights-members' )->escaped()
104 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
105 $grouplink = '<br />' . Linker::linkKnown(
106 SpecialPage::getTitleFor( 'Listusers' ),
107 $this->msg( 'listgrouprights-members' )->escaped(),
108 array(),
109 array( 'group' => $group )
111 } else {
112 // No link to Special:listusers for other implicit groups as they are unlistable
113 $grouplink = '';
116 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
117 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
118 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
119 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
120 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
122 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
123 $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
125 <td>$grouppage$grouplink</td>
126 <td>" .
127 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
128 $addgroupsSelf, $removegroupsSelf ) .
129 '</td>
131 ) );
133 $out->addHTML(
134 Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
136 $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
140 * Create a user-readable list of permissions from the given array.
142 * @param array $permissions of permission => bool (from $wgGroupPermissions items)
143 * @param array $revoke of permission => bool (from $wgRevokePermissions items)
144 * @param array $add of groups this group is allowed to add or true
145 * @param array $remove of groups this group is allowed to remove or true
146 * @param array $addSelf of groups this group is allowed to add to self or true
147 * @param array $removeSelf of group this group is allowed to remove from self or true
148 * @return string List of all granted permissions, separated by comma separator
150 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
151 $r = array();
152 foreach ( $permissions as $permission => $granted ) {
153 //show as granted only if it isn't revoked to prevent duplicate display of permissions
154 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
155 $description = $this->msg( 'listgrouprights-right-display',
156 User::getRightDescription( $permission ),
157 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
158 )->parse();
159 $r[] = $description;
162 foreach ( $revoke as $permission => $revoked ) {
163 if ( $revoked ) {
164 $description = $this->msg( 'listgrouprights-right-revoked',
165 User::getRightDescription( $permission ),
166 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
167 )->parse();
168 $r[] = $description;
171 sort( $r );
172 $lang = $this->getLanguage();
173 if ( $add === true ) {
174 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
175 } elseif ( is_array( $add ) && count( $add ) ) {
176 $add = array_values( array_unique( $add ) );
177 $r[] = $this->msg( 'listgrouprights-addgroup',
178 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
179 count( $add )
180 )->parse();
182 if ( $remove === true ) {
183 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
184 } elseif ( is_array( $remove ) && count( $remove ) ) {
185 $remove = array_values( array_unique( $remove ) );
186 $r[] = $this->msg( 'listgrouprights-removegroup',
187 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
188 count( $remove )
189 )->parse();
191 if ( $addSelf === true ) {
192 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
193 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
194 $addSelf = array_values( array_unique( $addSelf ) );
195 $r[] = $this->msg( 'listgrouprights-addgroup-self',
196 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
197 count( $addSelf )
198 )->parse();
200 if ( $removeSelf === true ) {
201 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
202 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
203 $removeSelf = array_values( array_unique( $removeSelf ) );
204 $r[] = $this->msg( 'listgrouprights-removegroup-self',
205 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
206 count( $removeSelf )
207 )->parse();
209 if ( empty( $r ) ) {
210 return '';
211 } else {
212 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
216 protected function getGroupName() {
217 return 'users';