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
21 * @ingroup SpecialPage
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
{
36 function __construct() {
37 parent
::__construct( 'Listgrouprights' );
41 * Show the special page
43 public function execute( $par ) {
44 global $wgImplicitGroups;
45 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
46 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
49 $this->outputHeader();
51 $out = $this->getOutput();
52 $out->addModuleStyles( 'mediawiki.special' );
55 Xml
::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
57 Xml
::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
58 Xml
::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
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 )
72 foreach ( $allGroups as $group ) {
73 $permissions = isset( $wgGroupPermissions[$group] )
74 ?
$wgGroupPermissions[$group]
76 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
80 $msg = $this->msg( 'group-' . $groupname );
81 $groupnameLocalized = !$msg->isBlank() ?
$msg->text() : $groupname;
83 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
84 $grouppageLocalized = !$msg->isBlank() ?
86 MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
89 // Do not make a link for the generic * group
90 $grouppage = htmlspecialchars( $groupnameLocalized );
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(),
109 array( 'group' => $group )
112 // No link to Special:listusers for other implicit groups as they are unlistable
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>
127 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
128 $addgroupsSelf, $removegroupsSelf ) .
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 $permissions Array of permission => bool (from $wgGroupPermissions items)
143 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
144 * @param $add Array of groups this group is allowed to add or true
145 * @param $remove Array of groups this group is allowed to remove or true
146 * @param $addSelf Array of groups this group is allowed to add to self or true
147 * @param $removeSelf Array 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 ) {
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>'
162 foreach( $revoke as $permission => $revoked ) {
164 $description = $this->msg( 'listgrouprights-right-revoked',
165 User
::getRightDescription( $permission ),
166 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
172 $lang = $this->getLanguage();
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 ) ),
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', array( 'parseinline' ),
187 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
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', array( 'parseinline' ),
196 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
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', array( 'parseinline' ),
205 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
212 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';