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