MediaWiki  master
SpecialListGrants.php
Go to the documentation of this file.
1 <?php
26 
36 
38  parent::__construct( 'Listgrants' );
39  $this->grantsLocalization = $grantsLocalization;
40  }
41 
46  public function execute( $par ) {
47  $this->setHeaders();
48  $this->outputHeader();
49 
50  $out = $this->getOutput();
51  $out->addModuleStyles( 'mediawiki.special' );
52 
53  $out->addHTML(
54  \Html::openElement( 'table',
55  [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
56  '<tr>' .
57  \Html::element( 'th', [], $this->msg( 'listgrants-grant' )->text() ) .
58  \Html::element( 'th', [], $this->msg( 'listgrants-rights' )->text() ) .
59  '</tr>'
60  );
61 
62  $lang = $this->getLanguage();
63 
64  foreach (
65  $this->getConfig()->get( MainConfigNames::GrantPermissions ) as $grant => $rights
66  ) {
67  $descs = [];
68  $rights = array_filter( $rights ); // remove ones with 'false'
69  foreach ( $rights as $permission => $granted ) {
70  $descs[] = $this->msg(
71  'listgrouprights-right-display',
72  \User::getRightDescription( $permission ),
73  '<span class="mw-listgrants-right-name">' . $permission . '</span>'
74  )->parse();
75  }
76  if ( $descs === [] ) {
77  $grantCellHtml = '';
78  } else {
79  sort( $descs );
80  $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
81  }
82 
83  $id = Sanitizer::escapeIdForAttribute( $grant );
84  $out->addHTML( \Html::rawElement( 'tr', [ 'id' => $id ],
85  "<td>" .
86  $this->msg(
87  "listgrants-grant-display",
88  $this->grantsLocalization->getGrantDescription( $grant, $lang ),
89  "<span class='mw-listgrants-grant-name'>" . $id . "</span>"
90  )->parse() .
91  "</td>" .
92  "<td>" . $grantCellHtml . "</td>"
93  ) );
94  }
95 
96  $out->addHTML( \Html::closeElement( 'table' ) );
97  }
98 
99  protected function getGroupName() {
100  return 'users';
101  }
102 }
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:256
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:320
A class containing constants representing the names of configuration variables.
This separate service is needed because the ::getGrantsLink method requires a LinkRenderer and if we ...
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:946
This special page lists all defined rights grants and the associated rights.
GrantsLocalization $grantsLocalization
__construct(GrantsLocalization $grantsLocalization)
execute( $par)
Show the special page.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
Definition: SpecialPage.php:44
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:3588
if(!isset( $args[0])) $lang