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 $this->addHelpLink( 'Help:Blocking_users' );
49 $out = $this->getOutput();
50 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
51 $out->addModuleStyles( [ 'mediawiki.special' ] );
53 $request = $this->getRequest();
54 $par = $request->getVal( 'ip', $par );
55 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
57 $this->options
= $request->getArray( 'wpOptions', [] );
58 $this->blockType
= $request->getVal( 'blockType' );
60 $action = $request->getText( 'action' );
62 if ( $action == 'unblock' ||
$action == 'submit' && $request->wasPosted() ) {
63 # B/C @since 1.18: Unblock interface is now at Special:Unblock
64 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
65 $out->redirect( $title->getFullURL() );
70 # setup BlockListPager here to get the actual default Limit
71 $pager = $this->getBlockListPager();
73 # Just show the block list
77 'label-message' => 'ipaddressorusername',
80 'default' => $this->target
,
83 'type' => 'multiselect',
84 'options-messages' => [
85 'blocklist-userblocks' => 'userblocks',
86 'blocklist-tempblocks' => 'tempblocks',
87 'blocklist-addressblocks' => 'addressblocks',
88 'blocklist-rangeblocks' => 'rangeblocks',
94 if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
95 $fields['BlockType'] = [
97 'label-message' => 'blocklist-type',
99 $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
100 $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
101 $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
103 'name' => 'blockType',
104 'cssclass' => 'mw-field-block-type',
109 'type' => 'limitselect',
110 'label-message' => 'table_pager_limit_label',
111 'options' => $pager->getLimitSelectList(),
113 'default' => $pager->getLimit(),
114 'cssclass' => $this->getConfig()->get( 'EnablePartialBlocks' ) ?
115 'mw-field-limit mw-has-field-block-type' :
119 $context = new DerivativeContext( $this->getContext() );
120 $context->setTitle( $this->getPageTitle() ); // Remove subpage
121 $form = HTMLForm
::factory( 'ooui', $fields, $context );
124 ->setFormIdentifier( 'blocklist' )
125 ->setWrapperLegendMsg( 'ipblocklist-legend' )
126 ->setSubmitTextMsg( 'ipblocklist-submit' )
128 ->displayForm( false );
130 $this->showList( $pager );
134 * Setup a new BlockListPager instance.
135 * @return BlockListPager
137 protected function getBlockListPager() {
139 # Is the user allowed to see hidden blocks?
140 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
141 $conds['ipb_deleted'] = 0;
144 if ( $this->target
!== '' ) {
145 list( $target, $type ) = DatabaseBlock
::parseTarget( $this->target
);
148 case DatabaseBlock
::TYPE_ID
:
149 case DatabaseBlock
::TYPE_AUTO
:
150 $conds['ipb_id'] = $target;
153 case DatabaseBlock
::TYPE_IP
:
154 case DatabaseBlock
::TYPE_RANGE
:
155 list( $start, $end ) = IP
::parseRange( $target );
156 $conds[] = wfGetDB( DB_REPLICA
)->makeList(
158 'ipb_address' => $target,
159 DatabaseBlock
::getRangeCond( $start, $end )
163 $conds['ipb_auto'] = 0;
166 case DatabaseBlock
::TYPE_USER
:
167 $conds['ipb_address'] = $target->getName();
168 $conds['ipb_auto'] = 0;
174 if ( in_array( 'userblocks', $this->options
) ) {
175 $conds['ipb_user'] = 0;
177 if ( in_array( 'tempblocks', $this->options
) ) {
178 $conds['ipb_expiry'] = 'infinity';
180 if ( in_array( 'addressblocks', $this->options
) ) {
181 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
183 if ( in_array( 'rangeblocks', $this->options
) ) {
184 $conds[] = "ipb_range_end = ipb_range_start";
187 if ( $this->blockType
=== 'sitewide' ) {
188 $conds[] = 'ipb_sitewide = 1';
189 } elseif ( $this->blockType
=== 'partial' ) {
190 $conds[] = 'ipb_sitewide = 0';
193 return new BlockListPager( $this, $conds );
197 * Show the list of blocked accounts matching the actual filter.
198 * @param BlockListPager $pager The BlockListPager instance for this page
200 protected function showList( BlockListPager
$pager ) {
201 $out = $this->getOutput();
203 # Check for other blocks, i.e. global/tor blocks
204 $otherBlockLink = [];
205 Hooks
::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target
] );
207 # Show additional header for the local block only when other blocks exists.
208 # Not necessary in a standard installation without such extensions enabled
209 if ( count( $otherBlockLink ) ) {
211 Html
::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
215 if ( $pager->getNumRows() ) {
216 $out->addParserOutputContent( $pager->getFullOutput() );
217 } elseif ( $this->target
) {
218 $out->addWikiMsg( 'ipblocklist-no-results' );
220 $out->addWikiMsg( 'ipblocklist-empty' );
223 if ( count( $otherBlockLink ) ) {
228 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
232 foreach ( $otherBlockLink as $link ) {
233 $list .= Html
::rawElement( 'li', [], $link ) . "\n";
235 $out->addHTML( Html
::rawElement(
237 [ 'class' => 'mw-ipblocklist-otherblocks' ],
243 protected function getGroupName() {