SpecialAutoblockList.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Implements Special:AutoblockList
  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. use MediaWiki\MediaWikiServices;
  24. /**
  25. * A special page that lists autoblocks
  26. *
  27. * @since 1.29
  28. * @ingroup SpecialPage
  29. */
  30. class SpecialAutoblockList extends SpecialPage {
  31. function __construct() {
  32. parent::__construct( 'AutoblockList' );
  33. }
  34. /**
  35. * @param string|null $par Title fragment
  36. */
  37. public function execute( $par ) {
  38. $this->setHeaders();
  39. $this->outputHeader();
  40. $out = $this->getOutput();
  41. $out->setPageTitle( $this->msg( 'autoblocklist' ) );
  42. $this->addHelpLink( 'Autoblock' );
  43. $out->addModuleStyles( [ 'mediawiki.special' ] );
  44. # setup BlockListPager here to get the actual default Limit
  45. $pager = $this->getBlockListPager();
  46. # Just show the block list
  47. $fields = [
  48. 'Limit' => [
  49. 'type' => 'limitselect',
  50. 'label-message' => 'table_pager_limit_label',
  51. 'options' => $pager->getLimitSelectList(),
  52. 'name' => 'limit',
  53. 'default' => $pager->getLimit(),
  54. ]
  55. ];
  56. $context = new DerivativeContext( $this->getContext() );
  57. $context->setTitle( $this->getPageTitle() ); // Remove subpage
  58. $form = HTMLForm::factory( 'ooui', $fields, $context );
  59. $form->setMethod( 'get' )
  60. ->setFormIdentifier( 'blocklist' )
  61. ->setWrapperLegendMsg( 'autoblocklist-legend' )
  62. ->setSubmitTextMsg( 'autoblocklist-submit' )
  63. ->prepareForm()
  64. ->displayForm( false );
  65. $this->showTotal( $pager );
  66. $this->showList( $pager );
  67. }
  68. /**
  69. * Setup a new BlockListPager instance.
  70. * @return BlockListPager
  71. */
  72. protected function getBlockListPager() {
  73. $conds = [
  74. 'ipb_parent_block_id IS NOT NULL'
  75. ];
  76. # Is the user allowed to see hidden blocks?
  77. if ( !MediaWikiServices::getInstance()
  78. ->getPermissionManager()
  79. ->userHasRight( $this->getUser(), 'hideuser' )
  80. ) {
  81. $conds['ipb_deleted'] = 0;
  82. }
  83. return new BlockListPager( $this, $conds );
  84. }
  85. /**
  86. * Show total number of autoblocks on top of the table
  87. *
  88. * @param BlockListPager $pager The BlockListPager instance for this page
  89. */
  90. protected function showTotal( BlockListPager $pager ) {
  91. $out = $this->getOutput();
  92. $out->addHTML(
  93. Html::rawElement( 'div', [ 'style' => 'font-weight: bold;' ],
  94. $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() )
  95. . "\n"
  96. );
  97. }
  98. /**
  99. * Show the list of blocked accounts matching the actual filter.
  100. * @param BlockListPager $pager The BlockListPager instance for this page
  101. */
  102. protected function showList( BlockListPager $pager ) {
  103. $out = $this->getOutput();
  104. # Check for other blocks, i.e. global/tor blocks
  105. $otherAutoblockLink = [];
  106. Hooks::run( 'OtherAutoblockLogLink', [ &$otherAutoblockLink ] );
  107. # Show additional header for the local block only when other blocks exists.
  108. # Not necessary in a standard installation without such extensions enabled
  109. if ( count( $otherAutoblockLink ) ) {
  110. $out->addHTML(
  111. Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
  112. $pager->getNumRows() )->parse() )
  113. . "\n"
  114. );
  115. }
  116. if ( $pager->getNumRows() ) {
  117. $out->addParserOutputContent( $pager->getFullOutput() );
  118. } else {
  119. $out->addWikiMsg( 'autoblocklist-empty' );
  120. }
  121. if ( count( $otherAutoblockLink ) ) {
  122. $out->addHTML(
  123. Html::rawElement(
  124. 'h2',
  125. [],
  126. $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
  127. ) . "\n"
  128. );
  129. $list = '';
  130. foreach ( $otherAutoblockLink as $link ) {
  131. $list .= Html::rawElement( 'li', [], $link ) . "\n";
  132. }
  133. $out->addHTML(
  134. Html::rawElement(
  135. 'ul',
  136. [ 'class' => 'mw-autoblocklist-otherblocks' ],
  137. $list
  138. ) . "\n"
  139. );
  140. }
  141. }
  142. protected function getGroupName() {
  143. return 'users';
  144. }
  145. }