Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 97
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 / 96
0.00% covered (danger)
0.00%
0 / 5
182
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 / 31
0.00% covered (danger)
0.00%
0 / 1
30
 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 * 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
24namespace MediaWiki\Specials;
25
26use MediaWiki\Block\BlockActionInfo;
27use MediaWiki\Block\BlockRestrictionStore;
28use MediaWiki\Block\BlockUtils;
29use MediaWiki\Block\HideUserUtils;
30use MediaWiki\Cache\LinkBatchFactory;
31use MediaWiki\CommentFormatter\RowCommentFormatter;
32use MediaWiki\CommentStore\CommentStore;
33use MediaWiki\Config\ConfigException;
34use MediaWiki\Html\Html;
35use MediaWiki\HTMLForm\HTMLForm;
36use MediaWiki\MainConfigNames;
37use MediaWiki\Pager\BlockListPager;
38use MediaWiki\SpecialPage\SpecialPage;
39use Wikimedia\Rdbms\IConnectionProvider;
40
41/**
42 * A special page that lists autoblocks
43 *
44 * @since 1.29
45 * @ingroup SpecialPage
46 */
47class SpecialAutoblockList extends SpecialPage {
48
49    private LinkBatchFactory $linkBatchFactory;
50    private BlockRestrictionStore $blockRestrictionStore;
51    private IConnectionProvider $dbProvider;
52    private CommentStore $commentStore;
53    private BlockUtils $blockUtils;
54    private HideUserUtils $hideUserUtils;
55    private BlockActionInfo $blockActionInfo;
56    private RowCommentFormatter $rowCommentFormatter;
57
58    /**
59     * @param LinkBatchFactory $linkBatchFactory
60     * @param BlockRestrictionStore $blockRestrictionStore
61     * @param IConnectionProvider $dbProvider
62     * @param CommentStore $commentStore
63     * @param BlockUtils $blockUtils
64     * @param HideUserUtils $hideUserUtils
65     * @param BlockActionInfo $blockActionInfo
66     * @param RowCommentFormatter $rowCommentFormatter
67     */
68    public function __construct(
69        LinkBatchFactory $linkBatchFactory,
70        BlockRestrictionStore $blockRestrictionStore,
71        IConnectionProvider $dbProvider,
72        CommentStore $commentStore,
73        BlockUtils $blockUtils,
74        HideUserUtils $hideUserUtils,
75        BlockActionInfo $blockActionInfo,
76        RowCommentFormatter $rowCommentFormatter
77    ) {
78        parent::__construct( 'AutoblockList' );
79
80        $this->linkBatchFactory = $linkBatchFactory;
81        $this->blockRestrictionStore = $blockRestrictionStore;
82        $this->dbProvider = $dbProvider;
83        $this->commentStore = $commentStore;
84        $this->blockUtils = $blockUtils;
85        $this->hideUserUtils = $hideUserUtils;
86        $this->blockActionInfo = $blockActionInfo;
87        $this->rowCommentFormatter = $rowCommentFormatter;
88    }
89
90    /**
91     * @param string|null $par Title fragment
92     */
93    public function execute( $par ) {
94        $this->setHeaders();
95        $this->outputHeader();
96        $out = $this->getOutput();
97        $out->setPageTitleMsg( $this->msg( 'autoblocklist' ) );
98        $this->addHelpLink( 'Autoblock' );
99        $out->addModuleStyles( [ 'mediawiki.special' ] );
100
101        # setup BlockListPager here to get the actual default Limit
102        $pager = $this->getBlockListPager();
103
104        # Just show the block list
105        $fields = [
106            'Limit' => [
107                'type' => 'limitselect',
108                'label-message' => 'table_pager_limit_label',
109                'options' => $pager->getLimitSelectList(),
110                'name' => 'limit',
111                'default' => $pager->getLimit(),
112            ]
113        ];
114
115        $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
116        $form->setMethod( 'get' )
117            ->setTitle( $this->getPageTitle() ) // Remove subpage
118            ->setFormIdentifier( 'blocklist' )
119            ->setWrapperLegendMsg( 'autoblocklist-legend' )
120            ->setSubmitTextMsg( 'autoblocklist-submit' )
121            ->prepareForm()
122            ->displayForm( false );
123
124        $this->showList( $pager );
125    }
126
127    /**
128     * Setup a new BlockListPager instance.
129     * @return BlockListPager
130     */
131    protected function getBlockListPager() {
132        $readStage = $this->getConfig()
133                ->get( MainConfigNames::BlockTargetMigrationStage ) & SCHEMA_COMPAT_READ_MASK;
134        if ( $readStage === SCHEMA_COMPAT_READ_OLD ) {
135            $conds = [
136                'ipb_parent_block_id IS NOT NULL',
137                // ipb_parent_block_id <> 0 because of T282890
138                'ipb_parent_block_id <> 0',
139            ];
140            # Is the user allowed to see hidden blocks?
141            if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
142                $conds['ipb_deleted'] = 0;
143            }
144        } elseif ( $readStage === SCHEMA_COMPAT_READ_NEW ) {
145            $conds = [
146                'bl_parent_block_id IS NOT NULL',
147            ];
148            # Is the user allowed to see hidden blocks?
149            if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
150                $conds['bl_deleted'] = 0;
151            }
152        } else {
153            throw new ConfigException(
154                '$wgBlockTargetMigrationStage has an invalid read stage' );
155        }
156
157        return new BlockListPager(
158            $this->getContext(),
159            $this->blockActionInfo,
160            $this->blockRestrictionStore,
161            $this->blockUtils,
162            $this->hideUserUtils,
163            $this->commentStore,
164            $this->linkBatchFactory,
165            $this->getLinkRenderer(),
166            $this->dbProvider,
167            $this->rowCommentFormatter,
168            $this->getSpecialPageFactory(),
169            $conds
170        );
171    }
172
173    /**
174     * Show the list of blocked accounts matching the actual filter.
175     * @param BlockListPager $pager The BlockListPager instance for this page
176     */
177    protected function showList( BlockListPager $pager ) {
178        $out = $this->getOutput();
179
180        # Check for other blocks, i.e. global/tor blocks
181        $otherAutoblockLink = [];
182        $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
183
184        # Show additional header for the local block only when other blocks exists.
185        # Not necessary in a standard installation without such extensions enabled
186        if ( count( $otherAutoblockLink ) ) {
187            $out->addHTML(
188                Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
189                    $pager->getNumRows() )->parse() )
190                . "\n"
191            );
192        }
193
194        if ( $pager->getNumRows() ) {
195            $out->addParserOutputContent( $pager->getFullOutput() );
196        } else {
197            $out->addWikiMsg( 'autoblocklist-empty' );
198        }
199
200        if ( count( $otherAutoblockLink ) ) {
201            $out->addHTML(
202                Html::rawElement(
203                    'h2',
204                    [],
205                    $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
206                ) . "\n"
207            );
208            $list = '';
209            foreach ( $otherAutoblockLink as $link ) {
210                $list .= Html::rawElement( 'li', [], $link ) . "\n";
211            }
212            $out->addHTML(
213                Html::rawElement(
214                    'ul',
215                    [ 'class' => 'mw-autoblocklist-otherblocks' ],
216                    $list
217                ) . "\n"
218            );
219        }
220    }
221
222    protected function getGroupName() {
223        return 'users';
224    }
225}
226
227/** @deprecated class alias since 1.41 */
228class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );