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