SpecialListGrants.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  24. * This special page lists all defined rights grants and the associated rights.
  25. * See also @ref $wgGrantPermissions and @ref $wgGrantPermissionGroups.
  26. *
  27. * @ingroup SpecialPage
  28. */
  29. class SpecialListGrants extends SpecialPage {
  30. function __construct() {
  31. parent::__construct( 'Listgrants' );
  32. }
  33. /**
  34. * Show the special page
  35. * @param string|null $par
  36. */
  37. public function execute( $par ) {
  38. $this->setHeaders();
  39. $this->outputHeader();
  40. $out = $this->getOutput();
  41. $out->addModuleStyles( 'mediawiki.special' );
  42. $out->addHTML(
  43. \Html::openElement( 'table',
  44. [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
  45. '<tr>' .
  46. \Html::element( 'th', null, $this->msg( 'listgrants-grant' )->text() ) .
  47. \Html::element( 'th', null, $this->msg( 'listgrants-rights' )->text() ) .
  48. '</tr>'
  49. );
  50. foreach ( $this->getConfig()->get( 'GrantPermissions' ) as $grant => $rights ) {
  51. $descs = [];
  52. $rights = array_filter( $rights ); // remove ones with 'false'
  53. foreach ( $rights as $permission => $granted ) {
  54. $descs[] = $this->msg(
  55. 'listgrouprights-right-display',
  56. \User::getRightDescription( $permission ),
  57. '<span class="mw-listgrants-right-name">' . $permission . '</span>'
  58. )->parse();
  59. }
  60. if ( $descs === [] ) {
  61. $grantCellHtml = '';
  62. } else {
  63. sort( $descs );
  64. $grantCellHtml = '<ul><li>' . implode( "</li>\n<li>", $descs ) . '</li></ul>';
  65. }
  66. $id = Sanitizer::escapeIdForAttribute( $grant );
  67. $out->addHTML( \Html::rawElement( 'tr', [ 'id' => $id ],
  68. "<td>" .
  69. $this->msg(
  70. "listgrants-grant-display",
  71. \User::getGrantName( $grant ),
  72. "<span class='mw-listgrants-grant-name'>" . $id . "</span>"
  73. )->parse() .
  74. "</td>" .
  75. "<td>" . $grantCellHtml . "</td>"
  76. ) );
  77. }
  78. $out->addHTML( \Html::closeElement( 'table' ) );
  79. }
  80. protected function getGroupName() {
  81. return 'users';
  82. }
  83. }