More ancient deprecated functions:
[lhc/web/wiklou.git] / includes / specials / SpecialRevisiondelete.php
index b78cb2f..f77fc34 100644 (file)
 <?php
 /**
- * Special page allowing users with the appropriate permissions to view
- * and hide revisions. Log items can also be hidden.
+ * Implements Special:Revisiondelete
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup SpecialPage
  */
 
+/**
+ * Special page allowing users with the appropriate permissions to view
+ * and hide revisions. Log items can also be hidden.
+ *
+ * @ingroup SpecialPage
+ */
 class SpecialRevisionDelete extends UnlistedSpecialPage {
+       /** Skin object */
+       var $skin;
+
+       /** True if the submit button was clicked, and the form was posted */
+       var $submitClicked;
+
+       /** Target ID list */
+       var $ids;
+
+       /** Archive name, for reviewing deleted files */
+       var $archiveName;
+
+       /** Edit token for securing image views against XSS */
+       var $token;
+
+       /** Title object for target parameter */
+       var $targetObj;
+
+       /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
+       var $typeName;
+
+       /** Array of checkbox specs (message, name, deletion bits) */
+       var $checks;
+
+       /** Information about the current type */
+       var $typeInfo;
+
+       /** The RevDel_List object, storing the list of items to be deleted/undeleted */
+       var $list;
+
+       /**
+        * Assorted information about each type, needed by the special page.
+        * TODO Move some of this to the list class
+        */
+       static $allowedTypes = array(
+               'revision' => array(
+                       'check-label' => 'revdelete-hide-text',
+                       'deletion-bits' => Revision::DELETED_TEXT,
+                       'success' => 'revdelete-success',
+                       'failure' => 'revdelete-failure',
+                       'list-class' => 'RevDel_RevisionList',
+               ),
+               'archive' => array(
+                       'check-label' => 'revdelete-hide-text',
+                       'deletion-bits' => Revision::DELETED_TEXT,
+                       'success' => 'revdelete-success',
+                       'failure' => 'revdelete-failure',
+                       'list-class' => 'RevDel_ArchiveList',
+               ),
+               'oldimage'=> array(
+                       'check-label' => 'revdelete-hide-image',
+                       'deletion-bits' => File::DELETED_FILE,
+                       'success' => 'revdelete-success',
+                       'failure' => 'revdelete-failure',
+                       'list-class' => 'RevDel_FileList',
+               ),
+               'filearchive' => array(
+                       'check-label' => 'revdelete-hide-image',
+                       'deletion-bits' => File::DELETED_FILE,
+                       'success' => 'revdelete-success',
+                       'failure' => 'revdelete-failure',
+                       'list-class' => 'RevDel_ArchivedFileList',
+               ),
+               'logging' => array(
+                       'check-label' => 'revdelete-hide-name',
+                       'deletion-bits' => LogPage::DELETED_ACTION,
+                       'success' => 'logdelete-success',
+                       'failure' => 'logdelete-failure',
+                       'list-class' => 'RevDel_LogList',
+               ),
+       );
+
+       /** Type map to support old log entries */
+       static $deprecatedTypeMap = array(
+               'oldid' => 'revision',
+               'artimestamp' => 'archive',
+               'oldimage' => 'oldimage',
+               'fileid' => 'filearchive',
+               'logid' => 'logging',
+       );
 
        public function __construct() {
-               parent::__construct( 'Revisiondelete', 'deleterevision' );
-               $this->includable( false ); // paranoia
+               parent::__construct( 'Revisiondelete', 'deletedhistory' );
        }
 
        public function execute( $par ) {
                global $wgOut, $wgUser, $wgRequest;
-               if( !$wgUser->isAllowed( 'deleterevision' ) ) {
-                       return $wgOut->permissionRequired( 'deleterevision' );
+               if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
+                       $wgOut->permissionRequired( 'deletedhistory' );
+                       return;
                } else if( wfReadOnly() ) {
-                       return $wgOut->readOnlyPage();
+                       $wgOut->readOnlyPage();
+                       return;
                }
-               $this->skin =& $wgUser->getSkin();
+               $this->mIsAllowed = $wgUser->isAllowed('deleterevision'); // for changes
+               $this->skin = $wgUser->getSkin();
                $this->setHeaders();
                $this->outputHeader();
-               $this->wasPosted = $wgRequest->wasPosted();
-               # Set title and such
-               $this->target = $wgRequest->getText( 'target' );
+               $this->submitClicked = $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
                # Handle our many different possible input types.
-               # Use CVS, since the cgi handling will break on arrays.
-               $this->oldids = explode( ',', $wgRequest->getVal('oldid') );
-               $this->oldids = array_unique( array_filter($this->oldids) );
-               $this->artimestamps = explode( ',', $wgRequest->getVal('artimestamp') );
-               $this->artimestamps = array_unique( array_filter($this->artimestamps) );
-               $this->logids = explode( ',', $wgRequest->getVal('logid') );
-               $this->logids = array_unique( array_filter($this->logids) );
-               $this->oldimgs = explode( ',', $wgRequest->getVal('oldimage') );
-               $this->oldimgs = array_unique( array_filter($this->oldimgs) );
-               $this->fileids = explode( ',', $wgRequest->getVal('fileid') );
-               $this->fileids = array_unique( array_filter($this->fileids) );
+               $ids = $wgRequest->getVal( 'ids' );
+               if ( !is_null( $ids ) ) {
+                       # Allow CSV, for backwards compatibility, or a single ID for show/hide links
+                       $this->ids = explode( ',', $ids );
+               } else {
+                       # Array input
+                       $this->ids = array_keys( $wgRequest->getArray('ids',array()) );
+               }
+               // $this->ids = array_map( 'intval', $this->ids );
+               $this->ids = array_unique( array_filter( $this->ids ) );
+
+               if ( $wgRequest->getVal( 'action' ) == 'historysubmit' ) {
+                       # For show/hide form submission from history page
+                       $this->targetObj = $GLOBALS['wgTitle'];
+                       $this->typeName = 'revision';
+               } else {
+                       $this->typeName = $wgRequest->getVal( 'type' );
+                       $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
+               }
+
                # For reviewing deleted files...
-               $this->file = $wgRequest->getVal( 'file' );
-               # Only one target set at a time please!
-               $types = (bool)$this->file + (bool)$this->oldids + (bool)$this->logids
-                       + (bool)$this->artimestamps + (bool)$this->fileids + (bool)$this->oldimgs;
+               $this->archiveName = $wgRequest->getVal( 'file' );
+               $this->token = $wgRequest->getVal( 'token' );
+               if ( $this->archiveName && $this->targetObj ) {
+                       $this->tryShowFile( $this->archiveName );
+                       return;
+               }
+
+               if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) {
+                       $this->typeName = self::$deprecatedTypeMap[$this->typeName];
+               }
+
                # No targets?
-               if( $types == 0 ) {
-                       return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
-               # Too many targets?
-               } else if( $types > 1 ) {
-                       return $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
+               if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) {
+                       $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
+                       return;
                }
-               $this->page = Title::newFromUrl( $this->target );
-               $this->contextPage = Title::newFromUrl( $wgRequest->getText( 'page' ) );
+               $this->typeInfo = self::$allowedTypes[$this->typeName];
+
                # If we have revisions, get the title from the first one
                # since they should all be from the same page. This allows 
                # for more flexibility with page moves...
-               if( count($this->oldids) > 0 ) {
-                       $rev = Revision::newFromId( $this->oldids[0] );
-                       $this->page = $rev ? $rev->getTitle() : $this->page;
+               if( $this->typeName == 'revision' ) {
+                       $rev = Revision::newFromId( $this->ids[0] );
+                       $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj;
                }
+               
+               $this->otherReason = $wgRequest->getVal( 'wpReason' );
                # We need a target page!
-               if( is_null($this->page) ) {
-                       return $wgOut->addWikiMsg( 'undelete-header' );
-               }
-               # For reviewing deleted files...show it now if allowed
-               if( $this->file ) {
-                       return $this->tryShowFile( $this->file );
-               }
-               # Logs must have a type given
-               if( $this->logids && !strpos($this->page->getDBKey(),'/') ) {
-                       return $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
+               if( is_null($this->targetObj) ) {
+                       $wgOut->addWikiMsg( 'undelete-header' );
+                       return;
                }
                # Give a link to the logs/hist for this page
                $this->showConvenienceLinks();
-               # Lock the operation and the form context
-               $this->secureOperation();
+
+               # Initialise checkboxes
+               $this->checks = array(
+                       array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ),
+                       array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
+                       array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
+               );
+               if( $wgUser->isAllowed('suppressrevision') ) {
+                       $this->checks[] = array( 'revdelete-hide-restricted',
+                               'wpHideRestricted', Revision::DELETED_RESTRICTED );
+               }
+
                # Either submit or create our form
-               if( $this->wasPosted ) {
+               if( $this->mIsAllowed && $this->submitClicked ) {
                        $this->submit( $wgRequest );
-               } else if( $this->deleteKey == 'oldid' || $this->deleteKey == 'artimestamp' ) {
-                       $this->showRevs();
-               } else if( $this->deleteKey == 'fileid' || $this->deleteKey == 'oldimage' ) {
-                       $this->showImages();
-               } else if( $this->deleteKey == 'logid' ) {
-                       $this->showLogItems();
+               } else {
+                       $this->showForm();
                }
-               list($qc,$lim) = $this->getLogQueryCond();
+               
+               $qc = $this->getLogQueryCond();
                # Show relevant lines from the deletion log
                $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
-               LogEventsList::showLogExtract( $wgOut, 'delete', $this->page->getPrefixedText(), '', $lim, $qc );
+               LogEventsList::showLogExtract( $wgOut, 'delete',
+                       $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
                # Show relevant lines from the suppression log
                if( $wgUser->isAllowed( 'suppressionlog' ) ) {
                        $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
-                       LogEventsList::showLogExtract( $wgOut, 'suppress', $this->page->getPrefixedText(), '', $lim, $qc );
+                       LogEventsList::showLogExtract( $wgOut, 'suppress',
+                               $this->targetObj->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
                }
        }
-       
-       private function showConvenienceLinks() {
-               global $wgOut, $wgUser;
+
+       /**
+        * Show some useful links in the subtitle
+        */
+       protected function showConvenienceLinks() {
+               global $wgOut, $wgUser, $wgLang;
                # Give a link to the logs/hist for this page
-               if( !is_null($this->page) && $this->page->getNamespace() > -1 ) {
+               if( $this->targetObj ) {
                        $links = array();
-                       $logtitle = SpecialPage::getTitleFor( 'Log' );
-                       $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
-                               wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) );
-                       # Give a link to the page history
-                       $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
-                               wfArrayToCGI( array( 'action' => 'history' ) ) );
-                       # Link to deleted edits
-                       if( $wgUser->isAllowed('undelete') ) {
-                               $undelete = SpecialPage::getTitleFor( 'Undelete' );
-                               $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
-                                       wfArrayToCGI( array( 'target' => $this->page->getPrefixedDBkey() ) ) );
+                       $links[] = $this->skin->linkKnown(
+                               SpecialPage::getTitleFor( 'Log' ),
+                               wfMsgHtml( 'viewpagelogs' ),
+                               array(),
+                               array( 'page' => $this->targetObj->getPrefixedText() )
+                       );
+                       if ( $this->targetObj->getNamespace() != NS_SPECIAL ) {
+                               # Give a link to the page history
+                               $links[] = $this->skin->linkKnown(
+                                       $this->targetObj,
+                                       wfMsgHtml( 'pagehist' ),
+                                       array(),
+                                       array( 'action' => 'history' )
+                               );
+                               # Link to deleted edits
+                               if( $wgUser->isAllowed('undelete') ) {
+                                       $undelete = SpecialPage::getTitleFor( 'Undelete' );
+                                       $links[] = $this->skin->linkKnown(
+                                               $undelete,
+                                               wfMsgHtml( 'deletedhist' ),
+                                               array(),
+                                               array( 'target' => $this->targetObj->getPrefixedDBkey() )
+                                       );
+                               }
                        }
                        # Logs themselves don't have histories or archived revisions
-                       $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
-               }
-       }
-       
-       private function getLogQueryCond() {
-               $ids = $safeIds = array();
-               $action = 'revision';
-               $limit = 25; // default
-               switch( $this->deleteKey ) {
-                       case 'oldid':
-                               $ids = $this->oldids;
-                               break;
-                       case 'artimestamp':
-                               $ids = $this->artimestamps;
-                               break;
-                       case 'oldimage':
-                               $ids = $this->oldimgs;
-                               break;
-                       case 'fileid':
-                               $ids = $this->fileids;
-                               break;
-                       case 'logid':
-                               $ids = $this->logids;
-                               $action = 'event';
-                               break;
-               }
-               // Revision delete logs
-               $conds = array( 'log_action' => $action );
-               // Just get the whole log if there are a lot if items
-               if( count($ids) > $limit )
-                       return array($conds,$limit);
-               // Digit chars only
-               foreach( $ids as $id ) {
-                       if( preg_match( '/^\d+$/', $id, $m ) ) {
-                               $safeIds[] = $m[0];
-                       }
+                       $wgOut->setSubtitle( '<p>' . $wgLang->pipeList( $links ) . '</p>' );
                }
-               // Optimization for logs
-               if( $action == 'event' ) {
-                       $dbr = wfGetDB( DB_SLAVE );
-                       # Get the timestamp of the first item
-                       $first = $dbr->selectField( 'logging', 'log_timestamp',
-                               array('log_id' => $safeIds), __METHOD__, array('ORDER BY' => 'log_id') );
-                       # If there are no items, then stop here
-                       if( $first == false ) {
-                               $conds = array('1=0');
-                               return array($conds,$limit);
-                       }
-                       # The event was be hidden after it was made
-                       $conds[] = 'log_timestamp > '.$dbr->addQuotes($first); // type,time index
-               }
-               // Format is <id1,id2,i3...>
-               if( count($safeIds) ) {
-                       $conds[] = "log_params RLIKE '(^|\n|,)(".implode('|',$safeIds).")(,|\n|$)'";
-               } else {
-                       $conds = array('1=0');
-               }
-               return array($conds,$limit);
        }
 
-       private function secureOperation() {
-               global $wgUser;
-               $this->deleteKey = '';
-               // At this point, we should only have one of these
-               if( $this->oldids ) {
-                       $this->revisions = $this->oldids;
-                       $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
-                       $this->deleteKey = 'oldid';
-               } else if( $this->artimestamps ) {
-                       $this->archrevs = $this->artimestamps;
-                       $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
-                       $this->deleteKey = 'artimestamp';
-               } else if( $this->oldimgs ) {
-                       $this->ofiles = $this->oldimgs;
-                       $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
-                       $this->deleteKey = 'oldimage';
-               } else if( $this->fileids ) {
-                       $this->afiles = $this->fileids;
-                       $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
-                       $this->deleteKey = 'fileid';
-               } else if( $this->logids ) {
-                       $this->events = $this->logids;
-                       $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage::DELETED_ACTION );
-                       $this->deleteKey = 'logid';
-               }
-               // Our checkbox messages depends one what we are doing,
-               // e.g. we don't hide "text" for logs or images
-               $this->checks = array(
-                       $hide_content_name,
-                       array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
-                       array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
-               );
-               if( $wgUser->isAllowed('suppressrevision') ) {
-                       $this->checks[] = array( 'revdelete-hide-restricted',
-                               'wpHideRestricted', Revision::DELETED_RESTRICTED );
-               }
+       /**
+        * Get the condition used for fetching log snippets
+        */
+       protected function getLogQueryCond() {
+               $conds = array();
+               // Revision delete logs for these item
+               $conds['log_type'] = array('delete','suppress');
+               $conds['log_action'] = $this->getList()->getLogAction();
+               $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
+               $conds['ls_value'] = $this->ids;
+               return $conds;
        }
 
        /**
         * Show a deleted file version requested by the visitor.
+        * TODO Mostly copied from Special:Undelete. Refactor.
         */
-       private function tryShowFile( $key ) {
-               global $wgOut, $wgRequest;
-               $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->page, $key );
+       protected function tryShowFile( $archiveName ) {
+               global $wgOut, $wgRequest, $wgUser, $wgLang;
+
+               $repo = RepoGroup::singleton()->getLocalRepo();
+               $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName );
                $oimage->load();
                // Check if user is allowed to see this file
-               if( !$oimage->userCan(File::DELETED_FILE) ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-               } else {
-                       $wgOut->disable();
-                       # We mustn't allow the output to be Squid cached, otherwise
-                       # if an admin previews a deleted image, and it's cached, then
-                       # a user without appropriate permissions can toddle off and
-                       # nab the image, and Squid will serve it
-                       $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
-                       $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
-                       $wgRequest->response()->header( 'Pragma: no-cache' );
-                       # Stream the file to the client
-                       $store = FileStore::get( 'deleted' );
-                       $store->stream( $key );
+               if ( !$oimage->exists() ) {
+                       $wgOut->addWikiMsg( 'revdelete-no-file' );
+                       return;
                }
-       }
-
-       /**
-        * This lets a user set restrictions for live and archived revisions
-        */
-       private function showRevs() {
-               global $wgOut, $wgUser;
-               $UserAllowed = true;
-
-               $count = ($this->deleteKey == 'oldid') ?
-                       count($this->revisions) : count($this->archrevs);
-               $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count );
-
-               $bitfields = 0;
-               $wgOut->addHTML( "<ul>" );
-
-               $where = $revObjs = array();
-               $dbr = wfGetDB( DB_MASTER );
-               
-               $revisions = 0;
-               // Live revisions...
-               if( $this->deleteKey == 'oldid' ) {
-                       // Run through and pull all our data in one query
-                       foreach( $this->revisions as $revid ) {
-                               $where[] = intval($revid);
-                       }
-                       $result = $dbr->select( array('revision','page'), '*',
-                               array(
-                                       'rev_page' => $this->page->getArticleID(),
-                                       'rev_id'   => $where,
-                                       'rev_page = page_id'
-                               ),
-                               __METHOD__
-                       );
-                       while( $row = $dbr->fetchObject( $result ) ) {
-                               $revObjs[$row->rev_id] = new Revision( $row );
-                       }
-                       foreach( $this->revisions as $revid ) {
-                               if( !isset($revObjs[$revid]) ) continue; // Must exist
-                               // Check if the revision was Oversighted
-                               if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
-                                       if( !$this->wasPosted ) {
-                                               return $wgOut->permissionRequired( 'suppressrevision' );
-                                       }
-                                       $UserAllowed = false;
-                               }
-                               $revisions++;
-                               $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
-                               $bitfields |= $revObjs[$revid]->mDeleted;
-                       }
-               // The archives...
-               } else {
-                       // Run through and pull all our data in one query
-                       foreach( $this->archrevs as $timestamp ) {
-                               $where[] = $dbr->timestamp( $timestamp );
+               if( !$oimage->userCan(File::DELETED_FILE) ) {
+                       if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) {
+                               $wgOut->permissionRequired( 'suppressrevision' );
+                       } else {
+                               $wgOut->permissionRequired( 'deletedtext' );
                        }
-                       $result = $dbr->select( 'archive', '*',
-                               array(
-                                       'ar_namespace' => $this->page->getNamespace(),
-                                       'ar_title'     => $this->page->getDBKey(),
-                                       'ar_timestamp' => $where
-                               ),
-                               __METHOD__
+                       return;
+               }
+               if ( !$wgUser->matchEditToken( $this->token, $archiveName ) ) {
+                       $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
+                               $this->targetObj->getText(),
+                               $wgLang->date( $oimage->getTimestamp() ),
+                               $wgLang->time( $oimage->getTimestamp() ) );
+                       $wgOut->addHTML(
+                               Xml::openElement( 'form', array(
+                                       'method' => 'POST',
+                                       'action' => $this->getTitle()->getLocalUrl(
+                                               'target=' . urlencode( $oimage->getName() ) .
+                                               '&file=' . urlencode( $archiveName ) .
+                                               '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
+                                       )
+                               ) .
+                               Xml::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
+                               '</form>'
                        );
-                       while( $row = $dbr->fetchObject( $result ) ) {
-                               $timestamp = wfTimestamp( TS_MW, $row->ar_timestamp );
-                               $revObjs[$timestamp] = new Revision( array(
-                                       'page'       => $this->page->getArticleId(),
-                                       'id'         => $row->ar_rev_id,
-                                       'text'       => $row->ar_text_id,
-                                       'comment'    => $row->ar_comment,
-                                       'user'       => $row->ar_user,
-                                       'user_text'  => $row->ar_user_text,
-                                       'timestamp'  => $timestamp,
-                                       'minor_edit' => $row->ar_minor_edit,
-                                       'text_id'    => $row->ar_text_id,
-                                       'deleted'    => $row->ar_deleted,
-                                       'len'        => $row->ar_len) );
-                       }
-                       foreach( $this->archrevs as $timestamp ) {
-                               if( !isset($revObjs[$timestamp]) ) {
-                                       continue;
-                               } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
-                               // If a rev is hidden from sysops
-                                       if( !$this->wasPosted ) {
-                                               return $wgOut->permissionRequired( 'suppressrevision' );
-                                       }
-                                       $UserAllowed = false;
-                               }
-                               $revisions++;
-                               $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
-                               $bitfields |= $revObjs[$timestamp]->mDeleted;
-                       }
+                       return;
                }
-               if( !$revisions ) {
-                       return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
-               }
-               
-               $wgOut->addHTML( "</ul>" );
-               // Explanation text
-               $this->addUsageText();
-
-               // Normal sysops can always see what they did, but can't always change it
-               if( !$UserAllowed ) return;
+               $wgOut->disable();
+               # We mustn't allow the output to be Squid cached, otherwise
+               # if an admin previews a deleted image, and it's cached, then
+               # a user without appropriate permissions can toddle off and
+               # nab the image, and Squid will serve it
+               $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
+               $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
+               $wgRequest->response()->header( 'Pragma: no-cache' );
 
-               $items = array(
-                       Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
-                       Xml::submitButton( wfMsg( 'revdelete-submit' ) )
-               );
-               $hidden = array(
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
-                       Xml::hidden( 'target', $this->page->getPrefixedText() ),
-                       Xml::hidden( 'type', $this->deleteKey )
-               );
-               if( $this->deleteKey == 'oldid' ) {
-                       $hidden[] = Xml::hidden( 'oldid', implode(',',$this->oldids) );
-               } else {
-                       $hidden[] = Xml::hidden( 'artimestamp', implode(',',$this->artimestamps) );
-               }
-               $wgOut->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 
-                               'id' => 'mw-revdel-form-revisions' ) ) .
-                       Xml::openElement( 'fieldset' ) .
-                       xml::element( 'legend', null,  wfMsg( 'revdelete-legend' ) )
-               );
+               # Stream the file to the client
+               global $IP;
+               require_once( "$IP/includes/StreamFile.php" );
+               $key = $oimage->getStorageKey();
+               $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
+               wfStreamFile( $path );
+       }
 
