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 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() {
174 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
175 if ( $this->isDeleted() && !$this->canViewContent() ) {
178 return $this->special
->skin
->link(
183 'oldid' => $this->revision
->getId(),
190 * Get the HTML link to the diff.
191 * Overridden by RevDel_ArchiveItem
193 protected function getDiffLink() {
194 if ( $this->isDeleted() && !$this->canViewContent() ) {
195 return wfMsgHtml('diff');
198 $this->special
->skin
->link(
203 'diff' => $this->revision
->getId(),
215 public function getHTML() {
216 $difflink = $this->getDiffLink();
217 $revlink = $this->getRevisionLink();
218 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
219 $comment = $this->special
->skin
->revComment( $this->revision
);
220 if ( $this->isDeleted() ) {
221 $revlink = "<span class=\"history-deleted\">$revlink</span>";
223 return "<li>($difflink) $revlink $userlink $comment</li>";
228 * List for archive table items, i.e. revisions deleted via action=delete
230 class RevDel_ArchiveList
extends RevDel_RevisionList
{
231 var $type = 'archive';
232 var $idField = 'ar_timestamp';
233 var $dateField = 'ar_timestamp';
234 var $authorIdField = 'ar_user';
235 var $authorNameField = 'ar_user_text';
238 * @param $db DatabaseBase
241 public function doQuery( $db ) {
242 $timestamps = array();
243 foreach ( $this->ids
as $id ) {
244 $timestamps[] = $db->timestamp( $id );
246 return $db->select( 'archive', '*',
248 'ar_namespace' => $this->title
->getNamespace(),
249 'ar_title' => $this->title
->getDBkey(),
250 'ar_timestamp' => $timestamps
253 array( 'ORDER BY' => 'ar_timestamp DESC' )
257 public function newItem( $row ) {
258 return new RevDel_ArchiveItem( $this, $row );
261 public function doPreCommitUpdates() {
262 return Status
::newGood();
265 public function doPostCommitUpdates() {
266 return Status
::newGood();
271 * Item class for a archive table row
273 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
274 public function __construct( $list, $row ) {
275 RevDel_Item
::__construct( $list, $row );
276 $this->revision
= Revision
::newFromArchiveRow( $row,
277 array( 'page' => $this->list->title
->getArticleId() ) );
280 public function getId() {
281 # Convert DB timestamp to MW timestamp
282 return $this->revision
->getTimestamp();
285 public function setBits( $bits ) {
286 $dbw = wfGetDB( DB_MASTER
);
287 $dbw->update( 'archive',
288 array( 'ar_deleted' => $bits ),
289 array( 'ar_namespace' => $this->list->title
->getNamespace(),
290 'ar_title' => $this->list->title
->getDBkey(),
291 // use timestamp for index
292 'ar_timestamp' => $this->row
->ar_timestamp
,
293 'ar_rev_id' => $this->row
->ar_rev_id
,
294 'ar_deleted' => $this->getBits()
297 return (bool)$dbw->affectedRows();
300 protected function getRevisionLink() {
302 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
303 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
304 if ( $this->isDeleted() && !$this->canViewContent() ) {
307 return $this->special
->skin
->link( $undelete, $date, array(),
309 'target' => $this->list->title
->getPrefixedText(),
310 'timestamp' => $this->revision
->getTimestamp()
314 protected function getDiffLink() {
315 if ( $this->isDeleted() && !$this->canViewContent() ) {
316 return wfMsgHtml( 'diff' );
318 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
319 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
321 'target' => $this->list->title
->getPrefixedText(),
323 'timestamp' => $this->revision
->getTimestamp()
330 * Item class for a archive table row by ar_rev_id -- actually
331 * used via RevDel_RevisionList.
333 class RevDel_ArchivedRevisionItem
extends RevDel_ArchiveItem
{
334 public function __construct( $list, $row ) {
335 RevDel_Item
::__construct( $list, $row );
337 $this->revision
= Revision
::newFromArchiveRow( $row,
338 array( 'page' => $this->list->title
->getArticleId() ) );
341 public function getId() {
342 return $this->revision
->getId();
345 public function setBits( $bits ) {
346 $dbw = wfGetDB( DB_MASTER
);
347 $dbw->update( 'archive',
348 array( 'ar_deleted' => $bits ),
349 array( 'ar_rev_id' => $this->row
->ar_rev_id
,
350 'ar_deleted' => $this->getBits()
353 return (bool)$dbw->affectedRows();
358 * List for oldimage table items
360 class RevDel_FileList
extends RevDel_List
{
361 var $type = 'oldimage';
362 var $idField = 'oi_archive_name';
363 var $dateField = 'oi_timestamp';
364 var $authorIdField = 'oi_user';
365 var $authorNameField = 'oi_user_text';
366 var $storeBatch, $deleteBatch, $cleanupBatch;
369 * @param $db DatabaseBase
372 public function doQuery( $db ) {
373 $archiveNames = array();
374 foreach( $this->ids
as $timestamp ) {
375 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
377 return $db->select( 'oldimage', '*',
379 'oi_name' => $this->title
->getDBkey(),
380 'oi_archive_name' => $archiveNames
383 array( 'ORDER BY' => 'oi_timestamp DESC' )
387 public function newItem( $row ) {
388 return new RevDel_FileItem( $this, $row );
391 public function clearFileOps() {
392 $this->deleteBatch
= array();
393 $this->storeBatch
= array();
394 $this->cleanupBatch
= array();
397 public function doPreCommitUpdates() {
398 $status = Status
::newGood();
399 $repo = RepoGroup
::singleton()->getLocalRepo();
400 if ( $this->storeBatch
) {
401 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
403 if ( !$status->isOK() ) {
406 if ( $this->deleteBatch
) {
407 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
409 if ( !$status->isOK() ) {
410 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
411 // modified (but destined for rollback) causes data loss
414 if ( $this->cleanupBatch
) {
415 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
420 public function doPostCommitUpdates() {
421 $file = wfLocalFile( $this->title
);
423 $file->purgeDescription();
424 return Status
::newGood();
427 public function getSuppressBit() {
428 return File
::DELETED_RESTRICTED
;
433 * Item class for an oldimage table row
435 class RevDel_FileItem
extends RevDel_Item
{
442 public function __construct( $list, $row ) {
443 parent
::__construct( $list, $row );
444 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
447 public function getId() {
448 $parts = explode( '!', $this->row
->oi_archive_name
);
452 public function canView() {
453 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
456 public function canViewContent() {
457 return $this->file
->userCan( File
::DELETED_FILE
);
460 public function getBits() {
461 return $this->file
->getVisibility();
464 public function setBits( $bits ) {
466 # @todo FIXME: Move to LocalFile.php
467 if ( $this->isDeleted() ) {
468 if ( $bits & File
::DELETED_FILE
) {
472 $key = $this->file
->getStorageKey();
473 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
474 $this->list->storeBatch
[] = array(
475 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
477 $this->file
->getRel()
479 $this->list->cleanupBatch
[] = $key;
481 } elseif ( $bits & File
::DELETED_FILE
) {
483 $key = $this->file
->getStorageKey();
484 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
485 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
488 # Do the database operations
489 $dbw = wfGetDB( DB_MASTER
);
490 $dbw->update( 'oldimage',
491 array( 'oi_deleted' => $bits ),
493 'oi_name' => $this->row
->oi_name
,
494 'oi_timestamp' => $this->row
->oi_timestamp
,
495 'oi_deleted' => $this->getBits()
499 return (bool)$dbw->affectedRows();
502 public function isDeleted() {
503 return $this->file
->isDeleted( File
::DELETED_FILE
);
507 * Get the link to the file.
508 * Overridden by RevDel_ArchivedFileItem.
510 protected function getLink() {
511 global $wgLang, $wgUser;
512 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
513 if ( $this->isDeleted() ) {
515 if ( !$this->canViewContent() ) {
518 $link = $this->special
->skin
->link(
519 $this->special
->getTitle(),
522 'target' => $this->list->title
->getPrefixedText(),
523 'file' => $this->file
->getArchiveName(),
524 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
528 return '<span class="history-deleted">' . $link . '</span>';
531 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
535 * Generate a user tool link cluster if the current user is allowed to view it
536 * @return string HTML
538 protected function getUserTools() {
539 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
540 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
541 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
543 $link = wfMsgHtml( 'rev-deleted-user' );
545 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
546 return '<span class="history-deleted">' . $link . '</span>';
552 * Wrap and format the file's comment block, if the current
553 * user is allowed to view it.
555 * @return string HTML
557 protected function getComment() {
558 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
559 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
561 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
563 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
564 return "<span class=\"history-deleted\">$block</span>";
569 public function getHTML() {
574 $wgLang->formatNum( $this->file
->getWidth() ),
575 $wgLang->formatNum( $this->file
->getHeight() )
578 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
581 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
582 $data . ' ' . $this->getComment(). '</li>';
587 * List for filearchive table items
589 class RevDel_ArchivedFileList
extends RevDel_FileList
{
590 var $type = 'filearchive';
591 var $idField = 'fa_id';
592 var $dateField = 'fa_timestamp';
593 var $authorIdField = 'fa_user';
594 var $authorNameField = 'fa_user_text';
597 * @param $db DatabaseBase
600 public function doQuery( $db ) {
601 $ids = array_map( 'intval', $this->ids
);
602 return $db->select( 'filearchive', '*',
604 'fa_name' => $this->title
->getDBkey(),
608 array( 'ORDER BY' => 'fa_id DESC' )
612 public function newItem( $row ) {
613 return new RevDel_ArchivedFileItem( $this, $row );
618 * Item class for a filearchive table row
620 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
621 public function __construct( $list, $row ) {
622 RevDel_Item
::__construct( $list, $row );
623 $this->file
= ArchivedFile
::newFromRow( $row );
626 public function getId() {
627 return $this->row
->fa_id
;
630 public function setBits( $bits ) {
631 $dbw = wfGetDB( DB_MASTER
);
632 $dbw->update( 'filearchive',
633 array( 'fa_deleted' => $bits ),
635 'fa_id' => $this->row
->fa_id
,
636 'fa_deleted' => $this->getBits(),
640 return (bool)$dbw->affectedRows();
643 protected function getLink() {
644 global $wgLang, $wgUser;
645 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
646 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
647 $key = $this->file
->getKey();
649 if( !$this->canViewContent() ) {
652 $link = $this->special
->skin
->link( $undelete, $date, array(),
654 'target' => $this->list->title
->getPrefixedText(),
656 'token' => $wgUser->editToken( $key )
660 if( $this->isDeleted() ) {
661 $link = '<span class="history-deleted">' . $link . '</span>';
668 * List for logging table items
670 class RevDel_LogList
extends RevDel_List
{
671 var $type = 'logging';
672 var $idField = 'log_id';
673 var $dateField = 'log_timestamp';
674 var $authorIdField = 'log_user';
675 var $authorNameField = 'log_user_text';
678 * @param $db DatabaseBase
681 public function doQuery( $db ) {
682 $ids = array_map( 'intval', $this->ids
);
683 return $db->select( 'logging', '*',
684 array( 'log_id' => $ids ),
686 array( 'ORDER BY' => 'log_id DESC' )
690 public function newItem( $row ) {
691 return new RevDel_LogItem( $this, $row );
694 public function getSuppressBit() {
695 return Revision
::DELETED_RESTRICTED
;
698 public function getLogAction() {
702 public function getLogParams( $params ) {
704 implode( ',', $params['ids'] ),
705 "ofield={$params['oldBits']}",
706 "nfield={$params['newBits']}"
712 * Item class for a logging table row
714 class RevDel_LogItem
extends RevDel_Item
{
715 public function canView() {
716 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
719 public function canViewContent() {
723 public function getBits() {
724 return $this->row
->log_deleted
;
727 public function setBits( $bits ) {
728 $dbw = wfGetDB( DB_MASTER
);
729 $dbw->update( 'recentchanges',
731 'rc_deleted' => $bits,
735 'rc_logid' => $this->row
->log_id
,
736 'rc_timestamp' => $this->row
->log_timestamp
// index
740 $dbw->update( 'logging',
741 array( 'log_deleted' => $bits ),
743 'log_id' => $this->row
->log_id
,
744 'log_deleted' => $this->getBits()
748 return (bool)$dbw->affectedRows();
751 public function getHTML() {
754 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
755 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
756 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
758 // Log link for this page
759 $loglink = $this->special
->skin
->link(
760 SpecialPage
::getTitleFor( 'Log' ),
763 array( 'page' => $title->getPrefixedText() )
766 if( !$this->canView() ) {
767 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
769 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
770 $this->special
->skin
, $paramArray, true, true );
771 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
772 $action = '<span class="history-deleted">' . $action . '</span>';
775 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
776 User
::WhoIs( $this->row
->log_user
) );
777 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
778 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
781 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
782 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
783 $comment = '<span class="history-deleted">' . $comment . '</span>';
785 return "<li>($loglink) $date $userLink $action $comment</li>";