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