9use InvalidArgumentException;
24use MediaWiki\Pager\BlockListPager;
61 parent::__construct(
'BlockList' );
72 $out->setPageTitleMsg( $this->
msg(
'ipblocklist' ) );
73 $out->addModuleStyles( [
'mediawiki.special' ] );
76 $par = $request->getVal(
'ip', $par ??
'' );
77 $this->target = trim( $request->getVal(
'wpTarget', $par ) );
79 $this->options = $request->getArray(
'wpOptions', [] );
80 $this->blockType = $request->getVal(
'blockType' );
82 $action = $request->getText(
'action' );
84 if ( $action ==
'unblock' || ( $action ==
'submit' && $request->wasPosted() ) ) {
87 $out->redirect( $title->getFullURL() );
95 $blockFilterOptions = [
96 'blocklist-tempblocks' =>
'tempblocks',
97 'blocklist-indefblocks' =>
'indefblocks',
98 'blocklist-autoblocks' =>
'autoblocks',
99 'blocklist-addressblocks' =>
'addressblocks',
100 'blocklist-rangeblocks' =>
'rangeblocks',
103 if ( $this->tempUserConfig->isKnown() ) {
105 $blockFilterOptions[
'blocklist-nameduserblocks'] =
'userblocks';
106 $blockFilterOptions[
'blocklist-tempuserblocks'] =
'tempuserblocks';
108 $blockFilterOptions[
'blocklist-userblocks'] =
'userblocks';
115 'label-message' =>
'ipaddressorusername',
121 'type' =>
'multiselect',
122 'options-messages' => $blockFilterOptions,
127 $fields[
'BlockType'] = [
129 'label-message' =>
'blocklist-type',
131 $this->
msg(
'blocklist-type-opt-all' )->escaped() =>
'',
132 $this->
msg(
'blocklist-type-opt-sitewide' )->escaped() =>
'sitewide',
133 $this->
msg(
'blocklist-type-opt-partial' )->escaped() =>
'partial',
135 'name' =>
'blockType',
136 'cssclass' =>
'mw-field-block-type',
140 'type' =>
'limitselect',
141 'label-message' =>
'table_pager_limit_label',
142 'options' => $pager->getLimitSelectList(),
144 'default' => $pager->getLimit(),
145 'cssclass' =>
'mw-field-limit mw-has-field-block-type',
148 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
152 ->setFormIdentifier(
'blocklist' )
153 ->setWrapperLegendMsg(
'ipblocklist-legend' )
154 ->setSubmitTextMsg(
'ipblocklist-submit' )
156 ->displayForm(
false );
167 $db = $this->
getDB();
170 if ( $this->target !==
'' ) {
171 $target = $this->blockTargetFactory->newFromString( $this->target );
173 $conds = $this->getTargetConds(
$target );
178 if ( in_array(
'userblocks', $this->options ) ) {
179 $namedUserConds = $db->expr(
'bt_user',
'=',
null );
183 if ( $this->tempUserConfig->isKnown() ) {
184 $namedUserConds = $namedUserConds->orExpr(
185 $this->tempUserConfig->getMatchCondition( $db,
'bt_user_text', IExpression::LIKE )
189 $conds[] = $namedUserConds;
191 if ( in_array(
'autoblocks', $this->options ) ) {
192 $conds[
'bl_parent_block_id'] =
null;
194 if ( in_array(
'addressblocks', $this->options )
195 && in_array(
'rangeblocks', $this->options )
198 $conds[] = $db->expr(
'bt_user',
'!=',
null );
199 } elseif ( in_array(
'addressblocks', $this->options ) ) {
200 $conds[] = $db->expr(
'bt_user',
'!=',
null )->or(
'bt_range_start',
'!=',
null );
201 } elseif ( in_array(
'rangeblocks', $this->options ) ) {
202 $conds[
'bt_range_start'] =
null;
206 in_array(
'tempuserblocks', $this->options ) &&
207 $this->tempUserConfig->isKnown()
209 $conds[] = $db->expr(
'bt_user',
'=',
null )
211 $this->tempUserConfig->getMatchCondition( $db,
'bt_user_text', IExpression::NOT_LIKE )
215 $hideTemp = in_array(
'tempblocks', $this->options );
216 $hideIndef = in_array(
'indefblocks', $this->options );
217 if ( $hideTemp && $hideIndef ) {
220 } elseif ( $hideTemp ) {
221 $conds[
'bl_expiry'] = $db->getInfinity();
222 } elseif ( $hideIndef ) {
223 $conds[] = $db->expr(
'bl_expiry',
'!=', $db->getInfinity() );
226 if ( $this->blockType ===
'sitewide' ) {
227 $conds[
'bl_sitewide'] = 1;
228 } elseif ( $this->blockType ===
'partial' ) {
229 $conds[
'bl_sitewide'] = 0;
232 return new BlockListPager(
234 $this->blockActionInfo,
235 $this->blockRestrictionStore,
236 $this->blockTargetFactory,
237 $this->hideUserUtils,
239 $this->linkBatchFactory,
242 $this->rowCommentFormatter,
263 return [
'bl_id' =>
$target->getId() ];
265 if (
$target instanceof BlockTargetWithIp ) {
266 $range =
$target->toHexRange();
268 $this->blockStore->getRangeCond( $range[0], $range[1] ),
272 if (
$target instanceof UserBlockTarget ) {
273 $user =
$target->getUserIdentity();
274 if ( $user->getId() ) {
276 'bt_user' => $user->getId(),
284 throw new InvalidArgumentException(
'Invalid block target type' );
291 protected function showList( BlockListPager $pager ) {
295 $otherBlockLink = [];
296 $this->
getHookRunner()->onOtherBlockLogLink( $otherBlockLink, $this->target );
300 if ( count( $otherBlockLink ) ) {
302 Html::element(
'h2', [], $this->
msg(
'ipblocklist-localblock' )->text() ) .
"\n"
306 if ( $pager->getNumRows() ) {
307 $out->addParserOutputContent(
308 $pager->getFullOutput(),
309 ParserOptions::newFromContext( $this->getContext() )
311 } elseif ( $this->target ) {
312 $out->addWikiMsg(
'ipblocklist-no-results' );
314 $out->addWikiMsg(
'ipblocklist-empty' );
317 if ( count( $otherBlockLink ) ) {
322 $this->
msg(
'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
326 foreach ( $otherBlockLink as $link ) {
327 $list .= Html::rawElement(
'li', [], $link ) .
"\n";
329 $out->addHTML( Html::rawElement(
331 [
'class' =>
'mw-ipblocklist-otherblocks' ],
348 return $this->dbProvider->getReplicaDatabase();
353class_alias( SpecialBlockList::class,
'SpecialBlockList' );
Factory for LinkBatch objects to batch query page metadata.
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.