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 } elseif ( $live->numRows() == 0 ) {
54 // Combine the two! Whee
56 foreach ( $live as $row ) {
57 $rows[$row->rev_id
] = $row;
59 foreach ( $archived as $row ) {
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. :)
74 throw new MWException( 'Invalid row type in RevDel_RevisionList' );
78 public function getCurrent() {
79 if ( is_null( $this->currentRevId
) ) {
80 $dbw = wfGetDB( DB_MASTER
);
81 $this->currentRevId
= $dbw->selectField(
82 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
84 return $this->currentRevId
;
87 public function getSuppressBit() {
88 return Revision
::DELETED_RESTRICTED
;
91 public function doPreCommitUpdates() {
92 $this->title
->invalidateCache();
93 return Status
::newGood();
96 public function doPostCommitUpdates() {
97 $this->title
->purgeSquid();
98 // Extensions that require referencing previous revisions may need this
99 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
100 return Status
::newGood();
105 * Item class for a live revision table row
107 class RevDel_RevisionItem
extends RevDel_Item
{
110 public function __construct( $list, $row ) {
111 parent
::__construct( $list, $row );
112 $this->revision
= new Revision( $row );
115 public function canView() {
116 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
119 public function canViewContent() {
120 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
123 public function getBits() {
124 return $this->revision
->mDeleted
;
127 public function setBits( $bits ) {
128 $dbw = wfGetDB( DB_MASTER
);
129 // Update revision table
130 $dbw->update( 'revision',
131 array( 'rev_deleted' => $bits ),
133 'rev_id' => $this->revision
->getId(),
134 'rev_page' => $this->revision
->getPage(),
135 'rev_deleted' => $this->getBits()
139 if ( !$dbw->affectedRows() ) {
143 // Update recentchanges table
144 $dbw->update( 'recentchanges',
146 'rc_deleted' => $bits,
150 'rc_this_oldid' => $this->revision
->getId(), // condition
151 // non-unique timestamp index
152 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
159 public function isDeleted() {
160 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
163 public function isHideCurrentOp( $newBits ) {
164 return ( $newBits & Revision
::DELETED_TEXT
)
165 && $this->list->getCurrent() == $this->getId();
169 * Get the HTML link to the revision text.
170 * Overridden by RevDel_ArchiveItem.
172 protected function getRevisionLink() {
173 $date = $this->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
174 if ( $this->isDeleted() && !$this->canViewContent() ) {
182 'oldid' => $this->revision
->getId(),
189 * Get the HTML link to the diff.
190 * Overridden by RevDel_ArchiveItem
192 protected function getDiffLink() {
193 if ( $this->isDeleted() && !$this->canViewContent() ) {
194 return wfMsgHtml('diff');
202 'diff' => $this->revision
->getId(),
214 public function getHTML() {
215 $difflink = $this->getDiffLink();
216 $revlink = $this->getRevisionLink();
217 $userlink = Linker
::revUserLink( $this->revision
);
218 $comment = Linker
::revComment( $this->revision
);
219 if ( $this->isDeleted() ) {
220 $revlink = "<span class=\"history-deleted\">$revlink</span>";
222 return "<li>($difflink) $revlink $userlink $comment</li>";
227 * List for archive table items, i.e. revisions deleted via action=delete
229 class RevDel_ArchiveList
extends RevDel_RevisionList
{
230 var $type = 'archive';
231 var $idField = 'ar_timestamp';
232 var $dateField = 'ar_timestamp';
233 var $authorIdField = 'ar_user';
234 var $authorNameField = 'ar_user_text';
237 * @param $db DatabaseBase
240 public function doQuery( $db ) {
241 $timestamps = array();
242 foreach ( $this->ids
as $id ) {
243 $timestamps[] = $db->timestamp( $id );
245 return $db->select( 'archive', '*',
247 'ar_namespace' => $this->title
->getNamespace(),
248 'ar_title' => $this->title
->getDBkey(),
249 'ar_timestamp' => $timestamps
252 array( 'ORDER BY' => 'ar_timestamp DESC' )
256 public function newItem( $row ) {
257 return new RevDel_ArchiveItem( $this, $row );
260 public function doPreCommitUpdates() {
261 return Status
::newGood();
264 public function doPostCommitUpdates() {
265 return Status
::newGood();
270 * Item class for a archive table row
272 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
273 public function __construct( $list, $row ) {
274 RevDel_Item
::__construct( $list, $row );
275 $this->revision
= Revision
::newFromArchiveRow( $row,
276 array( 'page' => $this->list->title
->getArticleId() ) );
279 public function getId() {
280 # Convert DB timestamp to MW timestamp
281 return $this->revision
->getTimestamp();
284 public function setBits( $bits ) {
285 $dbw = wfGetDB( DB_MASTER
);
286 $dbw->update( 'archive',
287 array( 'ar_deleted' => $bits ),
288 array( 'ar_namespace' => $this->list->title
->getNamespace(),
289 'ar_title' => $this->list->title
->getDBkey(),
290 // use timestamp for index
291 'ar_timestamp' => $this->row
->ar_timestamp
,
292 'ar_rev_id' => $this->row
->ar_rev_id
,
293 'ar_deleted' => $this->getBits()
296 return (bool)$dbw->affectedRows();
299 protected function getRevisionLink() {
300 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
301 $date = $this->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
302 if ( $this->isDeleted() && !$this->canViewContent() ) {
305 return Linker
::link( $undelete, $date, array(),
307 'target' => $this->list->title
->getPrefixedText(),
308 'timestamp' => $this->revision
->getTimestamp()
312 protected function getDiffLink() {
313 if ( $this->isDeleted() && !$this->canViewContent() ) {
314 return wfMsgHtml( 'diff' );
316 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
317 return Linker
::link( $undelete, wfMsgHtml('diff'), array(),
319 'target' => $this->list->title
->getPrefixedText(),
321 'timestamp' => $this->revision
->getTimestamp()
328 * Item class for a archive table row by ar_rev_id -- actually
329 * used via RevDel_RevisionList.
331 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
332 public function __construct( $list, $row ) {
333 RevDel_Item
::__construct( $list, $row );
335 $this->revision
= Revision
::newFromArchiveRow( $row,
336 array( 'page' => $this->list->title
->getArticleId() ) );
339 public function getId() {
340 return $this->revision
->getId();
343 public function setBits( $bits ) {
344 $dbw = wfGetDB( DB_MASTER
);
345 $dbw->update( 'archive',
346 array( 'ar_deleted' => $bits ),
347 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
348 'ar_deleted' => $this->getBits()
351 return (bool)$dbw->affectedRows();
356 * List for oldimage table items
358 class RevDel_FileList
extends RevDel_List
{
359 var $type = 'oldimage';
360 var $idField = 'oi_archive_name';
361 var $dateField = 'oi_timestamp';
362 var $authorIdField = 'oi_user';
363 var $authorNameField = 'oi_user_text';
364 var $storeBatch, $deleteBatch, $cleanupBatch;
367 * @param $db DatabaseBase
370 public function doQuery( $db ) {
371 $archiveNames = array();
372 foreach( $this->ids
as $timestamp ) {
373 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
375 return $db->select( 'oldimage', '*',
377 'oi_name' => $this->title
->getDBkey(),
378 'oi_archive_name' => $archiveNames
381 array( 'ORDER BY' => 'oi_timestamp DESC' )
385 public function newItem( $row ) {
386 return new RevDel_FileItem( $this, $row );
389 public function clearFileOps() {
390 $this->deleteBatch
= array();
391 $this->storeBatch
= array();
392 $this->cleanupBatch
= array();
395 public function doPreCommitUpdates() {
396 $status = Status
::newGood();
397 $repo = RepoGroup
::singleton()->getLocalRepo();
398 if ( $this->storeBatch
) {
399 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
401 if ( !$status->isOK() ) {
404 if ( $this->deleteBatch
) {
405 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
407 if ( !$status->isOK() ) {
408 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
409 // modified (but destined for rollback) causes data loss
412 if ( $this->cleanupBatch
) {
413 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
418 public function doPostCommitUpdates() {
419 $file = wfLocalFile( $this->title
);
421 $file->purgeDescription();
422 return Status
::newGood();
425 public function getSuppressBit() {
426 return File
::DELETED_RESTRICTED
;
431 * Item class for an oldimage table row
433 class RevDel_FileItem
extends RevDel_Item
{
440 public function __construct( $list, $row ) {
441 parent
::__construct( $list, $row );
442 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
445 public function getId() {
446 $parts = explode( '!', $this->row
->oi_archive_name
);
450 public function canView() {
451 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
454 public function canViewContent() {
455 return $this->file
->userCan( File
::DELETED_FILE
);
458 public function getBits() {
459 return $this->file
->getVisibility();
462 public function setBits( $bits ) {
464 # @todo FIXME: Move to LocalFile.php
465 if ( $this->isDeleted() ) {
466 if ( $bits & File
::DELETED_FILE
) {
470 $key = $this->file
->getStorageKey();
471 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
472 $this->list->storeBatch
[] = array(
473 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
475 $this->file
->getRel()
477 $this->list->cleanupBatch
[] = $key;
479 } elseif ( $bits & File
::DELETED_FILE
) {
481 $key = $this->file
->getStorageKey();
482 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
483 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
486 # Do the database operations
487 $dbw = wfGetDB( DB_MASTER
);
488 $dbw->update( 'oldimage',
489 array( 'oi_deleted' => $bits ),
491 'oi_name' => $this->row
->oi_name
,
492 'oi_timestamp' => $this->row
->oi_timestamp
,
493 'oi_deleted' => $this->getBits()
497 return (bool)$dbw->affectedRows();
500 public function isDeleted() {
501 return $this->file
->isDeleted( File
::DELETED_FILE
);
505 * Get the link to the file.
506 * Overridden by RevDel_ArchivedFileItem.
508 protected function getLink() {
509 $date = $this->getLang()->timeanddate( $this->file
->getTimestamp(), true );
510 if ( $this->isDeleted() ) {
512 if ( !$this->canViewContent() ) {
515 $link = Linker
::link(
516 $this->special
->getTitle(),
519 'target' => $this->list->title
->getPrefixedText(),
520 'file' => $this->file
->getArchiveName(),
521 'token' => $this->getUser()->editToken( $this->file
->getArchiveName() )
525 return '<span class="history-deleted">' . $link . '</span>';
528 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
532 * Generate a user tool link cluster if the current user is allowed to view it
533 * @return string HTML
535 protected function getUserTools() {
536 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
537 $link = Linker
::userLink( $this->file
->user
, $this->file
->user_text
) .
538 Linker
::userToolLinks( $this->file
->user
, $this->file
->user_text
);
540 $link = wfMsgHtml( 'rev-deleted-user' );
542 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
543 return '<span class="history-deleted">' . $link . '</span>';
549 * Wrap and format the file's comment block, if the current
550 * user is allowed to view it.
552 * @return string HTML
554 protected function getComment() {
555 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
556 $block = Linker
::commentBlock( $this->file
->description
);
558 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
560 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
561 return "<span class=\"history-deleted\">$block</span>";
566 public function getHTML() {
570 $this->getLang()->formatNum( $this->file
->getWidth() ),
571 $this->getLang()->formatNum( $this->file
->getHeight() )
574 wfMsgExt( 'nbytes', 'parsemag', $this->getLang()->formatNum( $this->file
->getSize() ) ) .
577 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
578 $data . ' ' . $this->getComment(). '</li>';
583 * List for filearchive table items
585 class RevDel_ArchivedFileList
extends RevDel_FileList
{
586 var $type = 'filearchive';
587 var $idField = 'fa_id';
588 var $dateField = 'fa_timestamp';
589 var $authorIdField = 'fa_user';
590 var $authorNameField = 'fa_user_text';
593 * @param $db DatabaseBase
596 public function doQuery( $db ) {
597 $ids = array_map( 'intval', $this->ids
);
598 return $db->select( 'filearchive', '*',
600 'fa_name' => $this->title
->getDBkey(),
604 array( 'ORDER BY' => 'fa_id DESC' )
608 public function newItem( $row ) {
609 return new RevDel_ArchivedFileItem( $this, $row );
614 * Item class for a filearchive table row
616 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
617 public function __construct( $list, $row ) {
618 RevDel_Item
::__construct( $list, $row );
619 $this->file
= ArchivedFile
::newFromRow( $row );
622 public function getId() {
623 return $this->row
->fa_id
;
626 public function setBits( $bits ) {
627 $dbw = wfGetDB( DB_MASTER
);
628 $dbw->update( 'filearchive',
629 array( 'fa_deleted' => $bits ),
631 'fa_id' => $this->row
->fa_id
,
632 'fa_deleted' => $this->getBits(),
636 return (bool)$dbw->affectedRows();
639 protected function getLink() {
640 $date = $this->getLang()->timeanddate( $this->file
->getTimestamp(), true );
641 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
642 $key = $this->file
->getKey();
644 if( !$this->canViewContent() ) {
647 $link = Linker
::link( $undelete, $date, array(),
649 'target' => $this->list->title
->getPrefixedText(),
651 'token' => $this->getUser()->editToken( $key )
655 if( $this->isDeleted() ) {
656 $link = '<span class="history-deleted">' . $link . '</span>';
663 * List for logging table items
665 class RevDel_LogList
extends RevDel_List
{
666 var $type = 'logging';
667 var $idField = 'log_id';
668 var $dateField = 'log_timestamp';
669 var $authorIdField = 'log_user';
670 var $authorNameField = 'log_user_text';
673 * @param $db DatabaseBase
676 public function doQuery( $db ) {
677 $ids = array_map( 'intval', $this->ids
);
678 return $db->select( 'logging', '*',
679 array( 'log_id' => $ids ),
681 array( 'ORDER BY' => 'log_id DESC' )
685 public function newItem( $row ) {
686 return new RevDel_LogItem( $this, $row );
689 public function getSuppressBit() {
690 return Revision
::DELETED_RESTRICTED
;
693 public function getLogAction() {
697 public function getLogParams( $params ) {
699 implode( ',', $params['ids'] ),
700 "ofield={$params['oldBits']}",
701 "nfield={$params['newBits']}"
707 * Item class for a logging table row
709 class RevDel_LogItem
extends RevDel_Item
{
710 public function canView() {
711 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
714 public function canViewContent() {
718 public function getBits() {
719 return $this->row
->log_deleted
;
722 public function setBits( $bits ) {
723 $dbw = wfGetDB( DB_MASTER
);
724 $dbw->update( 'recentchanges',
726 'rc_deleted' => $bits,
730 'rc_logid' => $this->row
->log_id
,
731 'rc_timestamp' => $this->row
->log_timestamp
// index
735 $dbw->update( 'logging',
736 array( 'log_deleted' => $bits ),
738 'log_id' => $this->row
->log_id
,
739 'log_deleted' => $this->getBits()
743 return (bool)$dbw->affectedRows();
746 public function getHTML() {
747 $date = htmlspecialchars( $this->getLang()->timeanddate( $this->row
->log_timestamp
) );
748 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
749 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
751 // Log link for this page
752 $loglink = Linker
::link(
753 SpecialPage
::getTitleFor( 'Log' ),
756 array( 'page' => $title->getPrefixedText() )
759 if( !$this->canView() ) {
760 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
762 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
763 $this->special
->getSkin(), $paramArray, true, true );
764 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
765 $action = '<span class="history-deleted">' . $action . '</span>';
768 $userLink = Linker
::userLink( $this->row
->log_user
,
769 User
::WhoIs( $this->row
->log_user
) );
770 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
771 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
774 $comment = $this->getLang()->getDirMark() . Linker
::commentBlock( $this->row
->log_comment
);
775 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
776 $comment = '<span class="history-deleted">' . $comment . '</span>';
778 return "<li>($loglink) $date $userLink $action $comment</li>";