3 * List for revision table items
5 class RevDel_RevisionList
extends RevDel_List
{
7 var $type = 'revision';
8 var $idField = 'rev_id';
9 var $dateField = 'rev_timestamp';
10 var $authorIdField = 'rev_user';
11 var $authorNameField = 'rev_user_text';
14 * @param $db DatabaseBase
17 public function doQuery( $db ) {
18 $ids = array_map( 'intval', $this->ids
);
19 return $db->select( array('revision','page'), '*',
21 'rev_page' => $this->title
->getArticleID(),
26 array( 'ORDER BY' => 'rev_id DESC' )
30 public function newItem( $row ) {
31 return new RevDel_RevisionItem( $this, $row );
34 public function getCurrent() {
35 if ( is_null( $this->currentRevId
) ) {
36 $dbw = wfGetDB( DB_MASTER
);
37 $this->currentRevId
= $dbw->selectField(
38 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
40 return $this->currentRevId
;
43 public function getSuppressBit() {
44 return Revision
::DELETED_RESTRICTED
;
47 public function doPreCommitUpdates() {
48 $this->title
->invalidateCache();
49 return Status
::newGood();
52 public function doPostCommitUpdates() {
53 $this->title
->purgeSquid();
54 // Extensions that require referencing previous revisions may need this
55 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
56 return Status
::newGood();
61 * Item class for a revision table row
63 class RevDel_RevisionItem
extends RevDel_Item
{
66 public function __construct( $list, $row ) {
67 parent
::__construct( $list, $row );
68 $this->revision
= new Revision( $row );
71 public function canView() {
72 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
75 public function canViewContent() {
76 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
79 public function getBits() {
80 return $this->revision
->mDeleted
;
83 public function setBits( $bits ) {
84 $dbw = wfGetDB( DB_MASTER
);
85 // Update revision table
86 $dbw->update( 'revision',
87 array( 'rev_deleted' => $bits ),
89 'rev_id' => $this->revision
->getId(),
90 'rev_page' => $this->revision
->getPage(),
91 'rev_deleted' => $this->getBits()
95 if ( !$dbw->affectedRows() ) {
99 // Update recentchanges table
100 $dbw->update( 'recentchanges',
102 'rc_deleted' => $bits,
106 'rc_this_oldid' => $this->revision
->getId(), // condition
107 // non-unique timestamp index
108 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
115 public function isDeleted() {
116 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
119 public function isHideCurrentOp( $newBits ) {
120 return ( $newBits & Revision
::DELETED_TEXT
)
121 && $this->list->getCurrent() == $this->getId();
125 * Get the HTML link to the revision text.
126 * Overridden by RevDel_ArchiveItem.
128 protected function getRevisionLink() {
130 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
131 if ( $this->isDeleted() && !$this->canViewContent() ) {
134 return $this->special
->skin
->link(
139 'oldid' => $this->revision
->getId(),
146 * Get the HTML link to the diff.
147 * Overridden by RevDel_ArchiveItem
149 protected function getDiffLink() {
150 if ( $this->isDeleted() && !$this->canViewContent() ) {
151 return wfMsgHtml('diff');
154 $this->special
->skin
->link(
159 'diff' => $this->revision
->getId(),
171 public function getHTML() {
172 $difflink = $this->getDiffLink();
173 $revlink = $this->getRevisionLink();
174 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
175 $comment = $this->special
->skin
->revComment( $this->revision
);
176 if ( $this->isDeleted() ) {
177 $revlink = "<span class=\"history-deleted\">$revlink</span>";
179 return "<li>($difflink) $revlink $userlink $comment</li>";
184 * List for archive table items, i.e. revisions deleted via action=delete
186 class RevDel_ArchiveList
extends RevDel_RevisionList
{
187 var $type = 'archive';
188 var $idField = 'ar_timestamp';
189 var $dateField = 'ar_timestamp';
190 var $authorIdField = 'ar_user';
191 var $authorNameField = 'ar_user_text';
194 * @param $db DatabaseBase
197 public function doQuery( $db ) {
198 $timestamps = array();
199 foreach ( $this->ids
as $id ) {
200 $timestamps[] = $db->timestamp( $id );
202 return $db->select( 'archive', '*',
204 'ar_namespace' => $this->title
->getNamespace(),
205 'ar_title' => $this->title
->getDBkey(),
206 'ar_timestamp' => $timestamps
209 array( 'ORDER BY' => 'ar_timestamp DESC' )
213 public function newItem( $row ) {
214 return new RevDel_ArchiveItem( $this, $row );
217 public function doPreCommitUpdates() {
218 return Status
::newGood();
221 public function doPostCommitUpdates() {
222 return Status
::newGood();
227 * Item class for a archive table row
229 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
230 public function __construct( $list, $row ) {
231 RevDel_Item
::__construct( $list, $row );
232 $this->revision
= Revision
::newFromArchiveRow( $row,
233 array( 'page' => $this->list->title
->getArticleId() ) );
236 public function getId() {
237 # Convert DB timestamp to MW timestamp
238 return $this->revision
->getTimestamp();
241 public function setBits( $bits ) {
242 $dbw = wfGetDB( DB_MASTER
);
243 $dbw->update( 'archive',
244 array( 'ar_deleted' => $bits ),
245 array( 'ar_namespace' => $this->list->title
->getNamespace(),
246 'ar_title' => $this->list->title
->getDBkey(),
247 // use timestamp for index
248 'ar_timestamp' => $this->row
->ar_timestamp
,
249 'ar_rev_id' => $this->row
->ar_rev_id
,
250 'ar_deleted' => $this->getBits()
253 return (bool)$dbw->affectedRows();
256 protected function getRevisionLink() {
258 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
259 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
260 if ( $this->isDeleted() && !$this->canViewContent() ) {
263 return $this->special
->skin
->link( $undelete, $date, array(),
265 'target' => $this->list->title
->getPrefixedText(),
266 'timestamp' => $this->revision
->getTimestamp()
270 protected function getDiffLink() {
271 if ( $this->isDeleted() && !$this->canViewContent() ) {
272 return wfMsgHtml( 'diff' );
274 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
275 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
277 'target' => $this->list->title
->getPrefixedText(),
279 'timestamp' => $this->revision
->getTimestamp()
285 * List for oldimage table items
287 class RevDel_FileList
extends RevDel_List
{
288 var $type = 'oldimage';
289 var $idField = 'oi_archive_name';
290 var $dateField = 'oi_timestamp';
291 var $authorIdField = 'oi_user';
292 var $authorNameField = 'oi_user_text';
293 var $storeBatch, $deleteBatch, $cleanupBatch;
296 * @param $db DatabaseBase
299 public function doQuery( $db ) {
300 $archiveNames = array();
301 foreach( $this->ids
as $timestamp ) {
302 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
304 return $db->select( 'oldimage', '*',
306 'oi_name' => $this->title
->getDBkey(),
307 'oi_archive_name' => $archiveNames
310 array( 'ORDER BY' => 'oi_timestamp DESC' )
314 public function newItem( $row ) {
315 return new RevDel_FileItem( $this, $row );
318 public function clearFileOps() {
319 $this->deleteBatch
= array();
320 $this->storeBatch
= array();
321 $this->cleanupBatch
= array();
324 public function doPreCommitUpdates() {
325 $status = Status
::newGood();
326 $repo = RepoGroup
::singleton()->getLocalRepo();
327 if ( $this->storeBatch
) {
328 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
330 if ( !$status->isOK() ) {
333 if ( $this->deleteBatch
) {
334 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
336 if ( !$status->isOK() ) {
337 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
338 // modified (but destined for rollback) causes data loss
341 if ( $this->cleanupBatch
) {
342 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
347 public function doPostCommitUpdates() {
348 $file = wfLocalFile( $this->title
);
350 $file->purgeDescription();
351 return Status
::newGood();
354 public function getSuppressBit() {
355 return File
::DELETED_RESTRICTED
;
360 * Item class for an oldimage table row
362 class RevDel_FileItem
extends RevDel_Item
{
369 public function __construct( $list, $row ) {
370 parent
::__construct( $list, $row );
371 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
374 public function getId() {
375 $parts = explode( '!', $this->row
->oi_archive_name
);
379 public function canView() {
380 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
383 public function canViewContent() {
384 return $this->file
->userCan( File
::DELETED_FILE
);
387 public function getBits() {
388 return $this->file
->getVisibility();
391 public function setBits( $bits ) {
393 # FIXME: move to LocalFile.php
394 if ( $this->isDeleted() ) {
395 if ( $bits & File
::DELETED_FILE
) {
399 $key = $this->file
->getStorageKey();
400 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
401 $this->list->storeBatch
[] = array(
402 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
404 $this->file
->getRel()
406 $this->list->cleanupBatch
[] = $key;
408 } elseif ( $bits & File
::DELETED_FILE
) {
410 $key = $this->file
->getStorageKey();
411 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
412 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
415 # Do the database operations
416 $dbw = wfGetDB( DB_MASTER
);
417 $dbw->update( 'oldimage',
418 array( 'oi_deleted' => $bits ),
420 'oi_name' => $this->row
->oi_name
,
421 'oi_timestamp' => $this->row
->oi_timestamp
,
422 'oi_deleted' => $this->getBits()
426 return (bool)$dbw->affectedRows();
429 public function isDeleted() {
430 return $this->file
->isDeleted( File
::DELETED_FILE
);
434 * Get the link to the file.
435 * Overridden by RevDel_ArchivedFileItem.
437 protected function getLink() {
438 global $wgLang, $wgUser;
439 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
440 if ( $this->isDeleted() ) {
442 if ( !$this->canViewContent() ) {
445 $link = $this->special
->skin
->link(
446 $this->special
->getTitle(),
449 'target' => $this->list->title
->getPrefixedText(),
450 'file' => $this->file
->getArchiveName(),
451 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
455 return '<span class="history-deleted">' . $link . '</span>';
458 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
462 * Generate a user tool link cluster if the current user is allowed to view it
463 * @return string HTML
465 protected function getUserTools() {
466 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
467 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
468 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
470 $link = wfMsgHtml( 'rev-deleted-user' );
472 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
473 return '<span class="history-deleted">' . $link . '</span>';
479 * Wrap and format the file's comment block, if the current
480 * user is allowed to view it.
482 * @return string HTML
484 protected function getComment() {
485 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
486 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
488 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
490 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
491 return "<span class=\"history-deleted\">$block</span>";
496 public function getHTML() {
501 $wgLang->formatNum( $this->file
->getWidth() ),
502 $wgLang->formatNum( $this->file
->getHeight() )
505 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
508 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
509 $data . ' ' . $this->getComment(). '</li>';
514 * List for filearchive table items
516 class RevDel_ArchivedFileList
extends RevDel_FileList
{
517 var $type = 'filearchive';
518 var $idField = 'fa_id';
519 var $dateField = 'fa_timestamp';
520 var $authorIdField = 'fa_user';
521 var $authorNameField = 'fa_user_text';
524 * @param $db DatabaseBase
527 public function doQuery( $db ) {
528 $ids = array_map( 'intval', $this->ids
);
529 return $db->select( 'filearchive', '*',
531 'fa_name' => $this->title
->getDBkey(),
535 array( 'ORDER BY' => 'fa_id DESC' )
539 public function newItem( $row ) {
540 return new RevDel_ArchivedFileItem( $this, $row );
545 * Item class for a filearchive table row
547 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
548 public function __construct( $list, $row ) {
549 RevDel_Item
::__construct( $list, $row );
550 $this->file
= ArchivedFile
::newFromRow( $row );
553 public function getId() {
554 return $this->row
->fa_id
;
557 public function setBits( $bits ) {
558 $dbw = wfGetDB( DB_MASTER
);
559 $dbw->update( 'filearchive',
560 array( 'fa_deleted' => $bits ),
562 'fa_id' => $this->row
->fa_id
,
563 'fa_deleted' => $this->getBits(),
567 return (bool)$dbw->affectedRows();
570 protected function getLink() {
571 global $wgLang, $wgUser;
572 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
573 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
574 $key = $this->file
->getKey();
576 if( !$this->canViewContent() ) {
579 $link = $this->special
->skin
->link( $undelete, $date, array(),
581 'target' => $this->list->title
->getPrefixedText(),
583 'token' => $wgUser->editToken( $key )
587 if( $this->isDeleted() ) {
588 $link = '<span class="history-deleted">' . $link . '</span>';
595 * List for logging table items
597 class RevDel_LogList
extends RevDel_List
{
598 var $type = 'logging';
599 var $idField = 'log_id';
600 var $dateField = 'log_timestamp';
601 var $authorIdField = 'log_user';
602 var $authorNameField = 'log_user_text';
605 * @param $db DatabaseBase
608 public function doQuery( $db ) {
609 $ids = array_map( 'intval', $this->ids
);
610 return $db->select( 'logging', '*',
611 array( 'log_id' => $ids ),
613 array( 'ORDER BY' => 'log_id DESC' )
617 public function newItem( $row ) {
618 return new RevDel_LogItem( $this, $row );
621 public function getSuppressBit() {
622 return Revision
::DELETED_RESTRICTED
;
625 public function getLogAction() {
629 public function getLogParams( $params ) {
631 implode( ',', $params['ids'] ),
632 "ofield={$params['oldBits']}",
633 "nfield={$params['newBits']}"
639 * Item class for a logging table row
641 class RevDel_LogItem
extends RevDel_Item
{
642 public function canView() {
643 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
646 public function canViewContent() {
650 public function getBits() {
651 return $this->row
->log_deleted
;
654 public function setBits( $bits ) {
655 $dbw = wfGetDB( DB_MASTER
);
656 $dbw->update( 'recentchanges',
658 'rc_deleted' => $bits,
662 'rc_logid' => $this->row
->log_id
,
663 'rc_timestamp' => $this->row
->log_timestamp
// index
667 $dbw->update( 'logging',
668 array( 'log_deleted' => $bits ),
670 'log_id' => $this->row
->log_id
,
671 'log_deleted' => $this->getBits()
675 return (bool)$dbw->affectedRows();
678 public function getHTML() {
681 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
682 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
683 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
685 // Log link for this page
686 $loglink = $this->special
->skin
->link(
687 SpecialPage
::getTitleFor( 'Log' ),
690 array( 'page' => $title->getPrefixedText() )
693 if( !$this->canView() ) {
694 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
696 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
697 $this->special
->skin
, $paramArray, true, true );
698 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
699 $action = '<span class="history-deleted">' . $action . '</span>';
702 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
703 User
::WhoIs( $this->row
->log_user
) );
704 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
705 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
708 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
709 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
710 $comment = '<span class="history-deleted">' . $comment . '</span>';
712 return "<li>($loglink) $date $userLink $action $comment</li>";