344589315384757b4411362a79b9e701d9536545
[lhc/web/wiklou.git] / includes / specials / SpecialRevisiondelete.php
1 <?php
2 /**
3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
5 *
6 * @file
7 * @ingroup SpecialPage
8 */
9
10 class SpecialRevisionDelete extends UnlistedSpecialPage {
11 /** Skin object */
12 var $skin;
13
14 /** True if the submit button was clicked, and the form was posted */
15 var $submitClicked;
16
17 /** Target ID list */
18 var $ids;
19
20 /** Archive name, for reviewing deleted files */
21 var $archiveName;
22
23 /** Edit token for securing image views against XSS */
24 var $token;
25
26 /** Title object for target parameter */
27 var $targetObj;
28
29 /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
30 var $typeName;
31
32 /** Array of checkbox specs (message, name, deletion bits) */
33 var $checks;
34
35 /** Information about the current type */
36 var $typeInfo;
37
38 /** The RevDel_List object, storing the list of items to be deleted/undeleted */
39 var $list;
40
41 /**
42 * Assorted information about each type, needed by the special page.
43 * TODO Move some of this to the list class
44 */
45 static $allowedTypes = array(
46 'revision' => array(
47 'check-label' => 'revdelete-hide-text',
48 'deletion-bits' => Revision::DELETED_TEXT,
49 'success' => 'revdelete-success',
50 'failure' => 'revdelete-failure',
51 'list-class' => 'RevDel_RevisionList',
52 ),
53 'archive' => array(
54 'check-label' => 'revdelete-hide-text',
55 'deletion-bits' => Revision::DELETED_TEXT,
56 'success' => 'revdelete-success',
57 'failure' => 'revdelete-failure',
58 'list-class' => 'RevDel_ArchiveList',
59 ),
60 'oldimage'=> array(
61 'check-label' => 'revdelete-hide-image',
62 'deletion-bits' => File::DELETED_FILE,
63 'success' => 'revdelete-success',
64 'failure' => 'revdelete-failure',
65 'list-class' => 'RevDel_FileList',
66 ),
67 'filearchive' => array(
68 'check-label' => 'revdelete-hide-image',
69 'deletion-bits' => File::DELETED_FILE,
70 'success' => 'revdelete-success',
71 'failure' => 'revdelete-failure',
72 'list-class' => 'RevDel_ArchivedFileList',
73 ),
74 'logging' => array(
75 'check-label' => 'revdelete-hide-name',
76 'deletion-bits' => LogPage::DELETED_ACTION,
77 'success' => 'logdelete-success',
78 'failure' => 'logdelete-failure',
79 'list-class' => 'RevDel_LogList',
80 ),
81 );
82
83 /** Type map to support old log entries */
84 static $deprecatedTypeMap = array(
85 'oldid' => 'revision',
86 'artimestamp' => 'archive',
87 'oldimage' => 'oldimage',
88 'fileid' => 'filearchive',
89 'logid' => 'logging',
90 );
91
92 public function __construct() {
93 parent::__construct( 'Revisiondelete', 'deleterevision' );
94 }
95
96 public function execute( $par ) {
97 global $wgOut, $wgUser, $wgRequest;
98 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
99 $wgOut->permissionRequired( 'deleterevision' );
100 return;
101 } else if( wfReadOnly() ) {
102 $wgOut->readOnlyPage();
103 return;
104 }
105 $this->skin = $wgUser->getSkin();
106 $this->setHeaders();
107 $this->outputHeader();
108 $this->submitClicked = $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
109 # Handle our many different possible input types.
110 # Use CSV, since the cgi handling will break on arrays.
111 $this->ids = explode( ',', $wgRequest->getVal('ids') );
112 $this->ids = array_unique( array_filter( $this->ids ) );
113 $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
114
115 # For reviewing deleted files...
116 $this->archiveName = $wgRequest->getVal( 'file' );
117 $this->token = $wgRequest->getVal( 'token' );
118 if ( $this->archiveName && $this->targetObj ) {
119 $this->tryShowFile( $this->archiveName );
120 return;
121 }
122
123 $this->typeName = $wgRequest->getVal( 'type' );
124 if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) {
125 $this->typeName = self::$deprecatedTypeMap[$this->typeName];
126 }
127
128 # No targets?
129 if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) {
130 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
131 return;
132 }
133 $this->typeInfo = self::$allowedTypes[$this->typeName];
134
135 # If we have revisions, get the title from the first one
136 # since they should all be from the same page. This allows
137 # for more flexibility with page moves...
138 if( $this->typeName == 'revision' ) {
139 $rev = Revision::newFromId( $this->ids[0] );
140 $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj;
141 }
142 # We need a target page!
143 if( is_null($this->targetObj) ) {
144 $wgOut->addWikiMsg( 'undelete-header' );
145 return;
146 }
147 # Give a link to the logs/hist for this page
148 $this->showConvenienceLinks();
149
150 # Initialise checkboxes
151 $this->checks = array(
152 array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ),
153 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
154 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
155 );
156 if( $wgUser->isAllowed('suppressrevision') ) {
157 $this->checks[] = array( 'revdelete-hide-restricted',
158 'wpHideRestricted', Revision::DELETED_RESTRICTED );
159 }
160
161 # Either submit or create our form
162 if( $this->submitClicked ) {
163 $this->submit( $wgRequest );
164 } else {
165 $this->showForm();
166 }
167 $qc = $this->getLogQueryCond();
168 # Show relevant lines from the deletion log
169 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
170 LogEventsList::showLogExtract( $wgOut, 'delete',
171 $this->targetObj->getPrefixedText(), '', 25, $qc );
172 # Show relevant lines from the suppression log
173 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
174 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
175 LogEventsList::showLogExtract( $wgOut, 'suppress',
176 $this->targetObj->getPrefixedText(), '', 25, $qc );
177 }
178 }
179
180 /**
181 * Show some useful links in the subtitle
182 */
183 protected function showConvenienceLinks() {
184 global $wgOut, $wgUser, $wgLang;
185 # Give a link to the logs/hist for this page
186 if( $this->targetObj ) {
187 $links = array();
188 $logtitle = SpecialPage::getTitleFor( 'Log' );
189 $links[] = $this->skin->linkKnown(
190 $logtitle,
191 wfMsgHtml( 'viewpagelogs' ),
192 array(),
193 array( 'page' => $this->targetObj->getPrefixedText() )
194 );
195 if ( $this->targetObj->getNamespace() != NS_SPECIAL ) {
196 # Give a link to the page history
197 $links[] = $this->skin->linkKnown(
198 $this->targetObj,
199 wfMsgHtml( 'pagehist' ),
200 array(),
201 array( 'action' => 'history' )
202 );
203 # Link to deleted edits
204 if( $wgUser->isAllowed('undelete') ) {
205 $undelete = SpecialPage::getTitleFor( 'Undelete' );
206 $links[] = $this->skin->linkKnown(
207 $undelete,
208 wfMsgHtml( 'deletedhist' ),
209 array(),
210 array( 'target' => $this->targetObj->getPrefixedDBkey() )
211 );
212 }
213 }
214 # Logs themselves don't have histories or archived revisions
215 $wgOut->setSubtitle( '<p>' . $wgLang->pipeList( $links ) . '</p>' );
216 }
217 }
218
219 /**
220 * Get the condition used for fetching log snippets
221 */
222 protected function getLogQueryCond() {
223 $conds = array();
224 // Revision delete logs for these item
225 $conds['log_type'] = array('delete','suppress');
226 $conds['log_action'] = $this->getList()->getLogAction();
227 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
228 $conds['ls_value'] = $this->ids;
229 return $conds;
230 }
231
232 /**
233 * Show a deleted file version requested by the visitor.
234 * TODO Mostly copied from Special:Undelete. Refactor.
235 */
236 protected function tryShowFile( $archiveName ) {
237 global $wgOut, $wgRequest, $wgUser, $wgLang;
238
239 $repo = RepoGroup::singleton()->getLocalRepo();
240 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName );
241 $oimage->load();
242 // Check if user is allowed to see this file
243 if ( !$oimage->exists() ) {
244 $wgOut->addWikiMsg( 'revdelete-no-file' );
245 return;
246 }
247 if( !$oimage->userCan(File::DELETED_FILE) ) {
248 $wgOut->permissionRequired( 'suppressrevision' );
249 return;
250 }
251 if ( !$wgUser->matchEditToken( $this->token, $archiveName ) ) {
252 $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
253 $this->targetObj->getText(),
254 $wgLang->date( $oimage->getTimestamp() ),
255 $wgLang->time( $oimage->getTimestamp() ) );
256 $wgOut->addHTML(
257 Xml::openElement( 'form', array(
258 'method' => 'POST',
259 'action' => $this->getTitle()->getLocalUrl(
260 'target=' . urlencode( $oimage->getName() ) .
261 '&file=' . urlencode( $archiveName ) .
262 '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
263 )
264 ) .
265 Xml::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
266 '</form>'
267 );
268 return;
269 }
270 $wgOut->disable();
271 # We mustn't allow the output to be Squid cached, otherwise
272 # if an admin previews a deleted image, and it's cached, then
273 # a user without appropriate permissions can toddle off and
274 # nab the image, and Squid will serve it
275 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
276 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
277 $wgRequest->response()->header( 'Pragma: no-cache' );
278
279 # Stream the file to the client
280 global $IP;
281 require_once( "$IP/includes/StreamFile.php" );
282 $key = $oimage->getStorageKey();
283 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
284 wfStreamFile( $path );
285 }
286
287 /**
288 * Get the list object for this request
289 */
290 protected function getList() {
291 if ( is_null( $this->list ) ) {
292 $class = $this->typeInfo['list-class'];
293 $this->list = new $class( $this, $this->targetObj, $this->ids );
294 }
295 return $this->list;
296 }
297
298 /**
299 * Show a list of items that we will operate on, and show a form with checkboxes
300 * which will allow the user to choose new visibility settings.
301 */
302 protected function showForm() {
303 global $wgOut, $wgUser, $wgLang;
304 $UserAllowed = true;
305
306 if ( $this->typeName == 'logging' ) {
307 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids) ) );
308 } else {
309 $wgOut->addWikiMsg( 'revdelete-selected',
310 $this->targetObj->getPrefixedText(), count( $this->ids ) );
311 }
312
313 $bitfields = 0;
314 $wgOut->addHTML( "<ul>" );
315
316 $where = $revObjs = array();
317
318 $numRevisions = 0;
319 // Live revisions...
320 $list = $this->getList();
321 for ( $list->reset(); $list->current(); $list->next() ) {
322 $item = $list->current();
323 if ( !$item->canView() ) {
324 if( !$this->submitClicked ) {
325 $wgOut->permissionRequired( 'suppressrevision' );
326 return;
327 }
328 $UserAllowed = false;
329 }
330 $numRevisions++;
331 $bitfields |= $item->getBits();
332 $wgOut->addHTML( $item->getHTML() );
333 }
334
335 if( !$numRevisions ) {
336 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
337 return;
338 }
339
340 $wgOut->addHTML( "</ul>" );
341 // Explanation text
342 $this->addUsageText();
343
344 // Normal sysops can always see what they did, but can't always change it
345 if( !$UserAllowed ) return;
346
347 $wgOut->addHTML(
348 Xml::openElement( 'form', array( 'method' => 'post',
349 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ),
350 'id' => 'mw-revdel-form-revisions' ) ) .
351 Xml::openElement( 'fieldset' ) .
352 Xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) ) .
353 $this->buildCheckBoxes( $bitfields ) .
354 '<p>' . Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ) . '</p>' .
355 '<p>' . Xml::submitButton( wfMsg( 'revdelete-submit' ),
356 array( 'name' => 'wpSubmit' ) ) . '</p>' .
357 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
358 Xml::hidden( 'target', $this->targetObj->getPrefixedText() ) .
359 Xml::hidden( 'type', $this->typeName ) .
360 Xml::hidden( 'ids', implode( ',', $this->ids ) ) .
361 Xml::closeElement( 'fieldset' ) .
362 Xml::closeElement( 'form' ) . "\n"
363 );
364 }
365
366 /**
367 * Show some introductory text
368 * FIXME Wikimedia-specific policy text
369 */
370 protected function addUsageText() {
371 global $wgOut, $wgUser;
372 $wgOut->addWikiMsg( 'revdelete-text' );
373 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
374 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
375 }
376 }
377
378 /**
379 * @param $bitfields Interger: aggregate bitfield of all the bitfields
380 * @return String: HTML
381 */
382 protected function buildCheckBoxes( $bitfields ) {
383 $html = '';
384 // FIXME: all items checked for just one rev are checked, even if not set for the others
385 foreach( $this->checks as $item ) {
386 list( $message, $name, $field ) = $item;
387 $line = Xml::tags( 'div', null, Xml::checkLabel( wfMsg($message), $name, $name,
388 $bitfields & $field ) );
389 if( $field == Revision::DELETED_RESTRICTED ) $line = "<b>$line</b>";
390 $html .= $line;
391 }
392 return $html;
393 }
394
395 /**
396 * UI entry point for form submission.
397 * @param $request WebRequest
398 */
399 protected function submit( $request ) {
400 global $wgUser, $wgOut;
401 # Check edit token on submission
402 if( $this->submitClicked && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
403 $wgOut->addWikiMsg( 'sessionfailure' );
404 return false;
405 }
406 $bitfield = $this->extractBitfield( $request );
407 $comment = $request->getText( 'wpReason' );
408 # Can the user set this field?
409 if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
410 $wgOut->permissionRequired( 'suppressrevision' );
411 return false;
412 }
413 # If the save went through, go to success message...
414 $status = $this->save( $bitfield, $comment, $this->targetObj );
415 if ( $status->isGood() ) {
416 $this->success();
417 return true;
418 # ...otherwise, bounce back to form...
419 } else {
420 $this->failure( $status );
421 }
422 return false;
423 }
424
425 /**
426 * Report that the submit operation succeeded
427 */
428 protected function success() {
429 global $wgOut;
430 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
431 $wgOut->wrapWikiMsg( '<span class="success">$1</span>', $this->typeInfo['success'] );
432 $this->list->reloadFromMaster();
433 $this->showForm();
434 }
435
436 /**
437 * Report that the submit operation failed
438 */
439 protected function failure( $status ) {
440 global $wgOut;
441 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
442 $wgOut->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) );
443 $this->showForm();
444 }
445
446 /**
447 * Put together a rev_deleted bitfield from the submitted checkboxes
448 * @param $request WebRequest
449 * @return Integer
450 */
451 protected function extractBitfield( $request ) {
452 $bitfield = 0;
453 foreach( $this->checks as $item ) {
454 list( /* message */ , $name, $field ) = $item;
455 if( $request->getCheck( $name ) ) {
456 $bitfield |= $field;
457 }
458 }
459 return $bitfield;
460 }
461
462 /**
463 * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
464 */
465 protected function save( $bitfield, $reason, $title ) {
466 // Don't allow simply locking the interface for no reason
467 if( $bitfield == Revision::DELETED_RESTRICTED ) {
468 return Status::newFatal( 'revdelete-only-restricted' );
469 }
470 return $this->getList()->setVisibility( array(
471 'value' => $bitfield,
472 'comment' => $reason ) );
473 }
474 }
475
476 /**
477 * Temporary b/c interface, collection of static functions.
478 * @ingroup SpecialPage
479 */
480 class RevisionDeleter {
481 /**
482 * Checks for a change in the bitfield for a certain option and updates the
483 * provided array accordingly.
484 *
485 * @param $desc String: description to add to the array if the option was
486 * enabled / disabled.
487 * @param $field Integer: the bitmask describing the single option.
488 * @param $diff Integer: the xor of the old and new bitfields.
489 * @param $new Integer: the new bitfield
490 * @param $arr Array: the array to update.
491 */
492 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
493 if( $diff & $field ) {
494 $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
495 }
496 }
497
498 /**
499 * Gets an array describing the changes made to the visibilit of the revision.
500 * If the resulting array is $arr, then $arr[0] will contain an array of strings
501 * describing the items that were hidden, $arr[2] will contain an array of strings
502 * describing the items that were unhidden, and $arr[3] will contain an array with
503 * a single string, which can be one of "applied restrictions to sysops",
504 * "removed restrictions from sysops", or null.
505 *
506 * @param $n Integer: the new bitfield.
507 * @param $o Integer: the old bitfield.
508 * @return An array as described above.
509 */
510 protected static function getChanges( $n, $o ) {
511 $diff = $n ^ $o;
512 $ret = array( 0 => array(), 1 => array(), 2 => array() );
513 // Build bitfield changes in language
514 self::checkItem( wfMsgForContent( 'revdelete-content' ),
515 Revision::DELETED_TEXT, $diff, $n, $ret );
516 self::checkItem( wfMsgForContent( 'revdelete-summary' ),
517 Revision::DELETED_COMMENT, $diff, $n, $ret );
518 self::checkItem( wfMsgForContent( 'revdelete-uname' ),
519 Revision::DELETED_USER, $diff, $n, $ret );
520 // Restriction application to sysops
521 if( $diff & Revision::DELETED_RESTRICTED ) {
522 if( $n & Revision::DELETED_RESTRICTED )
523 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
524 else
525 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
526 }
527 return $ret;
528 }
529
530 /**
531 * Gets a log message to describe the given revision visibility change. This
532 * message will be of the form "[hid {content, edit summary, username}];
533 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
534 *
535 * @param $count Integer: The number of effected revisions.
536 * @param $nbitfield Integer: The new bitfield for the revision.
537 * @param $obitfield Integer: The old bitfield for the revision.
538 * @param $isForLog Boolean
539 */
540 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
541 global $wgLang;
542 $s = '';
543 $changes = self::getChanges( $nbitfield, $obitfield );
544 if( count( $changes[0] ) ) {
545 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
546 }
547 if( count( $changes[1] ) ) {
548 if ($s) $s .= '; ';
549 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
550 }
551 if( count( $changes[2] ) ) {
552 $s .= $s ? ' (' . $changes[2][0] . ')' : $changes[2][0];
553 }
554 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
555 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
556
557 }
558
559 // Get DB field name for URL param...
560 // Future code for other things may also track
561 // other types of revision-specific changes.
562 public static function getRelationType( $typeName ) {
563 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
564 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
565 }
566 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
567 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
568 $list = new $class( null, null, null );
569 return $list->getIdField();
570 } else {
571 return null;
572 }
573 }
574 }
575
576 /**
577 * Abstract base class for a list of deletable items
578 */
579 abstract class RevDel_List {
580 var $special, $title, $ids, $res, $current;
581 var $type = null; // override this
582 var $idField = null; // override this
583 var $dateField = false; // override this
584
585 /**
586 * @param $special The parent SpecialPage
587 * @param $title The target title
588 * @param $ids Array of IDs
589 */
590 public function __construct( $special, $title, $ids ) {
591 $this->special = $special;
592 $this->title = $title;
593 $this->ids = $ids;
594 }
595
596 /**
597 * Get the internal type name of this list. Equal to the table name.
598 */
599 public function getType() {
600 return $this->type;
601 }
602
603 /**
604 * Get the DB field name associated with the ID list/
605 */
606 public function getIdField() {
607 return $this->idField;
608 }
609
610 /**
611 * Get the DB field name storing timestamps
612 */
613 public function getTimestampField() {
614 return $this->dateField;
615 }
616
617 /**
618 * Set the visibility for the revisions in this list. Logging and
619 * transactions are done here.
620 *
621 * @param $params Associative array of parameters. Members are:
622 * value: The integer value to set the visibility to
623 * comment: The log comment.
624 * @return Status
625 */
626 public function setVisibility( $params ) {
627 $newBits = $params['value'];
628 $comment = $params['comment'];
629
630 $this->res = false;
631 $dbw = wfGetDB( DB_MASTER );
632 $this->doQuery( $dbw );
633 $dbw->begin();
634 $status = Status::newGood();
635 $missing = array_flip( $this->ids );
636 $this->clearFileOps();
637 $idsForLog = array();
638
639 for ( $this->reset(); $this->current(); $this->next() ) {
640 $item = $this->current();
641 unset( $missing[ $item->getId() ] );
642
643 // Make error messages less vague
644 $oldBits = $item->getBits();
645 if ( $oldBits == $newBits ) {
646 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
647 $status->failCount++;
648 continue;
649 } elseif ( $oldBits == 0 && $newBits != 0 ) {
650 $opType = 'hide';
651 } elseif ( $oldBits != 0 && $newBits == 0 ) {
652 $opType = 'show';
653 } else {
654 $opType = 'modify';
655 }
656
657 if ( $item->isHideCurrentOp( $newBits ) ) {
658 // Cannot hide current version text
659 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
660 $status->failCount++;
661 continue;
662 }
663 if ( !$item->canView() ) {
664 // Cannot access this revision
665 $msg = $opType == 'show' ? 'revdelete-show-no-access' : 'revdelete-modify-no-access';
666 $status->error( $msg, $item->formatDate(), $item->formatTime() );
667 $status->failCount++;
668 continue;
669 }
670
671 // Update the revision
672 $ok = $item->setBits( $newBits );
673
674 if ( $ok ) {
675 $idsForLog[] = $item->getId();
676 $status->successCount++;
677 } else {
678 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
679 $status->failCount++;
680 }
681 }
682
683 // Handle missing revisions
684 foreach ( $missing as $id => $unused ) {
685 $status->error( 'revdelete-modify-missing', $id );
686 $status->failCount++;
687 }
688
689 if ( $status->successCount == 0 ) {
690 $status->ok = false;
691 $dbw->rollback();
692 return $status;
693 }
694
695 // Save success count
696 $successCount = $status->successCount;
697
698 // Move files, if there are any
699 $status->merge( $this->doPreCommitUpdates() );
700 if ( !$status->isOK() ) {
701 // Fatal error, such as no configured archive directory
702 $dbw->rollback();
703 return $status;
704 }
705
706 // Log it
707 $this->updateLog( array(
708 'title' => $this->title,
709 'count' => $successCount,
710 'newBits' => $newBits,
711 'oldBits' => $oldBits,
712 'comment' => $comment,
713 'ids' => $idsForLog,
714 ) );
715 $dbw->commit();
716
717 // Clear caches
718 $status->merge( $this->doPostCommitUpdates() );
719 return $status;
720 }
721
722 /**
723 * Reload the list data from the master DB. This can be done after setVisibility()
724 * to allow $item->getHTML() to show the new data.
725 */
726 function reloadFromMaster() {
727 $dbw = wfGetDB( DB_MASTER );
728 $this->res = $this->doQuery( $dbw );
729 }
730
731 /**
732 * Record a log entry on the action
733 * @param $params Associative array of parameters:
734 * newBits: The new value of the *_deleted bitfield
735 * oldBits: The old value of the *_deleted bitfield.
736 * title: The target title
737 * ids: The ID list
738 * comment: The log comment
739 */
740 protected function updateLog( $params ) {
741 // Get the URL param's corresponding DB field
742 $field = RevisionDeleter::getRelationType( $this->getType() );
743 if( !$field ) {
744 throw new MWException( "Bad log URL param type!" );
745 }
746 // Put things hidden from sysops in the oversight log
747 if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
748 $logType = 'suppress';
749 } else {
750 $logType = 'delete';
751 }
752 // Add params for effected page and ids
753 $logParams = $this->getLogParams( $params );
754 // Actually add the deletion log entry
755 $log = new LogPage( $logType );
756 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
757 $params['comment'], $logParams );
758 // Allow for easy searching of deletion log items for revision/log items
759 $log->addRelations( $field, $params['ids'], $logid );
760 }
761
762 /**
763 * Get the log action for this list type
764 */
765 public function getLogAction() {
766 return 'revision';
767 }
768
769 /**
770 * Get log parameter array.
771 * @param $params Associative array of log parameters, same as updateLog()
772 * @return array
773 */
774 public function getLogParams( $params ) {
775 return array(
776 $this->getType(),
777 implode( ',', $params['ids'] ),
778 "ofield={$params['oldBits']}",
779 "nfield={$params['newBits']}"
780 );
781 }
782
783 /**
784 * Initialise the current iteration pointer
785 */
786 protected function initCurrent() {
787 $row = $this->res->current();
788 if ( $row ) {
789 $this->current = $this->newItem( $row );
790 } else {
791 $this->current = false;
792 }
793 }
794
795 /**
796 * Start iteration. This must be called before current() or next().
797 * @return First list item
798 */
799 public function reset() {
800 if ( !$this->res ) {
801 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
802 } else {
803 $this->res->rewind();
804 }
805 $this->initCurrent();
806 return $this->current;
807 }
808
809 /**
810 * Get the current list item, or false if we are at the end
811 */
812 public function current() {
813 return $this->current;
814 }
815
816 /**
817 * Move the iteration pointer to the next list item, and return it.
818 */
819 public function next() {
820 $this->res->next();
821 $this->initCurrent();
822 return $this->current;
823 }
824
825 /**
826 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
827 * STUB
828 */
829 public function clearFileOps() {
830 }
831
832 /**
833 * A hook for setVisibility(): do batch updates pre-commit.
834 * STUB
835 * @return Status
836 */
837 public function doPreCommitUpdates() {
838 return Status::newGood();
839 }
840
841 /**
842 * A hook for setVisibility(): do any necessary updates post-commit.
843 * STUB
844 * @return Status
845 */
846 public function doPostCommitUpdates() {
847 return Status::newGood();
848 }
849
850 /**
851 * Create an item object from a DB result row
852 * @param $row stdclass
853 */
854 abstract public function newItem( $row );
855
856 /**
857 * Do the DB query to iterate through the objects.
858 * @param $db Database object to use for the query
859 */
860 abstract public function doQuery( $db );
861
862 /**
863 * Get the integer value of the flag used for suppression
864 */
865 abstract public function getSuppressBit();
866 }
867
868 /**
869 * Abstract base class for deletable items
870 */
871 abstract class RevDel_Item {
872 /** The parent SpecialPage */
873 var $special;
874
875 /** The parent RevDel_List */
876 var $list;
877
878 /** The DB result row */
879 var $row;
880
881 /**
882 * @param $list RevDel_List
883 * @param $row DB result row
884 */
885 public function __construct( $list, $row ) {
886 $this->special = $list->special;
887 $this->list = $list;
888 $this->row = $row;
889 }
890
891 /**
892 * Get the ID, as it would appear in the ids URL parameter
893 */
894 public function getId() {
895 $field = $this->list->getIdField();
896 return $this->row->$field;
897 }
898
899 /**
900 * Get the date, formatted with $wgLang
901 */
902 public function formatDate() {
903 global $wgLang;
904 return $wgLang->date( $this->getTimestamp() );
905 }
906
907 /**
908 * Get the time, formatted with $wgLang
909 */
910 public function formatTime() {
911 global $wgLang;
912 return $wgLang->time( $this->getTimestamp() );
913 }
914
915 /**
916 * Get the timestamp in MW 14-char form
917 */
918 public function getTimestamp() {
919 $field = $this->list->getTimestampField();
920 return wfTimestamp( TS_MW, $this->row->$field );
921 }
922
923 /**
924 * Returns true if the item is "current", and the operation to set the given
925 * bits can't be executed for that reason
926 * STUB
927 */
928 public function isHideCurrentOp( $newBits ) {
929 return false;
930 }
931
932 /**
933 * Returns true if the current user can view the item
934 */
935 abstract public function canView();
936
937 /**
938 * Get the current deletion bitfield value
939 */
940 abstract public function getBits();
941
942 /**
943 * Get the HTML of the list item. Should be include <li></li> tags.
944 * This is used to show the list in HTML form, by the special page.
945 */
946 abstract public function getHTML();
947
948 /**
949 * Set the visibility of the item. This should do any necessary DB queries.
950 *
951 * The DB update query should have a condition which forces it to only update
952 * if the value in the DB matches the value fetched earlier with the SELECT.
953 * If the update fails because it did not match, the function should return
954 * false. This prevents concurrency problems.
955 *
956 * @return boolean success
957 */
958 abstract public function setBits( $newBits );
959 }
960
961 /**
962 * List for revision table items
963 */
964 class RevDel_RevisionList extends RevDel_List {
965 var $currentRevId;
966 var $type = 'revision';
967 var $idField = 'rev_id';
968 var $dateField = 'rev_timestamp';
969
970 public function doQuery( $db ) {
971 $ids = array_map( 'intval', $this->ids );
972 return $db->select( array('revision','page'), '*',
973 array(
974 'rev_page' => $this->title->getArticleID(),
975 'rev_id' => $ids,
976 'rev_page = page_id'
977 ),
978 __METHOD__
979 );
980 }
981
982 public function newItem( $row ) {
983 return new RevDel_RevisionItem( $this, $row );
984 }
985
986 public function getCurrent() {
987 if ( is_null( $this->currentRevId ) ) {
988 $dbw = wfGetDB( DB_MASTER );
989 $this->currentRevId = $dbw->selectField(
990 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
991 }
992 return $this->currentRevId;
993 }
994
995 public function getSuppressBit() {
996 return Revision::DELETED_RESTRICTED;
997 }
998
999 public function doPreCommitUpdates() {
1000 $this->title->invalidateCache();
1001 return Status::newGood();
1002 }
1003
1004 public function doPostCommitUpdates() {
1005 $this->title->purgeSquid();
1006 // Extensions that require referencing previous revisions may need this
1007 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title ) );
1008 return Status::newGood();
1009 }
1010 }
1011
1012 /**
1013 * Item class for a revision table row
1014 */
1015 class RevDel_RevisionItem extends RevDel_Item {
1016 var $revision;
1017
1018 public function __construct( $list, $row ) {
1019 parent::__construct( $list, $row );
1020 $this->revision = new Revision( $row );
1021 }
1022
1023 public function canView() {
1024 return $this->revision->userCan( Revision::DELETED_RESTRICTED );
1025 }
1026
1027 public function getBits() {
1028 return $this->revision->mDeleted;
1029 }
1030
1031 public function setBits( $bits ) {
1032 $dbw = wfGetDB( DB_MASTER );
1033 // Update revision table
1034 $dbw->update( 'revision',
1035 array( 'rev_deleted' => $bits ),
1036 array(
1037 'rev_id' => $this->revision->getId(),
1038 'rev_page' => $this->revision->getPage(),
1039 'rev_deleted' => $this->getBits()
1040 ),
1041 __METHOD__
1042 );
1043 if ( !$dbw->affectedRows() ) {
1044 // Concurrent fail!
1045 return false;
1046 }
1047 // Update recentchanges table
1048 $dbw->update( 'recentchanges',
1049 array(
1050 'rc_deleted' => $bits,
1051 'rc_patrolled' => 1
1052 ),
1053 array(
1054 'rc_this_oldid' => $this->revision->getId(), // condition
1055 // non-unique timestamp index
1056 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
1057 ),
1058 __METHOD__
1059 );
1060 return true;
1061 }
1062
1063 public function isDeleted() {
1064 return $this->revision->isDeleted( Revision::DELETED_TEXT );
1065 }
1066
1067 public function isHideCurrentOp( $newBits ) {
1068 return ( $newBits & Revision::DELETED_TEXT )
1069 && $this->list->getCurrent() == $this->getId();
1070 }
1071
1072 /**
1073 * Get the HTML link to the revision text.
1074 * Overridden by RevDel_ArchiveItem.
1075 */
1076 protected function getRevisionLink() {
1077 global $wgLang;
1078 $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
1079 if ( $this->isDeleted() && !$this->canView() ) {
1080 return $date;
1081 }
1082 return $this->special->skin->link(
1083 $this->list->title,
1084 $date,
1085 array(),
1086 array(
1087 'oldid' => $this->revision->getId(),
1088 'unhide' => 1
1089 )
1090 );
1091 }
1092
1093 /**
1094 * Get the HTML link to the diff.
1095 * Overridden by RevDel_ArchiveItem
1096 */
1097 protected function getDiffLink() {
1098 if ( $this->isDeleted() && !$this->canView() ) {
1099 return wfMsgHtml('diff');
1100 } else {
1101 return
1102 $this->special->skin->link(
1103 $this->list->title,
1104 wfMsgHtml('diff'),
1105 array(),
1106 array(
1107 'diff' => $this->revision->getId(),
1108 'oldid' => 'prev',
1109 'unhide' => 1
1110 ),
1111 array(
1112 'known',
1113 'noclasses'
1114 )
1115 );
1116 }
1117 }
1118
1119 public function getHTML() {
1120 $difflink = $this->getDiffLink();
1121 $revlink = $this->getRevisionLink();
1122 $userlink = $this->special->skin->revUserLink( $this->revision );
1123 $comment = $this->special->skin->revComment( $this->revision );
1124 if ( $this->isDeleted() ) {
1125 $revlink = "<span class=\"history-deleted\">$revlink</span>";
1126 }
1127 return "<li>($difflink) $revlink $userlink $comment</li>";
1128 }
1129 }
1130
1131 /**
1132 * List for archive table items, i.e. revisions deleted via action=delete
1133 */
1134 class RevDel_ArchiveList extends RevDel_RevisionList {
1135 var $type = 'archive';
1136 var $idField = 'ar_timestamp';
1137 var $dateField = 'ar_timestamp';
1138
1139 public function doQuery( $db ) {
1140 $timestamps = array();
1141 foreach ( $this->ids as $id ) {
1142 $timestamps[] = $db->timestamp( $id );
1143 }
1144 return $db->select( 'archive', '*',
1145 array(
1146 'ar_namespace' => $this->title->getNamespace(),
1147 'ar_title' => $this->title->getDBkey(),
1148 'ar_timestamp' => $timestamps
1149 ),
1150 __METHOD__
1151 );
1152 }
1153
1154 public function newItem( $row ) {
1155 return new RevDel_ArchiveItem( $this, $row );
1156 }
1157
1158 public function doPreCommitUpdates() {
1159 return Status::newGood();
1160 }
1161
1162 public function doPostCommitUpdates() {
1163 return Status::newGood();
1164 }
1165 }
1166
1167 /**
1168 * Item class for a archive table row
1169 */
1170 class RevDel_ArchiveItem extends RevDel_RevisionItem {
1171 public function __construct( $list, $row ) {
1172 RevDel_Item::__construct( $list, $row );
1173 $this->revision = Revision::newFromArchiveRow( $row,
1174 array( 'page' => $this->list->title->getArticleId() ) );
1175 }
1176
1177 public function getId() {
1178 # Convert DB timestamp to MW timestamp
1179 return $this->revision->getTimestamp();
1180 }
1181
1182 public function setBits( $bits ) {
1183 $dbw = wfGetDB( DB_MASTER );
1184 $dbw->update( 'archive',
1185 array( 'ar_deleted' => $bits ),
1186 array( 'ar_namespace' => $this->list->title->getNamespace(),
1187 'ar_title' => $this->list->title->getDBkey(),
1188 // use timestamp for index
1189 'ar_timestamp' => $this->row->ar_timestamp,
1190 'ar_rev_id' => $this->row->ar_rev_id,
1191 'ar_deleted' => $this->getBits()
1192 ),
1193 __METHOD__ );
1194 return (bool)$dbw->affectedRows();
1195 }
1196
1197 protected function getRevisionLink() {
1198 global $wgLang;
1199 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1200 $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
1201 if ( $this->isDeleted() && !$this->canView() ) {
1202 return $date;
1203 }
1204 return $this->special->skin->link( $undelete, $date, array(),
1205 array(
1206 'target' => $this->list->title->getPrefixedText(),
1207 'timestamp' => $this->revision->getTimestamp()
1208 ) );
1209 }
1210
1211 protected function getDiffLink() {
1212 if ( $this->isDeleted() && !$this->canView() ) {
1213 return wfMsgHtml( 'diff' );
1214 }
1215 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1216 return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
1217 array(
1218 'target' => $this->list->title->getPrefixedText(),
1219 'diff' => 'prev',
1220 'timestamp' => $this->revision->getTimestamp()
1221 ) );
1222 }
1223 }
1224
1225 /**
1226 * List for oldimage table items
1227 */
1228 class RevDel_FileList extends RevDel_List {
1229 var $type = 'oldimage';
1230 var $idField = 'oi_archive_name';
1231 var $dateField = 'oi_timestamp';
1232 var $storeBatch, $deleteBatch, $cleanupBatch;
1233
1234 public function doQuery( $db ) {
1235 $archiveName = array();
1236 foreach( $this->ids as $timestamp ) {
1237 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
1238 }
1239 return $db->select( 'oldimage', '*',
1240 array(
1241 'oi_name' => $this->title->getDBkey(),
1242 'oi_archive_name' => $archiveNames
1243 ),
1244 __METHOD__
1245 );
1246 }
1247
1248 public function newItem( $row ) {
1249 return new RevDel_FileItem( $this, $row );
1250 }
1251
1252 public function clearFileOps() {
1253 $this->deleteBatch = array();
1254 $this->storeBatch = array();
1255 $this->cleanupBatch = array();
1256 }
1257
1258 public function doPreCommitUpdates() {
1259 $status = Status::newGood();
1260 $repo = RepoGroup::singleton()->getLocalRepo();
1261 if ( $this->storeBatch ) {
1262 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
1263 }
1264 if ( !$status->isOK() ) {
1265 return $status;
1266 }
1267 if ( $this->deleteBatch ) {
1268 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
1269 }
1270 if ( !$status->isOK() ) {
1271 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1272 // modified (but destined for rollback) causes data loss
1273 return $status;
1274 }
1275 if ( $this->cleanupBatch ) {
1276 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
1277 }
1278 return $status;
1279 }
1280
1281 public function doPostCommitUpdates() {
1282 $file = wfLocalFile( $this->title );
1283 $file->purgeCache();
1284 $file->purgeDescription();
1285 return Status::newGood();
1286 }
1287
1288 public function getSuppressBit() {
1289 return File::DELETED_RESTRICTED;
1290 }
1291 }
1292
1293 /**
1294 * Item class for an oldimage table row
1295 */
1296 class RevDel_FileItem extends RevDel_Item {
1297 var $file;
1298
1299 public function __construct( $list, $row ) {
1300 parent::__construct( $list, $row );
1301 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
1302 }
1303
1304 public function getId() {
1305 $parts = explode( '!', $this->row->oi_archive_name );
1306 return $parts[0];
1307 }
1308
1309 public function canView() {
1310 return $this->file->userCan( File::DELETED_RESTRICTED );
1311 }
1312
1313 public function getBits() {
1314 /** FIXME: use accessor */
1315 return $this->file->deleted;
1316 }
1317
1318 public function setBits( $bits ) {
1319 # Queue the file op
1320 # FIXME: move to LocalFile.php
1321 if ( $this->isDeleted() ) {
1322 if ( $bits & File::DELETED_FILE ) {
1323 # Still deleted
1324 } else {
1325 # Newly undeleted
1326 $key = $this->file->getStorageKey();
1327 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1328 $this->list->storeBatch[] = array(
1329 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1330 'public',
1331 $this->file->getRel()
1332 );
1333 $this->list->cleanupBatch[] = $key;
1334 }
1335 } elseif ( $bits & File::DELETED_FILE ) {
1336 # Newly deleted
1337 $key = $this->file->getStorageKey();
1338 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1339 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
1340 }
1341
1342 # Do the database operations
1343 $dbw = wfGetDB( DB_MASTER );
1344 $dbw->update( 'oldimage',
1345 array( 'oi_deleted' => $bits ),
1346 array(
1347 'oi_name' => $this->row->oi_name,
1348 'oi_timestamp' => $this->row->oi_timestamp,
1349 'oi_deleted' => $this->getBits()
1350 ),
1351 __METHOD__
1352 );
1353 return (bool)$dbw->affectedRows();
1354 }
1355
1356 public function isDeleted() {
1357 return $this->file->isDeleted( File::DELETED_FILE );
1358 }
1359
1360 /**
1361 * Get the link to the file.
1362 * Overridden by RevDel_ArchivedFileItem.
1363 */
1364 protected function getLink() {
1365 global $wgLang;
1366 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1367 if ( $this->isDeleted() ) {
1368 # Hidden files...
1369 if ( !$this->canView() ) {
1370 return $date;
1371 } else {
1372 return $this->special->skin->link(
1373 $this->special->getTitle(),
1374 $date, array(),
1375 array(
1376 'target' => $this->list->title->getPrefixedText(),
1377 'file' => $this->file->sha1 . '.' . $this->file->getExtension()
1378 )
1379 );
1380 }
1381 } else {
1382 # Regular files...
1383 $url = $this->file->getUrl();
1384 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
1385 }
1386 }
1387 /**
1388 * Generate a user tool link cluster if the current user is allowed to view it
1389 * @return string HTML
1390 */
1391 protected function getUserTools() {
1392 if( $this->file->userCan( Revision::DELETED_USER ) ) {
1393 $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
1394 $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
1395 } else {
1396 $link = wfMsgHtml( 'rev-deleted-user' );
1397 }
1398 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
1399 return '<span class="history-deleted">' . $link . '</span>';
1400 }
1401 return $link;
1402 }
1403
1404 /**
1405 * Wrap and format the file's comment block, if the current
1406 * user is allowed to view it.
1407 *
1408 * @return string HTML
1409 */
1410 protected function getComment() {
1411 if( $this->file->userCan( File::DELETED_COMMENT ) ) {
1412 $block = $this->special->skin->commentBlock( $this->file->description );
1413 } else {
1414 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1415 }
1416 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
1417 return "<span class=\"history-deleted\">$block</span>";
1418 }
1419 return $block;
1420 }
1421
1422 public function getHTML() {
1423 global $wgLang;
1424 $data =
1425 wfMsg(
1426 'widthheight',
1427 $wgLang->formatNum( $this->file->getWidth() ),
1428 $wgLang->formatNum( $this->file->getHeight() )
1429 ) .
1430 ' (' .
1431 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
1432 ')';
1433 $pageLink = $this->getLink();
1434
1435 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1436 $data . ' ' . $this->getComment(). '</li>';
1437 }
1438 }
1439
1440 /**
1441 * List for filearchive table items
1442 */
1443 class RevDel_ArchivedFileList extends RevDel_FileList {
1444 var $type = 'filearchive';
1445 var $idField = 'fa_id';
1446 var $dateField = 'fa_timestamp';
1447
1448 public function doQuery( $db ) {
1449 $ids = array_map( 'intval', $this->ids );
1450 return $db->select( 'filearchive', '*',
1451 array(
1452 'fa_name' => $this->title->getDBkey(),
1453 'fa_id' => $ids
1454 ),
1455 __METHOD__
1456 );
1457 }
1458
1459 public function newItem( $row ) {
1460 return new RevDel_ArchivedFileItem( $this, $row );
1461 }
1462 }
1463
1464 /**
1465 * Item class for a filearchive table row
1466 */
1467 class RevDel_ArchivedFileItem extends RevDel_FileItem {
1468 public function __construct( $list, $row ) {
1469 RevDel_Item::__construct( $list, $row );
1470 $this->file = ArchivedFile::newFromRow( $row );
1471 }
1472
1473 public function getId() {
1474 return $this->row->fa_id;
1475 }
1476
1477 public function setBits( $bits ) {
1478 $dbw = wfGetDB( DB_MASTER );
1479 $dbw->update( 'filearchive',
1480 array( 'fa_deleted' => $bits ),
1481 array(
1482 'fa_id' => $this->row->fa_id,
1483 'fa_deleted' => $this->getBits(),
1484 ),
1485 __METHOD__
1486 );
1487 return (bool)$dbw->affectedRows();
1488 }
1489
1490 protected function getLink() {
1491 global $wgLang, $wgUser;
1492 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1493 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1494 $key = $this->file->getKey();
1495 return $this->special->skin->link( $undelete, $date, array(),
1496 array(
1497 'target' => $this->list->title->getPrefixedText(),
1498 'file' => $key,
1499 'token' => $wgUser->editToken( $key )
1500 ) );
1501 }
1502 }
1503
1504 /**
1505 * List for logging table items
1506 */
1507 class RevDel_LogList extends RevDel_List {
1508 var $type = 'logging';
1509 var $idField = 'log_id';
1510 var $dateField = 'log_timestamp';
1511
1512 public function doQuery( $db ) {
1513 global $wgMessageCache;
1514 $wgMessageCache->loadAllMessages();
1515 $ids = array_map( 'intval', $this->ids );
1516 return $db->select( 'logging', '*',
1517 array( 'log_id' => $ids ),
1518 __METHOD__
1519 );
1520 }
1521
1522 public function newItem( $row ) {
1523 return new RevDel_LogItem( $this, $row );
1524 }
1525
1526 public function getSuppressBit() {
1527 return Revision::DELETED_RESTRICTED;
1528 }
1529
1530 public function getLogAction() {
1531 return 'event';
1532 }
1533
1534 public function getLogParams( $params ) {
1535 return array(
1536 implode( ',', $params['ids'] ),
1537 "ofield={$params['oldBits']}",
1538 "nfield={$params['newBits']}"
1539 );
1540 }
1541 }
1542
1543 /**
1544 * Item class for a logging table row
1545 */
1546 class RevDel_LogItem extends RevDel_Item {
1547 public function canView() {
1548 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
1549 }
1550
1551 public function getBits() {
1552 return $this->row->log_deleted;
1553 }
1554
1555 public function setBits( $bits ) {
1556 $dbw = wfGetDB( DB_MASTER );
1557 $dbw->update( 'recentchanges',
1558 array(
1559 'rc_deleted' => $bits,
1560 'rc_patrolled' => 1
1561 ),
1562 array(
1563 'rc_logid' => $this->row->log_id,
1564 'rc_timestamp' => $this->row->log_timestamp
1565 ),
1566 __METHOD__
1567 );
1568 $dbw->update( 'logging',
1569 array( 'log_deleted' => $bits ),
1570 array(
1571 'log_id' => $this->row->log_id,
1572 'log_deleted' => $this->getBits()
1573 ),
1574 __METHOD__
1575 );
1576 return (bool)$dbw->affectedRows();
1577 }
1578
1579 public function getHTML() {
1580 global $wgLang;
1581
1582 $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
1583 $paramArray = LogPage::extractParams( $this->row->log_params );
1584 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1585
1586 $logtitle = SpecialPage::getTitleFor( 'Log' );
1587 $loglink = $this->special->skin->link(
1588 $logtitle,
1589 wfMsgHtml( 'log' ),
1590 array(),
1591 array( 'page' => $title->getPrefixedText() )
1592 );
1593 // Action text
1594 if( !$this->canView() ) {
1595 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1596 } else {
1597 $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
1598 $this->special->skin, $paramArray, true, true );
1599 if( $this->row->log_deleted & LogPage::DELETED_ACTION )
1600 $action = '<span class="history-deleted">' . $action . '</span>';
1601 }
1602 // User links
1603 $userLink = $this->special->skin->userLink(
1604 $this->row->log_user, User::WhoIs( $this->row->log_user ) );
1605 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
1606 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
1607 }
1608 // Comment
1609 $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
1610 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
1611 $comment = '<span class="history-deleted">' . $comment . '</span>';
1612 }
1613 return "<li>($loglink) $date $userLink $action $comment</li>";
1614 }
1615 }