MediaWiki  master
SpecialProtectedpages.php
Go to the documentation of this file.
1 <?php
27 
34  protected $IdLevel = 'level';
35  protected $IdType = 'type';
36 
39 
41  private $loadBalancer;
42 
44  private $commentStore;
45 
47  private $userCache;
48 
51 
59  public function __construct(
65  ) {
66  parent::__construct( 'Protectedpages' );
67  $this->linkBatchFactory = $linkBatchFactory;
68  $this->loadBalancer = $loadBalancer;
69  $this->commentStore = $commentStore;
70  $this->userCache = $userCache;
71  $this->rowCommentFormatter = $rowCommentFormatter;
72  }
73 
74  public function execute( $par ) {
75  $this->setHeaders();
76  $this->outputHeader();
77  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
78  $this->addHelpLink( 'Help:Protected_pages' );
79 
80  $request = $this->getRequest();
81  $type = $request->getVal( $this->IdType );
82  $level = $request->getVal( $this->IdLevel );
83  $sizetype = $request->getVal( 'size-mode' );
84  $size = $request->getIntOrNull( 'size' );
85  $ns = $request->getIntOrNull( 'namespace' );
86 
87  $filters = $request->getArray( 'wpfilters', [] );
88  $indefOnly = in_array( 'indefonly', $filters );
89  $cascadeOnly = in_array( 'cascadeonly', $filters );
90  $noRedirect = in_array( 'noredirect', $filters );
91 
92  $pager = new ProtectedPagesPager(
93  $this,
94  [],
95  $type,
96  $level,
97  $ns,
98  $sizetype,
99  $size,
100  $indefOnly,
101  $cascadeOnly,
102  $noRedirect,
103  $this->getLinkRenderer(),
104  $this->linkBatchFactory,
105  $this->loadBalancer,
106  $this->commentStore,
107  $this->userCache,
108  $this->rowCommentFormatter
109  );
110 
111  $this->getOutput()->addHTML( $this->showOptions(
112  $ns,
113  $type,
114  $level,
115  $sizetype,
116  $size,
117  $filters
118  ) );
119 
120  if ( $pager->getNumRows() ) {
121  $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
122  } else {
123  $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
124  }
125  }
126 
137  protected function showOptions( $namespace, $type, $level, $sizetype,
138  $size, $filters
139  ) {
140  $formDescriptor = [
141  'namespace' => [
142  'class' => HTMLSelectNamespace::class,
143  'name' => 'namespace',
144  'id' => 'namespace',
145  'cssclass' => 'namespaceselector',
146  'all' => '',
147  'label' => $this->msg( 'namespace' )->text(),
148  ],
149  'typemenu' => $this->getTypeMenu( $type ),
150  'levelmenu' => $this->getLevelMenu( $level ),
151  'filters' => [
152  'class' => HTMLMultiSelectField::class,
153  'label' => $this->msg( 'protectedpages-filters' )->text(),
154  'flatlist' => true,
155  'options-messages' => [
156  'protectedpages-indef' => 'indefonly',
157  'protectedpages-cascade' => 'cascadeonly',
158  'protectedpages-noredirect' => 'noredirect',
159  ],
160  'default' => $filters,
161  ],
162  'sizelimit' => [
163  'class' => HTMLSizeFilterField::class,
164  'name' => 'size',
165  ]
166  ];
167  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
168  ->setMethod( 'get' )
169  ->setWrapperLegendMsg( 'protectedpages' )
170  ->setSubmitTextMsg( 'protectedpages-submit' );
171 
172  return $htmlForm->prepareForm()->getHTML( false );
173  }
174 
180  protected function getTypeMenu( $pr_type ) {
181  $m = []; // Temporary array
182  $options = [];
183 
184  // First pass to load the log names
185  foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
186  // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
187  $text = $this->msg( "restriction-$type" )->text();
188  $m[$text] = $type;
189  }
190 
191  // Third pass generates sorted XHTML content
192  foreach ( $m as $text => $type ) {
193  $options[$text] = $type;
194  }
195 
196  return [
197  'type' => 'select',
198  'options' => $options,
199  'label' => $this->msg( 'restriction-type' )->text(),
200  'name' => $this->IdType,
201  'id' => $this->IdType,
202  ];
203  }
204 
210  protected function getLevelMenu( $pr_level ) {
211  // Temporary array
212  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
213  $options = [];
214 
215  // First pass to load the log names
216  foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
217  // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
218  if ( $type != '' && $type != '*' ) {
219  $text = $this->msg( "restriction-level-$type" )->text();
220  $m[$text] = $type;
221  }
222  }
223 
224  // Third pass generates sorted XHTML content
225  foreach ( $m as $text => $type ) {
226  $options[$text] = $type;
227  }
228 
229  return [
230  'type' => 'select',
231  'options' => $options,
232  'label' => $this->msg( 'restriction-level' )->text(),
233  'name' => $this->IdLevel,
234  'id' => $this->IdLevel
235  ];
236  }
237 
238  protected function getGroupName() {
239  return 'maintenance';
240  }
241 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:936
SpecialProtectedpages\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialProtectedpages.php:74
Title\getFilteredRestrictionTypes
static getFilteredRestrictionTypes( $exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2422
UserCache
Definition: UserCache.php:32
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:814
SpecialProtectedpages\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialProtectedpages.php:41
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
SpecialProtectedpages\$rowCommentFormatter
RowCommentFormatter $rowCommentFormatter
Definition: SpecialProtectedpages.php:50
SpecialProtectedpages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialProtectedpages.php:238
SpecialProtectedpages\$commentStore
CommentStore $commentStore
Definition: SpecialProtectedpages.php:44
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:972
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:902
SpecialProtectedpages
A special page that lists protected pages.
Definition: SpecialProtectedpages.php:33
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialProtectedpages\__construct
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, CommentStore $commentStore, UserCache $userCache, RowCommentFormatter $rowCommentFormatter)
Definition: SpecialProtectedpages.php:59
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:642
SpecialProtectedpages\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialProtectedpages.php:38
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:788
SpecialProtectedpages\getLevelMenu
getLevelMenu( $pr_level)
Creates the input label of the restriction level.
Definition: SpecialProtectedpages.php:210
SpecialProtectedpages\getTypeMenu
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
Definition: SpecialProtectedpages.php:180
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:804
SpecialProtectedpages\$IdType
$IdType
Definition: SpecialProtectedpages.php:35
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1052
MediaWiki\CommentFormatter\RowCommentFormatter
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Definition: RowCommentFormatter.php:15
SpecialProtectedpages\$IdLevel
$IdLevel
Definition: SpecialProtectedpages.php:34
SpecialProtectedpages\$userCache
UserCache $userCache
Definition: SpecialProtectedpages.php:47
SpecialProtectedpages\showOptions
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
Definition: SpecialProtectedpages.php:137
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:332
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:733
ProtectedPagesPager
Definition: ProtectedPagesPager.php:27
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:52