Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 80
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 / 79
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 / 1
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 / 33
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 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Specials;
8
9use MediaWiki\Block\BlockActionInfo;
10use MediaWiki\Block\BlockRestrictionStore;
11use MediaWiki\Block\BlockTargetFactory;
12use MediaWiki\Block\HideUserUtils;
13use MediaWiki\CommentFormatter\RowCommentFormatter;
14use MediaWiki\CommentStore\CommentStore;
15use MediaWiki\Html\Html;
16use MediaWiki\HTMLForm\HTMLForm;
17use MediaWiki\Page\LinkBatchFactory;
18use MediaWiki\Pager\BlockListPager;
19use MediaWiki\Parser\ParserOptions;
20use MediaWiki\SpecialPage\SpecialPage;
21use Wikimedia\Rdbms\IConnectionProvider;
22
23/**
24 * List of autoblocks
25 *
26 * @since 1.29
27 * @ingroup SpecialPage
28 */
29class SpecialAutoblockList extends SpecialPage {
30
31    public function __construct(
32        private readonly LinkBatchFactory $linkBatchFactory,
33        private readonly BlockRestrictionStore $blockRestrictionStore,
34        private readonly IConnectionProvider $dbProvider,
35        private readonly CommentStore $commentStore,
36        private readonly BlockTargetFactory $blockTargetFactory,
37        private readonly HideUserUtils $hideUserUtils,
38        private readonly BlockActionInfo $blockActionInfo,
39        private readonly RowCommentFormatter $rowCommentFormatter
40    ) {
41        parent::__construct( 'AutoblockList' );
42    }
43
44    /**
45     * @param string|null $par Title fragment
46     */
47    public function execute( $par ) {
48        $this->setHeaders();
49        $this->outputHeader();
50        $out = $this->getOutput();
51        $out->setPageTitleMsg( $this->msg( 'autoblocklist' ) );
52        $this->addHelpLink( 'Autoblock' );
53        $out->addModuleStyles( [ 'mediawiki.special' ] );
54
55        # setup BlockListPager here to get the actual default Limit
56        $pager = $this->getBlockListPager();
57
58        # Just show the block list
59        $fields = [
60            'Limit' => [
61                'type' => 'limitselect',
62                'label-message' => 'table_pager_limit_label',
63                'options' => $pager->getLimitSelectList(),
64                'name' => 'limit',
65                'default' => $pager->getLimit(),
66            ]
67        ];
68
69        $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
70        $form->setMethod( 'get' )
71            ->setTitle( $this->getPageTitle() ) // Remove subpage
72            ->setFormIdentifier( 'blocklist' )
73            ->setWrapperLegendMsg( 'autoblocklist-legend' )
74            ->setSubmitTextMsg( 'autoblocklist-submit' )
75            ->prepareForm()
76            ->displayForm( false );
77
78        $this->showList( $pager );
79    }
80
81    /**
82     * Setup a new BlockListPager instance.
83     * @return BlockListPager
84     */
85    protected function getBlockListPager() {
86        $conds = [
87            $this->dbProvider->getReplicaDatabase()->expr( 'bl_parent_block_id', '!=', null ),
88        ];
89        # Is the user allowed to see hidden blocks?
90        if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
91            $conds['bl_deleted'] = 0;
92        }
93
94        return new BlockListPager(
95            $this->getContext(),
96            $this->blockActionInfo,
97            $this->blockRestrictionStore,
98            $this->blockTargetFactory,
99            $this->hideUserUtils,
100            $this->commentStore,
101            $this->linkBatchFactory,
102            $this->getLinkRenderer(),
103            $this->dbProvider,
104            $this->rowCommentFormatter,
105            $this->getSpecialPageFactory(),
106            $conds
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        $this->getHookRunner()->onOtherAutoblockLogLink( $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(
133                $pager->getFullOutput(),
134                ParserOptions::newFromContext( $this->getContext() )
135            );
136        } else {
137            $out->addWikiMsg( 'autoblocklist-empty' );
138        }
139
140        if ( count( $otherAutoblockLink ) ) {
141            $out->addHTML(
142                Html::rawElement(
143                    'h2',
144                    [],
145                    $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
146                ) . "\n"
147            );
148            $list = '';
149            foreach ( $otherAutoblockLink as $link ) {
150                $list .= Html::rawElement( 'li', [], $link ) . "\n";
151            }
152            $out->addHTML(
153                Html::rawElement(
154                    'ul',
155                    [ 'class' => 'mw-autoblocklist-otherblocks' ],
156                    $list
157                ) . "\n"
158            );
159        }
160    }
161
162    /** @inheritDoc */
163    protected function getGroupName() {
164        return 'users';
165    }
166}
167
168/** @deprecated class alias since 1.41 */
169class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );