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