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
{
14 public function getType() {
18 public static function getRelationType() {
23 * @param $db DatabaseBase
26 public function doQuery( $db ) {
27 $ids = array_map( 'intval', $this->ids
);
29 array( 'revision', 'page', 'user' ),
30 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
32 'rev_page' => $this->title
->getArticleID(),
36 array( 'ORDER BY' => 'rev_id DESC' ),
38 'page' => Revision
::pageJoinCond(),
39 'user' => Revision
::userJoinCond() )
42 if ( $live->numRows() >= count( $ids ) ) {
43 // All requested revisions are live, keeps things simple!
47 // Check if any requested revisions are available fully deleted.
48 $archived = $db->select( array( 'archive' ), '*',
53 array( 'ORDER BY' => 'ar_rev_id DESC' )
56 if ( $archived->numRows() == 0 ) {
58 } elseif ( $live->numRows() == 0 ) {
61 // Combine the two! Whee
63 foreach ( $live as $row ) {
64 $rows[$row->rev_id
] = $row;
66 foreach ( $archived as $row ) {
67 $rows[$row->ar_rev_id
] = $row;
70 return new FakeResultWrapper( array_values( $rows ) );
74 public function newItem( $row ) {
75 if ( isset( $row->rev_id
) ) {
76 return new RevDel_RevisionItem( $this, $row );
77 } elseif ( isset( $row->ar_rev_id
) ) {
78 return new RevDel_ArchivedRevisionItem( $this, $row );
80 // This shouldn't happen. :)
81 throw new MWException( 'Invalid row type in RevDel_RevisionList' );
85 public function getCurrent() {
86 if ( is_null( $this->currentRevId
) ) {
87 $dbw = wfGetDB( DB_MASTER
);
88 $this->currentRevId
= $dbw->selectField(
89 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
91 return $this->currentRevId
;
94 public function getSuppressBit() {
95 return Revision
::DELETED_RESTRICTED
;
98 public function doPreCommitUpdates() {
99 $this->title
->invalidateCache();
100 return Status
::newGood();
103 public function doPostCommitUpdates() {
104 $this->title
->purgeSquid();
105 // Extensions that require referencing previous revisions may need this
106 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
107 return Status
::newGood();
112 * Item class for a live revision table row
114 class RevDel_RevisionItem
extends RevDel_Item
{
117 public function __construct( $list, $row ) {
118 parent
::__construct( $list, $row );
119 $this->revision
= new Revision( $row );
122 public function getIdField() {
126 public function getTimestampField() {
127 return 'rev_timestamp';
130 public function getAuthorIdField() {
134 public function getAuthorNameField() {
135 return 'user_name'; // see Revision::selectUserFields()
138 public function canView() {
139 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->list->getUser() );
142 public function canViewContent() {
143 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->list->getUser() );
146 public function getBits() {
147 return $this->revision
->getVisibility();
150 public function setBits( $bits ) {
151 $dbw = wfGetDB( DB_MASTER
);
152 // Update revision table
153 $dbw->update( 'revision',
154 array( 'rev_deleted' => $bits ),
156 'rev_id' => $this->revision
->getId(),
157 'rev_page' => $this->revision
->getPage(),
158 'rev_deleted' => $this->getBits()
162 if ( !$dbw->affectedRows() ) {
166 // Update recentchanges table
167 $dbw->update( 'recentchanges',
169 'rc_deleted' => $bits,
173 'rc_this_oldid' => $this->revision
->getId(), // condition
174 // non-unique timestamp index
175 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
182 public function isDeleted() {
183 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
186 public function isHideCurrentOp( $newBits ) {
187 return ( $newBits & Revision
::DELETED_TEXT
)
188 && $this->list->getCurrent() == $this->getId();
192 * Get the HTML link to the revision text.
193 * Overridden by RevDel_ArchiveItem.
195 protected function getRevisionLink() {
196 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
197 if ( $this->isDeleted() && !$this->canViewContent() ) {
205 'oldid' => $this->revision
->getId(),
212 * Get the HTML link to the diff.
213 * Overridden by RevDel_ArchiveItem
215 protected function getDiffLink() {
216 if ( $this->isDeleted() && !$this->canViewContent() ) {
217 return wfMsgHtml('diff');
225 'diff' => $this->revision
->getId(),
237 public function getHTML() {
238 $difflink = $this->getDiffLink();
239 $revlink = $this->getRevisionLink();
240 $userlink = Linker
::revUserLink( $this->revision
);
241 $comment = Linker
::revComment( $this->revision
);
242 if ( $this->isDeleted() ) {
243 $revlink = "<span class=\"history-deleted\">$revlink</span>";
245 return "<li>($difflink) $revlink $userlink $comment</li>";
250 * List for archive table items, i.e. revisions deleted via action=delete
252 class RevDel_ArchiveList
extends RevDel_RevisionList
{
253 public function getType() {
257 public static function getRelationType() {
258 return 'ar_timestamp';
262 * @param $db DatabaseBase
265 public function doQuery( $db ) {
266 $timestamps = array();
267 foreach ( $this->ids
as $id ) {
268 $timestamps[] = $db->timestamp( $id );
270 return $db->select( 'archive', '*',
272 'ar_namespace' => $this->title
->getNamespace(),
273 'ar_title' => $this->title
->getDBkey(),
274 'ar_timestamp' => $timestamps
277 array( 'ORDER BY' => 'ar_timestamp DESC' )
281 public function newItem( $row ) {
282 return new RevDel_ArchiveItem( $this, $row );
285 public function doPreCommitUpdates() {
286 return Status
::newGood();
289 public function doPostCommitUpdates() {
290 return Status
::newGood();
295 * Item class for a archive table row
297 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
298 public function __construct( $list, $row ) {
299 RevDel_Item
::__construct( $list, $row );
300 $this->revision
= Revision
::newFromArchiveRow( $row,
301 array( 'page' => $this->list->title
->getArticleId() ) );
304 public function getIdField() {
305 return 'ar_timestamp';
308 public function getTimestampField() {
309 return 'ar_timestamp';
312 public function getAuthorIdField() {
316 public function getAuthorNameField() {
317 return 'ar_user_text';
320 public function getId() {
321 # Convert DB timestamp to MW timestamp
322 return $this->revision
->getTimestamp();
325 public function setBits( $bits ) {
326 $dbw = wfGetDB( DB_MASTER
);
327 $dbw->update( 'archive',
328 array( 'ar_deleted' => $bits ),
330 'ar_namespace' => $this->list->title
->getNamespace(),
331 'ar_title' => $this->list->title
->getDBkey(),
332 // use timestamp for index
333 'ar_timestamp' => $this->row
->ar_timestamp
,
334 'ar_rev_id' => $this->row
->ar_rev_id
,
335 'ar_deleted' => $this->getBits()
338 return (bool)$dbw->affectedRows();
341 protected function getRevisionLink() {
342 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
343 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
344 if ( $this->isDeleted() && !$this->canViewContent() ) {
347 return Linker
::link( $undelete, $date, array(),
349 'target' => $this->list->title
->getPrefixedText(),
350 'timestamp' => $this->revision
->getTimestamp()
354 protected function getDiffLink() {
355 if ( $this->isDeleted() && !$this->canViewContent() ) {
356 return wfMsgHtml( 'diff' );
358 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
359 return Linker
::link( $undelete, wfMsgHtml('diff'), array(),
361 'target' => $this->list->title
->getPrefixedText(),
363 'timestamp' => $this->revision
->getTimestamp()
370 * Item class for a archive table row by ar_rev_id -- actually
371 * used via RevDel_RevisionList.
373 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
374 public function __construct( $list, $row ) {
375 RevDel_Item
::__construct( $list, $row );
377 $this->revision
= Revision
::newFromArchiveRow( $row,
378 array( 'page' => $this->list->title
->getArticleId() ) );
381 public function getIdField() {
385 public function getId() {
386 return $this->revision
->getId();
389 public function setBits( $bits ) {
390 $dbw = wfGetDB( DB_MASTER
);
391 $dbw->update( 'archive',
392 array( 'ar_deleted' => $bits ),
393 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
394 'ar_deleted' => $this->getBits()
397 return (bool)$dbw->affectedRows();
402 * List for oldimage table items
404 class RevDel_FileList
extends RevDel_List
{
405 public function getType() {
409 public static function getRelationType() {
410 return 'oi_archive_name';
413 var $storeBatch, $deleteBatch, $cleanupBatch;
416 * @param $db DatabaseBase
419 public function doQuery( $db ) {
420 $archiveNames = array();
421 foreach( $this->ids
as $timestamp ) {
422 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
424 return $db->select( 'oldimage', '*',
426 'oi_name' => $this->title
->getDBkey(),
427 'oi_archive_name' => $archiveNames
430 array( 'ORDER BY' => 'oi_timestamp DESC' )
434 public function newItem( $row ) {
435 return new RevDel_FileItem( $this, $row );
438 public function clearFileOps() {
439 $this->deleteBatch
= array();
440 $this->storeBatch
= array();
441 $this->cleanupBatch
= array();
444 public function doPreCommitUpdates() {
445 $status = Status
::newGood();
446 $repo = RepoGroup
::singleton()->getLocalRepo();
447 if ( $this->storeBatch
) {
448 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
450 if ( !$status->isOK() ) {
453 if ( $this->deleteBatch
) {
454 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
456 if ( !$status->isOK() ) {
457 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
458 // modified (but destined for rollback) causes data loss
461 if ( $this->cleanupBatch
) {
462 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
467 public function doPostCommitUpdates() {
468 $file = wfLocalFile( $this->title
);
470 $file->purgeDescription();
471 return Status
::newGood();
474 public function getSuppressBit() {
475 return File
::DELETED_RESTRICTED
;
480 * Item class for an oldimage table row
482 class RevDel_FileItem
extends RevDel_Item
{
489 public function __construct( $list, $row ) {
490 parent
::__construct( $list, $row );
491 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
494 public function getIdField() {
495 return 'oi_archive_name';
498 public function getTimestampField() {
499 return 'oi_timestamp';
502 public function getAuthorIdField() {
506 public function getAuthorNameField() {
507 return 'oi_user_text';
510 public function getId() {
511 $parts = explode( '!', $this->row
->oi_archive_name
);
515 public function canView() {
516 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
519 public function canViewContent() {
520 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
523 public function getBits() {
524 return $this->file
->getVisibility();
527 public function setBits( $bits ) {
529 # @todo FIXME: Move to LocalFile.php
530 if ( $this->isDeleted() ) {
531 if ( $bits & File
::DELETED_FILE
) {
535 $key = $this->file
->getStorageKey();
536 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
537 $this->list->storeBatch
[] = array(
538 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
540 $this->file
->getRel()
542 $this->list->cleanupBatch
[] = $key;
544 } elseif ( $bits & File
::DELETED_FILE
) {
546 $key = $this->file
->getStorageKey();
547 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
548 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
551 # Do the database operations
552 $dbw = wfGetDB( DB_MASTER
);
553 $dbw->update( 'oldimage',
554 array( 'oi_deleted' => $bits ),
556 'oi_name' => $this->row
->oi_name
,
557 'oi_timestamp' => $this->row
->oi_timestamp
,
558 'oi_deleted' => $this->getBits()
562 return (bool)$dbw->affectedRows();
565 public function isDeleted() {
566 return $this->file
->isDeleted( File
::DELETED_FILE
);
570 * Get the link to the file.
571 * Overridden by RevDel_ArchivedFileItem.
573 protected function getLink() {
574 $date = $this->list->getLang()->timeanddate( $this->file
->getTimestamp(), true );
575 if ( $this->isDeleted() ) {
577 if ( !$this->canViewContent() ) {
580 $revdelete = SpecialPage
::getTitleFor( 'Revisiondelete' );
581 $link = Linker
::link(
585 'target' => $this->list->title
->getPrefixedText(),
586 'file' => $this->file
->getArchiveName(),
587 'token' => $this->list->getUser()->editToken(
588 $this->file
->getArchiveName() )
592 return '<span class="history-deleted">' . $link . '</span>';
595 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
599 * Generate a user tool link cluster if the current user is allowed to view it
600 * @return string HTML
602 protected function getUserTools() {
603 if( $this->file
->userCan( Revision
::DELETED_USER
, $this->list->getUser() ) ) {
604 $link = Linker
::userLink( $this->file
->user
, $this->file
->user_text
) .
605 Linker
::userToolLinks( $this->file
->user
, $this->file
->user_text
);
607 $link = wfMsgHtml( 'rev-deleted-user' );
609 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
610 return '<span class="history-deleted">' . $link . '</span>';
616 * Wrap and format the file's comment block, if the current
617 * user is allowed to view it.
619 * @return string HTML
621 protected function getComment() {
622 if( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
623 $block = Linker
::commentBlock( $this->file
->description
);
625 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
627 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
628 return "<span class=\"history-deleted\">$block</span>";
633 public function getHTML() {
637 $this->list->getLang()->formatNum( $this->file
->getWidth() ),
638 $this->list->getLang()->formatNum( $this->file
->getHeight() )
641 wfMsgExt( 'nbytes', 'parsemag', $this->list->getLang()->formatNum( $this->file
->getSize() ) ) .
644 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
645 $data . ' ' . $this->getComment(). '</li>';
650 * List for filearchive table items
652 class RevDel_ArchivedFileList
extends RevDel_FileList
{
653 public function getType() {
654 return 'filearchive';
657 public static function getRelationType() {
662 * @param $db DatabaseBase
665 public function doQuery( $db ) {
666 $ids = array_map( 'intval', $this->ids
);
667 return $db->select( 'filearchive', '*',
669 'fa_name' => $this->title
->getDBkey(),
673 array( 'ORDER BY' => 'fa_id DESC' )
677 public function newItem( $row ) {
678 return new RevDel_ArchivedFileItem( $this, $row );
683 * Item class for a filearchive table row
685 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
686 public function __construct( $list, $row ) {
687 RevDel_Item
::__construct( $list, $row );
688 $this->file
= ArchivedFile
::newFromRow( $row );
691 public function getIdField() {
695 public function getTimestampField() {
696 return 'fa_timestamp';
699 public function getAuthorIdField() {
703 public function getAuthorNameField() {
704 return 'fa_user_text';
707 public function getId() {
708 return $this->row
->fa_id
;
711 public function setBits( $bits ) {
712 $dbw = wfGetDB( DB_MASTER
);
713 $dbw->update( 'filearchive',
714 array( 'fa_deleted' => $bits ),
716 'fa_id' => $this->row
->fa_id
,
717 'fa_deleted' => $this->getBits(),
721 return (bool)$dbw->affectedRows();
724 protected function getLink() {
725 $date = $this->list->getLang()->timeanddate( $this->file
->getTimestamp(), true );
726 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
727 $key = $this->file
->getKey();
729 if( !$this->canViewContent() ) {
732 $link = Linker
::link( $undelete, $date, array(),
734 'target' => $this->list->title
->getPrefixedText(),
736 'token' => $this->list->getUser()->editToken( $key )
740 if( $this->isDeleted() ) {
741 $link = '<span class="history-deleted">' . $link . '</span>';
748 * List for logging table items
750 class RevDel_LogList
extends RevDel_List
{
751 public function getType() {
755 public static function getRelationType() {
760 * @param $db DatabaseBase
763 public function doQuery( $db ) {
764 $ids = array_map( 'intval', $this->ids
);
765 return $db->select( 'logging', '*',
766 array( 'log_id' => $ids ),
768 array( 'ORDER BY' => 'log_id DESC' )
772 public function newItem( $row ) {
773 return new RevDel_LogItem( $this, $row );
776 public function getSuppressBit() {
777 return Revision
::DELETED_RESTRICTED
;
780 public function getLogAction() {
784 public function getLogParams( $params ) {
786 implode( ',', $params['ids'] ),
787 "ofield={$params['oldBits']}",
788 "nfield={$params['newBits']}"
794 * Item class for a logging table row
796 class RevDel_LogItem
extends RevDel_Item
{
797 public function getIdField() {
801 public function getTimestampField() {
802 return 'log_timestamp';
805 public function getAuthorIdField() {
809 public function getAuthorNameField() {
810 return 'log_user_text';
813 public function canView() {
814 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
, $this->list->getUser() );
817 public function canViewContent() {
821 public function getBits() {
822 return $this->row
->log_deleted
;
825 public function setBits( $bits ) {
826 $dbw = wfGetDB( DB_MASTER
);
827 $dbw->update( 'recentchanges',
829 'rc_deleted' => $bits,
833 'rc_logid' => $this->row
->log_id
,
834 'rc_timestamp' => $this->row
->log_timestamp
// index
838 $dbw->update( 'logging',
839 array( 'log_deleted' => $bits ),
841 'log_id' => $this->row
->log_id
,
842 'log_deleted' => $this->getBits()
846 return (bool)$dbw->affectedRows();
849 public function getHTML() {
850 $date = htmlspecialchars( $this->list->getLang()->timeanddate( $this->row
->log_timestamp
) );
851 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
852 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
854 // Log link for this page
855 $loglink = Linker
::link(
856 SpecialPage
::getTitleFor( 'Log' ),
859 array( 'page' => $title->getPrefixedText() )
862 if( !$this->canView() ) {
863 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
865 $skin = $this->list->getUser()->getSkin();
866 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
,
867 $title, $skin, $paramArray, true, true );
868 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
869 $action = '<span class="history-deleted">' . $action . '</span>';
872 $userLink = Linker
::userLink( $this->row
->log_user
,
873 User
::WhoIs( $this->row
->log_user
) );
874 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
875 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
878 $comment = $this->list->getLang()->getDirMark() . Linker
::commentBlock( $this->row
->log_comment
);
879 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
880 $comment = '<span class="history-deleted">' . $comment . '</span>';
882 return "<li>($loglink) $date $userLink $action $comment</li>";