-               $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
-               foreach( $items as $item ) {
-                       $wgOut->addHTML( Xml::tags( 'p', null, $item ) );
-               }
-               foreach( $hidden as $item ) {
-                       $wgOut->addHTML( $item );
+       /**
+        * Get the list object for this request
+        */
+       protected function getList() {
+               if ( is_null( $this->list ) ) {
+                       $class = $this->typeInfo['list-class'];
+                       $this->list = new $class( $this, $this->targetObj, $this->ids );
                }
-               $wgOut->addHTML(
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) . "\n"
-               );
+               return $this->list;
        }
 
        /**
-        * This lets a user set restrictions for archived images
+        * Show a list of items that we will operate on, and show a form with checkboxes 
+        * which will allow the user to choose new visibility settings.
         */
-       private function showImages() {
+       protected function showForm() {
                global $wgOut, $wgUser, $wgLang;
                $UserAllowed = true;
 
-               $count = ($this->deleteKey == 'oldimage') ? count($this->ofiles) : count($this->afiles);
-               $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(),
-                       $wgLang->formatNum($count) );
+               if ( $this->typeName == 'logging' ) {
+                       $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids) ) );
+               } else {
+                       $wgOut->addWikiMsg( 'revdelete-selected',
+                               $this->targetObj->getPrefixedText(), count( $this->ids ) );
+               }
 
