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