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
{
35 function __construct() {
36 parent
::__construct( 'Listgrouprights' );
40 * Show the special page
42 public function execute( $par ) {
43 global $wgImplicitGroups;
44 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
45 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
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' );
56 Xml
::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
58 Xml
::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
59 Xml
::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
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 )
73 foreach ( $allGroups as $group ) {
74 $permissions = isset( $wgGroupPermissions[$group] )
75 ?
$wgGroupPermissions[$group]
77 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
81 $msg = $this->msg( 'group-' . $groupname );
82 $groupnameLocalized = !$msg->isBlank() ?
$msg->text() : $groupname;
84 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
85 $grouppageLocalized = !$msg->isBlank() ?
87 MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
89 if ( $group == '*' ) {
90 // Do not make a link for the generic * group
91 $grouppage = htmlspecialchars( $groupnameLocalized );
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(),
110 array( 'group' => $group )
113 // No link to Special:listusers for other implicit groups as they are unlistable
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>
128 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
129 $addgroupsSelf, $removegroupsSelf ) .
134 $out->addHTML( Xml
::closeElement( 'table' ) );
135 $this->outputNamespaceProtectionInfo();
138 private function outputNamespaceProtectionInfo() {
139 global $wgNamespaceProtection, $wgParser, $wgContLang;
140 $out = $this->getOutput();
142 if ( count( $wgNamespaceProtection ) == 0 ) {
146 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
148 Html
::rawElement( 'h2', array(), Html
::element( 'span', array(
149 'class' => 'mw-headline',
150 'id' => $wgParser->guessSectionNameFromWikiText( $header )
152 Xml
::openElement( 'table', array( 'class' => 'wikitable' ) ) .
156 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
161 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
165 ksort( $wgNamespaceProtection );
166 foreach ( $wgNamespaceProtection as $namespace => $rights ) {
167 if ( !in_array( $namespace, MWNamespace
::getValidNamespaces() ) ) {
171 if ( $namespace == NS_MAIN
) {
172 $namespaceText = $this->msg( 'blanknamespace' )->text();
174 $namespaceText = $wgContLang->convertNamespace( $namespace );
178 Xml
::openElement( 'tr' ) .
183 SpecialPage
::getTitleFor( 'Allpages' ),
186 array( 'namespace' => $namespace )
189 Xml
::openElement( 'td' ) . Xml
::openElement( 'ul' )
192 if ( !is_array( $rights ) ) {
193 $rights = array( $rights );
196 foreach ( $rights as $right ) {
198 Html
::rawElement( 'li', array(), $this->msg(
199 'listgrouprights-right-display',
200 User
::getRightDescription( $right ),
203 array( 'class' => 'mw-listgrouprights-right-name' ),
211 Xml
::closeElement( 'ul' ) .
212 Xml
::closeElement( 'td' ) .
213 Xml
::closeElement( 'tr' )
216 $out->addHTML( Xml
::closeElement( 'table' ) );
220 * Create a user-readable list of permissions from the given array.
222 * @param array $permissions of permission => bool (from $wgGroupPermissions items)
223 * @param array $revoke of permission => bool (from $wgRevokePermissions items)
224 * @param array $add of groups this group is allowed to add or true
225 * @param array $remove of groups this group is allowed to remove or true
226 * @param array $addSelf of groups this group is allowed to add to self or true
227 * @param array $removeSelf of group this group is allowed to remove from self or true
228 * @return string List of all granted permissions, separated by comma separator
230 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
232 foreach ( $permissions as $permission => $granted ) {
233 //show as granted only if it isn't revoked to prevent duplicate display of permissions
234 if ( $granted && ( !isset( $revoke[$permission] ) ||
!$revoke[$permission] ) ) {
235 $description = $this->msg( 'listgrouprights-right-display',
236 User
::getRightDescription( $permission ),
237 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
242 foreach ( $revoke as $permission => $revoked ) {
244 $description = $this->msg( 'listgrouprights-right-revoked',
245 User
::getRightDescription( $permission ),
246 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
254 $lang = $this->getLanguage();
256 if ( $add === true ) {
257 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
258 } elseif ( is_array( $add ) && count( $add ) ) {
259 $add = array_values( array_unique( $add ) );
260 $r[] = $this->msg( 'listgrouprights-addgroup',
261 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
266 if ( $remove === true ) {
267 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
268 } elseif ( is_array( $remove ) && count( $remove ) ) {
269 $remove = array_values( array_unique( $remove ) );
270 $r[] = $this->msg( 'listgrouprights-removegroup',
271 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
276 if ( $addSelf === true ) {
277 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
278 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
279 $addSelf = array_values( array_unique( $addSelf ) );
280 $r[] = $this->msg( 'listgrouprights-addgroup-self',
281 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
286 if ( $removeSelf === true ) {
287 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
288 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
289 $removeSelf = array_values( array_unique( $removeSelf ) );
290 $r[] = $this->msg( 'listgrouprights-removegroup-self',
291 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
299 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
303 protected function getGroupName() {