Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialListGrants
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
20
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
24namespace MediaWiki\Specials;
25
26use MediaWiki\Html\Html;
27use MediaWiki\MainConfigNames;
28use MediaWiki\Permissions\GrantsLocalization;
29use MediaWiki\SpecialPage\SpecialPage;
30use MediaWiki\User\User;
31
32/**
33 * This special page lists all defined rights grants and the associated rights.
34 * See also @ref $wgGrantPermissions and @ref $wgGrantPermissionGroups.
35 *
36 * @ingroup SpecialPage
37 */
38class SpecialListGrants extends SpecialPage {
39    private GrantsLocalization $grantsLocalization;
40
41    public function __construct( GrantsLocalization $grantsLocalization ) {
42        parent::__construct( 'Listgrants' );
43        $this->grantsLocalization = $grantsLocalization;
44    }
45
46    /**
47     * Show the special page
48     * @param string|null $par
49     */
50    public function execute( $par ) {
51        $this->setHeaders();
52        $this->outputHeader();
53
54        $out = $this->getOutput();
55        $out->addModuleStyles( 'mediawiki.special' );
56
57        $out->addHTML(
58            Html::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
59                '<tr>' .
60                Html::element( 'th', [], $this->msg( 'listgrants-grant' )->text() ) .
61                Html::element( 'th', [], $this->msg( 'listgrants-rights' )->text() ) .
62                '</tr>'
63        );
64
65        $lang = $this->getLanguage();
66
67        foreach (
68            $this->getConfig()->get( MainConfigNames::GrantPermissions ) as $grant => $rights
69        ) {
70            $descs = [];
71            $rights = array_filter( $rights ); // remove ones with 'false'
72            foreach ( $rights as $permission => $granted ) {
73                $descs[] = $this->msg( 'listgrouprights-right-display' )
74                    ->params( User::getRightDescription( $permission ) )
75                    ->rawParams( Html::element(
76                        'span',
77                        [ 'class' => 'mw-listgrants-right-name' ],
78                        $permission
79                    ) )
80                    ->parse();
81            }
82            if ( $descs === [] ) {
83                $grantCellHtml = '';
84            } else {
85                sort( $descs );
86                $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
87            }
88
89            $out->addHTML( Html::rawElement( 'tr', [ 'id' => $grant ],
90                                                             "<td>" .
91                $this->msg( 'listgrants-grant-display' )
92                    ->params( $this->grantsLocalization->getGrantDescription( $grant, $lang ) )
93                    ->rawParams( Html::element(
94                        'span',
95                        [ 'class' => 'mw-listgrants-grant-name' ],
96                        $grant
97                    ) )
98                    ->parse() .
99                "</td>" .
100                "<td>" . $grantCellHtml . "</td>"
101            ) );
102        }
103
104        $out->addHTML( Html::closeElement( 'table' ) );
105    }
106
107    protected function getGroupName() {
108        return 'users';
109    }
110}
111
112/** @deprecated class alias since 1.41 */
113class_alias( SpecialListGrants::class, 'SpecialListGrants' );