f8697a2f32631c77d015f1ee8f6536e0102e829a
[lhc/web/wiklou.git] / includes / specials / SpecialRevisiondelete.php
1 <?php
2 /**
3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
5 *
6 * @file
7 * @ingroup SpecialPage
8 */
9
10 class SpecialRevisionDelete extends UnlistedSpecialPage {
11 /** Skin object */
12 var $skin;
13
14 /** True if the submit button was clicked, and the form was posted */
15 var $submitClicked;
16
17 /** Target ID list */
18 var $ids;
19
20 /** Archive name, for reviewing deleted files */
21 var $archiveName;
22
23 /** Edit token for securing image views against XSS */
24 var $token;
25
26 /** Title object for target parameter */
27 var $targetObj;
28
29 /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
30 var $typeName;
31
32 /** Array of checkbox specs (message, name, deletion bits) */
33 var $checks;
34
35 /** Information about the current type */
36 var $typeInfo;
37
38 /** The RevDel_List object, storing the list of items to be deleted/undeleted */
39 var $list;
40
41 /**
42 * Assorted information about each type, needed by the special page.
43 * TODO Move some of this to the list class
44 */
45 static $allowedTypes = array(
46 'revision' => array(
47 'check-label' => 'revdelete-hide-text',
48 'deletion-bits' => Revision::DELETED_TEXT,
49 'success' => 'revdelete-success',
50 'failure' => 'revdelete-failure',
51 'list-class' => 'RevDel_RevisionList',
52 ),
53 'archive' => array(
54 'check-label' => 'revdelete-hide-text',
55 'deletion-bits' => Revision::DELETED_TEXT,
56 'success' => 'revdelete-success',
57 'failure' => 'revdelete-failure',
58 'list-class' => 'RevDel_ArchiveList',
59 ),
60 'oldimage'=> array(
61 'check-label' => 'revdelete-hide-image',
62 'deletion-bits' => File::DELETED_FILE,
63 'success' => 'revdelete-success',
64 'failure' => 'revdelete-failure',
65 'list-class' => 'RevDel_FileList',
66 ),
67 'filearchive' => array(
68 'check-label' => 'revdelete-hide-image',
69 'deletion-bits' => File::DELETED_FILE,
70 'success' => 'revdelete-success',
71 'failure' => 'revdelete-failure',
72 'list-class' => 'RevDel_ArchivedFileList',
73 ),
74 'logging' => array(
75 'check-label' => 'revdelete-hide-name',
76 'deletion-bits' => LogPage::DELETED_ACTION,
77 'success' => 'logdelete-success',
78 'failure' => 'logdelete-failure',
79 'list-class' => 'RevDel_LogList',
80 ),
81 );
82
83 /** Type map to support old log entries */
84 static $deprecatedTypeMap = array(
85 'oldid' => 'revision',
86 'artimestamp' => 'archive',
87 'oldimage' => 'oldimage',
88 'fileid' => 'filearchive',
89 'logid' => 'logging',
90 );
91
92 public function __construct() {
93 parent::__construct( 'Revisiondelete', 'deleterevision' );
94 }
95
96 public function execute( $par ) {
97 global $wgOut, $wgUser, $wgRequest;
98 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
99 $wgOut->permissionRequired( 'deleterevision' );
100 return;
101 } else if( wfReadOnly() ) {
102 $wgOut->readOnlyPage();
103 return;
104 }
105 $this->skin = $wgUser->getSkin();
106 $this->setHeaders();
107 $this->outputHeader();
108 $this->submitClicked = $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
109 # Handle our many different possible input types.
110 # Use CSV, since the cgi handling will break on arrays.
111 $this->ids = explode( ',', $wgRequest->getVal('ids') );
112 $this->ids = array_unique( array_filter( $this->ids ) );
113 $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
114
115 # For reviewing deleted files...
116 $this->archiveName = $wgRequest->getVal( 'file' );
117 $this->token = $wgRequest->getVal( 'token' );
118 if ( $this->archiveName && $this->targetObj ) {
119 $this->tryShowFile( $this->archiveName );
120 return;
121 }
122
123 $this->typeName = $wgRequest->getVal( 'type' );
124 if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) {
125 $this->typeName = self::$deprecatedTypeMap[$this->typeName];
126 }
127
128 # No targets?
129 if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) {
130 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
131 return;
132 }
133 $this->typeInfo = self::$allowedTypes[$this->typeName];
134
135 # If we have revisions, get the title from the first one
136 # since they should all be from the same page. This allows
137 # for more flexibility with page moves...
138 if( $this->typeName == 'revision' ) {
139 $rev = Revision::newFromId( $this->ids[0] );
140 $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj;
141 }
142 # We need a target page!
143 if( is_null($this->targetObj) ) {
144 $wgOut->addWikiMsg( 'undelete-header' );
145 return;
146 }
147 # Give a link to the logs/hist for this page
148 $this->showConvenienceLinks();
149
150 # Initialise checkboxes
151 $this->checks = array(
152 array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ),
153 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
154 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
155 );
156 if( $wgUser->isAllowed('suppressrevision') ) {
157 $this->checks[] = array( 'revdelete-hide-restricted',
158 'wpHideRestricted', Revision::DELETED_RESTRICTED );
159 }
160
161 # Either submit or create our form
162 if( $this->submitClicked ) {
163 $this->submit( $wgRequest );
164 } else {
165 $this->showForm();
166 }
167 $qc = $this->getLogQueryCond();
168 # Show relevant lines from the deletion log
169 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
170 LogEventsList::showLogExtract( $wgOut, 'delete',
171 $this->targetObj->getPrefixedText(), '', 25, $qc );
172 # Show relevant lines from the suppression log
173 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
174 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
175 LogEventsList::showLogExtract( $wgOut, 'suppress',
176 $this->targetObj->getPrefixedText(), '', 25, $qc );
177 }
178 }
179
180 /**
181 * Show some useful links in the subtitle
182 */
183 protected function showConvenienceLinks() {
184 global $wgOut, $wgUser;
185 # Give a link to the logs/hist for this page
186 if( $this->targetObj ) {
187 $links = array();
188 $logtitle = SpecialPage::getTitleFor( 'Log' );
189 $links[] = $this->skin->linkKnown(
190 $logtitle,
191 wfMsgHtml( 'viewpagelogs' ),
192 array(),
193 array( 'page' => $this->targetObj->getPrefixedUrl() )
194 );
195 # Give a link to the page history
196 $links[] = $this->skin->linkKnown(
197 $this->targetObj,
198 wfMsgHtml( 'pagehist' ),
199 array(),
200 array( 'action' => 'history' )
201 );
202 # Link to deleted edits
203 if( $wgUser->isAllowed('undelete') ) {
204 $undelete = SpecialPage::getTitleFor( 'Undelete' );
205 $links[] = $this->skin->linkKnown(
206 $undelete,
207 wfMsgHtml( 'deletedhist' ),
208 array(),
209 array( 'target' => $this->targetObj->getPrefixedDBkey() )
210 );
211 }
212 # Logs themselves don't have histories or archived revisions
213 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
214 }
215 }
216
217 /**
218 * Get the condition used for fetching log snippets
219 */
220 protected function getLogQueryCond() {
221 $conds = array();
222 // Revision delete logs for these item
223 $conds['log_type'] = array('delete','suppress');
224 $conds['log_action'] = $this->getList()->getLogAction();
225 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
226 $conds['ls_value'] = $this->ids;
227 return $conds;
228 }
229
230 /**
231 * Show a deleted file version requested by the visitor.
232 * TODO Mostly copied from Special:Undelete. Refactor.
233 */
234 protected function tryShowFile( $archiveName ) {
235 global $wgOut, $wgRequest, $wgUser, $wgLang;
236
237 $repo = RepoGroup::singleton()->getLocalRepo();
238 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName );
239 $oimage->load();
240 // Check if user is allowed to see this file
241 if ( !$oimage->exists() ) {
242 $wgOut->addWikiMsg( 'revdelete-no-file' );
243 return;
244 }
245 if( !$oimage->userCan(File::DELETED_FILE) ) {
246 $wgOut->permissionRequired( 'suppressrevision' );
247 return;
248 }
249 if ( !$wgUser->matchEditToken( $this->token, $archiveName ) ) {
250 $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
251 $this->targetObj->getText(),
252 $wgLang->date( $oimage->getTimestamp() ),
253 $wgLang->time( $oimage->getTimestamp() ) );
254 $wgOut->addHTML(
255 Xml::openElement( 'form', array(
256 'method' => 'POST',
257 'action' => $this->getTitle()->getLocalUrl(
258 'target=' . urlencode( $oimage->getName() ) .
259 '&file=' . urlencode( $archiveName ) .
260 '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
261 )
262 ) .
263 Xml::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
264 '</form>'
265 );
266 return;
267 }
268 $wgOut->disable();
269 # We mustn't allow the output to be Squid cached, otherwise
270 # if an admin previews a deleted image, and it's cached, then
271 # a user without appropriate permissions can toddle off and
272 # nab the image, and Squid will serve it
273 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
274 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
275 $wgRequest->response()->header( 'Pragma: no-cache' );
276
277 # Stream the file to the client
278 global $IP;
279 require_once( "$IP/includes/StreamFile.php" );
280 $key = $oimage->getStorageKey();
281 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
282 wfStreamFile( $path );
283 }
284
285 /**
286 * Get the list object for this request
287 */
288 protected function getList() {
289 if ( is_null( $this->list ) ) {
290 $class = $this->typeInfo['list-class'];
291 $this->list = new $class( $this, $this->targetObj, $this->ids );
292 }
293 return $this->list;
294 }
295
296 /**
297 * Show a list of items that we will operate on, and show a form with checkboxes
298 * which will allow the user to choose new visibility settings.
299 */
300 protected function showForm() {
301 global $wgOut, $wgUser, $wgLang;
302 $UserAllowed = true;
303
304 if ( $this->typeName == 'logging' ) {
305 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids) ) );
306 } else {
307 $wgOut->addWikiMsg( 'revdelete-selected',
308 $this->targetObj->getPrefixedText(), count( $this->ids ) );
309 }
310
311 $bitfields = 0;
312 $wgOut->addHTML( "<ul>" );
313
314 $where = $revObjs = array();
315
316 $numRevisions = 0;
317 // Live revisions...
318 $list = $this->getList();
319 for ( $list->reset(); $list->current(); $list->next() ) {
320 $item = $list->current();
321 if ( !$item->canView() ) {
322 if( !$this->submitClicked ) {
323 $wgOut->permissionRequired( 'suppressrevision' );
324 return;
325 }
326 $UserAllowed = false;
327 }
328 $numRevisions++;
329 $bitfields |= $item->getBits();
330 $wgOut->addHTML( $item->getHTML() );
331 }
332
333 if( !$numRevisions ) {
334 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
335 return;
336 }
337
338 $wgOut->addHTML( "</ul>" );
339 // Explanation text
340 $this->addUsageText();
341
342 // Normal sysops can always see what they did, but can't always change it
343 if( !$UserAllowed ) return;
344
345 $wgOut->addHTML(
346 Xml::openElement( 'form', array( 'method' => 'post',
347 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ),
348 'id' => 'mw-revdel-form-revisions' ) ) .
349 Xml::openElement( 'fieldset' ) .
350 Xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) ) .
351 $this->buildCheckBoxes( $bitfields ) .
352 '<p>' . Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ) . '</p>' .
353 '<p>' . Xml::submitButton( wfMsg( 'revdelete-submit' ),
354 array( 'name' => 'wpSubmit' ) ) . '</p>' .
355 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
356 Xml::hidden( 'target', $this->targetObj->getPrefixedText() ) .
357 Xml::hidden( 'type', $this->typeName ) .
358 Xml::hidden( 'ids', implode( ',', $this->ids ) ) .
359 Xml::closeElement( 'fieldset' ) .
360 Xml::closeElement( 'form' ) . "\n"
361 );
362 }
363
364 /**
365 * Show some introductory text
366 * FIXME Wikimedia-specific policy text
367 */
368 protected function addUsageText() {
369 global $wgOut, $wgUser;
370 $wgOut->addWikiMsg( 'revdelete-text' );
371 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
372 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
373 }
374 }
375
376 /**
377 * @param $bitfields Interger: aggregate bitfield of all the bitfields
378 * @return String: HTML
379 */
380 protected function buildCheckBoxes( $bitfields ) {
381 $html = '';
382 // FIXME: all items checked for just one rev are checked, even if not set for the others
383 foreach( $this->checks as $item ) {
384 list( $message, $name, $field ) = $item;
385 $line = Xml::tags( 'div', null, Xml::checkLabel( wfMsg($message), $name, $name,
386 $bitfields & $field ) );
387 if( $field == Revision::DELETED_RESTRICTED ) $line = "<b>$line</b>";
388 $html .= $line;
389 }
390 return $html;
391 }
392
393 /**
394 * UI entry point for form submission.
395 * @param $request WebRequest
396 */
397 protected function submit( $request ) {
398 global $wgUser, $wgOut;
399 # Check edit token on submission
400 if( $this->submitClicked && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
401 $wgOut->addWikiMsg( 'sessionfailure' );
402 return false;
403 }
404 $bitfield = $this->extractBitfield( $request );
405 $comment = $request->getText( 'wpReason' );
406 # Can the user set this field?
407 if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
408 $wgOut->permissionRequired( 'suppressrevision' );
409 return false;
410 }
411 # If the save went through, go to success message...
412 $status = $this->save( $bitfield, $comment, $this->targetObj );
413 if ( $status->isGood() ) {
414 $this->success();
415 return true;
416 # ...otherwise, bounce back to form...
417 } else {
418 $this->failure( $status );
419 }
420 return false;
421 }
422
423 /**
424 * Report that the submit operation succeeded
425 */
426 protected function success() {
427 global $wgOut;
428 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
429 $wgOut->wrapWikiMsg( '<span class="success">$1</span>', $this->typeInfo['success'] );
430 $this->list->reloadFromMaster();
431 $this->showForm();
432 }
433
434 /**
435 * Report that the submit operation failed
436 */
437 protected function failure( $status ) {
438 global $wgOut;
439 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
440 $wgOut->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) );
441 $this->showForm();
442 }
443
444 /**
445 * Put together a rev_deleted bitfield from the submitted checkboxes
446 * @param $request WebRequest
447 * @return Integer
448 */
449 protected function extractBitfield( $request ) {
450 $bitfield = 0;
451 foreach( $this->checks as $item ) {
452 list( /* message */ , $name, $field ) = $item;
453 if( $request->getCheck( $name ) ) {
454 $bitfield |= $field;
455 }
456 }
457 return $bitfield;
458 }
459
460 /**
461 * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
462 */
463 protected function save( $bitfield, $reason, $title ) {
464 // Don't allow simply locking the interface for no reason
465 if( $bitfield == Revision::DELETED_RESTRICTED ) {
466 return Status::newFatal( 'revdelete-only-restricted' );
467 }
468 return $this->getList()->setVisibility( array(
469 'value' => $bitfield,
470 'comment' => $reason ) );
471 }
472 }
473
474 /**
475 * Temporary b/c interface, collection of static functions.
476 * @ingroup SpecialPage
477 */
478 class RevisionDeleter {
479 /**
480 * Checks for a change in the bitfield for a certain option and updates the
481 * provided array accordingly.
482 *
483 * @param $desc String: description to add to the array if the option was
484 * enabled / disabled.
485 * @param $field Integer: the bitmask describing the single option.
486 * @param $diff Integer: the xor of the old and new bitfields.
487 * @param $new Integer: the new bitfield
488 * @param $arr Array: the array to update.
489 */
490 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
491 if( $diff & $field ) {
492 $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
493 }
494 }
495
496 /**
497 * Gets an array describing the changes made to the visibilit of the revision.
498 * If the resulting array is $arr, then $arr[0] will contain an array of strings
499 * describing the items that were hidden, $arr[2] will contain an array of strings
500 * describing the items that were unhidden, and $arr[3] will contain an array with
501 * a single string, which can be one of "applied restrictions to sysops",
502 * "removed restrictions from sysops", or null.
503 *
504 * @param $n Integer: the new bitfield.
505 * @param $o Integer: the old bitfield.
506 * @return An array as described above.
507 */
508 protected static function getChanges( $n, $o ) {
509 $diff = $n ^ $o;
510 $ret = array( 0 => array(), 1 => array(), 2 => array() );
511 // Build bitfield changes in language
512 self::checkItem( wfMsgForContent( 'revdelete-content' ),
513 Revision::DELETED_TEXT, $diff, $n, $ret );
514 self::checkItem( wfMsgForContent( 'revdelete-summary' ),
515 Revision::DELETED_COMMENT, $diff, $n, $ret );
516 self::checkItem( wfMsgForContent( 'revdelete-uname' ),
517 Revision::DELETED_USER, $diff, $n, $ret );
518 // Restriction application to sysops
519 if( $diff & Revision::DELETED_RESTRICTED ) {
520 if( $n & Revision::DELETED_RESTRICTED )
521 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
522 else
523 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
524 }
525 return $ret;
526 }
527
528 /**
529 * Gets a log message to describe the given revision visibility change. This
530 * message will be of the form "[hid {content, edit summary, username}];
531 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
532 *
533 * @param $count Integer: The number of effected revisions.
534 * @param $nbitfield Integer: The new bitfield for the revision.
535 * @param $obitfield Integer: The old bitfield for the revision.
536 * @param $isForLog Boolean
537 */
538 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
539 global $wgLang;
540 $s = '';
541 $changes = self::getChanges( $nbitfield, $obitfield );
542 if( count( $changes[0] ) ) {
543 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
544 }
545 if( count( $changes[1] ) ) {
546 if ($s) $s .= '; ';
547 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
548 }
549 if( count( $changes[2] ) ) {
550 $s .= $s ? ' (' . $changes[2][0] . ')' : $changes[2][0];
551 }
552 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
553 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
554
555 }
556
557 // Get DB field name for URL param...
558 // Future code for other things may also track
559 // other types of revision-specific changes.
560 public static function getRelationType( $typeName ) {
561 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
562 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
563 }
564 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
565 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
566 $list = new $class( null, null, null );
567 return $list->getIdField();
568 } else {
569 return null;
570 }
571 }
572 }
573
574 /**
575 * Abstract base class for a list of deletable items
576 */
577 abstract class RevDel_List {
578 var $special, $title, $ids, $res, $current;
579 var $type = null; // override this
580 var $idField = null; // override this
581 var $dateField = false; // override this
582
583 /**
584 * @param $special The parent SpecialPage
585 * @param $title The target title
586 * @param $ids Array of IDs
587 */
588 public function __construct( $special, $title, $ids ) {
589 $this->special = $special;
590 $this->title = $title;
591 $this->ids = $ids;
592 }
593
594 /**
595 * Get the internal type name of this list. Equal to the table name.
596 */
597 public function getType() {
598 return $this->type;
599 }
600
601 /**
602 * Get the DB field name associated with the ID list/
603 */
604 public function getIdField() {
605 return $this->idField;
606 }
607
608 /**
609 * Get the DB field name storing timestamps
610 */
611 public function getTimestampField() {
612 return $this->dateField;
613 }
614
615 /**
616 * Set the visibility for the revisions in this list. Logging and
617 * transactions are done here.
618 *
619 * @param $params Associative array of parameters. Members are:
620 * value: The integer value to set the visibility to
621 * comment: The log comment.
622 * @return Status
623 */
624 public function setVisibility( $params ) {
625 $newBits = $params['value'];
626 $comment = $params['comment'];
627
628 $this->res = false;
629 $dbw = wfGetDB( DB_MASTER );
630 $this->doQuery( $dbw );
631 $dbw->begin();
632 $status = Status::newGood();
633 $missing = array_flip( $this->ids );
634 $this->clearFileOps();
635 $idsForLog = array();
636
637 for ( $this->reset(); $this->current(); $this->next() ) {
638 $item = $this->current();
639 unset( $missing[ $item->getId() ] );
640
641 // Make error messages less vague
642 $oldBits = $item->getBits();
643 if ( $oldBits == $newBits ) {
644 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
645 $status->failCount++;
646 continue;
647 } elseif ( $oldBits == 0 && $newBits != 0 ) {
648 $opType = 'hide';
649 } elseif ( $oldBits != 0 && $newBits == 0 ) {
650 $opType = 'show';
651 } else {
652 $opType = 'modify';
653 }
654
655 if ( $item->isHideCurrentOp( $newBits ) ) {
656 // Cannot hide current version text
657 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
658 $status->failCount++;
659 continue;
660 }
661 if ( !$item->canView() ) {
662 // Cannot access this revision
663 $msg = $opType == 'show' ? 'revdelete-show-no-access' : 'revdelete-modify-no-access';
664 $status->error( $msg, $item->formatDate(), $item->formatTime() );
665 $status->failCount++;
666 continue;
667 }
668
669 // Update the revision
670 $ok = $item->setBits( $newBits );
671
672 if ( $ok ) {
673 $idsForLog[] = $item->getId();
674 $status->successCount++;
675 } else {
676 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
677 $status->failCount++;
678 }
679 }
680
681 // Handle missing revisions
682 foreach ( $missing as $id => $unused ) {
683 $status->error( 'revdelete-modify-missing', $id );
684 $status->failCount++;
685 }
686
687 if ( $status->successCount == 0 ) {
688 $status->ok = false;
689 $dbw->rollback();
690 return $status;
691 }
692
693 // Save success count
694 $successCount = $status->successCount;
695
696 // Move files, if there are any
697 $status->merge( $this->doPreCommitUpdates() );
698 if ( !$status->isOK() ) {
699 // Fatal error, such as no configured archive directory
700 $dbw->rollback();
701 return $status;
702 }
703
704 // Log it
705 $this->updateLog( array(
706 'title' => $this->title,
707 'count' => $successCount,
708 'newBits' => $newBits,
709 'oldBits' => $oldBits,
710 'comment' => $comment,
711 'ids' => $idsForLog,
712 ) );
713 $dbw->commit();
714
715 // Clear caches
716 $status->merge( $this->doPostCommitUpdates() );
717 return $status;
718 }
719
720 /**
721 * Reload the list data from the master DB. This can be done after setVisibility()
722 * to allow $item->getHTML() to show the new data.
723 */
724 function reloadFromMaster() {
725 $dbw = wfGetDB( DB_MASTER );
726 $this->res = $this->doQuery( $dbw );
727 }
728
729 /**
730 * Record a log entry on the action
731 * @param $params Associative array of parameters:
732 * newBits: The new value of the *_deleted bitfield
733 * oldBits: The old value of the *_deleted bitfield.
734 * title: The target title
735 * ids: The ID list
736 * comment: The log comment
737 */
738 protected function updateLog( $params ) {
739 // Get the URL param's corresponding DB field
740 $field = RevisionDeleter::getRelationType( $this->getType() );
741 if( !$field ) {
742 throw new MWException( "Bad log URL param type!" );
743 }
744 // Put things hidden from sysops in the oversight log
745 if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
746 $logType = 'suppress';
747 } else {
748 $logType = 'delete';
749 }
750 // Add params for effected page and ids
751 $logParams = $this->getLogParams( $params );
752 // Actually add the deletion log entry
753 $log = new LogPage( $logType );
754 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
755 $params['comment'], $logParams );
756 // Allow for easy searching of deletion log items for revision/log items
757 $log->addRelations( $field, $params['ids'], $logid );
758 }
759
760 /**
761 * Get the log action for this list type
762 */
763 public function getLogAction() {
764 return 'revision';
765 }
766
767 /**
768 * Get log parameter array.
769 * @param $params Associative array of log parameters, same as updateLog()
770 * @return array
771 */
772 public function getLogParams( $params ) {
773 return array(
774 $this->getType(),
775 implode( ',', $params['ids'] ),
776 "ofield={$params['oldBits']}",
777 "nfield={$params['newBits']}"
778 );
779 }
780
781 /**
782 * Initialise the current iteration pointer
783 */
784 protected function initCurrent() {
785 $row = $this->res->current();
786 if ( $row ) {
787 $this->current = $this->newItem( $row );
788 } else {
789 $this->current = false;
790 }
791 }
792
793 /**
794 * Start iteration. This must be called before current() or next().
795 * @return First list item
796 */
797 public function reset() {
798 if ( !$this->res ) {
799 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
800 } else {
801 $this->res->rewind();
802 }
803 $this->initCurrent();
804 return $this->current;
805 }
806
807 /**
808 * Get the current list item, or false if we are at the end
809 */
810 public function current() {
811 return $this->current;
812 }
813
814 /**
815 * Move the iteration pointer to the next list item, and return it.
816 */
817 public function next() {
818 $this->res->next();
819 $this->initCurrent();
820 return $this->current;
821 }
822
823 /**
824 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
825 * STUB
826 */
827 public function clearFileOps() {
828 }
829
830 /**
831 * A hook for setVisibility(): do batch updates pre-commit.
832 * STUB
833 * @return Status
834 */
835 public function doPreCommitUpdates() {
836 return Status::newGood();
837 }
838
839 /**
840 * A hook for setVisibility(): do any necessary updates post-commit.
841 * STUB
842 * @return Status
843 */
844 public function doPostCommitUpdates() {
845 return Status::newGood();
846 }
847
848 /**
849 * Create an item object from a DB result row
850 * @param $row stdclass
851 */
852 abstract public function newItem( $row );
853
854 /**
855 * Do the DB query to iterate through the objects.
856 * @param $db Database object to use for the query
857 */
858 abstract public function doQuery( $db );
859
860 /**
861 * Get the integer value of the flag used for suppression
862 */
863 abstract public function getSuppressBit();
864 }
865
866 /**
867 * Abstract base class for deletable items
868 */
869 abstract class RevDel_Item {
870 /** The parent SpecialPage */
871 var $special;
872
873 /** The parent RevDel_List */
874 var $list;
875
876 /** The DB result row */
877 var $row;
878
879 /**
880 * @param $list RevDel_List
881 * @param $row DB result row
882 */
883 public function __construct( $list, $row ) {
884 $this->special = $list->special;
885 $this->list = $list;
886 $this->row = $row;
887 }
888
889 /**
890 * Get the ID, as it would appear in the ids URL parameter
891 */
892 public function getId() {
893 $field = $this->list->getIdField();
894 return $this->row->$field;
895 }
896
897 /**
898 * Get the date, formatted with $wgLang
899 */
900 public function formatDate() {
901 global $wgLang;
902 return $wgLang->date( $this->getTimestamp() );
903 }
904
905 /**
906 * Get the time, formatted with $wgLang
907 */
908 public function formatTime() {
909 global $wgLang;
910 return $wgLang->time( $this->getTimestamp() );
911 }
912
913 /**
914 * Get the timestamp in MW 14-char form
915 */
916 public function getTimestamp() {
917 $field = $this->list->getTimestampField();
918 return wfTimestamp( TS_MW, $this->row->$field );
919 }
920
921 /**
922 * Returns true if the item is "current", and the operation to set the given
923 * bits can't be executed for that reason
924 * STUB
925 */
926 public function isHideCurrentOp( $newBits ) {
927 return false;
928 }
929
930 /**
931 * Returns true if the current user can view the item
932 */
933 abstract public function canView();
934
935 /**
936 * Get the current deletion bitfield value
937 */
938 abstract public function getBits();
939
940 /**
941 * Get the HTML of the list item. Should be include <li></li> tags.
942 * This is used to show the list in HTML form, by the special page.
943 */
944 abstract public function getHTML();
945
946 /**
947 * Set the visibility of the item. This should do any necessary DB queries.
948 *
949 * The DB update query should have a condition which forces it to only update
950 * if the value in the DB matches the value fetched earlier with the SELECT.
951 * If the update fails because it did not match, the function should return
952 * false. This prevents concurrency problems.
953 *
954 * @return boolean success
955 */
956 abstract public function setBits( $newBits );
957 }
958
959 /**
960 * List for revision table items
961 */
962 class RevDel_RevisionList extends RevDel_List {
963 var $currentRevId;
964 var $type = 'revision';
965 var $idField = 'rev_id';
966 var $dateField = 'rev_timestamp';
967
968 public function doQuery( $db ) {
969 $ids = array_map( 'intval', $this->ids );
970 return $db->select( array('revision','page'), '*',
971 array(
972 'rev_page' => $this->title->getArticleID(),
973 'rev_id' => $ids,
974 'rev_page = page_id'
975 ),
976 __METHOD__
977 );
978 }
979
980 public function newItem( $row ) {
981 return new RevDel_RevisionItem( $this, $row );
982 }
983
984 public function getCurrent() {
985 if ( is_null( $this->currentRevId ) ) {
986 $dbw = wfGetDB( DB_MASTER );
987 $this->currentRevId = $dbw->selectField(
988 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
989 }
990 return $this->currentRevId;
991 }
992
993 public function getSuppressBit() {
994 return Revision::DELETED_RESTRICTED;
995 }
996
997 public function doPreCommitUpdates() {
998 $this->title->invalidateCache();
999 return Status::newGood();
1000 }
1001
1002 public function doPostCommitUpdates() {
1003 $this->title->purgeSquid();
1004 // Extensions that require referencing previous revisions may need this
1005 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title ) );
1006 return Status::newGood();
1007 }
1008 }
1009
1010 /**
1011 * Item class for a revision table row
1012 */
1013 class RevDel_RevisionItem extends RevDel_Item {
1014 var $revision;
1015
1016 public function __construct( $list, $row ) {
1017 parent::__construct( $list, $row );
1018 $this->revision = new Revision( $row );
1019 }
1020
1021 public function canView() {
1022 return $this->revision->userCan( Revision::DELETED_RESTRICTED );
1023 }
1024
1025 public function getBits() {
1026 return $this->revision->mDeleted;
1027 }
1028
1029 public function setBits( $bits ) {
1030 $dbw = wfGetDB( DB_MASTER );
1031 // Update revision table
1032 $dbw->update( 'revision',
1033 array( 'rev_deleted' => $bits ),
1034 array(
1035 'rev_id' => $this->revision->getId(),
1036 'rev_page' => $this->revision->getPage(),
1037 'rev_deleted' => $this->getBits()
1038 ),
1039 __METHOD__
1040 );
1041 if ( !$dbw->affectedRows() ) {
1042 // Concurrent fail!
1043 return false;
1044 }
1045 // Update recentchanges table
1046 $dbw->update( 'recentchanges',
1047 array(
1048 'rc_deleted' => $bits,
1049 'rc_patrolled' => 1
1050 ),
1051 array(
1052 'rc_this_oldid' => $this->revision->getId(), // condition
1053 // non-unique timestamp index
1054 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
1055 ),
1056 __METHOD__
1057 );
1058 return true;
1059 }
1060
1061 public function isDeleted() {
1062 return $this->revision->isDeleted( Revision::DELETED_TEXT );
1063 }
1064
1065 public function isHideCurrentOp( $newBits ) {
1066 return ( $newBits & Revision::DELETED_TEXT )
1067 && $this->list->getCurrent() == $this->getId();
1068 }
1069
1070 /**
1071 * Get the HTML link to the revision text.
1072 * Overridden by RevDel_ArchiveItem.
1073 */
1074 protected function getRevisionLink() {
1075 global $wgLang;
1076 $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
1077 if ( $this->isDeleted() && !$this->canView() ) {
1078 return $date;
1079 }
1080 return $this->special->skin->link(
1081 $this->list->title,
1082 $date,
1083 array(),
1084 array(
1085 'oldid' => $this->revision->getId(),
1086 'unhide' => 1
1087 )
1088 );
1089 }
1090
1091 /**
1092 * Get the HTML link to the diff.
1093 * Overridden by RevDel_ArchiveItem
1094 */
1095 protected function getDiffLink() {
1096 if ( $this->isDeleted() && !$this->canView() ) {
1097 return wfMsgHtml('diff');
1098 } else {
1099 return
1100 $this->special->skin->link(
1101 $this->list->title,
1102 wfMsgHtml('diff'),
1103 array(),
1104 array(
1105 'diff' => $this->revision->getId(),
1106 'oldid' => 'prev',
1107 'unhide' => 1
1108 ),
1109 array(
1110 'known',
1111 'noclasses'
1112 )
1113 );
1114 }
1115 }
1116
1117 public function getHTML() {
1118 $difflink = $this->getDiffLink();
1119 $revlink = $this->getRevisionLink();
1120 $userlink = $this->special->skin->revUserLink( $this->revision );
1121 $comment = $this->special->skin->revComment( $this->revision );
1122 if ( $this->isDeleted() ) {
1123 $revlink = "<span class=\"history-deleted\">$revlink</span>";
1124 }
1125 return "<li>($difflink) $revlink $userlink $comment</li>";
1126 }
1127 }
1128
1129 /**
1130 * List for archive table items, i.e. revisions deleted via action=delete
1131 */
1132 class RevDel_ArchiveList extends RevDel_RevisionList {
1133 var $type = 'archive';
1134 var $idField = 'ar_timestamp';
1135 var $dateField = 'ar_timestamp';
1136
1137 public function doQuery( $db ) {
1138 $timestamps = array();
1139 foreach ( $this->ids as $id ) {
1140 $timestamps[] = $db->timestamp( $id );
1141 }
1142 return $db->select( 'archive', '*',
1143 array(
1144 'ar_namespace' => $this->title->getNamespace(),
1145 'ar_title' => $this->title->getDBkey(),
1146 'ar_timestamp' => $timestamps
1147 ),
1148 __METHOD__
1149 );
1150 }
1151
1152 public function newItem( $row ) {
1153 return new RevDel_ArchiveItem( $this, $row );
1154 }
1155
1156 public function doPreCommitUpdates() {
1157 return Status::newGood();
1158 }
1159
1160 public function doPostCommitUpdates() {
1161 return Status::newGood();
1162 }
1163 }
1164
1165 /**
1166 * Item class for a archive table row
1167 */
1168 class RevDel_ArchiveItem extends RevDel_RevisionItem {
1169 public function __construct( $list, $row ) {
1170 RevDel_Item::__construct( $list, $row );
1171 $this->revision = Revision::newFromArchiveRow( $row,
1172 array( 'page' => $this->list->title->getArticleId() ) );
1173 }
1174
1175 public function getId() {
1176 # Convert DB timestamp to MW timestamp
1177 return $this->revision->getTimestamp();
1178 }
1179
1180 public function setBits( $bits ) {
1181 $dbw = wfGetDB( DB_MASTER );
1182 $dbw->update( 'archive',
1183 array( 'ar_deleted' => $bits ),
1184 array( 'ar_namespace' => $this->list->title->getNamespace(),
1185 'ar_title' => $this->list->title->getDBkey(),
1186 // use timestamp for index
1187 'ar_timestamp' => $this->row->ar_timestamp,
1188 'ar_rev_id' => $this->row->ar_rev_id,
1189 'ar_deleted' => $this->getBits()
1190 ),
1191 __METHOD__ );
1192 return (bool)$dbw->affectedRows();
1193 }
1194
1195 protected function getRevisionLink() {
1196 global $wgLang;
1197 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1198 $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
1199 if ( $this->isDeleted() && !$this->canView() ) {
1200 return $date;
1201 }
1202 return $this->special->skin->link( $undelete, $date, array(),
1203 array(
1204 'target' => $this->list->title->getPrefixedText(),
1205 'timestamp' => $this->revision->getTimestamp()
1206 ) );
1207 }
1208
1209 protected function getDiffLink() {
1210 if ( $this->isDeleted() && !$this->canView() ) {
1211 return wfMsgHtml( 'diff' );
1212 }
1213 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1214 return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
1215 array(
1216 'target' => $this->list->title->getPrefixedText(),
1217 'diff' => 'prev',
1218 'timestamp' => $this->revision->getTimestamp()
1219 ) );
1220 }
1221 }
1222
1223 /**
1224 * List for oldimage table items
1225 */
1226 class RevDel_FileList extends RevDel_List {
1227 var $type = 'oldimage';
1228 var $idField = 'oi_archive_name';
1229 var $dateField = 'oi_timestamp';
1230 var $storeBatch, $deleteBatch, $cleanupBatch;
1231
1232 public function doQuery( $db ) {
1233 $archiveName = array();
1234 foreach( $this->ids as $timestamp ) {
1235 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
1236 }
1237 return $db->select( 'oldimage', '*',
1238 array(
1239 'oi_name' => $this->title->getDBkey(),
1240 'oi_archive_name' => $archiveNames
1241 ),
1242 __METHOD__
1243 );
1244 }
1245
1246 public function newItem( $row ) {
1247 return new RevDel_FileItem( $this, $row );
1248 }
1249
1250 public function clearFileOps() {
1251 $this->deleteBatch = array();
1252 $this->storeBatch = array();
1253 $this->cleanupBatch = array();
1254 }
1255
1256 public function doPreCommitUpdates() {
1257 $status = Status::newGood();
1258 $repo = RepoGroup::singleton()->getLocalRepo();
1259 if ( $this->storeBatch ) {
1260 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
1261 }
1262 if ( !$status->isOK() ) {
1263 return $status;
1264 }
1265 if ( $this->deleteBatch ) {
1266 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
1267 }
1268 if ( !$status->isOK() ) {
1269 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1270 // modified (but destined for rollback) causes data loss
1271 return $status;
1272 }
1273 if ( $this->cleanupBatch ) {
1274 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
1275 }
1276 return $status;
1277 }
1278
1279 public function doPostCommitUpdates() {
1280 $file = wfLocalFile( $this->title );
1281 $file->purgeCache();
1282 $file->purgeDescription();
1283 return Status::newGood();
1284 }
1285
1286 public function getSuppressBit() {
1287 return File::DELETED_RESTRICTED;
1288 }
1289 }
1290
1291 /**
1292 * Item class for an oldimage table row
1293 */
1294 class RevDel_FileItem extends RevDel_Item {
1295 var $file;
1296
1297 public function __construct( $list, $row ) {
1298 parent::__construct( $list, $row );
1299 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
1300 }
1301
1302 public function getId() {
1303 $parts = explode( '!', $this->row->oi_archive_name );
1304 return $parts[0];
1305 }
1306
1307 public function canView() {
1308 return $this->file->userCan( File::DELETED_RESTRICTED );
1309 }
1310
1311 public function getBits() {
1312 /** FIXME: use accessor */
1313 return $this->file->deleted;
1314 }
1315
1316 public function setBits( $bits ) {
1317 # Queue the file op
1318 # FIXME: move to LocalFile.php
1319 if ( $this->isDeleted() ) {
1320 if ( $bits & File::DELETED_FILE ) {
1321 # Still deleted
1322 } else {
1323 # Newly undeleted
1324 $key = $this->file->getStorageKey();
1325 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1326 $this->list->storeBatch[] = array(
1327 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1328 'public',
1329 $this->file->getRel()
1330 );
1331 $this->list->cleanupBatch[] = $key;
1332 }
1333 } elseif ( $bits & File::DELETED_FILE ) {
1334 # Newly deleted
1335 $key = $this->file->getStorageKey();
1336 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1337 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
1338 }
1339
1340 # Do the database operations
1341 $dbw = wfGetDB( DB_MASTER );
1342 $dbw->update( 'oldimage',
1343 array( 'oi_deleted' => $bits ),
1344 array(
1345 'oi_name' => $this->row->oi_name,
1346 'oi_timestamp' => $this->row->oi_timestamp,
1347 'oi_deleted' => $this->getBits()
1348 ),
1349 __METHOD__
1350 );
1351 return (bool)$dbw->affectedRows();
1352 }
1353
1354 public function isDeleted() {
1355 return $this->file->isDeleted( File::DELETED_FILE );
1356 }
1357
1358 /**
1359 * Get the link to the file.
1360 * Overridden by RevDel_ArchivedFileItem.
1361 */
1362 protected function getLink() {
1363 global $wgLang;
1364 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1365 if ( $this->isDeleted() ) {
1366 # Hidden files...
1367 if ( !$this->canView() ) {
1368 return $date;
1369 } else {
1370 return $this->special->skin->link(
1371 $this->special->getTitle(),
1372 $date, array(),
1373 array(
1374 'target' => $this->list->title->getPrefixedText(),
1375 'file' => $this->file->sha1 . '.' . $this->file->getExtension()
1376 )
1377 );
1378 }
1379 } else {
1380 # Regular files...
1381 $url = $this->file->getUrl();
1382 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
1383 }
1384 }
1385 /**
1386 * Generate a user tool link cluster if the current user is allowed to view it
1387 * @return string HTML
1388 */
1389 protected function getUserTools() {
1390 if( $this->file->userCan( Revision::DELETED_USER ) ) {
1391 $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
1392 $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
1393 } else {
1394 $link = wfMsgHtml( 'rev-deleted-user' );
1395 }
1396 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
1397 return '<span class="history-deleted">' . $link . '</span>';
1398 }
1399 return $link;
1400 }
1401
1402 /**
1403 * Wrap and format the file's comment block, if the current
1404 * user is allowed to view it.
1405 *
1406 * @return string HTML
1407 */
1408 protected function getComment() {
1409 if( $this->file->userCan( File::DELETED_COMMENT ) ) {
1410 $block = $this->special->skin->commentBlock( $this->file->description );
1411 } else {
1412 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1413 }
1414 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
1415 return "<span class=\"history-deleted\">$block</span>";
1416 }
1417 return $block;
1418 }
1419
1420 public function getHTML() {
1421 global $wgLang;
1422 $data =
1423 wfMsg(
1424 'widthheight',
1425 $wgLang->formatNum( $this->file->getWidth() ),
1426 $wgLang->formatNum( $this->file->getHeight() )
1427 ) .
1428 ' (' .
1429 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
1430 ')';
1431 $pageLink = $this->getLink();
1432
1433 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1434 $data . ' ' . $this->getComment(). '</li>';
1435 }
1436 }
1437
1438 /**
1439 * List for filearchive table items
1440 */
1441 class RevDel_ArchivedFileList extends RevDel_FileList {
1442 var $type = 'filearchive';
1443 var $idField = 'fa_id';
1444 var $dateField = 'fa_timestamp';
1445
1446 public function doQuery( $db ) {
1447 $ids = array_map( 'intval', $this->ids );
1448 return $db->select( 'filearchive', '*',
1449 array(
1450 'fa_name' => $this->title->getDBkey(),
1451 'fa_id' => $ids
1452 ),
1453 __METHOD__
1454 );
1455 }
1456
1457 public function newItem( $row ) {
1458 return new RevDel_ArchivedFileItem( $this, $row );
1459 }
1460 }
1461
1462 /**
1463 * Item class for a filearchive table row
1464 */
1465 class RevDel_ArchivedFileItem extends RevDel_FileItem {
1466 public function __construct( $list, $row ) {
1467 RevDel_Item::__construct( $list, $row );
1468 $this->file = ArchivedFile::newFromRow( $row );
1469 }
1470
1471 public function getId() {
1472 return $this->row->fa_id;
1473 }
1474
1475 public function setBits( $bits ) {
1476 $dbw = wfGetDB( DB_MASTER );
1477 $dbw->update( 'filearchive',
1478 array( 'fa_deleted' => $bits ),
1479 array(
1480 'fa_id' => $this->row->fa_id,
1481 'fa_deleted' => $this->getBits(),
1482 ),
1483 __METHOD__
1484 );
1485 return (bool)$dbw->affectedRows();
1486 }
1487
1488 protected function getLink() {
1489 global $wgLang, $wgUser;
1490 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1491 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1492 $key = $this->file->getKey();
1493 return $this->special->skin->link( $undelete, $date, array(),
1494 array(
1495 'target' => $this->list->title->getPrefixedText(),
1496 'file' => $key,
1497 'token' => $wgUser->editToken( $key )
1498 ) );
1499 }
1500 }
1501
1502 /**
1503 * List for logging table items
1504 */
1505 class RevDel_LogList extends RevDel_List {
1506 var $type = 'logging';
1507 var $idField = 'log_id';
1508 var $dateField = 'log_timestamp';
1509
1510 public function doQuery( $db ) {
1511 global $wgMessageCache;
1512 $wgMessageCache->loadAllMessages();
1513 $ids = array_map( 'intval', $this->ids );
1514 return $db->select( 'logging', '*',
1515 array( 'log_id' => $ids ),
1516 __METHOD__
1517 );
1518 }
1519
1520 public function newItem( $row ) {
1521 return new RevDel_LogItem( $this, $row );
1522 }
1523
1524 public function getSuppressBit() {
1525 return Revision::DELETED_RESTRICTED;
1526 }
1527
1528 public function getLogAction() {
1529 return 'event';
1530 }
1531
1532 public function getLogParams( $params ) {
1533 return array(
1534 implode( ',', $params['ids'] ),
1535 "ofield={$params['oldBits']}",
1536 "nfield={$params['newBits']}"
1537 );
1538 }
1539 }
1540
1541 /**
1542 * Item class for a logging table row
1543 */
1544 class RevDel_LogItem extends RevDel_Item {
1545 public function canView() {
1546 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
1547 }
1548
1549 public function getBits() {
1550 return $this->row->log_deleted;
1551 }
1552
1553 public function setBits( $bits ) {
1554 $dbw = wfGetDB( DB_MASTER );
1555 $dbw->update( 'recentchanges',
1556 array(
1557 'rc_deleted' => $bits,
1558 'rc_patrolled' => 1
1559 ),
1560 array(
1561 'rc_logid' => $this->row->log_id,
1562 'rc_timestamp' => $this->row->log_timestamp
1563 ),
1564 __METHOD__
1565 );
1566 $dbw->update( 'logging',
1567 array( 'log_deleted' => $bits ),
1568 array(
1569 'log_id' => $this->row->log_id,
1570 'log_deleted' => $this->getBits()
1571 ),
1572 __METHOD__
1573 );
1574 return (bool)$dbw->affectedRows();
1575 }
1576
1577 public function getHTML() {
1578 global $wgLang;
1579
1580 $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
1581 $paramArray = LogPage::extractParams( $this->row->log_params );
1582 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1583
1584 $logtitle = SpecialPage::getTitleFor( 'Log' );
1585 $loglink = $this->special->skin->link( $logtitle, wfMsgHtml( 'log' ), array(),
1586 array( 'page' => $title->getPrefixedUrl() ) );
1587 // Action text
1588 if( !$this->canView() ) {
1589 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1590 } else {
1591 $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
1592 $this->special->skin, $paramArray, true, true );
1593 if( $this->row->log_deleted & LogPage::DELETED_ACTION )
1594 $action = '<span class="history-deleted">' . $action . '</span>';
1595 }
1596 // User links
1597 $userLink = $this->special->skin->userLink(
1598 $this->row->log_user, User::WhoIs( $this->row->log_user ) );
1599 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
1600 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
1601 }
1602 // Comment
1603 $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
1604 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
1605 $comment = '<span class="history-deleted">' . $comment . '</span>';
1606 }
1607 return "<li>($loglink) $date $userLink $action $comment</li>";
1608 }
1609 }