MediaWiki  master
SpecialBlockList.php
Go to the documentation of this file.
1 <?php
25 
32  protected $target;
33 
34  protected $options;
35 
36  protected $blockType;
37 
38  function __construct() {
39  parent::__construct( 'BlockList' );
40  }
41 
45  public function execute( $par ) {
46  $this->setHeaders();
47  $this->outputHeader();
48  $this->addHelpLink( 'Help:Blocking_users' );
49  $out = $this->getOutput();
50  $out->setPageTitle( $this->msg( 'ipblocklist' ) );
51  $out->addModuleStyles( [ 'mediawiki.special' ] );
52 
53  $request = $this->getRequest();
54  $par = $request->getVal( 'ip', $par );
55  $this->target = trim( $request->getVal( 'wpTarget', $par ) );
56 
57  $this->options = $request->getArray( 'wpOptions', [] );
58  $this->blockType = $request->getVal( 'blockType' );
59 
60  $action = $request->getText( 'action' );
61 
62  if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) {
63  # B/C @since 1.18: Unblock interface is now at Special:Unblock
64  $title = SpecialPage::getTitleFor( 'Unblock', $this->target );
65  $out->redirect( $title->getFullURL() );
66 
67  return;
68  }
69 
70  # setup BlockListPager here to get the actual default Limit
71  $pager = $this->getBlockListPager();
72 
73  # Just show the block list
74  $fields = [
75  'Target' => [
76  'type' => 'user',
77  'label-message' => 'ipaddressorusername',
78  'tabindex' => '1',
79  'size' => '45',
80  'default' => $this->target,
81  ],
82  'Options' => [
83  'type' => 'multiselect',
84  'options-messages' => [
85  'blocklist-userblocks' => 'userblocks',
86  'blocklist-tempblocks' => 'tempblocks',
87  'blocklist-addressblocks' => 'addressblocks',
88  'blocklist-rangeblocks' => 'rangeblocks',
89  ],
90  'flatlist' => true,
91  ],
92  ];
93 
94  if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
95  $fields['BlockType'] = [
96  'type' => 'select',
97  'label-message' => 'blocklist-type',
98  'options' => [
99  $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
100  $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
101  $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
102  ],
103  'name' => 'blockType',
104  'cssclass' => 'mw-field-block-type',
105  ];
106  }
107 
108  $fields['Limit'] = [
109  'type' => 'limitselect',
110  'label-message' => 'table_pager_limit_label',
111  'options' => $pager->getLimitSelectList(),
112  'name' => 'limit',
113  'default' => $pager->getLimit(),
114  'cssclass' => $this->getConfig()->get( 'EnablePartialBlocks' ) ?
115  'mw-field-limit mw-has-field-block-type' :
116  'mw-field-limit',
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  # Is the user allowed to see hidden blocks?
140  if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
141  $conds['ipb_deleted'] = 0;
142  }
143 
144  if ( $this->target !== '' ) {
145  list( $target, $type ) = DatabaseBlock::parseTarget( $this->target );
146 
147  switch ( $type ) {
148  case DatabaseBlock::TYPE_ID:
149  case DatabaseBlock::TYPE_AUTO:
150  $conds['ipb_id'] = $target;
151  break;
152 
153  case DatabaseBlock::TYPE_IP:
154  case DatabaseBlock::TYPE_RANGE:
155  list( $start, $end ) = IP::parseRange( $target );
156  $conds[] = wfGetDB( DB_REPLICA )->makeList(
157  [
158  'ipb_address' => $target,
159  DatabaseBlock::getRangeCond( $start, $end )
160  ],
161  LIST_OR
162  );
163  $conds['ipb_auto'] = 0;
164  break;
165 
166  case DatabaseBlock::TYPE_USER:
167  $conds['ipb_address'] = $target->getName();
168  $conds['ipb_auto'] = 0;
169  break;
170  }
171  }
172 
173  # Apply filters
174  if ( in_array( 'userblocks', $this->options ) ) {
175  $conds['ipb_user'] = 0;
176  }
177  if ( in_array( 'tempblocks', $this->options ) ) {
178  $conds['ipb_expiry'] = 'infinity';
179  }
180  if ( in_array( 'addressblocks', $this->options ) ) {
181  $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
182  }
183  if ( in_array( 'rangeblocks', $this->options ) ) {
184  $conds[] = "ipb_range_end = ipb_range_start";
185  }
186 
187  if ( $this->blockType === 'sitewide' ) {
188  $conds[] = 'ipb_sitewide = 1';
189  } elseif ( $this->blockType === 'partial' ) {
190  $conds[] = 'ipb_sitewide = 0';
191  }
192 
193  return new BlockListPager( $this, $conds );
194  }
195 
200  protected function showList( BlockListPager $pager ) {
201  $out = $this->getOutput();
202 
203  # Check for other blocks, i.e. global/tor blocks
204  $otherBlockLink = [];
205  Hooks::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target ] );
206 
207  # Show additional header for the local block only when other blocks exists.
208  # Not necessary in a standard installation without such extensions enabled
209  if ( count( $otherBlockLink ) ) {
210  $out->addHTML(
211  Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
212  );
213  }
214 
215  if ( $pager->getNumRows() ) {
216  $out->addParserOutputContent( $pager->getFullOutput() );
217  } elseif ( $this->target ) {
218  $out->addWikiMsg( 'ipblocklist-no-results' );
219  } else {
220  $out->addWikiMsg( 'ipblocklist-empty' );
221  }
222 
223  if ( count( $otherBlockLink ) ) {
224  $out->addHTML(
226  'h2',
227  [],
228  $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
229  ) . "\n"
230  );
231  $list = '';
232  foreach ( $otherBlockLink as $link ) {
233  $list .= Html::rawElement( 'li', [], $link ) . "\n";
234  }
235  $out->addHTML( Html::rawElement(
236  'ul',
237  [ 'class' => 'mw-ipblocklist-otherblocks' ],
238  $list
239  ) . "\n" );
240  }
241  }
242 
243  protected function getGroupName() {
244  return 'users';
245  }
246 }
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
getContext()
Gets the context this SpecialPage is executed in.
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
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
An IContextSource implementation which will inherit context from another source but allow individual ...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getOutput()
Get the OutputPage being used for this instance.
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:299
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3039
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:767
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
A special page that lists existing blocks.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
const LIST_OR
Definition: Defines.php:42
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getBlockListPager()
Setup a new BlockListPager instance.
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
msg( $key)
Wrapper around wfMessage that sets the current context.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2621
const DB_REPLICA
Definition: defines.php:25
getFullOutput()
Get the formatted result list, with navigation bars.
Definition: TablePager.php:101
getRequest()
Get the WebRequest being used for this instance.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2621
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:602