Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 85
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialAutoblockList
0.00% covered (danger)
0.00%
0 / 84
0.00% covered (danger)
0.00%
0 / 5
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
2
 getBlockListPager
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
6
 showList
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
30
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Specials;
22
23use MediaWiki\Block\BlockActionInfo;
24use MediaWiki\Block\BlockRestrictionStore;
25use MediaWiki\Block\BlockUtils;
26use MediaWiki\Block\HideUserUtils;
27use MediaWiki\Cache\LinkBatchFactory;
28use MediaWiki\CommentFormatter\RowCommentFormatter;
29use MediaWiki\CommentStore\CommentStore;
30use MediaWiki\Html\Html;
31use MediaWiki\HTMLForm\HTMLForm;
32use MediaWiki\Pager\BlockListPager;
33use MediaWiki\SpecialPage\SpecialPage;
34use Wikimedia\Rdbms\IConnectionProvider;
35
36/**
37 * List of autoblocks
38 *
39 * @since 1.29
40 * @ingroup SpecialPage
41 */
42class SpecialAutoblockList extends SpecialPage {
43
44    private LinkBatchFactory $linkBatchFactory;
45    private BlockRestrictionStore $blockRestrictionStore;
46    private IConnectionProvider $dbProvider;
47    private CommentStore $commentStore;
48    private BlockUtils $blockUtils;
49    private HideUserUtils $hideUserUtils;
50    private BlockActionInfo $blockActionInfo;
51    private RowCommentFormatter $rowCommentFormatter;
52
53    /**
54     * @param LinkBatchFactory $linkBatchFactory
55     * @param BlockRestrictionStore $blockRestrictionStore
56     * @param IConnectionProvider $dbProvider
57     * @param CommentStore $commentStore
58     * @param BlockUtils $blockUtils
59     * @param HideUserUtils $hideUserUtils
60     * @param BlockActionInfo $blockActionInfo
61     * @param RowCommentFormatter $rowCommentFormatter
62     */
63    public function __construct(
64        LinkBatchFactory $linkBatchFactory,
65        BlockRestrictionStore $blockRestrictionStore,
66        IConnectionProvider $dbProvider,
67        CommentStore $commentStore,
68        BlockUtils $blockUtils,
69        HideUserUtils $hideUserUtils,
70        BlockActionInfo $blockActionInfo,
71        RowCommentFormatter $rowCommentFormatter
72    ) {
73        parent::__construct( 'AutoblockList' );
74
75        $this->linkBatchFactory = $linkBatchFactory;
76        $this->blockRestrictionStore = $blockRestrictionStore;
77        $this->dbProvider = $dbProvider;
78        $this->commentStore = $commentStore;
79        $this->blockUtils = $blockUtils;
80        $this->hideUserUtils = $hideUserUtils;
81        $this->blockActionInfo = $blockActionInfo;
82        $this->rowCommentFormatter = $rowCommentFormatter;
83    }
84
85    /**
86     * @param string|null $par Title fragment
87     */
88    public function execute( $par ) {
89        $this->setHeaders();
90        $this->outputHeader();
91        $out = $this->getOutput();
92        $out->setPageTitleMsg( $this->msg( 'autoblocklist' ) );
93        $this->addHelpLink( 'Autoblock' );
94        $out->addModuleStyles( [ 'mediawiki.special' ] );
95
96        # setup BlockListPager here to get the actual default Limit
97        $pager = $this->getBlockListPager();
98
99        # Just show the block list
100        $fields = [
101            'Limit' => [
102                'type' => 'limitselect',
103                'label-message' => 'table_pager_limit_label',
104                'options' => $pager->getLimitSelectList(),
105                'name' => 'limit',
106                'default' => $pager->getLimit(),
107            ]
108        ];
109
110        $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
111        $form->setMethod( 'get' )
112            ->setTitle( $this->getPageTitle() ) // Remove subpage
113            ->setFormIdentifier( 'blocklist' )
114            ->setWrapperLegendMsg( 'autoblocklist-legend' )
115            ->setSubmitTextMsg( 'autoblocklist-submit' )
116            ->prepareForm()
117            ->displayForm( false );
118
119        $this->showList( $pager );
120    }
121
122    /**
123     * Setup a new BlockListPager instance.
124     * @return BlockListPager
125     */
126    protected function getBlockListPager() {
127        $conds = [
128            $this->dbProvider->getReplicaDatabase()->expr( 'bl_parent_block_id', '!=', null ),
129        ];
130        # Is the user allowed to see hidden blocks?
131        if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
132            $conds['bl_deleted'] = 0;
133        }
134
135        return new BlockListPager(
136            $this->getContext(),
137            $this->blockActionInfo,
138            $this->blockRestrictionStore,
139            $this->blockUtils,
140            $this->hideUserUtils,
141            $this->commentStore,
142            $this->linkBatchFactory,
143            $this->getLinkRenderer(),
144            $this->dbProvider,
145            $this->rowCommentFormatter,
146            $this->getSpecialPageFactory(),
147            $conds
148        );
149    }
150
151    /**
152     * Show the list of blocked accounts matching the actual filter.
153     * @param BlockListPager $pager The BlockListPager instance for this page
154     */
155    protected function showList( BlockListPager $pager ) {
156        $out = $this->getOutput();
157
158        # Check for other blocks, i.e. global/tor blocks
159        $otherAutoblockLink = [];
160        $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
161
162        # Show additional header for the local block only when other blocks exists.
163        # Not necessary in a standard installation without such extensions enabled
164        if ( count( $otherAutoblockLink ) ) {
165            $out->addHTML(
166                Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
167                    $pager->getNumRows() )->parse() )
168                . "\n"
169            );
170        }
171
172        if ( $pager->getNumRows() ) {
173            $out->addParserOutputContent( $pager->getFullOutput() );
174        } else {
175            $out->addWikiMsg( 'autoblocklist-empty' );
176        }
177
178        if ( count( $otherAutoblockLink ) ) {
179            $out->addHTML(
180                Html::rawElement(
181                    'h2',
182                    [],
183                    $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
184                ) . "\n"
185            );
186            $list = '';
187            foreach ( $otherAutoblockLink as $link ) {
188                $list .= Html::rawElement( 'li', [], $link ) . "\n";
189            }
190            $out->addHTML(
191                Html::rawElement(
192                    'ul',
193                    [ 'class' => 'mw-autoblocklist-otherblocks' ],
194                    $list
195                ) . "\n"
196            );
197        }
198    }
199
200    protected function getGroupName() {
201        return 'users';
202    }
203}
204
205/** @deprecated class alias since 1.41 */
206class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );