3 * Implements Special:BlockList
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 use MediaWiki\Block\DatabaseBlock
;
27 * A special page that lists existing blocks
29 * @ingroup SpecialPage
31 class SpecialBlockList
extends SpecialPage
{
38 function __construct() {
39 parent
::__construct( 'BlockList' );
43 * @param string|null $par Title fragment
45 public function execute( $par ) {
47 $this->outputHeader();
48 $out = $this->getOutput();
49 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
50 $out->addModuleStyles( [ 'mediawiki.special' ] );
52 $request = $this->getRequest();
53 $par = $request->getVal( 'ip', $par );
54 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
56 $this->options
= $request->getArray( 'wpOptions', [] );
57 $this->blockType
= $request->getVal( 'blockType' );
59 $action = $request->getText( 'action' );
61 if ( $action == 'unblock' ||
$action == 'submit' && $request->wasPosted() ) {
62 # B/C @since 1.18: Unblock interface is now at Special:Unblock
63 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
64 $out->redirect( $title->getFullURL() );
69 # setup BlockListPager here to get the actual default Limit
70 $pager = $this->getBlockListPager();
72 # Just show the block list
76 'label-message' => 'ipaddressorusername',
79 'default' => $this->target
,
82 'type' => 'multiselect',
83 'options-messages' => [
84 'blocklist-userblocks' => 'userblocks',
85 'blocklist-tempblocks' => 'tempblocks',
86 'blocklist-addressblocks' => 'addressblocks',
87 'blocklist-rangeblocks' => 'rangeblocks',
93 if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
94 $fields['BlockType'] = [
96 'label-message' => 'blocklist-type',
98 $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
99 $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
100 $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
102 'name' => 'blockType',
103 'cssclass' => 'mw-field-block-type',
108 'type' => 'limitselect',
109 'label-message' => 'table_pager_limit_label',
110 'options' => $pager->getLimitSelectList(),
112 'default' => $pager->getLimit(),
113 'cssclass' => $this->getConfig()->get( 'EnablePartialBlocks' ) ?
114 'mw-field-limit mw-has-field-block-type' :
118 $context = new DerivativeContext( $this->getContext() );
119 $context->setTitle( $this->getPageTitle() ); // Remove subpage
120 $form = HTMLForm
::factory( 'ooui', $fields, $context );
123 ->setFormIdentifier( 'blocklist' )
124 ->setWrapperLegendMsg( 'ipblocklist-legend' )
125 ->setSubmitTextMsg( 'ipblocklist-submit' )
127 ->displayForm( false );
129 $this->showList( $pager );
133 * Setup a new BlockListPager instance.
134 * @return BlockListPager
136 protected function getBlockListPager() {
138 # Is the user allowed to see hidden blocks?
139 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
140 $conds['ipb_deleted'] = 0;
143 if ( $this->target
!== '' ) {
144 list( $target, $type ) = DatabaseBlock
::parseTarget( $this->target
);
147 case DatabaseBlock
::TYPE_ID
:
148 case DatabaseBlock
::TYPE_AUTO
:
149 $conds['ipb_id'] = $target;
152 case DatabaseBlock
::TYPE_IP
:
153 case DatabaseBlock
::TYPE_RANGE
:
154 list( $start, $end ) = IP
::parseRange( $target );
155 $conds[] = wfGetDB( DB_REPLICA
)->makeList(
157 'ipb_address' => $target,
158 DatabaseBlock
::getRangeCond( $start, $end )
162 $conds['ipb_auto'] = 0;
165 case DatabaseBlock
::TYPE_USER
:
166 $conds['ipb_address'] = $target->getName();
167 $conds['ipb_auto'] = 0;
173 if ( in_array( 'userblocks', $this->options
) ) {
174 $conds['ipb_user'] = 0;
176 if ( in_array( 'tempblocks', $this->options
) ) {
177 $conds['ipb_expiry'] = 'infinity';
179 if ( in_array( 'addressblocks', $this->options
) ) {
180 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
182 if ( in_array( 'rangeblocks', $this->options
) ) {
183 $conds[] = "ipb_range_end = ipb_range_start";
186 if ( $this->blockType
=== 'sitewide' ) {
187 $conds[] = 'ipb_sitewide = 1';
188 } elseif ( $this->blockType
=== 'partial' ) {
189 $conds[] = 'ipb_sitewide = 0';
192 return new BlockListPager( $this, $conds );
196 * Show the list of blocked accounts matching the actual filter.
197 * @param BlockListPager $pager The BlockListPager instance for this page
199 protected function showList( BlockListPager
$pager ) {
200 $out = $this->getOutput();
202 # Check for other blocks, i.e. global/tor blocks
203 $otherBlockLink = [];
204 Hooks
::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target
] );
206 # Show additional header for the local block only when other blocks exists.
207 # Not necessary in a standard installation without such extensions enabled
208 if ( count( $otherBlockLink ) ) {
210 Html
::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
214 if ( $pager->getNumRows() ) {
215 $out->addParserOutputContent( $pager->getFullOutput() );
216 } elseif ( $this->target
) {
217 $out->addWikiMsg( 'ipblocklist-no-results' );
219 $out->addWikiMsg( 'ipblocklist-empty' );
222 if ( count( $otherBlockLink ) ) {
227 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
231 foreach ( $otherBlockLink as $link ) {
232 $list .= Html
::rawElement( 'li', [], $link ) . "\n";
234 $out->addHTML( Html
::rawElement(
236 [ 'class' => 'mw-ipblocklist-otherblocks' ],
242 protected function getGroupName() {