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