Debian Codegraph @

includes/specials/SpecialAutoblockList.php

raw symbols SCIP
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
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Block\BlockActionInfo;
24 use MediaWiki\Block\BlockRestrictionStore;
25 use MediaWiki\Block\BlockUtils;
26 use MediaWiki\Block\HideUserUtils;
27 use MediaWiki\Cache\LinkBatchFactory;
28 use MediaWiki\CommentFormatter\RowCommentFormatter;
29 use MediaWiki\CommentStore\CommentStore;
30 use MediaWiki\Html\Html;
31 use MediaWiki\HTMLForm\HTMLForm;
32 use MediaWiki\Pager\BlockListPager;
33 use MediaWiki\SpecialPage\SpecialPage;
34 use Wikimedia\Rdbms\IConnectionProvider;
35
36 /**
37 * List of autoblocks
38 *
39 * @since 1.29
40 * @ingroup SpecialPage
41 */
42 class 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 */
206 class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );