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