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