MediaWiki  master
SpecialBlockList.php
Go to the documentation of this file.
1 <?php
28 use Wikimedia\IPUtils;
31 
38  protected $target;
39 
40  protected $options;
41 
42  protected $blockType;
43 
46 
49 
51  private $loadBalancer;
52 
54  private $actorMigration;
55 
57  private $commentStore;
58 
60  private $blockUtils;
61 
62  public function __construct(
69  ) {
70  parent::__construct( 'BlockList' );
71 
72  $this->linkBatchFactory = $linkBatchFactory;
73  $this->blockRestrictionStore = $blockRestrictionStore;
74  $this->loadBalancer = $loadBalancer;
75  $this->actorMigration = $actorMigration;
76  $this->commentStore = $commentStore;
77  $this->blockUtils = $blockUtils;
78  }
79 
83  public function execute( $par ) {
84  $this->setHeaders();
85  $this->outputHeader();
86  $this->addHelpLink( 'Help:Blocking_users' );
87  $out = $this->getOutput();
88  $out->setPageTitle( $this->msg( 'ipblocklist' ) );
89  $out->addModuleStyles( [ 'mediawiki.special' ] );
90 
91  $request = $this->getRequest();
92  $par = $request->getVal( 'ip', $par );
93  $this->target = trim( $request->getVal( 'wpTarget', $par ) );
94 
95  $this->options = $request->getArray( 'wpOptions', [] );
96  $this->blockType = $request->getVal( 'blockType' );
97 
98  $action = $request->getText( 'action' );
99 
100  if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) {
101  # B/C @since 1.18: Unblock interface is now at Special:Unblock
102  $title = $this->getSpecialPageFactory()->getTitleForAlias( 'Unblock/' . $this->target );
103  $out->redirect( $title->getFullURL() );
104 
105  return;
106  }
107 
108  # setup BlockListPager here to get the actual default Limit
109  $pager = $this->getBlockListPager();
110 
111  # Just show the block list
112  $fields = [
113  'Target' => [
114  'type' => 'user',
115  'label-message' => 'ipaddressorusername',
116  'tabindex' => '1',
117  'size' => '45',
118  'default' => $this->target,
119  ],
120  'Options' => [
121  'type' => 'multiselect',
122  'options-messages' => [
123  'blocklist-tempblocks' => 'tempblocks',
124  'blocklist-indefblocks' => 'indefblocks',
125  'blocklist-userblocks' => 'userblocks',
126  'blocklist-addressblocks' => 'addressblocks',
127  'blocklist-rangeblocks' => 'rangeblocks',
128  ],
129  'flatlist' => true,
130  ],
131  ];
132 
133  $fields['BlockType'] = [
134  'type' => 'select',
135  'label-message' => 'blocklist-type',
136  'options' => [
137  $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
138  $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
139  $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
140  ],
141  'name' => 'blockType',
142  'cssclass' => 'mw-field-block-type',
143  ];
144 
145  $fields['Limit'] = [
146  'type' => 'limitselect',
147  'label-message' => 'table_pager_limit_label',
148  'options' => $pager->getLimitSelectList(),
149  'name' => 'limit',
150  'default' => $pager->getLimit(),
151  'cssclass' => 'mw-field-limit mw-has-field-block-type',
152  ];
153 
154  $context = new DerivativeContext( $this->getContext() );
155  $context->setTitle( $this->getPageTitle() ); // Remove subpage
156  $form = HTMLForm::factory( 'ooui', $fields, $context );
157  $form
158  ->setMethod( 'get' )
159  ->setFormIdentifier( 'blocklist' )
160  ->setWrapperLegendMsg( 'ipblocklist-legend' )
161  ->setSubmitTextMsg( 'ipblocklist-submit' )
162  ->prepareForm()
163  ->displayForm( false );
164 
165  $this->showList( $pager );
166  }
167 
172  protected function getBlockListPager() {
173  $conds = [];
174  $db = $this->getDB();
175  # Is the user allowed to see hidden blocks?
176  if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
177  $conds['ipb_deleted'] = 0;
178  }
179 
180  if ( $this->target !== '' ) {
181  list( $target, $type ) = $this->blockUtils->parseBlockTarget( $this->target );
182 
183  switch ( $type ) {
184  case DatabaseBlock::TYPE_ID:
185  case DatabaseBlock::TYPE_AUTO:
186  $conds['ipb_id'] = $target;
187  break;
188 
189  case DatabaseBlock::TYPE_IP:
190  case DatabaseBlock::TYPE_RANGE:
191  list( $start, $end ) = IPUtils::parseRange( $target );
192  $conds[] = $db->makeList(
193  [
194  'ipb_address' => $target,
195  DatabaseBlock::getRangeCond( $start, $end )
196  ],
197  LIST_OR
198  );
199  $conds['ipb_auto'] = 0;
200  break;
201 
202  case DatabaseBlock::TYPE_USER:
203  $conds['ipb_address'] = $target->getName();
204  $conds['ipb_auto'] = 0;
205  break;
206  }
207  }
208 
209  # Apply filters
210  if ( in_array( 'userblocks', $this->options ) ) {
211  $conds['ipb_user'] = 0;
212  }
213  if ( in_array( 'addressblocks', $this->options ) ) {
214  $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
215  }
216  if ( in_array( 'rangeblocks', $this->options ) ) {
217  $conds[] = "ipb_range_end = ipb_range_start";
218  }
219 
220  $hideTemp = in_array( 'tempblocks', $this->options );
221  $hideIndef = in_array( 'indefblocks', $this->options );
222  if ( $hideTemp && $hideIndef ) {
223  // If both types are hidden, ensure query doesn't produce any results
224  $conds[] = '1=0';
225  } elseif ( $hideTemp ) {
226  $conds['ipb_expiry'] = $db->getInfinity();
227  } elseif ( $hideIndef ) {
228  $conds[] = "ipb_expiry != " . $db->addQuotes( $db->getInfinity() );
229  }
230 
231  if ( $this->blockType === 'sitewide' ) {
232  $conds['ipb_sitewide'] = 1;
233  } elseif ( $this->blockType === 'partial' ) {
234  $conds['ipb_sitewide'] = 0;
235  }
236 
237  return new BlockListPager(
238  $this,
239  $conds,
240  $this->linkBatchFactory,
241  $this->blockRestrictionStore,
242  $this->loadBalancer,
243  $this->getSpecialPageFactory(),
244  $this->actorMigration,
245  $this->commentStore,
246  $this->blockUtils
247  );
248  }
249 
254  protected function showList( BlockListPager $pager ) {
255  $out = $this->getOutput();
256 
257  # Check for other blocks, i.e. global/tor blocks
258  $otherBlockLink = [];
259  $this->getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
260 
261  # Show additional header for the local block only when other blocks exists.
262  # Not necessary in a standard installation without such extensions enabled
263  if ( count( $otherBlockLink ) ) {
264  $out->addHTML(
265  Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
266  );
267  }
268 
269  if ( $pager->getNumRows() ) {
270  $out->addParserOutputContent( $pager->getFullOutput() );
271  } elseif ( $this->target ) {
272  $out->addWikiMsg( 'ipblocklist-no-results' );
273  } else {
274  $out->addWikiMsg( 'ipblocklist-empty' );
275  }
276 
277  if ( count( $otherBlockLink ) ) {
278  $out->addHTML(
280  'h2',
281  [],
282  $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
283  ) . "\n"
284  );
285  $list = '';
286  foreach ( $otherBlockLink as $link ) {
287  $list .= Html::rawElement( 'li', [], $link ) . "\n";
288  }
289  $out->addHTML( Html::rawElement(
290  'ul',
291  [ 'class' => 'mw-ipblocklist-otherblocks' ],
292  $list
293  ) . "\n" );
294  }
295  }
296 
297  protected function getGroupName() {
298  return 'users';
299  }
300 
306  protected function getDB() {
307  return $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
308  }
309 }
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:42
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:911
SpecialBlockList\execute
execute( $par)
Definition: SpecialBlockList.php:83
SpecialBlockList\$actorMigration
ActorMigration $actorMigration
Definition: SpecialBlockList.php:54
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:789
SpecialBlockList\$blockUtils
BlockUtils $blockUtils
Definition: SpecialBlockList.php:60
BlockListPager
Definition: BlockListPager.php:37
SpecialBlockList\$options
$options
Definition: SpecialBlockList.php:40
MediaWiki\Block\BlockUtils
Backend class for blocking utils.
Definition: BlockUtils.php:44
SpecialBlockList\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialBlockList.php:51
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
ActorMigration
This class handles the logic for the actor table migration and should always be used in lieu of direc...
Definition: ActorMigration.php:41
SpecialBlockList\getBlockListPager
getBlockListPager()
Setup a new BlockListPager instance.
Definition: SpecialBlockList.php:172
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SpecialBlockList\__construct
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, ILoadBalancer $loadBalancer, ActorMigration $actorMigration, CommentStore $commentStore, BlockUtils $blockUtils)
Definition: SpecialBlockList.php:62
SpecialBlockList\$target
$target
Definition: SpecialBlockList.php:38
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:53
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:32
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:254
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:38
$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
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:45
SpecialBlockList\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBlockList.php:297
SpecialBlockList
A special page that lists existing blocks.
Definition: SpecialBlockList.php:37
SpecialPage\getSpecialPageFactory
getSpecialPageFactory()
Definition: SpecialPage.php:1114
SpecialBlockList\$blockRestrictionStore
BlockRestrictionStore $blockRestrictionStore
Definition: SpecialBlockList.php:48
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
SpecialBlockList\$commentStore
CommentStore $commentStore
Definition: SpecialBlockList.php:57
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:234
SpecialBlockList\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialBlockList.php:306
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:322
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:34
$type
$type
Definition: testCompression.php:52