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