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->showList( $pager );
125 }
126
131 protected function getBlockListPager() {
132 $readStage = $this->getConfig()
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
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
228class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );
const SCHEMA_COMPAT_READ_NEW
Definition Defines.php:279
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:275
const SCHEMA_COMPAT_READ_MASK
Definition Defines.php:281
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()
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...
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...