Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / specials / SpecialRevisionDelete.php
1 <?php
2 /**
3 * Implements Special:Revisiondelete
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 use MediaWiki\Storage\RevisionRecord;
25
26 /**
27 * Special page allowing users with the appropriate permissions to view
28 * and hide revisions. Log items can also be hidden.
29 *
30 * @ingroup SpecialPage
31 */
32 class SpecialRevisionDelete extends UnlistedSpecialPage {
33 /** @var bool Was the DB modified in this request */
34 protected $wasSaved = false;
35
36 /** @var bool True if the submit button was clicked, and the form was posted */
37 private $submitClicked;
38
39 /** @var array Target ID list */
40 private $ids;
41
42 /** @var string Archive name, for reviewing deleted files */
43 private $archiveName;
44
45 /** @var string Edit token for securing image views against XSS */
46 private $token;
47
48 /** @var Title Title object for target parameter */
49 private $targetObj;
50
51 /** @var string Deletion type, may be revision, archive, oldimage, filearchive, logging. */
52 private $typeName;
53
54 /** @var array Array of checkbox specs (message, name, deletion bits) */
55 private $checks;
56
57 /** @var array UI Labels about the current type */
58 private $typeLabels;
59
60 /** @var RevDelList RevDelList object, storing the list of items to be deleted/undeleted */
61 private $revDelList;
62
63 /** @var bool Whether user is allowed to perform the action */
64 private $mIsAllowed;
65
66 /** @var string */
67 private $otherReason;
68
69 /**
70 * UI labels for each type.
71 */
72 private static $UILabels = [
73 'revision' => [
74 'check-label' => 'revdelete-hide-text',
75 'success' => 'revdelete-success',
76 'failure' => 'revdelete-failure',
77 'text' => 'revdelete-text-text',
78 'selected' => 'revdelete-selected-text',
79 ],
80 'archive' => [
81 'check-label' => 'revdelete-hide-text',
82 'success' => 'revdelete-success',
83 'failure' => 'revdelete-failure',
84 'text' => 'revdelete-text-text',
85 'selected' => 'revdelete-selected-text',
86 ],
87 'oldimage' => [
88 'check-label' => 'revdelete-hide-image',
89 'success' => 'revdelete-success',
90 'failure' => 'revdelete-failure',
91 'text' => 'revdelete-text-file',
92 'selected' => 'revdelete-selected-file',
93 ],
94 'filearchive' => [
95 'check-label' => 'revdelete-hide-image',
96 'success' => 'revdelete-success',
97 'failure' => 'revdelete-failure',
98 'text' => 'revdelete-text-file',
99 'selected' => 'revdelete-selected-file',
100 ],
101 'logging' => [
102 'check-label' => 'revdelete-hide-name',
103 'success' => 'logdelete-success',
104 'failure' => 'logdelete-failure',
105 'text' => 'logdelete-text',
106 'selected' => 'logdelete-selected',
107 ],
108 ];
109
110 public function __construct() {
111 parent::__construct( 'Revisiondelete', 'deleterevision' );
112 }
113
114 public function doesWrites() {
115 return true;
116 }
117
118 public function execute( $par ) {
119 $this->useTransactionalTimeLimit();
120
121 $this->checkPermissions();
122 $this->checkReadOnly();
123
124 $output = $this->getOutput();
125 $user = $this->getUser();
126
127 // Check blocks
128 // @TODO Use PermissionManager::isBlockedFrom() instead.
129 $block = $user->getBlock();
130 if ( $block ) {
131 throw new UserBlockedError( $block );
132 }
133
134 $this->setHeaders();
135 $this->outputHeader();
136 $request = $this->getRequest();
137 $this->submitClicked = $request->wasPosted() && $request->getBool( 'wpSubmit' );
138 # Handle our many different possible input types.
139 $ids = $request->getVal( 'ids' );
140 if ( !is_null( $ids ) ) {
141 # Allow CSV, for backwards compatibility, or a single ID for show/hide links
142 $this->ids = explode( ',', $ids );
143 } else {
144 # Array input
145 $this->ids = array_keys( $request->getArray( 'ids', [] ) );
146 }
147 // $this->ids = array_map( 'intval', $this->ids );
148 $this->ids = array_unique( array_filter( $this->ids ) );
149
150 $this->typeName = $request->getVal( 'type' );
151 $this->targetObj = Title::newFromText( $request->getText( 'target' ) );
152
153 # For reviewing deleted files...
154 $this->archiveName = $request->getVal( 'file' );
155 $this->token = $request->getVal( 'token' );
156 if ( $this->archiveName && $this->targetObj ) {
157 $this->tryShowFile( $this->archiveName );
158
159 return;
160 }
161
162 $this->typeName = RevisionDeleter::getCanonicalTypeName( $this->typeName );
163
164 # No targets?
165 if ( !$this->typeName || count( $this->ids ) == 0 ) {
166 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
167 }
168
169 # Allow the list type to adjust the passed target
170 $this->targetObj = RevisionDeleter::suggestTarget(
171 $this->typeName,
172 $this->targetObj,
173 $this->ids
174 );
175
176 # We need a target page!
177 if ( $this->targetObj === null ) {
178 $output->addWikiMsg( 'undelete-header' );
179
180 return;
181 }
182
183 $this->typeLabels = self::$UILabels[$this->typeName];
184 $list = $this->getList();
185 $list->reset();
186 $this->mIsAllowed = $user->isAllowed( RevisionDeleter::getRestriction( $this->typeName ) );
187 $canViewSuppressedOnly = $this->getUser()->isAllowed( 'viewsuppressed' ) &&
188 !$this->getUser()->isAllowed( 'suppressrevision' );
189 $pageIsSuppressed = $list->areAnySuppressed();
190 $this->mIsAllowed = $this->mIsAllowed && !( $canViewSuppressedOnly && $pageIsSuppressed );
191
192 $this->otherReason = $request->getVal( 'wpReason' );
193 # Give a link to the logs/hist for this page
194 $this->showConvenienceLinks();
195
196 # Initialise checkboxes
197 $this->checks = [
198 # Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name
199 [ $this->typeLabels['check-label'], 'wpHidePrimary',
200 RevisionDeleter::getRevdelConstant( $this->typeName )
201 ],
202 [ 'revdelete-hide-comment', 'wpHideComment', RevisionRecord::DELETED_COMMENT ],
203 [ 'revdelete-hide-user', 'wpHideUser', RevisionRecord::DELETED_USER ]
204 ];
205 if ( $user->isAllowed( 'suppressrevision' ) ) {
206 $this->checks[] = [ 'revdelete-hide-restricted',
207 'wpHideRestricted', RevisionRecord::DELETED_RESTRICTED ];
208 }
209
210 # Either submit or create our form
211 if ( $this->mIsAllowed && $this->submitClicked ) {
212 $this->submit();
213 } else {
214 $this->showForm();
215 }
216
217 if ( $user->isAllowed( 'deletedhistory' ) ) {
218 $qc = $this->getLogQueryCond();
219 # Show relevant lines from the deletion log
220 $deleteLogPage = new LogPage( 'delete' );
221 $output->addHTML( "<h2>" . $deleteLogPage->getName()->escaped() . "</h2>\n" );
222 LogEventsList::showLogExtract(
223 $output,
224 'delete',
225 $this->targetObj,
226 '', /* user */
227 [ 'lim' => 25, 'conds' => $qc, 'useMaster' => $this->wasSaved ]
228 );
229 }
230 # Show relevant lines from the suppression log
231 if ( $user->isAllowed( 'suppressionlog' ) ) {
232 $suppressLogPage = new LogPage( 'suppress' );
233 $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" );
234 LogEventsList::showLogExtract(
235 $output,
236 'suppress',
237 $this->targetObj,
238 '',
239 [ 'lim' => 25, 'conds' => $qc, 'useMaster' => $this->wasSaved ]
240 );
241 }
242 }
243
244 /**
245 * Show some useful links in the subtitle
246 */
247 protected function showConvenienceLinks() {
248 $linkRenderer = $this->getLinkRenderer();
249 # Give a link to the logs/hist for this page
250 if ( $this->targetObj ) {
251 // Also set header tabs to be for the target.
252 $this->getSkin()->setRelevantTitle( $this->targetObj );
253
254 $links = [];
255 $links[] = $linkRenderer->makeKnownLink(
256 SpecialPage::getTitleFor( 'Log' ),
257 $this->msg( 'viewpagelogs' )->text(),
258 [],
259 [ 'page' => $this->targetObj->getPrefixedText() ]
260 );
261 if ( !$this->targetObj->isSpecialPage() ) {
262 # Give a link to the page history
263 $links[] = $linkRenderer->makeKnownLink(
264 $this->targetObj,
265 $this->msg( 'pagehist' )->text(),
266 [],
267 [ 'action' => 'history' ]
268 );
269 # Link to deleted edits
270 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
271 $undelete = SpecialPage::getTitleFor( 'Undelete' );
272 $links[] = $linkRenderer->makeKnownLink(
273 $undelete,
274 $this->msg( 'deletedhist' )->text(),
275 [],
276 [ 'target' => $this->targetObj->getPrefixedDBkey() ]
277 );
278 }
279 }
280 # Logs themselves don't have histories or archived revisions
281 $this->getOutput()->addSubtitle( $this->getLanguage()->pipeList( $links ) );
282 }
283 }
284
285 /**
286 * Get the condition used for fetching log snippets
287 * @return array
288 */
289 protected function getLogQueryCond() {
290 $conds = [];
291 // Revision delete logs for these item
292 $conds['log_type'] = [ 'delete', 'suppress' ];
293 $conds['log_action'] = $this->getList()->getLogAction();
294 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
295 $conds['ls_value'] = $this->ids;
296
297 return $conds;
298 }
299
300 /**
301 * Show a deleted file version requested by the visitor.
302 * @todo Mostly copied from Special:Undelete. Refactor.
303 * @param string $archiveName
304 * @throws MWException
305 * @throws PermissionsError
306 */
307 protected function tryShowFile( $archiveName ) {
308 $repo = RepoGroup::singleton()->getLocalRepo();
309 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName );
310 $oimage->load();
311 // Check if user is allowed to see this file
312 if ( !$oimage->exists() ) {
313 $this->getOutput()->addWikiMsg( 'revdelete-no-file' );
314
315 return;
316 }
317 $user = $this->getUser();
318 if ( !$oimage->userCan( File::DELETED_FILE, $user ) ) {
319 if ( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) {
320 throw new PermissionsError( 'suppressrevision' );
321 } else {
322 throw new PermissionsError( 'deletedtext' );
323 }
324 }
325 if ( !$user->matchEditToken( $this->token, $archiveName ) ) {
326 $lang = $this->getLanguage();
327 $this->getOutput()->addWikiMsg( 'revdelete-show-file-confirm',
328 $this->targetObj->getText(),
329 $lang->userDate( $oimage->getTimestamp(), $user ),
330 $lang->userTime( $oimage->getTimestamp(), $user ) );
331 $this->getOutput()->addHTML(
332 Xml::openElement( 'form', [
333 'method' => 'POST',
334 'action' => $this->getPageTitle()->getLocalURL( [
335 'target' => $this->targetObj->getPrefixedDBkey(),
336 'file' => $archiveName,
337 'token' => $user->getEditToken( $archiveName ),
338 ] )
339 ]
340 ) .
341 Xml::submitButton( $this->msg( 'revdelete-show-file-submit' )->text() ) .
342 '</form>'
343 );
344
345 return;
346 }
347 $this->getOutput()->disable();
348 # We mustn't allow the output to be CDN cached, otherwise
349 # if an admin previews a deleted image, and it's cached, then
350 # a user without appropriate permissions can toddle off and
351 # nab the image, and CDN will serve it
352 $this->getRequest()->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
353 $this->getRequest()->response()->header(
354 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate'
355 );
356 $this->getRequest()->response()->header( 'Pragma: no-cache' );
357
358 $key = $oimage->getStorageKey();
359 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
360 $repo->streamFileWithStatus( $path );
361 }
362
363 /**
364 * Get the list object for this request
365 * @return RevDelList
366 */
367 protected function getList() {
368 if ( is_null( $this->revDelList ) ) {
369 $this->revDelList = RevisionDeleter::createList(
370 $this->typeName, $this->getContext(), $this->targetObj, $this->ids
371 );
372 }
373
374 return $this->revDelList;
375 }
376
377 /**
378 * Show a list of items that we will operate on, and show a form with checkboxes
379 * which will allow the user to choose new visibility settings.
380 */
381 protected function showForm() {
382 $userAllowed = true;
383
384 // Messages: revdelete-selected-text, revdelete-selected-file, logdelete-selected
385 $out = $this->getOutput();
386 $out->wrapWikiMsg( "<strong>$1</strong>", [ $this->typeLabels['selected'],
387 $this->getLanguage()->formatNum( count( $this->ids ) ), $this->targetObj->getPrefixedText() ] );
388
389 $this->addHelpLink( 'Help:RevisionDelete' );
390 $out->addHTML( "<ul>" );
391
392 $numRevisions = 0;
393 // Live revisions...
394 $list = $this->getList();
395 for ( $list->reset(); $list->current(); $list->next() ) {
396 $item = $list->current();
397
398 if ( !$item->canView() ) {
399 if ( !$this->submitClicked ) {
400 throw new PermissionsError( 'suppressrevision' );
401 }
402 $userAllowed = false;
403 }
404
405 $numRevisions++;
406 $out->addHTML( $item->getHTML() );
407 }
408
409 if ( !$numRevisions ) {
410 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
411 }
412
413 $out->addHTML( "</ul>" );
414 // Explanation text
415 $this->addUsageText();
416
417 // Normal sysops can always see what they did, but can't always change it
418 if ( !$userAllowed ) {
419 return;
420 }
421
422 // Show form if the user can submit
423 if ( $this->mIsAllowed ) {
424 $out->addModules( [ 'mediawiki.special.revisionDelete' ] );
425 $out->addModuleStyles( [ 'mediawiki.special',
426 'mediawiki.interface.helpers.styles' ] );
427
428 $form = Xml::openElement( 'form', [ 'method' => 'post',
429 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ),
430 'id' => 'mw-revdel-form-revisions' ] ) .
431 Xml::fieldset( $this->msg( 'revdelete-legend' )->text() ) .
432 $this->buildCheckBoxes() .
433 Xml::openElement( 'table' ) .
434 "<tr>\n" .
435 '<td class="mw-label">' .
436 Xml::label( $this->msg( 'revdelete-log' )->text(), 'wpRevDeleteReasonList' ) .
437 '</td>' .
438 '<td class="mw-input">' .
439 Xml::listDropDown( 'wpRevDeleteReasonList',
440 $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->text(),
441 $this->msg( 'revdelete-reasonotherlist' )->inContentLanguage()->text(),
442 $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' ), 'wpReasonDropDown'
443 ) .
444 '</td>' .
445 "</tr><tr>\n" .
446 '<td class="mw-label">' .
447 Xml::label( $this->msg( 'revdelete-otherreason' )->text(), 'wpReason' ) .
448 '</td>' .
449 '<td class="mw-input">' .
450 Xml::input( 'wpReason', 60, $this->otherReason, [
451 'id' => 'wpReason',
452 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
453 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
454 // Unicode codepoints.
455 // "- 155" is to leave room for the 'wpRevDeleteReasonList' value.
456 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT - 155,
457 ] ) .
458 '</td>' .
459 "</tr><tr>\n" .
460 '<td></td>' .
461 '<td class="mw-submit">' .
462 Xml::submitButton( $this->msg( 'revdelete-submit', $numRevisions )->text(),
463 [ 'name' => 'wpSubmit' ] ) .
464 '</td>' .
465 "</tr>\n" .
466 Xml::closeElement( 'table' ) .
467 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
468 Html::hidden( 'target', $this->targetObj->getPrefixedText() ) .
469 Html::hidden( 'type', $this->typeName ) .
470 Html::hidden( 'ids', implode( ',', $this->ids ) ) .
471 Xml::closeElement( 'fieldset' ) . "\n" .
472 Xml::closeElement( 'form' ) . "\n";
473 // Show link to edit the dropdown reasons
474 if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
475 $link = $this->getLinkRenderer()->makeKnownLink(
476 $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->getTitle(),
477 $this->msg( 'revdelete-edit-reasonlist' )->text(),
478 [],
479 [ 'action' => 'edit' ]
480 );
481 $form .= Xml::tags( 'p', [ 'class' => 'mw-revdel-editreasons' ], $link ) . "\n";
482 }
483 } else {
484 $form = '';
485 }
486 $out->addHTML( $form );
487 }
488
489 /**
490 * Show some introductory text
491 * @todo FIXME: Wikimedia-specific policy text
492 */
493 protected function addUsageText() {
494 // Messages: revdelete-text-text, revdelete-text-file, logdelete-text
495 $this->getOutput()->wrapWikiMsg(
496 "<strong>$1</strong>\n$2", $this->typeLabels['text'],
497 'revdelete-text-others'
498 );
499
500 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
501 $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' );
502 }
503
504 if ( $this->mIsAllowed ) {
505 $this->getOutput()->addWikiMsg( 'revdelete-confirm' );
506 }
507 }
508
509 /**
510 * @return string HTML
511 */
512 protected function buildCheckBoxes() {
513 $html = '<table>';
514 // If there is just one item, use checkboxes
515 $list = $this->getList();
516 if ( $list->length() == 1 ) {
517 $list->reset();
518 $bitfield = $list->current()->getBits(); // existing field
519
520 if ( $this->submitClicked ) {
521 $bitfield = RevisionDeleter::extractBitfield( $this->extractBitParams(), $bitfield );
522 }
523
524 foreach ( $this->checks as $item ) {
525 // Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name,
526 // revdelete-hide-comment, revdelete-hide-user, revdelete-hide-restricted
527 list( $message, $name, $field ) = $item;
528 $innerHTML = Xml::checkLabel(
529 $this->msg( $message )->text(),
530 $name,
531 $name,
532 $bitfield & $field
533 );
534
535 if ( $field == RevisionRecord::DELETED_RESTRICTED ) {
536 $innerHTML = "<b>$innerHTML</b>";
537 }
538
539 $line = Xml::tags( 'td', [ 'class' => 'mw-input' ], $innerHTML );
540 $html .= "<tr>$line</tr>\n";
541 }
542 } else {
543 // Otherwise, use tri-state radios
544 $html .= '<tr>';
545 $html .= '<th class="mw-revdel-checkbox">'
546 . $this->msg( 'revdelete-radio-same' )->escaped() . '</th>';
547 $html .= '<th class="mw-revdel-checkbox">'
548 . $this->msg( 'revdelete-radio-unset' )->escaped() . '</th>';
549 $html .= '<th class="mw-revdel-checkbox">'
550 . $this->msg( 'revdelete-radio-set' )->escaped() . '</th>';
551 $html .= "<th></th></tr>\n";
552 foreach ( $this->checks as $item ) {
553 // Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name,
554 // revdelete-hide-comment, revdelete-hide-user, revdelete-hide-restricted
555 list( $message, $name, $field ) = $item;
556 // If there are several items, use third state by default...
557 if ( $this->submitClicked ) {
558 $selected = $this->getRequest()->getInt( $name, 0 /* unchecked */ );
559 } else {
560 $selected = -1; // use existing field
561 }
562 $line = '<td class="mw-revdel-checkbox">' . Xml::radio( $name, -1, $selected == -1 ) . '</td>';
563 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>';
564 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>';
565 $label = $this->msg( $message )->escaped();
566 if ( $field == RevisionRecord::DELETED_RESTRICTED ) {
567 $label = "<b>$label</b>";
568 }
569 $line .= "<td>$label</td>";
570 $html .= "<tr>$line</tr>\n";
571 }
572 }
573
574 $html .= '</table>';
575
576 return $html;
577 }
578
579 /**
580 * UI entry point for form submission.
581 * @throws PermissionsError
582 * @return bool
583 */
584 protected function submit() {
585 # Check edit token on submission
586 $token = $this->getRequest()->getVal( 'wpEditToken' );
587 if ( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) {
588 $this->getOutput()->addWikiMsg( 'sessionfailure' );
589
590 return false;
591 }
592 $bitParams = $this->extractBitParams();
593 // from dropdown
594 $listReason = $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' );
595 $comment = $listReason;
596 if ( $comment === 'other' ) {
597 $comment = $this->otherReason;
598 } elseif ( $this->otherReason !== '' ) {
599 // Entry from drop down menu + additional comment
600 $comment .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
601 . $this->otherReason;
602 }
603 # Can the user set this field?
604 if ( $bitParams[RevisionRecord::DELETED_RESTRICTED] == 1
605 && !$this->getUser()->isAllowed( 'suppressrevision' )
606 ) {
607 throw new PermissionsError( 'suppressrevision' );
608 }
609 # If the save went through, go to success message...
610 $status = $this->save( $bitParams, $comment );
611 if ( $status->isGood() ) {
612 $this->success();
613
614 return true;
615 } else {
616 # ...otherwise, bounce back to form...
617 $this->failure( $status );
618 }
619
620 return false;
621 }
622
623 /**
624 * Report that the submit operation succeeded
625 */
626 protected function success() {
627 // Messages: revdelete-success, logdelete-success
628 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
629 $this->getOutput()->wrapWikiMsg(
630 "<div class=\"successbox\">\n$1\n</div>",
631 $this->typeLabels['success']
632 );
633 $this->wasSaved = true;
634 $this->revDelList->reloadFromMaster();
635 $this->showForm();
636 }
637
638 /**
639 * Report that the submit operation failed
640 * @param Status $status
641 */
642 protected function failure( $status ) {
643 // Messages: revdelete-failure, logdelete-failure
644 $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
645 $this->getOutput()->wrapWikiTextAsInterface(
646 'errorbox',
647 $status->getWikiText( $this->typeLabels['failure'] )
648 );
649 $this->showForm();
650 }
651
652 /**
653 * Put together an array that contains -1, 0, or the *_deleted const for each bit
654 *
655 * @return array
656 */
657 protected function extractBitParams() {
658 $bitfield = [];
659 foreach ( $this->checks as $item ) {
660 list( /* message */, $name, $field ) = $item;
661 $val = $this->getRequest()->getInt( $name, 0 /* unchecked */ );
662 if ( $val < -1 || $val > 1 ) {
663 $val = -1; // -1 for existing value
664 }
665 $bitfield[$field] = $val;
666 }
667 if ( !isset( $bitfield[RevisionRecord::DELETED_RESTRICTED] ) ) {
668 $bitfield[RevisionRecord::DELETED_RESTRICTED] = 0;
669 }
670
671 return $bitfield;
672 }
673
674 /**
675 * Do the write operations. Simple wrapper for RevDel*List::setVisibility().
676 * @param array $bitPars ExtractBitParams() bitfield array
677 * @param string $reason
678 * @return Status
679 */
680 protected function save( array $bitPars, $reason ) {
681 return $this->getList()->setVisibility(
682 [ 'value' => $bitPars, 'comment' => $reason ]
683 );
684 }
685
686 protected function getGroupName() {
687 return 'pagetools';
688 }
689 }