Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 107 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| SpecialProtectedPages | |
0.00% |
0 / 106 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
6 | |||
| showOptions | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
2 | |||
| getTypeMenu | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| getLevelMenu | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 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\CommentFormatter\RowCommentFormatter; |
| 10 | use MediaWiki\CommentStore\CommentStore; |
| 11 | use MediaWiki\HTMLForm\Field\HTMLMultiSelectField; |
| 12 | use MediaWiki\HTMLForm\Field\HTMLSelectNamespace; |
| 13 | use MediaWiki\HTMLForm\Field\HTMLSizeFilterField; |
| 14 | use MediaWiki\HTMLForm\HTMLForm; |
| 15 | use MediaWiki\MainConfigNames; |
| 16 | use MediaWiki\Page\LinkBatchFactory; |
| 17 | use MediaWiki\Pager\ProtectedPagesPager; |
| 18 | use MediaWiki\Parser\ParserOptions; |
| 19 | use MediaWiki\Permissions\RestrictionStore; |
| 20 | use MediaWiki\SpecialPage\SpecialPage; |
| 21 | use Wikimedia\Rdbms\IConnectionProvider; |
| 22 | |
| 23 | /** |
| 24 | * A special page that lists protected pages |
| 25 | * |
| 26 | * @ingroup SpecialPage |
| 27 | */ |
| 28 | class SpecialProtectedPages extends SpecialPage { |
| 29 | private LinkBatchFactory $linkBatchFactory; |
| 30 | private IConnectionProvider $dbProvider; |
| 31 | private CommentStore $commentStore; |
| 32 | private RowCommentFormatter $rowCommentFormatter; |
| 33 | private RestrictionStore $restrictionStore; |
| 34 | |
| 35 | public function __construct( |
| 36 | LinkBatchFactory $linkBatchFactory, |
| 37 | IConnectionProvider $dbProvider, |
| 38 | CommentStore $commentStore, |
| 39 | RowCommentFormatter $rowCommentFormatter, |
| 40 | RestrictionStore $restrictionStore |
| 41 | ) { |
| 42 | parent::__construct( 'Protectedpages' ); |
| 43 | $this->linkBatchFactory = $linkBatchFactory; |
| 44 | $this->dbProvider = $dbProvider; |
| 45 | $this->commentStore = $commentStore; |
| 46 | $this->rowCommentFormatter = $rowCommentFormatter; |
| 47 | $this->restrictionStore = $restrictionStore; |
| 48 | } |
| 49 | |
| 50 | /** @inheritDoc */ |
| 51 | public function execute( $par ) { |
| 52 | $this->setHeaders(); |
| 53 | $this->outputHeader(); |
| 54 | $this->getOutput()->addModuleStyles( 'mediawiki.special' ); |
| 55 | $this->addHelpLink( 'Help:Protected_pages' ); |
| 56 | |
| 57 | $request = $this->getRequest(); |
| 58 | $type = $request->getVal( 'type' ); |
| 59 | $level = $request->getVal( 'level' ); |
| 60 | $sizetype = $request->getVal( 'size-mode' ); |
| 61 | $size = $request->getIntOrNull( 'size' ); |
| 62 | $ns = $request->getIntOrNull( 'namespace' ); |
| 63 | |
| 64 | $filters = $request->getArray( 'wpfilters', [] ); |
| 65 | $indefOnly = in_array( 'indefonly', $filters ); |
| 66 | $cascadeOnly = in_array( 'cascadeonly', $filters ); |
| 67 | $noRedirect = in_array( 'noredirect', $filters ); |
| 68 | |
| 69 | $pager = new ProtectedPagesPager( |
| 70 | $this->getContext(), |
| 71 | $this->commentStore, |
| 72 | $this->linkBatchFactory, |
| 73 | $this->getLinkRenderer(), |
| 74 | $this->dbProvider, |
| 75 | $this->rowCommentFormatter, |
| 76 | $type, |
| 77 | $level, |
| 78 | $ns, |
| 79 | $sizetype, |
| 80 | $size, |
| 81 | $indefOnly, |
| 82 | $cascadeOnly, |
| 83 | $noRedirect |
| 84 | ); |
| 85 | |
| 86 | $this->getOutput()->addHTML( $this->showOptions( |
| 87 | $type, |
| 88 | $level, |
| 89 | $filters |
| 90 | ) ); |
| 91 | |
| 92 | if ( $pager->getNumRows() ) { |
| 93 | $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' ); |
| 94 | $this->getOutput()->addParserOutputContent( |
| 95 | $pager->getFullOutput(), |
| 96 | ParserOptions::newFromContext( $this->getContext() ) |
| 97 | ); |
| 98 | } else { |
| 99 | $this->getOutput()->addWikiMsg( 'protectedpagesempty' ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @param string $type Restriction type |
| 105 | * @param string $level Restriction level |
| 106 | * @param array $filters Filters set for the pager: indefOnly, |
| 107 | * cascadeOnly, noRedirect |
| 108 | * @return string Input form |
| 109 | */ |
| 110 | protected function showOptions( $type, $level, $filters ) { |
| 111 | $formDescriptor = [ |
| 112 | 'namespace' => [ |
| 113 | 'class' => HTMLSelectNamespace::class, |
| 114 | 'name' => 'namespace', |
| 115 | 'id' => 'namespace', |
| 116 | 'cssclass' => 'namespaceselector', |
| 117 | 'all' => '', |
| 118 | 'label' => $this->msg( 'namespace' )->text(), |
| 119 | ], |
| 120 | 'typemenu' => $this->getTypeMenu( $type ), |
| 121 | 'levelmenu' => $this->getLevelMenu( $level ), |
| 122 | 'filters' => [ |
| 123 | 'class' => HTMLMultiSelectField::class, |
| 124 | 'label' => $this->msg( 'protectedpages-filters' )->text(), |
| 125 | 'flatlist' => true, |
| 126 | 'options-messages' => [ |
| 127 | 'protectedpages-indef' => 'indefonly', |
| 128 | 'protectedpages-cascade' => 'cascadeonly', |
| 129 | 'protectedpages-noredirect' => 'noredirect', |
| 130 | ], |
| 131 | 'default' => $filters, |
| 132 | ], |
| 133 | 'sizelimit' => [ |
| 134 | 'class' => HTMLSizeFilterField::class, |
| 135 | 'name' => 'size', |
| 136 | ] |
| 137 | ]; |
| 138 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
| 139 | ->setMethod( 'get' ) |
| 140 | ->setWrapperLegendMsg( 'protectedpages' ) |
| 141 | ->setSubmitTextMsg( 'protectedpages-submit' ); |
| 142 | |
| 143 | return $htmlForm->prepareForm()->getHTML( false ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Creates the input label of the restriction type |
| 148 | * @param string $pr_type Protection type |
| 149 | * @return array |
| 150 | */ |
| 151 | protected function getTypeMenu( $pr_type ) { |
| 152 | $m = []; // Temporary array |
| 153 | $options = []; |
| 154 | |
| 155 | // First pass to load the log names |
| 156 | foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) { |
| 157 | // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload |
| 158 | $text = $this->msg( "restriction-$type" )->text(); |
| 159 | $m[$text] = $type; |
| 160 | } |
| 161 | |
| 162 | // Third pass generates sorted XHTML content |
| 163 | foreach ( $m as $text => $type ) { |
| 164 | $options[$text] = $type; |
| 165 | } |
| 166 | |
| 167 | return [ |
| 168 | 'type' => 'select', |
| 169 | 'options' => $options, |
| 170 | 'label' => $this->msg( 'restriction-type' )->text(), |
| 171 | 'name' => 'type', |
| 172 | 'id' => 'type', |
| 173 | ]; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Creates the input label of the restriction level |
| 178 | * @param string $pr_level Protection level |
| 179 | * @return array |
| 180 | */ |
| 181 | protected function getLevelMenu( $pr_level ) { |
| 182 | $options = [ 'restriction-level-all' => 0 ]; |
| 183 | |
| 184 | // Load the log names as options |
| 185 | foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) { |
| 186 | if ( $type != '' && $type != '*' ) { |
| 187 | // Messages: restriction-level-sysop, restriction-level-autoconfirmed |
| 188 | $options["restriction-level-$type"] = $type; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return [ |
| 193 | 'type' => 'select', |
| 194 | 'options-messages' => $options, |
| 195 | 'label-message' => 'restriction-level', |
| 196 | 'name' => 'level', |
| 197 | 'id' => 'level', |
| 198 | ]; |
| 199 | } |
| 200 | |
| 201 | /** @inheritDoc */ |
| 202 | protected function getGroupName() { |
| 203 | return 'maintenance'; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Retain the old class name for backwards compatibility. |
| 209 | * @deprecated since 1.41 |
| 210 | */ |
| 211 | class_alias( SpecialProtectedPages::class, 'SpecialProtectedpages' ); |