Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
79 / 79
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
SpecialAutoblockList
100.00% covered (success)
100.00%
79 / 79
100.00% covered (success)
100.00%
4 / 4
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
1
 getBlockListPager
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
2
 showList
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
1 / 1
5
 getGroupName
n/a
0 / 0
n/a
0 / 0
1
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\Parser\ParserOptions;
19use MediaWiki\SpecialPage\SpecialPage;
20use MediaWiki\Specials\Pager\BlockListPager;
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            ->setId( 'mw-autoblock-list-form' )
76            ->prepareForm()
77            ->displayForm( false );
78
79        $this->showList( $pager );
80    }
81
82    /**
83     * Setup a new BlockListPager instance.
84     * @return BlockListPager
85     */
86    protected function getBlockListPager() {
87        $conds = [
88            $this->dbProvider->getReplicaDatabase()->expr( 'bl_parent_block_id', '!=', null ),
89        ];
90        # Is the user allowed to see hidden blocks?
91        if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
92            $conds['bl_deleted'] = 0;
93        }
94
95        return new BlockListPager(
96            $this->getContext(),
97            $this->blockActionInfo,
98            $this->blockRestrictionStore,
99            $this->blockTargetFactory,
100            $this->hideUserUtils,
101            $this->commentStore,
102            $this->linkBatchFactory,
103            $this->getLinkRenderer(),
104            $this->dbProvider,
105            $this->rowCommentFormatter,
106            $this->getSpecialPageFactory(),
107            $conds
108        );
109    }
110
111    /**
112     * Show the list of blocked accounts matching the actual filter.
113     * @param BlockListPager $pager The BlockListPager instance for this page
114     */
115    protected function showList( BlockListPager $pager ) {
116        $out = $this->getOutput();
117
118        # Check for other blocks, i.e. global/tor blocks
119        $otherAutoblockLink = [];
120        $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
121
122        # Show additional header for the local block only when other blocks exists.
123        # Not necessary in a standard installation without such extensions enabled
124        if ( count( $otherAutoblockLink ) ) {
125            $out->addHTML(
126                Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
127                    $pager->getNumRows() )->parse() )
128                . "\n"
129            );
130        }
131
132        if ( $pager->getNumRows() ) {
133            $out->addParserOutputContent(
134                $pager->getFullOutput(),
135                ParserOptions::newFromContext( $this->getContext() )
136            );
137        } else {
138            $out->addWikiMsg( 'autoblocklist-empty' );
139        }
140
141        if ( count( $otherAutoblockLink ) ) {
142            $out->addHTML(
143                Html::rawElement(
144                    'h2',
145                    [],
146                    $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
147                ) . "\n"
148            );
149            $list = '';
150            foreach ( $otherAutoblockLink as $link ) {
151                $list .= Html::rawElement( 'li', [], $link ) . "\n";
152            }
153            $out->addHTML(
154                Html::rawElement(
155                    'ul',
156                    [ 'class' => 'mw-autoblocklist-otherblocks' ],
157                    $list
158                ) . "\n"
159            );
160        }
161    }
162
163    /**
164     * @codeCoverageIgnore Merely declarative
165     * @inheritDoc
166     */
167    protected function getGroupName() {
168        return 'users';
169    }
170}
171
172// @codeCoverageIgnoreStart
173/** @deprecated class alias since 1.41 */
174class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );
175// @codeCoverageIgnoreEnd