MediaWiki  1.30.0
SpecialBlockList.php
Go to the documentation of this file.
1 <?php
30  protected $target;
31 
32  protected $options;
33 
34  function __construct() {
35  parent::__construct( 'BlockList' );
36  }
37 
43  public function execute( $par ) {
44  $this->setHeaders();
45  $this->outputHeader();
46  $out = $this->getOutput();
47  $lang = $this->getLanguage();
48  $out->setPageTitle( $this->msg( 'ipblocklist' ) );
49  $out->addModuleStyles( [ 'mediawiki.special' ] );
50 
51  $request = $this->getRequest();
52  $par = $request->getVal( 'ip', $par );
53  $this->target = trim( $request->getVal( 'wpTarget', $par ) );
54 
55  $this->options = $request->getArray( 'wpOptions', [] );
56 
57  $action = $request->getText( 'action' );
58 
59  if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) {
60  # B/C @since 1.18: Unblock interface is now at Special:Unblock
61  $title = SpecialPage::getTitleFor( 'Unblock', $this->target );
62  $out->redirect( $title->getFullURL() );
63 
64  return;
65  }
66 
67  # setup BlockListPager here to get the actual default Limit
68  $pager = $this->getBlockListPager();
69 
70  # Just show the block list
71  $fields = [
72  'Target' => [
73  'type' => 'user',
74  'label-message' => 'ipaddressorusername',
75  'tabindex' => '1',
76  'size' => '45',
77  'default' => $this->target,
78  ],
79  'Options' => [
80  'type' => 'multiselect',
81  'options-messages' => [
82  'blocklist-userblocks' => 'userblocks',
83  'blocklist-tempblocks' => 'tempblocks',
84  'blocklist-addressblocks' => 'addressblocks',
85  'blocklist-rangeblocks' => 'rangeblocks',
86  ],
87  'flatlist' => true,
88  ],
89  'Limit' => [
90  'type' => 'limitselect',
91  'label-message' => 'table_pager_limit_label',
92  'options' => [
93  $lang->formatNum( 20 ) => 20,
94  $lang->formatNum( 50 ) => 50,
95  $lang->formatNum( 100 ) => 100,
96  $lang->formatNum( 250 ) => 250,
97  $lang->formatNum( 500 ) => 500,
98  ],
99  'name' => 'limit',
100  'default' => $pager->getLimit(),
101  ],
102  ];
103  $context = new DerivativeContext( $this->getContext() );
104  $context->setTitle( $this->getPageTitle() ); // Remove subpage
105  $form = HTMLForm::factory( 'ooui', $fields, $context );
106  $form
107  ->setMethod( 'get' )
108  ->setFormIdentifier( 'blocklist' )
109  ->setWrapperLegendMsg( 'ipblocklist-legend' )
110  ->setSubmitTextMsg( 'ipblocklist-submit' )
111  ->setSubmitProgressive()
112  ->prepareForm()
113  ->displayForm( false );
114 
115  $this->showList( $pager );
116  }
117 
122  protected function getBlockListPager() {
123  $conds = [];
124  # Is the user allowed to see hidden blocks?
125  if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
126  $conds['ipb_deleted'] = 0;
127  }
128 
129  if ( $this->target !== '' ) {
130  list( $target, $type ) = Block::parseTarget( $this->target );
131 
132  switch ( $type ) {
133  case Block::TYPE_ID:
134  case Block::TYPE_AUTO:
135  $conds['ipb_id'] = $target;
136  break;
137 
138  case Block::TYPE_IP:
139  case Block::TYPE_RANGE:
140  list( $start, $end ) = IP::parseRange( $target );
141  $conds[] = wfGetDB( DB_REPLICA )->makeList(
142  [
143  'ipb_address' => $target,
144  Block::getRangeCond( $start, $end )
145  ],
146  LIST_OR
147  );
148  $conds['ipb_auto'] = 0;
149  break;
150 
151  case Block::TYPE_USER:
152  $conds['ipb_address'] = $target->getName();
153  $conds['ipb_auto'] = 0;
154  break;
155  }
156  }
157 
158  # Apply filters
159  if ( in_array( 'userblocks', $this->options ) ) {
160  $conds['ipb_user'] = 0;
161  }
162  if ( in_array( 'tempblocks', $this->options ) ) {
163  $conds['ipb_expiry'] = 'infinity';
164  }
165  if ( in_array( 'addressblocks', $this->options ) ) {
166  $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
167  }
168  if ( in_array( 'rangeblocks', $this->options ) ) {
169  $conds[] = "ipb_range_end = ipb_range_start";
170  }
171 
172  return new BlockListPager( $this, $conds );
173  }
174 
179  protected function showList( BlockListPager $pager ) {
180  $out = $this->getOutput();
181 
182  # Check for other blocks, i.e. global/tor blocks
183  $otherBlockLink = [];
184  Hooks::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target ] );
185 
186  # Show additional header for the local block only when other blocks exists.
187  # Not necessary in a standard installation without such extensions enabled
188  if ( count( $otherBlockLink ) ) {
189  $out->addHTML(
190  Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
191  );
192  }
193 
194  if ( $pager->getNumRows() ) {
195  $out->addParserOutputContent( $pager->getFullOutput() );
196  } elseif ( $this->target ) {
197  $out->addWikiMsg( 'ipblocklist-no-results' );
198  } else {
199  $out->addWikiMsg( 'ipblocklist-empty' );
200  }
201 
202  if ( count( $otherBlockLink ) ) {
203  $out->addHTML(
205  'h2',
206  [],
207  $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
208  ) . "\n"
209  );
210  $list = '';
211  foreach ( $otherBlockLink as $link ) {
212  $list .= Html::rawElement( 'li', [], $link ) . "\n";
213  }
214  $out->addHTML( Html::rawElement(
215  'ul',
216  [ 'class' => 'mw-ipblocklist-otherblocks' ],
217  $list
218  ) . "\n" );
219  }
220  }
221 
222  protected function getGroupName() {
223  return 'users';
224  }
225 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
SpecialBlockList\execute
execute( $par)
Main execution point.
Definition: SpecialBlockList.php:43
$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:2581
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
Block\TYPE_IP
const TYPE_IP
Definition: Block.php:84
captcha-old.count
count
Definition: captcha-old.py:249
Block\TYPE_RANGE
const TYPE_RANGE
Definition: Block.php:85
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
BlockListPager
Definition: BlockListPager.php:28
SpecialBlockList\$options
$options
Definition: SpecialBlockList.php:32
TablePager\getFullOutput
getFullOutput()
Get the formatted result list, with navigation bars.
Definition: TablePager.php:99
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:82
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:705
SpecialBlockList\getBlockListPager
getBlockListPager()
Setup a new BlockListPager instance.
Definition: SpecialBlockList.php:122
php
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
SpecialBlockList\$target
$target
Definition: SpecialBlockList.php:30
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
LIST_OR
const LIST_OR
Definition: Defines.php:47
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
Block\parseTarget
static parseTarget( $target)
From an existing Block, get the target and the type of target.
Definition: Block.php:1334
SpecialBlockList\showList
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
Definition: SpecialBlockList.php:179
Block\getRangeCond
static getRangeCond( $start, $end=null)
Get a set of SQL conditions which will select rangeblocks encompassing a given range.
Definition: Block.php:360
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
Block\TYPE_ID
const TYPE_ID
Definition: Block.php:87
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
list
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
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
SpecialBlockList\__construct
__construct()
Definition: SpecialBlockList.php:34
$request
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:2581
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
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:513
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
options
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
SpecialBlockList\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialBlockList.php:222
Block\TYPE_AUTO
const TYPE_AUTO
Definition: Block.php:86
Block\TYPE_USER
const TYPE_USER
Definition: Block.php:83
SpecialBlockList
A special page that lists existing blocks.
Definition: SpecialBlockList.php:29
as
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2981
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
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:583
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:555
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:781
$type
$type
Definition: testCompression.php:48