Merge "Chinese Conversion Table Update 2017-6"
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
1 <?php
2 /**
3 * Implements Special:Protectedpages
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 protected pages
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialProtectedpages extends SpecialPage {
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
32
33 public function __construct() {
34 parent::__construct( 'Protectedpages' );
35 }
36
37 public function execute( $par ) {
38 $this->setHeaders();
39 $this->outputHeader();
40 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
41
42 $request = $this->getRequest();
43 $type = $request->getVal( $this->IdType );
44 $level = $request->getVal( $this->IdLevel );
45 $sizetype = $request->getVal( 'size-mode' );
46 $size = $request->getIntOrNull( 'size' );
47 $ns = $request->getIntOrNull( 'namespace' );
48 $indefOnly = $request->getBool( 'indefonly' ) ? 1 : 0;
49 $cascadeOnly = $request->getBool( 'cascadeonly' ) ? 1 : 0;
50 $noRedirect = $request->getBool( 'noredirect' ) ? 1 : 0;
51
52 $pager = new ProtectedPagesPager(
53 $this,
54 [],
55 $type,
56 $level,
57 $ns,
58 $sizetype,
59 $size,
60 $indefOnly,
61 $cascadeOnly,
62 $noRedirect,
63 $this->getLinkRenderer()
64 );
65
66 $this->getOutput()->addHTML( $this->showOptions(
67 $ns,
68 $type,
69 $level,
70 $sizetype,
71 $size,
72 $indefOnly,
73 $cascadeOnly,
74 $noRedirect
75 ) );
76
77 if ( $pager->getNumRows() ) {
78 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
79 } else {
80 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
81 }
82 }
83
84 /**
85 * @param int $namespace
86 * @param string $type Restriction type
87 * @param string $level Restriction level
88 * @param string $sizetype "min" or "max"
89 * @param int $size
90 * @param bool $indefOnly Only indefinite protection
91 * @param bool $cascadeOnly Only cascading protection
92 * @param bool $noRedirect Don't show redirects
93 * @return string Input form
94 */
95 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
96 $size, $indefOnly, $cascadeOnly, $noRedirect
97 ) {
98 $formDescriptor = [
99 'namespace' => [
100 'class' => 'HTMLSelectNamespace',
101 'name' => 'namespace',
102 'id' => 'namespace',
103 'cssclass' => 'namespaceselector',
104 'selected' => $namespace,
105 'all' => '',
106 'label' => $this->msg( 'namespace' )->text(),
107 ],
108 'typemenu' => $this->getTypeMenu( $type ),
109 'levelmenu' => $this->getLevelMenu( $level ),
110 'expirycheck' => [
111 'type' => 'check',
112 'label' => $this->msg( 'protectedpages-indef' )->text(),
113 'name' => 'indefonly',
114 'id' => 'indefonly',
115 'value' => $indefOnly
116 ],
117 'cascadecheck' => [
118 'type' => 'check',
119 'label' => $this->msg( 'protectedpages-cascade' )->text(),
120 'name' => 'cascadeonly',
121 'id' => 'cascadeonly',
122 'value' => $cascadeOnly
123 ],
124 'redirectcheck' => [
125 'type' => 'check',
126 'label' => $this->msg( 'protectedpages-noredirect' )->text(),
127 'name' => 'noredirect',
128 'id' => 'noredirect',
129 'value' => $noRedirect,
130 ],
131 'sizelimit' => [
132 'class' => 'HTMLSizeFilterField',
133 'name' => 'size',
134 ]
135 ];
136 $htmlForm = new HTMLForm( $formDescriptor, $this->getContext() );
137 $htmlForm
138 ->setMethod( 'get' )
139 ->setWrapperLegendMsg( 'protectedpages' )
140 ->setSubmitText( $this->msg( 'protectedpages-submit' )->text() );
141
142 return $htmlForm->prepareForm()->getHTML( false );
143 }
144
145 /**
146 * Creates the input label of the restriction type
147 * @param string $pr_type Protection type
148 * @return array
149 */
150 protected function getTypeMenu( $pr_type ) {
151 $m = []; // Temporary array
152 $options = [];
153
154 // First pass to load the log names
155 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
156 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
157 $text = $this->msg( "restriction-$type" )->text();
158 $m[$text] = $type;
159 }
160
161 // Third pass generates sorted XHTML content
162 foreach ( $m as $text => $type ) {
163 $options[$text] = $type;
164 }
165
166 return [
167 'type' => 'select',
168 'options' => $options,
169 'value' => $pr_type,
170 'label' => $this->msg( 'restriction-type' )->text(),
171 'name' => $this->IdType,
172 'id' => $this->IdType,
173 ];
174 }
175
176 /**
177 * Creates the input label of the restriction level
178 * @param string $pr_level Protection level
179 * @return array
180 */
181 protected function getLevelMenu( $pr_level ) {
182 // Temporary array
183 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
184 $options = [];
185
186 // First pass to load the log names
187 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
188 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
189 if ( $type != '' && $type != '*' ) {
190 $text = $this->msg( "restriction-level-$type" )->text();
191 $m[$text] = $type;
192 }
193 }
194
195 // Third pass generates sorted XHTML content
196 foreach ( $m as $text => $type ) {
197 $options[$text] = $type;
198 }
199
200 return [
201 'type' => 'select',
202 'options' => $options,
203 'value' => $pr_level,
204 'label' => $this->msg( 'restriction-level' )->text(),
205 'name' => $this->IdLevel,
206 'id' => $this->IdLevel
207 ];
208 }
209
210 protected function getGroupName() {
211 return 'maintenance';
212 }
213 }