8e20d88372bcdc7fd0df0748ebea040bdbbdd638
3 * Implements Special:Protectedpages
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.
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.
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
21 * @ingroup SpecialPage
25 * A special page that lists protected pages
27 * @ingroup SpecialPage
29 class SpecialProtectedpages
extends SpecialPage
{
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
33 public function __construct() {
34 parent
::__construct( 'Protectedpages' );
37 public function execute( $par ) {
39 $this->outputHeader();
40 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
42 $request = $this->getRequest();
43 $type = $request->getVal( $this->IdType
);
44 $level = $request->getVal( $this->IdLevel
);
45 $sizetype = $request->getVal( 'sizetype' );
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;
52 $pager = new ProtectedPagesPager(
63 $this->getLinkRenderer()
66 $this->getOutput()->addHTML( $this->showOptions(
77 if ( $pager->getNumRows() ) {
78 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
80 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
85 * @param int $namespace
86 * @param string $type Restriction type
87 * @param string $level Restriction level
88 * @param string $sizetype "min" or "max"
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
95 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
96 $size, $indefOnly, $cascadeOnly, $noRedirect
98 $title = $this->getPageTitle();
100 return Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
101 Xml
::openElement( 'fieldset' ) .
102 Xml
::element( 'legend', [], $this->msg( 'protectedpages' )->text() ) .
103 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
104 $this->getNamespaceMenu( $namespace ) . "\n" .
105 $this->getTypeMenu( $type ) . "\n" .
106 $this->getLevelMenu( $level ) . "\n" .
108 $this->getExpiryCheck( $indefOnly ) . "\n" .
109 $this->getCascadeCheck( $cascadeOnly ) . "\n" .
110 $this->getRedirectCheck( $noRedirect ) . "\n" .
112 $this->getSizeLimit( $sizetype, $size ) . "\n" .
113 Xml
::submitButton( $this->msg( 'protectedpages-submit' )->text() ) . "\n" .
114 Xml
::closeElement( 'fieldset' ) .
115 Xml
::closeElement( 'form' );
119 * Prepare the namespace filter drop-down; standard namespace
120 * selector, sans the MediaWiki namespace
122 * @param string|null $namespace Pre-select namespace
125 protected function getNamespaceMenu( $namespace = null ) {
126 return Html
::rawElement( 'span', [ 'class' => 'mw-input-with-label' ],
127 Html
::namespaceSelector(
129 'selected' => $namespace,
131 'label' => $this->msg( 'namespace' )->text()
133 'name' => 'namespace',
135 'class' => 'namespaceselector',
142 * @param bool $indefOnly
143 * @return string Formatted HTML
145 protected function getExpiryCheck( $indefOnly ) {
146 return '<span class="mw-input-with-label">' . Xml
::checkLabel(
147 $this->msg( 'protectedpages-indef' )->text(),
155 * @param bool $cascadeOnly
156 * @return string Formatted HTML
158 protected function getCascadeCheck( $cascadeOnly ) {
159 return '<span class="mw-input-with-label">' . Xml
::checkLabel(
160 $this->msg( 'protectedpages-cascade' )->text(),
168 * @param bool $noRedirect
169 * @return string Formatted HTML
171 protected function getRedirectCheck( $noRedirect ) {
172 return '<span class="mw-input-with-label">' . Xml
::checkLabel(
173 $this->msg( 'protectedpages-noredirect' )->text(),
181 * @param string $sizetype "min" or "max"
183 * @return string Formatted HTML
185 protected function getSizeLimit( $sizetype, $size ) {
186 $max = $sizetype === 'max';
188 return '<span class="mw-input-with-label">' . Xml
::radioLabel(
189 $this->msg( 'minimum-size' )->text(),
197 $this->msg( 'maximum-size' )->text(),
204 Xml
::input( 'size', 9, $size, [ 'id' => 'wpsize' ] ) .
206 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' ) . "</span>\n";
210 * Creates the input label of the restriction type
211 * @param string $pr_type Protection type
212 * @return string Formatted HTML
214 protected function getTypeMenu( $pr_type ) {
215 $m = []; // Temporary array
218 // First pass to load the log names
219 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
220 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
221 $text = $this->msg( "restriction-$type" )->text();
225 // Third pass generates sorted XHTML content
226 foreach ( $m as $text => $type ) {
227 $selected = ( $type == $pr_type );
228 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
231 return '<span class="mw-input-with-label">' .
232 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
234 [ 'id' => $this->IdType
, 'name' => $this->IdType
],
235 implode( "\n", $options ) ) . "</span>";
239 * Creates the input label of the restriction level
240 * @param string $pr_level Protection level
241 * @return string Formatted HTML
243 protected function getLevelMenu( $pr_level ) {
245 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
248 // First pass to load the log names
249 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
250 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
251 if ( $type != '' && $type != '*' ) {
252 $text = $this->msg( "restriction-level-$type" )->text();
257 // Third pass generates sorted XHTML content
258 foreach ( $m as $text => $type ) {
259 $selected = ( $type == $pr_level );
260 $options[] = Xml
::option( $text, $type, $selected );
263 return '<span class="mw-input-with-label">' .
264 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
266 [ 'id' => $this->IdLevel
, 'name' => $this->IdLevel
],
267 implode( "\n", $options ) ) . "</span>";
270 protected function getGroupName() {
271 return 'maintenance';