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