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 * Main execution point
41 * @param string $par Title fragment
43 public function execute( $par ) {
45 $this->outputHeader();
46 $out = $this->getOutput();
47 $lang = $this->getLanguage();
48 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
49 $out->addModuleStyles( [ 'mediawiki.special' ] );
51 $request = $this->getRequest();
52 $par = $request->getVal( 'ip', $par );
53 $this->target
= trim( $request->getVal( 'wpTarget', $par ) );
55 $this->options
= $request->getArray( 'wpOptions', [] );
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',
90 'type' => 'limitselect',
91 'label-message' => 'table_pager_limit_label',
93 $lang->formatNum( 20 ) => 20,
94 $lang->formatNum( 50 ) => 50,
95 $lang->formatNum( 100 ) => 100,
96 $lang->formatNum( 250 ) => 250,
97 $lang->formatNum( 500 ) => 500,
100 'default' => $pager->getLimit(),
103 $context = new DerivativeContext( $this->getContext() );
104 $context->setTitle( $this->getPageTitle() ); // Remove subpage
105 $form = HTMLForm
::factory( 'ooui', $fields, $context );
106 $form->setMethod( 'get' );
107 $form->setWrapperLegendMsg( 'ipblocklist-legend' );
108 $form->setSubmitTextMsg( 'ipblocklist-submit' );
109 $form->setSubmitProgressive();
110 $form->prepareForm();
112 $form->displayForm( '' );
113 $this->showList( $pager );
117 * Setup a new BlockListPager instance.
118 * @return BlockListPager
120 protected function getBlockListPager() {
122 # Is the user allowed to see hidden blocks?
123 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
124 $conds['ipb_deleted'] = 0;
127 if ( $this->target
!== '' ) {
128 list( $target, $type ) = Block
::parseTarget( $this->target
);
132 case Block
::TYPE_AUTO
:
133 $conds['ipb_id'] = $target;
137 case Block
::TYPE_RANGE
:
138 list( $start, $end ) = IP
::parseRange( $target );
139 $conds[] = wfGetDB( DB_REPLICA
)->makeList(
141 'ipb_address' => $target,
142 Block
::getRangeCond( $start, $end )
146 $conds['ipb_auto'] = 0;
149 case Block
::TYPE_USER
:
150 $conds['ipb_address'] = $target->getName();
151 $conds['ipb_auto'] = 0;
157 if ( in_array( 'userblocks', $this->options
) ) {
158 $conds['ipb_user'] = 0;
160 if ( in_array( 'tempblocks', $this->options
) ) {
161 $conds['ipb_expiry'] = 'infinity';
163 if ( in_array( 'addressblocks', $this->options
) ) {
164 $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
166 if ( in_array( 'rangeblocks', $this->options
) ) {
167 $conds[] = "ipb_range_end = ipb_range_start";
170 return new BlockListPager( $this, $conds );
174 * Show the list of blocked accounts matching the actual filter.
175 * @param BlockListPager $pager The BlockListPager instance for this page
177 protected function showList( BlockListPager
$pager ) {
178 $out = $this->getOutput();
180 # Check for other blocks, i.e. global/tor blocks
181 $otherBlockLink = [];
182 Hooks
::run( 'OtherBlockLogLink', [ &$otherBlockLink, $this->target
] );
184 # Show additional header for the local block only when other blocks exists.
185 # Not necessary in a standard installation without such extensions enabled
186 if ( count( $otherBlockLink ) ) {
188 Html
::element( 'h2', [], $this->msg( 'ipblocklist-localblock' )->text() ) . "\n"
192 if ( $pager->getNumRows() ) {
193 $out->addParserOutputContent( $pager->getFullOutput() );
194 } elseif ( $this->target
) {
195 $out->addWikiMsg( 'ipblocklist-no-results' );
197 $out->addWikiMsg( 'ipblocklist-empty' );
200 if ( count( $otherBlockLink ) ) {
205 $this->msg( 'ipblocklist-otherblocks', count( $otherBlockLink ) )->parse()
209 foreach ( $otherBlockLink as $link ) {
210 $list .= Html
::rawElement( 'li', [], $link ) . "\n";
212 $out->addHTML( Html
::rawElement(
214 [ 'class' => 'mw-ipblocklist-otherblocks' ],
220 protected function getGroupName() {