Merge "Exclude redirects from Special:Fewestrevisions"
[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 $this->addHelpLink( 'Help:Protected_pages' );
42
43 $request = $this->getRequest();
44 $type = $request->getVal( $this->IdType );
45 $level = $request->getVal( $this->IdLevel );
46 $sizetype = $request->getVal( 'size-mode' );
47 $size = $request->getIntOrNull( 'size' );
48 $ns = $request->getIntOrNull( 'namespace' );
49
50 $filters = $request->getArray( 'wpfilters', [] );
51 $indefOnly = in_array( 'indefonly', $filters );
52 $cascadeOnly = in_array( 'cascadeonly', $filters );
53 $noRedirect = in_array( 'noredirect', $filters );
54
55 $pager = new ProtectedPagesPager(
56 $this,
57 [],
58 $type,
59 $level,
60 $ns,
61 $sizetype,
62 $size,
63 $indefOnly,
64 $cascadeOnly,
65 $noRedirect,
66 $this->getLinkRenderer()
67 );
68
69 $this->getOutput()->addHTML( $this->showOptions(
70 $ns,
71 $type,
72 $level,
73 $sizetype,
74 $size,
75 $filters
76 ) );
77
78 if ( $pager->getNumRows() ) {
79 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
80 } else {
81 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
82 }
83 }
84
85 /**
86 * @param int $namespace
87 * @param string $type Restriction type
88 * @param string $level Restriction level
89 * @param string $sizetype "min" or "max"
90 * @param int $size
91 * @param array $filters Filters set for the pager: indefOnly,
92 * cascadeOnly, noRedirect
93 * @return string Input form
94 */
95 protected function showOptions( $namespace, $type, $level, $sizetype,
96 $size, $filters
97 ) {
98 $formDescriptor = [
99 'namespace' => [
100 'class' => HTMLSelectNamespace::class,
101 'name' => 'namespace',
102 'id' => 'namespace',
103 'cssclass' => 'namespaceselector',
104 'all' => '',
105 'label' => $this->msg( 'namespace' )->text(),
106 ],
107 'typemenu' => $this->getTypeMenu( $type ),
108 'levelmenu' => $this->getLevelMenu( $level ),
109 'filters' => [
110 'class' => 'HTMLMultiSelectField',
111 'label' => $this->msg( 'protectedpages-filters' )->text(),
112 'flatlist' => true,
113 'options-messages' => [
114 'protectedpages-indef' => 'indefonly',
115 'protectedpages-cascade' => 'cascadeonly',
116 'protectedpages-noredirect' => 'noredirect',
117 ],
118 'default' => $filters,
119 ],
120 'sizelimit' => [
121 'class' => HTMLSizeFilterField::class,
122 'name' => 'size',
123 ]
124 ];
125 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
126 $htmlForm
127 ->setMethod( 'get' )
128 ->setWrapperLegendMsg( 'protectedpages' )
129 ->setSubmitText( $this->msg( 'protectedpages-submit' )->text() );
130
131 return $htmlForm->prepareForm()->getHTML( false );
132 }
133
134 /**
135 * Creates the input label of the restriction type
136 * @param string $pr_type Protection type
137 * @return array
138 */
139 protected function getTypeMenu( $pr_type ) {
140 $m = []; // Temporary array
141 $options = [];
142
143 // First pass to load the log names
144 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
145 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
146 $text = $this->msg( "restriction-$type" )->text();
147 $m[$text] = $type;
148 }
149
150 // Third pass generates sorted XHTML content
151 foreach ( $m as $text => $type ) {
152 $options[$text] = $type;
153 }
154
155 return [
156 'type' => 'select',
157 'options' => $options,
158 'label' => $this->msg( 'restriction-type' )->text(),
159 'name' => $this->IdType,
160 'id' => $this->IdType,
161 ];
162 }
163
164 /**
165 * Creates the input label of the restriction level
166 * @param string $pr_level Protection level
167 * @return array
168 */
169 protected function getLevelMenu( $pr_level ) {
170 // Temporary array
171 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
172 $options = [];
173
174 // First pass to load the log names
175 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
176 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
177 if ( $type != '' && $type != '*' ) {
178 $text = $this->msg( "restriction-level-$type" )->text();
179 $m[$text] = $type;
180 }
181 }
182
183 // Third pass generates sorted XHTML content
184 foreach ( $m as $text => $type ) {
185 $options[$text] = $type;
186 }
187
188 return [
189 'type' => 'select',
190 'options' => $options,
191 'label' => $this->msg( 'restriction-level' )->text(),
192 'name' => $this->IdLevel,
193 'id' => $this->IdLevel
194 ];
195 }
196
197 protected function getGroupName() {
198 return 'maintenance';
199 }
200 }