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.
196 protected function getRevisionLink() {
197 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
198 if ( $this->isDeleted() && !$this->canViewContent() ) {
206 'oldid' => $this->revision
->getId(),
213 * Get the HTML link to the diff.
214 * Overridden by RevDel_ArchiveItem
217 protected function getDiffLink() {
218 if ( $this->isDeleted() && !$this->canViewContent() ) {
219 return wfMsgHtml('diff');
227 'diff' => $this->revision
->getId(),
239 public function getHTML() {
240 $difflink = $this->getDiffLink();
241 $revlink = $this->getRevisionLink();
242 $userlink = Linker
::revUserLink( $this->revision
);
243 $comment = Linker
::revComment( $this->revision
);
244 if ( $this->isDeleted() ) {
245 $revlink = "<span class=\"history-deleted\">$revlink</span>";
247 return "<li>($difflink) $revlink $userlink $comment</li>";
252 * List for archive table items, i.e. revisions deleted via action=delete
254 class RevDel_ArchiveList
extends RevDel_RevisionList
{
255 public function getType() {
259 public static function getRelationType() {
260 return 'ar_timestamp';
264 * @param $db DatabaseBase
267 public function doQuery( $db ) {
268 $timestamps = array();
269 foreach ( $this->ids
as $id ) {
270 $timestamps[] = $db->timestamp( $id );
272 return $db->select( 'archive', '*',
274 'ar_namespace' => $this->title
->getNamespace(),
275 'ar_title' => $this->title
->getDBkey(),
276 'ar_timestamp' => $timestamps
279 array( 'ORDER BY' => 'ar_timestamp DESC' )
283 public function newItem( $row ) {
284 return new RevDel_ArchiveItem( $this, $row );
287 public function doPreCommitUpdates() {
288 return Status
::newGood();
291 public function doPostCommitUpdates() {
292 return Status
::newGood();
297 * Item class for a archive table row
299 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
300 public function __construct( $list, $row ) {
301 RevDel_Item
::__construct( $list, $row );
302 $this->revision
= Revision
::newFromArchiveRow( $row,
303 array( 'page' => $this->list->title
->getArticleID() ) );
306 public function getIdField() {
307 return 'ar_timestamp';
310 public function getTimestampField() {
311 return 'ar_timestamp';
314 public function getAuthorIdField() {
318 public function getAuthorNameField() {
319 return 'ar_user_text';
322 public function getId() {
323 # Convert DB timestamp to MW timestamp
324 return $this->revision
->getTimestamp();
327 public function setBits( $bits ) {
328 $dbw = wfGetDB( DB_MASTER
);
329 $dbw->update( 'archive',
330 array( 'ar_deleted' => $bits ),
332 'ar_namespace' => $this->list->title
->getNamespace(),
333 'ar_title' => $this->list->title
->getDBkey(),
334 // use timestamp for index
335 'ar_timestamp' => $this->row
->ar_timestamp
,
336 'ar_rev_id' => $this->row
->ar_rev_id
,
337 'ar_deleted' => $this->getBits()
340 return (bool)$dbw->affectedRows();
343 protected function getRevisionLink() {
344 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
345 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
346 if ( $this->isDeleted() && !$this->canViewContent() ) {
349 return Linker
::link( $undelete, $date, array(),
351 'target' => $this->list->title
->getPrefixedText(),
352 'timestamp' => $this->revision
->getTimestamp()
356 protected function getDiffLink() {
357 if ( $this->isDeleted() && !$this->canViewContent() ) {
358 return wfMsgHtml( 'diff' );
360 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
361 return Linker
::link( $undelete, wfMsgHtml('diff'), array(),
363 'target' => $this->list->title
->getPrefixedText(),
365 'timestamp' => $this->revision
->getTimestamp()
372 * Item class for a archive table row by ar_rev_id -- actually
373 * used via RevDel_RevisionList.
375 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
376 public function __construct( $list, $row ) {
377 RevDel_Item
::__construct( $list, $row );
379 $this->revision
= Revision
::newFromArchiveRow( $row,
380 array( 'page' => $this->list->title
->getArticleID() ) );
383 public function getIdField() {
387 public function getId() {
388 return $this->revision
->getId();
391 public function setBits( $bits ) {
392 $dbw = wfGetDB( DB_MASTER
);
393 $dbw->update( 'archive',
394 array( 'ar_deleted' => $bits ),
395 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
396 'ar_deleted' => $this->getBits()
399 return (bool)$dbw->affectedRows();
404 * List for oldimage table items
406 class RevDel_FileList
extends RevDel_List
{
407 public function getType() {
411 public static function getRelationType() {
412 return 'oi_archive_name';
415 var $storeBatch, $deleteBatch, $cleanupBatch;
418 * @param $db DatabaseBase
421 public function doQuery( $db ) {
422 $archiveNames = array();
423 foreach( $this->ids
as $timestamp ) {
424 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
426 return $db->select( 'oldimage', '*',
428 'oi_name' => $this->title
->getDBkey(),
429 'oi_archive_name' => $archiveNames
432 array( 'ORDER BY' => 'oi_timestamp DESC' )
436 public function newItem( $row ) {
437 return new RevDel_FileItem( $this, $row );
440 public function clearFileOps() {
441 $this->deleteBatch
= array();
442 $this->storeBatch
= array();
443 $this->cleanupBatch
= array();
446 public function doPreCommitUpdates() {
447 $status = Status
::newGood();
448 $repo = RepoGroup
::singleton()->getLocalRepo();
449 if ( $this->storeBatch
) {
450 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
452 if ( !$status->isOK() ) {
455 if ( $this->deleteBatch
) {
456 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
458 if ( !$status->isOK() ) {
459 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
460 // modified (but destined for rollback) causes data loss
463 if ( $this->cleanupBatch
) {
464 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
469 public function doPostCommitUpdates() {
470 $file = wfLocalFile( $this->title
);
472 $file->purgeDescription();
473 return Status
::newGood();
476 public function getSuppressBit() {
477 return File
::DELETED_RESTRICTED
;
482 * Item class for an oldimage table row
484 class RevDel_FileItem
extends RevDel_Item
{
491 public function __construct( $list, $row ) {
492 parent
::__construct( $list, $row );
493 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
496 public function getIdField() {
497 return 'oi_archive_name';
500 public function getTimestampField() {
501 return 'oi_timestamp';
504 public function getAuthorIdField() {
508 public function getAuthorNameField() {
509 return 'oi_user_text';
512 public function getId() {
513 $parts = explode( '!', $this->row
->oi_archive_name
);
517 public function canView() {
518 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
521 public function canViewContent() {
522 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
525 public function getBits() {
526 return $this->file
->getVisibility();
529 public function setBits( $bits ) {
531 # @todo FIXME: Move to LocalFile.php
532 if ( $this->isDeleted() ) {
533 if ( $bits & File
::DELETED_FILE
) {
537 $key = $this->file
->getStorageKey();
538 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
539 $this->list->storeBatch
[] = array(
540 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
542 $this->file
->getRel()
544 $this->list->cleanupBatch
[] = $key;
546 } elseif ( $bits & File
::DELETED_FILE
) {
548 $key = $this->file
->getStorageKey();
549 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
550 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
553 # Do the database operations
554 $dbw = wfGetDB( DB_MASTER
);
555 $dbw->update( 'oldimage',
556 array( 'oi_deleted' => $bits ),
558 'oi_name' => $this->row
->oi_name
,
559 'oi_timestamp' => $this->row
->oi_timestamp
,
560 'oi_deleted' => $this->getBits()
564 return (bool)$dbw->affectedRows();
567 public function isDeleted() {
568 return $this->file
->isDeleted( File
::DELETED_FILE
);
572 * Get the link to the file.
573 * Overridden by RevDel_ArchivedFileItem.
576 protected function getLink() {
577 $date = $this->list->getLanguage()->timeanddate( $this->file
->getTimestamp(), true );
578 if ( $this->isDeleted() ) {
580 if ( !$this->canViewContent() ) {
583 $revdelete = SpecialPage
::getTitleFor( 'Revisiondelete' );
584 $link = Linker
::link(
588 'target' => $this->list->title
->getPrefixedText(),
589 'file' => $this->file
->getArchiveName(),
590 'token' => $this->list->getUser()->getEditToken(
591 $this->file
->getArchiveName() )
595 return '<span class="history-deleted">' . $link . '</span>';
598 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
602 * Generate a user tool link cluster if the current user is allowed to view it
603 * @return string HTML
605 protected function getUserTools() {
606 if( $this->file
->userCan( Revision
::DELETED_USER
, $this->list->getUser() ) ) {
607 $link = Linker
::userLink( $this->file
->user
, $this->file
->user_text
) .
608 Linker
::userToolLinks( $this->file
->user
, $this->file
->user_text
);
610 $link = wfMsgHtml( 'rev-deleted-user' );
612 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
613 return '<span class="history-deleted">' . $link . '</span>';
619 * Wrap and format the file's comment block, if the current
620 * user is allowed to view it.
622 * @return string HTML
624 protected function getComment() {
625 if( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
626 $block = Linker
::commentBlock( $this->file
->description
);
628 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
630 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
631 return "<span class=\"history-deleted\">$block</span>";
636 public function getHTML() {
640 $this->list->getLanguage()->formatNum( $this->file
->getWidth() ),
641 $this->list->getLanguage()->formatNum( $this->file
->getHeight() )
644 wfMsgExt( 'nbytes', 'parsemag', $this->list->getLanguage()->formatNum( $this->file
->getSize() ) ) .
647 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
648 $data . ' ' . $this->getComment(). '</li>';
653 * List for filearchive table items
655 class RevDel_ArchivedFileList
extends RevDel_FileList
{
656 public function getType() {
657 return 'filearchive';
660 public static function getRelationType() {
665 * @param $db DatabaseBase
668 public function doQuery( $db ) {
669 $ids = array_map( 'intval', $this->ids
);
670 return $db->select( 'filearchive', '*',
672 'fa_name' => $this->title
->getDBkey(),
676 array( 'ORDER BY' => 'fa_id DESC' )
680 public function newItem( $row ) {
681 return new RevDel_ArchivedFileItem( $this, $row );
686 * Item class for a filearchive table row
688 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
689 public function __construct( $list, $row ) {
690 RevDel_Item
::__construct( $list, $row );
691 $this->file
= ArchivedFile
::newFromRow( $row );
694 public function getIdField() {
698 public function getTimestampField() {
699 return 'fa_timestamp';
702 public function getAuthorIdField() {
706 public function getAuthorNameField() {
707 return 'fa_user_text';
710 public function getId() {
711 return $this->row
->fa_id
;
714 public function setBits( $bits ) {
715 $dbw = wfGetDB( DB_MASTER
);
716 $dbw->update( 'filearchive',
717 array( 'fa_deleted' => $bits ),
719 'fa_id' => $this->row
->fa_id
,
720 'fa_deleted' => $this->getBits(),
724 return (bool)$dbw->affectedRows();
727 protected function getLink() {
728 $date = $this->list->getLanguage()->timeanddate( $this->file
->getTimestamp(), true );
729 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
730 $key = $this->file
->getKey();
732 if( !$this->canViewContent() ) {
735 $link = Linker
::link( $undelete, $date, array(),
737 'target' => $this->list->title
->getPrefixedText(),
739 'token' => $this->list->getUser()->getEditToken( $key )
743 if( $this->isDeleted() ) {
744 $link = '<span class="history-deleted">' . $link . '</span>';
751 * List for logging table items
753 class RevDel_LogList
extends RevDel_List
{
754 public function getType() {
758 public static function getRelationType() {
763 * @param $db DatabaseBase
766 public function doQuery( $db ) {
767 $ids = array_map( 'intval', $this->ids
);
768 return $db->select( 'logging', '*',
769 array( 'log_id' => $ids ),
771 array( 'ORDER BY' => 'log_id DESC' )
775 public function newItem( $row ) {
776 return new RevDel_LogItem( $this, $row );
779 public function getSuppressBit() {
780 return Revision
::DELETED_RESTRICTED
;
783 public function getLogAction() {
787 public function getLogParams( $params ) {
789 implode( ',', $params['ids'] ),
790 "ofield={$params['oldBits']}",
791 "nfield={$params['newBits']}"
797 * Item class for a logging table row
799 class RevDel_LogItem
extends RevDel_Item
{
800 public function getIdField() {
804 public function getTimestampField() {
805 return 'log_timestamp';
808 public function getAuthorIdField() {
812 public function getAuthorNameField() {
813 return 'log_user_text';
816 public function canView() {
817 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
, $this->list->getUser() );
820 public function canViewContent() {
824 public function getBits() {
825 return $this->row
->log_deleted
;
828 public function setBits( $bits ) {
829 $dbw = wfGetDB( DB_MASTER
);
830 $dbw->update( 'recentchanges',
832 'rc_deleted' => $bits,
836 'rc_logid' => $this->row
->log_id
,
837 'rc_timestamp' => $this->row
->log_timestamp
// index
841 $dbw->update( 'logging',
842 array( 'log_deleted' => $bits ),
844 'log_id' => $this->row
->log_id
,
845 'log_deleted' => $this->getBits()
849 return (bool)$dbw->affectedRows();
852 public function getHTML() {
853 $date = htmlspecialchars( $this->list->getLanguage()->timeanddate( $this->row
->log_timestamp
) );
854 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
855 $formatter = LogFormatter
::newFromRow( $this->row
);
856 $formatter->setAudience( LogFormatter
::FOR_THIS_USER
);
858 // Log link for this page
859 $loglink = Linker
::link(
860 SpecialPage
::getTitleFor( 'Log' ),
863 array( 'page' => $title->getPrefixedText() )
865 // User links and action text
866 $action = $formatter->getActionText();
868 $comment = $this->list->getLanguage()->getDirMark() . Linker
::commentBlock( $this->row
->log_comment
);
869 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
870 $comment = '<span class="history-deleted">' . $comment . '</span>';
873 return "<li>($loglink) $date $action $comment</li>";