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' ),
37 array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
38 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
41 if ( $live->numRows() >= count( $ids ) ) {
42 // All requested revisions are live, keeps things simple!
46 // Check if any requested revisions are available fully deleted.
47 $archived = $db->select( array( 'archive' ), '*',
52 array( 'ORDER BY' => 'ar_rev_id DESC' )
55 if ( $archived->numRows() == 0 ) {
57 } elseif ( $live->numRows() == 0 ) {
60 // Combine the two! Whee
62 foreach ( $live as $row ) {
63 $rows[$row->rev_id
] = $row;
65 foreach ( $archived as $row ) {
66 $rows[$row->ar_rev_id
] = $row;
69 return new FakeResultWrapper( array_values( $rows ) );
73 public function newItem( $row ) {
74 if ( isset( $row->rev_id
) ) {
75 return new RevDel_RevisionItem( $this, $row );
76 } elseif ( isset( $row->ar_rev_id
) ) {
77 return new RevDel_ArchivedRevisionItem( $this, $row );
79 // This shouldn't happen. :)
80 throw new MWException( 'Invalid row type in RevDel_RevisionList' );
84 public function getCurrent() {
85 if ( is_null( $this->currentRevId
) ) {
86 $dbw = wfGetDB( DB_MASTER
);
87 $this->currentRevId
= $dbw->selectField(
88 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
90 return $this->currentRevId
;
93 public function getSuppressBit() {
94 return Revision
::DELETED_RESTRICTED
;
97 public function doPreCommitUpdates() {
98 $this->title
->invalidateCache();
99 return Status
::newGood();
102 public function doPostCommitUpdates() {
103 $this->title
->purgeSquid();
104 // Extensions that require referencing previous revisions may need this
105 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
106 return Status
::newGood();
111 * Item class for a live revision table row
113 class RevDel_RevisionItem
extends RevDel_Item
{
116 public function __construct( $list, $row ) {
117 parent
::__construct( $list, $row );
118 $this->revision
= new Revision( $row );
121 public function getIdField() {
125 public function getTimestampField() {
126 return 'rev_timestamp';
129 public function getAuthorIdField() {
133 public function getAuthorNameField() {
134 return 'rev_user_name'; // see Revision::selectUserFields()
137 public function canView() {
138 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->list->getUser() );
141 public function canViewContent() {
142 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->list->getUser() );
145 public function getBits() {
146 return $this->revision
->mDeleted
;
149 public function setBits( $bits ) {
150 $dbw = wfGetDB( DB_MASTER
);
151 // Update revision table
152 $dbw->update( 'revision',
153 array( 'rev_deleted' => $bits ),
155 'rev_id' => $this->revision
->getId(),
156 'rev_page' => $this->revision
->getPage(),
157 'rev_deleted' => $this->getBits()
161 if ( !$dbw->affectedRows() ) {
165 // Update recentchanges table
166 $dbw->update( 'recentchanges',
168 'rc_deleted' => $bits,
172 'rc_this_oldid' => $this->revision
->getId(), // condition
173 // non-unique timestamp index
174 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
181 public function isDeleted() {
182 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
185 public function isHideCurrentOp( $newBits ) {
186 return ( $newBits & Revision
::DELETED_TEXT
)
187 && $this->list->getCurrent() == $this->getId();
191 * Get the HTML link to the revision text.
192 * Overridden by RevDel_ArchiveItem.
194 protected function getRevisionLink() {
195 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
196 if ( $this->isDeleted() && !$this->canViewContent() ) {
204 'oldid' => $this->revision
->getId(),
211 * Get the HTML link to the diff.
212 * Overridden by RevDel_ArchiveItem
214 protected function getDiffLink() {
215 if ( $this->isDeleted() && !$this->canViewContent() ) {
216 return wfMsgHtml('diff');
224 'diff' => $this->revision
->getId(),
236 public function getHTML() {
237 $difflink = $this->getDiffLink();
238 $revlink = $this->getRevisionLink();
239 $userlink = Linker
::revUserLink( $this->revision
);
240 $comment = Linker
::revComment( $this->revision
);
241 if ( $this->isDeleted() ) {
242 $revlink = "<span class=\"history-deleted\">$revlink</span>";
244 return "<li>($difflink) $revlink $userlink $comment</li>";
249 * List for archive table items, i.e. revisions deleted via action=delete
251 class RevDel_ArchiveList
extends RevDel_RevisionList
{
252 public function getType() {
256 public static function getRelationType() {
257 return 'ar_timestamp';
261 * @param $db DatabaseBase
264 public function doQuery( $db ) {
265 $timestamps = array();
266 foreach ( $this->ids
as $id ) {
267 $timestamps[] = $db->timestamp( $id );
269 return $db->select( 'archive', '*',
271 'ar_namespace' => $this->title
->getNamespace(),
272 'ar_title' => $this->title
->getDBkey(),
273 'ar_timestamp' => $timestamps
276 array( 'ORDER BY' => 'ar_timestamp DESC' )
280 public function newItem( $row ) {
281 return new RevDel_ArchiveItem( $this, $row );
284 public function doPreCommitUpdates() {
285 return Status
::newGood();
288 public function doPostCommitUpdates() {
289 return Status
::newGood();
294 * Item class for a archive table row
296 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
297 public function __construct( $list, $row ) {
298 RevDel_Item
::__construct( $list, $row );
299 $this->revision
= Revision
::newFromArchiveRow( $row,
300 array( 'page' => $this->list->title
->getArticleId() ) );
303 public function getIdField() {
304 return 'ar_timestamp';
307 public function getTimestampField() {
308 return 'ar_timestamp';
311 public function getAuthorIdField() {
315 public function getAuthorNameField() {
316 return 'ar_user_text';
319 public function getId() {
320 # Convert DB timestamp to MW timestamp
321 return $this->revision
->getTimestamp();
324 public function setBits( $bits ) {
325 $dbw = wfGetDB( DB_MASTER
);
326 $dbw->update( 'archive',
327 array( 'ar_deleted' => $bits ),
329 'ar_namespace' => $this->list->title
->getNamespace(),
330 'ar_title' => $this->list->title
->getDBkey(),
331 // use timestamp for index
332 'ar_timestamp' => $this->row
->ar_timestamp
,
333 'ar_rev_id' => $this->row
->ar_rev_id
,
334 'ar_deleted' => $this->getBits()
337 return (bool)$dbw->affectedRows();
340 protected function getRevisionLink() {
341 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
342 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
343 if ( $this->isDeleted() && !$this->canViewContent() ) {
346 return Linker
::link( $undelete, $date, array(),
348 'target' => $this->list->title
->getPrefixedText(),
349 'timestamp' => $this->revision
->getTimestamp()
353 protected function getDiffLink() {
354 if ( $this->isDeleted() && !$this->canViewContent() ) {
355 return wfMsgHtml( 'diff' );
357 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
358 return Linker
::link( $undelete, wfMsgHtml('diff'), array(),
360 'target' => $this->list->title
->getPrefixedText(),
362 'timestamp' => $this->revision
->getTimestamp()
369 * Item class for a archive table row by ar_rev_id -- actually
370 * used via RevDel_RevisionList.
372 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
373 public function __construct( $list, $row ) {
374 RevDel_Item
::__construct( $list, $row );
376 $this->revision
= Revision
::newFromArchiveRow( $row,
377 array( 'page' => $this->list->title
->getArticleId() ) );
380 public function getIdField() {
384 public function getId() {
385 return $this->revision
->getId();
388 public function setBits( $bits ) {
389 $dbw = wfGetDB( DB_MASTER
);
390 $dbw->update( 'archive',
391 array( 'ar_deleted' => $bits ),
392 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
393 'ar_deleted' => $this->getBits()
396 return (bool)$dbw->affectedRows();
401 * List for oldimage table items
403 class RevDel_FileList
extends RevDel_List
{
404 public function getType() {
408 public static function getRelationType() {
409 return 'oi_archive_name';
412 var $storeBatch, $deleteBatch, $cleanupBatch;
415 * @param $db DatabaseBase
418 public function doQuery( $db ) {
419 $archiveNames = array();
420 foreach( $this->ids
as $timestamp ) {
421 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
423 return $db->select( 'oldimage', '*',
425 'oi_name' => $this->title
->getDBkey(),
426 'oi_archive_name' => $archiveNames
429 array( 'ORDER BY' => 'oi_timestamp DESC' )
433 public function newItem( $row ) {
434 return new RevDel_FileItem( $this, $row );
437 public function clearFileOps() {
438 $this->deleteBatch
= array();
439 $this->storeBatch
= array();
440 $this->cleanupBatch
= array();
443 public function doPreCommitUpdates() {
444 $status = Status
::newGood();
445 $repo = RepoGroup
::singleton()->getLocalRepo();
446 if ( $this->storeBatch
) {
447 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
449 if ( !$status->isOK() ) {
452 if ( $this->deleteBatch
) {
453 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
455 if ( !$status->isOK() ) {
456 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
457 // modified (but destined for rollback) causes data loss
460 if ( $this->cleanupBatch
) {
461 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
466 public function doPostCommitUpdates() {
467 $file = wfLocalFile( $this->title
);
469 $file->purgeDescription();
470 return Status
::newGood();
473 public function getSuppressBit() {
474 return File
::DELETED_RESTRICTED
;
479 * Item class for an oldimage table row
481 class RevDel_FileItem
extends RevDel_Item
{
488 public function __construct( $list, $row ) {
489 parent
::__construct( $list, $row );
490 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
493 public function getIdField() {
494 return 'oi_archive_name';
497 public function getTimestampField() {
498 return 'oi_timestamp';
501 public function getAuthorIdField() {
505 public function getAuthorNameField() {
506 return 'oi_user_text';
509 public function getId() {
510 $parts = explode( '!', $this->row
->oi_archive_name
);
514 public function canView() {
515 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
518 public function canViewContent() {
519 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
522 public function getBits() {
523 return $this->file
->getVisibility();
526 public function setBits( $bits ) {
528 # @todo FIXME: Move to LocalFile.php
529 if ( $this->isDeleted() ) {
530 if ( $bits & File
::DELETED_FILE
) {
534 $key = $this->file
->getStorageKey();
535 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
536 $this->list->storeBatch
[] = array(
537 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
539 $this->file
->getRel()
541 $this->list->cleanupBatch
[] = $key;
543 } elseif ( $bits & File
::DELETED_FILE
) {
545 $key = $this->file
->getStorageKey();
546 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
547 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
550 # Do the database operations
551 $dbw = wfGetDB( DB_MASTER
);
552 $dbw->update( 'oldimage',
553 array( 'oi_deleted' => $bits ),
555 'oi_name' => $this->row
->oi_name
,
556 'oi_timestamp' => $this->row
->oi_timestamp
,
557 'oi_deleted' => $this->getBits()
561 return (bool)$dbw->affectedRows();
564 public function isDeleted() {
565 return $this->file
->isDeleted( File
::DELETED_FILE
);
569 * Get the link to the file.
570 * Overridden by RevDel_ArchivedFileItem.
572 protected function getLink() {
573 $date = $this->list->getLang()->timeanddate( $this->file
->getTimestamp(), true );
574 if ( $this->isDeleted() ) {
576 if ( !$this->canViewContent() ) {
579 $revdelete = SpecialPage
::getTitleFor( 'Revisiondelete' );
580 $link = Linker
::link(
584 'target' => $this->list->title
->getPrefixedText(),
585 'file' => $this->file
->getArchiveName(),
586 'token' => $this->list->getUser()->editToken(
587 $this->file
->getArchiveName() )
591 return '<span class="history-deleted">' . $link . '</span>';
594 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
598 * Generate a user tool link cluster if the current user is allowed to view it
599 * @return string HTML
601 protected function getUserTools() {
602 if( $this->file
->userCan( Revision
::DELETED_USER
, $this->list->getUser() ) ) {
603 $link = Linker
::userLink( $this->file
->user
, $this->file
->user_text
) .
604 Linker
::userToolLinks( $this->file
->user
, $this->file
->user_text
);
606 $link = wfMsgHtml( 'rev-deleted-user' );
608 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
609 return '<span class="history-deleted">' . $link . '</span>';
615 * Wrap and format the file's comment block, if the current
616 * user is allowed to view it.
618 * @return string HTML
620 protected function getComment() {
621 if( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
622 $block = Linker
::commentBlock( $this->file
->description
);
624 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
626 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
627 return "<span class=\"history-deleted\">$block</span>";
632 public function getHTML() {
636 $this->list->getLang()->formatNum( $this->file
->getWidth() ),
637 $this->list->getLang()->formatNum( $this->file
->getHeight() )
640 wfMsgExt( 'nbytes', 'parsemag', $this->list->getLang()->formatNum( $this->file
->getSize() ) ) .
643 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
644 $data . ' ' . $this->getComment(). '</li>';
649 * List for filearchive table items
651 class RevDel_ArchivedFileList
extends RevDel_FileList
{
652 public function getType() {
653 return 'filearchive';
656 public static function getRelationType() {
661 * @param $db DatabaseBase
664 public function doQuery( $db ) {
665 $ids = array_map( 'intval', $this->ids
);
666 return $db->select( 'filearchive', '*',
668 'fa_name' => $this->title
->getDBkey(),
672 array( 'ORDER BY' => 'fa_id DESC' )
676 public function newItem( $row ) {
677 return new RevDel_ArchivedFileItem( $this, $row );
682 * Item class for a filearchive table row
684 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
685 public function __construct( $list, $row ) {
686 RevDel_Item
::__construct( $list, $row );
687 $this->file
= ArchivedFile
::newFromRow( $row );
690 public function getIdField() {
694 public function getTimestampField() {
695 return 'fa_timestamp';
698 public function getAuthorIdField() {
702 public function getAuthorNameField() {
703 return 'fa_user_text';
706 public function getId() {
707 return $this->row
->fa_id
;
710 public function setBits( $bits ) {
711 $dbw = wfGetDB( DB_MASTER
);
712 $dbw->update( 'filearchive',
713 array( 'fa_deleted' => $bits ),
715 'fa_id' => $this->row
->fa_id
,
716 'fa_deleted' => $this->getBits(),
720 return (bool)$dbw->affectedRows();
723 protected function getLink() {
724 $date = $this->list->getLang()->timeanddate( $this->file
->getTimestamp(), true );
725 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
726 $key = $this->file
->getKey();
728 if( !$this->canViewContent() ) {
731 $link = Linker
::link( $undelete, $date, array(),
733 'target' => $this->list->title
->getPrefixedText(),
735 'token' => $this->list->getUser()->editToken( $key )
739 if( $this->isDeleted() ) {
740 $link = '<span class="history-deleted">' . $link . '</span>';
747 * List for logging table items
749 class RevDel_LogList
extends RevDel_List
{
750 public function getType() {
754 public static function getRelationType() {
759 * @param $db DatabaseBase
762 public function doQuery( $db ) {
763 $ids = array_map( 'intval', $this->ids
);
764 return $db->select( 'logging', '*',
765 array( 'log_id' => $ids ),
767 array( 'ORDER BY' => 'log_id DESC' )
771 public function newItem( $row ) {
772 return new RevDel_LogItem( $this, $row );
775 public function getSuppressBit() {
776 return Revision
::DELETED_RESTRICTED
;
779 public function getLogAction() {
783 public function getLogParams( $params ) {
785 implode( ',', $params['ids'] ),
786 "ofield={$params['oldBits']}",
787 "nfield={$params['newBits']}"
793 * Item class for a logging table row
795 class RevDel_LogItem
extends RevDel_Item
{
796 public function getIdField() {
800 public function getTimestampField() {
801 return 'log_timestamp';
804 public function getAuthorIdField() {
808 public function getAuthorNameField() {
809 return 'log_user_text';
812 public function canView() {
813 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
, $this->list->getUser() );
816 public function canViewContent() {
820 public function getBits() {
821 return $this->row
->log_deleted
;
824 public function setBits( $bits ) {
825 $dbw = wfGetDB( DB_MASTER
);
826 $dbw->update( 'recentchanges',
828 'rc_deleted' => $bits,
832 'rc_logid' => $this->row
->log_id
,
833 'rc_timestamp' => $this->row
->log_timestamp
// index
837 $dbw->update( 'logging',
838 array( 'log_deleted' => $bits ),
840 'log_id' => $this->row
->log_id
,
841 'log_deleted' => $this->getBits()
845 return (bool)$dbw->affectedRows();
848 public function getHTML() {
849 $date = htmlspecialchars( $this->list->getLang()->timeanddate( $this->row
->log_timestamp
) );
850 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
851 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
853 // Log link for this page
854 $loglink = Linker
::link(
855 SpecialPage
::getTitleFor( 'Log' ),
858 array( 'page' => $title->getPrefixedText() )
861 if( !$this->canView() ) {
862 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
864 $skin = $this->list->getUser()->getSkin();
865 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
,
866 $title, $skin, $paramArray, true, true );
867 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
868 $action = '<span class="history-deleted">' . $action . '</span>';
871 $userLink = Linker
::userLink( $this->row
->log_user
,
872 User
::WhoIs( $this->row
->log_user
) );
873 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
874 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
877 $comment = $this->list->getLang()->getDirMark() . Linker
::commentBlock( $this->row
->log_comment
);
878 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
879 $comment = '<span class="history-deleted">' . $comment . '</span>';
881 return "<li>($loglink) $date $userLink $action $comment</li>";