* ( bug 18264 ) upload-by-url form was still disabled in non-js2 form output
[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(), '', array( 'lim' => 25, 'conds' => $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(), '', array( 'lim' => 25, 'conds' => $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 $links[] = $this->skin->linkKnown(
205 SpecialPage::getTitleFor( 'Log' ),
206 wfMsgHtml( 'viewpagelogs' ),
207 array(),
208 array( 'page' => $this->targetObj->getPrefixedText() )
209 );
210 if ( $this->targetObj->getNamespace() != NS_SPECIAL ) {
211 # Give a link to the page history
212 $links[] = $this->skin->linkKnown(
213 $this->targetObj,
214 wfMsgHtml( 'pagehist' ),
215 array(),
216 array( 'action' => 'history' )
217 );
218 # Link to deleted edits
219 if( $wgUser->isAllowed('undelete') ) {
220 $undelete = SpecialPage::getTitleFor( 'Undelete' );
221 $links[] = $this->skin->linkKnown(
222 $undelete,
223 wfMsgHtml( 'deletedhist' ),
224 array(),
225 array( 'target' => $this->targetObj->getPrefixedDBkey() )
226 );
227 }
228 }
229 # Logs themselves don't have histories or archived revisions
230 $wgOut->setSubtitle( '<p>' . $wgLang->pipeList( $links ) . '</p>' );
231 }
232 }
233
234 /**
235 * Get the condition used for fetching log snippets
236 */
237 protected function getLogQueryCond() {
238 $conds = array();
239 // Revision delete logs for these item
240 $conds['log_type'] = array('delete','suppress');
241 $conds['log_action'] = $this->getList()->getLogAction();
242 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
243 $conds['ls_value'] = $this->ids;
244 return $conds;
245 }
246
247 /**
248 * Show a deleted file version requested by the visitor.
249 * TODO Mostly copied from Special:Undelete. Refactor.
250 */
251 protected function tryShowFile( $archiveName ) {
252 global $wgOut, $wgRequest, $wgUser, $wgLang;
253
254 $repo = RepoGroup::singleton()->getLocalRepo();
255 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName );
256 $oimage->load();
257 // Check if user is allowed to see this file
258 if ( !$oimage->exists() ) {
259 $wgOut->addWikiMsg( 'revdelete-no-file' );
260 return;
261 }
262 if( !$oimage->userCan(File::DELETED_FILE) ) {
263 $wgOut->permissionRequired( 'suppressrevision' );
264 return;
265 }
266 if ( !$wgUser->matchEditToken( $this->token, $archiveName ) ) {
267 $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
268 $this->targetObj->getText(),
269 $wgLang->date( $oimage->getTimestamp() ),
270 $wgLang->time( $oimage->getTimestamp() ) );
271 $wgOut->addHTML(
272 Xml::openElement( 'form', array(
273 'method' => 'POST',
274 'action' => $this->getTitle()->getLocalUrl(
275 'target=' . urlencode( $oimage->getName() ) .
276 '&file=' . urlencode( $archiveName ) .
277 '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
278 )
279 ) .
280 Xml::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
281 '</form>'
282 );
283 return;
284 }
285 $wgOut->disable();
286 # We mustn't allow the output to be Squid cached, otherwise
287 # if an admin previews a deleted image, and it's cached, then
288 # a user without appropriate permissions can toddle off and
289 # nab the image, and Squid will serve it
290 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
291 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
292 $wgRequest->response()->header( 'Pragma: no-cache' );
293
294 # Stream the file to the client
295 global $IP;
296 require_once( "$IP/includes/StreamFile.php" );
297 $key = $oimage->getStorageKey();
298 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
299 wfStreamFile( $path );
300 }
301
302 /**
303 * Get the list object for this request
304 */
305 protected function getList() {
306 if ( is_null( $this->list ) ) {
307 $class = $this->typeInfo['list-class'];
308 $this->list = new $class( $this, $this->targetObj, $this->ids );
309 }
310 return $this->list;
311 }
312
313 /**
314 * Show a list of items that we will operate on, and show a form with checkboxes
315 * which will allow the user to choose new visibility settings.
316 */
317 protected function showForm() {
318 global $wgOut, $wgUser, $wgLang;
319 $UserAllowed = true;
320
321 if ( $this->typeName == 'logging' ) {
322 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids) ) );
323 } else {
324 $wgOut->addWikiMsg( 'revdelete-selected',
325 $this->targetObj->getPrefixedText(), count( $this->ids ) );
326 }
327
328 $bitfields = 0;
329 $wgOut->addHTML( "<ul>" );
330
331 $where = $revObjs = array();
332
333 $numRevisions = 0;
334 // Live revisions...
335 $list = $this->getList();
336 for ( $list->reset(); $list->current(); $list->next() ) {
337 $item = $list->current();
338 if ( !$item->canView() ) {
339 if( !$this->submitClicked ) {
340 $wgOut->permissionRequired( 'suppressrevision' );
341 return;
342 }
343 $UserAllowed = false;
344 }
345 $numRevisions++;
346 $bitfields |= $item->getBits();
347 $wgOut->addHTML( $item->getHTML() );
348 }
349
350 if( !$numRevisions ) {
351 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
352 return;
353 }
354
355 $wgOut->addHTML( "</ul>" );
356 // Explanation text
357 $this->addUsageText();
358
359 // Normal sysops can always see what they did, but can't always change it
360 if( !$UserAllowed ) return;
361
362 $out = Xml::openElement( 'form', array( 'method' => 'post',
363 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ),
364 'id' => 'mw-revdel-form-revisions' ) ) .
365 Xml::fieldset( wfMsg( 'revdelete-legend' ) ) .
366 $this->buildCheckBoxes( $bitfields ) .
367 Xml::openElement( 'table' ) .
368 "<tr>\n" .
369 '<td class="mw-label">' .
370 Xml::label( wfMsg( 'revdelete-log' ), 'wpRevDeleteReasonList' ) .
371 '</td>' .
372 '<td class="mw-input">' .
373 Xml::listDropDown( 'wpRevDeleteReasonList',
374 wfMsgForContent( 'revdelete-reason-dropdown' ),
375 wfMsgForContent( 'revdelete-reasonotherlist' ), '', 'wpReasonDropDown', 1
376 ) .
377 '</td>' .
378 "</tr><tr>\n" .
379 '<td class="mw-label">' .
380 Xml::label( wfMsg( 'revdelete-otherreason' ), 'wpReason' ) .
381 '</td>' .
382 '<td class="mw-input">' .
383 Xml::input( 'wpReason', 60, $this->otherReason, array( 'id' => 'wpReason' ) ) .
384 '</td>' .
385 "</tr><tr>\n" .
386 '<td></td>' .
387 '<td class="mw-submit">' .
388 Xml::submitButton( wfMsg( 'revdelete-submit' ), array( 'name' => 'wpSubmit' ) ) .
389 '</td>' .
390 "</tr>\n" .
391 Xml::closeElement( 'table' ) .
392 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
393 Xml::hidden( 'target', $this->targetObj->getPrefixedText() ) .
394 Xml::hidden( 'type', $this->typeName ) .
395 Xml::hidden( 'ids', implode( ',', $this->ids ) ) .
396 Xml::closeElement( 'fieldset' ) . "\n";
397
398 if( $wgUser->isAllowed( 'editinterface' ) ) {
399 $title = Title::makeTitle( NS_MEDIAWIKI, 'revdelete-reason-dropdown' );
400 $link = $wgUser->getSkin()->link(
401 $title,
402 wfMsgHtml( 'revdelete-edit-reasonlist' ),
403 array(),
404 array( 'action' => 'edit' )
405 );
406 $out .= Xml::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n";
407 }
408 $out .= Xml::closeElement( 'form' ) . "\n";
409
410 $wgOut->addHTML( $out );
411 }
412
413 /**
414 * Show some introductory text
415 * FIXME Wikimedia-specific policy text
416 */
417 protected function addUsageText() {
418 global $wgOut, $wgUser;
419 $wgOut->addWikiMsg( 'revdelete-text' );
420 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
421 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
422 }
423 }
424
425 /**
426 * @param $bitfields Interger: aggregate bitfield of all the bitfields
427 * @return String: HTML
428 */
429 protected function buildCheckBoxes( $bitfields ) {
430 $html = '<table>';
431 // FIXME: all items checked for just one rev are checked, even if not set for the others
432 foreach( $this->checks as $item ) {
433 list( $message, $name, $field ) = $item;
434 $innerHTML = Xml::checkLabel( wfMsg($message), $name, $name, $bitfields & $field );
435 if( $field == Revision::DELETED_RESTRICTED )
436 $innerHTML = "<b>$innerHTML</b>";
437 $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML );
438 $html .= '<tr>' . $line . "</tr>\n";
439 }
440 $html .= '</table>';
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 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
619 public static function getRelationType( $typeName ) {
620 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
621 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
622 }
623 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
624 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
625 $list = new $class( null, null, null );
626 return $list->getIdField();
627 } else {
628 return null;
629 }
630 }
631 }
632
633 /**
634 * Abstract base class for a list of deletable items
635 */
636 abstract class RevDel_List {
637 var $special, $title, $ids, $res, $current;
638 var $type = null; // override this
639 var $idField = null; // override this
640 var $dateField = false; // override this
641 var $authorIdField = false; // override this
642 var $authorNameField = false; // override this
643
644 /**
645 * @param $special The parent SpecialPage
646 * @param $title The target title
647 * @param $ids Array of IDs
648 */
649 public function __construct( $special, $title, $ids ) {
650 $this->special = $special;
651 $this->title = $title;
652 $this->ids = $ids;
653 }
654
655 /**
656 * Get the internal type name of this list. Equal to the table name.
657 */
658 public function getType() {
659 return $this->type;
660 }
661
662 /**
663 * Get the DB field name associated with the ID list
664 */
665 public function getIdField() {
666 return $this->idField;
667 }
668
669 /**
670 * Get the DB field name storing timestamps
671 */
672 public function getTimestampField() {
673 return $this->dateField;
674 }
675
676 /**
677 * Get the DB field name storing user ids
678 */
679 public function getAuthorIdField() {
680 return $this->authorIdField;
681 }
682
683 /**
684 * Get the DB field name storing user names
685 */
686 public function getAuthorNameField() {
687 return $this->authorNameField;
688 }
689 /**
690 * Set the visibility for the revisions in this list. Logging and
691 * transactions are done here.
692 *
693 * @param $params Associative array of parameters. Members are:
694 * value: The integer value to set the visibility to
695 * comment: The log comment.
696 * @return Status
697 */
698 public function setVisibility( $params ) {
699 $newBits = $params['value'];
700 $comment = $params['comment'];
701
702 $this->res = false;
703 $dbw = wfGetDB( DB_MASTER );
704 $this->doQuery( $dbw );
705 $dbw->begin();
706 $status = Status::newGood();
707 $missing = array_flip( $this->ids );
708 $this->clearFileOps();
709 $idsForLog = array();
710 $authorIds = $authorIPs = array();
711
712 for ( $this->reset(); $this->current(); $this->next() ) {
713 $item = $this->current();
714 unset( $missing[ $item->getId() ] );
715
716 // Make error messages less vague
717 $oldBits = $item->getBits();
718 if ( $oldBits == $newBits ) {
719 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
720 $status->failCount++;
721 continue;
722 } elseif ( $oldBits == 0 && $newBits != 0 ) {
723 $opType = 'hide';
724 } elseif ( $oldBits != 0 && $newBits == 0 ) {
725 $opType = 'show';
726 } else {
727 $opType = 'modify';
728 }
729
730 if ( $item->isHideCurrentOp( $newBits ) ) {
731 // Cannot hide current version text
732 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
733 $status->failCount++;
734 continue;
735 }
736 if ( !$item->canView() ) {
737 // Cannot access this revision
738 $msg = $opType == 'show' ? 'revdelete-show-no-access' : 'revdelete-modify-no-access';
739 $status->error( $msg, $item->formatDate(), $item->formatTime() );
740 $status->failCount++;
741 continue;
742 }
743
744 // Update the revision
745 $ok = $item->setBits( $newBits );
746
747 if ( $ok ) {
748 $idsForLog[] = $item->getId();
749 $status->successCount++;
750 if( $item->getAuthorId() > 0 ) {
751 $authorIds[] = $item->getAuthorId();
752 } else if( IP::isIPAddress( $item->getAuthorName() ) ) {
753 $authorIPs[] = $item->getAuthorName();
754 }
755 } else {
756 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
757 $status->failCount++;
758 }
759 }
760
761 // Handle missing revisions
762 foreach ( $missing as $id => $unused ) {
763 $status->error( 'revdelete-modify-missing', $id );
764 $status->failCount++;
765 }
766
767 if ( $status->successCount == 0 ) {
768 $status->ok = false;
769 $dbw->rollback();
770 return $status;
771 }
772
773 // Save success count
774 $successCount = $status->successCount;
775
776 // Move files, if there are any
777 $status->merge( $this->doPreCommitUpdates() );
778 if ( !$status->isOK() ) {
779 // Fatal error, such as no configured archive directory
780 $dbw->rollback();
781 return $status;
782 }
783
784 // Log it
785 $this->updateLog( array(
786 'title' => $this->title,
787 'count' => $successCount,
788 'newBits' => $newBits,
789 'oldBits' => $oldBits,
790 'comment' => $comment,
791 'ids' => $idsForLog,
792 'authorIds' => $authorIds,
793 'authorIPs' => $authorIPs
794 ) );
795 $dbw->commit();
796
797 // Clear caches
798 $status->merge( $this->doPostCommitUpdates() );
799 return $status;
800 }
801
802 /**
803 * Reload the list data from the master DB. This can be done after setVisibility()
804 * to allow $item->getHTML() to show the new data.
805 */
806 function reloadFromMaster() {
807 $dbw = wfGetDB( DB_MASTER );
808 $this->res = $this->doQuery( $dbw );
809 }
810
811 /**
812 * Record a log entry on the action
813 * @param $params Associative array of parameters:
814 * newBits: The new value of the *_deleted bitfield
815 * oldBits: The old value of the *_deleted bitfield.
816 * title: The target title
817 * ids: The ID list
818 * comment: The log comment
819 * authorsIds: The array of the user IDs of the offenders
820 * authorsIPs: The array of the IP/anon user offenders
821 */
822 protected function updateLog( $params ) {
823 // Get the URL param's corresponding DB field
824 $field = RevisionDeleter::getRelationType( $this->getType() );
825 if( !$field ) {
826 throw new MWException( "Bad log URL param type!" );
827 }
828 // Put things hidden from sysops in the oversight log
829 if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
830 $logType = 'suppress';
831 } else {
832 $logType = 'delete';
833 }
834 // Add params for effected page and ids
835 $logParams = $this->getLogParams( $params );
836 // Actually add the deletion log entry
837 $log = new LogPage( $logType );
838 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
839 $params['comment'], $logParams );
840 // Allow for easy searching of deletion log items for revision/log items
841 $log->addRelations( $field, $params['ids'], $logid );
842 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
843 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
844 }
845
846 /**
847 * Get the log action for this list type
848 */
849 public function getLogAction() {
850 return 'revision';
851 }
852
853 /**
854 * Get log parameter array.
855 * @param $params Associative array of log parameters, same as updateLog()
856 * @return array
857 */
858 public function getLogParams( $params ) {
859 return array(
860 $this->getType(),
861 implode( ',', $params['ids'] ),
862 "ofield={$params['oldBits']}",
863 "nfield={$params['newBits']}"
864 );
865 }
866
867 /**
868 * Initialise the current iteration pointer
869 */
870 protected function initCurrent() {
871 $row = $this->res->current();
872 if ( $row ) {
873 $this->current = $this->newItem( $row );
874 } else {
875 $this->current = false;
876 }
877 }
878
879 /**
880 * Start iteration. This must be called before current() or next().
881 * @return First list item
882 */
883 public function reset() {
884 if ( !$this->res ) {
885 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
886 } else {
887 $this->res->rewind();
888 }
889 $this->initCurrent();
890 return $this->current;
891 }
892
893 /**
894 * Get the current list item, or false if we are at the end
895 */
896 public function current() {
897 return $this->current;
898 }
899
900 /**
901 * Move the iteration pointer to the next list item, and return it.
902 */
903 public function next() {
904 $this->res->next();
905 $this->initCurrent();
906 return $this->current;
907 }
908
909 /**
910 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
911 * STUB
912 */
913 public function clearFileOps() {
914 }
915
916 /**
917 * A hook for setVisibility(): do batch updates pre-commit.
918 * STUB
919 * @return Status
920 */
921 public function doPreCommitUpdates() {
922 return Status::newGood();
923 }
924
925 /**
926 * A hook for setVisibility(): do any necessary updates post-commit.
927 * STUB
928 * @return Status
929 */
930 public function doPostCommitUpdates() {
931 return Status::newGood();
932 }
933
934 /**
935 * Create an item object from a DB result row
936 * @param $row stdclass
937 */
938 abstract public function newItem( $row );
939
940 /**
941 * Do the DB query to iterate through the objects.
942 * @param $db Database object to use for the query
943 */
944 abstract public function doQuery( $db );
945
946 /**
947 * Get the integer value of the flag used for suppression
948 */
949 abstract public function getSuppressBit();
950 }
951
952 /**
953 * Abstract base class for deletable items
954 */
955 abstract class RevDel_Item {
956 /** The parent SpecialPage */
957 var $special;
958
959 /** The parent RevDel_List */
960 var $list;
961
962 /** The DB result row */
963 var $row;
964
965 /**
966 * @param $list RevDel_List
967 * @param $row DB result row
968 */
969 public function __construct( $list, $row ) {
970 $this->special = $list->special;
971 $this->list = $list;
972 $this->row = $row;
973 }
974
975 /**
976 * Get the ID, as it would appear in the ids URL parameter
977 */
978 public function getId() {
979 $field = $this->list->getIdField();
980 return $this->row->$field;
981 }
982
983 /**
984 * Get the date, formatted with $wgLang
985 */
986 public function formatDate() {
987 global $wgLang;
988 return $wgLang->date( $this->getTimestamp() );
989 }
990
991 /**
992 * Get the time, formatted with $wgLang
993 */
994 public function formatTime() {
995 global $wgLang;
996 return $wgLang->time( $this->getTimestamp() );
997 }
998
999 /**
1000 * Get the timestamp in MW 14-char form
1001 */
1002 public function getTimestamp() {
1003 $field = $this->list->getTimestampField();
1004 return wfTimestamp( TS_MW, $this->row->$field );
1005 }
1006
1007 /**
1008 * Get the author user ID
1009 */
1010 public function getAuthorId() {
1011 $field = $this->list->getAuthorIdField();
1012 return intval( $this->row->$field );
1013 }
1014
1015 /**
1016 * Get the author user name
1017 */
1018 public function getAuthorName() {
1019 $field = $this->list->getAuthorNameField();
1020 return strval( $this->row->$field );
1021 }
1022
1023 /**
1024 * Returns true if the item is "current", and the operation to set the given
1025 * bits can't be executed for that reason
1026 * STUB
1027 */
1028 public function isHideCurrentOp( $newBits ) {
1029 return false;
1030 }
1031
1032 /**
1033 * Returns true if the current user can view the item
1034 */
1035 abstract public function canView();
1036
1037 /**
1038 * Get the current deletion bitfield value
1039 */
1040 abstract public function getBits();
1041
1042 /**
1043 * Get the HTML of the list item. Should be include <li></li> tags.
1044 * This is used to show the list in HTML form, by the special page.
1045 */
1046 abstract public function getHTML();
1047
1048 /**
1049 * Set the visibility of the item. This should do any necessary DB queries.
1050 *
1051 * The DB update query should have a condition which forces it to only update
1052 * if the value in the DB matches the value fetched earlier with the SELECT.
1053 * If the update fails because it did not match, the function should return
1054 * false. This prevents concurrency problems.
1055 *
1056 * @return boolean success
1057 */
1058 abstract public function setBits( $newBits );
1059 }
1060
1061 /**
1062 * List for revision table items
1063 */
1064 class RevDel_RevisionList extends RevDel_List {
1065 var $currentRevId;
1066 var $type = 'revision';
1067 var $idField = 'rev_id';
1068 var $dateField = 'rev_timestamp';
1069 var $authorIdField = 'rev_user';
1070 var $authorNameField = 'rev_user_text';
1071
1072 public function doQuery( $db ) {
1073 $ids = array_map( 'intval', $this->ids );
1074 return $db->select( array('revision','page'), '*',
1075 array(
1076 'rev_page' => $this->title->getArticleID(),
1077 'rev_id' => $ids,
1078 'rev_page = page_id'
1079 ),
1080 __METHOD__
1081 );
1082 }
1083
1084 public function newItem( $row ) {
1085 return new RevDel_RevisionItem( $this, $row );
1086 }
1087
1088 public function getCurrent() {
1089 if ( is_null( $this->currentRevId ) ) {
1090 $dbw = wfGetDB( DB_MASTER );
1091 $this->currentRevId = $dbw->selectField(
1092 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
1093 }
1094 return $this->currentRevId;
1095 }
1096
1097 public function getSuppressBit() {
1098 return Revision::DELETED_RESTRICTED;
1099 }
1100
1101 public function doPreCommitUpdates() {
1102 $this->title->invalidateCache();
1103 return Status::newGood();
1104 }
1105
1106 public function doPostCommitUpdates() {
1107 $this->title->purgeSquid();
1108 // Extensions that require referencing previous revisions may need this
1109 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title ) );
1110 return Status::newGood();
1111 }
1112 }
1113
1114 /**
1115 * Item class for a revision table row
1116 */
1117 class RevDel_RevisionItem extends RevDel_Item {
1118 var $revision;
1119
1120 public function __construct( $list, $row ) {
1121 parent::__construct( $list, $row );
1122 $this->revision = new Revision( $row );
1123 }
1124
1125 public function canView() {
1126 return $this->revision->userCan( Revision::DELETED_RESTRICTED );
1127 }
1128
1129 public function getBits() {
1130 return $this->revision->mDeleted;
1131 }
1132
1133 public function setBits( $bits ) {
1134 $dbw = wfGetDB( DB_MASTER );
1135 // Update revision table
1136 $dbw->update( 'revision',
1137 array( 'rev_deleted' => $bits ),
1138 array(
1139 'rev_id' => $this->revision->getId(),
1140 'rev_page' => $this->revision->getPage(),
1141 'rev_deleted' => $this->getBits()
1142 ),
1143 __METHOD__
1144 );
1145 if ( !$dbw->affectedRows() ) {
1146 // Concurrent fail!
1147 return false;
1148 }
1149 // Update recentchanges table
1150 $dbw->update( 'recentchanges',
1151 array(
1152 'rc_deleted' => $bits,
1153 'rc_patrolled' => 1
1154 ),
1155 array(
1156 'rc_this_oldid' => $this->revision->getId(), // condition
1157 // non-unique timestamp index
1158 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
1159 ),
1160 __METHOD__
1161 );
1162 return true;
1163 }
1164
1165 public function isDeleted() {
1166 return $this->revision->isDeleted( Revision::DELETED_TEXT );
1167 }
1168
1169 public function isHideCurrentOp( $newBits ) {
1170 return ( $newBits & Revision::DELETED_TEXT )
1171 && $this->list->getCurrent() == $this->getId();
1172 }
1173
1174 /**
1175 * Get the HTML link to the revision text.
1176 * Overridden by RevDel_ArchiveItem.
1177 */
1178 protected function getRevisionLink() {
1179 global $wgLang;
1180 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
1181 if ( $this->isDeleted() && !$this->canView() ) {
1182 return $date;
1183 }
1184 return $this->special->skin->link(
1185 $this->list->title,
1186 $date,
1187 array(),
1188 array(
1189 'oldid' => $this->revision->getId(),
1190 'unhide' => 1
1191 )
1192 );
1193 }
1194
1195 /**
1196 * Get the HTML link to the diff.
1197 * Overridden by RevDel_ArchiveItem
1198 */
1199 protected function getDiffLink() {
1200 if ( $this->isDeleted() && !$this->canView() ) {
1201 return wfMsgHtml('diff');
1202 } else {
1203 return
1204 $this->special->skin->link(
1205 $this->list->title,
1206 wfMsgHtml('diff'),
1207 array(),
1208 array(
1209 'diff' => $this->revision->getId(),
1210 'oldid' => 'prev',
1211 'unhide' => 1
1212 ),
1213 array(
1214 'known',
1215 'noclasses'
1216 )
1217 );
1218 }
1219 }
1220
1221 public function getHTML() {
1222 $difflink = $this->getDiffLink();
1223 $revlink = $this->getRevisionLink();
1224 $userlink = $this->special->skin->revUserLink( $this->revision );
1225 $comment = $this->special->skin->revComment( $this->revision );
1226 if ( $this->isDeleted() ) {
1227 $revlink = "<span class=\"history-deleted\">$revlink</span>";
1228 }
1229 return "<li>($difflink) $revlink $userlink $comment</li>";
1230 }
1231 }
1232
1233 /**
1234 * List for archive table items, i.e. revisions deleted via action=delete
1235 */
1236 class RevDel_ArchiveList extends RevDel_RevisionList {
1237 var $type = 'archive';
1238 var $idField = 'ar_timestamp';
1239 var $dateField = 'ar_timestamp';
1240 var $authorIdField = 'ar_user';
1241 var $authorNameField = 'ar_user_text';
1242
1243 public function doQuery( $db ) {
1244 $timestamps = array();
1245 foreach ( $this->ids as $id ) {
1246 $timestamps[] = $db->timestamp( $id );
1247 }
1248 return $db->select( 'archive', '*',
1249 array(
1250 'ar_namespace' => $this->title->getNamespace(),
1251 'ar_title' => $this->title->getDBkey(),
1252 'ar_timestamp' => $timestamps
1253 ),
1254 __METHOD__
1255 );
1256 }
1257
1258 public function newItem( $row ) {
1259 return new RevDel_ArchiveItem( $this, $row );
1260 }
1261
1262 public function doPreCommitUpdates() {
1263 return Status::newGood();
1264 }
1265
1266 public function doPostCommitUpdates() {
1267 return Status::newGood();
1268 }
1269 }
1270
1271 /**
1272 * Item class for a archive table row
1273 */
1274 class RevDel_ArchiveItem extends RevDel_RevisionItem {
1275 public function __construct( $list, $row ) {
1276 RevDel_Item::__construct( $list, $row );
1277 $this->revision = Revision::newFromArchiveRow( $row,
1278 array( 'page' => $this->list->title->getArticleId() ) );
1279 }
1280
1281 public function getId() {
1282 # Convert DB timestamp to MW timestamp
1283 return $this->revision->getTimestamp();
1284 }
1285
1286 public function setBits( $bits ) {
1287 $dbw = wfGetDB( DB_MASTER );
1288 $dbw->update( 'archive',
1289 array( 'ar_deleted' => $bits ),
1290 array( 'ar_namespace' => $this->list->title->getNamespace(),
1291 'ar_title' => $this->list->title->getDBkey(),
1292 // use timestamp for index
1293 'ar_timestamp' => $this->row->ar_timestamp,
1294 'ar_rev_id' => $this->row->ar_rev_id,
1295 'ar_deleted' => $this->getBits()
1296 ),
1297 __METHOD__ );
1298 return (bool)$dbw->affectedRows();
1299 }
1300
1301 protected function getRevisionLink() {
1302 global $wgLang;
1303 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1304 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
1305 if ( $this->isDeleted() && !$this->canView() ) {
1306 return $date;
1307 }
1308 return $this->special->skin->link( $undelete, $date, array(),
1309 array(
1310 'target' => $this->list->title->getPrefixedText(),
1311 'timestamp' => $this->revision->getTimestamp()
1312 ) );
1313 }
1314
1315 protected function getDiffLink() {
1316 if ( $this->isDeleted() && !$this->canView() ) {
1317 return wfMsgHtml( 'diff' );
1318 }
1319 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1320 return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
1321 array(
1322 'target' => $this->list->title->getPrefixedText(),
1323 'diff' => 'prev',
1324 'timestamp' => $this->revision->getTimestamp()
1325 ) );
1326 }
1327 }
1328
1329 /**
1330 * List for oldimage table items
1331 */
1332 class RevDel_FileList extends RevDel_List {
1333 var $type = 'oldimage';
1334 var $idField = 'oi_archive_name';
1335 var $dateField = 'oi_timestamp';
1336 var $authorIdField = 'oi_user';
1337 var $authorNameField = 'oi_user_text';
1338 var $storeBatch, $deleteBatch, $cleanupBatch;
1339
1340 public function doQuery( $db ) {
1341 $archiveName = array();
1342 foreach( $this->ids as $timestamp ) {
1343 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
1344 }
1345 return $db->select( 'oldimage', '*',
1346 array(
1347 'oi_name' => $this->title->getDBkey(),
1348 'oi_archive_name' => $archiveNames
1349 ),
1350 __METHOD__
1351 );
1352 }
1353
1354 public function newItem( $row ) {
1355 return new RevDel_FileItem( $this, $row );
1356 }
1357
1358 public function clearFileOps() {
1359 $this->deleteBatch = array();
1360 $this->storeBatch = array();
1361 $this->cleanupBatch = array();
1362 }
1363
1364 public function doPreCommitUpdates() {
1365 $status = Status::newGood();
1366 $repo = RepoGroup::singleton()->getLocalRepo();
1367 if ( $this->storeBatch ) {
1368 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
1369 }
1370 if ( !$status->isOK() ) {
1371 return $status;
1372 }
1373 if ( $this->deleteBatch ) {
1374 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
1375 }
1376 if ( !$status->isOK() ) {
1377 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1378 // modified (but destined for rollback) causes data loss
1379 return $status;
1380 }
1381 if ( $this->cleanupBatch ) {
1382 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
1383 }
1384 return $status;
1385 }
1386
1387 public function doPostCommitUpdates() {
1388 $file = wfLocalFile( $this->title );
1389 $file->purgeCache();
1390 $file->purgeDescription();
1391 return Status::newGood();
1392 }
1393
1394 public function getSuppressBit() {
1395 return File::DELETED_RESTRICTED;
1396 }
1397 }
1398
1399 /**
1400 * Item class for an oldimage table row
1401 */
1402 class RevDel_FileItem extends RevDel_Item {
1403 var $file;
1404
1405 public function __construct( $list, $row ) {
1406 parent::__construct( $list, $row );
1407 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
1408 }
1409
1410 public function getId() {
1411 $parts = explode( '!', $this->row->oi_archive_name );
1412 return $parts[0];
1413 }
1414
1415 public function canView() {
1416 return $this->file->userCan( File::DELETED_RESTRICTED );
1417 }
1418
1419 public function getBits() {
1420 return $this->file->getVisibility();
1421 }
1422
1423 public function setBits( $bits ) {
1424 # Queue the file op
1425 # FIXME: move to LocalFile.php
1426 if ( $this->isDeleted() ) {
1427 if ( $bits & File::DELETED_FILE ) {
1428 # Still deleted
1429 } else {
1430 # Newly undeleted
1431 $key = $this->file->getStorageKey();
1432 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1433 $this->list->storeBatch[] = array(
1434 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1435 'public',
1436 $this->file->getRel()
1437 );
1438 $this->list->cleanupBatch[] = $key;
1439 }
1440 } elseif ( $bits & File::DELETED_FILE ) {
1441 # Newly deleted
1442 $key = $this->file->getStorageKey();
1443 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1444 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
1445 }
1446
1447 # Do the database operations
1448 $dbw = wfGetDB( DB_MASTER );
1449 $dbw->update( 'oldimage',
1450 array( 'oi_deleted' => $bits ),
1451 array(
1452 'oi_name' => $this->row->oi_name,
1453 'oi_timestamp' => $this->row->oi_timestamp,
1454 'oi_deleted' => $this->getBits()
1455 ),
1456 __METHOD__
1457 );
1458 return (bool)$dbw->affectedRows();
1459 }
1460
1461 public function isDeleted() {
1462 return $this->file->isDeleted( File::DELETED_FILE );
1463 }
1464
1465 /**
1466 * Get the link to the file.
1467 * Overridden by RevDel_ArchivedFileItem.
1468 */
1469 protected function getLink() {
1470 global $wgLang;
1471 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1472 if ( $this->isDeleted() ) {
1473 # Hidden files...
1474 if ( !$this->canView() ) {
1475 $link = $date;
1476 } else {
1477 $link = $this->special->skin->link(
1478 $this->special->getTitle(),
1479 $date, array(),
1480 array(
1481 'target' => $this->list->title->getPrefixedText(),
1482 'file' => $this->file->sha1 . '.' . $this->file->getExtension()
1483 )
1484 );
1485 }
1486 return '<span class="history-deleted">' . $link . '</span>';
1487 } else {
1488 # Regular files...
1489 $url = $this->file->getUrl();
1490 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
1491 }
1492 }
1493 /**
1494 * Generate a user tool link cluster if the current user is allowed to view it
1495 * @return string HTML
1496 */
1497 protected function getUserTools() {
1498 if( $this->file->userCan( Revision::DELETED_USER ) ) {
1499 $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
1500 $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
1501 } else {
1502 $link = wfMsgHtml( 'rev-deleted-user' );
1503 }
1504 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
1505 return '<span class="history-deleted">' . $link . '</span>';
1506 }
1507 return $link;
1508 }
1509
1510 /**
1511 * Wrap and format the file's comment block, if the current
1512 * user is allowed to view it.
1513 *
1514 * @return string HTML
1515 */
1516 protected function getComment() {
1517 if( $this->file->userCan( File::DELETED_COMMENT ) ) {
1518 $block = $this->special->skin->commentBlock( $this->file->description );
1519 } else {
1520 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1521 }
1522 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
1523 return "<span class=\"history-deleted\">$block</span>";
1524 }
1525 return $block;
1526 }
1527
1528 public function getHTML() {
1529 global $wgLang;
1530 $data =
1531 wfMsg(
1532 'widthheight',
1533 $wgLang->formatNum( $this->file->getWidth() ),
1534 $wgLang->formatNum( $this->file->getHeight() )
1535 ) .
1536 ' (' .
1537 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
1538 ')';
1539 $pageLink = $this->getLink();
1540
1541 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1542 $data . ' ' . $this->getComment(). '</li>';
1543 }
1544 }
1545
1546 /**
1547 * List for filearchive table items
1548 */
1549 class RevDel_ArchivedFileList extends RevDel_FileList {
1550 var $type = 'filearchive';
1551 var $idField = 'fa_id';
1552 var $dateField = 'fa_timestamp';
1553 var $authorIdField = 'fa_user';
1554 var $authorNameField = 'fa_user_text';
1555
1556 public function doQuery( $db ) {
1557 $ids = array_map( 'intval', $this->ids );
1558 return $db->select( 'filearchive', '*',
1559 array(
1560 'fa_name' => $this->title->getDBkey(),
1561 'fa_id' => $ids
1562 ),
1563 __METHOD__
1564 );
1565 }
1566
1567 public function newItem( $row ) {
1568 return new RevDel_ArchivedFileItem( $this, $row );
1569 }
1570 }
1571
1572 /**
1573 * Item class for a filearchive table row
1574 */
1575 class RevDel_ArchivedFileItem extends RevDel_FileItem {
1576 public function __construct( $list, $row ) {
1577 RevDel_Item::__construct( $list, $row );
1578 $this->file = ArchivedFile::newFromRow( $row );
1579 }
1580
1581 public function getId() {
1582 return $this->row->fa_id;
1583 }
1584
1585 public function setBits( $bits ) {
1586 $dbw = wfGetDB( DB_MASTER );
1587 $dbw->update( 'filearchive',
1588 array( 'fa_deleted' => $bits ),
1589 array(
1590 'fa_id' => $this->row->fa_id,
1591 'fa_deleted' => $this->getBits(),
1592 ),
1593 __METHOD__
1594 );
1595 return (bool)$dbw->affectedRows();
1596 }
1597
1598 protected function getLink() {
1599 global $wgLang, $wgUser;
1600 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1601 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1602 $key = $this->file->getKey();
1603 return $this->special->skin->link( $undelete, $date, array(),
1604 array(
1605 'target' => $this->list->title->getPrefixedText(),
1606 'file' => $key,
1607 'token' => $wgUser->editToken( $key )
1608 )
1609 );
1610 }
1611 }
1612
1613 /**
1614 * List for logging table items
1615 */
1616 class RevDel_LogList extends RevDel_List {
1617 var $type = 'logging';
1618 var $idField = 'log_id';
1619 var $dateField = 'log_timestamp';
1620 var $authorIdField = 'log_user';
1621 var $authorNameField = 'log_user_text';
1622
1623 public function doQuery( $db ) {
1624 global $wgMessageCache;
1625 $wgMessageCache->loadAllMessages();
1626 $ids = array_map( 'intval', $this->ids );
1627 return $db->select( 'logging', '*',
1628 array( 'log_id' => $ids ),
1629 __METHOD__
1630 );
1631 }
1632
1633 public function newItem( $row ) {
1634 return new RevDel_LogItem( $this, $row );
1635 }
1636
1637 public function getSuppressBit() {
1638 return Revision::DELETED_RESTRICTED;
1639 }
1640
1641 public function getLogAction() {
1642 return 'event';
1643 }
1644
1645 public function getLogParams( $params ) {
1646 return array(
1647 implode( ',', $params['ids'] ),
1648 "ofield={$params['oldBits']}",
1649 "nfield={$params['newBits']}"
1650 );
1651 }
1652 }
1653
1654 /**
1655 * Item class for a logging table row
1656 */
1657 class RevDel_LogItem extends RevDel_Item {
1658 public function canView() {
1659 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
1660 }
1661
1662 public function getBits() {
1663 return $this->row->log_deleted;
1664 }
1665
1666 public function setBits( $bits ) {
1667 $dbw = wfGetDB( DB_MASTER );
1668 $dbw->update( 'recentchanges',
1669 array(
1670 'rc_deleted' => $bits,
1671 'rc_patrolled' => 1
1672 ),
1673 array(
1674 'rc_logid' => $this->row->log_id,
1675 'rc_timestamp' => $this->row->log_timestamp // index
1676 ),
1677 __METHOD__
1678 );
1679 $dbw->update( 'logging',
1680 array( 'log_deleted' => $bits ),
1681 array(
1682 'log_id' => $this->row->log_id,
1683 'log_deleted' => $this->getBits()
1684 ),
1685 __METHOD__
1686 );
1687 return (bool)$dbw->affectedRows();
1688 }
1689
1690 public function getHTML() {
1691 global $wgLang;
1692
1693 $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
1694 $paramArray = LogPage::extractParams( $this->row->log_params );
1695 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1696
1697 // Log link for this page
1698 $loglink = $this->special->skin->link(
1699 SpecialPage::getTitleFor( 'Log' ),
1700 wfMsgHtml( 'log' ),
1701 array(),
1702 array( 'page' => $title->getPrefixedText() )
1703 );
1704 // Action text
1705 if( !$this->canView() ) {
1706 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1707 } else {
1708 $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
1709 $this->special->skin, $paramArray, true, true );
1710 if( $this->row->log_deleted & LogPage::DELETED_ACTION )
1711 $action = '<span class="history-deleted">' . $action . '</span>';
1712 }
1713 // User links
1714 $userLink = $this->special->skin->userLink( $this->row->log_user,
1715 User::WhoIs( $this->row->log_user ) );
1716 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
1717 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
1718 }
1719 // Comment
1720 $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
1721 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
1722 $comment = '<span class="history-deleted">' . $comment . '</span>';
1723 }
1724 return "<li>($loglink) $date $userLink $action $comment</li>";
1725 }
1726 }