MediaWiki master
SpecialListGrants.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
14
24 private GrantsLocalization $grantsLocalization;
25
26 public function __construct( GrantsLocalization $grantsLocalization ) {
27 parent::__construct( 'Listgrants' );
28 $this->grantsLocalization = $grantsLocalization;
29 }
30
35 public function execute( $par ) {
36 $this->setHeaders();
37 $this->outputHeader();
38
39 $out = $this->getOutput();
40 $out->addModuleStyles( 'mediawiki.special' );
41
42 $out->addHTML(
43 Html::openElement( 'table', [ 'class' => [ 'wikitable', 'mw-listgrouprights-table' ] ] ) .
44 '<tr>' .
45 Html::element( 'th', [], $this->msg( 'listgrants-grant' )->text() ) .
46 Html::element( 'th', [], $this->msg( 'listgrants-rights' )->text() ) .
47 '</tr>'
48 );
49
50 $lang = $this->getLanguage();
51
52 foreach (
53 $this->getConfig()->get( MainConfigNames::GrantPermissions ) as $grant => $rights
54 ) {
55 $descs = [];
56 $rights = array_filter( $rights ); // remove ones with 'false'
57 foreach ( $rights as $permission => $granted ) {
58 $descs[] = $this->msg( 'listgrouprights-right-display' )
59 ->params( User::getRightDescription( $permission ) )
60 ->rawParams( Html::element(
61 'span',
62 [ 'class' => 'mw-listgrants-right-name' ],
63 $permission
64 ) )
65 ->parse();
66 }
67 if ( $descs === [] ) {
68 $grantCellHtml = '';
69 } else {
70 sort( $descs );
71 $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
72 }
73
74 $out->addHTML( Html::rawElement( 'tr', [ 'id' => $grant ],
75 "<td>" .
76 $this->msg( 'listgrants-grant-display' )
77 ->params( $this->grantsLocalization->getGrantDescription( $grant, $lang ) )
78 ->rawParams( Html::element(
79 'span',
80 [ 'class' => 'mw-listgrants-grant-name' ],
81 $grant
82 ) )
83 ->parse() .
84 "</td>" .
85 "<td>" . $grantCellHtml . "</td>"
86 ) );
87 }
88
89 $out->addHTML( Html::closeElement( 'table' ) );
90 }
91
93 protected function getGroupName() {
94 return 'users';
95 }
96}
97
99class_alias( SpecialListGrants::class, 'SpecialListGrants' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
A class containing constants representing the names of configuration variables.
const GrantPermissions
Name constant for the GrantPermissions setting, for use with Config::get()
This separate service is needed because the ::getGrantsLink method requires a LinkRenderer and if we ...
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
List all defined rights grants and the associated rights.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(GrantsLocalization $grantsLocalization)
execute( $par)
Show the special page.
User class for the MediaWiki software.
Definition User.php:130
element(SerializerNode $parent, SerializerNode $node, $contents)