Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / specials / SpecialListgrouprights.php
blob82a4f70f1daafd29135062e6898b4132e9659cbc
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 {
32 /**
33 * Constructor
35 function __construct() {
36 parent::__construct( 'Listgrouprights' );
39 /**
40 * Show the special page
42 public function execute( $par ) {
43 global $wgImplicitGroups;
44 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
45 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
47 $this->setHeaders();
48 $this->outputHeader();
50 $out = $this->getOutput();
51 $out->addModuleStyles( 'mediawiki.special' );
53 $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
55 $out->addHTML(
56 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
57 '<tr>' .
58 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
59 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
60 '</tr>'
63 $allGroups = array_unique( array_merge(
64 array_keys( $wgGroupPermissions ),
65 array_keys( $wgRevokePermissions ),
66 array_keys( $wgAddGroups ),
67 array_keys( $wgRemoveGroups ),
68 array_keys( $wgGroupsAddToSelf ),
69 array_keys( $wgGroupsRemoveFromSelf )
70 ) );
71 asort( $allGroups );
73 foreach ( $allGroups as $group ) {
74 $permissions = isset( $wgGroupPermissions[$group] )
75 ? $wgGroupPermissions[$group]
76 : array();
77 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
78 ? 'all'
79 : $group;
81 $msg = $this->msg( 'group-' . $groupname );
82 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
84 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
85 $grouppageLocalized = !$msg->isBlank() ?
86 $msg->text() :
87 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
89 if ( $group == '*' ) {
90 // Do not make a link for the generic * group
91 $grouppage = htmlspecialchars( $groupnameLocalized );
92 } else {
93 $grouppage = Linker::link(
94 Title::newFromText( $grouppageLocalized ),
95 htmlspecialchars( $groupnameLocalized )
99 if ( $group === 'user' ) {
100 // Link to Special:listusers for implicit group 'user'
101 $grouplink = '<br />' . Linker::linkKnown(
102 SpecialPage::getTitleFor( 'Listusers' ),
103 $this->msg( 'listgrouprights-members' )->escaped()
105 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
106 $grouplink = '<br />' . Linker::linkKnown(
107 SpecialPage::getTitleFor( 'Listusers' ),
108 $this->msg( 'listgrouprights-members' )->escaped(),
109 array(),
110 array( 'group' => $group )
112 } else {
113 // No link to Special:listusers for other implicit groups as they are unlistable
114 $grouplink = '';
117 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
118 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
119 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
120 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
121 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
123 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
124 $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
126 <td>$grouppage$grouplink</td>
127 <td>" .
128 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
129 $addgroupsSelf, $removegroupsSelf ) .
130 '</td>
132 ) );
134 $out->addHTML( Xml::closeElement( 'table' ) );
138 * Create a user-readable list of permissions from the given array.
140 * @param array $permissions of permission => bool (from $wgGroupPermissions items)
141 * @param array $revoke of permission => bool (from $wgRevokePermissions items)
142 * @param array $add of groups this group is allowed to add or true
143 * @param array $remove of groups this group is allowed to remove or true
144 * @param array $addSelf of groups this group is allowed to add to self or true
145 * @param array $removeSelf of group this group is allowed to remove from self or true
146 * @return string List of all granted permissions, separated by comma separator
148 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
149 $r = array();
150 foreach ( $permissions as $permission => $granted ) {
151 //show as granted only if it isn't revoked to prevent duplicate display of permissions
152 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
153 $description = $this->msg( 'listgrouprights-right-display',
154 User::getRightDescription( $permission ),
155 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
156 )->parse();
157 $r[] = $description;
160 foreach ( $revoke as $permission => $revoked ) {
161 if ( $revoked ) {
162 $description = $this->msg( 'listgrouprights-right-revoked',
163 User::getRightDescription( $permission ),
164 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
165 )->parse();
166 $r[] = $description;
170 sort( $r );
172 $lang = $this->getLanguage();
174 if ( $add === true ) {
175 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
176 } elseif ( is_array( $add ) && count( $add ) ) {
177 $add = array_values( array_unique( $add ) );
178 $r[] = $this->msg( 'listgrouprights-addgroup',
179 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
180 count( $add )
181 )->parse();
184 if ( $remove === true ) {
185 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
186 } elseif ( is_array( $remove ) && count( $remove ) ) {
187 $remove = array_values( array_unique( $remove ) );
188 $r[] = $this->msg( 'listgrouprights-removegroup',
189 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
190 count( $remove )
191 )->parse();
194 if ( $addSelf === true ) {
195 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
196 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
197 $addSelf = array_values( array_unique( $addSelf ) );
198 $r[] = $this->msg( 'listgrouprights-addgroup-self',
199 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
200 count( $addSelf )
201 )->parse();
204 if ( $removeSelf === true ) {
205 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
206 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
207 $removeSelf = array_values( array_unique( $removeSelf ) );
208 $r[] = $this->msg( 'listgrouprights-removegroup-self',
209 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
210 count( $removeSelf )
211 )->parse();
214 if ( empty( $r ) ) {
215 return '';
216 } else {
217 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
221 protected function getGroupName() {
222 return 'users';