| 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\CommentFormatter\RowCommentFormatter; |
| 25 |
use MediaWiki\CommentStore\CommentStore; |
| 26 |
use MediaWiki\HTMLForm\Field\HTMLMultiSelectField; |
| 27 |
use MediaWiki\HTMLForm\Field\HTMLSelectNamespace; |
| 28 |
use MediaWiki\HTMLForm\Field\HTMLSizeFilterField; |
| 29 |
use MediaWiki\HTMLForm\HTMLForm; |
| 30 |
use MediaWiki\MainConfigNames; |
| 31 |
use MediaWiki\Pager\ProtectedPagesPager; |
| 32 |
use MediaWiki\Permissions\RestrictionStore; |
| 33 |
use MediaWiki\SpecialPage\SpecialPage; |
| 34 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class SpecialProtectedPages extends SpecialPage { |
| 42 |
private LinkBatchFactory $linkBatchFactory; |
| 43 |
private IConnectionProvider $dbProvider; |
| 44 |
private CommentStore $commentStore; |
| 45 |
private RowCommentFormatter $rowCommentFormatter; |
| 46 |
private RestrictionStore $restrictionStore; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function __construct( |
| 56 |
LinkBatchFactory $linkBatchFactory, |
| 57 |
IConnectionProvider $dbProvider, |
| 58 |
CommentStore $commentStore, |
| 59 |
RowCommentFormatter $rowCommentFormatter, |
| 60 |
RestrictionStore $restrictionStore |
| 61 |
) { |
| 62 |
parent::__construct( 'Protectedpages' ); |
| 63 |
$this->linkBatchFactory = $linkBatchFactory; |
| 64 |
$this->dbProvider = $dbProvider; |
| 65 |
$this->commentStore = $commentStore; |
| 66 |
$this->rowCommentFormatter = $rowCommentFormatter; |
| 67 |
$this->restrictionStore = $restrictionStore; |
| 68 |
} |
| 69 |
|
| 70 |
public function execute( $par ) { |
| 71 |
$this->setHeaders(); |
| 72 |
$this->outputHeader(); |
| 73 |
$this->getOutput()->addModuleStyles( 'mediawiki.special' ); |
| 74 |
$this->addHelpLink( 'Help:Protected_pages' ); |
| 75 |
|
| 76 |
$request = $this->getRequest(); |
| 77 |
$type = $request->getVal( 'type' ); |
| 78 |
$level = $request->getVal( 'level' ); |
| 79 |
$sizetype = $request->getVal( 'size-mode' ); |
| 80 |
$size = $request->getIntOrNull( 'size' ); |
| 81 |
$ns = $request->getIntOrNull( 'namespace' ); |
| 82 |
|
| 83 |
$filters = $request->getArray( 'wpfilters', [] ); |
| 84 |
$indefOnly = in_array( 'indefonly', $filters ); |
| 85 |
$cascadeOnly = in_array( 'cascadeonly', $filters ); |
| 86 |
$noRedirect = in_array( 'noredirect', $filters ); |
| 87 |
|
| 88 |
$pager = new ProtectedPagesPager( |
| 89 |
$this->getContext(), |
| 90 |
$this->commentStore, |
| 91 |
$this->linkBatchFactory, |
| 92 |
$this->getLinkRenderer(), |
| 93 |
$this->dbProvider, |
| 94 |
$this->rowCommentFormatter, |
| 95 |
$type, |
| 96 |
$level, |
| 97 |
$ns, |
| 98 |
$sizetype, |
| 99 |
$size, |
| 100 |
$indefOnly, |
| 101 |
$cascadeOnly, |
| 102 |
$noRedirect |
| 103 |
); |
| 104 |
|
| 105 |
$this->getOutput()->addHTML( $this->showOptions( |
| 106 |
$type, |
| 107 |
$level, |
| 108 |
$filters |
| 109 |
) ); |
| 110 |
|
| 111 |
if ( $pager->getNumRows() ) { |
| 112 |
$this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' ); |
| 113 |
$this->getOutput()->addParserOutputContent( $pager->getFullOutput() ); |
| 114 |
} else { |
| 115 |
$this->getOutput()->addWikiMsg( 'protectedpagesempty' ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
protected function showOptions( $type, $level, $filters ) { |
| 127 |
$formDescriptor = [ |
| 128 |
'namespace' => [ |
| 129 |
'class' => HTMLSelectNamespace::class, |
| 130 |
'name' => 'namespace', |
| 131 |
'id' => 'namespace', |
| 132 |
'cssclass' => 'namespaceselector', |
| 133 |
'all' => '', |
| 134 |
'label' => $this->msg( 'namespace' )->text(), |
| 135 |
], |
| 136 |
'typemenu' => $this->getTypeMenu( $type ), |
| 137 |
'levelmenu' => $this->getLevelMenu( $level ), |
| 138 |
'filters' => [ |
| 139 |
'class' => HTMLMultiSelectField::class, |
| 140 |
'label' => $this->msg( 'protectedpages-filters' )->text(), |
| 141 |
'flatlist' => true, |
| 142 |
'options-messages' => [ |
| 143 |
'protectedpages-indef' => 'indefonly', |
| 144 |
'protectedpages-cascade' => 'cascadeonly', |
| 145 |
'protectedpages-noredirect' => 'noredirect', |
| 146 |
], |
| 147 |
'default' => $filters, |
| 148 |
], |
| 149 |
'sizelimit' => [ |
| 150 |
'class' => HTMLSizeFilterField::class, |
| 151 |
'name' => 'size', |
| 152 |
] |
| 153 |
]; |
| 154 |
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
| 155 |
->setMethod( 'get' ) |
| 156 |
->setWrapperLegendMsg( 'protectedpages' ) |
| 157 |
->setSubmitTextMsg( 'protectedpages-submit' ); |
| 158 |
|
| 159 |
return $htmlForm->prepareForm()->getHTML( false ); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
protected function getTypeMenu( $pr_type ) { |
| 168 |
$m = []; |
| 169 |
$options = []; |
| 170 |
|
| 171 |
|
| 172 |
foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) { |
| 173 |
|
| 174 |
$text = $this->msg( "restriction-$type" )->text(); |
| 175 |
$m[$text] = $type; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
foreach ( $m as $text => $type ) { |
| 180 |
$options[$text] = $type; |
| 181 |
} |
| 182 |
|
| 183 |
return [ |
| 184 |
'type' => 'select', |
| 185 |
'options' => $options, |
| 186 |
'label' => $this->msg( 'restriction-type' )->text(), |
| 187 |
'name' => 'type', |
| 188 |
'id' => 'type', |
| 189 |
]; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
protected function getLevelMenu( $pr_level ) { |
| 198 |
$options = [ 'restriction-level-all' => 0 ]; |
| 199 |
|
| 200 |
|
| 201 |
foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) { |
| 202 |
if ( $type != '' && $type != '*' ) { |
| 203 |
|
| 204 |
$options["restriction-level-$type"] = $type; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
return [ |
| 209 |
'type' => 'select', |
| 210 |
'options-messages' => $options, |
| 211 |
'label-message' => 'restriction-level', |
| 212 |
'name' => 'level', |
| 213 |
'id' => 'level', |
| 214 |
]; |
| 215 |
} |
| 216 |
|
| 217 |
protected function getGroupName() { |
| 218 |
return 'maintenance'; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
class_alias( SpecialProtectedPages::class, 'SpecialProtectedpages' ); |