| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class SpecialProtectedTitles extends SpecialPage { |
| 37 |
private LinkBatchFactory $linkBatchFactory; |
| 38 |
private IConnectionProvider $dbProvider; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
|
| 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 |
|
| 110 |
|
| 111 |
private function getLevelMenu() { |
| 112 |
$options = [ 'restriction-level-all' => 0 ]; |
| 113 |
|
| 114 |
|
| 115 |
foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) { |
| 116 |
if ( $type != '' && $type != '*' ) { |
| 117 |
|
| 118 |
$options["restriction-level-$type"] = $type; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 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 |
|
| 143 |
|
| 144 |
|
| 145 |
class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' ); |