Debian Codegraph @

includes/specials/SpecialProtectedTitles.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\HTMLForm\Field\HTMLSelectNamespace;
25 use MediaWiki\HTMLForm\HTMLForm;
26 use MediaWiki\MainConfigNames;
27 use MediaWiki\Pager\ProtectedTitlesPager;
28 use MediaWiki\SpecialPage\SpecialPage;
29 use Wikimedia\Rdbms\IConnectionProvider;
30
31 /**
32 * A special page that list protected titles from creation
33 *
34 * @ingroup SpecialPage
35 */
36 class SpecialProtectedTitles extends SpecialPage {
37 private LinkBatchFactory $linkBatchFactory;
38 private IConnectionProvider $dbProvider;
39
40 /**
41 * @param LinkBatchFactory $linkBatchFactory
42 * @param IConnectionProvider $dbProvider
43 */
44 public function __construct(
45 LinkBatchFactory $linkBatchFactory,
46 IConnectionProvider $dbProvider
47 ) {
48 parent::__construct( 'Protectedtitles' );
49 $this->linkBatchFactory = $linkBatchFactory;
50 $this->dbProvider = $dbProvider;
51 }
52
53 public function execute( $par ) {
54 $this->setHeaders();
55 $this->outputHeader();
56 $this->addHelpLink( 'Help:Protected_pages' );
57
58 $request = $this->getRequest();
59 $level = $request->getVal( 'level' );
60 $NS = $request->getIntOrNull( 'namespace' );
61
62 $pager = new ProtectedTitlesPager(
63 $this->getContext(),
64 $this->getLinkRenderer(),
65 $this->linkBatchFactory,
66 $this->dbProvider,
67 $level,
68 $NS
69 );
70
71 $this->getOutput()->addHTML( $this->showOptions() );
72
73 if ( $pager->getNumRows() ) {
74 $this->getOutput()->addHTML(
75 $pager->getNavigationBar() .
76 '<ul>' . $pager->getBody() . '</ul>' .
77 $pager->getNavigationBar()
78 );
79 } else {
80 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
81 }
82 }
83
84 /**
85 * @return string
86 */
87 private function showOptions() {
88 $formDescriptor = [
89 'namespace' => [
90 'class' => HTMLSelectNamespace::class,
91 'name' => 'namespace',
92 'id' => 'namespace',
93 'cssclass' => 'namespaceselector',
94 'all' => '',
95 'label' => $this->msg( 'namespace' )->text()
96 ],
97 'levelmenu' => $this->getLevelMenu()
98 ];
99
100 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
101 ->setMethod( 'get' )
102 ->setWrapperLegendMsg( 'protectedtitles' )
103 ->setSubmitTextMsg( 'protectedtitles-submit' );
104
105 return $htmlForm->prepareForm()->getHTML( false );
106 }
107
108 /**
109 * @return string|array
110 */
111 private function getLevelMenu() {
112 $options = [ 'restriction-level-all' => 0 ];
113
114 // Load the log names as options
115 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
116 if ( $type != '' && $type != '*' ) {
117 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
118 $options["restriction-level-$type"] = $type;
119 }
120 }
121
122 // Is there only one level (aside from "all")?
123 if ( count( $options ) <= 2 ) {
124 return '';
125 }
126
127 return [
128 'type' => 'select',
129 'options-messages' => $options,
130 'label-message' => 'restriction-level',
131 'name' => 'level',
132 'id' => 'level',
133 ];
134 }
135
136 protected function getGroupName() {
137 return 'maintenance';
138 }
139 }
140
141 /**
142 * Retain the old class name for backwards compatibility.
143 * @deprecated since 1.41
144 */
145 class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' );