]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListgrants.php
MediaWiki 1.30.2 renames
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListgrants.php
1 <?php
2 /**
3  * Implements Special:Listgrants
4  *
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.
9  *
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.
14  *
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
19  *
20  * @file
21  * @ingroup SpecialPage
22  */
23
24 /**
25  * This special page lists all defined rights grants and the associated rights.
26  * See also @ref $wgGrantPermissions and @ref $wgGrantPermissionGroups.
27  *
28  * @ingroup SpecialPage
29  */
30 class SpecialListGrants extends SpecialPage {
31         function __construct() {
32                 parent::__construct( 'Listgrants' );
33         }
34
35         /**
36          * Show the special page
37          * @param string|null $par
38          */
39         public function execute( $par ) {
40                 $this->setHeaders();
41                 $this->outputHeader();
42
43                 $out = $this->getOutput();
44                 $out->addModuleStyles( 'mediawiki.special' );
45
46                 $out->addHTML(
47                         \Html::openElement( 'table',
48                                 [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
49                                 '<tr>' .
50                                 \Html::element( 'th', null, $this->msg( 'listgrants-grant' )->text() ) .
51                                 \Html::element( 'th', null, $this->msg( 'listgrants-rights' )->text() ) .
52                                 '</tr>'
53                 );
54
55                 foreach ( $this->getConfig()->get( 'GrantPermissions' ) as $grant => $rights ) {
56                         $descs = [];
57                         $rights = array_filter( $rights ); // remove ones with 'false'
58                         foreach ( $rights as $permission => $granted ) {
59                                 $descs[] = $this->msg(
60                                         'listgrouprights-right-display',
61                                         \User::getRightDescription( $permission ),
62                                         '<span class="mw-listgrants-right-name">' . $permission . '</span>'
63                                 )->parse();
64                         }
65                         if ( !count( $descs ) ) {
66                                 $grantCellHtml = '';
67                         } else {
68                                 sort( $descs );
69                                 $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
70                         }
71
72                         $id = Sanitizer::escapeIdForAttribute( $grant );
73                         $out->addHTML( \Html::rawElement( 'tr', [ 'id' => $id ],
74                                 "<td>" .
75                                 $this->msg(
76                                         "listgrants-grant-display",
77                                         \User::getGrantName( $grant ),
78                                         "<span class='mw-listgrants-grant-name'>" . $id . "</span>"
79                                 )->parse() .
80                                 "</td>" .
81                                 "<td>" . $grantCellHtml . "</td>"
82                         ) );
83                 }
84
85                 $out->addHTML( \Html::closeElement( 'table' ) );
86         }
87
88         protected function getGroupName() {
89                 return 'users';
90         }
91 }