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