Fixup 1 more autoloader from r77677
[lhc/web/wiklou.git] / includes / revisiondelete / RevisionDelete.php
1 <?php
2 /**
3 * Revision/log/file deletion backend
4 *
5 * @file
6 */
7
8 /**
9 * Temporary b/c interface, collection of static functions.
10 * @ingroup SpecialPage
11 */
12 class RevisionDeleter {
13 /**
14 * Checks for a change in the bitfield for a certain option and updates the
15 * provided array accordingly.
16 *
17 * @param $desc String: description to add to the array if the option was
18 * enabled / disabled.
19 * @param $field Integer: the bitmask describing the single option.
20 * @param $diff Integer: the xor of the old and new bitfields.
21 * @param $new Integer: the new bitfield
22 * @param $arr Array: the array to update.
23 */
24 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
25 if( $diff & $field ) {
26 $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
27 }
28 }
29
30 /**
31 * Gets an array of message keys describing the changes made to the visibility
32 * of the revision. If the resulting array is $arr, then $arr[0] will contain an
33 * array of strings describing the items that were hidden, $arr[2] will contain
34 * an array of strings describing the items that were unhidden, and $arr[3] will
35 * contain an array with a single string, which can be one of "applied
36 * restrictions to sysops", "removed restrictions from sysops", or null.
37 *
38 * @param $n Integer: the new bitfield.
39 * @param $o Integer: the old bitfield.
40 * @return An array as described above.
41 */
42 protected static function getChanges( $n, $o ) {
43 $diff = $n ^ $o;
44 $ret = array( 0 => array(), 1 => array(), 2 => array() );
45 // Build bitfield changes in language
46 self::checkItem( 'revdelete-content',
47 Revision::DELETED_TEXT, $diff, $n, $ret );
48 self::checkItem( 'revdelete-summary',
49 Revision::DELETED_COMMENT, $diff, $n, $ret );
50 self::checkItem( 'revdelete-uname',
51 Revision::DELETED_USER, $diff, $n, $ret );
52 // Restriction application to sysops
53 if( $diff & Revision::DELETED_RESTRICTED ) {
54 if( $n & Revision::DELETED_RESTRICTED )
55 $ret[2][] = 'revdelete-restricted';
56 else
57 $ret[2][] = 'revdelete-unrestricted';
58 }
59 return $ret;
60 }
61
62 /**
63 * Gets a log message to describe the given revision visibility change. This
64 * message will be of the form "[hid {content, edit summary, username}];
65 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
66 *
67 * @param $count Integer: The number of effected revisions.
68 * @param $nbitfield Integer: The new bitfield for the revision.
69 * @param $obitfield Integer: The old bitfield for the revision.
70 * @param $isForLog Boolean
71 * @param $forContent Boolean
72 */
73 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
74 global $wgLang, $wgContLang;
75
76 $lang = $forContent ? $wgContLang : $wgLang;
77 $msgFunc = $forContent ? "wfMsgForContent" : "wfMsg";
78
79 $changes = self::getChanges( $nbitfield, $obitfield );
80 array_walk($changes, 'RevisionDeleter::expandMessageArray', $forContent);
81
82 $changesText = array();
83
84 if( count( $changes[0] ) ) {
85 $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
86 }
87 if( count( $changes[1] ) ) {
88 $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
89 }
90
91 $s = $lang->semicolonList( $changesText );
92 if( count( $changes[2] ) ) {
93 $s .= $s ? ' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
94 }
95
96 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
97 return wfMsgExt( $msg, $forContent ? array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
98 }
99
100 private static function expandMessageArray(& $msg, $key, $forContent) {
101 if ( is_array ($msg) ) {
102 array_walk($msg, 'RevisionDeleter::expandMessageArray', $forContent);
103 } else {
104 if ( $forContent ) {
105 $msg = wfMsgForContent($msg);
106 } else {
107 $msg = wfMsg($msg);
108 }
109 }
110 }
111
112 // Get DB field name for URL param...
113 // Future code for other things may also track
114 // other types of revision-specific changes.
115 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
116 public static function getRelationType( $typeName ) {
117 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
118 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
119 }
120 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
121 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
122 $list = new $class( null, null, null );
123 return $list->getIdField();
124 } else {
125 return null;
126 }
127 }
128
129 // Checks if a revision still exists in the revision table.
130 // If it doesn't, returns the corresponding ar_timestamp field
131 // so that this key can be used instead.
132 public static function checkRevisionExistence( $title, $revid ) {
133 $dbr = wfGetDB( DB_SLAVE );
134 $exists = $dbr->selectField( 'revision', '1',
135 array( 'rev_id' => $revid ), __METHOD__ );
136
137 if ( $exists ) {
138 return true;
139 }
140
141 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
142 array( 'ar_namespace' => $title->getNamespace(),
143 'ar_title' => $title->getDBkey(),
144 'ar_rev_id' => $revid ), __METHOD__ );
145
146 return $timestamp;
147 }
148
149 // Creates utility links for log entries.
150 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
151 global $wgLang;
152
153 if( count($paramArray) >= 2 ) {
154 // Different revision types use different URL params...
155 $originalKey = $key = $paramArray[0];
156 // $paramArray[1] is a CSV of the IDs
157 $Ids = explode( ',', $paramArray[1] );
158
159 $revert = array();
160
161 // For if undeleted revisions are found amidst deleted ones.
162 $undeletedRevisions = array();
163
164 // This is not going to work if some revs are deleted and some
165 // aren't.
166 if ($key == 'revision') {
167 foreach( $Ids as $k => $id ) {
168 $existResult =
169 self::checkRevisionExistence( $title, $id );
170
171 if ($existResult !== true) {
172 $key = 'archive';
173 $Ids[$k] = $existResult;
174 } else {
175 // Undeleted revision amidst deleted ones
176 unset($Ids[$k]);
177 $undeletedRevisions[] = $id;
178 }
179 }
180
181 if ( $key == $originalKey ) {
182 $Ids = $undeletedRevisions;
183 $undeletedRevisions = array();
184 }
185 }
186
187 // Diff link for single rev deletions
188 if( count($Ids) == 1 && !count($undeletedRevisions) ) {
189 // Live revision diffs...
190 if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
191 $revert[] = $skin->link(
192 $title,
193 $messages['diff'],
194 array(),
195 array(
196 'diff' => intval( $Ids[0] ),
197 'unhide' => 1
198 ),
199 array( 'known', 'noclasses' )
200 );
201 // Deleted revision diffs...
202 } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
203 $revert[] = $skin->link(
204 SpecialPage::getTitleFor( 'Undelete' ),
205 $messages['diff'],
206 array(),
207 array(
208 'target' => $title->getPrefixedDBKey(),
209 'diff' => 'prev',
210 'timestamp' => $Ids[0]
211 ),
212 array( 'known', 'noclasses' )
213 );
214 }
215 }
216
217 // View/modify link...
218 if ( count($undeletedRevisions) ) {
219 // FIXME THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
220 // It's not possible to pass a list of both deleted and
221 // undeleted revisions to SpecialRevisionDelete, so we're
222 // stuck with two links. See bug 23363.
223 $restoreLinks = array();
224
225 $restoreLinks[] = $skin->link(
226 SpecialPage::getTitleFor( 'Revisiondelete' ),
227 $messages['revdel-restore-visible'],
228 array(),
229 array(
230 'target' => $title->getPrefixedText(),
231 'type' => $originalKey,
232 'ids' => implode(',', $undeletedRevisions),
233 ),
234 array( 'known', 'noclasses' )
235 );
236
237 $restoreLinks[] = $skin->link(
238 SpecialPage::getTitleFor( 'Revisiondelete' ),
239 $messages['revdel-restore-deleted'],
240 array(),
241 array(
242 'target' => $title->getPrefixedText(),
243 'type' => $key,
244 'ids' => implode(',', $Ids),
245 ),
246 array( 'known', 'noclasses' )
247 );
248
249 $revert[] = $messages['revdel-restore'] . ' [' .
250 $wgLang->pipeList( $restoreLinks ) . ']';
251 } else {
252 $revert[] = $skin->link(
253 SpecialPage::getTitleFor( 'Revisiondelete' ),
254 $messages['revdel-restore'],
255 array(),
256 array(
257 'target' => $title->getPrefixedText(),
258 'type' => $key,
259 'ids' => implode(',', $Ids),
260 ),
261 array( 'known', 'noclasses' )
262 );
263 }
264
265 // Pipe links
266 return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
267 }
268 return '';
269 }
270 }
271
272 /**
273 * List for revision table items
274 */
275 class RevDel_RevisionList extends RevDel_List {
276 var $currentRevId;
277 var $type = 'revision';
278 var $idField = 'rev_id';
279 var $dateField = 'rev_timestamp';
280 var $authorIdField = 'rev_user';
281 var $authorNameField = 'rev_user_text';
282
283 public function doQuery( $db ) {
284 $ids = array_map( 'intval', $this->ids );
285 return $db->select( array('revision','page'), '*',
286 array(
287 'rev_page' => $this->title->getArticleID(),
288 'rev_id' => $ids,
289 'rev_page = page_id'
290 ),
291 __METHOD__,
292 array( 'ORDER BY' => 'rev_id DESC' )
293 );
294 }
295
296 public function newItem( $row ) {
297 return new RevDel_RevisionItem( $this, $row );
298 }
299
300 public function getCurrent() {
301 if ( is_null( $this->currentRevId ) ) {
302 $dbw = wfGetDB( DB_MASTER );
303 $this->currentRevId = $dbw->selectField(
304 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
305 }
306 return $this->currentRevId;
307 }
308
309 public function getSuppressBit() {
310 return Revision::DELETED_RESTRICTED;
311 }
312
313 public function doPreCommitUpdates() {
314 $this->title->invalidateCache();
315 return Status::newGood();
316 }
317
318 public function doPostCommitUpdates() {
319 $this->title->purgeSquid();
320 // Extensions that require referencing previous revisions may need this
321 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title ) );
322 return Status::newGood();
323 }
324 }
325
326 /**
327 * Item class for a revision table row
328 */
329 class RevDel_RevisionItem extends RevDel_Item {
330 var $revision;
331
332 public function __construct( $list, $row ) {
333 parent::__construct( $list, $row );
334 $this->revision = new Revision( $row );
335 }
336
337 public function canView() {
338 return $this->revision->userCan( Revision::DELETED_RESTRICTED );
339 }
340
341 public function canViewContent() {
342 return $this->revision->userCan( Revision::DELETED_TEXT );
343 }
344
345 public function getBits() {
346 return $this->revision->mDeleted;
347 }
348
349 public function setBits( $bits ) {
350 $dbw = wfGetDB( DB_MASTER );
351 // Update revision table
352 $dbw->update( 'revision',
353 array( 'rev_deleted' => $bits ),
354 array(
355 'rev_id' => $this->revision->getId(),
356 'rev_page' => $this->revision->getPage(),
357 'rev_deleted' => $this->getBits()
358 ),
359 __METHOD__
360 );
361 if ( !$dbw->affectedRows() ) {
362 // Concurrent fail!
363 return false;
364 }
365 // Update recentchanges table
366 $dbw->update( 'recentchanges',
367 array(
368 'rc_deleted' => $bits,
369 'rc_patrolled' => 1
370 ),
371 array(
372 'rc_this_oldid' => $this->revision->getId(), // condition
373 // non-unique timestamp index
374 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
375 ),
376 __METHOD__
377 );
378 return true;
379 }
380
381 public function isDeleted() {
382 return $this->revision->isDeleted( Revision::DELETED_TEXT );
383 }
384
385 public function isHideCurrentOp( $newBits ) {
386 return ( $newBits & Revision::DELETED_TEXT )
387 && $this->list->getCurrent() == $this->getId();
388 }
389
390 /**
391 * Get the HTML link to the revision text.
392 * Overridden by RevDel_ArchiveItem.
393 */
394 protected function getRevisionLink() {
395 global $wgLang;
396 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
397 if ( $this->isDeleted() && !$this->canViewContent() ) {
398 return $date;
399 }
400 return $this->special->skin->link(
401 $this->list->title,
402 $date,
403 array(),
404 array(
405 'oldid' => $this->revision->getId(),
406 'unhide' => 1
407 )
408 );
409 }
410
411 /**
412 * Get the HTML link to the diff.
413 * Overridden by RevDel_ArchiveItem
414 */
415 protected function getDiffLink() {
416 if ( $this->isDeleted() && !$this->canViewContent() ) {
417 return wfMsgHtml('diff');
418 } else {
419 return
420 $this->special->skin->link(
421 $this->list->title,
422 wfMsgHtml('diff'),
423 array(),
424 array(
425 'diff' => $this->revision->getId(),
426 'oldid' => 'prev',
427 'unhide' => 1
428 ),
429 array(
430 'known',
431 'noclasses'
432 )
433 );
434 }
435 }
436
437 public function getHTML() {
438 $difflink = $this->getDiffLink();
439 $revlink = $this->getRevisionLink();
440 $userlink = $this->special->skin->revUserLink( $this->revision );
441 $comment = $this->special->skin->revComment( $this->revision );
442 if ( $this->isDeleted() ) {
443 $revlink = "<span class=\"history-deleted\">$revlink</span>";
444 }
445 return "<li>($difflink) $revlink $userlink $comment</li>";
446 }
447 }
448
449 /**
450 * List for archive table items, i.e. revisions deleted via action=delete
451 */
452 class RevDel_ArchiveList extends RevDel_RevisionList {
453 var $type = 'archive';
454 var $idField = 'ar_timestamp';
455 var $dateField = 'ar_timestamp';
456 var $authorIdField = 'ar_user';
457 var $authorNameField = 'ar_user_text';
458
459 public function doQuery( $db ) {
460 $timestamps = array();
461 foreach ( $this->ids as $id ) {
462 $timestamps[] = $db->timestamp( $id );
463 }
464 return $db->select( 'archive', '*',
465 array(
466 'ar_namespace' => $this->title->getNamespace(),
467 'ar_title' => $this->title->getDBkey(),
468 'ar_timestamp' => $timestamps
469 ),
470 __METHOD__,
471 array( 'ORDER BY' => 'ar_timestamp DESC' )
472 );
473 }
474
475 public function newItem( $row ) {
476 return new RevDel_ArchiveItem( $this, $row );
477 }
478
479 public function doPreCommitUpdates() {
480 return Status::newGood();
481 }
482
483 public function doPostCommitUpdates() {
484 return Status::newGood();
485 }
486 }
487
488 /**
489 * Item class for a archive table row
490 */
491 class RevDel_ArchiveItem extends RevDel_RevisionItem {
492 public function __construct( $list, $row ) {
493 parent::__construct( $list, $row );
494 $this->revision = Revision::newFromArchiveRow( $row,
495 array( 'page' => $this->list->title->getArticleId() ) );
496 }
497
498 public function getId() {
499 # Convert DB timestamp to MW timestamp
500 return $this->revision->getTimestamp();
501 }
502
503 public function setBits( $bits ) {
504 $dbw = wfGetDB( DB_MASTER );
505 $dbw->update( 'archive',
506 array( 'ar_deleted' => $bits ),
507 array( 'ar_namespace' => $this->list->title->getNamespace(),
508 'ar_title' => $this->list->title->getDBkey(),
509 // use timestamp for index
510 'ar_timestamp' => $this->row->ar_timestamp,
511 'ar_rev_id' => $this->row->ar_rev_id,
512 'ar_deleted' => $this->getBits()
513 ),
514 __METHOD__ );
515 return (bool)$dbw->affectedRows();
516 }
517
518 protected function getRevisionLink() {
519 global $wgLang;
520 $undelete = SpecialPage::getTitleFor( 'Undelete' );
521 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
522 if ( $this->isDeleted() && !$this->canViewContent() ) {
523 return $date;
524 }
525 return $this->special->skin->link( $undelete, $date, array(),
526 array(
527 'target' => $this->list->title->getPrefixedText(),
528 'timestamp' => $this->revision->getTimestamp()
529 ) );
530 }
531
532 protected function getDiffLink() {
533 if ( $this->isDeleted() && !$this->canViewContent() ) {
534 return wfMsgHtml( 'diff' );
535 }
536 $undelete = SpecialPage::getTitleFor( 'Undelete' );
537 return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
538 array(
539 'target' => $this->list->title->getPrefixedText(),
540 'diff' => 'prev',
541 'timestamp' => $this->revision->getTimestamp()
542 ) );
543 }
544 }
545
546 /**
547 * List for oldimage table items
548 */
549 class RevDel_FileList extends RevDel_List {
550 var $type = 'oldimage';
551 var $idField = 'oi_archive_name';
552 var $dateField = 'oi_timestamp';
553 var $authorIdField = 'oi_user';
554 var $authorNameField = 'oi_user_text';
555 var $storeBatch, $deleteBatch, $cleanupBatch;
556
557 public function doQuery( $db ) {
558 $archiveNames = array();
559 foreach( $this->ids as $timestamp ) {
560 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
561 }
562 return $db->select( 'oldimage', '*',
563 array(
564 'oi_name' => $this->title->getDBkey(),
565 'oi_archive_name' => $archiveNames
566 ),
567 __METHOD__,
568 array( 'ORDER BY' => 'oi_timestamp DESC' )
569 );
570 }
571
572 public function newItem( $row ) {
573 return new RevDel_FileItem( $this, $row );
574 }
575
576 public function clearFileOps() {
577 $this->deleteBatch = array();
578 $this->storeBatch = array();
579 $this->cleanupBatch = array();
580 }
581
582 public function doPreCommitUpdates() {
583 $status = Status::newGood();
584 $repo = RepoGroup::singleton()->getLocalRepo();
585 if ( $this->storeBatch ) {
586 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
587 }
588 if ( !$status->isOK() ) {
589 return $status;
590 }
591 if ( $this->deleteBatch ) {
592 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
593 }
594 if ( !$status->isOK() ) {
595 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
596 // modified (but destined for rollback) causes data loss
597 return $status;
598 }
599 if ( $this->cleanupBatch ) {
600 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
601 }
602 return $status;
603 }
604
605 public function doPostCommitUpdates() {
606 $file = wfLocalFile( $this->title );
607 $file->purgeCache();
608 $file->purgeDescription();
609 return Status::newGood();
610 }
611
612 public function getSuppressBit() {
613 return File::DELETED_RESTRICTED;
614 }
615 }
616
617 /**
618 * Item class for an oldimage table row
619 */
620 class RevDel_FileItem extends RevDel_Item {
621 var $file;
622
623 public function __construct( $list, $row ) {
624 parent::__construct( $list, $row );
625 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
626 }
627
628 public function getId() {
629 $parts = explode( '!', $this->row->oi_archive_name );
630 return $parts[0];
631 }
632
633 public function canView() {
634 return $this->file->userCan( File::DELETED_RESTRICTED );
635 }
636
637 public function canViewContent() {
638 return $this->file->userCan( File::DELETED_FILE );
639 }
640
641 public function getBits() {
642 return $this->file->getVisibility();
643 }
644
645 public function setBits( $bits ) {
646 # Queue the file op
647 # FIXME: move to LocalFile.php
648 if ( $this->isDeleted() ) {
649 if ( $bits & File::DELETED_FILE ) {
650 # Still deleted
651 } else {
652 # Newly undeleted
653 $key = $this->file->getStorageKey();
654 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
655 $this->list->storeBatch[] = array(
656 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
657 'public',
658 $this->file->getRel()
659 );
660 $this->list->cleanupBatch[] = $key;
661 }
662 } elseif ( $bits & File::DELETED_FILE ) {
663 # Newly deleted
664 $key = $this->file->getStorageKey();
665 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
666 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
667 }
668
669 # Do the database operations
670 $dbw = wfGetDB( DB_MASTER );
671 $dbw->update( 'oldimage',
672 array( 'oi_deleted' => $bits ),
673 array(
674 'oi_name' => $this->row->oi_name,
675 'oi_timestamp' => $this->row->oi_timestamp,
676 'oi_deleted' => $this->getBits()
677 ),
678 __METHOD__
679 );
680 return (bool)$dbw->affectedRows();
681 }
682
683 public function isDeleted() {
684 return $this->file->isDeleted( File::DELETED_FILE );
685 }
686
687 /**
688 * Get the link to the file.
689 * Overridden by RevDel_ArchivedFileItem.
690 */
691 protected function getLink() {
692 global $wgLang, $wgUser;
693 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
694 if ( $this->isDeleted() ) {
695 # Hidden files...
696 if ( !$this->canViewContent() ) {
697 $link = $date;
698 } else {
699 $link = $this->special->skin->link(
700 $this->special->getTitle(),
701 $date, array(),
702 array(
703 'target' => $this->list->title->getPrefixedText(),
704 'file' => $this->file->getArchiveName(),
705 'token' => $wgUser->editToken( $this->file->getArchiveName() )
706 )
707 );
708 }
709 return '<span class="history-deleted">' . $link . '</span>';
710 } else {
711 # Regular files...
712 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
713 }
714 }
715 /**
716 * Generate a user tool link cluster if the current user is allowed to view it
717 * @return string HTML
718 */
719 protected function getUserTools() {
720 if( $this->file->userCan( Revision::DELETED_USER ) ) {
721 $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
722 $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
723 } else {
724 $link = wfMsgHtml( 'rev-deleted-user' );
725 }
726 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
727 return '<span class="history-deleted">' . $link . '</span>';
728 }
729 return $link;
730 }
731
732 /**
733 * Wrap and format the file's comment block, if the current
734 * user is allowed to view it.
735 *
736 * @return string HTML
737 */
738 protected function getComment() {
739 if( $this->file->userCan( File::DELETED_COMMENT ) ) {
740 $block = $this->special->skin->commentBlock( $this->file->description );
741 } else {
742 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
743 }
744 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
745 return "<span class=\"history-deleted\">$block</span>";
746 }
747 return $block;
748 }
749
750 public function getHTML() {
751 global $wgLang;
752 $data =
753 wfMsg(
754 'widthheight',
755 $wgLang->formatNum( $this->file->getWidth() ),
756 $wgLang->formatNum( $this->file->getHeight() )
757 ) .
758 ' (' .
759 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
760 ')';
761
762 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
763 $data . ' ' . $this->getComment(). '</li>';
764 }
765 }
766
767 /**
768 * List for filearchive table items
769 */
770 class RevDel_ArchivedFileList extends RevDel_FileList {
771 var $type = 'filearchive';
772 var $idField = 'fa_id';
773 var $dateField = 'fa_timestamp';
774 var $authorIdField = 'fa_user';
775 var $authorNameField = 'fa_user_text';
776
777 public function doQuery( $db ) {
778 $ids = array_map( 'intval', $this->ids );
779 return $db->select( 'filearchive', '*',
780 array(
781 'fa_name' => $this->title->getDBkey(),
782 'fa_id' => $ids
783 ),
784 __METHOD__,
785 array( 'ORDER BY' => 'fa_id DESC' )
786 );
787 }
788
789 public function newItem( $row ) {
790 return new RevDel_ArchivedFileItem( $this, $row );
791 }
792 }
793
794 /**
795 * Item class for a filearchive table row
796 */
797 class RevDel_ArchivedFileItem extends RevDel_FileItem {
798 public function __construct( $list, $row ) {
799 parent::__construct( $list, $row );
800 $this->file = ArchivedFile::newFromRow( $row );
801 }
802
803 public function getId() {
804 return $this->row->fa_id;
805 }
806
807 public function setBits( $bits ) {
808 $dbw = wfGetDB( DB_MASTER );
809 $dbw->update( 'filearchive',
810 array( 'fa_deleted' => $bits ),
811 array(
812 'fa_id' => $this->row->fa_id,
813 'fa_deleted' => $this->getBits(),
814 ),
815 __METHOD__
816 );
817 return (bool)$dbw->affectedRows();
818 }
819
820 protected function getLink() {
821 global $wgLang, $wgUser;
822 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
823 $undelete = SpecialPage::getTitleFor( 'Undelete' );
824 $key = $this->file->getKey();
825 # Hidden files...
826 if( !$this->canViewContent() ) {
827 $link = $date;
828 } else {
829 $link = $this->special->skin->link( $undelete, $date, array(),
830 array(
831 'target' => $this->list->title->getPrefixedText(),
832 'file' => $key,
833 'token' => $wgUser->editToken( $key )
834 )
835 );
836 }
837 if( $this->isDeleted() ) {
838 $link = '<span class="history-deleted">' . $link . '</span>';
839 }
840 return $link;
841 }
842 }
843
844 /**
845 * List for logging table items
846 */
847 class RevDel_LogList extends RevDel_List {
848 var $type = 'logging';
849 var $idField = 'log_id';
850 var $dateField = 'log_timestamp';
851 var $authorIdField = 'log_user';
852 var $authorNameField = 'log_user_text';
853
854 public function doQuery( $db ) {
855 $ids = array_map( 'intval', $this->ids );
856 return $db->select( 'logging', '*',
857 array( 'log_id' => $ids ),
858 __METHOD__,
859 array( 'ORDER BY' => 'log_id DESC' )
860 );
861 }
862
863 public function newItem( $row ) {
864 return new RevDel_LogItem( $this, $row );
865 }
866
867 public function getSuppressBit() {
868 return Revision::DELETED_RESTRICTED;
869 }
870
871 public function getLogAction() {
872 return 'event';
873 }
874
875 public function getLogParams( $params ) {
876 return array(
877 implode( ',', $params['ids'] ),
878 "ofield={$params['oldBits']}",
879 "nfield={$params['newBits']}"
880 );
881 }
882 }
883
884 /**
885 * Item class for a logging table row
886 */
887 class RevDel_LogItem extends RevDel_Item {
888 public function canView() {
889 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
890 }
891
892 public function canViewContent() {
893 return true; // none
894 }
895
896 public function getBits() {
897 return $this->row->log_deleted;
898 }
899
900 public function setBits( $bits ) {
901 $dbw = wfGetDB( DB_MASTER );
902 $dbw->update( 'recentchanges',
903 array(
904 'rc_deleted' => $bits,
905 'rc_patrolled' => 1
906 ),
907 array(
908 'rc_logid' => $this->row->log_id,
909 'rc_timestamp' => $this->row->log_timestamp // index
910 ),
911 __METHOD__
912 );
913 $dbw->update( 'logging',
914 array( 'log_deleted' => $bits ),
915 array(
916 'log_id' => $this->row->log_id,
917 'log_deleted' => $this->getBits()
918 ),
919 __METHOD__
920 );
921 return (bool)$dbw->affectedRows();
922 }
923
924 public function getHTML() {
925 global $wgLang;
926
927 $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
928 $paramArray = LogPage::extractParams( $this->row->log_params );
929 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
930
931 // Log link for this page
932 $loglink = $this->special->skin->link(
933 SpecialPage::getTitleFor( 'Log' ),
934 wfMsgHtml( 'log' ),
935 array(),
936 array( 'page' => $title->getPrefixedText() )
937 );
938 // Action text
939 if( !$this->canView() ) {
940 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
941 } else {
942 $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
943 $this->special->skin, $paramArray, true, true );
944 if( $this->row->log_deleted & LogPage::DELETED_ACTION )
945 $action = '<span class="history-deleted">' . $action . '</span>';
946 }
947 // User links
948 $userLink = $this->special->skin->userLink( $this->row->log_user,
949 User::WhoIs( $this->row->log_user ) );
950 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
951 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
952 }
953 // Comment
954 $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
955 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
956 $comment = '<span class="history-deleted">' . $comment . '</span>';
957 }
958 return "<li>($loglink) $date $userLink $action $comment</li>";
959 }
960 }