MediaWiki  master
SpecialListGrants.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Specials;
25 
28 use Sanitizer;
29 use SpecialPage;
30 
39  private $grantsLocalization;
40 
41  public function __construct( GrantsLocalization $grantsLocalization ) {
42  parent::__construct( 'Listgrants' );
43  $this->grantsLocalization = $grantsLocalization;
44  }
45 
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(
59  [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
60  '<tr>' .
61  \MediaWiki\Html\Html::element( 'th', [], $this->msg( 'listgrants-grant' )->text() ) .
62  \MediaWiki\Html\Html::element( 'th', [], $this->msg( 'listgrants-rights' )->text() ) .
63  '</tr>'
64  );
65 
66  $lang = $this->getLanguage();
67 
68  foreach (
69  $this->getConfig()->get( MainConfigNames::GrantPermissions ) as $grant => $rights
70  ) {
71  $descs = [];
72  $rights = array_filter( $rights ); // remove ones with 'false'
73  foreach ( $rights as $permission => $granted ) {
74  $descs[] = $this->msg(
75  'listgrouprights-right-display',
76  \User::getRightDescription( $permission ),
77  '<span class="mw-listgrants-right-name">' . $permission . '</span>'
78  )->parse();
79  }
80  if ( $descs === [] ) {
81  $grantCellHtml = '';
82  } else {
83  sort( $descs );
84  $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
85  }
86 
87  $id = Sanitizer::escapeIdForAttribute( $grant );
88  $out->addHTML( \MediaWiki\Html\Html::rawElement( 'tr', [ 'id' => $id ],
89  "<td>" .
90  $this->msg(
91  "listgrants-grant-display",
92  $this->grantsLocalization->getGrantDescription( $grant, $lang ),
93  "<span class='mw-listgrants-grant-name'>" . $id . "</span>"
94  )->parse() .
95  "</td>" .
96  "<td>" . $grantCellHtml . "</td>"
97  ) );
98  }
99 
100  $out->addHTML( \MediaWiki\Html\Html::closeElement( 'table' ) );
101  }
102 
103  protected function getGroupName() {
104  return 'users';
105  }
106 }
107 
111 class_alias( SpecialListGrants::class, 'SpecialListGrants' );
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:264
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:219
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:328
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:240
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 ...
This special page lists 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.
The MediaWiki class is the helper class for the index.php entry point.
Definition: MediaWiki.php:43
HTML sanitizer for MediaWiki.
Definition: Sanitizer.php:42
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
Definition: Sanitizer.php:947
Parent class for all special pages.
Definition: SpecialPage.php:45
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
static getRightDescription( $right)
Get the description of a given right.
Definition: User.php:3367
if(!isset( $args[0])) $lang