9use InvalidArgumentException;
19use MediaWiki\Cache\LinkBatchFactory;
24use MediaWiki\Pager\BlockListPager;
49 private LinkBatchFactory $linkBatchFactory;
61 LinkBatchFactory $linkBatchFactory,
72 parent::__construct(
'BlockList' );
74 $this->linkBatchFactory = $linkBatchFactory;
75 $this->blockStore = $blockStore;
76 $this->blockRestrictionStore = $blockRestrictionStore;
77 $this->dbProvider = $dbProvider;
78 $this->commentStore = $commentStore;
79 $this->blockTargetFactory = $blockTargetFactory;
80 $this->hideUserUtils = $hideUserUtils;
81 $this->blockActionInfo = $blockActionInfo;
82 $this->rowCommentFormatter = $rowCommentFormatter;
83 $this->tempUserConfig = $tempUserConfig;
94 $out->setPageTitleMsg( $this->
msg(
'ipblocklist' ) );
95 $out->addModuleStyles( [
'mediawiki.special' ] );
98 $par = $request->getVal(
'ip', $par ??
'' );
99 $this->target = trim( $request->getVal(
'wpTarget', $par ) );
101 $this->options = $request->getArray(
'wpOptions', [] );
102 $this->blockType = $request->getVal(
'blockType' );
104 $action = $request->getText(
'action' );
106 if ( $action ==
'unblock' || ( $action ==
'submit' && $request->wasPosted() ) ) {
109 $out->redirect( $title->getFullURL() );
117 $blockFilterOptions = [
118 'blocklist-tempblocks' =>
'tempblocks',
119 'blocklist-indefblocks' =>
'indefblocks',
120 'blocklist-autoblocks' =>
'autoblocks',
121 'blocklist-addressblocks' =>
'addressblocks',
122 'blocklist-rangeblocks' =>
'rangeblocks',
125 if ( $this->tempUserConfig->isKnown() ) {
127 $blockFilterOptions[
'blocklist-nameduserblocks'] =
'userblocks';
128 $blockFilterOptions[
'blocklist-tempuserblocks'] =
'tempuserblocks';
130 $blockFilterOptions[
'blocklist-userblocks'] =
'userblocks';
137 'label-message' =>
'ipaddressorusername',
143 'type' =>
'multiselect',
144 'options-messages' => $blockFilterOptions,
149 $fields[
'BlockType'] = [
151 'label-message' =>
'blocklist-type',
153 $this->
msg(
'blocklist-type-opt-all' )->escaped() =>
'',
154 $this->
msg(
'blocklist-type-opt-sitewide' )->escaped() =>
'sitewide',
155 $this->
msg(
'blocklist-type-opt-partial' )->escaped() =>
'partial',
157 'name' =>
'blockType',
158 'cssclass' =>
'mw-field-block-type',
162 'type' =>
'limitselect',
163 'label-message' =>
'table_pager_limit_label',
164 'options' => $pager->getLimitSelectList(),
166 'default' => $pager->getLimit(),
167 'cssclass' =>
'mw-field-limit mw-has-field-block-type',
170 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
174 ->setFormIdentifier(
'blocklist' )
175 ->setWrapperLegendMsg(
'ipblocklist-legend' )
176 ->setSubmitTextMsg(
'ipblocklist-submit' )
178 ->displayForm(
false );
189 $db = $this->
getDB();
192 if ( $this->target !==
'' ) {
193 $target = $this->blockTargetFactory->newFromString( $this->target );
195 $conds = $this->getTargetConds(
$target );
200 if ( in_array(
'userblocks', $this->options ) ) {
201 $namedUserConds = $db->expr(
'bt_user',
'=',
null );
205 if ( $this->tempUserConfig->isKnown() ) {
206 $namedUserConds = $namedUserConds->orExpr(
207 $this->tempUserConfig->getMatchCondition( $db,
'bt_user_text', IExpression::LIKE )
211 $conds[] = $namedUserConds;
213 if ( in_array(
'autoblocks', $this->options ) ) {
214 $conds[
'bl_parent_block_id'] =
null;
216 if ( in_array(
'addressblocks', $this->options )
217 && in_array(
'rangeblocks', $this->options )
220 $conds[] = $db->expr(
'bt_user',
'!=',
null );
221 } elseif ( in_array(
'addressblocks', $this->options ) ) {
222 $conds[] = $db->expr(
'bt_user',
'!=',
null )->or(
'bt_range_start',
'!=',
null );
223 } elseif ( in_array(
'rangeblocks', $this->options ) ) {
224 $conds[
'bt_range_start'] =
null;
228 in_array(
'tempuserblocks', $this->options ) &&
229 $this->tempUserConfig->isKnown()
231 $conds[] = $db->expr(
'bt_user',
'=',
null )
233 $this->tempUserConfig->getMatchCondition( $db,
'bt_user_text', IExpression::NOT_LIKE )
237 $hideTemp = in_array(
'tempblocks', $this->options );
238 $hideIndef = in_array(
'indefblocks', $this->options );
239 if ( $hideTemp && $hideIndef ) {
242 } elseif ( $hideTemp ) {
243 $conds[
'bl_expiry'] = $db->getInfinity();
244 } elseif ( $hideIndef ) {
245 $conds[] = $db->expr(
'bl_expiry',
'!=', $db->getInfinity() );
248 if ( $this->blockType ===
'sitewide' ) {
249 $conds[
'bl_sitewide'] = 1;
250 } elseif ( $this->blockType ===
'partial' ) {
251 $conds[
'bl_sitewide'] = 0;
254 return new BlockListPager(
256 $this->blockActionInfo,
257 $this->blockRestrictionStore,
258 $this->blockTargetFactory,
259 $this->hideUserUtils,
261 $this->linkBatchFactory,
264 $this->rowCommentFormatter,
285 return [
'bl_id' =>
$target->getId() ];
287 if (
$target instanceof BlockTargetWithIp ) {
288 $range =
$target->toHexRange();
290 $this->blockStore->getRangeCond( $range[0], $range[1] ),
294 if (
$target instanceof UserBlockTarget ) {
295 $user =
$target->getUserIdentity();
296 if ( $user->getId() ) {
298 'bt_user' => $user->getId(),
306 throw new InvalidArgumentException(
'Invalid block target type' );
313 protected function showList( BlockListPager $pager ) {
317 $otherBlockLink = [];
318 $this->
getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
322 if ( count( $otherBlockLink ) ) {
324 Html::element(
'h2', [], $this->
msg(
'ipblocklist-localblock' )->text() ) .
"\n"
328 if ( $pager->getNumRows() ) {
329 $out->addParserOutputContent(
330 $pager->getFullOutput(),
331 ParserOptions::newFromContext( $this->getContext() )
333 } elseif ( $this->target ) {
334 $out->addWikiMsg(
'ipblocklist-no-results' );
336 $out->addWikiMsg(
'ipblocklist-empty' );
339 if ( count( $otherBlockLink ) ) {
344 $this->
msg(
'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
348 foreach ( $otherBlockLink as $link ) {
349 $list .= Html::rawElement(
'li', [], $link ) .
"\n";
351 $out->addHTML( Html::rawElement(
353 [
'class' =>
'mw-ipblocklist-otherblocks' ],
370 return $this->dbProvider->getReplicaDatabase();
375class_alias( SpecialBlockList::class,
'SpecialBlockList' );
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.