-               $bitfields = 0;
                $wgOut->addHTML( "<ul>" );
 
-               $where = $filesObjs = array();
-               $dbr = wfGetDB( DB_MASTER );
-               // Live old revisions...
-               $revisions = 0;
-               if( $this->deleteKey == 'oldimage' ) {
-                       // Run through and pull all our data in one query
-                       foreach( $this->ofiles as $timestamp ) {
-                               $where[] = $timestamp.'!'.$this->page->getDBKey();
-                       }
-                       $result = $dbr->select( 'oldimage', '*',
-                               array(
-                                       'oi_name'         => $this->page->getDBKey(),
-                                       'oi_archive_name' => $where
-                               ),
-                               __METHOD__
-                       );
-                       while( $row = $dbr->fetchObject( $result ) ) {
-                               $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
-                               $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
-                               $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
-                       }
-                       // Check through our images
-                       foreach( $this->ofiles as $timestamp ) {
-                               $archivename = $timestamp.'!'.$this->page->getDBKey();
-                               if( !isset($filesObjs[$archivename]) ) {
-                                       continue;
-                               } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
-                                       // If a rev is hidden from sysops
-                                       if( !$this->wasPosted ) {
-                                               return $wgOut->permissionRequired( 'suppressrevision' );
-                                       }
-                                       $UserAllowed = false;
-                               }
-                               $revisions++;
-                               // Inject history info
-                               $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
-                               $bitfields |= $filesObjs[$archivename]->deleted;
-                       }
-               // Archived files...
-               } else {
-                       // Run through and pull all our data in one query
-                       foreach( $this->afiles as $id ) {
-                               $where[] = intval($id);
-                       }
-                       $result = $dbr->select( 'filearchive', '*',
-                               array(
-                                       'fa_name' => $this->page->getDBKey(),
-                                       'fa_id'   => $where
-                               ),
-                               __METHOD__
-                       );
-                       while( $row = $dbr->fetchObject( $result ) ) {
-                               $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
-                       }
-
-                       foreach( $this->afiles as $fileid ) {
-                               if( !isset($filesObjs[$fileid]) ) {
-                                       continue;
-                               } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
-                                       // If a rev is hidden from sysops
-                                       if( !$this->wasPosted ) {
-                                               return $wgOut->permissionRequired( 'suppressrevision' );
-                                       }
-                                       $UserAllowed = false;
+               $numRevisions = 0;
+               // Live revisions...
+               $list = $this->getList();
+               for ( $list->reset(); $list->current(); $list->next() ) {
+                       $item = $list->current();
+                       if ( !$item->canView() ) {
+                               if( !$this->submitClicked ) {
+                                       $wgOut->permissionRequired( 'suppressrevision' );
+                                       return;
                                }
-                               $revisions++;
-                               // Inject history info
-                               $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
-                               $bitfields |= $filesObjs[$fileid]->deleted;
+                               $UserAllowed = false;
                        }
+                       $numRevisions++;
+                       $wgOut->addHTML( $item->getHTML() );
                }
-               if( !$revisions ) {
-                       return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
+
+               if( !$numRevisions ) {
+                       $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
+                       return;
                }
                
                $wgOut->addHTML( "</ul>" );
                // Explanation text
                $this->addUsageText();
+
                // Normal sysops can always see what they did, but can't always change it
                if( !$UserAllowed ) return;
 
-               $items = array(
-                       Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
-                       Xml::submitButton( wfMsg( 'revdelete-submit' ) )
-               );
-               $hidden = array(
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
-                       Xml::hidden( 'target', $this->page->getPrefixedText() ),
-                       Xml::hidden( 'type', $this->deleteKey )
-               );
-               if( $this->deleteKey == 'oldimage' ) {
-                       $hidden[] = Xml::hidden( 'oldimage', implode(',',$this->oldimgs) );
+               // Show form if the user can submit
+               if( $this->mIsAllowed ) {
+                       $out = Xml::openElement( 'form', array( 'method' => 'post',
+                                       'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), 
+                                       'id' => 'mw-revdel-form-revisions' ) ) .
+                               Xml::fieldset( wfMsg( 'revdelete-legend' ) ) .
+                               $this->buildCheckBoxes() .
+                               Xml::openElement( 'table' ) .
+                               "<tr>\n" .
+                                       '<td class="mw-label">' .
+                                               Xml::label( wfMsg( 'revdelete-log' ), 'wpRevDeleteReasonList' ) .
+                                       '</td>' .
+                                       '<td class="mw-input">' .
+                                               Xml::listDropDown( 'wpRevDeleteReasonList',
+                                                       wfMsgForContent( 'revdelete-reason-dropdown' ),
+                                                       wfMsgForContent( 'revdelete-reasonotherlist' ), '', 'wpReasonDropDown', 1
+                                               ) .
+                                       '</td>' .
+                               "</tr><tr>\n" .
+                                       '<td class="mw-label">' .
+                                               Xml::label( wfMsg( 'revdelete-otherreason' ), 'wpReason' ) .
+                                       '</td>' .
+                                       '<td class="mw-input">' .
+                                               Xml::input( 'wpReason', 60, $this->otherReason, array( 'id' => 'wpReason' ) ) .
+                                       '</td>' .
+                               "</tr><tr>\n" .
+                                       '<td></td>' .
+                                       '<td class="mw-submit">' .
+                                               Xml::submitButton( wfMsgExt('revdelete-submit','parsemag',$numRevisions),
+                                                       array( 'name' => 'wpSubmit' ) ) .
+                                       '</td>' .
+                               "</tr>\n" .
+                               Xml::closeElement( 'table' ) .
+                               Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                               Html::hidden( 'target', $this->targetObj->getPrefixedText() ) .
+                               Html::hidden( 'type', $this->typeName ) .
+                               Html::hidden( 'ids', implode( ',', $this->ids ) ) .
+                               Xml::closeElement( 'fieldset' ) . "\n";
                } else {
-                       $hidden[] = Xml::hidden( 'fileid', implode(',',$this->fileids) );
-               }
-               $wgOut->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 
-                               'id' => 'mw-revdel-form-filerevisions' )
-                       ) .
-                       Xml::fieldset( wfMsg( 'revdelete-legend' ) )
-               );
-
-               $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
-               foreach( $items as $item ) {
-                       $wgOut->addHTML( "<p>$item</p>" );
-               }
-               foreach( $hidden as $item ) {
-                       $wgOut->addHTML( $item );
+                       $out = '';
+               }
+               if( $this->mIsAllowed ) {
+                       $out .= Xml::closeElement( 'form' ) . "\n";
+                       // Show link to edit the dropdown reasons
+                       if( $wgUser->isAllowed( 'editinterface' ) ) {
+                               $title = Title::makeTitle( NS_MEDIAWIKI, 'revdelete-reason-dropdown' );
+                               $link = $wgUser->getSkin()->link(
+                                       $title,
+                                       wfMsgHtml( 'revdelete-edit-reasonlist' ),
+                                       array(),
+                                       array( 'action' => 'edit' )
+                               );
+                               $out .= Xml::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n";
+                       }
                }
-
-               $wgOut->addHTML(
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) . "\n"
-               );
+               $wgOut->addHTML( $out );
        }
 
        /**
-        * This lets a user set restrictions for log items
+        * Show some introductory text
+        * FIXME Wikimedia-specific policy text
         */
