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
{
34 function __construct() {
35 parent
::__construct( 'BlockList' );
39 * @param string|null $par Title fragment
41 public function execute( $par ) {
43 $this->outputHeader();
44 $out = $this->getOutput();
45 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
46 $out->addModuleStyles( [ 'mediawiki.special' ] );
48 $request = $this->getRequest();
49 $par = $request->getVal( 'ip', $par );
50 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
52 $this->options
= $request->getArray( 'wpOptions', [] );
54 $action = $request->getText( 'action' );
56 if ( $action == 'unblock' ||
$action == 'submit' && $request->wasPosted() ) {
57 # B/C @since 1.18: Unblock interface is now at Special:Unblock
58 $title = SpecialPage
::getTitleFor( 'Unblock', $this->target
);
59 $out->redirect( $title->getFullURL() );
64 # setup BlockListPager here to get the actual default Limit
65 $pager = $this->getBlockListPager();
67 # Just show the block list
71 'label-message' => 'ipaddressorusername',
74 'default' => $this->target
,
77 'type' => 'multiselect',
78 'options-messages' => [
79 'blocklist-userblocks' => 'userblocks',
80 'blocklist-tempblocks' => 'tempblocks',
81 'blocklist-addressblocks' => 'addressblocks',
82 'blocklist-rangeblocks' => 'rangeblocks',
87 'type' => 'limitselect',
88 'label-message' => 'table_pager_limit_label',
89 'options' => $pager->getLimitSelectList(),
91 'default' => $pager->getLimit(),
94 $context = new DerivativeContext( $this->getContext() );
95 $context->setTitle( $this->getPageTitle() ); // Remove subpage
96 $form = HTMLForm
::factory( 'ooui', $fields, $context );
99 ->setFormIdentifier( 'blocklist' )
100 ->setWrapperLegendMsg( 'ipblocklist-legend' )
101 ->setSubmitTextMsg( 'ipblocklist-submit' )
103 ->displayForm( false );
105 $this->showList( $pager );
109 * Setup a new BlockListPager instance.
110 * @return BlockListPager
112 protected function getBlockListPager() {
114 # Is the user allowed to see hidden blocks?
115 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
116 $conds['ipb_deleted'] = 0;
119 if ( $this->target
!== '' ) {
120 list( $target, $type ) = Block
::parseTarget( $this->target
);
124 case Block
::TYPE_AUTO
:
125 $conds['ipb_id'] = $target;
129 case Block
::TYPE_RANGE
:
130 list( $start, $end ) = IP
::parseRange( $target );
131 $conds[] = wfGetDB( DB_REPLICA
)->makeList(
133 'ipb_address' => $target,
134 Block
::getRangeCond( $start, $end )
138 $conds['ipb_auto'] = 0;
141 case Block
::TYPE_USER
:
142 $conds['ipb_address'] = $target->getName();
143 $conds['ipb_auto'] = 0;
149 if ( in_array( 'userblocks', $this->options
) ) {
150 $conds['ipb_user'] = 0;
152 if ( in_array( 'tempblocks', $this->options
) ) {
153 $conds['ipb_expiry'] = 'infinity';
155 if ( in_array( 'addressblocks', $this->options
) ) {
156 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
158 if ( in_array( 'rangeblocks', $this->options
) ) {
159 $conds[] = "ipb_range_end = ipb_range_start";
162 return new BlockListPager( $this, $conds );
166 * Show the list of blocked accounts matching the actual filter.
167 * @param BlockListPager $pager The BlockListPager instance for this page
169 protected function showList( BlockListPager
$pager ) {
170 $out = $this->getOutput();
172 # Check for other blocks, i.e. global/tor blocks
173 $otherBlockLink = [];
174 Hooks
::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target
] );
176 # Show additional header for the local block only when other blocks exists.
177 # Not necessary in a standard installation without such extensions enabled
178 if ( count( $otherBlockLink ) ) {
180 Html
::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
184 if ( $pager->getNumRows() ) {
185 $out->addParserOutputContent( $pager->getFullOutput() );
186 } elseif ( $this->target
) {
187 $out->addWikiMsg( 'ipblocklist-no-results' );
189 $out->addWikiMsg( 'ipblocklist-empty' );
192 if ( count( $otherBlockLink ) ) {
197 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
201 foreach ( $otherBlockLink as $link ) {
202 $list .= Html
::rawElement( 'li', [], $link ) . "\n";
204 $out->addHTML( Html
::rawElement(
206 [ 'class' => 'mw-ipblocklist-otherblocks' ],
212 protected function getGroupName() {