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
25 * A special page that lists existing blocks
27 * @ingroup SpecialPage
29 class SpecialBlockList
extends SpecialPage
{
36 function __construct() {
37 parent
::__construct( 'BlockList' );
41 * @param string|null $par Title fragment
43 public function execute( $par ) {
45 $this->outputHeader();
46 $out = $this->getOutput();
47 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
48 $out->addModuleStyles( [ 'mediawiki.special', 'mediawiki.special.blocklist' ] );
50 $request = $this->getRequest();
51 $par = $request->getVal( 'ip', $par );
52 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
54 $this->options
= $request->getArray( 'wpOptions', [] );
55 $this->blockType
= $request->getVal( 'blockType' );
57 $action = $request->getText( 'action' );
59 if ( $action == 'unblock' ||
$action == 'submit' && $request->wasPosted() ) {
60 # B/C @since 1.18: Unblock interface is now at Special:Unblock
61 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
62 $out->redirect( $title->getFullURL() );
67 # setup BlockListPager here to get the actual default Limit
68 $pager = $this->getBlockListPager();
70 # Just show the block list
74 'label-message' => 'ipaddressorusername',
77 'default' => $this->target
,
80 'type' => 'multiselect',
81 'options-messages' => [
82 'blocklist-userblocks' => 'userblocks',
83 'blocklist-tempblocks' => 'tempblocks',
84 'blocklist-addressblocks' => 'addressblocks',
85 'blocklist-rangeblocks' => 'rangeblocks',
91 if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
92 $fields['BlockType'] = [
94 'label-message' => 'blocklist-type',
96 $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
97 $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
98 $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
100 'name' => 'blockType',
101 'cssclass' => 'mw-field-block-type',
106 'type' => 'limitselect',
107 'label-message' => 'table_pager_limit_label',
108 'options' => $pager->getLimitSelectList(),
110 'default' => $pager->getLimit(),
111 'cssclass' => $this->getConfig()->get( 'EnablePartialBlocks' ) ?
112 'mw-field-limit mw-has-field-block-type' :
116 $context = new DerivativeContext( $this->getContext() );
117 $context->setTitle( $this->getPageTitle() ); // Remove subpage
118 $form = HTMLForm
::factory( 'ooui', $fields, $context );
121 ->setFormIdentifier( 'blocklist' )
122 ->setWrapperLegendMsg( 'ipblocklist-legend' )
123 ->setSubmitTextMsg( 'ipblocklist-submit' )
125 ->displayForm( false );
127 $this->showList( $pager );
131 * Setup a new BlockListPager instance.
132 * @return BlockListPager
134 protected function getBlockListPager() {
136 # Is the user allowed to see hidden blocks?
137 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
138 $conds['ipb_deleted'] = 0;
141 if ( $this->target
!== '' ) {
142 list( $target, $type ) = Block
::parseTarget( $this->target
);
146 case Block
::TYPE_AUTO
:
147 $conds['ipb_id'] = $target;
151 case Block
::TYPE_RANGE
:
152 list( $start, $end ) = IP
::parseRange( $target );
153 $conds[] = wfGetDB( DB_REPLICA
)->makeList(
155 'ipb_address' => $target,
156 Block
::getRangeCond( $start, $end )
160 $conds['ipb_auto'] = 0;
163 case Block
::TYPE_USER
:
164 $conds['ipb_address'] = $target->getName();
165 $conds['ipb_auto'] = 0;
171 if ( in_array( 'userblocks', $this->options
) ) {
172 $conds['ipb_user'] = 0;
174 if ( in_array( 'tempblocks', $this->options
) ) {
175 $conds['ipb_expiry'] = 'infinity';
177 if ( in_array( 'addressblocks', $this->options
) ) {
178 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
180 if ( in_array( 'rangeblocks', $this->options
) ) {
181 $conds[] = "ipb_range_end = ipb_range_start";
184 if ( $this->blockType
=== 'sitewide' ) {
185 $conds[] = 'ipb_sitewide = 1';
186 } elseif ( $this->blockType
=== 'partial' ) {
187 $conds[] = 'ipb_sitewide = 0';
190 return new BlockListPager( $this, $conds );
194 * Show the list of blocked accounts matching the actual filter.
195 * @param BlockListPager $pager The BlockListPager instance for this page
197 protected function showList( BlockListPager
$pager ) {
198 $out = $this->getOutput();
200 # Check for other blocks, i.e. global/tor blocks
201 $otherBlockLink = [];
202 Hooks
::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target
] );
204 # Show additional header for the local block only when other blocks exists.
205 # Not necessary in a standard installation without such extensions enabled
206 if ( count( $otherBlockLink ) ) {
208 Html
::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
212 if ( $pager->getNumRows() ) {
213 $out->addParserOutputContent( $pager->getFullOutput() );
214 } elseif ( $this->target
) {
215 $out->addWikiMsg( 'ipblocklist-no-results' );
217 $out->addWikiMsg( 'ipblocklist-empty' );
220 if ( count( $otherBlockLink ) ) {
225 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
229 foreach ( $otherBlockLink as $link ) {
230 $list .= Html
::rawElement( 'li', [], $link ) . "\n";
232 $out->addHTML( Html
::rawElement(
234 [ 'class' => 'mw-ipblocklist-otherblocks' ],
240 protected function getGroupName() {