-       private function showLogItems() {
-               global $wgOut, $wgUser, $wgMessageCache, $wgLang;
-               $UserAllowed = true;
-
-               $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events) ) );
-
-               $bitfields = 0;
-               $wgOut->addHTML( "<ul>" );
-
-               $where = $logRows = array();
-               $dbr = wfGetDB( DB_MASTER );
-               // Run through and pull all our data in one query
-               $logItems = 0;
-               foreach( $this->events as $logid ) {
-                       $where[] = intval($logid);
-               }
-               list($log,$logtype) = explode( '/',$this->page->getDBKey(), 2 );
-               $result = $dbr->select( 'logging', '*',
-                       array( 'log_type' => $logtype, 'log_id' => $where ),
-                       __METHOD__
-               );
-               while( $row = $dbr->fetchObject( $result ) ) {
-                       $logRows[$row->log_id] = $row;
-               }
-               $wgMessageCache->loadAllMessages();
-               foreach( $this->events as $logid ) {
-                       // Don't hide from oversight log!!!
-                       if( !isset( $logRows[$logid] ) || $logRows[$logid]->log_type=='suppress' ) {
-                               continue;
-                       } else if( !LogEventsList::userCan( $logRows[$logid],Revision::DELETED_RESTRICTED) ) {
-                       // If an event is hidden from sysops
-                               if( !$this->wasPosted ) {
-                                       return $wgOut->permissionRequired( 'suppressrevision' );
-                               }
-                               $UserAllowed = false;
-                       }
-                       $logItems++;
-                       $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
-                       $bitfields |= $logRows[$logid]->log_deleted;
-               }
-               if( !$logItems ) {
-                       return $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
-               }
-               
-               $wgOut->addHTML( "</ul>" );
-               // Explanation text
-               $this->addUsageText();
-               // Normal sysops can always see what they did, but can't always change it
-               if( !$UserAllowed ) return;
-
-               $items = array(
-                       Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
-                       Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
-               $hidden = array(
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
-                       Xml::hidden( 'target', $this->page->getPrefixedDBKey() ),
-                       Xml::hidden( 'page', $this->contextPage ? $this->contextPage->getPrefixedDBKey() : '' ),
-                       Xml::hidden( 'type', $this->deleteKey ),
-                       Xml::hidden( 'logid', implode(',',$this->logids) )
-               );
-
-               $wgOut->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
-                       Xml::fieldset( wfMsg( 'revdelete-legend' ) )
-               );
-               
-               $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
-               foreach( $items as $item ) {
-                       $wgOut->addHTML( "<p>$item</p>" );
-               }
-               foreach( $hidden as $item ) {
-                       $wgOut->addHTML( $item );
-               }
-
-               $wgOut->addHTML(
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) . "\n"
-               );
-       }
-       
-       private function addUsageText() {
+       protected function addUsageText() {
                global $wgOut, $wgUser;
                $wgOut->addWikiMsg( 'revdelete-text' );
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
                        $wgOut->addWikiMsg( 'revdelete-suppress-text' );
                }
+               if( $this->mIsAllowed ) {
+                       $wgOut->addWikiMsg( 'revdelete-confirm' );
+               }
        }
        
        /**
-       * @param int $bitfields, aggregate bitfield of all the bitfields
-       * @returns string HTML
+       * @return String: HTML
        */
