411e3152174fe0b632c2e3fc1de84f32ef437f2f
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * This special page lists all defined user groups and the associated rights.
22 * See also @ref $wgGroupPermissions.
24 * @ingroup SpecialPage
25 * @author Petr Kadlec <mormegil@centrum.cz>
27 class SpecialListGroupRights
extends SpecialPage
{
34 function __construct() {
36 parent
::__construct( 'Listgrouprights' );
37 $this->skin
= $wgUser->getSkin();
41 * Show the special page
43 public function execute( $par ) {
44 global $wgOut, $wgImplicitGroups;
45 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
46 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
49 $this->outputHeader();
52 Xml
::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
54 Xml
::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
55 Xml
::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
59 foreach( $wgGroupPermissions as $group => $permissions ) {
60 $groupname = ( $group == '*' ) ?
'all' : $group; // Replace * with a more descriptive groupname
62 $msg = wfMsg( 'group-' . $groupname );
63 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
64 $groupnameLocalized = $groupname;
66 $groupnameLocalized = $msg;
69 $msg = wfMsgForContent( 'grouppage-' . $groupname );
70 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
71 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
73 $grouppageLocalized = $msg;
77 // Do not make a link for the generic * group
78 $grouppage = htmlspecialchars( $groupnameLocalized );
80 $grouppage = $this->skin
->link(
81 Title
::newFromText( $grouppageLocalized ),
82 htmlspecialchars( $groupnameLocalized )
86 if ( $group === 'user' ) {
87 // Link to Special:listusers for implicit group 'user'
88 $grouplink = '<br />' . $this->skin
->link(
89 SpecialPage
::getTitleFor( 'Listusers' ),
90 wfMsgHtml( 'listgrouprights-members' ),
93 array( 'known', 'noclasses' )
95 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
96 $grouplink = '<br />' . $this->skin
->link(
97 SpecialPage
::getTitleFor( 'Listusers' ),
98 wfMsgHtml( 'listgrouprights-members' ),
100 array( 'group' => $group ),
101 array( 'known', 'noclasses' )
104 // No link to Special:listusers for other implicit groups as they are unlistable
108 $revoke = isset( $wgRevokePermissions[$group] ) ?
$wgRevokePermissions[$group] : array();
109 $addgroups = isset( $wgAddGroups[$group] ) ?
$wgAddGroups[$group] : array();
110 $removegroups = isset( $wgRemoveGroups[$group] ) ?
$wgRemoveGroups[$group] : array();
111 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ?
$wgGroupsAddToSelf[$group] : array();
112 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ?
$wgGroupsRemoveFromSelf[$group] : array();
114 $id = $group == '*' ?
false : Sanitizer
::escapeId( $group );
115 $wgOut->addHTML( Html
::rawElement( 'tr', array( 'id' => $id ),
117 <td>$grouppage$grouplink</td>
119 self
::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
125 Xml
::closeElement( 'table' ) . "\n<br /><hr />\n"
127 $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
131 * Create a user-readable list of permissions from the given array.
133 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
134 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
135 * @param $add Array of groups this group is allowed to add or true
136 * @param $remove Array of groups this group is allowed to remove or true
137 * @param $addSelf Array of groups this group is allowed to add to self or true
138 * @param $removeSelf Array of group this group is allowed to remove from self or true
139 * @return string List of all granted permissions, separated by comma separator
141 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
145 foreach( $permissions as $permission => $granted ) {
146 //show as granted only if it isn't revoked to prevent duplicate display of permissions
147 if( $granted && ( !isset( $revoke[$permission] ) ||
!$revoke[$permission] ) ) {
148 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
149 User
::getRightDescription( $permission ),
150 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
155 foreach( $revoke as $permission => $revoked ) {
157 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
158 User
::getRightDescription( $permission ),
159 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
166 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
167 } else if( is_array( $add ) && count( $add ) ) {
168 $add = array_values( array_unique( $add ) );
169 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
171 if( $remove === true ){
172 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
173 } else if( is_array( $remove ) && count( $remove ) ) {
174 $remove = array_values( array_unique( $remove ) );
175 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
177 if( $addSelf === true ){
178 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
179 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
180 $addSelf = array_values( array_unique( $addSelf ) );
181 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
183 if( $removeSelf === true ){
184 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
185 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
186 $removeSelf = array_values( array_unique( $removeSelf ) );
187 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
192 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';