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