-       private function buildCheckBoxes( $bitfields ) {
-               $html = '';
-               // FIXME: all items checked for just one rev are checked, even if not set for the others
-               foreach( $this->checks as $item ) {
-                       list( $message, $name, $field ) = $item;
-                       $line = Xml::tags( 'div', null, Xml::checkLabel( wfMsg($message), $name, $name,
-                               $bitfields & $field ) );
-                       if( $field == Revision::DELETED_RESTRICTED ) $line = "<b>$line</b>";
-                       $html .= $line;
-               }
-               return $html;
-       }
-
-       /**
-        * @param Revision $rev
-        * @returns string
-        */
-       private function historyLine( $rev ) {
-               global $wgLang, $wgUser;
-
-               $date = $wgLang->timeanddate( $rev->getTimestamp() );
-               $difflink = $del = '';
-               // Live revisions
-               if( $this->deleteKey == 'oldid' ) {
-                       $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
-                       $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid='.$rev->getId() . $tokenParams );
-                       $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'),
-                               'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
-               // Archived revisions
-               } else {
-                       $undelete = SpecialPage::getTitleFor( 'Undelete' );
-                       $target = $this->page->getPrefixedText();
-                       $revlink = $this->skin->makeLinkObj( $undelete, $date,
-                               "target=$target&timestamp=" . $rev->getTimestamp() );
-                       $difflink = '(' . $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
-                               "target=$target&diff=prev&timestamp=" . $rev->getTimestamp() ) . ')';
-               }
-               // Check permissions; items may be "suppressed"
-               if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
-                       $revlink = '<span class="history-deleted">'.$revlink.'</span>';
-                       $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
-                       if( !$rev->userCan(Revision::DELETED_TEXT) ) {
-                               $revlink = '<span class="history-deleted">'.$date.'</span>';
-                               $difflink = '(' . wfMsgHtml('diff') . ')';
+       protected function buildCheckBoxes() {
+               global $wgRequest;
+
+               $html = '<table>';
+               // If there is just one item, use checkboxes
+               $list = $this->getList();
+               if( $list->length() == 1 ) {
+                       $list->reset();
+                       $bitfield = $list->current()->getBits(); // existing field
+                       if( $this->submitClicked ) {
+                               $bitfield = $this->extractBitfield( $this->extractBitParams($wgRequest), $bitfield );
                        }
-               }
-               $userlink = $this->skin->revUserLink( $rev );
-               $comment = $this->skin->revComment( $rev );
-
-               return "<li>$difflink $revlink $userlink $comment{$del}</li>";
-       }
-
-       /**
-        * @param File $file
-        * @returns string
-        */
-       private function fileLine( $file ) {
-               global $wgLang;
-
-               $target = $this->page->getPrefixedText();
-               $date = $wgLang->timeanddate( $file->getTimestamp(), true  );
-
-               $del = '';
-               # Hidden files...
-               if( $file->isDeleted(File::DELETED_FILE) ) {
-                       $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
-                       if( !$file->userCan(File::DELETED_FILE) ) {
-                               $pageLink = $date;
-                       } else {
-                               $pageLink = $this->skin->makeKnownLinkObj( $this->getTitle(), $date,
-                                       "target=$target&file=$file->sha1.".$file->getExtension() );
+                       foreach( $this->checks as $item ) {
+                               list( $message, $name, $field ) = $item;
+                               $innerHTML = Xml::checkLabel( wfMsg($message), $name, $name, $bitfield & $field );
+                               if( $field == Revision::DELETED_RESTRICTED )
+                                       $innerHTML = "<b>$innerHTML</b>";
+                               $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML );
+                               $html .= "<tr>$line</tr>\n";
                        }
-                       $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
-               # Regular files...
+               // Otherwise, use tri-state radios
                } else {
-                       $url = $file->getUrlRel();
-                       $pageLink = "<a href=\"{$url}\">{$date}</a>";
-               }
-
-               $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
-                       $wgLang->formatNum( $file->getHeight() ) ) .
-                       ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
-               $data = htmlspecialchars( $data );
-
-               return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
-                       $this->fileComment( $file )."$del</li>";
-       }
-
-       /**
-        * @param ArchivedFile $file
-        * @returns string
-        */
-       private function archivedfileLine( $file ) {
-               global $wgLang;
-
-               $target = $this->page->getPrefixedText();
-               $date = $wgLang->timeanddate( $file->getTimestamp(), true  );
-
-               $undelete = SpecialPage::getTitleFor( 'Undelete' );
-               $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date,
-                       "target=$target&file={$file->getKey()}" );
-
-               $del = '';
-               if( $file->isDeleted(File::DELETED_FILE) ) {
-                       $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
-               }
-
-               $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
-                       $wgLang->formatNum( $file->getHeight() ) ) .
-                       ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
-               $data = htmlspecialchars( $data );
-
-               return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
-                       $this->fileComment( $file )."$del</li>";
-       }
-
-       /**
-        * @param Array $row row
-        * @returns string
-        */
-       private function logLine( $row ) {
-               global $wgLang;
-
-               $date = $wgLang->timeanddate( $row->log_timestamp );
-               $paramArray = LogPage::extractParams( $row->log_params );
-               $title = Title::makeTitle( $row->log_namespace, $row->log_title );
-
-               $logtitle = SpecialPage::getTitleFor( 'Log' );
-               $loglink = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
-                       wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
-               // Action text
-               if( !LogEventsList::userCan($row,LogPage::DELETED_ACTION) ) {
-                       $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
-               } else {
-                       $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
-                               $this->skin, $paramArray, true, true );
-                       if( $row->log_deleted & LogPage::DELETED_ACTION )
-                               $action = '<span class="history-deleted">' . $action . '</span>';
-               }
-               // User links
-               $userLink = $this->skin->userLink( $row->log_user, User::WhoIs($row->log_user) );
-               if( LogEventsList::isDeleted($row,LogPage::DELETED_USER) ) {
-                       $userLink = '<span class="history-deleted">' . $userLink . '</span>';
-               }
-               // Comment
-               $comment = $wgLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
-               if( LogEventsList::isDeleted($row,LogPage::DELETED_COMMENT) ) {
-                       $comment = '<span class="history-deleted">' . $comment . '</span>';
-               }
-               return "<li>($loglink) $date $userLink $action $comment</li>";
-       }
-
-       /**
-        * Generate a user tool link cluster if the current user is allowed to view it
-        * @param ArchivedFile $file
-        * @return string HTML
-        */
-       private function fileUserTools( $file ) {
-               if( $file->userCan( Revision::DELETED_USER ) ) {
-                       $link = $this->skin->userLink( $file->user, $file->user_text ) .
-                               $this->skin->userToolLinks( $file->user, $file->user_text );
-               } else {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               }
-               if( $file->isDeleted( Revision::DELETED_USER ) ) {
-                       return '<span class="history-deleted">' . $link . '</span>';
-               }
-               return $link;
-       }
-
-       /**
-        * Wrap and format the given file's comment block, if the current
-        * user is allowed to view it.
-        *
-        * @param ArchivedFile $file
-        * @return string HTML
-        */
-       private function fileComment( $file ) {
-               if( $file->userCan( File::DELETED_COMMENT ) ) {
-                       $block = $this->skin->commentBlock( $file->description );
-               } else {
-                       $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
-               }
-               if( $file->isDeleted( File::DELETED_COMMENT ) ) {
-                       return "<span class=\"history-deleted\">$block</span>";
+                       $html .= '<tr>';
+                       $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-same').'</th>';
+                       $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-unset').'</th>';
+                       $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-set').'</th>';
+                       $html .= "<th></th></tr>\n";
+                       foreach( $this->checks as $item ) {
+                               list( $message, $name, $field ) = $item;
+                               // If there are several items, use third state by default...
+                               if( $this->submitClicked ) {
+                                       $selected = $wgRequest->getInt( $name, 0 /* unchecked */ );
+                               } else {
+                                       $selected = -1; // use existing field
+                               }
+                               $line = '<td class="mw-revdel-checkbox">' . Xml::radio( $name, -1, $selected == -1 ) . '</td>';
+                               $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>';
+                               $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>';
+                               $label = wfMsgHtml($message);
+                               if( $field == Revision::DELETED_RESTRICTED ) {
+                                       $label = "<b>$label</b>";
+                               }
+                               $line .= "<td>$label</td>";
+                               $html .= "<tr>$line</tr>\n";
+                       }
                }
-               return $block;
+               
+               $html .= '</table>';
+               return $html;
        }
 
        /**
-        * @param WebRequest $request
+        * UI entry point for form submission.
+        * @param $request WebRequest
         */
