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';
13 public function doQuery( $db ) {
14 $ids = array_map( 'intval', $this->ids
);
15 return $db->select( array('revision','page'), '*',
17 'rev_page' => $this->title
->getArticleID(),
22 array( 'ORDER BY' => 'rev_id DESC' )
26 public function newItem( $row ) {
27 return new RevDel_RevisionItem( $this, $row );
30 public function getCurrent() {
31 if ( is_null( $this->currentRevId
) ) {
32 $dbw = wfGetDB( DB_MASTER
);
33 $this->currentRevId
= $dbw->selectField(
34 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
36 return $this->currentRevId
;
39 public function getSuppressBit() {
40 return Revision
::DELETED_RESTRICTED
;
43 public function doPreCommitUpdates() {
44 $this->title
->invalidateCache();
45 return Status
::newGood();
48 public function doPostCommitUpdates() {
49 $this->title
->purgeSquid();
50 // Extensions that require referencing previous revisions may need this
51 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
52 return Status
::newGood();
57 * Item class for a revision table row
59 class RevDel_RevisionItem
extends RevDel_Item
{
62 public function __construct( $list, $row ) {
63 parent
::__construct( $list, $row );
64 $this->revision
= new Revision( $row );
67 public function canView() {
68 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
71 public function canViewContent() {
72 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
75 public function getBits() {
76 return $this->revision
->mDeleted
;
79 public function setBits( $bits ) {
80 $dbw = wfGetDB( DB_MASTER
);
81 // Update revision table
82 $dbw->update( 'revision',
83 array( 'rev_deleted' => $bits ),
85 'rev_id' => $this->revision
->getId(),
86 'rev_page' => $this->revision
->getPage(),
87 'rev_deleted' => $this->getBits()
91 if ( !$dbw->affectedRows() ) {
95 // Update recentchanges table
96 $dbw->update( 'recentchanges',
98 'rc_deleted' => $bits,
102 'rc_this_oldid' => $this->revision
->getId(), // condition
103 // non-unique timestamp index
104 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
111 public function isDeleted() {
112 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
115 public function isHideCurrentOp( $newBits ) {
116 return ( $newBits & Revision
::DELETED_TEXT
)
117 && $this->list->getCurrent() == $this->getId();
121 * Get the HTML link to the revision text.
122 * Overridden by RevDel_ArchiveItem.
124 protected function getRevisionLink() {
126 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
127 if ( $this->isDeleted() && !$this->canViewContent() ) {
130 return $this->special
->skin
->link(
135 'oldid' => $this->revision
->getId(),
142 * Get the HTML link to the diff.
143 * Overridden by RevDel_ArchiveItem
145 protected function getDiffLink() {
146 if ( $this->isDeleted() && !$this->canViewContent() ) {
147 return wfMsgHtml('diff');
150 $this->special
->skin
->link(
155 'diff' => $this->revision
->getId(),
167 public function getHTML() {
168 $difflink = $this->getDiffLink();
169 $revlink = $this->getRevisionLink();
170 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
171 $comment = $this->special
->skin
->revComment( $this->revision
);
172 if ( $this->isDeleted() ) {
173 $revlink = "<span class=\"history-deleted\">$revlink</span>";
175 return "<li>($difflink) $revlink $userlink $comment</li>";
180 * List for archive table items, i.e. revisions deleted via action=delete
182 class RevDel_ArchiveList
extends RevDel_RevisionList
{
183 var $type = 'archive';
184 var $idField = 'ar_timestamp';
185 var $dateField = 'ar_timestamp';
186 var $authorIdField = 'ar_user';
187 var $authorNameField = 'ar_user_text';
189 public function doQuery( $db ) {
190 $timestamps = array();
191 foreach ( $this->ids
as $id ) {
192 $timestamps[] = $db->timestamp( $id );
194 return $db->select( 'archive', '*',
196 'ar_namespace' => $this->title
->getNamespace(),
197 'ar_title' => $this->title
->getDBkey(),
198 'ar_timestamp' => $timestamps
201 array( 'ORDER BY' => 'ar_timestamp DESC' )
205 public function newItem( $row ) {
206 return new RevDel_ArchiveItem( $this, $row );
209 public function doPreCommitUpdates() {
210 return Status
::newGood();
213 public function doPostCommitUpdates() {
214 return Status
::newGood();
219 * Item class for a archive table row
221 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
222 public function __construct( $list, $row ) {
223 RevDel_Item
::__construct( $list, $row );
224 $this->revision
= Revision
::newFromArchiveRow( $row,
225 array( 'page' => $this->list->title
->getArticleId() ) );
228 public function getId() {
229 # Convert DB timestamp to MW timestamp
230 return $this->revision
->getTimestamp();
233 public function setBits( $bits ) {
234 $dbw = wfGetDB( DB_MASTER
);
235 $dbw->update( 'archive',
236 array( 'ar_deleted' => $bits ),
237 array( 'ar_namespace' => $this->list->title
->getNamespace(),
238 'ar_title' => $this->list->title
->getDBkey(),
239 // use timestamp for index
240 'ar_timestamp' => $this->row
->ar_timestamp
,
241 'ar_rev_id' => $this->row
->ar_rev_id
,
242 'ar_deleted' => $this->getBits()
245 return (bool)$dbw->affectedRows();
248 protected function getRevisionLink() {
250 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
251 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
252 if ( $this->isDeleted() && !$this->canViewContent() ) {
255 return $this->special
->skin
->link( $undelete, $date, array(),
257 'target' => $this->list->title
->getPrefixedText(),
258 'timestamp' => $this->revision
->getTimestamp()
262 protected function getDiffLink() {
263 if ( $this->isDeleted() && !$this->canViewContent() ) {
264 return wfMsgHtml( 'diff' );
266 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
267 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
269 'target' => $this->list->title
->getPrefixedText(),
271 'timestamp' => $this->revision
->getTimestamp()
277 * List for oldimage table items
279 class RevDel_FileList
extends RevDel_List
{
280 var $type = 'oldimage';
281 var $idField = 'oi_archive_name';
282 var $dateField = 'oi_timestamp';
283 var $authorIdField = 'oi_user';
284 var $authorNameField = 'oi_user_text';
285 var $storeBatch, $deleteBatch, $cleanupBatch;
287 public function doQuery( $db ) {
288 $archiveNames = array();
289 foreach( $this->ids
as $timestamp ) {
290 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
292 return $db->select( 'oldimage', '*',
294 'oi_name' => $this->title
->getDBkey(),
295 'oi_archive_name' => $archiveNames
298 array( 'ORDER BY' => 'oi_timestamp DESC' )
302 public function newItem( $row ) {
303 return new RevDel_FileItem( $this, $row );
306 public function clearFileOps() {
307 $this->deleteBatch
= array();
308 $this->storeBatch
= array();
309 $this->cleanupBatch
= array();
312 public function doPreCommitUpdates() {
313 $status = Status
::newGood();
314 $repo = RepoGroup
::singleton()->getLocalRepo();
315 if ( $this->storeBatch
) {
316 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
318 if ( !$status->isOK() ) {
321 if ( $this->deleteBatch
) {
322 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
324 if ( !$status->isOK() ) {
325 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
326 // modified (but destined for rollback) causes data loss
329 if ( $this->cleanupBatch
) {
330 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
335 public function doPostCommitUpdates() {
336 $file = wfLocalFile( $this->title
);
338 $file->purgeDescription();
339 return Status
::newGood();
342 public function getSuppressBit() {
343 return File
::DELETED_RESTRICTED
;
348 * Item class for an oldimage table row
350 class RevDel_FileItem
extends RevDel_Item
{
353 public function __construct( $list, $row ) {
354 parent
::__construct( $list, $row );
355 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
358 public function getId() {
359 $parts = explode( '!', $this->row
->oi_archive_name
);
363 public function canView() {
364 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
367 public function canViewContent() {
368 return $this->file
->userCan( File
::DELETED_FILE
);
371 public function getBits() {
372 return $this->file
->getVisibility();
375 public function setBits( $bits ) {
377 # FIXME: move to LocalFile.php
378 if ( $this->isDeleted() ) {
379 if ( $bits & File
::DELETED_FILE
) {
383 $key = $this->file
->getStorageKey();
384 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
385 $this->list->storeBatch
[] = array(
386 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
388 $this->file
->getRel()
390 $this->list->cleanupBatch
[] = $key;
392 } elseif ( $bits & File
::DELETED_FILE
) {
394 $key = $this->file
->getStorageKey();
395 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
396 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
399 # Do the database operations
400 $dbw = wfGetDB( DB_MASTER
);
401 $dbw->update( 'oldimage',
402 array( 'oi_deleted' => $bits ),
404 'oi_name' => $this->row
->oi_name
,
405 'oi_timestamp' => $this->row
->oi_timestamp
,
406 'oi_deleted' => $this->getBits()
410 return (bool)$dbw->affectedRows();
413 public function isDeleted() {
414 return $this->file
->isDeleted( File
::DELETED_FILE
);
418 * Get the link to the file.
419 * Overridden by RevDel_ArchivedFileItem.
421 protected function getLink() {
422 global $wgLang, $wgUser;
423 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
424 if ( $this->isDeleted() ) {
426 if ( !$this->canViewContent() ) {
429 $link = $this->special
->skin
->link(
430 $this->special
->getTitle(),
433 'target' => $this->list->title
->getPrefixedText(),
434 'file' => $this->file
->getArchiveName(),
435 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
439 return '<span class="history-deleted">' . $link . '</span>';
442 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
446 * Generate a user tool link cluster if the current user is allowed to view it
447 * @return string HTML
449 protected function getUserTools() {
450 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
451 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
452 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
454 $link = wfMsgHtml( 'rev-deleted-user' );
456 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
457 return '<span class="history-deleted">' . $link . '</span>';
463 * Wrap and format the file's comment block, if the current
464 * user is allowed to view it.
466 * @return string HTML
468 protected function getComment() {
469 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
470 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
472 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
474 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
475 return "<span class=\"history-deleted\">$block</span>";
480 public function getHTML() {
485 $wgLang->formatNum( $this->file
->getWidth() ),
486 $wgLang->formatNum( $this->file
->getHeight() )
489 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
492 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
493 $data . ' ' . $this->getComment(). '</li>';
498 * List for filearchive table items
500 class RevDel_ArchivedFileList
extends RevDel_FileList
{
501 var $type = 'filearchive';
502 var $idField = 'fa_id';
503 var $dateField = 'fa_timestamp';
504 var $authorIdField = 'fa_user';
505 var $authorNameField = 'fa_user_text';
507 public function doQuery( $db ) {
508 $ids = array_map( 'intval', $this->ids
);
509 return $db->select( 'filearchive', '*',
511 'fa_name' => $this->title
->getDBkey(),
515 array( 'ORDER BY' => 'fa_id DESC' )
519 public function newItem( $row ) {
520 return new RevDel_ArchivedFileItem( $this, $row );
525 * Item class for a filearchive table row
527 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
528 public function __construct( $list, $row ) {
529 RevDel_Item
::__construct( $list, $row );
530 $this->file
= ArchivedFile
::newFromRow( $row );
533 public function getId() {
534 return $this->row
->fa_id
;
537 public function setBits( $bits ) {
538 $dbw = wfGetDB( DB_MASTER
);
539 $dbw->update( 'filearchive',
540 array( 'fa_deleted' => $bits ),
542 'fa_id' => $this->row
->fa_id
,
543 'fa_deleted' => $this->getBits(),
547 return (bool)$dbw->affectedRows();
550 protected function getLink() {
551 global $wgLang, $wgUser;
552 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
553 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
554 $key = $this->file
->getKey();
556 if( !$this->canViewContent() ) {
559 $link = $this->special
->skin
->link( $undelete, $date, array(),
561 'target' => $this->list->title
->getPrefixedText(),
563 'token' => $wgUser->editToken( $key )
567 if( $this->isDeleted() ) {
568 $link = '<span class="history-deleted">' . $link . '</span>';
575 * List for logging table items
577 class RevDel_LogList
extends RevDel_List
{
578 var $type = 'logging';
579 var $idField = 'log_id';
580 var $dateField = 'log_timestamp';
581 var $authorIdField = 'log_user';
582 var $authorNameField = 'log_user_text';
584 public function doQuery( $db ) {
585 $ids = array_map( 'intval', $this->ids
);
586 return $db->select( 'logging', '*',
587 array( 'log_id' => $ids ),
589 array( 'ORDER BY' => 'log_id DESC' )
593 public function newItem( $row ) {
594 return new RevDel_LogItem( $this, $row );
597 public function getSuppressBit() {
598 return Revision
::DELETED_RESTRICTED
;
601 public function getLogAction() {
605 public function getLogParams( $params ) {
607 implode( ',', $params['ids'] ),
608 "ofield={$params['oldBits']}",
609 "nfield={$params['newBits']}"
615 * Item class for a logging table row
617 class RevDel_LogItem
extends RevDel_Item
{
618 public function canView() {
619 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
622 public function canViewContent() {
626 public function getBits() {
627 return $this->row
->log_deleted
;
630 public function setBits( $bits ) {
631 $dbw = wfGetDB( DB_MASTER
);
632 $dbw->update( 'recentchanges',
634 'rc_deleted' => $bits,
638 'rc_logid' => $this->row
->log_id
,
639 'rc_timestamp' => $this->row
->log_timestamp
// index
643 $dbw->update( 'logging',
644 array( 'log_deleted' => $bits ),
646 'log_id' => $this->row
->log_id
,
647 'log_deleted' => $this->getBits()
651 return (bool)$dbw->affectedRows();
654 public function getHTML() {
657 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
658 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
659 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
661 // Log link for this page
662 $loglink = $this->special
->skin
->link(
663 SpecialPage
::getTitleFor( 'Log' ),
666 array( 'page' => $title->getPrefixedText() )
669 if( !$this->canView() ) {
670 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
672 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
673 $this->special
->skin
, $paramArray, true, true );
674 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
675 $action = '<span class="history-deleted">' . $action . '</span>';
678 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
679 User
::WhoIs( $this->row
->log_user
) );
680 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
681 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
684 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
685 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
686 $comment = '<span class="history-deleted">' . $comment . '</span>';
688 return "<li>($loglink) $date $userLink $action $comment</li>";