MediaWiki  master
SpecialProtectedpages.php
Go to the documentation of this file.
1 <?php
26 
33  protected $IdLevel = 'level';
34  protected $IdType = 'type';
35 
38 
40  private $loadBalancer;
41 
43  private $commentStore;
44 
46  private $userCache;
47 
54  public function __construct(
59  ) {
60  parent::__construct( 'Protectedpages' );
61  $this->linkBatchFactory = $linkBatchFactory;
62  $this->loadBalancer = $loadBalancer;
63  $this->commentStore = $commentStore;
64  $this->userCache = $userCache;
65  }
66 
67  public function execute( $par ) {
68  $this->setHeaders();
69  $this->outputHeader();
70  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
71  $this->addHelpLink( 'Help:Protected_pages' );
72 
73  $request = $this->getRequest();
74  $type = $request->getVal( $this->IdType );
75  $level = $request->getVal( $this->IdLevel );
76  $sizetype = $request->getVal( 'size-mode' );
77  $size = $request->getIntOrNull( 'size' );
78  $ns = $request->getIntOrNull( 'namespace' );
79 
80  $filters = $request->getArray( 'wpfilters', [] );
81  $indefOnly = in_array( 'indefonly', $filters );
82  $cascadeOnly = in_array( 'cascadeonly', $filters );
83  $noRedirect = in_array( 'noredirect', $filters );
84 
85  $pager = new ProtectedPagesPager(
86  $this,
87  [],
88  $type,
89  $level,
90  $ns,
91  $sizetype,
92  $size,
93  $indefOnly,
94  $cascadeOnly,
95  $noRedirect,
96  $this->getLinkRenderer(),
97  $this->linkBatchFactory,
98  $this->loadBalancer,
99  $this->commentStore,
100  $this->userCache
101  );
102 
103  $this->getOutput()->addHTML( $this->showOptions(
104  $ns,
105  $type,
106  $level,
107  $sizetype,
108  $size,
109  $filters
110  ) );
111 
112  if ( $pager->getNumRows() ) {
113  $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
114  } else {
115  $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
116  }
117  }
118 
129  protected function showOptions( $namespace, $type, $level, $sizetype,
130  $size, $filters
131  ) {
132  $formDescriptor = [
133  'namespace' => [
134  'class' => HTMLSelectNamespace::class,
135  'name' => 'namespace',
136  'id' => 'namespace',
137  'cssclass' => 'namespaceselector',
138  'all' => '',
139  'label' => $this->msg( 'namespace' )->text(),
140  ],
141  'typemenu' => $this->getTypeMenu( $type ),
142  'levelmenu' => $this->getLevelMenu( $level ),
143  'filters' => [
144  'class' => HTMLMultiSelectField::class,
145  'label' => $this->msg( 'protectedpages-filters' )->text(),
146  'flatlist' => true,
147  'options-messages' => [
148  'protectedpages-indef' => 'indefonly',
149  'protectedpages-cascade' => 'cascadeonly',
150  'protectedpages-noredirect' => 'noredirect',
151  ],
152  'default' => $filters,
153  ],
154  'sizelimit' => [
155  'class' => HTMLSizeFilterField::class,
156  'name' => 'size',
157  ]
158  ];
159  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
160  ->setMethod( 'get' )
161  ->setWrapperLegendMsg( 'protectedpages' )
162  ->setSubmitTextMsg( 'protectedpages-submit' );
163 
164  return $htmlForm->prepareForm()->getHTML( false );
165  }
166 
172  protected function getTypeMenu( $pr_type ) {
173  $m = []; // Temporary array
174  $options = [];
175 
176  // First pass to load the log names
177  foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
178  // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
179  $text = $this->msg( "restriction-$type" )->text();
180  $m[$text] = $type;
181  }
182 
183  // Third pass generates sorted XHTML content
184  foreach ( $m as $text => $type ) {
185  $options[$text] = $type;
186  }
187 
188  return [
189  'type' => 'select',
190  'options' => $options,
191  'label' => $this->msg( 'restriction-type' )->text(),
192  'name' => $this->IdType,
193  'id' => $this->IdType,
194  ];
195  }
196 
202  protected function getLevelMenu( $pr_level ) {
203  // Temporary array
204  $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
205  $options = [];
206 
207  // First pass to load the log names
208  foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
209  // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
210  if ( $type != '' && $type != '*' ) {
211  $text = $this->msg( "restriction-level-$type" )->text();
212  $m[$text] = $type;
213  }
214  }
215 
216  // Third pass generates sorted XHTML content
217  foreach ( $m as $text => $type ) {
218  $options[$text] = $type;
219  }
220 
221  return [
222  'type' => 'select',
223  'options' => $options,
224  'label' => $this->msg( 'restriction-level' )->text(),
225  'name' => $this->IdLevel,
226  'id' => $this->IdLevel
227  ];
228  }
229 
230  protected function getGroupName() {
231  return 'maintenance';
232  }
233 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialProtectedpages\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialProtectedpages.php:67
Title\getFilteredRestrictionTypes
static getFilteredRestrictionTypes( $exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2455
UserCache
Definition: UserCache.php:32
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
SpecialProtectedpages\__construct
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, CommentStore $commentStore, UserCache $userCache)
Definition: SpecialProtectedpages.php:54
SpecialProtectedpages\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialProtectedpages.php:40
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
SpecialProtectedpages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialProtectedpages.php:230
SpecialProtectedpages\$commentStore
CommentStore $commentStore
Definition: SpecialProtectedpages.php:43
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
SpecialProtectedpages
A special page that lists protected pages.
Definition: SpecialProtectedpages.php:32
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:618
SpecialProtectedpages\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialProtectedpages.php:37
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
SpecialProtectedpages\getLevelMenu
getLevelMenu( $pr_level)
Creates the input label of the restriction level.
Definition: SpecialProtectedpages.php:202
SpecialProtectedpages\getTypeMenu
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
Definition: SpecialProtectedpages.php:172
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:780
SpecialProtectedpages\$IdType
$IdType
Definition: SpecialProtectedpages.php:34
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialProtectedpages\$IdLevel
$IdLevel
Definition: SpecialProtectedpages.php:33
SpecialProtectedpages\$userCache
UserCache $userCache
Definition: SpecialProtectedpages.php:46
SpecialProtectedpages\showOptions
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
Definition: SpecialProtectedpages.php:129
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:326
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:709
ProtectedPagesPager
Definition: ProtectedPagesPager.php:26
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:52