Merge "Use local context to get messages and time formatting methods of Language...
[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 = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
220 if ( $this->isDeleted() && !$this->canViewContent() ) {
221 return $date;
222 }
223 return Linker::link(
224 $this->list->title,
225 $date,
226 array(),
227 array(
228 'oldid' => $this->revision->getId(),
229 'unhide' => 1
230 )
231 );
232 }
233
234 /**
235 * Get the HTML link to the diff.
236 * Overridden by RevDel_ArchiveItem
237 * @return string
238 */
239 protected function getDiffLink() {
240 if ( $this->isDeleted() && !$this->canViewContent() ) {
241 return wfMsgHtml('diff');
242 } else {
243 return
244 Linker::link(
245 $this->list->title,
246 wfMsgHtml('diff'),
247 array(),
248 array(
249 'diff' => $this->revision->getId(),
250 'oldid' => 'prev',
251 'unhide' => 1
252 ),
253 array(
254 'known',
255 'noclasses'
256 )
257 );
258 }
259 }
260
261 public function getHTML() {
262 $difflink = $this->getDiffLink();
263 $revlink = $this->getRevisionLink();
264 $userlink = Linker::revUserLink( $this->revision );
265 $comment = Linker::revComment( $this->revision );
266 if ( $this->isDeleted() ) {
267 $revlink = "<span class=\"history-deleted\">$revlink</span>";
268 }
269 return "<li>($difflink) $revlink $userlink $comment</li>";
270 }
271 }
272
273 /**
274 * List for archive table items, i.e. revisions deleted via action=delete
275 */
276 class RevDel_ArchiveList extends RevDel_RevisionList {
277 public function getType() {
278 return 'archive';
279 }
280
281 public static function getRelationType() {
282 return 'ar_timestamp';
283 }
284
285 /**
286 * @param $db DatabaseBase
287 * @return mixed
288 */
289 public function doQuery( $db ) {
290 $timestamps = array();
291 foreach ( $this->ids as $id ) {
292 $timestamps[] = $db->timestamp( $id );
293 }
294 return $db->select( 'archive', '*',
295 array(
296 'ar_namespace' => $this->title->getNamespace(),
297 'ar_title' => $this->title->getDBkey(),
298 'ar_timestamp' => $timestamps
299 ),
300 __METHOD__,
301 array( 'ORDER BY' => 'ar_timestamp DESC' )
302 );
303 }
304
305 public function newItem( $row ) {
306 return new RevDel_ArchiveItem( $this, $row );
307 }
308
309 public function doPreCommitUpdates() {
310 return Status::newGood();
311 }
312
313 public function doPostCommitUpdates() {
314 return Status::newGood();
315 }
316 }
317
318 /**
319 * Item class for a archive table row
320 */
321 class RevDel_ArchiveItem extends RevDel_RevisionItem {
322 public function __construct( $list, $row ) {
323 RevDel_Item::__construct( $list, $row );
324 $this->revision = Revision::newFromArchiveRow( $row,
325 array( 'page' => $this->list->title->getArticleID() ) );
326 }
327
328 public function getIdField() {
329 return 'ar_timestamp';
330 }
331
332 public function getTimestampField() {
333 return 'ar_timestamp';
334 }
335
336 public function getAuthorIdField() {
337 return 'ar_user';
338 }
339
340 public function getAuthorNameField() {
341 return 'ar_user_text';
342 }
343
344 public function getId() {
345 # Convert DB timestamp to MW timestamp
346 return $this->revision->getTimestamp();
347 }
348
349 public function setBits( $bits ) {
350 $dbw = wfGetDB( DB_MASTER );
351 $dbw->update( 'archive',
352 array( 'ar_deleted' => $bits ),
353 array(
354 'ar_namespace' => $this->list->title->getNamespace(),
355 'ar_title' => $this->list->title->getDBkey(),
356 // use timestamp for index
357 'ar_timestamp' => $this->row->ar_timestamp,
358 'ar_rev_id' => $this->row->ar_rev_id,
359 'ar_deleted' => $this->getBits()
360 ),
361 __METHOD__ );
362 return (bool)$dbw->affectedRows();
363 }
364
365 protected function getRevisionLink() {
366 $undelete = SpecialPage::getTitleFor( 'Undelete' );
367 $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
368 if ( $this->isDeleted() && !$this->canViewContent() ) {
369 return $date;
370 }
371 return Linker::link( $undelete, $date, array(),
372 array(
373 'target' => $this->list->title->getPrefixedText(),
374 'timestamp' => $this->revision->getTimestamp()
375 ) );
376 }
377
378 protected function getDiffLink() {
379 if ( $this->isDeleted() && !$this->canViewContent() ) {
380 return wfMsgHtml( 'diff' );
381 }
382 $undelete = SpecialPage::getTitleFor( 'Undelete' );
383 return Linker::link( $undelete, wfMsgHtml('diff'), array(),
384 array(
385 'target' => $this->list->title->getPrefixedText(),
386 'diff' => 'prev',
387 'timestamp' => $this->revision->getTimestamp()
388 ) );
389 }
390 }
391
392
393 /**
394 * Item class for a archive table row by ar_rev_id -- actually
395 * used via RevDel_RevisionList.
396 */
397 class RevDel_ArchivedRevisionItem extends RevDel_ArchiveItem {
398 public function __construct( $list, $row ) {
399 RevDel_Item::__construct( $list, $row );
400
401 $this->revision = Revision::newFromArchiveRow( $row,
402 array( 'page' => $this->list->title->getArticleID() ) );
403 }
404
405 public function getIdField() {
406 return 'ar_rev_id';
407 }
408
409 public function getId() {
410 return $this->revision->getId();
411 }
412
413 public function setBits( $bits ) {
414 $dbw = wfGetDB( DB_MASTER );
415 $dbw->update( 'archive',
416 array( 'ar_deleted' => $bits ),
417 array( 'ar_rev_id' => $this->row->ar_rev_id,
418 'ar_deleted' => $this->getBits()
419 ),
420 __METHOD__ );
421 return (bool)$dbw->affectedRows();
422 }
423 }
424
425 /**
426 * List for oldimage table items
427 */
428 class RevDel_FileList extends RevDel_List {
429 public function getType() {
430 return 'oldimage';
431 }
432
433 public static function getRelationType() {
434 return 'oi_archive_name';
435 }
436
437 var $storeBatch, $deleteBatch, $cleanupBatch;
438
439 /**
440 * @param $db DatabaseBase
441 * @return mixed
442 */
443 public function doQuery( $db ) {
444 $archiveNames = array();
445 foreach( $this->ids as $timestamp ) {
446 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
447 }
448 return $db->select( 'oldimage', '*',
449 array(
450 'oi_name' => $this->title->getDBkey(),
451 'oi_archive_name' => $archiveNames
452 ),
453 __METHOD__,
454 array( 'ORDER BY' => 'oi_timestamp DESC' )
455 );
456 }
457
458 public function newItem( $row ) {
459 return new RevDel_FileItem( $this, $row );
460 }
461
462 public function clearFileOps() {
463 $this->deleteBatch = array();
464 $this->storeBatch = array();
465 $this->cleanupBatch = array();
466 }
467
468 public function doPreCommitUpdates() {
469 $status = Status::newGood();
470 $repo = RepoGroup::singleton()->getLocalRepo();
471 if ( $this->storeBatch ) {
472 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
473 }
474 if ( !$status->isOK() ) {
475 return $status;
476 }
477 if ( $this->deleteBatch ) {
478 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
479 }
480 if ( !$status->isOK() ) {
481 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
482 // modified (but destined for rollback) causes data loss
483 return $status;
484 }
485 if ( $this->cleanupBatch ) {
486 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
487 }
488 return $status;
489 }
490
491 public function doPostCommitUpdates() {
492 $file = wfLocalFile( $this->title );
493 $file->purgeCache();
494 $file->purgeDescription();
495 return Status::newGood();
496 }
497
498 public function getSuppressBit() {
499 return File::DELETED_RESTRICTED;
500 }
501 }
502
503 /**
504 * Item class for an oldimage table row
505 */
506 class RevDel_FileItem extends RevDel_Item {
507
508 /**
509 * @var File
510 */
511 var $file;
512
513 public function __construct( $list, $row ) {
514 parent::__construct( $list, $row );
515 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
516 }
517
518 public function getIdField() {
519 return 'oi_archive_name';
520 }
521
522 public function getTimestampField() {
523 return 'oi_timestamp';
524 }
525
526 public function getAuthorIdField() {
527 return 'oi_user';
528 }
529
530 public function getAuthorNameField() {
531 return 'oi_user_text';
532 }
533
534 public function getId() {
535 $parts = explode( '!', $this->row->oi_archive_name );
536 return $parts[0];
537 }
538
539 public function canView() {
540 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
541 }
542
543 public function canViewContent() {
544 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
545 }
546
547 public function getBits() {
548 return $this->file->getVisibility();
549 }
550
551 public function setBits( $bits ) {
552 # Queue the file op
553 # @todo FIXME: Move to LocalFile.php
554 if ( $this->isDeleted() ) {
555 if ( $bits & File::DELETED_FILE ) {
556 # Still deleted
557 } else {
558 # Newly undeleted
559 $key = $this->file->getStorageKey();
560 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
561 $this->list->storeBatch[] = array(
562 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
563 'public',
564 $this->file->getRel()
565 );
566 $this->list->cleanupBatch[] = $key;
567 }
568 } elseif ( $bits & File::DELETED_FILE ) {
569 # Newly deleted
570 $key = $this->file->getStorageKey();
571 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
572 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
573 }
574
575 # Do the database operations
576 $dbw = wfGetDB( DB_MASTER );
577 $dbw->update( 'oldimage',
578 array( 'oi_deleted' => $bits ),
579 array(
580 'oi_name' => $this->row->oi_name,
581 'oi_timestamp' => $this->row->oi_timestamp,
582 'oi_deleted' => $this->getBits()
583 ),
584 __METHOD__
585 );
586 return (bool)$dbw->affectedRows();
587 }
588
589 public function isDeleted() {
590 return $this->file->isDeleted( File::DELETED_FILE );
591 }
592
593 /**
594 * Get the link to the file.
595 * Overridden by RevDel_ArchivedFileItem.
596 * @return string
597 */
598 protected function getLink() {
599 $date = $this->list->getLanguage()->timeanddate( $this->file->getTimestamp(), true );
600 if ( $this->isDeleted() ) {
601 # Hidden files...
602 if ( !$this->canViewContent() ) {
603 $link = $date;
604 } else {
605 $revdelete = SpecialPage::getTitleFor( 'Revisiondelete' );
606 $link = Linker::link(
607 $revdelete,
608 $date, array(),
609 array(
610 'target' => $this->list->title->getPrefixedText(),
611 'file' => $this->file->getArchiveName(),
612 'token' => $this->list->getUser()->getEditToken(
613 $this->file->getArchiveName() )
614 )
615 );
616 }
617 return '<span class="history-deleted">' . $link . '</span>';
618 } else {
619 # Regular files...
620 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
621 }
622 }
623 /**
624 * Generate a user tool link cluster if the current user is allowed to view it
625 * @return string HTML
626 */
627 protected function getUserTools() {
628 if( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) {
629 $link = Linker::userLink( $this->file->user, $this->file->user_text ) .
630 Linker::userToolLinks( $this->file->user, $this->file->user_text );
631 } else {
632 $link = wfMsgHtml( 'rev-deleted-user' );
633 }
634 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
635 return '<span class="history-deleted">' . $link . '</span>';
636 }
637 return $link;
638 }
639
640 /**
641 * Wrap and format the file's comment block, if the current
642 * user is allowed to view it.
643 *
644 * @return string HTML
645 */
646 protected function getComment() {
647 if( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
648 $block = Linker::commentBlock( $this->file->description );
649 } else {
650 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
651 }
652 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
653 return "<span class=\"history-deleted\">$block</span>";
654 }
655 return $block;
656 }
657
658 public function getHTML() {
659 $data =
660 wfMsg(
661 'widthheight',
662 $this->list->getLanguage()->formatNum( $this->file->getWidth() ),
663 $this->list->getLanguage()->formatNum( $this->file->getHeight() )
664 ) .
665 ' (' .
666 wfMsgExt( 'nbytes', 'parsemag', $this->list->getLanguage()->formatNum( $this->file->getSize() ) ) .
667 ')';
668
669 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
670 $data . ' ' . $this->getComment(). '</li>';
671 }
672 }
673
674 /**
675 * List for filearchive table items
676 */
677 class RevDel_ArchivedFileList extends RevDel_FileList {
678 public function getType() {
679 return 'filearchive';
680 }
681
682 public static function getRelationType() {
683 return 'fa_id';
684 }
685
686 /**
687 * @param $db DatabaseBase
688 * @return mixed
689 */
690 public function doQuery( $db ) {
691 $ids = array_map( 'intval', $this->ids );
692 return $db->select( 'filearchive', '*',
693 array(
694 'fa_name' => $this->title->getDBkey(),
695 'fa_id' => $ids
696 ),
697 __METHOD__,
698 array( 'ORDER BY' => 'fa_id DESC' )
699 );
700 }
701
702 public function newItem( $row ) {
703 return new RevDel_ArchivedFileItem( $this, $row );
704 }
705 }
706
707 /**
708 * Item class for a filearchive table row
709 */
710 class RevDel_ArchivedFileItem extends RevDel_FileItem {
711 public function __construct( $list, $row ) {
712 RevDel_Item::__construct( $list, $row );
713 $this->file = ArchivedFile::newFromRow( $row );
714 }
715
716 public function getIdField() {
717 return 'fa_id';
718 }
719
720 public function getTimestampField() {
721 return 'fa_timestamp';
722 }
723
724 public function getAuthorIdField() {
725 return 'fa_user';
726 }
727
728 public function getAuthorNameField() {
729 return 'fa_user_text';
730 }
731
732 public function getId() {
733 return $this->row->fa_id;
734 }
735
736 public function setBits( $bits ) {
737 $dbw = wfGetDB( DB_MASTER );
738 $dbw->update( 'filearchive',
739 array( 'fa_deleted' => $bits ),
740 array(
741 'fa_id' => $this->row->fa_id,
742 'fa_deleted' => $this->getBits(),
743 ),
744 __METHOD__
745 );
746 return (bool)$dbw->affectedRows();
747 }
748
749 protected function getLink() {
750 $date = $this->list->getLanguage()->timeanddate( $this->file->getTimestamp(), true );
751 $undelete = SpecialPage::getTitleFor( 'Undelete' );
752 $key = $this->file->getKey();
753 # Hidden files...
754 if( !$this->canViewContent() ) {
755 $link = $date;
756 } else {
757 $link = Linker::link( $undelete, $date, array(),
758 array(
759 'target' => $this->list->title->getPrefixedText(),
760 'file' => $key,
761 'token' => $this->list->getUser()->getEditToken( $key )
762 )
763 );
764 }
765 if( $this->isDeleted() ) {
766 $link = '<span class="history-deleted">' . $link . '</span>';
767 }
768 return $link;
769 }
770 }
771
772 /**
773 * List for logging table items
774 */
775 class RevDel_LogList extends RevDel_List {
776 public function getType() {
777 return 'logging';
778 }
779
780 public static function getRelationType() {
781 return 'log_id';
782 }
783
784 /**
785 * @param $db DatabaseBase
786 * @return mixed
787 */
788 public function doQuery( $db ) {
789 $ids = array_map( 'intval', $this->ids );
790 return $db->select( 'logging', '*',
791 array( 'log_id' => $ids ),
792 __METHOD__,
793 array( 'ORDER BY' => 'log_id DESC' )
794 );
795 }
796
797 public function newItem( $row ) {
798 return new RevDel_LogItem( $this, $row );
799 }
800
801 public function getSuppressBit() {
802 return Revision::DELETED_RESTRICTED;
803 }
804
805 public function getLogAction() {
806 return 'event';
807 }
808
809 public function getLogParams( $params ) {
810 return array(
811 implode( ',', $params['ids'] ),
812 "ofield={$params['oldBits']}",
813 "nfield={$params['newBits']}"
814 );
815 }
816 }
817
818 /**
819 * Item class for a logging table row
820 */
821 class RevDel_LogItem extends RevDel_Item {
822 public function getIdField() {
823 return 'log_id';
824 }
825
826 public function getTimestampField() {
827 return 'log_timestamp';
828 }
829
830 public function getAuthorIdField() {
831 return 'log_user';
832 }
833
834 public function getAuthorNameField() {
835 return 'log_user_text';
836 }
837
838 public function canView() {
839 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
840 }
841
842 public function canViewContent() {
843 return true; // none
844 }
845
846 public function getBits() {
847 return $this->row->log_deleted;
848 }
849
850 public function setBits( $bits ) {
851 $dbw = wfGetDB( DB_MASTER );
852 $dbw->update( 'recentchanges',
853 array(
854 'rc_deleted' => $bits,
855 'rc_patrolled' => 1
856 ),
857 array(
858 'rc_logid' => $this->row->log_id,
859 'rc_timestamp' => $this->row->log_timestamp // index
860 ),
861 __METHOD__
862 );
863 $dbw->update( 'logging',
864 array( 'log_deleted' => $bits ),
865 array(
866 'log_id' => $this->row->log_id,
867 'log_deleted' => $this->getBits()
868 ),
869 __METHOD__
870 );
871 return (bool)$dbw->affectedRows();
872 }
873
874 public function getHTML() {
875 $date = htmlspecialchars( $this->list->getLanguage()->timeanddate( $this->row->log_timestamp ) );
876 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
877 $formatter = LogFormatter::newFromRow( $this->row );
878 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
879
880 // Log link for this page
881 $loglink = Linker::link(
882 SpecialPage::getTitleFor( 'Log' ),
883 wfMsgHtml( 'log' ),
884 array(),
885 array( 'page' => $title->getPrefixedText() )
886 );
887 // User links and action text
888 $action = $formatter->getActionText();
889 // Comment
890 $comment = $this->list->getLanguage()->getDirMark() . Linker::commentBlock( $this->row->log_comment );
891 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
892 $comment = '<span class="history-deleted">' . $comment . '</span>';
893 }
894
895 return "<li>($loglink) $date $action $comment</li>";
896 }
897 }