-       private function submit( $request ) {
+       protected function submit( $request ) {
                global $wgUser, $wgOut;
                # Check edit token on submission
-               if( $this->wasPosted && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
+               if( $this->submitClicked && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
                        $wgOut->addWikiMsg( 'sessionfailure' );
                        return false;
                }
-               $bitfield = $this->extractBitfield( $request );
-               $comment = $request->getText( 'wpReason' );
+               $bitParams = $this->extractBitParams( $request );
+               $listReason = $request->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown
+               $comment = $listReason;
+               if( $comment != 'other' && $this->otherReason != '' ) {
+                       // Entry from drop down menu + additional comment
+                       $comment .= wfMsgForContent( 'colon-separator' ) . $this->otherReason;
+               } elseif( $comment == 'other' ) {
+                       $comment = $this->otherReason;
+               }
                # Can the user set this field?
-               if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
+               if( $bitParams[Revision::DELETED_RESTRICTED]==1 && !$wgUser->isAllowed('suppressrevision') ) {
                        $wgOut->permissionRequired( 'suppressrevision' );
                        return false;
                }
                # If the save went through, go to success message...
-               if( $this->save( $bitfield, $comment, $this->page ) ) {
+               $status = $this->save( $bitParams, $comment, $this->targetObj );
+               if ( $status->isGood() ) {
                        $this->success();
                        return true;
                # ...otherwise, bounce back to form...
                } else {
-                       $this->failure();
+                       $this->failure( $status );
                }
                return false;
        }
 
-       private function success() {
-               global $wgOut;
-               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-               $wrap = '<span class="success">$1</span>';
-               if( $this->deleteKey == 'logid' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
-                       $this->showLogItems();
-               } else if( $this->deleteKey == 'oldid' || $this->deleteKey == 'artimestamp' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
-                       $this->showRevs();
-               } else if( $this->deleteKey == 'fileid' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
-                       $this->showImages();
-               } else if( $this->deleteKey == 'oldimage' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
-                       $this->showImages();
-               }
-       }
-       
-       private function failure() {
-               global $wgOut;
-               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-               $wrap = '<span class="error">$1</span>';
-               if( $this->deleteKey == 'logid' ) {
-                       $this->showLogItems();
-               } else if( $this->deleteKey == 'oldid' || $this->deleteKey == 'artimestamp' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
-                       $this->showRevs();
-               } else if( $this->deleteKey == 'fileid' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
-                       $this->showImages();
-               } else if( $this->deleteKey == 'oldimage' ) {
-                       $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
-                       $this->showImages();
-               }
-       }
-
        /**
-        * Put together a rev_deleted bitfield from the submitted checkboxes
-        * @param WebRequest $request
-        * @return int
-        */
-       private function extractBitfield( $request ) {
-               $bitfield = 0;
-               foreach( $this->checks as $item ) {
-                       list( /* message */ , $name, $field ) = $item;
-                       if( $request->getCheck( $name ) ) {
-                               $bitfield |= $field;
-                       }
-               }
-               return $bitfield;
-       }
-
-       private function save( $bitfield, $reason, $title ) {
-               $dbw = wfGetDB( DB_MASTER );
-               // Don't allow simply locking the interface for no reason
-               if( $bitfield == Revision::DELETED_RESTRICTED ) {
-                       $bitfield = 0;
-               }
-               $deleter = new RevisionDeleter( $dbw );
-               // By this point, only one of the below should be set
-               if( isset($this->revisions) ) {
-                       return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
-               } else if( isset($this->archrevs) ) {
-                       return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
-               } else if( isset($this->ofiles) ) {
-                       return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
-               } else if( isset($this->afiles) ) {
-                       return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
-               } else if( isset($this->events) ) {
-                       return $deleter->setEventVisibility( $title, $this->events, $bitfield, $reason );
-               }
-               return false;
-       }
-}
-
-/**
- * Implements the actions for Revision Deletion.
- * @ingroup SpecialPage
- */
-class RevisionDeleter {
-       function __construct( $db ) {
-               $this->dbw = $db;
-       }
-
-       /**
-        * @param $title, the page these events apply to
-        * @param array $items list of revision ID numbers
-        * @param int $bitfield new rev_deleted value
-        * @param string $comment Comment for log records
-        */
-       function setRevVisibility( $title, $items, $bitfield, $comment ) {
-               global $wgOut;
-
-               $userAllowedAll = $success = true;
-               $revIDs = array();
-               $revCount = 0;
-               // Run through and pull all our data in one query
-               foreach( $items as $revid ) {
-                       $where[] = intval($revid);
-               }
-               $result = $this->dbw->select( array('revision','page'), '*',
-                       array( 'rev_page' => $title->getArticleID(),
-                               'rev_id' => $where, 'rev_page = page_id' ),
-                       __METHOD__
-               );
-               while( $row = $this->dbw->fetchObject( $result ) ) {
-                       $revObjs[$row->rev_id] = new Revision( $row );
-               }
-               // To work!
-               foreach( $items as $revid ) {
-                       if( !isset($revObjs[$revid]) ) {
-                               $success = false;
-                               continue; // Must exist
-                       } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision::DELETED_TEXT) ) {
-                               $success = false;
-                               continue; // Cannot hide current version text
-                       } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
-                       $userAllowedAll = false;
-                               continue;
-                       }
-                       // For logging, maintain a count of revisions
-                       if( $revObjs[$revid]->mDeleted != $bitfield ) {
-                               $revIDs[] = $revid;
-                               $this->updateRevision( $revObjs[$revid], $bitfield );
-                               $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
-                               $revCount++;
-                       }
-               }
-               // Clear caches...
-               // Don't log or touch if nothing changed
-               if( $revCount > 0 ) {
-                       $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
-                               $comment, $title, 'oldid', $revIDs );
-                       $this->updatePage( $title );
-               }
-               // Where all revs allowed to be set?
-               if( !$userAllowedAll ) {
-                       //FIXME: still might be confusing???
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-
-               return $success;
-       }
-
-        /**
-        * @param $title, the page these events apply to
-        * @param array $items list of revision ID numbers
-        * @param int $bitfield new rev_deleted value
-        * @param string $comment Comment for log records
-        */
-       function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
-               global $wgOut;
-
-               $userAllowedAll = $success = true;
-               $count = 0;
-               $Id_set = array();
-               // Run through and pull all our data in one query
-               foreach( $items as $timestamp ) {
-                       $where[] = $this->dbw->timestamp( $timestamp );
-               }
-               $result = $this->dbw->select( 'archive', '*',
-                       array(
-                               'ar_namespace' => $title->getNamespace(),
-                               'ar_title' => $title->getDBKey(),
-                               'ar_timestamp' => $where
-                       ), __METHOD__
-               );
-               while( $row = $this->dbw->fetchObject( $result ) ) {
-                       $timestamp = wfTimestamp( TS_MW, $row->ar_timestamp );
-                       $revObjs[$timestamp] = new Revision( array(
-                               'page'       => $title->getArticleId(),
-                               'id'         => $row->ar_rev_id,
-                               'text'       => $row->ar_text_id,
-                               'comment'    => $row->ar_comment,
-                               'user'       => $row->ar_user,
-                               'user_text'  => $row->ar_user_text,
-                               'timestamp'  => $timestamp,
-                               'minor_edit' => $row->ar_minor_edit,
-                               'text_id'    => $row->ar_text_id,
-                               'deleted'    => $row->ar_deleted,
-                               'len'        => $row->ar_len) );
-               }
-               // To work!
-               foreach( $items as $timestamp ) {
-                       // This will only select the first revision with this timestamp.
-                       // Since they are all selected/deleted at once, we can just check the
-                       // permissions of one. UPDATE is done via timestamp, so all revs are set.
-                       if( !is_object($revObjs[$timestamp]) ) {
-                               $success = false;
-                               continue; // Must exist
-                       } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
-                       $userAllowedAll=false;
-                               continue;
-                       }
-                       // Which revisions did we change anything about?
-                       if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
-                               $Id_set[] = $timestamp;
-                               $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
-                           $count++;
-                       }
-               }
-               // For logging, maintain a count of revisions
-               if( $count > 0 ) {
-                       $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
-                               $comment, $title, 'artimestamp', $Id_set );
-               }
-               // Where all revs allowed to be set?
-               if( !$userAllowedAll ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-
-               return $success;
-       }
-
-        /**
-        * @param $title, the page these events apply to
-        * @param array $items list of revision ID numbers
-        * @param int $bitfield new rev_deleted value
-        * @param string $comment Comment for log records
+        * Report that the submit operation succeeded
         */
