MediaWiki  master
SpecialBlockList.php
Go to the documentation of this file.
1 <?php
29 use Wikimedia\IPUtils;
32 
39  protected $target;
40 
41  protected $options;
42 
43  protected $blockType;
44 
47 
50 
52  private $loadBalancer;
53 
55  private $commentStore;
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(
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 }
LIST_OR
const LIST_OR
Definition: Defines.php:46
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:743
SpecialBlockList\$blockType
$blockType
Definition: SpecialBlockList.php:43
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:911
SpecialBlockList\execute
execute( $par)
Definition: SpecialBlockList.php:84
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:789
SpecialBlockList\$blockUtils
BlockUtils $blockUtils
Definition: SpecialBlockList.php:58
BlockListPager
Definition: BlockListPager.php:39
SpecialBlockList\$options
$options
Definition: SpecialBlockList.php:41
MediaWiki\Block\BlockUtils
Backend class for blocking utils.
Definition: BlockUtils.php:45
SpecialBlockList\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialBlockList.php:52
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
TablePager\getFullOutput
getFullOutput()
Get the formatted result list, with navigation bars.
Definition: TablePager.php:111
SpecialPage\getAuthority
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: SpecialPage.php:809
SpecialBlockList\__construct
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, ILoadBalancer $loadBalancer, CommentStore $commentStore, BlockUtils $blockUtils, BlockActionInfo $blockActionInfo)
Definition: SpecialBlockList.php:63
SpecialBlockList\getBlockListPager
getBlockListPager()
Setup a new BlockListPager instance.
Definition: SpecialBlockList.php:174
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SpecialBlockList\$target
$target
Definition: SpecialBlockList.php:39
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:52
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:33
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:947
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1094
SpecialBlockList\showList
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
Definition: SpecialBlockList.php:260
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:617
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:763
SpecialBlockList\$blockActionInfo
BlockActionInfo $blockActionInfo
Definition: SpecialBlockList.php:61
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:779
SpecialBlockList\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialBlockList.php:46
MediaWiki\Block\BlockActionInfo
Defines the actions that can be blocked by a partial block.
Definition: BlockActionInfo.php:40
SpecialBlockList\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBlockList.php:303
SpecialBlockList
A special page that lists existing blocks.
Definition: SpecialBlockList.php:38
SpecialPage\getSpecialPageFactory
getSpecialPageFactory()
Definition: SpecialPage.php:1114
SpecialBlockList\$blockRestrictionStore
BlockRestrictionStore $blockRestrictionStore
Definition: SpecialBlockList.php:49
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
SpecialBlockList\$commentStore
CommentStore $commentStore
Definition: SpecialBlockList.php:55
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
SpecialBlockList\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialBlockList.php:312
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:327
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:708
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:731
MediaWiki\Block\BlockRestrictionStore
Definition: BlockRestrictionStore.php:35
$type
$type
Definition: testCompression.php:52