MediaWiki  master
SpecialBlockList.php
Go to the documentation of this file.
1 <?php
26 use Wikimedia\IPUtils;
28 
35  protected $target;
36 
37  protected $options;
38 
39  protected $blockType;
40 
41  public function __construct() {
42  parent::__construct( 'BlockList' );
43  }
44 
48  public function execute( $par ) {
49  $this->setHeaders();
50  $this->outputHeader();
51  $this->addHelpLink( 'Help:Blocking_users' );
52  $out = $this->getOutput();
53  $out->setPageTitle( $this->msg( 'ipblocklist' ) );
54  $out->addModuleStyles( [ 'mediawiki.special' ] );
55 
56  $request = $this->getRequest();
57  $par = $request->getVal( 'ip', $par );
58  $this->target = trim( $request->getVal( 'wpTarget', $par ) );
59 
60  $this->options = $request->getArray( 'wpOptions', [] );
61  $this->blockType = $request->getVal( 'blockType' );
62 
63  $action = $request->getText( 'action' );
64 
65  if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) {
66  # B/C @since 1.18: Unblock interface is now at Special:Unblock
67  $title = SpecialPage::getTitleFor( 'Unblock', $this->target );
68  $out->redirect( $title->getFullURL() );
69 
70  return;
71  }
72 
73  # setup BlockListPager here to get the actual default Limit
74  $pager = $this->getBlockListPager();
75 
76  # Just show the block list
77  $fields = [
78  'Target' => [
79  'type' => 'user',
80  'label-message' => 'ipaddressorusername',
81  'tabindex' => '1',
82  'size' => '45',
83  'default' => $this->target,
84  ],
85  'Options' => [
86  'type' => 'multiselect',
87  'options-messages' => [
88  'blocklist-tempblocks' => 'tempblocks',
89  'blocklist-indefblocks' => 'indefblocks',
90  'blocklist-userblocks' => 'userblocks',
91  'blocklist-addressblocks' => 'addressblocks',
92  'blocklist-rangeblocks' => 'rangeblocks',
93  ],
94  'flatlist' => true,
95  ],
96  ];
97 
98  $fields['BlockType'] = [
99  'type' => 'select',
100  'label-message' => 'blocklist-type',
101  'options' => [
102  $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
103  $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
104  $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
105  ],
106  'name' => 'blockType',
107  'cssclass' => 'mw-field-block-type',
108  ];
109 
110  $fields['Limit'] = [
111  'type' => 'limitselect',
112  'label-message' => 'table_pager_limit_label',
113  'options' => $pager->getLimitSelectList(),
114  'name' => 'limit',
115  'default' => $pager->getLimit(),
116  'cssclass' => 'mw-field-limit mw-has-field-block-type',
117  ];
118 
119  $context = new DerivativeContext( $this->getContext() );
120  $context->setTitle( $this->getPageTitle() ); // Remove subpage
121  $form = HTMLForm::factory( 'ooui', $fields, $context );
122  $form
123  ->setMethod( 'get' )
124  ->setFormIdentifier( 'blocklist' )
125  ->setWrapperLegendMsg( 'ipblocklist-legend' )
126  ->setSubmitTextMsg( 'ipblocklist-submit' )
127  ->prepareForm()
128  ->displayForm( false );
129 
130  $this->showList( $pager );
131  }
132 
137  protected function getBlockListPager() {
138  $conds = [];
139  $db = $this->getDB();
140  # Is the user allowed to see hidden blocks?
141  if ( !MediaWikiServices::getInstance()
143  ->userHasRight( $this->getUser(), 'hideuser' )
144  ) {
145  $conds['ipb_deleted'] = 0;
146  }
147 
148  if ( $this->target !== '' ) {
149  list( $target, $type ) = DatabaseBlock::parseTarget( $this->target );
150 
151  switch ( $type ) {
152  case DatabaseBlock::TYPE_ID:
153  case DatabaseBlock::TYPE_AUTO:
154  $conds['ipb_id'] = $target;
155  break;
156 
157  case DatabaseBlock::TYPE_IP:
158  case DatabaseBlock::TYPE_RANGE:
159  list( $start, $end ) = IPUtils::parseRange( $target );
160  $conds[] = $db->makeList(
161  [
162  'ipb_address' => $target,
163  DatabaseBlock::getRangeCond( $start, $end )
164  ],
165  LIST_OR
166  );
167  $conds['ipb_auto'] = 0;
168  break;
169 
170  case DatabaseBlock::TYPE_USER:
171  $conds['ipb_address'] = $target->getName();
172  $conds['ipb_auto'] = 0;
173  break;
174  }
175  }
176 
177  # Apply filters
178  if ( in_array( 'userblocks', $this->options ) ) {
179  $conds['ipb_user'] = 0;
180  }
181  if ( in_array( 'addressblocks', $this->options ) ) {
182  $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
183  }
184  if ( in_array( 'rangeblocks', $this->options ) ) {
185  $conds[] = "ipb_range_end = ipb_range_start";
186  }
187 
188  $hideTemp = in_array( 'tempblocks', $this->options );
189  $hideIndef = in_array( 'indefblocks', $this->options );
190  if ( $hideTemp && $hideIndef ) {
191  // If both types are hidden, ensure query doesn't produce any results
192  $conds[] = '1=0';
193  } elseif ( $hideTemp ) {
194  $conds['ipb_expiry'] = $db->getInfinity();
195  } elseif ( $hideIndef ) {
196  $conds[] = "ipb_expiry != " . $db->addQuotes( $db->getInfinity() );
197  }
198 
199  if ( $this->blockType === 'sitewide' ) {
200  $conds['ipb_sitewide'] = 1;
201  } elseif ( $this->blockType === 'partial' ) {
202  $conds['ipb_sitewide'] = 0;
203  }
204 
205  return new BlockListPager(
206  $this,
207  $conds,
208  MediaWikiServices::getInstance()->getLinkBatchFactory()
209  );
210  }
211 
216  protected function showList( BlockListPager $pager ) {
217  $out = $this->getOutput();
218 
219  # Check for other blocks, i.e. global/tor blocks
220  $otherBlockLink = [];
221  $this->getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
222 
223  # Show additional header for the local block only when other blocks exists.
224  # Not necessary in a standard installation without such extensions enabled
225  if ( count( $otherBlockLink ) ) {
226  $out->addHTML(
227  Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
228  );
229  }
230 
231  if ( $pager->getNumRows() ) {
232  $out->addParserOutputContent( $pager->getFullOutput() );
233  } elseif ( $this->target ) {
234  $out->addWikiMsg( 'ipblocklist-no-results' );
235  } else {
236  $out->addWikiMsg( 'ipblocklist-empty' );
237  }
238 
239  if ( count( $otherBlockLink ) ) {
240  $out->addHTML(
242  'h2',
243  [],
244  $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
245  ) . "\n"
246  );
247  $list = '';
248  foreach ( $otherBlockLink as $link ) {
249  $list .= Html::rawElement( 'li', [], $link ) . "\n";
250  }
251  $out->addHTML( Html::rawElement(
252  'ul',
253  [ 'class' => 'mw-ipblocklist-otherblocks' ],
254  $list
255  ) . "\n" );
256  }
257  }
258 
259  protected function getGroupName() {
260  return 'users';
261  }
262 
268  protected function getDB() {
269  return wfGetDB( DB_REPLICA );
270  }
271 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:697
SpecialBlockList\$blockType
$blockType
Definition: SpecialBlockList.php:39
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:828
SpecialBlockList\execute
execute( $par)
Definition: SpecialBlockList.php:48
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:744
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:157
BlockListPager
Definition: BlockListPager.php:35
SpecialBlockList\$options
$options
Definition: SpecialBlockList.php:37
TablePager\getFullOutput
getFullOutput()
Get the formatted result list, with navigation bars.
Definition: TablePager.php:111
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:92
SpecialBlockList\getBlockListPager
getBlockListPager()
Setup a new BlockListPager instance.
Definition: SpecialBlockList.php:137
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SpecialBlockList\$target
$target
Definition: SpecialBlockList.php:35
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:31
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:864
LIST_OR
const LIST_OR
Definition: Defines.php:51
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1011
getPermissionManager
getPermissionManager()
SpecialBlockList\showList
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
Definition: SpecialBlockList.php:216
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2469
$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:571
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:754
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:717
SpecialBlockList\__construct
__construct()
Definition: SpecialBlockList.php:41
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:41
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:734
SpecialBlockList\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBlockList.php:259
SpecialBlockList
A special page that lists existing blocks.
Definition: SpecialBlockList.php:34
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
SpecialBlockList\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialBlockList.php:268
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:315
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:662
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:731
$type
$type
Definition: testCompression.php:52