MediaWiki master
SpecialListGrants.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
28
38 private GrantsLocalization $grantsLocalization;
39
40 public function __construct( GrantsLocalization $grantsLocalization ) {
41 parent::__construct( 'Listgrants' );
42 $this->grantsLocalization = $grantsLocalization;
43 }
44
49 public function execute( $par ) {
50 $this->setHeaders();
51 $this->outputHeader();
52
53 $out = $this->getOutput();
54 $out->addModuleStyles( 'mediawiki.special' );
55
56 $out->addHTML(
57 Html::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
58 '<tr>' .
59 Html::element( 'th', [], $this->msg( 'listgrants-grant' )->text() ) .
60 Html::element( 'th', [], $this->msg( 'listgrants-rights' )->text() ) .
61 '</tr>'
62 );
63
64 $lang = $this->getLanguage();
65
66 foreach (
67 $this->getConfig()->get( MainConfigNames::GrantPermissions ) as $grant => $rights
68 ) {
69 $descs = [];
70 $rights = array_filter( $rights ); // remove ones with 'false'
71 foreach ( $rights as $permission => $granted ) {
72 $descs[] = $this->msg( 'listgrouprights-right-display' )
73 ->params( User::getRightDescription( $permission ) )
74 ->rawParams( Html::element(
75 'span',
76 [ 'class' => 'mw-listgrants-right-name' ],
77 $permission
78 ) )
79 ->parse();
80 }
81 if ( $descs === [] ) {
82 $grantCellHtml = '';
83 } else {
84 sort( $descs );
85 $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
86 }
87
88 $out->addHTML( Html::rawElement( 'tr', [ 'id' => $grant ],
89 "<td>" .
90 $this->msg( 'listgrants-grant-display' )
91 ->params( $this->grantsLocalization->getGrantDescription( $grant, $lang ) )
92 ->rawParams( Html::element(
93 'span',
94 [ 'class' => 'mw-listgrants-grant-name' ],
95 $grant
96 ) )
97 ->parse() .
98 "</td>" .
99 "<td>" . $grantCellHtml . "</td>"
100 ) );
101 }
102
103 $out->addHTML( Html::closeElement( 'table' ) );
104 }
105
106 protected function getGroupName() {
107 return 'users';
108 }
109}
110
112class_alias( SpecialListGrants::class, 'SpecialListGrants' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
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.
internal since 1.36
Definition User.php:93
element(SerializerNode $parent, SerializerNode $node, $contents)