Add rate limiter to Special:ConfirmEmail
[lhc/web/wiklou.git] / includes / specials / SpecialAutoblockList.php
1 <?php
2 /**
3 * Implements Special:AutoblockList
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that lists autoblocks
26 *
27 * @since 1.29
28 * @ingroup SpecialPage
29 */
30 class SpecialAutoblockList extends SpecialPage {
31
32 function __construct() {
33 parent::__construct( 'AutoblockList' );
34 }
35
36 /**
37 * @param string|null $par Title fragment
38 */
39 public function execute( $par ) {
40 $this->setHeaders();
41 $this->outputHeader();
42 $out = $this->getOutput();
43 $out->setPageTitle( $this->msg( 'autoblocklist' ) );
44 $this->addHelpLink( 'Autoblock' );
45 $out->addModuleStyles( [ 'mediawiki.special' ] );
46
47 # setup BlockListPager here to get the actual default Limit
48 $pager = $this->getBlockListPager();
49
50 # Just show the block list
51 $fields = [
52 'Limit' => [
53 'type' => 'limitselect',
54 'label-message' => 'table_pager_limit_label',
55 'options' => $pager->getLimitSelectList(),
56 'name' => 'limit',
57 'default' => $pager->getLimit(),
58 ]
59 ];
60
61 $context = new DerivativeContext( $this->getContext() );
62 $context->setTitle( $this->getPageTitle() ); // Remove subpage
63 $form = HTMLForm::factory( 'ooui', $fields, $context );
64 $form->setMethod( 'get' )
65 ->setFormIdentifier( 'blocklist' )
66 ->setWrapperLegendMsg( 'autoblocklist-legend' )
67 ->setSubmitTextMsg( 'autoblocklist-submit' )
68 ->prepareForm()
69 ->displayForm( false );
70
71 $this->showTotal( $pager );
72 $this->showList( $pager );
73 }
74
75 /**
76 * Setup a new BlockListPager instance.
77 * @return BlockListPager
78 */
79 protected function getBlockListPager() {
80 $conds = [
81 'ipb_parent_block_id IS NOT NULL'
82 ];
83 # Is the user allowed to see hidden blocks?
84 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
85 $conds['ipb_deleted'] = 0;
86 }
87
88 return new BlockListPager( $this, $conds );
89 }
90
91 /**
92 * Show total number of autoblocks on top of the table
93 *
94 * @param BlockListPager $pager The BlockListPager instance for this page
95 */
96 protected function showTotal( BlockListPager $pager ) {
97 $out = $this->getOutput();
98 $out->addHTML(
99 Html::rawElement( 'div', [ 'style' => 'font-weight: bold;' ],
100 $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() )
101 . "\n"
102 );
103 }
104
105 /**
106 * Show the list of blocked accounts matching the actual filter.
107 * @param BlockListPager $pager The BlockListPager instance for this page
108 */
109 protected function showList( BlockListPager $pager ) {
110 $out = $this->getOutput();
111
112 # Check for other blocks, i.e. global/tor blocks
113 $otherAutoblockLink = [];
114 Hooks::run( 'OtherAutoblockLogLink', [ &$otherAutoblockLink ] );
115
116 # Show additional header for the local block only when other blocks exists.
117 # Not necessary in a standard installation without such extensions enabled
118 if ( count( $otherAutoblockLink ) ) {
119 $out->addHTML(
120 Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
121 $pager->getNumRows() )->parse() )
122 . "\n"
123 );
124 }
125
126 if ( $pager->getNumRows() ) {
127 $out->addParserOutputContent( $pager->getFullOutput() );
128 } else {
129 $out->addWikiMsg( 'autoblocklist-empty' );
130 }
131
132 if ( count( $otherAutoblockLink ) ) {
133 $out->addHTML(
134 Html::rawElement(
135 'h2',
136 [],
137 $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
138 ) . "\n"
139 );
140 $list = '';
141 foreach ( $otherAutoblockLink as $link ) {
142 $list .= Html::rawElement( 'li', [], $link ) . "\n";
143 }
144 $out->addHTML(
145 Html::rawElement(
146 'ul',
147 [ 'class' => 'mw-autoblocklist-otherblocks' ],
148 $list
149 ) . "\n"
150 );
151 }
152 }
153
154 protected function getGroupName() {
155 return 'users';
156 }
157 }