MediaWiki master
SpecialAutoblockList.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
40
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
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
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->showTotal( $pager );
125 $this->showList( $pager );
126 }
127
132 protected function getBlockListPager() {
133 $readStage = $this->getConfig()
135 if ( $readStage === SCHEMA_COMPAT_READ_OLD ) {
136 $conds = [
137 'ipb_parent_block_id IS NOT NULL',
138 // ipb_parent_block_id <> 0 because of T282890
139 'ipb_parent_block_id <> 0',
140 ];
141 # Is the user allowed to see hidden blocks?
142 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
143 $conds['ipb_deleted'] = 0;
144 }
145 } elseif ( $readStage === SCHEMA_COMPAT_READ_NEW ) {
146 $conds = [
147 'bl_parent_block_id IS NOT NULL',
148 ];
149 # Is the user allowed to see hidden blocks?
150 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
151 $conds['bl_deleted'] = 0;
152 }
153 } else {
154 throw new ConfigException(
155 '$wgBlockTargetMigrationStage has an invalid read stage' );
156 }
157
158 return new BlockListPager(
159 $this->getContext(),
160 $this->blockActionInfo,
161 $this->blockRestrictionStore,
162 $this->blockUtils,
163 $this->hideUserUtils,
164 $this->commentStore,
165 $this->linkBatchFactory,
166 $this->getLinkRenderer(),
167 $this->dbProvider,
168 $this->rowCommentFormatter,
169 $this->getSpecialPageFactory(),
170 $conds
171 );
172 }
173
179 protected function showTotal( BlockListPager $pager ) {
180 $out = $this->getOutput();
181 $out->addHTML(
182 Html::rawElement( 'div', [ 'style' => 'font-weight: bold;' ],
183 $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() )
184 . "\n"
185 );
186 }
187
192 protected function showList( BlockListPager $pager ) {
193 $out = $this->getOutput();
194
195 # Check for other blocks, i.e. global/tor blocks
196 $otherAutoblockLink = [];
197 $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
198
199 # Show additional header for the local block only when other blocks exists.
200 # Not necessary in a standard installation without such extensions enabled
201 if ( count( $otherAutoblockLink ) ) {
202 $out->addHTML(
203 Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
204 $pager->getNumRows() )->parse() )
205 . "\n"
206 );
207 }
208
209 if ( $pager->getNumRows() ) {
210 $out->addParserOutputContent( $pager->getFullOutput() );
211 } else {
212 $out->addWikiMsg( 'autoblocklist-empty' );
213 }
214
215 if ( count( $otherAutoblockLink ) ) {
216 $out->addHTML(
217 Html::rawElement(
218 'h2',
219 [],
220 $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
221 ) . "\n"
222 );
223 $list = '';
224 foreach ( $otherAutoblockLink as $link ) {
225 $list .= Html::rawElement( 'li', [], $link ) . "\n";
226 }
227 $out->addHTML(
228 Html::rawElement(
229 'ul',
230 [ 'class' => 'mw-autoblocklist-otherblocks' ],
231 $list
232 ) . "\n"
233 );
234 }
235 }
236
237 protected function getGroupName() {
238 return 'users';
239 }
240}
241
245class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );
const SCHEMA_COMPAT_READ_NEW
Definition Defines.php:277
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:273
const SCHEMA_COMPAT_READ_MASK
Definition Defines.php:279
Defines the actions that can be blocked by a partial block.
Backend class for blocking utils.
Helpers for building queries that determine whether a user is hidden.
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Handle database storage of comments such as edit summaries and log reasons.
Exceptions for config failures.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
A class containing constants representing the names of configuration variables.
const BlockTargetMigrationStage
Name constant for the BlockTargetMigrationStage setting, for use with Config::get()
getTotalAutoblocks()
Get total number of autoblocks at any given time.
getNumRows()
Get the number of rows in the result set.
getFullOutput()
Get the formatted result list, with navigation bars.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists autoblocks.
getBlockListPager()
Setup a new BlockListPager instance.
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, IConnectionProvider $dbProvider, CommentStore $commentStore, BlockUtils $blockUtils, HideUserUtils $hideUserUtils, BlockActionInfo $blockActionInfo, RowCommentFormatter $rowCommentFormatter)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
showTotal(BlockListPager $pager)
Show total number of autoblocks on top of the table.
Provide primary and replica IDatabase connections.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...