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