MediaWiki REL1_35
SpecialBlockList.php
Go to the documentation of this file.
1<?php
26use 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( $this, $conds );
206 }
207
212 protected function showList( BlockListPager $pager ) {
213 $out = $this->getOutput();
214
215 # Check for other blocks, i.e. global/tor blocks
216 $otherBlockLink = [];
217 $this->getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
218
219 # Show additional header for the local block only when other blocks exists.
220 # Not necessary in a standard installation without such extensions enabled
221 if ( count( $otherBlockLink ) ) {
222 $out->addHTML(
223 Html::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
224 );
225 }
226
227 if ( $pager->getNumRows() ) {
228 $out->addParserOutputContent( $pager->getFullOutput() );
229 } elseif ( $this->target ) {
230 $out->addWikiMsg( 'ipblocklist-no-results' );
231 } else {
232 $out->addWikiMsg( 'ipblocklist-empty' );
233 }
234
235 if ( count( $otherBlockLink ) ) {
236 $out->addHTML(
237 Html::rawElement(
238 'h2',
239 [],
240 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
241 ) . "\n"
242 );
243 $list = '';
244 foreach ( $otherBlockLink as $link ) {
245 $list .= Html::rawElement( 'li', [], $link ) . "\n";
246 }
247 $out->addHTML( Html::rawElement(
248 'ul',
249 [ 'class' => 'mw-ipblocklist-otherblocks' ],
250 $list
251 ) . "\n" );
252 }
253 }
254
255 protected function getGroupName() {
256 return 'users';
257 }
258
264 protected function getDB() {
265 return wfGetDB( DB_REPLICA );
266 }
267}
getPermissionManager()
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
An IContextSource implementation which will inherit context from another source but allow individual ...
getNumRows()
Get the number of rows in the result set.
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
MediaWikiServices is the service locator for the application scope of MediaWiki.
A special page that lists existing blocks.
getDB()
Return a IDatabase object for reading.
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
getBlockListPager()
Setup a new BlockListPager instance.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
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,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getFullOutput()
Get the formatted result list, with navigation bars.
const LIST_OR
Definition Defines.php:52
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
const DB_REPLICA
Definition defines.php:25