-       function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
+       protected function success() {
                global $wgOut;
-
-               $userAllowedAll = $success = true;
-               $count = 0;
-               $set = array();
-               // Run through and pull all our data in one query
-               foreach( $items as $timestamp ) {
-                       $where[] = $timestamp.'!'.$title->getDBKey();
-               }
-               $result = $this->dbw->select( 'oldimage', '*',
-                       array( 'oi_name' => $title->getDBKey(), 'oi_archive_name' => $where ),
-                       __METHOD__
-               );
-               while( $row = $this->dbw->fetchObject( $result ) ) {
-                       $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
-                       $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
-                       $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
-               }
-               // To work!
-               foreach( $items as $timestamp ) {
-                       $archivename = $timestamp.'!'.$title->getDBKey();
-                       if( !isset($filesObjs[$archivename]) ) {
-                               $success = false;
-                               continue; // Must exist
-                       } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
-                       $userAllowedAll=false;
-                               continue;
-                       }
-
-                       $transaction = true;
-                       // Which revisions did we change anything about?
-                       if( $filesObjs[$archivename]->deleted != $bitfield ) {
-                               $count++;
-
-                               $this->dbw->begin();
-                               $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
-                               // If this image is currently hidden...
-                               if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
-                                       if( $bitfield & File::DELETED_FILE ) {
-                                               # Leave it alone if we are not changing this...
-                                               $set[]=$timestamp;
-                                               $transaction = true;
-                                       } else {
-                                               # We are moving this out
-                                               $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
-                                               $set[]=$transaction;
-                                       }
-                               // Is it just now becoming hidden?
-                               } else if( $bitfield & File::DELETED_FILE ) {
-                                       $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
-                                       $set[]=$transaction;
-                               } else {
-                                       $set[]=$timestamp;
-                               }
-                               // If our file operations fail, then revert back the db
-                               if( $transaction==false ) {
-                                       $this->dbw->rollback();
-                                       return false;
-                               }
-                               $this->dbw->commit();
-                       }
-               }
-
-               // Log if something was changed
-               if( $count > 0 ) {
-                       $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
-                               $comment, $title, 'oldimage', $set );
-                       # Purge page/history
-                       $file = wfLocalFile( $title );
-                       $file->purgeCache();
-                       $file->purgeHistory();
-                       # Invalidate cache for all pages using this file
-                       $update = new HTMLCacheUpdate( $title, 'imagelinks' );
-                       $update->doUpdate();
-               }
-               // Where all revs allowed to be set?
-               if( !$userAllowedAll ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-
-               return $success;
-       }
-
-        /**
-        * @param $title, the page these events apply to
-        * @param array $items list of revision ID numbers
-        * @param int $bitfield new rev_deleted value
-        * @param string $comment Comment for log records
-        */
-       function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
-               global $wgOut;
-
-               $userAllowedAll = $success = true;
-               $count = 0;
-               $Id_set = array();
-
-               // Run through and pull all our data in one query
-               foreach( $items as $id ) {
-                       $where[] = intval($id);
-               }
-               $result = $this->dbw->select( 'filearchive', '*',
-                       array( 'fa_name' => $title->getDBKey(),
-                               'fa_id' => $where ),
-                       __METHOD__ );
-               while( $row = $this->dbw->fetchObject( $result ) ) {
-                       $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
-               }
-               // To work!
-               foreach( $items as $fileid ) {
-                       if( !isset($filesObjs[$fileid]) ) {
-                               $success = false;
-                               continue; // Must exist
-                       } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
-                       $userAllowedAll=false;
-                               continue;
-                       }
-                       // Which revisions did we change anything about?
-                       if( $filesObjs[$fileid]->deleted != $bitfield ) {
-                          $Id_set[]=$fileid;
-                          $count++;
-
-                          $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
-                       }
-               }
-               // Log if something was changed
-               if( $count > 0 ) {
-                       $this->updateLog( $title, $count, $bitfield, $comment,
-                               $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
-               }
-               // Where all revs allowed to be set?
-               if( !$userAllowedAll ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-
-               return $success;
+               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
+               $wgOut->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeInfo['success'] );
+               $this->list->reloadFromMaster();
+               $this->showForm();
        }
 
        /**
-        * @param $title, the log page these events apply to
-        * @param array $items list of log ID numbers
-        * @param int $bitfield new log_deleted value
-        * @param string $comment Comment for log records
+        * Report that the submit operation failed
         */
-       function setEventVisibility( $title, $items, $bitfield, $comment ) {
+       protected function failure( $status ) {
                global $wgOut;
-
-               $userAllowedAll = $success = true;
-               $count = 0;
-               $log_Ids = array();
-
-               // Run through and pull all our data in one query
-               foreach( $items as $logid ) {
-                       $where[] = intval($logid);
-               }
-               list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
-               $result = $this->dbw->select( 'logging', '*',
-                       array( 'log_type' => $logtype, 'log_id' => $where ),
-                       __METHOD__
-               );
-               while( $row = $this->dbw->fetchObject( $result ) ) {
-                       $logRows[$row->log_id] = $row;
-               }
-               // To work!
-               foreach( $items as $logid ) {
-                       if( !isset($logRows[$logid]) ) {
-                               $success = false;
-                               continue; // Must exist
-                       } else if( !LogEventsList::userCan($logRows[$logid], LogPage::DELETED_RESTRICTED)
-                               || $logRows[$logid]->log_type == 'suppress' )
-                       {
-                       $userAllowedAll=false; // Don't hide from oversight log!!!
-                       continue;
-                       }
-                       // Which logs did we change anything about?
-                       if( $logRows[$logid]->log_deleted != $bitfield ) {
-                               $log_Ids[] = $logid;
-                               $this->updateLogs( $logRows[$logid], $bitfield );
-                               $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
-                               $count++;
-                       }
-               }
-               // Don't log or touch if nothing changed
-               if( $count > 0 ) {
-                       $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted,
-                               $comment, $title, 'logid', $log_Ids );
-               }
-               // Were all revs allowed to be set?
-               if( !$userAllowedAll ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-
-               return $success;
+               $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
+               $wgOut->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) );
+               $this->showForm();
        }
 
        /**
-        * Moves an image to a safe private location
-        * Caller is responsible for clearing caches
-        * @param File $oimage
-        * @returns mixed, timestamp string on success, false on failure
+        * Put together an array that contains -1, 0, or the *_deleted const for each bit
+        * @param $request WebRequest
+        * @return array
         */
