Oracle support: added a DB piped function & collection type for getting of DBMS_OUTPU...
[mediawiki.git] / includes / specials / SpecialRevisiondelete.php
blobb1c71341ca84d721b7d39add94fb0fd3925e20a3
1 <?php
2 /**
3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
6 * @file
7 * @ingroup SpecialPage
8 */
10 class SpecialRevisionDelete extends UnlistedSpecialPage {
11 /** Skin object */
12 var $skin;
14 /** True if the submit button was clicked, and the form was posted */
15 var $submitClicked;
17 /** Target ID list */
18 var $ids;
20 /** Archive name, for reviewing deleted files */
21 var $archiveName;
23 /** Edit token for securing image views against XSS */
24 var $token;
26 /** Title object for target parameter */
27 var $targetObj;
29 /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
30 var $typeName;
32 /** Array of checkbox specs (message, name, deletion bits) */
33 var $checks;
35 /** Information about the current type */
36 var $typeInfo;
38 /** The RevDel_List object, storing the list of items to be deleted/undeleted */
39 var $list;
41 /**
42 * Assorted information about each type, needed by the special page.
43 * TODO Move some of this to the list class
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',
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',
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',
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',
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',
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',
92 public function __construct() {
93 parent::__construct( 'Revisiondelete', 'deletedhistory' );
96 public function execute( $par ) {
97 global $wgOut, $wgUser, $wgRequest;
98 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
99 $wgOut->permissionRequired( 'deletedhistory' );
100 return;
101 } else if( wfReadOnly() ) {
102 $wgOut->readOnlyPage();
103 return;
105 $this->mIsAllowed = $wgUser->isAllowed('deleterevision'); // for changes
106 $this->skin = $wgUser->getSkin();
107 $this->setHeaders();
108 $this->outputHeader();
109 $this->submitClicked = $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
110 # Handle our many different possible input types.
111 $ids = $wgRequest->getVal( 'ids' );
112 if ( !is_null( $ids ) ) {
113 # Allow CSV, for backwards compatibility, or a single ID for show/hide links
114 $this->ids = explode( ',', $ids );
115 } else {
116 # Array input
117 $this->ids = array_keys( $wgRequest->getArray('ids',array()) );
119 // $this->ids = array_map( 'intval', $this->ids );
120 $this->ids = array_unique( array_filter( $this->ids ) );
122 if ( $wgRequest->getVal( 'action' ) == 'historysubmit' ) {
123 # For show/hide form submission from history page
124 $this->targetObj = $GLOBALS['wgTitle'];
125 $this->typeName = 'revision';
126 } else {
127 $this->typeName = $wgRequest->getVal( 'type' );
128 $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
131 # For reviewing deleted files...
132 $this->archiveName = $wgRequest->getVal( 'file' );
133 $this->token = $wgRequest->getVal( 'token' );
134 if ( $this->archiveName && $this->targetObj ) {
135 $this->tryShowFile( $this->archiveName );
136 return;
139 if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) {
140 $this->typeName = self::$deprecatedTypeMap[$this->typeName];
143 # No targets?
144 if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) {
145 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
146 return;
148 $this->typeInfo = self::$allowedTypes[$this->typeName];
150 # If we have revisions, get the title from the first one
151 # since they should all be from the same page. This allows
152 # for more flexibility with page moves...
153 if( $this->typeName == 'revision' ) {
154 $rev = Revision::newFromId( $this->ids[0] );
155 $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj;
158 $this->otherReason = $wgRequest->getVal( 'wpReason' );
159 # We need a target page!
160 if( is_null($this->targetObj) ) {
161 $wgOut->addWikiMsg( 'undelete-header' );
162 return;
164 # Give a link to the logs/hist for this page
165 $this->showConvenienceLinks();
167 # Initialise checkboxes
168 $this->checks = array(
169 array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ),
170 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
171 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
173 if( $wgUser->isAllowed('suppressrevision') ) {
174 $this->checks[] = array( 'revdelete-hide-restricted',
175 'wpHideRestricted', Revision::DELETED_RESTRICTED );
178 # Either submit or create our form
179 if( $this->mIsAllowed && $this->submitClicked ) {
180 $this->submit( $wgRequest );
181 } else {
182 $this->showForm();
184 $qc = $this->getLogQueryCond();
185 # Show relevant lines from the deletion log
186 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
187 LogEventsList::showLogExtract( $wgOut, 'delete',
188 $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
189 # Show relevant lines from the suppression log
190 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
191 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
192 LogEventsList::showLogExtract( $wgOut, 'suppress',
193 $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
198 * Show some useful links in the subtitle
200 protected function showConvenienceLinks() {
201 global $wgOut, $wgUser, $wgLang;
202 # Give a link to the logs/hist for this page
203 if( $this->targetObj ) {
204 $links = array();
205 $links[] = $this->skin->linkKnown(
206 SpecialPage::getTitleFor( 'Log' ),
207 wfMsgHtml( 'viewpagelogs' ),
208 array(),
209 array( 'page' => $this->targetObj->getPrefixedText() )
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' )
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() )
230 # Logs themselves don't have histories or archived revisions
231 $wgOut->setSubtitle( '<p>' . $wgLang->pipeList( $links ) . '</p>' );
236 * Get the condition used for fetching log snippets
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;
249 * Show a deleted file version requested by the visitor.
250 * TODO Mostly copied from Special:Undelete. Refactor.
252 protected function tryShowFile( $archiveName ) {
253 global $wgOut, $wgRequest, $wgUser, $wgLang;
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;
263 if( !$oimage->userCan(File::DELETED_FILE) ) {
264 if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) {
265 $wgOut->permissionRequired( 'suppressrevision' );
266 } else {
267 $wgOut->permissionRequired( 'deletedtext' );
269 return;
271 if ( !$wgUser->matchEditToken( $this->token, $archiveName ) ) {
272 $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
273 $this->targetObj->getText(),
274 $wgLang->date( $oimage->getTimestamp() ),
275 $wgLang->time( $oimage->getTimestamp() ) );
276 $wgOut->addHTML(
277 Xml::openElement( 'form', array(
278 'method' => 'POST',
279 'action' => $this->getTitle()->getLocalUrl(
280 'target=' . urlencode( $oimage->getName() ) .
281 '&file=' . urlencode( $archiveName ) .
282 '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
285 Xml::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
286 '</form>'
288 return;
290 $wgOut->disable();
291 # We mustn't allow the output to be Squid cached, otherwise
292 # if an admin previews a deleted image, and it's cached, then
293 # a user without appropriate permissions can toddle off and
294 # nab the image, and Squid will serve it
295 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
296 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
297 $wgRequest->response()->header( 'Pragma: no-cache' );
299 # Stream the file to the client
300 global $IP;
301 require_once( "$IP/includes/StreamFile.php" );
302 $key = $oimage->getStorageKey();
303 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
304 wfStreamFile( $path );
308 * Get the list object for this request
310 protected function getList() {
311 if ( is_null( $this->list ) ) {
312 $class = $this->typeInfo['list-class'];
313 $this->list = new $class( $this, $this->targetObj, $this->ids );
315 return $this->list;
319 * Show a list of items that we will operate on, and show a form with checkboxes
320 * which will allow the user to choose new visibility settings.
322 protected function showForm() {
323 global $wgOut, $wgUser, $wgLang;
324 $UserAllowed = true;
326 if ( $this->typeName == 'logging' ) {
327 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids) ) );
328 } else {
329 $wgOut->addWikiMsg( 'revdelete-selected',
330 $this->targetObj->getPrefixedText(), count( $this->ids ) );
333 $bitfields = 0;
334 $wgOut->addHTML( "<ul>" );
336 $where = $revObjs = array();
338 $numRevisions = 0;
339 // Live revisions...
340 $list = $this->getList();
341 for ( $list->reset(); $list->current(); $list->next() ) {
342 $item = $list->current();
343 if ( !$item->canView() ) {
344 if( !$this->submitClicked ) {
345 $wgOut->permissionRequired( 'suppressrevision' );
346 return;
348 $UserAllowed = false;
350 $numRevisions++;
351 $bitfields |= $item->getBits();
352 $wgOut->addHTML( $item->getHTML() );
355 if( !$numRevisions ) {
356 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
357 return;
360 $wgOut->addHTML( "</ul>" );
361 // Explanation text
362 $this->addUsageText();
364 // Normal sysops can always see what they did, but can't always change it
365 if( !$UserAllowed ) return;
367 // Show form if the user can submit
368 if( $this->mIsAllowed ) {
369 $out = Xml::openElement( 'form', array( 'method' => 'post',
370 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ),
371 'id' => 'mw-revdel-form-revisions' ) ) .
372 Xml::fieldset( wfMsg( 'revdelete-legend' ) ) .
373 $this->buildCheckBoxes( $bitfields ) .
374 Xml::openElement( 'table' ) .
375 "<tr>\n" .
376 '<td class="mw-label">' .
377 Xml::label( wfMsg( 'revdelete-log' ), 'wpRevDeleteReasonList' ) .
378 '</td>' .
379 '<td class="mw-input">' .
380 Xml::listDropDown( 'wpRevDeleteReasonList',
381 wfMsgForContent( 'revdelete-reason-dropdown' ),
382 wfMsgForContent( 'revdelete-reasonotherlist' ), '', 'wpReasonDropDown', 1
384 '</td>' .
385 "</tr><tr>\n" .
386 '<td class="mw-label">' .
387 Xml::label( wfMsg( 'revdelete-otherreason' ), 'wpReason' ) .
388 '</td>' .
389 '<td class="mw-input">' .
390 Xml::input( 'wpReason', 60, $this->otherReason, array( 'id' => 'wpReason' ) ) .
391 '</td>' .
392 "</tr><tr>\n" .
393 '<td></td>' .
394 '<td class="mw-submit">' .
395 Xml::submitButton( wfMsg( 'revdelete-submit' ), array( 'name' => 'wpSubmit' ) ) .
396 '</td>' .
397 "</tr>\n" .
398 Xml::closeElement( 'table' ) .
399 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
400 Xml::hidden( 'target', $this->targetObj->getPrefixedText() ) .
401 Xml::hidden( 'type', $this->typeName ) .
402 Xml::hidden( 'ids', implode( ',', $this->ids ) ) .
403 Xml::closeElement( 'fieldset' ) . "\n";
404 } else {
405 $out = '';
407 if( $this->mIsAllowed ) {
408 $out .= Xml::closeElement( 'form' ) . "\n";
409 // Show link to edit the dropdown reasons
410 if( $wgUser->isAllowed( 'editinterface' ) ) {
411 $title = Title::makeTitle( NS_MEDIAWIKI, 'revdelete-reason-dropdown' );
412 $link = $wgUser->getSkin()->link(
413 $title,
414 wfMsgHtml( 'revdelete-edit-reasonlist' ),
415 array(),
416 array( 'action' => 'edit' )
418 $out .= Xml::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n";
421 $wgOut->addHTML( $out );
425 * Show some introductory text
426 * FIXME Wikimedia-specific policy text
428 protected function addUsageText() {
429 global $wgOut, $wgUser;
430 $wgOut->addWikiMsg( 'revdelete-text' );
431 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
432 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
434 if( $this->mIsAllowed ) {
435 $wgOut->addWikiMsg( 'revdelete-confirm' );
440 * @param $bitfields Interger: aggregate bitfield of all the bitfields
441 * @return String: HTML
443 protected function buildCheckBoxes( $bitfields ) {
444 $html = '<table>';
445 // FIXME: all items checked for just one rev are checked, even if not set for the others
446 foreach( $this->checks as $item ) {
447 list( $message, $name, $field ) = $item;
448 $innerHTML = Xml::checkLabel( wfMsg($message), $name, $name, $bitfields & $field );
449 if( $field == Revision::DELETED_RESTRICTED )
450 $innerHTML = "<b>$innerHTML</b>";
451 $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML );
452 $html .= '<tr>' . $line . "</tr>\n";
454 $html .= '</table>';
455 return $html;
459 * UI entry point for form submission.
460 * @param $request WebRequest
462 protected function submit( $request ) {
463 global $wgUser, $wgOut;
464 # Check edit token on submission
465 if( $this->submitClicked && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
466 $wgOut->addWikiMsg( 'sessionfailure' );
467 return false;
469 $bitfield = $this->extractBitfield( $request );
470 $listReason = $request->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown
471 $comment = $listReason;
472 if( $comment != 'other' && $this->otherReason != '' ) {
473 // Entry from drop down menu + additional comment
474 $comment .= wfMsgForContent( 'colon-separator' ) . $this->otherReason;
475 } elseif( $comment == 'other' ) {
476 $comment = $this->otherReason;
478 # Can the user set this field?
479 if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
480 $wgOut->permissionRequired( 'suppressrevision' );
481 return false;
483 # If the save went through, go to success message...
484 $status = $this->save( $bitfield, $comment, $this->targetObj );
485 if ( $status->isGood() ) {
486 $this->success();
487 return true;
488 # ...otherwise, bounce back to form...
489 } else {
490 $this->failure( $status );
492 return false;
496 * Report that the submit operation succeeded
498 protected function success() {
499 global $wgOut;
500 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
501 $wgOut->wrapWikiMsg( '<span class="success">$1</span>', $this->typeInfo['success'] );
502 $this->list->reloadFromMaster();
503 $this->showForm();
507 * Report that the submit operation failed
509 protected function failure( $status ) {
510 global $wgOut;
511 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
512 $wgOut->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) );
513 $this->showForm();
517 * Put together a rev_deleted bitfield from the submitted checkboxes
518 * @param $request WebRequest
519 * @return Integer
521 protected function extractBitfield( $request ) {
522 $bitfield = 0;
523 foreach( $this->checks as $item ) {
524 list( /* message */ , $name, $field ) = $item;
525 if( $request->getCheck( $name ) ) {
526 $bitfield |= $field;
529 return $bitfield;
533 * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
535 protected function save( $bitfield, $reason, $title ) {
536 // Don't allow simply locking the interface for no reason
537 if( $bitfield == Revision::DELETED_RESTRICTED ) {
538 return Status::newFatal( 'revdelete-only-restricted' );
540 return $this->getList()->setVisibility( array(
541 'value' => $bitfield,
542 'comment' => $reason ) );
547 * Temporary b/c interface, collection of static functions.
548 * @ingroup SpecialPage
550 class RevisionDeleter {
552 * Checks for a change in the bitfield for a certain option and updates the
553 * provided array accordingly.
555 * @param $desc String: description to add to the array if the option was
556 * enabled / disabled.
557 * @param $field Integer: the bitmask describing the single option.
558 * @param $diff Integer: the xor of the old and new bitfields.
559 * @param $new Integer: the new bitfield
560 * @param $arr Array: the array to update.
562 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
563 if( $diff & $field ) {
564 $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
569 * Gets an array describing the changes made to the visibilit of the revision.
570 * If the resulting array is $arr, then $arr[0] will contain an array of strings
571 * describing the items that were hidden, $arr[2] will contain an array of strings
572 * describing the items that were unhidden, and $arr[3] will contain an array with
573 * a single string, which can be one of "applied restrictions to sysops",
574 * "removed restrictions from sysops", or null.
576 * @param $n Integer: the new bitfield.
577 * @param $o Integer: the old bitfield.
578 * @return An array as described above.
580 protected static function getChanges( $n, $o ) {
581 $diff = $n ^ $o;
582 $ret = array( 0 => array(), 1 => array(), 2 => array() );
583 // Build bitfield changes in language
584 self::checkItem( wfMsgForContent( 'revdelete-content' ),
585 Revision::DELETED_TEXT, $diff, $n, $ret );
586 self::checkItem( wfMsgForContent( 'revdelete-summary' ),
587 Revision::DELETED_COMMENT, $diff, $n, $ret );
588 self::checkItem( wfMsgForContent( 'revdelete-uname' ),
589 Revision::DELETED_USER, $diff, $n, $ret );
590 // Restriction application to sysops
591 if( $diff & Revision::DELETED_RESTRICTED ) {
592 if( $n & Revision::DELETED_RESTRICTED )
593 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
594 else
595 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
597 return $ret;
601 * Gets a log message to describe the given revision visibility change. This
602 * message will be of the form "[hid {content, edit summary, username}];
603 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
605 * @param $count Integer: The number of effected revisions.
606 * @param $nbitfield Integer: The new bitfield for the revision.
607 * @param $obitfield Integer: The old bitfield for the revision.
608 * @param $isForLog Boolean
610 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
611 global $wgLang;
612 $s = '';
613 $changes = self::getChanges( $nbitfield, $obitfield );
614 if( count( $changes[0] ) ) {
615 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
617 if( count( $changes[1] ) ) {
618 if ($s) $s .= '; ';
619 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
621 if( count( $changes[2] ) ) {
622 $s .= $s ? ' (' . $changes[2][0] . ')' : $changes[2][0];
624 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
625 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
629 // Get DB field name for URL param...
630 // Future code for other things may also track
631 // other types of revision-specific changes.
632 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
633 public static function getRelationType( $typeName ) {
634 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
635 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
637 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
638 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
639 $list = new $class( null, null, null );
640 return $list->getIdField();
641 } else {
642 return null;
648 * Abstract base class for a list of deletable items
650 abstract class RevDel_List {
651 var $special, $title, $ids, $res, $current;
652 var $type = null; // override this
653 var $idField = null; // override this
654 var $dateField = false; // override this
655 var $authorIdField = false; // override this
656 var $authorNameField = false; // override this
659 * @param $special The parent SpecialPage
660 * @param $title The target title
661 * @param $ids Array of IDs
663 public function __construct( $special, $title, $ids ) {
664 $this->special = $special;
665 $this->title = $title;
666 $this->ids = $ids;
670 * Get the internal type name of this list. Equal to the table name.
672 public function getType() {
673 return $this->type;
677 * Get the DB field name associated with the ID list
679 public function getIdField() {
680 return $this->idField;
684 * Get the DB field name storing timestamps
686 public function getTimestampField() {
687 return $this->dateField;
691 * Get the DB field name storing user ids
693 public function getAuthorIdField() {
694 return $this->authorIdField;
698 * Get the DB field name storing user names
700 public function getAuthorNameField() {
701 return $this->authorNameField;
704 * Set the visibility for the revisions in this list. Logging and
705 * transactions are done here.
707 * @param $params Associative array of parameters. Members are:
708 * value: The integer value to set the visibility to
709 * comment: The log comment.
710 * @return Status
712 public function setVisibility( $params ) {
713 $newBits = $params['value'];
714 $comment = $params['comment'];
716 $this->res = false;
717 $dbw = wfGetDB( DB_MASTER );
718 $this->doQuery( $dbw );
719 $dbw->begin();
720 $status = Status::newGood();
721 $missing = array_flip( $this->ids );
722 $this->clearFileOps();
723 $idsForLog = array();
724 $authorIds = $authorIPs = array();
726 for ( $this->reset(); $this->current(); $this->next() ) {
727 $item = $this->current();
728 unset( $missing[ $item->getId() ] );
730 // Make error messages less vague
731 $oldBits = $item->getBits();
732 if ( $oldBits == $newBits ) {
733 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
734 $status->failCount++;
735 continue;
736 } elseif ( $oldBits == 0 && $newBits != 0 ) {
737 $opType = 'hide';
738 } elseif ( $oldBits != 0 && $newBits == 0 ) {
739 $opType = 'show';
740 } else {
741 $opType = 'modify';
744 if ( $item->isHideCurrentOp( $newBits ) ) {
745 // Cannot hide current version text
746 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
747 $status->failCount++;
748 continue;
750 if ( !$item->canView() ) {
751 // Cannot access this revision
752 $msg = $opType == 'show' ? 'revdelete-show-no-access' : 'revdelete-modify-no-access';
753 $status->error( $msg, $item->formatDate(), $item->formatTime() );
754 $status->failCount++;
755 continue;
758 // Update the revision
759 $ok = $item->setBits( $newBits );
761 if ( $ok ) {
762 $idsForLog[] = $item->getId();
763 $status->successCount++;
764 if( $item->getAuthorId() > 0 ) {
765 $authorIds[] = $item->getAuthorId();
766 } else if( IP::isIPAddress( $item->getAuthorName() ) ) {
767 $authorIPs[] = $item->getAuthorName();
769 } else {
770 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
771 $status->failCount++;
775 // Handle missing revisions
776 foreach ( $missing as $id => $unused ) {
777 $status->error( 'revdelete-modify-missing', $id );
778 $status->failCount++;
781 if ( $status->successCount == 0 ) {
782 $status->ok = false;
783 $dbw->rollback();
784 return $status;
787 // Save success count
788 $successCount = $status->successCount;
790 // Move files, if there are any
791 $status->merge( $this->doPreCommitUpdates() );
792 if ( !$status->isOK() ) {
793 // Fatal error, such as no configured archive directory
794 $dbw->rollback();
795 return $status;
798 // Log it
799 $this->updateLog( array(
800 'title' => $this->title,
801 'count' => $successCount,
802 'newBits' => $newBits,
803 'oldBits' => $oldBits,
804 'comment' => $comment,
805 'ids' => $idsForLog,
806 'authorIds' => $authorIds,
807 'authorIPs' => $authorIPs
808 ) );
809 $dbw->commit();
811 // Clear caches
812 $status->merge( $this->doPostCommitUpdates() );
813 return $status;
817 * Reload the list data from the master DB. This can be done after setVisibility()
818 * to allow $item->getHTML() to show the new data.
820 function reloadFromMaster() {
821 $dbw = wfGetDB( DB_MASTER );
822 $this->res = $this->doQuery( $dbw );
826 * Record a log entry on the action
827 * @param $params Associative array of parameters:
828 * newBits: The new value of the *_deleted bitfield
829 * oldBits: The old value of the *_deleted bitfield.
830 * title: The target title
831 * ids: The ID list
832 * comment: The log comment
833 * authorsIds: The array of the user IDs of the offenders
834 * authorsIPs: The array of the IP/anon user offenders
836 protected function updateLog( $params ) {
837 // Get the URL param's corresponding DB field
838 $field = RevisionDeleter::getRelationType( $this->getType() );
839 if( !$field ) {
840 throw new MWException( "Bad log URL param type!" );
842 // Put things hidden from sysops in the oversight log
843 if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
844 $logType = 'suppress';
845 } else {
846 $logType = 'delete';
848 // Add params for effected page and ids
849 $logParams = $this->getLogParams( $params );
850 // Actually add the deletion log entry
851 $log = new LogPage( $logType );
852 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
853 $params['comment'], $logParams );
854 // Allow for easy searching of deletion log items for revision/log items
855 $log->addRelations( $field, $params['ids'], $logid );
856 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
857 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
861 * Get the log action for this list type
863 public function getLogAction() {
864 return 'revision';
868 * Get log parameter array.
869 * @param $params Associative array of log parameters, same as updateLog()
870 * @return array
872 public function getLogParams( $params ) {
873 return array(
874 $this->getType(),
875 implode( ',', $params['ids'] ),
876 "ofield={$params['oldBits']}",
877 "nfield={$params['newBits']}"
882 * Initialise the current iteration pointer
884 protected function initCurrent() {
885 $row = $this->res->current();
886 if ( $row ) {
887 $this->current = $this->newItem( $row );
888 } else {
889 $this->current = false;
894 * Start iteration. This must be called before current() or next().
895 * @return First list item
897 public function reset() {
898 if ( !$this->res ) {
899 $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
900 } else {
901 $this->res->rewind();
903 $this->initCurrent();
904 return $this->current;
908 * Get the current list item, or false if we are at the end
910 public function current() {
911 return $this->current;
915 * Move the iteration pointer to the next list item, and return it.
917 public function next() {
918 $this->res->next();
919 $this->initCurrent();
920 return $this->current;
924 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
925 * STUB
927 public function clearFileOps() {
930 /**
931 * A hook for setVisibility(): do batch updates pre-commit.
932 * STUB
933 * @return Status
935 public function doPreCommitUpdates() {
936 return Status::newGood();
940 * A hook for setVisibility(): do any necessary updates post-commit.
941 * STUB
942 * @return Status
944 public function doPostCommitUpdates() {
945 return Status::newGood();
949 * Create an item object from a DB result row
950 * @param $row stdclass
952 abstract public function newItem( $row );
955 * Do the DB query to iterate through the objects.
956 * @param $db Database object to use for the query
958 abstract public function doQuery( $db );
961 * Get the integer value of the flag used for suppression
963 abstract public function getSuppressBit();
967 * Abstract base class for deletable items
969 abstract class RevDel_Item {
970 /** The parent SpecialPage */
971 var $special;
973 /** The parent RevDel_List */
974 var $list;
976 /** The DB result row */
977 var $row;
979 /**
980 * @param $list RevDel_List
981 * @param $row DB result row
983 public function __construct( $list, $row ) {
984 $this->special = $list->special;
985 $this->list = $list;
986 $this->row = $row;
990 * Get the ID, as it would appear in the ids URL parameter
992 public function getId() {
993 $field = $this->list->getIdField();
994 return $this->row->$field;
998 * Get the date, formatted with $wgLang
1000 public function formatDate() {
1001 global $wgLang;
1002 return $wgLang->date( $this->getTimestamp() );
1006 * Get the time, formatted with $wgLang
1008 public function formatTime() {
1009 global $wgLang;
1010 return $wgLang->time( $this->getTimestamp() );
1014 * Get the timestamp in MW 14-char form
1016 public function getTimestamp() {
1017 $field = $this->list->getTimestampField();
1018 return wfTimestamp( TS_MW, $this->row->$field );
1022 * Get the author user ID
1024 public function getAuthorId() {
1025 $field = $this->list->getAuthorIdField();
1026 return intval( $this->row->$field );
1030 * Get the author user name
1032 public function getAuthorName() {
1033 $field = $this->list->getAuthorNameField();
1034 return strval( $this->row->$field );
1037 /**
1038 * Returns true if the item is "current", and the operation to set the given
1039 * bits can't be executed for that reason
1040 * STUB
1042 public function isHideCurrentOp( $newBits ) {
1043 return false;
1047 * Returns true if the current user can view the item
1049 abstract public function canView();
1052 * Returns true if the current user can view the item text/file
1054 abstract public function canViewContent();
1057 * Get the current deletion bitfield value
1059 abstract public function getBits();
1062 * Get the HTML of the list item. Should be include <li></li> tags.
1063 * This is used to show the list in HTML form, by the special page.
1065 abstract public function getHTML();
1068 * Set the visibility of the item. This should do any necessary DB queries.
1070 * The DB update query should have a condition which forces it to only update
1071 * if the value in the DB matches the value fetched earlier with the SELECT.
1072 * If the update fails because it did not match, the function should return
1073 * false. This prevents concurrency problems.
1075 * @return boolean success
1077 abstract public function setBits( $newBits );
1081 * List for revision table items
1083 class RevDel_RevisionList extends RevDel_List {
1084 var $currentRevId;
1085 var $type = 'revision';
1086 var $idField = 'rev_id';
1087 var $dateField = 'rev_timestamp';
1088 var $authorIdField = 'rev_user';
1089 var $authorNameField = 'rev_user_text';
1091 public function doQuery( $db ) {
1092 $ids = array_map( 'intval', $this->ids );
1093 return $db->select( array('revision','page'), '*',
1094 array(
1095 'rev_page' => $this->title->getArticleID(),
1096 'rev_id' => $ids,
1097 'rev_page = page_id'
1099 __METHOD__
1103 public function newItem( $row ) {
1104 return new RevDel_RevisionItem( $this, $row );
1107 public function getCurrent() {
1108 if ( is_null( $this->currentRevId ) ) {
1109 $dbw = wfGetDB( DB_MASTER );
1110 $this->currentRevId = $dbw->selectField(
1111 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
1113 return $this->currentRevId;
1116 public function getSuppressBit() {
1117 return Revision::DELETED_RESTRICTED;
1120 public function doPreCommitUpdates() {
1121 $this->title->invalidateCache();
1122 return Status::newGood();
1125 public function doPostCommitUpdates() {
1126 $this->title->purgeSquid();
1127 // Extensions that require referencing previous revisions may need this
1128 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title ) );
1129 return Status::newGood();
1134 * Item class for a revision table row
1136 class RevDel_RevisionItem extends RevDel_Item {
1137 var $revision;
1139 public function __construct( $list, $row ) {
1140 parent::__construct( $list, $row );
1141 $this->revision = new Revision( $row );
1144 public function canView() {
1145 return $this->revision->userCan( Revision::DELETED_RESTRICTED );
1148 public function canViewContent() {
1149 return $this->revision->userCan( Revision::DELETED_TEXT );
1152 public function getBits() {
1153 return $this->revision->mDeleted;
1156 public function setBits( $bits ) {
1157 $dbw = wfGetDB( DB_MASTER );
1158 // Update revision table
1159 $dbw->update( 'revision',
1160 array( 'rev_deleted' => $bits ),
1161 array(
1162 'rev_id' => $this->revision->getId(),
1163 'rev_page' => $this->revision->getPage(),
1164 'rev_deleted' => $this->getBits()
1166 __METHOD__
1168 if ( !$dbw->affectedRows() ) {
1169 // Concurrent fail!
1170 return false;
1172 // Update recentchanges table
1173 $dbw->update( 'recentchanges',
1174 array(
1175 'rc_deleted' => $bits,
1176 'rc_patrolled' => 1
1178 array(
1179 'rc_this_oldid' => $this->revision->getId(), // condition
1180 // non-unique timestamp index
1181 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
1183 __METHOD__
1185 return true;
1188 public function isDeleted() {
1189 return $this->revision->isDeleted( Revision::DELETED_TEXT );
1192 public function isHideCurrentOp( $newBits ) {
1193 return ( $newBits & Revision::DELETED_TEXT )
1194 && $this->list->getCurrent() == $this->getId();
1198 * Get the HTML link to the revision text.
1199 * Overridden by RevDel_ArchiveItem.
1201 protected function getRevisionLink() {
1202 global $wgLang;
1203 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
1204 if ( $this->isDeleted() && !$this->canViewContent() ) {
1205 return $date;
1207 return $this->special->skin->link(
1208 $this->list->title,
1209 $date,
1210 array(),
1211 array(
1212 'oldid' => $this->revision->getId(),
1213 'unhide' => 1
1219 * Get the HTML link to the diff.
1220 * Overridden by RevDel_ArchiveItem
1222 protected function getDiffLink() {
1223 if ( $this->isDeleted() && !$this->canViewContent() ) {
1224 return wfMsgHtml('diff');
1225 } else {
1226 return
1227 $this->special->skin->link(
1228 $this->list->title,
1229 wfMsgHtml('diff'),
1230 array(),
1231 array(
1232 'diff' => $this->revision->getId(),
1233 'oldid' => 'prev',
1234 'unhide' => 1
1236 array(
1237 'known',
1238 'noclasses'
1244 public function getHTML() {
1245 $difflink = $this->getDiffLink();
1246 $revlink = $this->getRevisionLink();
1247 $userlink = $this->special->skin->revUserLink( $this->revision );
1248 $comment = $this->special->skin->revComment( $this->revision );
1249 if ( $this->isDeleted() ) {
1250 $revlink = "<span class=\"history-deleted\">$revlink</span>";
1252 return "<li>($difflink) $revlink $userlink $comment</li>";
1257 * List for archive table items, i.e. revisions deleted via action=delete
1259 class RevDel_ArchiveList extends RevDel_RevisionList {
1260 var $type = 'archive';
1261 var $idField = 'ar_timestamp';
1262 var $dateField = 'ar_timestamp';
1263 var $authorIdField = 'ar_user';
1264 var $authorNameField = 'ar_user_text';
1266 public function doQuery( $db ) {
1267 $timestamps = array();
1268 foreach ( $this->ids as $id ) {
1269 $timestamps[] = $db->timestamp( $id );
1271 return $db->select( 'archive', '*',
1272 array(
1273 'ar_namespace' => $this->title->getNamespace(),
1274 'ar_title' => $this->title->getDBkey(),
1275 'ar_timestamp' => $timestamps
1277 __METHOD__
1281 public function newItem( $row ) {
1282 return new RevDel_ArchiveItem( $this, $row );
1285 public function doPreCommitUpdates() {
1286 return Status::newGood();
1289 public function doPostCommitUpdates() {
1290 return Status::newGood();
1295 * Item class for a archive table row
1297 class RevDel_ArchiveItem extends RevDel_RevisionItem {
1298 public function __construct( $list, $row ) {
1299 RevDel_Item::__construct( $list, $row );
1300 $this->revision = Revision::newFromArchiveRow( $row,
1301 array( 'page' => $this->list->title->getArticleId() ) );
1304 public function getId() {
1305 # Convert DB timestamp to MW timestamp
1306 return $this->revision->getTimestamp();
1309 public function setBits( $bits ) {
1310 $dbw = wfGetDB( DB_MASTER );
1311 $dbw->update( 'archive',
1312 array( 'ar_deleted' => $bits ),
1313 array( 'ar_namespace' => $this->list->title->getNamespace(),
1314 'ar_title' => $this->list->title->getDBkey(),
1315 // use timestamp for index
1316 'ar_timestamp' => $this->row->ar_timestamp,
1317 'ar_rev_id' => $this->row->ar_rev_id,
1318 'ar_deleted' => $this->getBits()
1320 __METHOD__ );
1321 return (bool)$dbw->affectedRows();
1324 protected function getRevisionLink() {
1325 global $wgLang;
1326 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1327 $date = $wgLang->timeanddate( $this->revision->getTimestamp(), true );
1328 if ( $this->isDeleted() && !$this->canViewContent() ) {
1329 return $date;
1331 return $this->special->skin->link( $undelete, $date, array(),
1332 array(
1333 'target' => $this->list->title->getPrefixedText(),
1334 'timestamp' => $this->revision->getTimestamp()
1335 ) );
1338 protected function getDiffLink() {
1339 if ( $this->isDeleted() && !$this->canViewContent() ) {
1340 return wfMsgHtml( 'diff' );
1342 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1343 return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(),
1344 array(
1345 'target' => $this->list->title->getPrefixedText(),
1346 'diff' => 'prev',
1347 'timestamp' => $this->revision->getTimestamp()
1348 ) );
1353 * List for oldimage table items
1355 class RevDel_FileList extends RevDel_List {
1356 var $type = 'oldimage';
1357 var $idField = 'oi_archive_name';
1358 var $dateField = 'oi_timestamp';
1359 var $authorIdField = 'oi_user';
1360 var $authorNameField = 'oi_user_text';
1361 var $storeBatch, $deleteBatch, $cleanupBatch;
1363 public function doQuery( $db ) {
1364 $archiveName = array();
1365 foreach( $this->ids as $timestamp ) {
1366 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
1368 return $db->select( 'oldimage', '*',
1369 array(
1370 'oi_name' => $this->title->getDBkey(),
1371 'oi_archive_name' => $archiveNames
1373 __METHOD__
1377 public function newItem( $row ) {
1378 return new RevDel_FileItem( $this, $row );
1381 public function clearFileOps() {
1382 $this->deleteBatch = array();
1383 $this->storeBatch = array();
1384 $this->cleanupBatch = array();
1387 public function doPreCommitUpdates() {
1388 $status = Status::newGood();
1389 $repo = RepoGroup::singleton()->getLocalRepo();
1390 if ( $this->storeBatch ) {
1391 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
1393 if ( !$status->isOK() ) {
1394 return $status;
1396 if ( $this->deleteBatch ) {
1397 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
1399 if ( !$status->isOK() ) {
1400 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1401 // modified (but destined for rollback) causes data loss
1402 return $status;
1404 if ( $this->cleanupBatch ) {
1405 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
1407 return $status;
1410 public function doPostCommitUpdates() {
1411 $file = wfLocalFile( $this->title );
1412 $file->purgeCache();
1413 $file->purgeDescription();
1414 return Status::newGood();
1417 public function getSuppressBit() {
1418 return File::DELETED_RESTRICTED;
1423 * Item class for an oldimage table row
1425 class RevDel_FileItem extends RevDel_Item {
1426 var $file;
1428 public function __construct( $list, $row ) {
1429 parent::__construct( $list, $row );
1430 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
1433 public function getId() {
1434 $parts = explode( '!', $this->row->oi_archive_name );
1435 return $parts[0];
1438 public function canView() {
1439 return $this->file->userCan( File::DELETED_RESTRICTED );
1442 public function canViewContent() {
1443 return $this->file->userCan( File::DELETED_FILE );
1446 public function getBits() {
1447 return $this->file->getVisibility();
1450 public function setBits( $bits ) {
1451 # Queue the file op
1452 # FIXME: move to LocalFile.php
1453 if ( $this->isDeleted() ) {
1454 if ( $bits & File::DELETED_FILE ) {
1455 # Still deleted
1456 } else {
1457 # Newly undeleted
1458 $key = $this->file->getStorageKey();
1459 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1460 $this->list->storeBatch[] = array(
1461 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1462 'public',
1463 $this->file->getRel()
1465 $this->list->cleanupBatch[] = $key;
1467 } elseif ( $bits & File::DELETED_FILE ) {
1468 # Newly deleted
1469 $key = $this->file->getStorageKey();
1470 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
1471 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
1474 # Do the database operations
1475 $dbw = wfGetDB( DB_MASTER );
1476 $dbw->update( 'oldimage',
1477 array( 'oi_deleted' => $bits ),
1478 array(
1479 'oi_name' => $this->row->oi_name,
1480 'oi_timestamp' => $this->row->oi_timestamp,
1481 'oi_deleted' => $this->getBits()
1483 __METHOD__
1485 return (bool)$dbw->affectedRows();
1488 public function isDeleted() {
1489 return $this->file->isDeleted( File::DELETED_FILE );
1493 * Get the link to the file.
1494 * Overridden by RevDel_ArchivedFileItem.
1496 protected function getLink() {
1497 global $wgLang, $wgUser;
1498 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1499 if ( $this->isDeleted() ) {
1500 # Hidden files...
1501 if ( !$this->canViewContent() ) {
1502 $link = $date;
1503 } else {
1504 $link = $this->special->skin->link(
1505 $this->special->getTitle(),
1506 $date, array(),
1507 array(
1508 'target' => $this->list->title->getPrefixedText(),
1509 'file' => $this->file->getArchiveName(),
1510 'token' => $wgUser->editToken( $this->file->getArchiveName() )
1514 return '<span class="history-deleted">' . $link . '</span>';
1515 } else {
1516 # Regular files...
1517 $url = $this->file->getUrl();
1518 return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
1522 * Generate a user tool link cluster if the current user is allowed to view it
1523 * @return string HTML
1525 protected function getUserTools() {
1526 if( $this->file->userCan( Revision::DELETED_USER ) ) {
1527 $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
1528 $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
1529 } else {
1530 $link = wfMsgHtml( 'rev-deleted-user' );
1532 if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
1533 return '<span class="history-deleted">' . $link . '</span>';
1535 return $link;
1539 * Wrap and format the file's comment block, if the current
1540 * user is allowed to view it.
1542 * @return string HTML
1544 protected function getComment() {
1545 if( $this->file->userCan( File::DELETED_COMMENT ) ) {
1546 $block = $this->special->skin->commentBlock( $this->file->description );
1547 } else {
1548 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1550 if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
1551 return "<span class=\"history-deleted\">$block</span>";
1553 return $block;
1556 public function getHTML() {
1557 global $wgLang;
1558 $data =
1559 wfMsg(
1560 'widthheight',
1561 $wgLang->formatNum( $this->file->getWidth() ),
1562 $wgLang->formatNum( $this->file->getHeight() )
1564 ' (' .
1565 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) .
1566 ')';
1567 $pageLink = $this->getLink();
1569 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1570 $data . ' ' . $this->getComment(). '</li>';
1575 * List for filearchive table items
1577 class RevDel_ArchivedFileList extends RevDel_FileList {
1578 var $type = 'filearchive';
1579 var $idField = 'fa_id';
1580 var $dateField = 'fa_timestamp';
1581 var $authorIdField = 'fa_user';
1582 var $authorNameField = 'fa_user_text';
1584 public function doQuery( $db ) {
1585 $ids = array_map( 'intval', $this->ids );
1586 return $db->select( 'filearchive', '*',
1587 array(
1588 'fa_name' => $this->title->getDBkey(),
1589 'fa_id' => $ids
1591 __METHOD__
1595 public function newItem( $row ) {
1596 return new RevDel_ArchivedFileItem( $this, $row );
1601 * Item class for a filearchive table row
1603 class RevDel_ArchivedFileItem extends RevDel_FileItem {
1604 public function __construct( $list, $row ) {
1605 RevDel_Item::__construct( $list, $row );
1606 $this->file = ArchivedFile::newFromRow( $row );
1609 public function getId() {
1610 return $this->row->fa_id;
1613 public function setBits( $bits ) {
1614 $dbw = wfGetDB( DB_MASTER );
1615 $dbw->update( 'filearchive',
1616 array( 'fa_deleted' => $bits ),
1617 array(
1618 'fa_id' => $this->row->fa_id,
1619 'fa_deleted' => $this->getBits(),
1621 __METHOD__
1623 return (bool)$dbw->affectedRows();
1626 protected function getLink() {
1627 global $wgLang, $wgUser;
1628 $date = $wgLang->timeanddate( $this->file->getTimestamp(), true );
1629 $undelete = SpecialPage::getTitleFor( 'Undelete' );
1630 $key = $this->file->getKey();
1631 # Hidden files...
1632 if( !$this->canViewContent() ) {
1633 $link = $date;
1634 } else {
1635 $link = $this->special->skin->link( $undelete, $date, array(),
1636 array(
1637 'target' => $this->list->title->getPrefixedText(),
1638 'file' => $key,
1639 'token' => $wgUser->editToken( $key )
1643 if( $this->isDeleted() ) {
1644 $link = '<span class="history-deleted">' . $link . '</span>';
1646 return $link;
1651 * List for logging table items
1653 class RevDel_LogList extends RevDel_List {
1654 var $type = 'logging';
1655 var $idField = 'log_id';
1656 var $dateField = 'log_timestamp';
1657 var $authorIdField = 'log_user';
1658 var $authorNameField = 'log_user_text';
1660 public function doQuery( $db ) {
1661 global $wgMessageCache;
1662 $wgMessageCache->loadAllMessages();
1663 $ids = array_map( 'intval', $this->ids );
1664 return $db->select( 'logging', '*',
1665 array( 'log_id' => $ids ),
1666 __METHOD__
1670 public function newItem( $row ) {
1671 return new RevDel_LogItem( $this, $row );
1674 public function getSuppressBit() {
1675 return Revision::DELETED_RESTRICTED;
1678 public function getLogAction() {
1679 return 'event';
1682 public function getLogParams( $params ) {
1683 return array(
1684 implode( ',', $params['ids'] ),
1685 "ofield={$params['oldBits']}",
1686 "nfield={$params['newBits']}"
1692 * Item class for a logging table row
1694 class RevDel_LogItem extends RevDel_Item {
1695 public function canView() {
1696 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
1699 public function canViewContent() {
1700 return true; // none
1703 public function getBits() {
1704 return $this->row->log_deleted;
1707 public function setBits( $bits ) {
1708 $dbw = wfGetDB( DB_MASTER );
1709 $dbw->update( 'recentchanges',
1710 array(
1711 'rc_deleted' => $bits,
1712 'rc_patrolled' => 1
1714 array(
1715 'rc_logid' => $this->row->log_id,
1716 'rc_timestamp' => $this->row->log_timestamp // index
1718 __METHOD__
1720 $dbw->update( 'logging',
1721 array( 'log_deleted' => $bits ),
1722 array(
1723 'log_id' => $this->row->log_id,
1724 'log_deleted' => $this->getBits()
1726 __METHOD__
1728 return (bool)$dbw->affectedRows();
1731 public function getHTML() {
1732 global $wgLang;
1734 $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
1735 $paramArray = LogPage::extractParams( $this->row->log_params );
1736 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
1738 // Log link for this page
1739 $loglink = $this->special->skin->link(
1740 SpecialPage::getTitleFor( 'Log' ),
1741 wfMsgHtml( 'log' ),
1742 array(),
1743 array( 'page' => $title->getPrefixedText() )
1745 // Action text
1746 if( !$this->canView() ) {
1747 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1748 } else {
1749 $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
1750 $this->special->skin, $paramArray, true, true );
1751 if( $this->row->log_deleted & LogPage::DELETED_ACTION )
1752 $action = '<span class="history-deleted">' . $action . '</span>';
1754 // User links
1755 $userLink = $this->special->skin->userLink( $this->row->log_user,
1756 User::WhoIs( $this->row->log_user ) );
1757 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
1758 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
1760 // Comment
1761 $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
1762 if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
1763 $comment = '<span class="history-deleted">' . $comment . '</span>';
1765 return "<li>($loglink) $date $userLink $action $comment</li>";