3 * List for revision table items
5 * This will check both the 'revision' table for live revisions and the
6 * 'archive' table for traditionally-deleted revisions that have an
9 * See RevDel_RevisionItem and RevDel_ArchivedRevisionItem for items.
11 class RevDel_RevisionList
extends RevDel_List
{
13 var $type = 'revision';
14 var $idField = 'rev_id';
15 var $dateField = 'rev_timestamp';
16 var $authorIdField = 'rev_user';
17 var $authorNameField = 'rev_user_text';
20 * @param $db DatabaseBase
23 public function doQuery( $db ) {
24 $ids = array_map( 'intval', $this->ids
);
25 $live = $db->select( array('revision','page'), '*',
27 'rev_page' => $this->title
->getArticleID(),
32 array( 'ORDER BY' => 'rev_id DESC' )
35 if ( $live->numRows() >= count( $ids ) ) {
36 // All requested revisions are live, keeps things simple!
40 // Check if any requested revisions are available fully deleted.
41 $archived = $db->select( array( 'archive' ), '*',
46 array( 'ORDER BY' => 'ar_rev_id DESC' )
49 if ( $archived->numRows() == 0 ) {
51 } else if ( $live->numRows() == 0 ) {
54 // Combine the two! Whee
56 while ( $row = $live->fetchObject() ) {
57 $rows[$row->rev_id
] = $row;
59 while ( $row = $archived->fetchObject() ) {
60 $rows[$row->ar_rev_id
] = $row;
63 return new FakeResultWrapper( array_values( $rows ) );
67 public function newItem( $row ) {
68 if ( isset( $row->rev_id
) ) {
69 return new RevDel_RevisionItem( $this, $row );
70 } elseif ( isset( $row->ar_rev_id
) ) {
71 return new RevDel_ArchivedRevisionItem( $this, $row );
73 // This shouldn't happen. :)
75 throw new MWException( 'Invalid row type in RevDel_RevisionList' );
79 public function getCurrent() {
80 if ( is_null( $this->currentRevId
) ) {
81 $dbw = wfGetDB( DB_MASTER
);
82 $this->currentRevId
= $dbw->selectField(
83 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
85 return $this->currentRevId
;
88 public function getSuppressBit() {
89 return Revision
::DELETED_RESTRICTED
;
92 public function doPreCommitUpdates() {
93 $this->title
->invalidateCache();
94 return Status
::newGood();
97 public function doPostCommitUpdates() {
98 $this->title
->purgeSquid();
99 // Extensions that require referencing previous revisions may need this
100 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
101 return Status
::newGood();
106 * Item class for a live revision table row
108 class RevDel_RevisionItem
extends RevDel_Item
{
111 public function __construct( $list, $row ) {
112 parent
::__construct( $list, $row );
113 $this->revision
= new Revision( $row );
116 public function canView() {
117 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
120 public function canViewContent() {
121 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
124 public function getBits() {
125 return $this->revision
->mDeleted
;
128 public function setBits( $bits ) {
129 $dbw = wfGetDB( DB_MASTER
);
130 // Update revision table
131 $dbw->update( 'revision',
132 array( 'rev_deleted' => $bits ),
134 'rev_id' => $this->revision
->getId(),
135 'rev_page' => $this->revision
->getPage(),
136 'rev_deleted' => $this->getBits()
140 if ( !$dbw->affectedRows() ) {
144 // Update recentchanges table
145 $dbw->update( 'recentchanges',
147 'rc_deleted' => $bits,
151 'rc_this_oldid' => $this->revision
->getId(), // condition
152 // non-unique timestamp index
153 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
160 public function isDeleted() {
161 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
164 public function isHideCurrentOp( $newBits ) {
165 return ( $newBits & Revision
::DELETED_TEXT
)
166 && $this->list->getCurrent() == $this->getId();
170 * Get the HTML link to the revision text.
171 * Overridden by RevDel_ArchiveItem.
173 protected function getRevisionLink() {
175 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
176 if ( $this->isDeleted() && !$this->canViewContent() ) {
179 return $this->special
->skin
->link(
184 'oldid' => $this->revision
->getId(),
191 * Get the HTML link to the diff.
192 * Overridden by RevDel_ArchiveItem
194 protected function getDiffLink() {
195 if ( $this->isDeleted() && !$this->canViewContent() ) {
196 return wfMsgHtml('diff');
199 $this->special
->skin
->link(
204 'diff' => $this->revision
->getId(),
216 public function getHTML() {
217 $difflink = $this->getDiffLink();
218 $revlink = $this->getRevisionLink();
219 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
220 $comment = $this->special
->skin
->revComment( $this->revision
);
221 if ( $this->isDeleted() ) {
222 $revlink = "<span class=\"history-deleted\">$revlink</span>";
224 return "<li>($difflink) $revlink $userlink $comment</li>";
229 * List for archive table items, i.e. revisions deleted via action=delete
231 class RevDel_ArchiveList
extends RevDel_RevisionList
{
232 var $type = 'archive';
233 var $idField = 'ar_timestamp';
234 var $dateField = 'ar_timestamp';
235 var $authorIdField = 'ar_user';
236 var $authorNameField = 'ar_user_text';
239 * @param $db DatabaseBase
242 public function doQuery( $db ) {
243 $timestamps = array();
244 foreach ( $this->ids
as $id ) {
245 $timestamps[] = $db->timestamp( $id );
247 return $db->select( 'archive', '*',
249 'ar_namespace' => $this->title
->getNamespace(),
250 'ar_title' => $this->title
->getDBkey(),
251 'ar_timestamp' => $timestamps
254 array( 'ORDER BY' => 'ar_timestamp DESC' )
258 public function newItem( $row ) {
259 return new RevDel_ArchiveItem( $this, $row );
262 public function doPreCommitUpdates() {
263 return Status
::newGood();
266 public function doPostCommitUpdates() {
267 return Status
::newGood();
272 * Item class for a archive table row
274 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
275 public function __construct( $list, $row ) {
276 RevDel_Item
::__construct( $list, $row );
277 $this->revision
= Revision
::newFromArchiveRow( $row,
278 array( 'page' => $this->list->title
->getArticleId() ) );
281 public function getId() {
282 # Convert DB timestamp to MW timestamp
283 return $this->revision
->getTimestamp();
286 public function setBits( $bits ) {
287 $dbw = wfGetDB( DB_MASTER
);
288 $dbw->update( 'archive',
289 array( 'ar_deleted' => $bits ),
290 array( 'ar_namespace' => $this->list->title
->getNamespace(),
291 'ar_title' => $this->list->title
->getDBkey(),
292 // use timestamp for index
293 'ar_timestamp' => $this->row
->ar_timestamp
,
294 'ar_rev_id' => $this->row
->ar_rev_id
,
295 'ar_deleted' => $this->getBits()
298 return (bool)$dbw->affectedRows();
301 protected function getRevisionLink() {
303 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
304 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
305 if ( $this->isDeleted() && !$this->canViewContent() ) {
308 return $this->special
->skin
->link( $undelete, $date, array(),
310 'target' => $this->list->title
->getPrefixedText(),
311 'timestamp' => $this->revision
->getTimestamp()
315 protected function getDiffLink() {
316 if ( $this->isDeleted() && !$this->canViewContent() ) {
317 return wfMsgHtml( 'diff' );
319 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
320 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
322 'target' => $this->list->title
->getPrefixedText(),
324 'timestamp' => $this->revision
->getTimestamp()
331 * Item class for a archive table row by ar_rev_id -- actually
332 * used via RevDel_RevisionList.
334 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
335 public function __construct( $list, $row ) {
336 RevDel_Item
::__construct( $list, $row );
338 $this->revision
= Revision
::newFromArchiveRow( $row,
339 array( 'page' => $this->list->title
->getArticleId() ) );
342 public function getId() {
343 return $this->revision
->getId();
346 public function setBits( $bits ) {
347 $dbw = wfGetDB( DB_MASTER
);
348 $dbw->update( 'archive',
349 array( 'ar_deleted' => $bits ),
350 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
351 'ar_deleted' => $this->getBits()
354 return (bool)$dbw->affectedRows();
359 * List for oldimage table items
361 class RevDel_FileList
extends RevDel_List
{
362 var $type = 'oldimage';
363 var $idField = 'oi_archive_name';
364 var $dateField = 'oi_timestamp';
365 var $authorIdField = 'oi_user';
366 var $authorNameField = 'oi_user_text';
367 var $storeBatch, $deleteBatch, $cleanupBatch;
370 * @param $db DatabaseBase
373 public function doQuery( $db ) {
374 $archiveNames = array();
375 foreach( $this->ids
as $timestamp ) {
376 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
378 return $db->select( 'oldimage', '*',
380 'oi_name' => $this->title
->getDBkey(),
381 'oi_archive_name' => $archiveNames
384 array( 'ORDER BY' => 'oi_timestamp DESC' )
388 public function newItem( $row ) {
389 return new RevDel_FileItem( $this, $row );
392 public function clearFileOps() {
393 $this->deleteBatch
= array();
394 $this->storeBatch
= array();
395 $this->cleanupBatch
= array();
398 public function doPreCommitUpdates() {
399 $status = Status
::newGood();
400 $repo = RepoGroup
::singleton()->getLocalRepo();
401 if ( $this->storeBatch
) {
402 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
404 if ( !$status->isOK() ) {
407 if ( $this->deleteBatch
) {
408 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
410 if ( !$status->isOK() ) {
411 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
412 // modified (but destined for rollback) causes data loss
415 if ( $this->cleanupBatch
) {
416 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
421 public function doPostCommitUpdates() {
422 $file = wfLocalFile( $this->title
);
424 $file->purgeDescription();
425 return Status
::newGood();
428 public function getSuppressBit() {
429 return File
::DELETED_RESTRICTED
;
434 * Item class for an oldimage table row
436 class RevDel_FileItem
extends RevDel_Item
{
443 public function __construct( $list, $row ) {
444 parent
::__construct( $list, $row );
445 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
448 public function getId() {
449 $parts = explode( '!', $this->row
->oi_archive_name
);
453 public function canView() {
454 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
457 public function canViewContent() {
458 return $this->file
->userCan( File
::DELETED_FILE
);
461 public function getBits() {
462 return $this->file
->getVisibility();
465 public function setBits( $bits ) {
467 # @todo FIXME: Move to LocalFile.php
468 if ( $this->isDeleted() ) {
469 if ( $bits & File
::DELETED_FILE
) {
473 $key = $this->file
->getStorageKey();
474 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
475 $this->list->storeBatch
[] = array(
476 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
478 $this->file
->getRel()
480 $this->list->cleanupBatch
[] = $key;
482 } elseif ( $bits & File
::DELETED_FILE
) {
484 $key = $this->file
->getStorageKey();
485 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
486 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
489 # Do the database operations
490 $dbw = wfGetDB( DB_MASTER
);
491 $dbw->update( 'oldimage',
492 array( 'oi_deleted' => $bits ),
494 'oi_name' => $this->row
->oi_name
,
495 'oi_timestamp' => $this->row
->oi_timestamp
,
496 'oi_deleted' => $this->getBits()
500 return (bool)$dbw->affectedRows();
503 public function isDeleted() {
504 return $this->file
->isDeleted( File
::DELETED_FILE
);
508 * Get the link to the file.
509 * Overridden by RevDel_ArchivedFileItem.
511 protected function getLink() {
512 global $wgLang, $wgUser;
513 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
514 if ( $this->isDeleted() ) {
516 if ( !$this->canViewContent() ) {
519 $link = $this->special
->skin
->link(
520 $this->special
->getTitle(),
523 'target' => $this->list->title
->getPrefixedText(),
524 'file' => $this->file
->getArchiveName(),
525 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
529 return '<span class="history-deleted">' . $link . '</span>';
532 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
536 * Generate a user tool link cluster if the current user is allowed to view it
537 * @return string HTML
539 protected function getUserTools() {
540 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
541 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
542 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
544 $link = wfMsgHtml( 'rev-deleted-user' );
546 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
547 return '<span class="history-deleted">' . $link . '</span>';
553 * Wrap and format the file's comment block, if the current
554 * user is allowed to view it.
556 * @return string HTML
558 protected function getComment() {
559 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
560 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
562 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
564 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
565 return "<span class=\"history-deleted\">$block</span>";
570 public function getHTML() {
575 $wgLang->formatNum( $this->file
->getWidth() ),
576 $wgLang->formatNum( $this->file
->getHeight() )
579 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
582 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
583 $data . ' ' . $this->getComment(). '</li>';
588 * List for filearchive table items
590 class RevDel_ArchivedFileList
extends RevDel_FileList
{
591 var $type = 'filearchive';
592 var $idField = 'fa_id';
593 var $dateField = 'fa_timestamp';
594 var $authorIdField = 'fa_user';
595 var $authorNameField = 'fa_user_text';
598 * @param $db DatabaseBase
601 public function doQuery( $db ) {
602 $ids = array_map( 'intval', $this->ids
);
603 return $db->select( 'filearchive', '*',
605 'fa_name' => $this->title
->getDBkey(),
609 array( 'ORDER BY' => 'fa_id DESC' )
613 public function newItem( $row ) {
614 return new RevDel_ArchivedFileItem( $this, $row );
619 * Item class for a filearchive table row
621 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
622 public function __construct( $list, $row ) {
623 RevDel_Item
::__construct( $list, $row );
624 $this->file
= ArchivedFile
::newFromRow( $row );
627 public function getId() {
628 return $this->row
->fa_id
;
631 public function setBits( $bits ) {
632 $dbw = wfGetDB( DB_MASTER
);
633 $dbw->update( 'filearchive',
634 array( 'fa_deleted' => $bits ),
636 'fa_id' => $this->row
->fa_id
,
637 'fa_deleted' => $this->getBits(),
641 return (bool)$dbw->affectedRows();
644 protected function getLink() {
645 global $wgLang, $wgUser;
646 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
647 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
648 $key = $this->file
->getKey();
650 if( !$this->canViewContent() ) {
653 $link = $this->special
->skin
->link( $undelete, $date, array(),
655 'target' => $this->list->title
->getPrefixedText(),
657 'token' => $wgUser->editToken( $key )
661 if( $this->isDeleted() ) {
662 $link = '<span class="history-deleted">' . $link . '</span>';
669 * List for logging table items
671 class RevDel_LogList
extends RevDel_List
{
672 var $type = 'logging';
673 var $idField = 'log_id';
674 var $dateField = 'log_timestamp';
675 var $authorIdField = 'log_user';
676 var $authorNameField = 'log_user_text';
679 * @param $db DatabaseBase
682 public function doQuery( $db ) {
683 $ids = array_map( 'intval', $this->ids
);
684 return $db->select( 'logging', '*',
685 array( 'log_id' => $ids ),
687 array( 'ORDER BY' => 'log_id DESC' )
691 public function newItem( $row ) {
692 return new RevDel_LogItem( $this, $row );
695 public function getSuppressBit() {
696 return Revision
::DELETED_RESTRICTED
;
699 public function getLogAction() {
703 public function getLogParams( $params ) {
705 implode( ',', $params['ids'] ),
706 "ofield={$params['oldBits']}",
707 "nfield={$params['newBits']}"
713 * Item class for a logging table row
715 class RevDel_LogItem
extends RevDel_Item
{
716 public function canView() {
717 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
720 public function canViewContent() {
724 public function getBits() {
725 return $this->row
->log_deleted
;
728 public function setBits( $bits ) {
729 $dbw = wfGetDB( DB_MASTER
);
730 $dbw->update( 'recentchanges',
732 'rc_deleted' => $bits,
736 'rc_logid' => $this->row
->log_id
,
737 'rc_timestamp' => $this->row
->log_timestamp
// index
741 $dbw->update( 'logging',
742 array( 'log_deleted' => $bits ),
744 'log_id' => $this->row
->log_id
,
745 'log_deleted' => $this->getBits()
749 return (bool)$dbw->affectedRows();
752 public function getHTML() {
755 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
756 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
757 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
759 // Log link for this page
760 $loglink = $this->special
->skin
->link(
761 SpecialPage
::getTitleFor( 'Log' ),
764 array( 'page' => $title->getPrefixedText() )
767 if( !$this->canView() ) {
768 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
770 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
771 $this->special
->skin
, $paramArray, true, true );
772 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
773 $action = '<span class="history-deleted">' . $action . '</span>';
776 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
777 User
::WhoIs( $this->row
->log_user
) );
778 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
779 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
782 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
783 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
784 $comment = '<span class="history-deleted">' . $comment . '</span>';
786 return "<li>($loglink) $date $userLink $action $comment</li>";