MediaWiki  master
SpecialProtectedpages.php
Go to the documentation of this file.
1 <?php
29 
36  protected $IdLevel = 'level';
37  protected $IdType = 'type';
38 
40  private $linkBatchFactory;
41 
43  private $loadBalancer;
44 
46  private $commentStore;
47 
49  private $userCache;
50 
52  private $rowCommentFormatter;
53 
55  private $restrictionStore;
56 
65  public function __construct(
66  LinkBatchFactory $linkBatchFactory,
67  ILoadBalancer $loadBalancer,
68  CommentStore $commentStore,
69  UserCache $userCache,
70  RowCommentFormatter $rowCommentFormatter,
71  RestrictionStore $restrictionStore
72  ) {
73  parent::__construct( 'Protectedpages' );
74  $this->linkBatchFactory = $linkBatchFactory;
75  $this->loadBalancer = $loadBalancer;
76  $this->commentStore = $commentStore;
77  $this->userCache = $userCache;
78  $this->rowCommentFormatter = $rowCommentFormatter;
79  $this->restrictionStore = $restrictionStore;
80  }
81 
82  public function execute( $par ) {
83  $this->setHeaders();
84  $this->outputHeader();
85  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
86  $this->addHelpLink( 'Help:Protected_pages' );
87 
88  $request = $this->getRequest();
89  $type = $request->getVal( $this->IdType );
90  $level = $request->getVal( $this->IdLevel );
91  $sizetype = $request->getVal( 'size-mode' );
92  $size = $request->getIntOrNull( 'size' );
93  $ns = $request->getIntOrNull( 'namespace' );
94 
95  $filters = $request->getArray( 'wpfilters', [] );
96  $indefOnly = in_array( 'indefonly', $filters );
97  $cascadeOnly = in_array( 'cascadeonly', $filters );
98  $noRedirect = in_array( 'noredirect', $filters );
99 
100  $pager = new ProtectedPagesPager(
101  $this->getContext(),
102  $this->commentStore,
103  $this->linkBatchFactory,
104  $this->getLinkRenderer(),
105  $this->loadBalancer,
106  $this->rowCommentFormatter,
107  $this->userCache,
108  [],
109  $type,
110  $level,
111  $ns,
112  $sizetype,
113  $size,
114  $indefOnly,
115  $cascadeOnly,
116  $noRedirect
117  );
118 
119  $this->getOutput()->addHTML( $this->showOptions(
120  $ns,
121  $type,
122  $level,
123  $sizetype,
124  $size,
125  $filters
126  ) );
127 
128  if ( $pager->getNumRows() ) {
129  $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
130  $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
131  } else {
132  $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
133  }
134  }
135 
146  protected function showOptions( $namespace, $type, $level, $sizetype,
147  $size, $filters
148  ) {
149  $formDescriptor = [
150  'namespace' => [
151  'class' => HTMLSelectNamespace::class,
152  'name' => 'namespace',
153  'id' => 'namespace',
154  'cssclass' => 'namespaceselector',
155  'all' => '',
156  'label' => $this->msg( 'namespace' )->text(),
157  ],
158  'typemenu' => $this->getTypeMenu( $type ),
159  'levelmenu' => $this->getLevelMenu( $level ),
160  'filters' => [
161  'class' => HTMLMultiSelectField::class,
162  'label' => $this->msg( 'protectedpages-filters' )->text(),
163  'flatlist' => true,
164  'options-messages' => [
165  'protectedpages-indef' => 'indefonly',
166  'protectedpages-cascade' => 'cascadeonly',
167  'protectedpages-noredirect' => 'noredirect',
168  ],
169  'default' => $filters,
170  ],
171  'sizelimit' => [
172  'class' => HTMLSizeFilterField::class,
173  'name' => 'size',
174  ]
175  ];
176  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
177  ->setMethod( 'get' )
178  ->setWrapperLegendMsg( 'protectedpages' )
179  ->setSubmitTextMsg( 'protectedpages-submit' );
180 
181  return $htmlForm->prepareForm()->getHTML( false );
182  }
183 
189  protected function getTypeMenu( $pr_type ) {
190  $m = []; // Temporary array
191  $options = [];
192 
193  // First pass to load the log names
194  foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
195  // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
196  $text = $this->msg( "restriction-$type" )->text();
197  $m[$text] = $type;
198  }
199 
200  // Third pass generates sorted XHTML content
201  foreach ( $m as $text => $type ) {
202  $options[$text] = $type;
203  }
204 
205  return [
206  'type' => 'select',
207  'options' => $options,
208  'label' => $this->msg( 'restriction-type' )->text(),
209  'name' => $this->IdType,
210  'id' => $this->IdType,
211  ];
212  }
213 
219  protected function getLevelMenu( $pr_level ) {
220  // Temporary array
221  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
222  $options = [];
223 
224  // First pass to load the log names
225  foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
226  // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
227  if ( $type != '' && $type != '*' ) {
228  $text = $this->msg( "restriction-level-$type" )->text();
229  $m[$text] = $type;
230  }
231  }
232 
233  // Third pass generates sorted XHTML content
234  foreach ( $m as $text => $type ) {
235  $options[$text] = $type;
236  }
237 
238  return [
239  'type' => 'select',
240  'options' => $options,
241  'label' => $this->msg( 'restriction-level' )->text(),
242  'name' => $this->IdLevel,
243  'id' => $this->IdLevel
244  ];
245  }
246 
247  protected function getGroupName() {
248  return 'maintenance';
249  }
250 }
Handle database storage of comments such as edit summaries and log reasons.
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:349
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
A class containing constants representing the names of configuration variables.
Parent class for all special pages.
Definition: SpecialPage.php:44
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists protected pages.
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, CommentStore $commentStore, UserCache $userCache, RowCommentFormatter $rowCommentFormatter, RestrictionStore $restrictionStore)
getLevelMenu( $pr_level)
Creates the input label of the restriction level.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
execute( $par)
Default execute method Checks user permissions.
Create and track the database connections and transactions for a given database cluster.