Merge "Make update.php file executable"
[mediawiki.git] / includes / revisiondelete / RevisionDelete.php
blob7e0e45d9f7f0f66ed623717a88e3e6f6d4eb9dec
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 int */
35 protected $currentRevId;
37 public function getType() {
38 return 'revision';
41 public static function getRelationType() {
42 return 'rev_id';
45 public static function getRestriction() {
46 return 'deleterevision';
49 public static function getRevdelConstant() {
50 return Revision::DELETED_TEXT;
53 public static function suggestTarget( $target, array $ids ) {
54 $rev = Revision::newFromId( $ids[0] );
55 return $rev ? $rev->getTitle() : $target;
58 /**
59 * @param DatabaseBase $db
60 * @return mixed
62 public function doQuery( $db ) {
63 $ids = array_map( 'intval', $this->ids );
64 $live = $db->select(
65 array( 'revision', 'page', 'user' ),
66 array_merge( Revision::selectFields(), Revision::selectUserFields() ),
67 array(
68 'rev_page' => $this->title->getArticleID(),
69 'rev_id' => $ids,
71 __METHOD__,
72 array( 'ORDER BY' => 'rev_id DESC' ),
73 array(
74 'page' => Revision::pageJoinCond(),
75 'user' => Revision::userJoinCond() )
78 if ( $live->numRows() >= count( $ids ) ) {
79 // All requested revisions are live, keeps things simple!
80 return $live;
83 // Check if any requested revisions are available fully deleted.
84 $archived = $db->select( array( 'archive' ), Revision::selectArchiveFields(),
85 array(
86 'ar_rev_id' => $ids
88 __METHOD__,
89 array( 'ORDER BY' => 'ar_rev_id DESC' )
92 if ( $archived->numRows() == 0 ) {
93 return $live;
94 } elseif ( $live->numRows() == 0 ) {
95 return $archived;
96 } else {
97 // Combine the two! Whee
98 $rows = array();
99 foreach ( $live as $row ) {
100 $rows[$row->rev_id] = $row;
102 foreach ( $archived as $row ) {
103 $rows[$row->ar_rev_id] = $row;
105 krsort( $rows );
106 return new FakeResultWrapper( array_values( $rows ) );
110 public function newItem( $row ) {
111 if ( isset( $row->rev_id ) ) {
112 return new RevDelRevisionItem( $this, $row );
113 } elseif ( isset( $row->ar_rev_id ) ) {
114 return new RevDelArchivedRevisionItem( $this, $row );
115 } else {
116 // This shouldn't happen. :)
117 throw new MWException( 'Invalid row type in RevDelRevisionList' );
121 public function getCurrent() {
122 if ( is_null( $this->currentRevId ) ) {
123 $dbw = wfGetDB( DB_MASTER );
124 $this->currentRevId = $dbw->selectField(
125 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
127 return $this->currentRevId;
130 public function getSuppressBit() {
131 return Revision::DELETED_RESTRICTED;
134 public function doPreCommitUpdates() {
135 $this->title->invalidateCache();
136 return Status::newGood();
139 public function doPostCommitUpdates() {
140 $this->title->purgeSquid();
141 // Extensions that require referencing previous revisions may need this
142 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title ) );
143 return Status::newGood();
148 * Item class for a live revision table row
150 class RevDelRevisionItem extends RevDelItem {
151 protected $revision;
153 public function __construct( $list, $row ) {
154 parent::__construct( $list, $row );
155 $this->revision = new Revision( $row );
158 public function getIdField() {
159 return 'rev_id';
162 public function getTimestampField() {
163 return 'rev_timestamp';
166 public function getAuthorIdField() {
167 return 'rev_user';
170 public function getAuthorNameField() {
171 return 'rev_user_text';
174 public function canView() {
175 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
178 public function canViewContent() {
179 return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
182 public function getBits() {
183 return $this->revision->getVisibility();
186 public function setBits( $bits ) {
187 $dbw = wfGetDB( DB_MASTER );
188 // Update revision table
189 $dbw->update( 'revision',
190 array( 'rev_deleted' => $bits ),
191 array(
192 'rev_id' => $this->revision->getId(),
193 'rev_page' => $this->revision->getPage(),
194 'rev_deleted' => $this->getBits()
196 __METHOD__
198 if ( !$dbw->affectedRows() ) {
199 // Concurrent fail!
200 return false;
202 // Update recentchanges table
203 $dbw->update( 'recentchanges',
204 array(
205 'rc_deleted' => $bits,
206 'rc_patrolled' => 1
208 array(
209 'rc_this_oldid' => $this->revision->getId(), // condition
210 // non-unique timestamp index
211 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
213 __METHOD__
215 return true;
218 public function isDeleted() {
219 return $this->revision->isDeleted( Revision::DELETED_TEXT );
222 public function isHideCurrentOp( $newBits ) {
223 return ( $newBits & Revision::DELETED_TEXT )
224 && $this->list->getCurrent() == $this->getId();
228 * Get the HTML link to the revision text.
229 * Overridden by RevDelArchiveItem.
230 * @return string
232 protected function getRevisionLink() {
233 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
234 $this->revision->getTimestamp(), $this->list->getUser() ) );
236 if ( $this->isDeleted() && !$this->canViewContent() ) {
237 return $date;
239 return Linker::linkKnown(
240 $this->list->title,
241 $date,
242 array(),
243 array(
244 'oldid' => $this->revision->getId(),
245 'unhide' => 1
251 * Get the HTML link to the diff.
252 * Overridden by RevDelArchiveItem
253 * @return string
255 protected function getDiffLink() {
256 if ( $this->isDeleted() && !$this->canViewContent() ) {
257 return $this->list->msg( 'diff' )->escaped();
258 } else {
259 return Linker::linkKnown(
260 $this->list->title,
261 $this->list->msg( 'diff' )->escaped(),
262 array(),
263 array(
264 'diff' => $this->revision->getId(),
265 'oldid' => 'prev',
266 'unhide' => 1
272 public function getHTML() {
273 $difflink = $this->list->msg( 'parentheses' )
274 ->rawParams( $this->getDiffLink() )->escaped();
275 $revlink = $this->getRevisionLink();
276 $userlink = Linker::revUserLink( $this->revision );
277 $comment = Linker::revComment( $this->revision );
278 if ( $this->isDeleted() ) {
279 $revlink = "<span class=\"history-deleted\">$revlink</span>";
281 return "<li>$difflink $revlink $userlink $comment</li>";
284 public function getApiData( ApiResult $result ) {
285 $rev = $this->revision;
286 $user = $this->list->getUser();
287 $ret = array(
288 'id' => $rev->getId(),
289 'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
291 $ret += $rev->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
292 $ret += $rev->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
293 $ret += $rev->isDeleted( Revision::DELETED_TEXT ) ? array( 'texthidden' => '' ) : array();
294 if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
295 $ret += array(
296 'userid' => $rev->getUser( Revision::FOR_THIS_USER ),
297 'user' => $rev->getUserText( Revision::FOR_THIS_USER ),
300 if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
301 $ret += array(
302 'comment' => $rev->getComment( Revision::FOR_THIS_USER ),
305 return $ret;
310 * List for archive table items, i.e. revisions deleted via action=delete
312 class RevDelArchiveList extends RevDelRevisionList {
313 public function getType() {
314 return 'archive';
317 public static function getRelationType() {
318 return 'ar_timestamp';
322 * @param DatabaseBase $db
323 * @return mixed
325 public function doQuery( $db ) {
326 $timestamps = array();
327 foreach ( $this->ids as $id ) {
328 $timestamps[] = $db->timestamp( $id );
330 return $db->select( 'archive', Revision::selectArchiveFields(),
331 array(
332 'ar_namespace' => $this->title->getNamespace(),
333 'ar_title' => $this->title->getDBkey(),
334 'ar_timestamp' => $timestamps
336 __METHOD__,
337 array( 'ORDER BY' => 'ar_timestamp DESC' )
341 public function newItem( $row ) {
342 return new RevDelArchiveItem( $this, $row );
345 public function doPreCommitUpdates() {
346 return Status::newGood();
349 public function doPostCommitUpdates() {
350 return Status::newGood();
355 * Item class for a archive table row
357 class RevDelArchiveItem extends RevDelRevisionItem {
358 public function __construct( $list, $row ) {
359 RevDelItem::__construct( $list, $row );
360 $this->revision = Revision::newFromArchiveRow( $row,
361 array( 'page' => $this->list->title->getArticleID() ) );
364 public function getIdField() {
365 return 'ar_timestamp';
368 public function getTimestampField() {
369 return 'ar_timestamp';
372 public function getAuthorIdField() {
373 return 'ar_user';
376 public function getAuthorNameField() {
377 return 'ar_user_text';
380 public function getId() {
381 # Convert DB timestamp to MW timestamp
382 return $this->revision->getTimestamp();
385 public function setBits( $bits ) {
386 $dbw = wfGetDB( DB_MASTER );
387 $dbw->update( 'archive',
388 array( 'ar_deleted' => $bits ),
389 array(
390 'ar_namespace' => $this->list->title->getNamespace(),
391 'ar_title' => $this->list->title->getDBkey(),
392 // use timestamp for index
393 'ar_timestamp' => $this->row->ar_timestamp,
394 'ar_rev_id' => $this->row->ar_rev_id,
395 'ar_deleted' => $this->getBits()
397 __METHOD__ );
398 return (bool)$dbw->affectedRows();
401 protected function getRevisionLink() {
402 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
403 $this->revision->getTimestamp(), $this->list->getUser() ) );
405 if ( $this->isDeleted() && !$this->canViewContent() ) {
406 return $date;
409 return Linker::link(
410 SpecialPage::getTitleFor( 'Undelete' ),
411 $date,
412 array(),
413 array(
414 'target' => $this->list->title->getPrefixedText(),
415 'timestamp' => $this->revision->getTimestamp()
420 protected function getDiffLink() {
421 if ( $this->isDeleted() && !$this->canViewContent() ) {
422 return $this->list->msg( 'diff' )->escaped();
425 return Linker::link(
426 SpecialPage::getTitleFor( 'Undelete' ),
427 $this->list->msg( 'diff' )->escaped(),
428 array(),
429 array(
430 'target' => $this->list->title->getPrefixedText(),
431 'diff' => 'prev',
432 'timestamp' => $this->revision->getTimestamp()
439 * Item class for a archive table row by ar_rev_id -- actually
440 * used via RevDelRevisionList.
442 class RevDelArchivedRevisionItem extends RevDelArchiveItem {
443 public function __construct( $list, $row ) {
444 RevDelItem::__construct( $list, $row );
446 $this->revision = Revision::newFromArchiveRow( $row,
447 array( 'page' => $this->list->title->getArticleID() ) );
450 public function getIdField() {
451 return 'ar_rev_id';
454 public function getId() {
455 return $this->revision->getId();
458 public function setBits( $bits ) {
459 $dbw = wfGetDB( DB_MASTER );
460 $dbw->update( 'archive',
461 array( 'ar_deleted' => $bits ),
462 array( 'ar_rev_id' => $this->row->ar_rev_id,
463 'ar_deleted' => $this->getBits()
465 __METHOD__ );
466 return (bool)$dbw->affectedRows();
471 * List for oldimage table items
473 class RevDelFileList extends RevDelList {
474 /** @var array */
475 protected $storeBatch;
477 /** @var array */
478 protected $deleteBatch;
480 /** @var array */
481 protected $cleanupBatch;
483 public function getType() {
484 return 'oldimage';
487 public static function getRelationType() {
488 return 'oi_archive_name';
491 public static function getRestriction() {
492 return 'deleterevision';
495 public static function getRevdelConstant() {
496 return File::DELETED_FILE;
500 * @param DatabaseBase $db
501 * @return mixed
503 public function doQuery( $db ) {
504 $archiveNames = array();
505 foreach ( $this->ids as $timestamp ) {
506 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
508 return $db->select(
509 'oldimage',
510 OldLocalFile::selectFields(),
511 array(
512 'oi_name' => $this->title->getDBkey(),
513 'oi_archive_name' => $archiveNames
515 __METHOD__,
516 array( 'ORDER BY' => 'oi_timestamp DESC' )
520 public function newItem( $row ) {
521 return new RevDelFileItem( $this, $row );
524 public function clearFileOps() {
525 $this->deleteBatch = array();
526 $this->storeBatch = array();
527 $this->cleanupBatch = array();
530 public function doPreCommitUpdates() {
531 $status = Status::newGood();
532 $repo = RepoGroup::singleton()->getLocalRepo();
533 if ( $this->storeBatch ) {
534 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
536 if ( !$status->isOK() ) {
537 return $status;
539 if ( $this->deleteBatch ) {
540 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
542 if ( !$status->isOK() ) {
543 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
544 // modified (but destined for rollback) causes data loss
545 return $status;
547 if ( $this->cleanupBatch ) {
548 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
550 return $status;
553 public function doPostCommitUpdates() {
554 global $wgUseSquid;
555 $file = wfLocalFile( $this->title );
556 $file->purgeCache();
557 $file->purgeDescription();
558 $purgeUrls = array();
559 foreach ( $this->ids as $timestamp ) {
560 $archiveName = $timestamp . '!' . $this->title->getDBkey();
561 $file->purgeOldThumbnails( $archiveName );
562 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
564 if ( $wgUseSquid ) {
565 // purge full images from cache
566 SquidUpdate::purge( $purgeUrls );
568 return Status::newGood();
571 public function getSuppressBit() {
572 return File::DELETED_RESTRICTED;
577 * Item class for an oldimage table row
579 class RevDelFileItem extends RevDelItem {
580 /** @var File */
581 protected $file;
583 public function __construct( $list, $row ) {
584 parent::__construct( $list, $row );
585 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
588 public function getIdField() {
589 return 'oi_archive_name';
592 public function getTimestampField() {
593 return 'oi_timestamp';
596 public function getAuthorIdField() {
597 return 'oi_user';
600 public function getAuthorNameField() {
601 return 'oi_user_text';
604 public function getId() {
605 $parts = explode( '!', $this->row->oi_archive_name );
606 return $parts[0];
609 public function canView() {
610 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
613 public function canViewContent() {
614 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
617 public function getBits() {
618 return $this->file->getVisibility();
621 public function setBits( $bits ) {
622 # Queue the file op
623 # @todo FIXME: Move to LocalFile.php
624 if ( $this->isDeleted() ) {
625 if ( $bits & File::DELETED_FILE ) {
626 # Still deleted
627 } else {
628 # Newly undeleted
629 $key = $this->file->getStorageKey();
630 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
631 $this->list->storeBatch[] = array(
632 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
633 'public',
634 $this->file->getRel()
636 $this->list->cleanupBatch[] = $key;
638 } elseif ( $bits & File::DELETED_FILE ) {
639 # Newly deleted
640 $key = $this->file->getStorageKey();
641 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
642 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
645 # Do the database operations
646 $dbw = wfGetDB( DB_MASTER );
647 $dbw->update( 'oldimage',
648 array( 'oi_deleted' => $bits ),
649 array(
650 'oi_name' => $this->row->oi_name,
651 'oi_timestamp' => $this->row->oi_timestamp,
652 'oi_deleted' => $this->getBits()
654 __METHOD__
656 return (bool)$dbw->affectedRows();
659 public function isDeleted() {
660 return $this->file->isDeleted( File::DELETED_FILE );
664 * Get the link to the file.
665 * Overridden by RevDelArchivedFileItem.
666 * @return string
668 protected function getLink() {
669 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
670 $this->file->getTimestamp(), $this->list->getUser() ) );
672 if ( !$this->isDeleted() ) {
673 # Regular files...
674 return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date );
677 # Hidden files...
678 if ( !$this->canViewContent() ) {
679 $link = $date;
680 } else {
681 $link = Linker::link(
682 SpecialPage::getTitleFor( 'Revisiondelete' ),
683 $date,
684 array(),
685 array(
686 'target' => $this->list->title->getPrefixedText(),
687 'file' => $this->file->getArchiveName(),
688 'token' => $this->list->getUser()->getEditToken(
689 $this->file->getArchiveName() )
693 return '<span class="history-deleted">' . $link . '</span>';
697 * Generate a user tool link cluster if the current user is allowed to view it
698 * @return string HTML
700 protected function getUserTools() {
701 if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
702 $uid = $this->file->getUser( 'id' );
703 $name = $this->file->getUser( 'text' );
704 $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name );
705 } else {
706 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
708 if ( $this->file->isDeleted( Revision::DELETED_USER ) ) {
709 return '<span class="history-deleted">' . $link . '</span>';
711 return $link;
715 * Wrap and format the file's comment block, if the current
716 * user is allowed to view it.
718 * @return string HTML
720 protected function getComment() {
721 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
722 $block = Linker::commentBlock( $this->file->getDescription() );
723 } else {
724 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
726 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
727 return "<span class=\"history-deleted\">$block</span>";
729 return $block;
732 public function getHTML() {
733 $data =
734 $this->list->msg( 'widthheight' )->numParams(
735 $this->file->getWidth(), $this->file->getHeight() )->text() .
736 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
738 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
739 $data . ' ' . $this->getComment() . '</li>';
742 public function getApiData( ApiResult $result ) {
743 $file = $this->file;
744 $user = $this->list->getUser();
745 $ret = array(
746 'title' => $this->list->title->getPrefixedText(),
747 'archivename' => $file->getArchiveName(),
748 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
749 'width' => $file->getWidth(),
750 'height' => $file->getHeight(),
751 'size' => $file->getSize(),
753 $ret += $file->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
754 $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
755 $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) : array();
756 if ( !$this->isDeleted() ) {
757 $ret += array(
758 'url' => $file->getUrl(),
760 } elseif ( $this->canViewContent() ) {
761 $ret += array(
762 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
763 array(
764 'target' => $this->list->title->getPrefixedText(),
765 'file' => $file->getArchiveName(),
766 'token' => $user->getEditToken( $file->getArchiveName() )
768 false, PROTO_RELATIVE
772 if ( $file->userCan( Revision::DELETED_USER, $user ) ) {
773 $ret += array(
774 'userid' => $file->user,
775 'user' => $file->user_text,
778 if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) {
779 $ret += array(
780 'comment' => $file->description,
783 return $ret;
788 * List for filearchive table items
790 class RevDelArchivedFileList extends RevDelFileList {
791 public function getType() {
792 return 'filearchive';
795 public static function getRelationType() {
796 return 'fa_id';
800 * @param DatabaseBase $db
801 * @return mixed
803 public function doQuery( $db ) {
804 $ids = array_map( 'intval', $this->ids );
805 return $db->select(
806 'filearchive',
807 ArchivedFile::selectFields(),
808 array(
809 'fa_name' => $this->title->getDBkey(),
810 'fa_id' => $ids
812 __METHOD__,
813 array( 'ORDER BY' => 'fa_id DESC' )
817 public function newItem( $row ) {
818 return new RevDelArchivedFileItem( $this, $row );
823 * Item class for a filearchive table row
825 class RevDelArchivedFileItem extends RevDelFileItem {
826 public function __construct( $list, $row ) {
827 RevDelItem::__construct( $list, $row );
828 $this->file = ArchivedFile::newFromRow( $row );
831 public function getIdField() {
832 return 'fa_id';
835 public function getTimestampField() {
836 return 'fa_timestamp';
839 public function getAuthorIdField() {
840 return 'fa_user';
843 public function getAuthorNameField() {
844 return 'fa_user_text';
847 public function getId() {
848 return $this->row->fa_id;
851 public function setBits( $bits ) {
852 $dbw = wfGetDB( DB_MASTER );
853 $dbw->update( 'filearchive',
854 array( 'fa_deleted' => $bits ),
855 array(
856 'fa_id' => $this->row->fa_id,
857 'fa_deleted' => $this->getBits(),
859 __METHOD__
861 return (bool)$dbw->affectedRows();
864 protected function getLink() {
865 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
866 $this->file->getTimestamp(), $this->list->getUser() ) );
868 # Hidden files...
869 if ( !$this->canViewContent() ) {
870 $link = $date;
871 } else {
872 $undelete = SpecialPage::getTitleFor( 'Undelete' );
873 $key = $this->file->getKey();
874 $link = Linker::link( $undelete, $date, array(),
875 array(
876 'target' => $this->list->title->getPrefixedText(),
877 'file' => $key,
878 'token' => $this->list->getUser()->getEditToken( $key )
882 if ( $this->isDeleted() ) {
883 $link = '<span class="history-deleted">' . $link . '</span>';
885 return $link;
890 * List for logging table items
892 class RevDelLogList extends RevDelList {
893 public function getType() {
894 return 'logging';
897 public static function getRelationType() {
898 return 'log_id';
901 public static function getRestriction() {
902 return 'deletelogentry';
905 public static function getRevdelConstant() {
906 return LogPage::DELETED_ACTION;
909 public static function suggestTarget( $target, array $ids ) {
910 $result = wfGetDB( DB_SLAVE )->select( 'logging',
911 'log_type',
912 array( 'log_id' => $ids ),
913 __METHOD__,
914 array( 'DISTINCT' )
916 if ( $result->numRows() == 1 ) {
917 // If there's only one type, the target can be set to include it.
918 return SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
920 return SpecialPage::getTitleFor( 'Log' );
924 * @param DatabaseBase $db
925 * @return mixed
927 public function doQuery( $db ) {
928 $ids = array_map( 'intval', $this->ids );
929 return $db->select( 'logging', array(
930 'log_id',
931 'log_type',
932 'log_action',
933 'log_timestamp',
934 'log_user',
935 'log_user_text',
936 'log_namespace',
937 'log_title',
938 'log_page',
939 'log_comment',
940 'log_params',
941 'log_deleted'
943 array( 'log_id' => $ids ),
944 __METHOD__,
945 array( 'ORDER BY' => 'log_id DESC' )
949 public function newItem( $row ) {
950 return new RevDelLogItem( $this, $row );
953 public function getSuppressBit() {
954 return Revision::DELETED_RESTRICTED;
957 public function getLogAction() {
958 return 'event';
961 public function getLogParams( $params ) {
962 return array(
963 implode( ',', $params['ids'] ),
964 "ofield={$params['oldBits']}",
965 "nfield={$params['newBits']}"
971 * Item class for a logging table row
973 class RevDelLogItem extends RevDelItem {
974 public function getIdField() {
975 return 'log_id';
978 public function getTimestampField() {
979 return 'log_timestamp';
982 public function getAuthorIdField() {
983 return 'log_user';
986 public function getAuthorNameField() {
987 return 'log_user_text';
990 public function canView() {
991 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
994 public function canViewContent() {
995 return true; // none
998 public function getBits() {
999 return $this->row->log_deleted;
1002 public function setBits( $bits ) {
1003 $dbw = wfGetDB( DB_MASTER );
1004 $dbw->update( 'recentchanges',
1005 array(
1006 'rc_deleted' => $bits,
1007 'rc_patrolled' => 1
1009 array(
1010 'rc_logid' => $this->row->log_id,
1011 'rc_timestamp' => $this->row->log_timestamp // index
1013 __METHOD__
1015 $dbw->update( 'logging',
1016 array( 'log_deleted' => $bits ),
1017 array(
1018 'log_id' => $this->row->log_id,
1019 'log_deleted' => $this->getBits()
1021 __METHOD__
1023 return (bool)$dbw->affectedRows();
1026 public function getHTML() {
1027 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
1028 $this->row->log_timestamp, $this->list->getUser() ) );
1029 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1030 $formatter = LogFormatter::newFromRow( $this->row );
1031 $formatter->setContext( $this->list->getContext() );
1032 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
1034 // Log link for this page
1035 $loglink = Linker::link(
1036 SpecialPage::getTitleFor( 'Log' ),
1037 $this->list->msg( 'log' )->escaped(),
1038 array(),
1039 array( 'page' => $title->getPrefixedText() )
1041 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
1042 // User links and action text
1043 $action = $formatter->getActionText();
1044 // Comment
1045 $comment = $this->list->getLanguage()->getDirMark()
1046 . Linker::commentBlock( $this->row->log_comment );
1048 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
1049 $comment = '<span class="history-deleted">' . $comment . '</span>';
1052 return "<li>$loglink $date $action $comment</li>";
1055 public function getApiData( ApiResult $result ) {
1056 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
1057 $user = $this->list->getUser();
1058 $ret = array(
1059 'id' => $logEntry->getId(),
1060 'type' => $logEntry->getType(),
1061 'action' => $logEntry->getSubtype(),
1063 $ret += $logEntry->isDeleted( LogPage::DELETED_USER )
1064 ? array( 'userhidden' => '' )
1065 : array();
1066 $ret += $logEntry->isDeleted( LogPage::DELETED_COMMENT )
1067 ? array( 'commenthidden' => '' )
1068 : array();
1069 $ret += $logEntry->isDeleted( LogPage::DELETED_ACTION )
1070 ? array( 'actionhidden' => '' )
1071 : array();
1073 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
1074 ApiQueryLogEvents::addLogParams(
1075 $result,
1076 $ret,
1077 $logEntry->getParameters(),
1078 $logEntry->getType(),
1079 $logEntry->getSubtype(),
1080 $logEntry->getTimestamp(),
1081 $logEntry->isLegacy()
1084 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
1085 $ret += array(
1086 'userid' => $this->row->log_user,
1087 'user' => $this->row->log_user_text,
1090 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
1091 $ret += array(
1092 'comment' => $this->row->log_comment,
1095 return $ret;