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