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