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