Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 63
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialProtectedTitles
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 5
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 1
6
 showOptions
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
 getLevelMenu
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Implements Special:Protectedtitles
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
24namespace MediaWiki\Specials;
25
26use HTMLSelectNamespace;
27use MediaWiki\Cache\LinkBatchFactory;
28use MediaWiki\HTMLForm\HTMLForm;
29use MediaWiki\MainConfigNames;
30use MediaWiki\Pager\ProtectedTitlesPager;
31use MediaWiki\SpecialPage\SpecialPage;
32use Wikimedia\Rdbms\IConnectionProvider;
33
34/**
35 * A special page that list protected titles from creation
36 *
37 * @ingroup SpecialPage
38 */
39class SpecialProtectedTitles extends SpecialPage {
40    protected $IdLevel = 'level';
41    protected $IdType = 'type';
42
43    private LinkBatchFactory $linkBatchFactory;
44    private IConnectionProvider $dbProvider;
45
46    /**
47     * @param LinkBatchFactory $linkBatchFactory
48     * @param IConnectionProvider $dbProvider
49     */
50    public function __construct(
51        LinkBatchFactory $linkBatchFactory,
52        IConnectionProvider $dbProvider
53    ) {
54        parent::__construct( 'Protectedtitles' );
55        $this->linkBatchFactory = $linkBatchFactory;
56        $this->dbProvider = $dbProvider;
57    }
58
59    public function execute( $par ) {
60        $this->setHeaders();
61        $this->outputHeader();
62        $this->addHelpLink( 'Help:Protected_pages' );
63
64        $request = $this->getRequest();
65        $type = $request->getVal( $this->IdType );
66        $level = $request->getVal( $this->IdLevel );
67        $sizetype = $request->getVal( 'sizetype' );
68        $size = $request->getIntOrNull( 'size' );
69        $NS = $request->getIntOrNull( 'namespace' );
70
71        $pager = new ProtectedTitlesPager(
72            $this->getContext(),
73            $this->getLinkRenderer(),
74            $this->linkBatchFactory,
75            $this->dbProvider,
76            [],
77            $type,
78            $level,
79            $NS,
80            $sizetype,
81            $size
82        );
83
84        $this->getOutput()->addHTML( $this->showOptions() );
85
86        if ( $pager->getNumRows() ) {
87            $this->getOutput()->addHTML(
88                $pager->getNavigationBar() .
89                    '<ul>' . $pager->getBody() . '</ul>' .
90                    $pager->getNavigationBar()
91            );
92        } else {
93            $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
94        }
95    }
96
97    /**
98     * @return string
99     */
100    private function showOptions() {
101        $formDescriptor = [
102            'namespace' => [
103                'class' => HTMLSelectNamespace::class,
104                'name' => 'namespace',
105                'id' => 'namespace',
106                'cssclass' => 'namespaceselector',
107                'all' => '',
108                'label' => $this->msg( 'namespace' )->text()
109            ],
110            'levelmenu' => $this->getLevelMenu()
111        ];
112
113        $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
114            ->setMethod( 'get' )
115            ->setWrapperLegendMsg( 'protectedtitles' )
116            ->setSubmitTextMsg( 'protectedtitles-submit' );
117
118        return $htmlForm->prepareForm()->getHTML( false );
119    }
120
121    /**
122     * @return string|array
123     */
124    private function getLevelMenu() {
125        $options = [ 'restriction-level-all' => 0 ];
126
127        // Load the log names as options
128        foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
129            if ( $type != '' && $type != '*' ) {
130                // Messages: restriction-level-sysop, restriction-level-autoconfirmed
131                $options["restriction-level-$type"] = $type;
132            }
133        }
134
135        // Is there only one level (aside from "all")?
136        if ( count( $options ) <= 2 ) {
137            return '';
138        }
139
140        return [
141            'type' => 'select',
142            'options-messages' => $options,
143            'label-message' => 'restriction-level',
144            'name' => $this->IdLevel,
145            'id' => $this->IdLevel
146        ];
147    }
148
149    protected function getGroupName() {
150        return 'maintenance';
151    }
152}
153
154/**
155 * Retain the old class name for backwards compatibility.
156 * @deprecated since 1.41
157 */
158class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' );