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