Actually format search error Status objects nicely
[mediawiki.git] / includes / revisiondelete / RevisionDelete.php
blobfbfe325a7f79cbdfcefb6a726bbbc26f94454ca2
1 <?php
2 /**
3 * Base implementations for deletable items.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup RevisionDelete
24 /**
25 * List for revision table items
27 * This will check both the 'revision' table for live revisions and the
28 * 'archive' table for traditionally-deleted revisions that have an
29 * ar_rev_id saved.
31 * See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
33 class RevDelRevisionList extends RevDelList {
34 var $currentRevId;
36 public function getType() {
37 return 'revision';
40 public static function getRelationType() {
41 return 'rev_id';
44 public static function getRestriction() {
45 return 'deleterevision';
48 public static function getRevdelConstant() {
49 return Revision::DELETED_TEXT;
52 public static function suggestTarget( $target, array $ids ) {
53 $rev = Revision::newFromId( $ids[0] );
54 return $rev ? $rev->getTitle() : $target;
57 /**
58 * @param DatabaseBase $db
59 * @return mixed
61 public function doQuery( $db ) {
62 $ids = array_map( 'intval', $this->ids );
63 $live = $db->select(
64 array( 'revision', 'page', 'user' ),
65 array_merge( Revision::selectFields(), Revision::selectUserFields() ),
66 array(
67 'rev_page' => $this->title->getArticleID(),
68 'rev_id' => $ids,
70 __METHOD__,
71 array( 'ORDER BY' => 'rev_id DESC' ),
72 array(
73 'page' => Revision::pageJoinCond(),
74 'user' => Revision::userJoinCond() )
77 if ( $live->numRows() >= count( $ids ) ) {
78 // All requested revisions are live, keeps things simple!
79 return $live;
82 // Check if any requested revisions are available fully deleted.
83 $archived = $db->select( array( 'archive' ), Revision::selectArchiveFields(),
84 array(
85 'ar_rev_id' => $ids
87 __METHOD__,
88 array( 'ORDER BY' => 'ar_rev_id DESC' )
91 if ( $archived->numRows() == 0 ) {
92 return $live;
93 } elseif ( $live->numRows() == 0 ) {
94 return $archived;
95 } else {
96 // Combine the two! Whee
97 $rows = array();
98 foreach ( $live as $row ) {
99 $rows[$row->rev_id] = $row;
101 foreach ( $archived as $row ) {
102 $rows[$row->ar_rev_id] = $row;
104 krsort( $rows );
105 return new FakeResultWrapper( array_values( $rows ) );
109 public function newItem( $row ) {
110 if ( isset( $row->rev_id ) ) {
111 return new RevDelRevisionItem( $this, $row );
112 } elseif ( isset( $row->ar_rev_id ) ) {
113 return new RevDelArchivedRevisionItem( $this, $row );
114 } else {
115 // This shouldn't happen. :)
116 throw new MWException( 'Invalid row type in RevDelRevisionList' );
120 public function getCurrent() {
121 if ( is_null( $this->currentRevId ) ) {
122 $dbw = wfGetDB( DB_MASTER );
123 $this->currentRevId = $dbw->selectField(
124 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
126 return $this->currentRevId;
129 public function getSuppressBit() {
130 return Revision::DELETED_RESTRICTED;
133 public function doPreCommitUpdates() {
134 $this->title->invalidateCache();
135 return Status::newGood();
138 public function doPostCommitUpdates() {
139 $this->title->purgeSquid();
140 // Extensions that require referencing previous revisions may need this
141 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title ) );
142 return Status::newGood();
147 * Item class for a live revision table row
149 class RevDelRevisionItem extends RevDelItem {
150 var $revision;
152 public function __construct( $list, $row ) {
153 parent::__construct( $list, $row );
154 $this->revision = new Revision( $row );
157 public function getIdField() {
158 return 'rev_id';
161 public function getTimestampField() {
162 return 'rev_timestamp';
165 public function getAuthorIdField() {
166 return 'rev_user';
169 public function getAuthorNameField() {
170 return 'rev_user_text';
173 public function canView() {
174 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
177 public function canViewContent() {
178 return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
181 public function getBits() {
182 return $this->revision->getVisibility();
185 public function setBits( $bits ) {
186 $dbw = wfGetDB( DB_MASTER );
187 // Update revision table
188 $dbw->update( 'revision',
189 array( 'rev_deleted' => $bits ),
190 array(
191 'rev_id' => $this->revision->getId(),
192 'rev_page' => $this->revision->getPage(),
193 'rev_deleted' => $this->getBits()
195 __METHOD__
197 if ( !$dbw->affectedRows() ) {
198 // Concurrent fail!
199 return false;
201 // Update recentchanges table
202 $dbw->update( 'recentchanges',
203 array(
204 'rc_deleted' => $bits,
205 'rc_patrolled' => 1
207 array(
208 'rc_this_oldid' => $this->revision->getId(), // condition
209 // non-unique timestamp index
210 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
212 __METHOD__
214 return true;
217 public function isDeleted() {
218 return $this->revision->isDeleted( Revision::DELETED_TEXT );
221 public function isHideCurrentOp( $newBits ) {
222 return ( $newBits & Revision::DELETED_TEXT )
223 && $this->list->getCurrent() == $this->getId();
227 * Get the HTML link to the revision text.
228 * Overridden by RevDelArchiveItem.
229 * @return string
231 protected function getRevisionLink() {
232 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
233 $this->revision->getTimestamp(), $this->list->getUser() ) );
235 if ( $this->isDeleted() && !$this->canViewContent() ) {
236 return $date;
238 return Linker::linkKnown(
239 $this->list->title,
240 $date,
241 array(),
242 array(
243 'oldid' => $this->revision->getId(),
244 'unhide' => 1
250 * Get the HTML link to the diff.
251 * Overridden by RevDelArchiveItem
252 * @return string
254 protected function getDiffLink() {
255 if ( $this->isDeleted() && !$this->canViewContent() ) {
256 return $this->list->msg( 'diff' )->escaped();
257 } else {
258 return Linker::linkKnown(
259 $this->list->title,
260 $this->list->msg( 'diff' )->escaped(),
261 array(),
262 array(
263 'diff' => $this->revision->getId(),
264 'oldid' => 'prev',
265 'unhide' => 1
271 public function getHTML() {
272 $difflink = $this->list->msg( 'parentheses' )
273 ->rawParams( $this->getDiffLink() )->escaped();
274 $revlink = $this->getRevisionLink();
275 $userlink = Linker::revUserLink( $this->revision );
276 $comment = Linker::revComment( $this->revision );
277 if ( $this->isDeleted() ) {
278 $revlink = "<span class=\"history-deleted\">$revlink</span>";
280 return "<li>$difflink $revlink $userlink $comment</li>";
283 public function getApiData( ApiResult $result ) {
284 $rev = $this->revision;
285 $user = $this->list->getUser();
286 $ret = array(
287 'id' => $rev->getId(),
288 'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
290 $ret += $rev->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
291 $ret += $rev->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
292 $ret += $rev->isDeleted( Revision::DELETED_TEXT ) ? array( 'texthidden' => '' ) : array();
293 if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
294 $ret += array(
295 'userid' => $rev->getUser( Revision::FOR_THIS_USER ),
296 'user' => $rev->getUserText( Revision::FOR_THIS_USER ),
299 if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
300 $ret += array(
301 'comment' => $rev->getComment( Revision::FOR_THIS_USER ),
304 return $ret;
309 * List for archive table items, i.e. revisions deleted via action=delete
311 class RevDelArchiveList extends RevDelRevisionList {
312 public function getType() {
313 return 'archive';
316 public static function getRelationType() {
317 return 'ar_timestamp';
321 * @param DatabaseBase $db
322 * @return mixed
324 public function doQuery( $db ) {
325 $timestamps = array();
326 foreach ( $this->ids as $id ) {
327 $timestamps[] = $db->timestamp( $id );
329 return $db->select( 'archive', Revision::selectArchiveFields(),
330 array(
331 'ar_namespace' => $this->title->getNamespace(),
332 'ar_title' => $this->title->getDBkey(),
333 'ar_timestamp' => $timestamps
335 __METHOD__,
336 array( 'ORDER BY' => 'ar_timestamp DESC' )
340 public function newItem( $row ) {
341 return new RevDelArchiveItem( $this, $row );
344 public function doPreCommitUpdates() {
345 return Status::newGood();
348 public function doPostCommitUpdates() {
349 return Status::newGood();
354 * Item class for a archive table row
356 class RevDelArchiveItem extends RevDelRevisionItem {
357 public function __construct( $list, $row ) {
358 RevDelItem::__construct( $list, $row );
359 $this->revision = Revision::newFromArchiveRow( $row,
360 array( 'page' => $this->list->title->getArticleID() ) );
363 public function getIdField() {
364 return 'ar_timestamp';
367 public function getTimestampField() {
368 return 'ar_timestamp';
371 public function getAuthorIdField() {
372 return 'ar_user';
375 public function getAuthorNameField() {
376 return 'ar_user_text';
379 public function getId() {
380 # Convert DB timestamp to MW timestamp
381 return $this->revision->getTimestamp();
384 public function setBits( $bits ) {
385 $dbw = wfGetDB( DB_MASTER );
386 $dbw->update( 'archive',
387 array( 'ar_deleted' => $bits ),
388 array(
389 'ar_namespace' => $this->list->title->getNamespace(),
390 'ar_title' => $this->list->title->getDBkey(),
391 // use timestamp for index
392 'ar_timestamp' => $this->row->ar_timestamp,
393 'ar_rev_id' => $this->row->ar_rev_id,
394 'ar_deleted' => $this->getBits()
396 __METHOD__ );
397 return (bool)$dbw->affectedRows();
400 protected function getRevisionLink() {
401 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
402 $this->revision->getTimestamp(), $this->list->getUser() ) );
404 if ( $this->isDeleted() && !$this->canViewContent() ) {
405 return $date;
408 return Linker::link(
409 SpecialPage::getTitleFor( 'Undelete' ),
410 $date,
411 array(),
412 array(
413 'target' => $this->list->title->getPrefixedText(),
414 'timestamp' => $this->revision->getTimestamp()
419 protected function getDiffLink() {
420 if ( $this->isDeleted() && !$this->canViewContent() ) {
421 return $this->list->msg( 'diff' )->escaped();
424 return Linker::link(
425 SpecialPage::getTitleFor( 'Undelete' ),
426 $this->list->msg( 'diff' )->escaped(),
427 array(),
428 array(
429 'target' => $this->list->title->getPrefixedText(),
430 'diff' => 'prev',
431 'timestamp' => $this->revision->getTimestamp()
438 * Item class for a archive table row by ar_rev_id -- actually
439 * used via RevDelRevisionList.
441 class RevDelArchivedRevisionItem extends RevDelArchiveItem {
442 public function __construct( $list, $row ) {
443 RevDelItem::__construct( $list, $row );
445 $this->revision = Revision::newFromArchiveRow( $row,
446 array( 'page' => $this->list->title->getArticleID() ) );
449 public function getIdField() {
450 return 'ar_rev_id';
453 public function getId() {
454 return $this->revision->getId();
457 public function setBits( $bits ) {
458 $dbw = wfGetDB( DB_MASTER );
459 $dbw->update( 'archive',
460 array( 'ar_deleted' => $bits ),
461 array( 'ar_rev_id' => $this->row->ar_rev_id,
462 'ar_deleted' => $this->getBits()
464 __METHOD__ );
465 return (bool)$dbw->affectedRows();
470 * List for oldimage table items
472 class RevDelFileList extends RevDelList {
473 public function getType() {
474 return 'oldimage';
477 public static function getRelationType() {
478 return 'oi_archive_name';
481 public static function getRestriction() {
482 return 'deleterevision';
485 public static function getRevdelConstant() {
486 return File::DELETED_FILE;
489 var $storeBatch, $deleteBatch, $cleanupBatch;
492 * @param DatabaseBase $db
493 * @return mixed
495 public function doQuery( $db ) {
496 $archiveNames = array();
497 foreach ( $this->ids as $timestamp ) {
498 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
500 return $db->select(
501 'oldimage',
502 OldLocalFile::selectFields(),
503 array(
504 'oi_name' => $this->title->getDBkey(),
505 'oi_archive_name' => $archiveNames
507 __METHOD__,
508 array( 'ORDER BY' => 'oi_timestamp DESC' )
512 public function newItem( $row ) {
513 return new RevDelFileItem( $this, $row );
516 public function clearFileOps() {
517 $this->deleteBatch = array();
518 $this->storeBatch = array();
519 $this->cleanupBatch = array();
522 public function doPreCommitUpdates() {
523 $status = Status::newGood();
524 $repo = RepoGroup::singleton()->getLocalRepo();
525 if ( $this->storeBatch ) {
526 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
528 if ( !$status->isOK() ) {
529 return $status;
531 if ( $this->deleteBatch ) {
532 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
534 if ( !$status->isOK() ) {
535 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
536 // modified (but destined for rollback) causes data loss
537 return $status;
539 if ( $this->cleanupBatch ) {
540 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
542 return $status;
545 public function doPostCommitUpdates() {
546 global $wgUseSquid;
547 $file = wfLocalFile( $this->title );
548 $file->purgeCache();
549 $file->purgeDescription();
550 $purgeUrls = array();
551 foreach ( $this->ids as $timestamp ) {
552 $archiveName = $timestamp . '!' . $this->title->getDBkey();
553 $file->purgeOldThumbnails( $archiveName );
554 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
556 if ( $wgUseSquid ) {
557 // purge full images from cache
558 SquidUpdate::purge( $purgeUrls );
560 return Status::newGood();
563 public function getSuppressBit() {
564 return File::DELETED_RESTRICTED;
569 * Item class for an oldimage table row
571 class RevDelFileItem extends RevDelItem {
574 * @var File
576 var $file;
578 public function __construct( $list, $row ) {
579 parent::__construct( $list, $row );
580 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
583 public function getIdField() {
584 return 'oi_archive_name';
587 public function getTimestampField() {
588 return 'oi_timestamp';
591 public function getAuthorIdField() {
592 return 'oi_user';
595 public function getAuthorNameField() {
596 return 'oi_user_text';
599 public function getId() {
600 $parts = explode( '!', $this->row->oi_archive_name );
601 return $parts[0];
604 public function canView() {
605 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
608 public function canViewContent() {
609 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
612 public function getBits() {
613 return $this->file->getVisibility();
616 public function setBits( $bits ) {
617 # Queue the file op
618 # @todo FIXME: Move to LocalFile.php
619 if ( $this->isDeleted() ) {
620 if ( $bits & File::DELETED_FILE ) {
621 # Still deleted
622 } else {
623 # Newly undeleted
624 $key = $this->file->getStorageKey();
625 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
626 $this->list->storeBatch[] = array(
627 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
628 'public',
629 $this->file->getRel()
631 $this->list->cleanupBatch[] = $key;
633 } elseif ( $bits & File::DELETED_FILE ) {
634 # Newly deleted
635 $key = $this->file->getStorageKey();
636 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
637 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
640 # Do the database operations
641 $dbw = wfGetDB( DB_MASTER );
642 $dbw->update( 'oldimage',
643 array( 'oi_deleted' => $bits ),
644 array(
645 'oi_name' => $this->row->oi_name,
646 'oi_timestamp' => $this->row->oi_timestamp,
647 'oi_deleted' => $this->getBits()
649 __METHOD__
651 return (bool)$dbw->affectedRows();
654 public function isDeleted() {
655 return $this->file->isDeleted( File::DELETED_FILE );
659 * Get the link to the file.
660 * Overridden by RevDelArchivedFileItem.
661 * @return string
663 protected function getLink() {
664 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
665 $this->file->getTimestamp(), $this->list->getUser() ) );
667 if ( !$this->isDeleted() ) {
668 # Regular files...
669 return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date );
672 # Hidden files...
673 if ( !$this->canViewContent() ) {
674 $link = $date;
675 } else {
676 $link = Linker::link(
677 SpecialPage::getTitleFor( 'Revisiondelete' ),
678 $date,
679 array(),
680 array(
681 'target' => $this->list->title->getPrefixedText(),
682 'file' => $this->file->getArchiveName(),
683 'token' => $this->list->getUser()->getEditToken(
684 $this->file->getArchiveName() )
688 return '<span class="history-deleted">' . $link . '</span>';
692 * Generate a user tool link cluster if the current user is allowed to view it
693 * @return string HTML
695 protected function getUserTools() {
696 if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
697 $uid = $this->file->getUser( 'id' );
698 $name = $this->file->getUser( 'text' );
699 $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name );
700 } else {
701 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
703 if ( $this->file->isDeleted( Revision::DELETED_USER ) ) {
704 return '<span class="history-deleted">' . $link . '</span>';
706 return $link;
710 * Wrap and format the file's comment block, if the current
711 * user is allowed to view it.
713 * @return string HTML
715 protected function getComment() {
716 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
717 $block = Linker::commentBlock( $this->file->getDescription() );
718 } else {
719 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
721 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
722 return "<span class=\"history-deleted\">$block</span>";
724 return $block;
727 public function getHTML() {
728 $data =
729 $this->list->msg( 'widthheight' )->numParams(
730 $this->file->getWidth(), $this->file->getHeight() )->text() .
731 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
733 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
734 $data . ' ' . $this->getComment() . '</li>';
737 public function getApiData( ApiResult $result ) {
738 $file = $this->file;
739 $user = $this->list->getUser();
740 $ret = array(
741 'title' => $this->list->title->getPrefixedText(),
742 'archivename' => $file->getArchiveName(),
743 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
744 'width' => $file->getWidth(),
745 'height' => $file->getHeight(),
746 'size' => $file->getSize(),
748 $ret += $file->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
749 $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
750 $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) : array();
751 if ( !$this->isDeleted() ) {
752 $ret += array(
753 'url' => $file->getUrl(),
755 } elseif ( $this->canViewContent() ) {
756 $ret += array(
757 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
758 array(
759 'target' => $this->list->title->getPrefixedText(),
760 'file' => $file->getArchiveName(),
761 'token' => $user->getEditToken( $file->getArchiveName() )
763 false, PROTO_RELATIVE
767 if ( $file->userCan( Revision::DELETED_USER, $user ) ) {
768 $ret += array(
769 'userid' => $file->user,
770 'user' => $file->user_text,
773 if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) {
774 $ret += array(
775 'comment' => $file->description,
778 return $ret;
783 * List for filearchive table items
785 class RevDelArchivedFileList extends RevDelFileList {
786 public function getType() {
787 return 'filearchive';
790 public static function getRelationType() {
791 return 'fa_id';
795 * @param DatabaseBase $db
796 * @return mixed
798 public function doQuery( $db ) {
799 $ids = array_map( 'intval', $this->ids );
800 return $db->select(
801 'filearchive',
802 ArchivedFile::selectFields(),
803 array(
804 'fa_name' => $this->title->getDBkey(),
805 'fa_id' => $ids
807 __METHOD__,
808 array( 'ORDER BY' => 'fa_id DESC' )
812 public function newItem( $row ) {
813 return new RevDelArchivedFileItem( $this, $row );
818 * Item class for a filearchive table row
820 class RevDelArchivedFileItem extends RevDelFileItem {
821 public function __construct( $list, $row ) {
822 RevDelItem::__construct( $list, $row );
823 $this->file = ArchivedFile::newFromRow( $row );
826 public function getIdField() {
827 return 'fa_id';
830 public function getTimestampField() {
831 return 'fa_timestamp';
834 public function getAuthorIdField() {
835 return 'fa_user';
838 public function getAuthorNameField() {
839 return 'fa_user_text';
842 public function getId() {
843 return $this->row->fa_id;
846 public function setBits( $bits ) {
847 $dbw = wfGetDB( DB_MASTER );
848 $dbw->update( 'filearchive',
849 array( 'fa_deleted' => $bits ),
850 array(
851 'fa_id' => $this->row->fa_id,
852 'fa_deleted' => $this->getBits(),
854 __METHOD__
856 return (bool)$dbw->affectedRows();
859 protected function getLink() {
860 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
861 $this->file->getTimestamp(), $this->list->getUser() ) );
863 # Hidden files...
864 if ( !$this->canViewContent() ) {
865 $link = $date;
866 } else {
867 $undelete = SpecialPage::getTitleFor( 'Undelete' );
868 $key = $this->file->getKey();
869 $link = Linker::link( $undelete, $date, array(),
870 array(
871 'target' => $this->list->title->getPrefixedText(),
872 'file' => $key,
873 'token' => $this->list->getUser()->getEditToken( $key )
877 if ( $this->isDeleted() ) {
878 $link = '<span class="history-deleted">' . $link . '</span>';
880 return $link;
885 * List for logging table items
887 class RevDelLogList extends RevDelList {
888 public function getType() {
889 return 'logging';
892 public static function getRelationType() {
893 return 'log_id';
896 public static function getRestriction() {
897 return 'deletelogentry';
900 public static function getRevdelConstant() {
901 return LogPage::DELETED_ACTION;
904 public static function suggestTarget( $target, array $ids ) {
905 $result = wfGetDB( DB_SLAVE )->select( 'logging',
906 'log_type',
907 array( 'log_id' => $ids ),
908 __METHOD__,
909 array( 'DISTINCT' )
911 if ( $result->numRows() == 1 ) {
912 // If there's only one type, the target can be set to include it.
913 return SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
915 return SpecialPage::getTitleFor( 'Log' );
919 * @param DatabaseBase $db
920 * @return mixed
922 public function doQuery( $db ) {
923 $ids = array_map( 'intval', $this->ids );
924 return $db->select( 'logging', array(
925 'log_id',
926 'log_type',
927 'log_action',
928 'log_timestamp',
929 'log_user',
930 'log_user_text',
931 'log_namespace',
932 'log_title',
933 'log_page',
934 'log_comment',
935 'log_params',
936 'log_deleted'
938 array( 'log_id' => $ids ),
939 __METHOD__,
940 array( 'ORDER BY' => 'log_id DESC' )
944 public function newItem( $row ) {
945 return new RevDelLogItem( $this, $row );
948 public function getSuppressBit() {
949 return Revision::DELETED_RESTRICTED;
952 public function getLogAction() {
953 return 'event';
956 public function getLogParams( $params ) {
957 return array(
958 implode( ',', $params['ids'] ),
959 "ofield={$params['oldBits']}",
960 "nfield={$params['newBits']}"
966 * Item class for a logging table row
968 class RevDelLogItem extends RevDelItem {
969 public function getIdField() {
970 return 'log_id';
973 public function getTimestampField() {
974 return 'log_timestamp';
977 public function getAuthorIdField() {
978 return 'log_user';
981 public function getAuthorNameField() {
982 return 'log_user_text';
985 public function canView() {
986 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
989 public function canViewContent() {
990 return true; // none
993 public function getBits() {
994 return $this->row->log_deleted;
997 public function setBits( $bits ) {
998 $dbw = wfGetDB( DB_MASTER );
999 $dbw->update( 'recentchanges',
1000 array(
1001 'rc_deleted' => $bits,
1002 'rc_patrolled' => 1
1004 array(
1005 'rc_logid' => $this->row->log_id,
1006 'rc_timestamp' => $this->row->log_timestamp // index
1008 __METHOD__
1010 $dbw->update( 'logging',
1011 array( 'log_deleted' => $bits ),
1012 array(
1013 'log_id' => $this->row->log_id,
1014 'log_deleted' => $this->getBits()
1016 __METHOD__
1018 return (bool)$dbw->affectedRows();
1021 public function getHTML() {
1022 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
1023 $this->row->log_timestamp, $this->list->getUser() ) );
1024 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1025 $formatter = LogFormatter::newFromRow( $this->row );
1026 $formatter->setContext( $this->list->getContext() );
1027 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
1029 // Log link for this page
1030 $loglink = Linker::link(
1031 SpecialPage::getTitleFor( 'Log' ),
1032 $this->list->msg( 'log' )->escaped(),
1033 array(),
1034 array( 'page' => $title->getPrefixedText() )
1036 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
1037 // User links and action text
1038 $action = $formatter->getActionText();
1039 // Comment
1040 $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment );
1041 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
1042 $comment = '<span class="history-deleted">' . $comment . '</span>';
1045 return "<li>$loglink $date $action $comment</li>";
1048 public function getApiData( ApiResult $result ) {
1049 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
1050 $user = $this->list->getUser();
1051 $ret = array(
1052 'id' => $logEntry->getId(),
1053 'type' => $logEntry->getType(),
1054 'action' => $logEntry->getSubtype(),
1056 $ret += $logEntry->isDeleted( LogPage::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
1057 $ret += $logEntry->isDeleted( LogPage::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
1058 $ret += $logEntry->isDeleted( LogPage::DELETED_ACTION ) ? array( 'actionhidden' => '' ) : array();
1060 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
1061 ApiQueryLogEvents::addLogParams(
1062 $result,
1063 $ret,
1064 $logEntry->getParameters(),
1065 $logEntry->getType(),
1066 $logEntry->getSubtype(),
1067 $logEntry->getTimestamp(),
1068 $logEntry->isLegacy()
1071 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
1072 $ret += array(
1073 'userid' => $this->row->log_user,
1074 'user' => $this->row->log_user_text,
1077 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
1078 $ret += array(
1079 'comment' => $this->row->log_comment,
1082 return $ret;