Merge "Revert "Add .gitignore to the /skins directory""
[lhc/web/wiklou.git] / includes / revisiondelete / RevisionDelete.php
1 <?php
2 /**
3 * Base implementations for deletable items.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup RevisionDelete
22 */
23
24 /**
25 * List for revision table items
26 *
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.
30 *
31 * See RevDel_RevisionItem and RevDel_ArchivedRevisionItem for items.
32 */
33 class RevDel_RevisionList extends RevDel_List {
34 var $currentRevId;
35
36 public function getType() {
37 return 'revision';
38 }
39
40 public static function getRelationType() {
41 return 'rev_id';
42 }
43
44 public static function getRestriction() {
45 return 'deleterevision';
46 }
47
48 public static function getRevdelConstant() {
49 return Revision::DELETED_TEXT;
50 }
51
52 public static function suggestTarget( $target, array $ids ) {
53 $rev = Revision::newFromId( $ids[0] );
54 return $rev ? $rev->getTitle() : $target;
55 }
56
57 /**
58 * @param $db DatabaseBase
59 * @return mixed
60 */
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,
69 ),
70 __METHOD__,
71 array( 'ORDER BY' => 'rev_id DESC' ),
72 array(
73 'page' => Revision::pageJoinCond(),
74 'user' => Revision::userJoinCond() )
75 );
76
77 if ( $live->numRows() >= count( $ids ) ) {
78 // All requested revisions are live, keeps things simple!
79 return $live;
80 }
81
82 // Check if any requested revisions are available fully deleted.
83 $archived = $db->select( array( 'archive' ), '*',
84 array(
85 'ar_rev_id' => $ids
86 ),
87 __METHOD__,
88 array( 'ORDER BY' => 'ar_rev_id DESC' )
89 );
90
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;
100 }
101 foreach ( $archived as $row ) {
102 $rows[$row->ar_rev_id] = $row;
103 }
104 krsort( $rows );
105 return new FakeResultWrapper( array_values( $rows ) );
106 }
107 }
108
109 public function newItem( $row ) {
110 if ( isset( $row->rev_id ) ) {
111 return new RevDel_RevisionItem( $this, $row );
112 } elseif ( isset( $row->ar_rev_id ) ) {
113 return new RevDel_ArchivedRevisionItem( $this, $row );
114 } else {
115 // This shouldn't happen. :)
116 throw new MWException( 'Invalid row type in RevDel_RevisionList' );
117 }
118 }
119
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__ );
125 }
126 return $this->currentRevId;
127 }
128
129 public function getSuppressBit() {
130 return Revision::DELETED_RESTRICTED;
131 }
132
133 public function doPreCommitUpdates() {
134 $this->title->invalidateCache();
135 return Status::newGood();
136 }
137
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();
143 }
144 }
145
146 /**
147 * Item class for a live revision table row
148 */
149 class RevDel_RevisionItem extends RevDel_Item {
150 var $revision;
151
152 public function __construct( $list, $row ) {
153 parent::__construct( $list, $row );
154 $this->revision = new Revision( $row );
155 }
156
157 public function getIdField() {
158 return 'rev_id';
159 }
160
161 public function getTimestampField() {
162 return 'rev_timestamp';
163 }
164
165 public function getAuthorIdField() {
166 return 'rev_user';
167 }
168
169 public function getAuthorNameField() {
170 return 'user_name'; // see Revision::selectUserFields()
171 }
172
173 public function canView() {
174 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
175 }
176
177 public function canViewContent() {
178 return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
179 }
180
181 public function getBits() {
182 return $this->revision->getVisibility();
183 }
184
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()
194 ),
195 __METHOD__
196 );
197 if ( !$dbw->affectedRows() ) {
198 // Concurrent fail!
199 return false;
200 }
201 // Update recentchanges table
202 $dbw->update( 'recentchanges',
203 array(
204 'rc_deleted' => $bits,
205 'rc_patrolled' => 1
206 ),
207 array(
208 'rc_this_oldid' => $this->revision->getId(), // condition
209 // non-unique timestamp index
210 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
211 ),
212 __METHOD__
213 );
214 return true;
215 }
216
217 public function isDeleted() {
218 return $this->revision->isDeleted( Revision::DELETED_TEXT );
219 }
220
221 public function isHideCurrentOp( $newBits ) {
222 return ( $newBits & Revision::DELETED_TEXT )
223 && $this->list->getCurrent() == $this->getId();
224 }
225
226 /**
227 * Get the HTML link to the revision text.
228 * Overridden by RevDel_ArchiveItem.
229 * @return string
230 */
231 protected function getRevisionLink() {
232 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
233 $this->revision->getTimestamp(), $this->list->getUser() ) );
234
235 if ( $this->isDeleted() && !$this->canViewContent() ) {
236 return $date;
237 }
238 return Linker::linkKnown(
239 $this->list->title,
240 $date,
241 array(),
242 array(
243 'oldid' => $this->revision->getId(),
244 'unhide' => 1
245 )
246 );
247 }
248
249 /**
250 * Get the HTML link to the diff.
251 * Overridden by RevDel_ArchiveItem
252 * @return string
253 */
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
266 )
267 );
268 }
269 }
270
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>";
279 }
280 return "<li>$difflink $revlink $userlink $comment</li>";
281 }
282 }
283
284 /**
285 * List for archive table items, i.e. revisions deleted via action=delete
286 */
287 class RevDel_ArchiveList extends RevDel_RevisionList {
288 public function getType() {
289 return 'archive';
290 }
291
292 public static function getRelationType() {
293 return 'ar_timestamp';
294 }
295
296 /**
297 * @param $db DatabaseBase
298 * @return mixed
299 */
300 public function doQuery( $db ) {
301 $timestamps = array();
302 foreach ( $this->ids as $id ) {
303 $timestamps[] = $db->timestamp( $id );
304 }
305 return $db->select( 'archive', '*',
306 array(
307 'ar_namespace' => $this->title->getNamespace(),
308 'ar_title' => $this->title->getDBkey(),
309 'ar_timestamp' => $timestamps
310 ),
311 __METHOD__,
312 array( 'ORDER BY' => 'ar_timestamp DESC' )
313 );
314 }
315
316 public function newItem( $row ) {
317 return new RevDel_ArchiveItem( $this, $row );
318 }
319
320 public function doPreCommitUpdates() {
321 return Status::newGood();
322 }
323
324 public function doPostCommitUpdates() {
325 return Status::newGood();
326 }
327 }
328
329 /**
330 * Item class for a archive table row
331 */
332 class RevDel_ArchiveItem extends RevDel_RevisionItem {
333 public function __construct( $list, $row ) {
334 RevDel_Item::__construct( $list, $row );
335 $this->revision = Revision::newFromArchiveRow( $row,
336 array( 'page' => $this->list->title->getArticleID() ) );
337 }
338
339 public function getIdField() {
340 return 'ar_timestamp';
341 }
342
343 public function getTimestampField() {
344 return 'ar_timestamp';
345 }
346
347 public function getAuthorIdField() {
348 return 'ar_user';
349 }
350
351 public function getAuthorNameField() {
352 return 'ar_user_text';
353 }
354
355 public function getId() {
356 # Convert DB timestamp to MW timestamp
357 return $this->revision->getTimestamp();
358 }
359
360 public function setBits( $bits ) {
361 $dbw = wfGetDB( DB_MASTER );
362 $dbw->update( 'archive',
363 array( 'ar_deleted' => $bits ),
364 array(
365 'ar_namespace' => $this->list->title->getNamespace(),
366 'ar_title' => $this->list->title->getDBkey(),
367 // use timestamp for index
368 'ar_timestamp' => $this->row->ar_timestamp,
369 'ar_rev_id' => $this->row->ar_rev_id,
370 'ar_deleted' => $this->getBits()
371 ),
372 __METHOD__ );
373 return (bool)$dbw->affectedRows();
374 }
375
376 protected function getRevisionLink() {
377 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
378 $this->revision->getTimestamp(), $this->list->getUser() ) );
379
380 if ( $this->isDeleted() && !$this->canViewContent() ) {
381 return $date;
382 }
383
384 return Linker::link(
385 SpecialPage::getTitleFor( 'Undelete' ),
386 $date,
387 array(),
388 array(
389 'target' => $this->list->title->getPrefixedText(),
390 'timestamp' => $this->revision->getTimestamp()
391 )
392 );
393 }
394
395 protected function getDiffLink() {
396 if ( $this->isDeleted() && !$this->canViewContent() ) {
397 return $this->list->msg( 'diff' )->escaped();
398 }
399
400 return Linker::link(
401 SpecialPage::getTitleFor( 'Undelete' ),
402 $this->list->msg( 'diff' )->escaped(),
403 array(),
404 array(
405 'target' => $this->list->title->getPrefixedText(),
406 'diff' => 'prev',
407 'timestamp' => $this->revision->getTimestamp()
408 )
409 );
410 }
411 }
412
413 /**
414 * Item class for a archive table row by ar_rev_id -- actually
415 * used via RevDel_RevisionList.
416 */
417 class RevDel_ArchivedRevisionItem extends RevDel_ArchiveItem {
418 public function __construct( $list, $row ) {
419 RevDel_Item::__construct( $list, $row );
420
421 $this->revision = Revision::newFromArchiveRow( $row,
422 array( 'page' => $this->list->title->getArticleID() ) );
423 }
424
425 public function getIdField() {
426 return 'ar_rev_id';
427 }
428
429 public function getId() {
430 return $this->revision->getId();
431 }
432
433 public function setBits( $bits ) {
434 $dbw = wfGetDB( DB_MASTER );
435 $dbw->update( 'archive',
436 array( 'ar_deleted' => $bits ),
437 array( 'ar_rev_id' => $this->row->ar_rev_id,
438 'ar_deleted' => $this->getBits()
439 ),
440 __METHOD__ );
441 return (bool)$dbw->affectedRows();
442 }
443 }
444
445 /**
446 * List for oldimage table items
447 */
448 class RevDel_FileList extends RevDel_List {
449 public function getType() {
450 return 'oldimage';
451 }
452
453 public static function getRelationType() {
454 return 'oi_archive_name';
455 }
456
457 public static function getRestriction() {
458 return 'deleterevision';
459 }
460
461 public static function getRevdelConstant() {
462 return File::DELETED_FILE;
463 }
464
465 var $storeBatch, $deleteBatch, $cleanupBatch;
466
467 /**
468 * @param $db DatabaseBase
469 * @return mixed
470 */
471 public function doQuery( $db ) {
472 $archiveNames = array();
473 foreach ( $this->ids as $timestamp ) {
474 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
475 }
476 return $db->select(
477 'oldimage',
478 OldLocalFile::selectFields(),
479 array(
480 'oi_name' => $this->title->getDBkey(),
481 'oi_archive_name' => $archiveNames
482 ),
483 __METHOD__,
484 array( 'ORDER BY' => 'oi_timestamp DESC' )
485 );
486 }
487
488 public function newItem( $row ) {
489 return new RevDel_FileItem( $this, $row );
490 }
491
492 public function clearFileOps() {
493 $this->deleteBatch = array();
494 $this->storeBatch = array();
495 $this->cleanupBatch = array();
496 }
497
498 public function doPreCommitUpdates() {
499 $status = Status::newGood();
500 $repo = RepoGroup::singleton()->getLocalRepo();
501 if ( $this->storeBatch ) {
502 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
503 }
504 if ( !$status->isOK() ) {
505 return $status;
506 }
507 if ( $this->deleteBatch ) {
508 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
509 }
510 if ( !$status->isOK() ) {
511 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
512 // modified (but destined for rollback) causes data loss
513 return $status;
514 }
515 if ( $this->cleanupBatch ) {
516 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
517 }
518 return $status;
519 }
520
521 public function doPostCommitUpdates() {
522 global $wgUseSquid;
523 $file = wfLocalFile( $this->title );
524 $file->purgeCache();
525 $file->purgeDescription();
526 $purgeUrls = array();
527 foreach ( $this->ids as $timestamp ) {
528 $archiveName = $timestamp . '!' . $this->title->getDBkey();
529 $file->purgeOldThumbnails( $archiveName );
530 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
531 }
532 if ( $wgUseSquid ) {
533 // purge full images from cache
534 SquidUpdate::purge( $purgeUrls );
535 }
536 return Status::newGood();
537 }
538
539 public function getSuppressBit() {
540 return File::DELETED_RESTRICTED;
541 }
542 }
543
544 /**
545 * Item class for an oldimage table row
546 */
547 class RevDel_FileItem extends RevDel_Item {
548
549 /**
550 * @var File
551 */
552 var $file;
553
554 public function __construct( $list, $row ) {
555 parent::__construct( $list, $row );
556 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
557 }
558
559 public function getIdField() {
560 return 'oi_archive_name';
561 }
562
563 public function getTimestampField() {
564 return 'oi_timestamp';
565 }
566
567 public function getAuthorIdField() {
568 return 'oi_user';
569 }
570
571 public function getAuthorNameField() {
572 return 'oi_user_text';
573 }
574
575 public function getId() {
576 $parts = explode( '!', $this->row->oi_archive_name );
577 return $parts[0];
578 }
579
580 public function canView() {
581 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
582 }
583
584 public function canViewContent() {
585 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
586 }
587
588 public function getBits() {
589 return $this->file->getVisibility();
590 }
591
592 public function setBits( $bits ) {
593 # Queue the file op
594 # @todo FIXME: Move to LocalFile.php
595 if ( $this->isDeleted() ) {
596 if ( $bits & File::DELETED_FILE ) {
597 # Still deleted
598 } else {
599 # Newly undeleted
600 $key = $this->file->getStorageKey();
601 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
602 $this->list->storeBatch[] = array(
603 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
604 'public',
605 $this->file->getRel()
606 );
607 $this->list->cleanupBatch[] = $key;
608 }
609 } elseif ( $bits & File::DELETED_FILE ) {
610 # Newly deleted
611 $key = $this->file->getStorageKey();
612 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
613 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
614 }
615
616 # Do the database operations
617 $dbw = wfGetDB( DB_MASTER );
618 $dbw->update( 'oldimage',
619 array( 'oi_deleted' => $bits ),
620 array(
621 'oi_name' => $this->row->oi_name,
622 'oi_timestamp' => $this->row->oi_timestamp,
623 'oi_deleted' => $this->getBits()
624 ),
625 __METHOD__
626 );
627 return (bool)$dbw->affectedRows();
628 }
629
630 public function isDeleted() {
631 return $this->file->isDeleted( File::DELETED_FILE );
632 }
633
634 /**
635 * Get the link to the file.
636 * Overridden by RevDel_ArchivedFileItem.
637 * @return string
638 */
639 protected function getLink() {
640 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
641 $this->file->getTimestamp(), $this->list->getUser() ) );
642
643 if ( !$this->isDeleted() ) {
644 # Regular files...
645 return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date );
646 }
647
648 # Hidden files...
649 if ( !$this->canViewContent() ) {
650 $link = $date;
651 } else {
652 $link = Linker::link(
653 SpecialPage::getTitleFor( 'Revisiondelete' ),
654 $date,
655 array(),
656 array(
657 'target' => $this->list->title->getPrefixedText(),
658 'file' => $this->file->getArchiveName(),
659 'token' => $this->list->getUser()->getEditToken(
660 $this->file->getArchiveName() )
661 )
662 );
663 }
664 return '<span class="history-deleted">' . $link . '</span>';
665 }
666 /**
667 * Generate a user tool link cluster if the current user is allowed to view it
668 * @return string HTML
669 */
670 protected function getUserTools() {
671 if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
672 $uid = $this->file->getUser( 'id' );
673 $name = $this->file->getUser( 'text' );
674 $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name );
675 } else {
676 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
677 }
678 if ( $this->file->isDeleted( Revision::DELETED_USER ) ) {
679 return '<span class="history-deleted">' . $link . '</span>';
680 }
681 return $link;
682 }
683
684 /**
685 * Wrap and format the file's comment block, if the current
686 * user is allowed to view it.
687 *
688 * @return string HTML
689 */
690 protected function getComment() {
691 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
692 $block = Linker::commentBlock( $this->file->getDescription() );
693 } else {
694 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
695 }
696 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
697 return "<span class=\"history-deleted\">$block</span>";
698 }
699 return $block;
700 }
701
702 public function getHTML() {
703 $data =
704 $this->list->msg( 'widthheight' )->numParams(
705 $this->file->getWidth(), $this->file->getHeight() )->text() .
706 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')';
707
708 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
709 $data . ' ' . $this->getComment() . '</li>';
710 }
711 }
712
713 /**
714 * List for filearchive table items
715 */
716 class RevDel_ArchivedFileList extends RevDel_FileList {
717 public function getType() {
718 return 'filearchive';
719 }
720
721 public static function getRelationType() {
722 return 'fa_id';
723 }
724
725 /**
726 * @param $db DatabaseBase
727 * @return mixed
728 */
729 public function doQuery( $db ) {
730 $ids = array_map( 'intval', $this->ids );
731 return $db->select(
732 'filearchive',
733 ArchivedFile::selectFields(),
734 array(
735 'fa_name' => $this->title->getDBkey(),
736 'fa_id' => $ids
737 ),
738 __METHOD__,
739 array( 'ORDER BY' => 'fa_id DESC' )
740 );
741 }
742
743 public function newItem( $row ) {
744 return new RevDel_ArchivedFileItem( $this, $row );
745 }
746 }
747
748 /**
749 * Item class for a filearchive table row
750 */
751 class RevDel_ArchivedFileItem extends RevDel_FileItem {
752 public function __construct( $list, $row ) {
753 RevDel_Item::__construct( $list, $row );
754 $this->file = ArchivedFile::newFromRow( $row );
755 }
756
757 public function getIdField() {
758 return 'fa_id';
759 }
760
761 public function getTimestampField() {
762 return 'fa_timestamp';
763 }
764
765 public function getAuthorIdField() {
766 return 'fa_user';
767 }
768
769 public function getAuthorNameField() {
770 return 'fa_user_text';
771 }
772
773 public function getId() {
774 return $this->row->fa_id;
775 }
776
777 public function setBits( $bits ) {
778 $dbw = wfGetDB( DB_MASTER );
779 $dbw->update( 'filearchive',
780 array( 'fa_deleted' => $bits ),
781 array(
782 'fa_id' => $this->row->fa_id,
783 'fa_deleted' => $this->getBits(),
784 ),
785 __METHOD__
786 );
787 return (bool)$dbw->affectedRows();
788 }
789
790 protected function getLink() {
791 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
792 $this->file->getTimestamp(), $this->list->getUser() ) );
793
794 # Hidden files...
795 if ( !$this->canViewContent() ) {
796 $link = $date;
797 } else {
798 $undelete = SpecialPage::getTitleFor( 'Undelete' );
799 $key = $this->file->getKey();
800 $link = Linker::link( $undelete, $date, array(),
801 array(
802 'target' => $this->list->title->getPrefixedText(),
803 'file' => $key,
804 'token' => $this->list->getUser()->getEditToken( $key )
805 )
806 );
807 }
808 if ( $this->isDeleted() ) {
809 $link = '<span class="history-deleted">' . $link . '</span>';
810 }
811 return $link;
812 }
813 }
814
815 /**
816 * List for logging table items
817 */
818 class RevDel_LogList extends RevDel_List {
819 public function getType() {
820 return 'logging';
821 }
822
823 public static function getRelationType() {
824 return 'log_id';
825 }
826
827 public static function getRestriction() {
828 return 'deletelogentry';
829 }
830
831 public static function getRevdelConstant() {
832 return LogPage::DELETED_ACTION;
833 }
834
835 public static function suggestTarget( $target, array $ids ) {
836 $result = wfGetDB( DB_SLAVE )->select( 'logging',
837 'log_type',
838 array( 'log_id' => $ids ),
839 __METHOD__,
840 array( 'DISTINCT' )
841 );
842 if ( $result->numRows() == 1 ) {
843 // If there's only one type, the target can be set to include it.
844 return SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
845 }
846 return SpecialPage::getTitleFor( 'Log' );
847 }
848
849 /**
850 * @param $db DatabaseBase
851 * @return mixed
852 */
853 public function doQuery( $db ) {
854 $ids = array_map( 'intval', $this->ids );
855 return $db->select( 'logging', '*',
856 array( 'log_id' => $ids ),
857 __METHOD__,
858 array( 'ORDER BY' => 'log_id DESC' )
859 );
860 }
861
862 public function newItem( $row ) {
863 return new RevDel_LogItem( $this, $row );
864 }
865
866 public function getSuppressBit() {
867 return Revision::DELETED_RESTRICTED;
868 }
869
870 public function getLogAction() {
871 return 'event';
872 }
873
874 public function getLogParams( $params ) {
875 return array(
876 implode( ',', $params['ids'] ),
877 "ofield={$params['oldBits']}",
878 "nfield={$params['newBits']}"
879 );
880 }
881 }
882
883 /**
884 * Item class for a logging table row
885 */
886 class RevDel_LogItem extends RevDel_Item {
887 public function getIdField() {
888 return 'log_id';
889 }
890
891 public function getTimestampField() {
892 return 'log_timestamp';
893 }
894
895 public function getAuthorIdField() {
896 return 'log_user';
897 }
898
899 public function getAuthorNameField() {
900 return 'log_user_text';
901 }
902
903 public function canView() {
904 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
905 }
906
907 public function canViewContent() {
908 return true; // none
909 }
910
911 public function getBits() {
912 return $this->row->log_deleted;
913 }
914
915 public function setBits( $bits ) {
916 $dbw = wfGetDB( DB_MASTER );
917 $dbw->update( 'recentchanges',
918 array(
919 'rc_deleted' => $bits,
920 'rc_patrolled' => 1
921 ),
922 array(
923 'rc_logid' => $this->row->log_id,
924 'rc_timestamp' => $this->row->log_timestamp // index
925 ),
926 __METHOD__
927 );
928 $dbw->update( 'logging',
929 array( 'log_deleted' => $bits ),
930 array(
931 'log_id' => $this->row->log_id,
932 'log_deleted' => $this->getBits()
933 ),
934 __METHOD__
935 );
936 return (bool)$dbw->affectedRows();
937 }
938
939 public function getHTML() {
940 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
941 $this->row->log_timestamp, $this->list->getUser() ) );
942 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
943 $formatter = LogFormatter::newFromRow( $this->row );
944 $formatter->setContext( $this->list->getContext() );
945 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
946
947 // Log link for this page
948 $loglink = Linker::link(
949 SpecialPage::getTitleFor( 'Log' ),
950 $this->list->msg( 'log' )->escaped(),
951 array(),
952 array( 'page' => $title->getPrefixedText() )
953 );
954 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
955 // User links and action text
956 $action = $formatter->getActionText();
957 // Comment
958 $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment );
959 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
960 $comment = '<span class="history-deleted">' . $comment . '</span>';
961 }
962
963 return "<li>$loglink $date $action $comment</li>";
964 }
965 }