-       function makeOldImagePrivate( $oimage ) {
-               $transaction = new FSTransaction();
-               if( !FileStore::lock() ) {
-                       wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
-                       return false;
-               }
-               $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
-               // Dupe the file into the file store
-               if( file_exists( $oldpath ) ) {
-                       // Is our directory configured?
-                       if( $store = FileStore::get( 'deleted' ) ) {
-                               if( !$oimage->sha1 ) {
-                                       $oimage->upgradeRow(); // sha1 may be missing
-                               }
-                               $key = $oimage->sha1 . '.' . $oimage->getExtension();
-                               $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
-                       } else {
-                               $group = null;
-                               $key = null;
-                               $transaction = false; // Return an error and do nothing
+       protected function extractBitParams( $request ) {
+               $bitfield = array();
+               foreach( $this->checks as $item ) {
+                       list( /* message */ , $name, $field ) = $item;
+                       $val = $request->getInt( $name, 0 /* unchecked */ );
+                       if( $val < -1 || $val > 1) {
+                               $val = -1; // -1 for existing value
                        }
-               } else {
-                       wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
-                       $group = null;
-                       $key = '';
-                       $transaction = new FSTransaction(); // empty
+                       $bitfield[$field] = $val;
                }
-
-               if( $transaction === false ) {
-                       // Fail to restore?
-                       wfDebug( __METHOD__.": import to file store failed, aborting\n" );
-                       throw new MWException( "Could not archive and delete file $oldpath" );
-                       return false;
+               if( !isset($bitfield[Revision::DELETED_RESTRICTED]) ) {
+                       $bitfield[Revision::DELETED_RESTRICTED] = 0;
                }
-
-               wfDebug( __METHOD__.": set db items, applying file transactions\n" );
-               $transaction->commit();
-               FileStore::unlock();
-
-               $m = explode('!',$oimage->archive_name,2);
-               $timestamp = $m[0];
-
-               return $timestamp;
+               return $bitfield;
        }
-
+       
        /**
-        * Moves an image from a safe private location
-        * Caller is responsible for clearing caches
-        * @param File $oimage
-        * @returns mixed, string timestamp on success, false on failure
+        * Put together a rev_deleted bitfield
+        * @param $bitPars array extractBitParams() params
+        * @param $oldfield int current bitfield
+        * @return array
         */
-       function makeOldImagePublic( $oimage ) {
-               $transaction = new FSTransaction();
-               if( !FileStore::lock() ) {
-                       wfDebug( __METHOD__." could not acquire filestore lock\n" );
-                       return false;
-               }
-
-               $store = FileStore::get( 'deleted' );
-               if( !$store ) {
-                       wfDebug( __METHOD__.": skipping row with no file.\n" );
-                       return false;
-               }
-
-               $key = $oimage->sha1.'.'.$oimage->getExtension();
-               $destDir = $oimage->getArchivePath();
-               if( !is_dir( $destDir ) ) {
-                       wfMkdirParents( $destDir );
-               }
-               $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
-               // Check if any other stored revisions use this file;
-               // if so, we shouldn't remove the file from the hidden
-               // archives so they will still work. Check hidden files first.
-               $useCount = $this->dbw->selectField( 'oldimage', '1',
-                       array( 'oi_sha1' => $oimage->sha1,
-                               'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
-                       __METHOD__, array( 'FOR UPDATE' ) );
-               // Check the rest of the deleted archives too.
-               // (these are the ones that don't show in the image history)
-               if( !$useCount ) {
-                       $useCount = $this->dbw->selectField( 'filearchive', '1',
-                               array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
-                               __METHOD__, array( 'FOR UPDATE' ) );
-               }
-
-               if( $useCount == 0 ) {
-                       wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
-                       $flags = FileStore::DELETE_ORIGINAL;
-               } else {
-                       $flags = 0;
+       public static function extractBitfield( $bitPars, $oldfield ) {
+               // Build the actual new rev_deleted bitfield
+               $newBits = 0;
+               foreach( $bitPars as $const => $val ) {
+                       if( $val == 1 ) {
+                               $newBits |= $const; // $const is the *_deleted const
+                       } else if( $val == -1 ) {
+                               $newBits |= ($oldfield & $const); // use existing
+                       }
                }
-               $transaction->add( $store->export( $key, $destPath, $flags ) );
-
-               wfDebug( __METHOD__.": set db items, applying file transactions\n" );
-               $transaction->commit();
-               FileStore::unlock();
-
-               $m = explode('!',$oimage->archive_name,2);
-               $timestamp = $m[0];
-
-               return $timestamp;
+               return $newBits;
        }
 
        /**
-        * Update the revision's rev_deleted field
-        * @param Revision $rev
-        * @param int $bitfield new rev_deleted bitfield value
+        * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
         */
-       function updateRevision( $rev, $bitfield ) {
-               $this->dbw->update( 'revision',
-                       array( 'rev_deleted' => $bitfield ),
-                       array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
-                       __METHOD__
+       protected function save( $bitfield, $reason, $title ) {
+               return $this->getList()->setVisibility(
+                       array( 'value' => $bitfield, 'comment' => $reason )
                );
        }
-
-       /**
-        * Update the revision's rev_deleted field
-        * @param Revision $rev
-        * @param Title $title
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateArchive( $rev, $title, $bitfield ) {
-               $this->dbw->update( 'archive',
-                       array( 'ar_deleted' => $bitfield ),
-                       array( 'ar_namespace' => $title->getNamespace(),
-                               'ar_title'     => $title->getDBKey(),
-                               // use timestamp for index
-                               'ar_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ),
-                               'ar_rev_id'    => $rev->getId()
-                       ),
-                       __METHOD__ );
-       }
-
-       /**
-        * Update the images's oi_deleted field
-        * @param File $file
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateOldFiles( $file, $bitfield ) {
-               $this->dbw->update( 'oldimage',
-                       array( 'oi_deleted' => $bitfield ),
-                       array( 'oi_name' => $file->getName(),
-                               'oi_timestamp' => $this->dbw->timestamp( $file->getTimestamp() ) ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * Update the images's fa_deleted field
-        * @param ArchivedFile $file
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateArchFiles( $file, $bitfield ) {
-               $this->dbw->update( 'filearchive',
-                       array( 'fa_deleted' => $bitfield ),
-                       array( 'fa_id' => $file->getId() ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * Update the logging log_deleted field
-        * @param Row $row
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateLogs( $row, $bitfield ) {
-               $this->dbw->update( 'logging',
-                       array( 'log_deleted' => $bitfield ),
-                       array( 'log_id' => $row->log_id ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * Update the revision's recentchanges record if fields have been hidden
-        * @param Revision $rev
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateRecentChangesEdits( $rev, $bitfield ) {
-               $this->dbw->update( 'recentchanges',
-                       array( 'rc_deleted' => $bitfield,
-                                  'rc_patrolled' => 1 ),
-                       array( 'rc_this_oldid' => $rev->getId(),
-                               'rc_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ) ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * Update the revision's recentchanges record if fields have been hidden
-        * @param Row $row
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateRecentChangesLog( $row, $bitfield ) {
-               $this->dbw->update( 'recentchanges',
-                       array( 'rc_deleted' => $bitfield,
-                                  'rc_patrolled' => 1 ),
-                       array( 'rc_logid' => $row->log_id,
-                               'rc_timestamp' => $row->log_timestamp ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * Touch the page's cache invalidation timestamp; this forces cached
-        * history views to refresh, so any newly hidden or shown fields will
-        * update properly.
-        * @param Title $title
-        */
-       function updatePage( $title ) {
-               $title->invalidateCache();
-               $title->purgeSquid();
-               $title->touchLinks();
-               // Extensions that require referencing previous revisions may need this
-               wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
-       }
-
-       /**
-        * Checks for a change in the bitfield for a certain option and updates the
-        * provided array accordingly.
-        *
-        * @param String $desc Description to add to the array if the option was
-        * enabled / disabled.
-        * @param int $field The bitmask describing the single option.
-        * @param int $diff The xor of the old and new bitfields.
-        * @param array $arr The array to update.
-        */
-       protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
-               if( $diff & $field ) {
-                       $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
-               }
-       }
-
-       /**
-        * Gets an array describing the changes made to the visibilit of the revision.
-        * If the resulting array is $arr, then $arr[0] will contain an array of strings
-        * describing the items that were hidden, $arr[2] will contain an array of strings
-        * describing the items that were unhidden, and $arr[3] will contain an array with
-        * a single string, which can be one of "applied restrictions to sysops",
-        * "removed restrictions from sysops", or null.
-        *
-        * @param int $n The new bitfield.
-        * @param int $o The old bitfield.
-        * @return An array as described above.
-        */
-       protected static function getChanges( $n, $o ) {
-               $diff = $n ^ $o;
-               $ret = array( 0 => array(), 1 => array(), 2 => array() );
-               // Build bitfield changes in language
-               self::checkItem( wfMsgForContent( 'revdelete-content' ),
-                       Revision::DELETED_TEXT, $diff, $n, $ret );
-               self::checkItem( wfMsgForContent( 'revdelete-summary' ),
-                       Revision::DELETED_COMMENT, $diff, $n, $ret );
-               self::checkItem( wfMsgForContent( 'revdelete-uname' ),
-                       Revision::DELETED_USER, $diff, $n, $ret );
-               // Restriction application to sysops
-               if( $diff & Revision::DELETED_RESTRICTED ) {
-                       if( $n & Revision::DELETED_RESTRICTED )
-                               $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
-                       else
-                               $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
-               }
-               return $ret;
-       }
-
-       /**
-        * Gets a log message to describe the given revision visibility change. This
-        * message will be of the form "[hid {content, edit summary, username}];
-        * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
-        *
-        * @param int $count The number of effected revisions.
-        * @param int $nbitfield The new bitfield for the revision.
-        * @param int $obitfield The old bitfield for the revision.
-        * @param bool $isForLog
-        */
-       public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
-               global $wgLang;
-               $s = '';
-               $changes = self::getChanges( $nbitfield, $obitfield );
-               if( count( $changes[0] ) ) {
-                       $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
-               }
-               if( count( $changes[1] ) ) {
-                       if ($s) $s .= '; ';
-                       $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
-               }
-               if( count( $changes[2] ) ) {
-                       $s .= $s ? ' (' . $changes[2][0] . ')' : $changes[2][0];
-               }
-               $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
-               return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
-
-       }
-
-       /**
-        * Record a log entry on the action
-        * @param Title $title, page where item was removed from
-        * @param int $count the number of revisions altered for this page
-        * @param int $nbitfield the new _deleted value
-        * @param int $obitfield the old _deleted value
-        * @param string $comment
-        * @param Title $target, the relevant page
-        * @param string $param, URL param
-        * @param Array $items
-        */
-       function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
-               $param, $items = array() )
-       {
-               // Put things hidden from sysops in the oversight log
-               $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ?
-                       'suppress' : 'delete';
-               $log = new LogPage( $logtype );
-               $itemCSV = implode(',',$items);
-
-               if( $param == 'logid' ) {
-                       $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
-                       $log->addEntry( 'event', $title, $comment, $params );
-               } else {
-                       // Add params for effected page and ids
-                       $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
-                       $log->addEntry( 'revision', $title, $comment, $params );
-               }
-       }
 }
+