MediaWiki REL1_37
SpecialBlockList.php
Go to the documentation of this file.
1<?php
29use Wikimedia\IPUtils;
32
39 protected $target;
40
41 protected $options;
42
43 protected $blockType;
44
47
50
53
56
58 private $blockUtils;
59
62
63 public function __construct(
70 ) {
71 parent::__construct( 'BlockList' );
72
73 $this->linkBatchFactory = $linkBatchFactory;
74 $this->blockRestrictionStore = $blockRestrictionStore;
75 $this->loadBalancer = $loadBalancer;
76 $this->commentStore = $commentStore;
77 $this->blockUtils = $blockUtils;
78 $this->blockActionInfo = $blockActionInfo;
79 }
80
84 public function execute( $par ) {
85 $this->setHeaders();
86 $this->outputHeader();
87 $this->addHelpLink( 'Help:Blocking_users' );
88 $out = $this->getOutput();
89 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
90 $out->addModuleStyles( [ 'mediawiki.special' ] );
91
92 $request = $this->getRequest();
93 $par = $request->getVal( 'ip', $par ?? '' );
94 $this->target = trim( $request->getVal( 'wpTarget', $par ) );
95
96 $this->options = $request->getArray( 'wpOptions', [] );
97 $this->blockType = $request->getVal( 'blockType' );
98
99 $action = $request->getText( 'action' );
100
101 if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) {
102 # B/C @since 1.18: Unblock interface is now at Special:Unblock
103 $title = $this->getSpecialPageFactory()->getTitleForAlias( 'Unblock/' . $this->target );
104 $out->redirect( $title->getFullURL() );
105
106 return;
107 }
108
109 # setup BlockListPager here to get the actual default Limit
110 $pager = $this->getBlockListPager();
111
112 # Just show the block list
113 $fields = [
114 'Target' => [
115 'type' => 'user',
116 'label-message' => 'ipaddressorusername',
117 'tabindex' => '1',
118 'size' => '45',
119 'default' => $this->target,
120 ],
121 'Options' => [
122 'type' => 'multiselect',
123 'options-messages' => [
124 'blocklist-tempblocks' => 'tempblocks',
125 'blocklist-indefblocks' => 'indefblocks',
126 'blocklist-autoblocks' => 'autoblocks',
127 'blocklist-userblocks' => 'userblocks',
128 'blocklist-addressblocks' => 'addressblocks',
129 'blocklist-rangeblocks' => 'rangeblocks',
130 ],
131 'flatlist' => true,
132 ],
133 ];
134
135 $fields['BlockType'] = [
136 'type' => 'select',
137 'label-message' => 'blocklist-type',
138 'options' => [
139 $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
140 $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
141 $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
142 ],
143 'name' => 'blockType',
144 'cssclass' => 'mw-field-block-type',
145 ];
146
147 $fields['Limit'] = [
148 'type' => 'limitselect',
149 'label-message' => 'table_pager_limit_label',
150 'options' => $pager->getLimitSelectList(),
151 'name' => 'limit',
152 'default' => $pager->getLimit(),
153 'cssclass' => 'mw-field-limit mw-has-field-block-type',
154 ];
155
156 $context = new DerivativeContext( $this->getContext() );
157 $context->setTitle( $this->getPageTitle() ); // Remove subpage
158 $form = HTMLForm::factory( 'ooui', $fields, $context );
159 $form
160 ->setMethod( 'get' )
161 ->setFormIdentifier( 'blocklist' )
162 ->setWrapperLegendMsg( 'ipblocklist-legend' )
163 ->setSubmitTextMsg( 'ipblocklist-submit' )
164 ->prepareForm()
165 ->displayForm( false );
166
167 $this->showList( $pager );
168 }
169
174 protected function getBlockListPager() {
175 $conds = [];
176 $db = $this->getDB();
177 # Is the user allowed to see hidden blocks?
178 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
179 $conds['ipb_deleted'] = 0;
180 }
181
182 if ( $this->target !== '' ) {
183 list( $target, $type ) = $this->blockUtils->parseBlockTarget( $this->target );
184
185 switch ( $type ) {
186 case DatabaseBlock::TYPE_ID:
187 case DatabaseBlock::TYPE_AUTO:
188 $conds['ipb_id'] = $target;
189 break;
190
191 case DatabaseBlock::TYPE_IP:
192 case DatabaseBlock::TYPE_RANGE:
193 list( $start, $end ) = IPUtils::parseRange( $target );
194 $conds[] = $db->makeList(
195 [
196 'ipb_address' => $target,
197 DatabaseBlock::getRangeCond( $start, $end )
198 ],
199 LIST_OR
200 );
201 $conds['ipb_auto'] = 0;
202 break;
203
204 case DatabaseBlock::TYPE_USER:
205 $conds['ipb_address'] = $target->getName();
206 $conds['ipb_auto'] = 0;
207 break;
208 }
209 }
210
211 # Apply filters
212 if ( in_array( 'userblocks', $this->options ) ) {
213 $conds['ipb_user'] = 0;
214 }
215 if ( in_array( 'autoblocks', $this->options ) ) {
216 // ipb_parent_block_id = 0 because of T282890
217 $conds[] = "ipb_parent_block_id IS NULL OR ipb_parent_block_id = 0";
218 }
219 if ( in_array( 'addressblocks', $this->options ) ) {
220 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
221 }
222 if ( in_array( 'rangeblocks', $this->options ) ) {
223 $conds[] = "ipb_range_end = ipb_range_start";
224 }
225
226 $hideTemp = in_array( 'tempblocks', $this->options );
227 $hideIndef = in_array( 'indefblocks', $this->options );
228 if ( $hideTemp && $hideIndef ) {
229 // If both types are hidden, ensure query doesn't produce any results
230 $conds[] = '1=0';
231 } elseif ( $hideTemp ) {
232 $conds['ipb_expiry'] = $db->getInfinity();
233 } elseif ( $hideIndef ) {
234 $conds[] = "ipb_expiry != " . $db->addQuotes( $db->getInfinity() );
235 }
236
237 if ( $this->blockType === 'sitewide' ) {
238 $conds['ipb_sitewide'] = 1;
239 } elseif ( $this->blockType === 'partial' ) {
240 $conds['ipb_sitewide'] = 0;
241 }
242
243 return new BlockListPager(
244 $this,
245 $conds,
246 $this->linkBatchFactory,
247 $this->blockRestrictionStore,
248 $this->loadBalancer,
249 $this->getSpecialPageFactory(),
250 $this->commentStore,
251 $this->blockUtils,
252 $this->blockActionInfo
253 );
254 }
255
260 protected function showList( BlockListPager $pager ) {
261 $out = $this->getOutput();
262
263 # Check for other blocks, i.e. global/tor blocks
264 $otherBlockLink = [];
265 $this->getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
266
267 # Show additional header for the local block only when other blocks exists.
268 # Not necessary in a standard installation without such extensions enabled
269 if ( count( $otherBlockLink ) ) {
270 $out->addHTML(
271 Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
272 );
273 }
274
275 if ( $pager->getNumRows() ) {
276 $out->addParserOutputContent( $pager->getFullOutput() );
277 } elseif ( $this->target ) {
278 $out->addWikiMsg( 'ipblocklist-no-results' );
279 } else {
280 $out->addWikiMsg( 'ipblocklist-empty' );
281 }
282
283 if ( count( $otherBlockLink ) ) {
284 $out->addHTML(
285 Html::rawElement(
286 'h2',
287 [],
288 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
289 ) . "\n"
290 );
291 $list = '';
292 foreach ( $otherBlockLink as $link ) {
293 $list .= Html::rawElement( 'li', [], $link ) . "\n";
294 }
295 $out->addHTML( Html::rawElement(
296 'ul',
297 [ 'class' => 'mw-ipblocklist-otherblocks' ],
298 $list
299 ) . "\n" );
300 }
301 }
302
303 protected function getGroupName() {
304 return 'users';
305 }
306
312 protected function getDB() {
313 return $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
314 }
315}
const LIST_OR
Definition Defines.php:46
Handle database storage of comments such as edit summaries and log reasons.
An IContextSource implementation which will inherit context from another source but allow individual ...
getNumRows()
Get the number of rows in the result set.
Defines the actions that can be blocked by a partial block.
Backend class for blocking utils.
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
A special page that lists existing blocks.
BlockActionInfo $blockActionInfo
BlockRestrictionStore $blockRestrictionStore
getDB()
Return a IDatabase object for reading.
ILoadBalancer $loadBalancer
LinkBatchFactory $linkBatchFactory
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, ILoadBalancer $loadBalancer, CommentStore $commentStore, BlockUtils $blockUtils, BlockActionInfo $blockActionInfo)
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
CommentStore $commentStore
getBlockListPager()
Setup a new BlockListPager instance.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getFullOutput()
Get the formatted result list, with navigation bars.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.