In Special:RevisionDelete:
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 1 Jun 2009 11:37:06 +0000 (11:37 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 1 Jun 2009 11:37:06 +0000 (11:37 +0000)
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.

Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText

FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.

17 files changed:
includes/Article.php
includes/AutoLoader.php
includes/FileStore.php [deleted file]
includes/ImagePage.php
includes/LogEventsList.php
includes/PageHistory.php
includes/Revision.php
includes/Status.php
includes/diff/DifferenceEngine.php
includes/filerepo/ArchivedFile.php
includes/filerepo/File.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialRevisiondelete.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialUpload.php
languages/messages/MessagesEn.php

index ac038dd..b1213fd 100644 (file)
@@ -792,8 +792,7 @@ class Article {
 
                # Allow admins to see deleted content if explicitly requested
                $delId = $diff ? $diff : $oldid;
-               $unhide = $wgRequest->getInt('unhide') == 1
-                       && $wgUser->matchEditToken( $wgRequest->getVal('token'), $delId );
+               $unhide = $wgRequest->getInt('unhide') == 1;
                # If we got diff and oldid in the query, we want to see a
                # diff page instead of the article.
                if( !is_null( $diff ) ) {
@@ -950,8 +949,7 @@ class Article {
                                                // If the user needs to confirm that they want to see it...
                                                } else if( !$unhide ) {
                                                        # Give explanation and add a link to view the revision...
-                                                       $link = $this->mTitle->getFullUrl( "oldid={$oldid}".
-                                                               '&unhide=1&token='.urlencode( $wgUser->editToken($oldid) ) );
+                                                       $link = $this->mTitle->getFullUrl( "oldid={$oldid}&unhide=1" );
                                                        $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n",
                                                                array('rev-deleted-text-unhide',$link) );
                                                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
@@ -3084,8 +3082,9 @@ class Article {
                        } else {
                                $cdel = $sk->makeKnownLinkObj( $revdel,
                                        wfMsgHtml('rev-delundel'),
-                                       'target=' . urlencode( $this->mTitle->getPrefixedDbkey() ) .
-                                       '&oldid=' . urlencode( $oldid ) );
+                                       'type=revision' . 
+                                       '&target=' . urlencode( $this->mTitle->getPrefixedDbkey() ) .
+                                       '&ids=' . urlencode( $oldid ) );
                                // Bolden oversighted content
                                if( $revision->isDeleted( Revision::DELETED_RESTRICTED ) )
                                        $cdel = "<strong>$cdel</strong>";
index d6c487b..a43ed3f 100644 (file)
@@ -74,12 +74,9 @@ $wgAutoloadLocalClasses = array(
        'FileDeleteForm' => 'includes/FileDeleteForm.php',
        'FileDependency' => 'includes/CacheDependency.php',
        'FileRevertForm' => 'includes/FileRevertForm.php',
-       'FileStore' => 'includes/FileStore.php',
        'ForkController' => 'includes/ForkController.php',
        'FormatExif' => 'includes/Exif.php',
        'FormOptions' => 'includes/FormOptions.php',
-       'FSException' => 'includes/FileStore.php',
-       'FSTransaction' => 'includes/FileStore.php',
        'GlobalDependency' => 'includes/CacheDependency.php',
        'HashBagOStuff' => 'includes/BagOStuff.php',
        'HashtableReplacer' => 'includes/StringUtils.php',
diff --git a/includes/FileStore.php b/includes/FileStore.php
deleted file mode 100644 (file)
index 278777b..0000000
+++ /dev/null
@@ -1,360 +0,0 @@
-<?php
-
-/**
- * @todo document (needs one-sentence top-level class description).
- */
-class FileStore {
-       const DELETE_ORIGINAL = 1;
-
-       /**
-        * Fetch the FileStore object for a given storage group
-        */
-       static function get( $group ) {
-               global $wgFileStore;
-
-               if( isset( $wgFileStore[$group] ) ) {
-                       $info = $wgFileStore[$group];
-                       return new FileStore( $group,
-                               $info['directory'],
-                               $info['url'],
-                               intval( $info['hash'] ) );
-               } else {
-                       return null;
-               }
-       }
-
-       private function __construct( $group, $directory, $path, $hash ) {
-               $this->mGroup = $group;
-               $this->mDirectory = $directory;
-               $this->mPath = $path;
-               $this->mHashLevel = $hash;
-       }
-
-       /**
-        * Acquire a lock; use when performing write operations on a store.
-        * This is attached to your master database connection, so if you
-        * suffer an uncaught error the lock will be released when the
-        * connection is closed.
-        * @see Database::lock()
-        */
-       static function lock() {
-               $dbw = wfGetDB( DB_MASTER );
-               $lockname = $dbw->addQuotes( FileStore::lockName() );
-               return $dbw->lock( $lockname, __METHOD__ );
-       }
-
-       /**
-        * Release the global file store lock.
-        * @see Database::unlock()
-        */
-       static function unlock() {
-               $dbw = wfGetDB( DB_MASTER );
-               $lockname = $dbw->addQuotes( FileStore::lockName() );
-               return $dbw->unlock( $lockname, __METHOD__ );
-       }
-
-       private static function lockName() {
-               return 'MediaWiki.' . wfWikiID() . '.FileStore';
-       }
-
-       /**
-        * Copy a file into the file store from elsewhere in the filesystem.
-        * Should be protected by FileStore::lock() to avoid race conditions.
-        *
-        * @param $key storage key string
-        * @param $flags
-        *  DELETE_ORIGINAL - remove the source file on transaction commit.
-        *
-        * @throws FSException if copy can't be completed
-        * @return FSTransaction
-        */
-       function insert( $key, $sourcePath, $flags=0 ) {
-               $destPath = $this->filePath( $key );
-               return $this->copyFile( $sourcePath, $destPath, $flags );
-       }
-
-       /**
-        * Copy a file from the file store to elsewhere in the filesystem.
-        * Should be protected by FileStore::lock() to avoid race conditions.
-        *
-        * @param $key storage key string
-        * @param $flags
-        *  DELETE_ORIGINAL - remove the source file on transaction commit.
-        *
-        * @throws FSException if copy can't be completed
-        * @return FSTransaction on success
-        */
-       function export( $key, $destPath, $flags=0 ) {
-               $sourcePath = $this->filePath( $key );
-               return $this->copyFile( $sourcePath, $destPath, $flags );
-       }
-
-       private function copyFile( $sourcePath, $destPath, $flags=0 ) {
-               if( !file_exists( $sourcePath ) ) {
-                       // Abort! Abort!
-                       throw new FSException( "missing source file '$sourcePath'" );
-               }
-
-               $transaction = new FSTransaction();
-
-               if( $flags & self::DELETE_ORIGINAL ) {
-                       $transaction->addCommit( FSTransaction::DELETE_FILE, $sourcePath );
-               }
-
-               if( file_exists( $destPath ) ) {
-                       // An identical file is already present; no need to copy.
-               } else {
-                       if( !file_exists( dirname( $destPath ) ) ) {
-                               wfSuppressWarnings();
-                               $ok = wfMkdirParents( dirname( $destPath ) );
-                               wfRestoreWarnings();
-
-                               if( !$ok ) {
-                                       throw new FSException(
-                                               "failed to create directory for '$destPath'" );
-                               }
-                       }
-
-                       wfSuppressWarnings();
-                       $ok = copy( $sourcePath, $destPath );
-                       wfRestoreWarnings();
-
-                       if( $ok ) {
-                               wfDebug( __METHOD__." copied '$sourcePath' to '$destPath'\n" );
-                               $transaction->addRollback( FSTransaction::DELETE_FILE, $destPath );
-                       } else {
-                               throw new FSException(
-                                       __METHOD__." failed to copy '$sourcePath' to '$destPath'" );
-                       }
-               }
-
-               return $transaction;
-       }
-
-       /**
-        * Delete a file from the file store.
-        * Caller's responsibility to make sure it's not being used by another row.
-        *
-        * File is not actually removed until transaction commit.
-        * Should be protected by FileStore::lock() to avoid race conditions.
-        *
-        * @param $key storage key string
-        * @throws FSException if file can't be deleted
-        * @return FSTransaction
-        */
-       function delete( $key ) {
-               $destPath = $this->filePath( $key );
-               if( false === $destPath ) {
-                       throw new FSException( "file store does not contain file '$key'" );
-               } else {
-                       return FileStore::deleteFile( $destPath );
-               }
-       }
-
-       /**
-        * Delete a non-managed file on a transactional basis.
-        *
-        * File is not actually removed until transaction commit.
-        * Should be protected by FileStore::lock() to avoid race conditions.
-        *
-        * @param $path file to remove
-        * @throws FSException if file can't be deleted
-        * @return FSTransaction
-        *
-        * @todo Might be worth preliminary permissions check
-        */
-       static function deleteFile( $path ) {
-               if( file_exists( $path ) ) {
-                       $transaction = new FSTransaction();
-                       $transaction->addCommit( FSTransaction::DELETE_FILE, $path );
-                       return $transaction;
-               } else {
-                       throw new FSException( "cannot delete missing file '$path'" );
-               }
-       }
-
-       /**
-        * Stream a contained file directly to HTTP output.
-        * Will throw a 404 if file is missing; 400 if invalid key.
-        * @return true on success, false on failure
-        */
-       function stream( $key ) {
-               $path = $this->filePath( $key );
-               if( $path === false ) {
-                       wfHttpError( 400, "Bad request", "Invalid or badly-formed filename." );
-                       return false;
-               }
-
-               if( file_exists( $path ) ) {
-                       // Set the filename for more convenient save behavior from browsers
-                       // FIXME: Is this safe?
-                       header( 'Content-Disposition: inline; filename="' . $key . '"' );
-
-                       require_once 'StreamFile.php';
-                       wfStreamFile( $path );
-               } else {
-                       return wfHttpError( 404, "Not found",
-                               "The requested resource does not exist." );
-               }
-       }
-
-       /**
-        * Confirm that the given file key is valid.
-        * Note that a valid key may refer to a file that does not exist.
-        *
-        * Key should consist of a 31-digit base-36 SHA-1 hash and
-        * an optional alphanumeric extension, all lowercase.
-        * The whole must not exceed 64 characters.
-        *
-        * @param $key
-        * @return boolean
-        */
-       static function validKey( $key ) {
-               return preg_match( '/^[0-9a-z]{31,32}(\.[0-9a-z]{1,31})?$/', $key );
-       }
-
-
-       /**
-        * Calculate file storage key from a file on disk.
-        * You must pass an extension to it, as some files may be calculated
-        * out of a temporary file etc.
-        *
-        * @param $path to file
-        * @param $extension
-        * @return string or false if could not open file or bad extension
-        */
-       static function calculateKey( $path, $extension ) {
-               wfSuppressWarnings();
-               $hash = sha1_file( $path );
-               wfRestoreWarnings();
-               if( $hash === false ) {
-                       wfDebug( __METHOD__.": couldn't hash file '$path'\n" );
-                       return false;
-               }
-
-               $base36 = wfBaseConvert( $hash, 16, 36, 31 );
-               if( $extension == '' ) {
-                       $key = $base36;
-               } else {
-                       $key = $base36 . '.' . $extension;
-               }
-
-               // Sanity check
-               if( self::validKey( $key ) ) {
-                       return $key;
-               } else {
-                       wfDebug( __METHOD__.": generated bad key '$key'\n" );
-                       return false;
-               }
-       }
-
-       /**
-        * Return filesystem path to the given file.
-        * Note that the file may or may not exist.
-        * @return string or false if an invalid key
-        */
-       function filePath( $key ) {
-               if( self::validKey( $key ) ) {
-                       return $this->mDirectory . DIRECTORY_SEPARATOR .
-                               $this->hashPath( $key, DIRECTORY_SEPARATOR );
-               } else {
-                       return false;
-               }
-       }
-
-       /**
-        * Return URL path to the given file, if the store is public.
-        * @return string or false if not public
-        */
-       function urlPath( $key ) {
-               if( $this->mUrl && self::validKey( $key ) ) {
-                       return $this->mUrl . '/' . $this->hashPath( $key, '/' );
-               } else {
-                       return false;
-               }
-       }
-
-       private function hashPath( $key, $separator ) {
-               $parts = array();
-               for( $i = 0; $i < $this->mHashLevel; $i++ ) {
-                       $parts[] = $key{$i};
-               }
-               $parts[] = $key;
-               return implode( $separator, $parts );
-       }
-}
-
-/**
- * Wrapper for file store transaction stuff.
- *
- * FileStore methods may return one of these for undoable operations;
- * you can then call its rollback() or commit() methods to perform
- * final cleanup if dependent database work fails or succeeds.
- */
-class FSTransaction {
-       const DELETE_FILE = 1;
-
-       /**
-        * Combine more items into a fancier transaction
-        */
-       function add( FSTransaction $transaction ) {
-               $this->mOnCommit = array_merge(
-                       $this->mOnCommit, $transaction->mOnCommit );
-               $this->mOnRollback = array_merge(
-                       $this->mOnRollback, $transaction->mOnRollback );
-       }
-
-       /**
-        * Perform final actions for success.
-        * @return true if actions applied ok, false if errors
-        */
-       function commit() {
-               return $this->apply( $this->mOnCommit );
-       }
-
-       /**
-        * Perform final actions for failure.
-        * @return true if actions applied ok, false if errors
-        */
-       function rollback() {
-               return $this->apply( $this->mOnRollback );
-       }
-
-       // --- Private and friend functions below...
-
-       function __construct() {
-               $this->mOnCommit = array();
-               $this->mOnRollback = array();
-       }
-
-       function addCommit( $action, $path ) {
-               $this->mOnCommit[] = array( $action, $path );
-       }
-
-       function addRollback( $action, $path ) {
-               $this->mOnRollback[] = array( $action, $path );
-       }
-
-       private function apply( $actions ) {
-               $result = true;
-               foreach( $actions as $item ) {
-                       list( $action, $path ) = $item;
-                       if( $action == self::DELETE_FILE ) {
-                               wfSuppressWarnings();
-                               $ok = unlink( $path );
-                               wfRestoreWarnings();
-                               if( $ok )
-                                       wfDebug( __METHOD__.": deleting file '$path'\n" );
-                               else
-                                       wfDebug( __METHOD__.": failed to delete file '$path'\n" );
-                               $result = $result && $ok;
-                       }
-               }
-               return $result;
-       }
-}
-
-/**
- * @ingroup Exception
- */
-class FSException extends MWException { }
index 65ff9ce..3120e53 100644 (file)
@@ -795,7 +795,6 @@ class ImageHistoryList {
                $user = $file->getUser('id');
                $usertext = $file->getUser('text');
                $description = $file->getDescription();
-               $sha1 = $file->getSha1();
 
                $local = $this->current->isLocal();
                $row = $css = $selected = '';
@@ -828,7 +827,11 @@ class ImageHistoryList {
                                        list( $ts, $name ) = explode( '!', $img, 2 );
                                        $del = $this->skin->link( $revdel, wfMsgHtml( 'rev-delundel' ),
                                                array(),
-                                               array( 'target' => $wgTitle->getPrefixedText(), 'oldimage' => $ts ),
+                                               array( 
+                                                       'type' => 'oldimage',
+                                                       'target' => $wgTitle->getPrefixedText(), 
+                                                       'ids' => $ts,
+                                               ),
                                                array( 'known' )
                                        );
                                        // Bolden oversighted content
@@ -871,7 +874,9 @@ class ImageHistoryList {
                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                        # Make a link to review the image
                        $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
-                               "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current->getExtension() );
+                               "target=".$wgTitle->getPrefixedUrl().
+                               "&file=" . urlencode( $img ) .
+                               "&token=" . urlencode( $wgUser->editToken( $img ) ) );
                        $row .= '<span class="history-deleted">'.$url.'</span>';
                } elseif( $file->isMissing() ) {
                        # Don't link to missing files
index 32d73f3..9cc3c13 100644 (file)
@@ -298,19 +298,18 @@ class LogEventsList {
                                $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                                // Different revision types use different URL params...
                                $key = $paramArray[0];
-                               // $paramArray[1] is a CVS of the IDs
+                               // $paramArray[1] is a CSV of the IDs
                                $Ids = explode( ',', $paramArray[1] );
                                $query = urlencode($paramArray[1]);
                                $revert = array();
                                // Diff link for single rev deletions
-                               if( $key === 'oldid' && count($Ids) == 1 ) {
-                                       $token = urlencode( $wgUser->editToken( intval($Ids[0]) ) );
+                               if( ( $key === 'oldid' || $key == 'revision' ) && count($Ids) == 1 ) {
                                        $revert[] = $this->skin->makeKnownLinkObj( $title, $this->message['diff'], 
-                                               'diff='.intval($Ids[0])."&unhide=1&token=$token" );
+                                               'diff='.intval($Ids[0])."&unhide=1" );
                                }
                                // View/modify link...
                                $revert[] = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
-                                       'target='.$title->getPrefixedUrl()."&$key=$query" );
+                                       'target='.$title->getPrefixedUrl()."&type=$key&ids=$query" );
                                // Pipe links
                                $revert = '(' . implode(' | ',$revert) . ')';
                        }
@@ -318,12 +317,12 @@ class LogEventsList {
                } else if( self::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
                        if( count($paramArray) >= 1 ) {
                                $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
-                               // $paramArray[1] is a CVS of the IDs
+                               // $paramArray[1] is a CSV of the IDs
                                $Ids = explode( ',', $paramArray[0] );
                                $query = urlencode($paramArray[0]);
                                // Link to each hidden object ID, $paramArray[1] is the url param
                                $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'], 
-                                       'target='.$title->getPrefixedUrl()."&logid=$query" ) . ')';
+                                       'target='.$title->getPrefixedUrl()."&type=logging&ids=$query" ) . ')';
                        }
                // Self-created users
                } else if( self::typeAction($row,'newusers','create2') ) {
@@ -370,7 +369,6 @@ class LogEventsList {
         * @return string
         */
        private function getShowHideLinks( $row ) {
-               $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                // If event was hidden from sysops
                if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
                        $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
@@ -380,8 +378,11 @@ class LogEventsList {
                } else {
                        $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
                        $page = Title::makeTitle( $row->log_namespace, $row->log_title );
-                       $query = array( 'target' => $target->getPrefixedDBkey(),
-                               'logid' => $row->log_id, 'page' => $page->getPrefixedDBkey() );
+                       $query = array( 
+                               'target' => $target->getPrefixedDBkey(),
+                               'type' => 'logging',
+                               'ids' => $row->log_id, 
+                       );
                        $del = $this->skin->revDeleteLink( $query,
                                self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
                }
index 7354a89..56e9e18 100644 (file)
@@ -160,13 +160,16 @@ class PageHistory {
                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                        $s .= Xml::openElement( 'form',
                                array(
-                                       'action' => $revdel->getFullUrl(),
-                                       'method' => 'get', 'id' => 'mw-history-revdeleteform',
+                                       'action' => $revdel->getLocalURL( array( 
+                                               'type' => 'revision',
+                                               'target' => $this->mTitle->getPrefixedDbKey()
+                                       ) ),
+                                       'method' => 'post', 
+                                       'id' => 'mw-history-revdeleteform',
                                        'style'  => 'visibility:hidden;float:right;'
                                )
                        );
-                       $s .= Xml::hidden( 'target', $this->mTitle->getPrefixedDbKey() );
-                       $s .= Xml::hidden( 'oldid', '', array('id'=>'revdel-oldid') );
+                       $s .= Xml::hidden( 'ids', '', array('id'=>'revdel-oldid') );
                        $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) );
                        $s .= Xml::closeElement( 'form' );
                }
@@ -296,8 +299,10 @@ class PageHistory {
                                $jsCall = 'updateShowHideForm('.$rev->getId().',this.checked)';
                                $del = Xml::check( 'showhiderevisions', false,
                                        $hidden + array('onchange' => $jsCall) );
-                               $query = array( 'target' => $this->mTitle->getPrefixedDbkey(),
-                                       'oldid' => $rev->getId() );
+                               $query = array(
+                                       'type' => 'revision',
+                                       'target' => $this->mTitle->getPrefixedDbkey(),
+                                       'ids' => $rev->getId() );
                                $del .= $this->mSkin->revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
index 8a2149c..780bed2 100644 (file)
@@ -66,6 +66,30 @@ class Revision {
                return Revision::newFromConds( $conds );
        }
 
+       /**
+        * Make a fake revision object from an archive table row. This is queried
+        * for permissions or even inserted (as in Special:Undelete)
+        * @fixme: should be a subclass for RevisionDelete. [TS]
+        */
+       public static function newFromArchiveRow( $row, $overrides = array() ) {
+               $attribs = $overrides + array(
+                       'page'       => isset( $row->page_id ) ? $row->page_id : null,
+                       'id'         => isset( $row->ar_rev_id ) ? $row->ar_rev_id : null,
+                       'comment'    => $row->ar_comment,
+                       'user'       => $row->ar_user,
+                       'user_text'  => $row->ar_user_text,
+                       'timestamp'  => $row->ar_timestamp,
+                       'minor_edit' => $row->ar_minor_edit,
+                       'text_id'    => isset( $row->ar_text_id ) ? $row->ar_text_id : null,
+                       'deleted'    => $row->ar_deleted,
+                       'len'        => $row->ar_len);
+               if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
+                       // Pre-1.5 ar_text row
+                       $attribs['text'] = $row->ar_text;
+               }
+               return new self( $attribs );
+       }
+
        /**
         * Load a page revision from a given revision ID number.
         * Returns null if no such revision can be found.
@@ -864,15 +888,17 @@ class Revision {
         *
         * @return string
         */
-       private function loadText() {
+       protected function loadText() {
                wfProfileIn( __METHOD__ );
 
                // Caching may be beneficial for massive use of external storage
                global $wgRevisionCacheExpiry, $wgMemc;
-               $key = wfMemcKey( 'revisiontext', 'textid', $this->getTextId() );
+               $textId = $this->getTextId();
+               $key = wfMemcKey( 'revisiontext', 'textid', $textId );
                if( $wgRevisionCacheExpiry ) {
                        $text = $wgMemc->get( $key );
                        if( is_string( $text ) ) {
+                               wfDebug( __METHOD__. ": got id $textId from cache\n" );
                                wfProfileOut( __METHOD__ );
                                return $text;
                        }
index 516ed95..4bceb2e 100644 (file)
@@ -159,7 +159,7 @@ class Status {
                        if ( $longContext ) {
                                $s = wfMsgNoTrans( $longContext, $s );
                        } elseif ( $shortContext ) {
-                               $s = wfMsgNoTrans( $shortContext, "\n$s\n" );
+                               $s = wfMsgNoTrans( $shortContext, "\n$s\n" );
                        }
                }
                return $s;
index 53f9f8a..2df9e14 100644 (file)
@@ -255,8 +255,10 @@ CONTROL;
                                // If revision was hidden from sysops
                                $ldel = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml( 'rev-delundel' ).')' );
                        } else {
-                               $query = array( 'target' => $this->mOldRev->mTitle->getPrefixedDbkey(),
-                                       'oldid' => $this->mOldRev->getId()
+                               $query = array( 
+                                       'type' => 'revision',
+                                       'target' => $this->mOldRev->mTitle->getPrefixedDbkey(),
+                                       'ids' => $this->mOldRev->getId()
                                );
                                $ldel = $sk->revDeleteLink( $query, $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
@@ -268,8 +270,10 @@ CONTROL;
                                // If revision was hidden from sysops
                                $rdel = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml( 'rev-delundel' ).')' );
                        } else {
-                               $query = array( 'target' =>  $this->mNewRev->mTitle->getPrefixedDbkey(),
-                                       'oldid' => $this->mNewRev->getId()
+                               $query = array( 
+                                       'type' => 'revision',
+                                       'target' =>  $this->mNewRev->mTitle->getPrefixedDbkey(),
+                                       'ids' => $this->mNewRev->getId()
                                );
                                $rdel = $sk->revDeleteLink( $query, $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
@@ -301,8 +305,7 @@ CONTROL;
                                        array( 'rev-deleted-no-diff' ) );
                        } else {
                                # Give explanation and add a link to view the diff...
-                               $link = $this->mTitle->getFullUrl( "diff={$this->mNewid}&oldid={$this->mOldid}".
-                                       '&unhide=1&token='.urlencode( $wgUser->editToken($this->mNewid) ) );
+                               $link = $this->mTitle->getFullUrl( "diff={$this->mNewid}&oldid={$this->mOldid}&unhide=1" );
                                $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n",
                                        array( 'rev-deleted-unhide-diff', $link ) );
                        }
index 68c93b8..46a295d 100644 (file)
@@ -202,6 +202,13 @@ class ArchivedFile
                return $this->key;
        }
 
+       /**
+        * Return the FileStore key (overriding base File class)
+        */
+       public function getStorageKey() {
+               return $this->getKey();
+       }
+
        /**
         * Return the FileStore storage group
         */
index 88e69a2..8d7899e 100644 (file)
@@ -1127,6 +1127,19 @@ abstract class File {
                return self::sha1Base36( $this->getPath() );
        }
 
+       /**
+        * Get the deletion archive key, <sha1>.<ext>
+        */
+       function getStorageKey() {
+               $hash = $this->getSha1();
+               if ( !$hash ) {
+                       return false;
+               }
+               $ext = $this->getExtension();
+               $dotExt = $ext === '' ? '' : ".$ext";
+               return $hash . $dotExt;                         
+       }
+
        /**
         * Determine if the current user is allowed to view a particular
         * field of this file, if it's marked as deleted.
index 8a4fc92..19c895e 100644 (file)
@@ -545,7 +545,10 @@ class ContribsPager extends ReverseChronologicalPager {
                                        '(' . $this->message['rev-delundel'] . ')' ) . ' ';
                        // Otherwise, show the link...
                        } else {
-                               $query = array( 'target' => $page->getPrefixedDbkey(), 'oldid' => $rev->getId() );
+                               $query = array(
+                                       'type' => 'revision',
+                                       'target' => $page->getPrefixedDbkey(),
+                                       'ids' => $rev->getId() );
                                $del = $this->mSkin->revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ) ) . ' ';
                        }
index 5d6615e..763bd9b 100644 (file)
@@ -170,8 +170,10 @@ class DeletedContribsPager extends IndexPager {
                                        '(' . $this->message['rev-delundel'] . ')' ) . ' ';
                        // Otherwise, show the link...
                        } else {
-                               $query = array( 'target' => $page->getPrefixedDbkey(),
-                                       'artimestamp' => $rev->getTimestamp() );
+                               $query = array(
+                                       'type' => 'archive',
+                                       'target' => $page->getPrefixedDbkey(),
+                                       'ids' => $rev->getTimestamp() );
                                $del = $this->mSkin->revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ) ) . ' ';
                        }
index 291705c..02099fb 100644 (file)
  */
 
 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;
+
+       /** New bitfield value, used for form display post-submit */
+       var $newBits;
+
+       /**
+        * 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
        }
 
        public function execute( $par ) {
                global $wgOut, $wgUser, $wgRequest;
                if( !$wgUser->isAllowed( 'deleterevision' ) ) {
-                       return $wgOut->permissionRequired( 'deleterevision' );
+                       $wgOut->permissionRequired( 'deleterevision' );
+                       return;
                } else if( wfReadOnly() ) {
-                       return $wgOut->readOnlyPage();
+                       $wgOut->readOnlyPage();
+                       return;
                }
-               $this->skin =& $wgUser->getSkin();
+               $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) );
+               # Use CSV, since the cgi handling will break on arrays.
+               $this->ids = explode( ',', $wgRequest->getVal('ids') );
+               $this->ids = array_unique( array_filter( $this->ids ) );
+               $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;
+               }
+
+               $this->typeName = $wgRequest->getVal( 'type' );
+               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;
                }
                # 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->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();
                }
                $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(), '', 25, $qc );
+               LogEventsList::showLogExtract( $wgOut, 'delete', $this->targetObj->getPrefixedText(), '', 25, $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(), '', 25, $qc );
+                       LogEventsList::showLogExtract( $wgOut, 'suppress', $this->targetObj->getPrefixedText(), '', 25, $qc );
                }
        }
-       
-       private function showConvenienceLinks() {
+
+       /**
+        * Show some useful links in the subtitle
+        */
+       protected function showConvenienceLinks() {
                global $wgOut, $wgUser;
                # 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() ) ) );
+                               wfArrayToCGI( array( 'page' => $this->targetObj->getPrefixedUrl() ) ) );
                        # Give a link to the page history
-                       $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
+                       $links[] = $this->skin->makeKnownLinkObj( $this->targetObj, 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() ) ) );
+                                       wfArrayToCGI( array( 'target' => $this->targetObj->getPrefixedDBkey() ) ) );
                        }
                        # Logs themselves don't have histories or archived revisions
                        $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
                }
        }
-       
-       private function getLogQueryCond() {
+
+       /**
+        * Get the condition used for fetching log snippets
+        */
+       protected function getLogQueryCond() {
                $conds = array();
-               $logAction = 'revision';
-               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;
-                               $logAction = 'event';
-                               break;
-                       default: // bad type?
-                               return array();
-               }
                // Revision delete logs for these item
                $conds['log_type'] = array('delete','suppress');
-               $conds['log_action'] = $logAction;
-               $conds['ls_field'] = RevisionDeleter::getRelationType( $this->deleteKey );
-               $conds['ls_value'] = $ids;
+               $conds['log_action'] = $this->getList()->getLogAction();
+               $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
+               $conds['ls_value'] = $this->ids;
                return $conds;
        }
 
-       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 );
-               }
-       }
-
        /**
         * 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->exists() ) {
+                       $wgOut->addWikiMsg( 'revdelete-no-file' );
+                       return;
+               }
                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 );
-               }
+                       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>'
+                       );
+                       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' );
+
+               # 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 );
        }
 
        /**
-        * This lets a user set restrictions for live and archived revisions
+        * Get the list object for this request
         */
-       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 );
-                       }
-                       $result = $dbr->select( 'archive', '*',
-                               array(
-                                       'ar_namespace' => $this->page->getNamespace(),
-                                       'ar_title'     => $this->page->getDBkey(),
-                                       'ar_timestamp' => $where
-                               ),
-                               __METHOD__
-                       );
-                       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;
-                       }
-               }
-               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;
-
-               $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' ) )
-               );
-
-               $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
-               foreach( $items as $item ) {
-                       $wgOut->addHTML( Xml::tags( 'p', null, $item ) );
-               }
-               foreach( $hidden as $item ) {
-                       $wgOut->addHTML( $item );
+       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;
+               $where = $revObjs = array();
+               
+               $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->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 );
+                               $UserAllowed = false;
                        }
+                       $numRevisions++;
+                       $bitfields |= $item->getBits();
+                       $wgOut->addHTML( $item->getHTML() );
+               }
 
-                       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;
-                               }
-                               $revisions++;
-                               // Inject history info
-                               $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
-                               $bitfields |= $filesObjs[$fileid]->deleted;
-                       }
+               if( !$numRevisions ) {
+                       $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
+                       return;
                }
-               if( !$revisions ) {
-                       return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
+
+               if ( !is_null( $this->newBits ) ) {
+                       $bitfields = $this->newBits;
                }
                
                $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) );
-               } 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 );
-               }
-
-               $wgOut->addHTML(
+                               'id' => 'mw-revdel-form-revisions' ) ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null,  wfMsg( 'revdelete-legend' ) ) .
+                       $this->buildCheckBoxes( $bitfields ) .
+                       '<p>' . Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ) . '</p>' . 
+                       '<p>' . Xml::submitButton( wfMsg( 'revdelete-submit' ), 
+                               array( 'name' => 'wpSubmit' ) ) . '</p>' .
+                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Xml::hidden( 'target', $this->targetObj->getPrefixedText() ) .
+                       Xml::hidden( 'type', $this->typeName ) .
+                       Xml::hidden( 'ids', implode( ',', $this->ids ) ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' ) . "\n"
                );
        }
 
        /**
-        * 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' ) ) {
@@ -578,7 +369,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        * @param int $bitfields, aggregate bitfield of all the bitfields
        * @returns string HTML
        */
-       private function buildCheckBoxes( $bitfields ) {
+       protected 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 ) {
@@ -592,846 +383,91 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        }
 
        /**
-        * @param Revision $rev
-        * @returns string
+        * UI entry point for form submission.
+        * @param WebRequest $request
         */
-       private function historyLine( $rev ) {
-               global $wgLang, $wgUser;
-
-               $date = $wgLang->timeanddate( $rev->getTimestamp() );
-               $difflink = '';
-               // 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() ) . ')';
+       protected function submit( $request ) {
+               global $wgUser, $wgOut;
+               # Check edit token on submission
+               if( $this->submitClicked && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
+                       $wgOut->addWikiMsg( 'sessionfailure' );
+                       return false;
                }
-               // Check permissions; items may be "suppressed"
-               if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
-                       $revlink = '<span class="history-deleted">'.$revlink.'</span>';
-                       if( !$rev->userCan(Revision::DELETED_TEXT) ) {
-                               $revlink = '<span class="history-deleted">'.$date.'</span>';
-                               $difflink = '(' . wfMsgHtml('diff') . ')';
-                       }
+               $bitfield = $this->extractBitfield( $request );
+               $comment = $request->getText( 'wpReason' );
+               # Can the user set this field?
+               if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
+                       $wgOut->permissionRequired( 'suppressrevision' );
+                       return false;
                }
-               $userlink = $this->skin->revUserLink( $rev );
-               $comment = $this->skin->revComment( $rev );
-
-               return "<li>$difflink $revlink $userlink $comment</li>";
+               # If the save went through, go to success message...
+               $status = $this->save( $bitfield, $comment, $this->targetObj );
+               if ( $status->isGood() ) {
+                       $this->success();
+                       return true;
+               # ...otherwise, bounce back to form...
+               } else {
+                       $this->failure( $status );
+               }
+               return false;
        }
 
        /**
-        * @param File $file
-        * @returns string
+        * Report that the submit operation succeeded
         */
-       private function fileLine( $file ) {
-               global $wgLang;
-
-               $target = $this->page->getPrefixedText();
-               $date = $wgLang->timeanddate( $file->getTimestamp(), true  );
-
-               # Hidden files...
-               if( $file->isDeleted(File::DELETED_FILE) ) {
-                       if( !$file->userCan(File::DELETED_FILE) ) {
-                               $pageLink = $date;
-                       } else {
-                               $pageLink = $this->skin->makeKnownLinkObj( $this->getTitle(), $date,
-                                       "target=$target&file=$file->sha1.".$file->getExtension() );
-                       }
-                       $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
-               # Regular files...
-               } 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 )."</li>";
+       protected function success() {
+               global $wgOut;
+               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
+               $wgOut->wrapWikiMsg( '<span class="success">$1</span>', $this->typeInfo['success'] );
+               $this->showForm();
        }
 
        /**
-        * @param ArchivedFile $file
-        * @returns string
+        * Report that the submit operation failed
         */
-       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()}" );
-
-               $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 )."</li>";
+       protected function failure( $status ) {
+               global $wgOut;
+               $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
+               $wgOut->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) );
+               $this->showForm();
        }
 
        /**
-        * @param Array $row row
-        * @returns string
+        * Put together a rev_deleted bitfield from the submitted checkboxes
+        * @param WebRequest $request
+        * @return int
         */
-       private function logLine( $row ) {
-               global $wgLang;
-
-               $date = htmlspecialchars( $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>';
+       protected function extractBitfield( $request ) {
+               $bitfield = 0;
+               foreach( $this->checks as $item ) {
+                       list( /* message */ , $name, $field ) = $item;
+                       if( $request->getCheck( $name ) ) {
+                               $bitfield |= $field;
+                       }
                }
-               return "<li>($loglink) $date $userLink $action $comment</li>";
+               return $bitfield;
        }
 
        /**
-        * Generate a user tool link cluster if the current user is allowed to view it
-        * @param ArchivedFile $file
-        * @return string HTML
+        * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
         */
-       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>";
-               }
-               return $block;
-       }
-
-       /**
-        * @param WebRequest $request
-        */
-       private function submit( $request ) {
-               global $wgUser, $wgOut;
-               # Check edit token on submission
-               if( $this->wasPosted && !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
-                       $wgOut->addWikiMsg( 'sessionfailure' );
-                       return false;
-               }
-               $bitfield = $this->extractBitfield( $request );
-               $comment = $request->getText( 'wpReason' );
-               # Can the user set this field?
-               if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
-                       $wgOut->permissionRequired( 'suppressrevision' );
-                       return false;
-               }
-               # If the save went through, go to success message...
-               if( $this->save( $bitfield, $comment, $this->page ) ) {
-                       $this->success();
-                       return true;
-               # ...otherwise, bounce back to form...
-               } else {
-                       $this->failure();
-               }
-               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( 'actionfailed' ) );
-               $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 );
+       protected function save( $bitfield, $reason, $title ) {
                // Don't allow simply locking the interface for no reason
                if( $bitfield == Revision::DELETED_RESTRICTED ) {
-                       return false;
-               }
-               $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 Status::newFatal( 'revdelete-only-restricted' );
                }
-               return false;
+               $this->newBits = $bitfield;
+               return $this->getList()->setVisibility( array(
+                       'value' => $bitfield,
+                       'comment' => $reason ) );
        }
 }
 
 /**
- * Implements the actions for Revision Deletion.
+ * Temporary b/c interface, collection of static functions.
  * @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
-        */
-       function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
-               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;
-       }
-
-       /**
-        * @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
-        */
-       function setEventVisibility( $title, $items, $bitfield, $comment ) {
-               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;
-       }
-
-       /**
-        * 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
-        */
-       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
-                       }
-               } else {
-                       wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
-                       $group = null;
-                       $key = '';
-                       $transaction = new FSTransaction(); // empty
-               }
-
-               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;
-               }
-
-               wfDebug( __METHOD__.": set db items, applying file transactions\n" );
-               $transaction->commit();
-               FileStore::unlock();
-
-               $m = explode('!',$oimage->archive_name,2);
-               $timestamp = $m[0];
-
-               return $timestamp;
-       }
-
-       /**
-        * 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
-        */
-       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;
-               }
-               $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;
-       }
-
-       /**
-        * Update the revision's rev_deleted field
-        * @param Revision $rev
-        * @param int $bitfield new rev_deleted bitfield value
-        */
-       function updateRevision( $rev, $bitfield ) {
-               $this->dbw->update( 'revision',
-                       array( 'rev_deleted' => $bitfield ),
-                       array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
-                       __METHOD__
-               );
-       }
-
-       /**
-        * 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();
-               $this->dbw->commit(); // Commit the transaction before the purge is sent
-               $title->purgeSquid();
-               // 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.
@@ -1508,60 +544,1020 @@ class RevisionDeleter {
                return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
 
        }
-
+       
+       // Get DB field name for URL param...
+       // Future code for other things may also track
+       // other types of revision-specific changes.
+       public static function getRelationType( $typeName ) {
+               if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
+                       $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
+               }
+               if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
+                       $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
+                       $list = new $class( null, null, null );
+                       return $list->getIdField();
+               } else {
+                       return null;
+               }
+       }
+}
+
+/**
+ * Abstract base class for a list of deletable items
+ */
+abstract class RevDel_List {
+       var $special, $title, $ids, $res, $current;
+       var $type = null; // override this
+       var $idField = null; // override this
+       var $dateField = false; // override this
+
+       /**
+        * @param $special The parent SpecialPage
+        * @param $title The target title
+        * @param $ids Array of IDs
+        */
+       public function __construct( $special, $title, $ids ) {
+               $this->special = $special;
+               $this->title = $title;
+               $this->ids = $ids;
+       }
+
+       /**
+        * Get the internal type name of this list. Equal to the table name.
+        */
+       public function getType() {
+               return $this->type;
+       }
+
+       /**
+        * Get the DB field name associated with the ID list/
+        */
+       public function getIdField() {
+               return $this->idField;
+       }
+
+       /**
+        * Get the DB field name storing timestamps
+        */
+       public function getTimestampField() {
+               return $this->dateField;
+       }
+
+       /**
+        * Set the visibility for the revisions in this list. Logging and 
+        * transactions are done here.
+        *
+        * @param $params Associative array of parameters. Members are:
+        *     value:       The integer value to set the visibility to
+        *     comment:     The log comment.
+        * @return Status
+        */
+       public function setVisibility( $params ) {
+               $newBits = $params['value'];
+               $comment = $params['comment'];
+
+               $this->res = false;
+               $dbw = wfGetDB( DB_MASTER );
+               $this->doQuery( $dbw );
+               $dbw->begin();
+               $status = Status::newGood();
+               $missing = array_flip( $this->ids );
+               $this->clearFileOps();
+               $idsForLog = array();
+
+               for ( $this->reset(); $this->current(); $this->next() ) {
+                       $item = $this->current();
+                       unset( $missing[ $item->getId() ] );
+
+                       // Make error messages less vague
+                       $oldBits = $item->getBits();
+                       if ( $oldBits == $newBits ) {
+                               $status->warning( 'revdelete-no-change', $item->formatDateTime() );
+                               $status->failCount++;
+                               continue;
+                       } elseif ( $oldBits == 0 && $newBits != 0 ) {
+                               $opType = 'hide';
+                       } elseif ( $oldBits != 0 && $newBits == 0 ) {
+                               $opType = 'show';
+                       } else {
+                               $opType = 'modify';
+                       }
+
+                       if ( $item->isCurrent() && $opType == 'hide' ) {
+                               // Cannot hide current version text
+                               $status->error( 'revdelete-hide-current', $item->formatDateTime() );
+                               $status->failCount++;
+                               continue;
+                       }
+                       if ( !$item->canView() ) {
+                               // Cannot access this revision
+                               $msg = $opType == 'show' ? 'revdelete-show-no-access' : 'revdelete-modify-no-access';
+                               $status->error( $msg, $item->formatDateTime() );
+                               $status->failCount++;
+                               continue;
+                       }
+
+                       // Update the revision
+                       $ok = $item->setBits( $newBits );
+
+                       if ( $ok ) {
+                               $idsForLog[] = $item->getId();
+                               $status->successCount++;
+                       } else {
+                               $status->error( 'revdelete-concurrent-change', $item->formatDateTime() );
+                               $status->failCount++;
+                       }
+               }
+
+               // Handle missing revisions
+               foreach ( $missing as $id => $unused ) {
+                       $status->error( 'revdelete-modify-missing', $id );
+                       $status->failCount++;
+               }
+
+               if ( $status->successCount == 0 ) {
+                       $status->ok = false;
+                       $dbw->rollback();
+                       return $status;
+               }
+
+               // Save success count 
+               $successCount = $status->successCount;
+
+               // Move files, if there are any
+               $status->merge( $this->doPreCommitUpdates() );
+               if ( !$status->isOK() ) {
+                       // Fatal error, such as no configured archive directory
+                       $dbw->rollback();
+                       return $status;
+               }
+
+               // Log it
+               $this->updateLog( array(
+                       'title' => $this->title, 
+                       'count' => $successCount, 
+                       'newBits' => $newBits, 
+                       'oldBits' => $oldBits,
+                       'comment' => $comment,
+                       'ids' => $idsForLog,
+               ) );
+               $dbw->commit();
+
+               // Clear caches
+               $status->merge( $this->doPostCommitUpdates() );
+               return $status;
+       }
+
        /**
         * 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
+        * @param $params Associative array of parameters:
+        *     newBits:         The new value of the *_deleted bitfield
+        *     oldBits:         The old value of the *_deleted bitfield. 
+        *     title:           The target title
+        *     ids:             The ID list
+        *     comment:         The log comment
         */
-       protected function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
-               $param, $items = array() )
-       {
+       protected function updateLog( $params ) {
                // Get the URL param's corresponding DB field
-               if( !($field = self::getRelationType($param)) )
+               $field = RevisionDeleter::getRelationType( $this->getType() );
+               if( !$field ) {
                        throw new MWException( "Bad log URL param type!" );
+               }
                // Put things hidden from sysops in the oversight log
-               $logType = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ?
-                       'suppress' : 'delete';
-               // Log deletions show with a difference action message
-               $logAction = ( $param == 'logid' ) ? 'event' : 'revision';
-               // Track what items changed here
-               $itemCSV = implode(',',$items);
-               // Add params for effected page and ids
-               if( $param == 'logid' ) {
-                       $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
+               if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
+                       $logType = 'suppress';
                } else {
-                       $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
+                       $logType = 'delete';
                }
+               // Add params for effected page and ids
+               $logParams = $this->getLogParams( $params );
                // Actually add the deletion log entry
                $log = new LogPage( $logType );
-               $logid = $log->addEntry( $logAction, $title, $comment, $params );
+               $logid = $log->addEntry( $this->getLogAction(), $params['title'], $params['comment'], $logParams );
                // Allow for easy searching of deletion log items for revision/log items
-               $log->addRelations( $field, $items, $logid );
+               $log->addRelations( $field, $params['ids'], $logid );
+       }
+
+       /**
+        * Get the log action for this list type
+        */
+       public function getLogAction() {
+               return 'revision';
+       }
+
+       /**
+        * Get log parameter array.
+        * @param $params Associative array of log parameters, same as updateLog()
+        * @return array
+        */
+       public function getLogParams( $params ) {
+               return array(
+                       $this->getType(),
+                       implode( ',', $params['ids'] ),
+                       "ofield={$params['oldBits']}",
+                       "nfield={$params['newBits']}"
+               );
+       }
+
+       /**
+        * Initialise the current iteration pointer
+        */
+       protected function initCurrent() {
+               $row = $this->res->current();
+               if ( $row ) {
+                       $this->current = $this->newItem( $row );
+               } else {
+                       $this->current = false;
+               }
+       }
+
+       /**
+        * Start iteration. This must be called before current() or next(). 
+        * @return First list item
+        */
+       public function reset() {
+               if ( !$this->res ) {
+                       $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
+               } else {
+                       $this->res->rewind();
+               }
+               $this->initCurrent();
+               return $this->current;
+       }
+
+       /**
+        * Get the current list item, or false if we are at the end
+        */
+       public function current() {
+               return $this->current;
+       }
+
+       /**
+        * Move the iteration pointer to the next list item, and return it.
+        */
+       public function next() {
+               $this->res->next();
+               $this->initCurrent();
+               return $this->current;
+       }
+
+       /**
+        * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
+        * STUB
+        */
+       public function clearFileOps() {
+       }
+
+       /** 
+        * A hook for setVisibility(): do batch updates pre-commit.
+        * STUB
+        * @return Status
+        */
+       public function doPreCommitUpdates() {
+               return Status::newGood();
+       }
+
+       /**
+        * A hook for setVisibility(): do any necessary updates post-commit. 
+        * STUB
+        * @return Status 
+        */
+       public function doPostCommitUpdates() {
+               return Status::newGood();
+       }
+
+       /**
+        * Create an item object from a DB result row
+        * @param $row stdclass
+        */
+       abstract public function newItem( $row );
+
+       /**
+        * Do the DB query to iterate through the objects.
+        * @param $db Database object to use for the query
+        */
+       abstract public function doQuery( $db );
+
+       /**
+        * Get the integer value of the flag used for suppression
+        */
+       abstract public function getSuppressBit();
+}
+
+/**
+ * Abstract base class for deletable items
+ */
+abstract class RevDel_Item {
+       /** The parent SpecialPage */
+       var $special;
+
+       /** The parent RevDel_List */
+       var $list;
+
+       /** The DB result row */
+       var $row;
+
+       /** 
+        * @param $list RevDel_List
+        * @param $row DB result row
+        */
+       public function __construct( $list, $row ) {
+               $this->special = $list->special;
+               $this->list = $list;
+               $this->row = $row;
+       }
+
+       /**
+        * Get the ID, as it would appear in the ids URL parameter
+        */
+       public function getId() {
+               $field = $this->list->getIdField();
+               return $this->row->$field;
+       }
+
+       /**
+        * Get the timestamp, formatted with $wgLang
+        */
+       public function formatDateTime() {
+               global $wgLang;
+               return $wgLang->timeanddate( $this->getTimestamp() );
+       }
+
+       /**
+        * Get the timestamp in MW 14-char form
+        */
+       public function getTimestamp() {
+               $field = $this->list->getTimestampField();
+               return wfTimestamp( TS_MW, $this->row->$field );
+       }
+
+       /** 
+        * Returns true if the item is "current" and can't be deleted for that reason
+        * STUB
+        */
+       public function isCurrent() {
+               return false;
+       }
+
+       /**
+        * Returns true if the current user can view the item
+        */
+       abstract public function canView();
+
+       /**
+        * Get the current deletion bitfield value
+        */
+       abstract public function getBits();
+
+       /**
+        * Get the HTML of the list item. Should be include <li></li> tags.
+        * This is used to show the list in HTML form, by the special page.
+        */
+       abstract public function getHTML();
+
+       /**
+        * Set the visibility of the item. This should do any necessary DB queries.
+        *
+        * The DB update query should have a condition which forces it to only update
+        * if the value in the DB matches the value fetched earlier with the SELECT. 
+        * If the update fails because it did not match, the function should return 
+        * false. This prevents concurrency problems.
+        *
+        * @return boolean success
+        */
+       abstract public function setBits( $newBits );
+}
+
+/**
+ * List for revision table items
+ */
+class RevDel_RevisionList extends RevDel_List {
+       var $currentRevId;
+       var $type = 'revision';
+       var $idField = 'rev_id';
+       var $dateField = 'rev_timestamp';
+
+       public function doQuery( $db ) {
+               $ids = array_map( 'intval', $this->ids );
+               return $db->select( array('revision','page'), '*',
+                       array(
+                               'rev_page' => $this->title->getArticleID(),
+                               'rev_id'   => $ids,
+                               'rev_page = page_id'
+                       ),
+                       __METHOD__
+               );
+       }
+
+       public function newItem( $row ) {
+               return new RevDel_RevisionItem( $this, $row );
+       }
+
+       public function getCurrent() {
+               if ( is_null( $this->currentRevId ) ) {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $this->currentRevId = $dbw->selectField( 
+                               'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
+               }
+               return $this->currentRevId;
+       }
+
+       public function getSuppressBit() {
+               return Revision::DELETED_RESTRICTED;
+       }
+
+       public function doPreCommitUpdates() {
+               $this->title->invalidateCache();
+               return Status::newGood();
+       }
+
+       public function doPostCommitUpdates() {
+               $this->title->purgeSquid();
+               // Extensions that require referencing previous revisions may need this
+               wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title ) );
+               return Status::newGood();
+       }
+}
+
+/**
+ * Item class for a revision table row
+ */
+class RevDel_RevisionItem extends RevDel_Item {
+       var $revision;
+
+       public function __construct( $list, $row ) {
+               parent::__construct( $list, $row );
+               $this->revision = new Revision( $row );
+       }
+
+       public function canView() {
+               return $this->revision->userCan( Revision::DELETED_RESTRICTED );
+       }
+
+       public function getBits() {
+               return $this->revision->mDeleted;
+       }
+
+       public function setBits( $bits ) {
+               $dbw = wfGetDB( DB_MASTER );
+               // Update revision table
+               $dbw->update( 'revision',
+                       array( 'rev_deleted' => $bits ),
+                       array( 
+                               'rev_id' => $this->revision->getId(), 
+                               'rev_page' => $this->revision->getPage(),
+                               'rev_deleted' => $this->getBits()
+                       ),
+                       __METHOD__
+               );
+               if ( !$dbw->affectedRows() ) {
+                       // Concurrent fail!
+                       return false;
+               }
+               // Update recentchanges table
+               $dbw->update( 'recentchanges',
+                       array( 
+                               'rc_deleted' => $bits,
+                               'rc_patrolled' => 1
+                       ),
+                       array(
+                               'rc_this_oldid' => $this->revision->getId(), // condition
+                               'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ), // non-unique index
+                       ),
+                       __METHOD__
+               );
+               return true;
+       }
+
+       public function isDeleted() {
+               return $this->revision->isDeleted( Revision::DELETED_TEXT );
+       }
+
+       public function isCurrent() {
+               return $this->list->getCurrent() == $this->getId();
+       }
+
+       /**
+        * Get the HTML link to the revision text.
+        * Overridden by RevDel_ArchiveItem.
+        */
+       protected function getRevisionLink() {
+               global $wgLang;
+               $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
+               if ( $this->isDeleted() && !$this->canView() ) {
+                       return $date;
+               }
+               return $this->special->skin->makeLinkObj( $this->list->title, $date, 
+                       'oldid='.$this->revision->getId() . '&unhide=1' );
+       }
+
+       /**
+        * Get the HTML link to the diff.
+        * Overridden by RevDel_ArchiveItem
+        */
+       protected function getDiffLink() {
+               if ( $this->isDeleted() && !$this->canView() ) {
+                       return wfMsgHtml('diff');
+               } else {
+                       return 
+                               $this->special->skin->makeKnownLinkObj( 
+                                       $this->list->title, 
+                                       wfMsgHtml('diff'),
+                                       'diff=' . $this->revision->getId() . '&oldid=prev&unhide=1' 
+                               );
+               }
+       }
+
+       public function getHTML() {
+               $difflink = $this->getDiffLink();
+               $revlink = $this->getRevisionLink();
+               $userlink = $this->special->skin->revUserLink( $this->revision );
+               $comment = $this->special->skin->revComment( $this->revision );
+               if ( $this->isDeleted() ) {
+                       $revlink = "<span class=\"history-deleted\">$revlink</span>";
+               }
+               return "<li>($difflink) $revlink $userlink $comment</li>";
+       }
+}
+
+/**
+ * List for archive table items, i.e. revisions deleted via action=delete
+ */
+class RevDel_ArchiveList extends RevDel_RevisionList {
+       var $type = 'archive';
+       var $idField = 'ar_timestamp';
+       var $dateField = 'ar_timestamp';
+
+       public function doQuery( $db ) {
+               $timestamps = array();
+               foreach ( $this->ids as $id ) {
+                       $timestamps[] = $db->timestamp( $id );
+               }
+               return $db->select( 'archive', '*',
+                               array(
+                                       'ar_namespace' => $this->title->getNamespace(),
+                                       'ar_title'     => $this->title->getDBkey(),
+                                       'ar_timestamp' => $timestamps
+                               ),
+                               __METHOD__
+                       );
+       }
+
+       public function newItem( $row ) {
+               return new RevDel_ArchiveItem( $this, $row );
+       }
+
+       public function doPreCommitUpdates() {
+               return Status::newGood();
+       }
+
+       public function doPostCommitUpdates() {
+               return Status::newGood();
+       }
+}
+
+/**
+ * Item class for a archive table row
+ */
+class RevDel_ArchiveItem extends RevDel_RevisionItem {
+       public function __construct( $list, $row ) {
+               RevDel_Item::__construct( $list, $row );
+               $this->revision = Revision::newFromArchiveRow( $row,
+                       array( 'page' => $this->list->title->getArticleId() ) );
+       }
+
+       public function getId() {
+               # Convert DB timestamp to MW timestamp
+               return $this->revision->getTimestamp();
        }
        
-       // Get DB field name for URL param...
-       // Future code for other things may also track
-       // other types of revision-specific changes.
-       public static function getRelationType( $param ) {
-               switch( $param ) {
-                       case 'oldid':
-                               return 'rev_id';
-                       case 'artimestamp':
-                               return 'rev_timestamp';
-                       case 'oldimage':
-                               return 'oi_timestamp';
-                       case 'fileid':
-                               return 'file_id';
-                       case 'logid':
-                               return 'log_id';
+       public function setBits( $bits ) {
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->update( 'archive',
+                       array( 'ar_deleted' => $bits ),
+                       array( 'ar_namespace' => $this->list->title->getNamespace(),
+                               'ar_title'     => $this->list->title->getDBkey(),
+                               // use timestamp for index
+                               'ar_timestamp' => $this->row->ar_timestamp,
+                               'ar_rev_id'    => $this->row->ar_rev_id,
+                               'ar_deleted' => $this->getBits()
+                       ),
+                       __METHOD__ );
+               return (bool)$dbw->affectedRows();
+       }
+
+       protected function getRevisionLink() {
+               global $wgLang;
+               $undelete = SpecialPage::getTitleFor( 'Undelete' );
+               $date = $wgLang->timeanddate( $this->revision->getTimestamp() );
+               if ( $this->isDeleted() && !$this->canView() ) {
+                       return $date;
+               }
+               return $this->special->skin->link( $undelete, $date, array(),
+                       array(
+                               'target' => $this->list->title->getPrefixedText(),
+                               'timestamp' => $this->revision->getTimestamp()
+                       ) );
+       }
+
+       protected function getDiffLink() {
+               if ( $this->isDeleted() && !$this->canView() ) {
+                       return wfMsgHtml( 'diff' );
+               }
+               $undelete = SpecialPage::getTitleFor( 'Undelete' );             
+               return $this->special->skin->link( $undelete, wfMsgHtml('diff'), array(), 
+                       array(
+                               'target' => $this->list->title->getPrefixedText(),
+                               'diff' => 'prev',
+                               'timestamp' => $this->revision->getTimestamp()
+                       ) );
+       }
+}
+
+/**
+ * List for oldimage table items
+ */
+class RevDel_FileList extends RevDel_List {
+       var $type = 'oldimage';
+       var $idField = 'oi_archive_name';
+       var $dateField = 'oi_timestamp';
+       var $storeBatch, $deleteBatch, $cleanupBatch;
+
+       public function doQuery( $db ) {
+               $archiveName = array();
+               foreach( $this->ids as $timestamp ) {
+                       $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
+               }
+               return $db->select( 'oldimage', '*',
+                       array(
+                               'oi_name'         => $this->title->getDBkey(),
+                               'oi_archive_name' => $archiveNames
+                       ),
+                       __METHOD__
+               );
+       }
+
+       public function newItem( $row ) {
+               return new RevDel_FileItem( $this, $row );
+       }
+
+       public function clearFileOps() {
+               $this->deleteBatch = array();
+               $this->storeBatch = array();
+               $this->cleanupBatch = array();
+       }
+
+       public function doPreCommitUpdates() {
+               $status = Status::newGood();
+               $repo = RepoGroup::singleton()->getLocalRepo();
+               if ( $this->storeBatch ) {
+                       $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
+               }
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+               if ( $this->deleteBatch ) {
+                       $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
+               }
+               if ( !$status->isOK() ) {
+                       // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
+                       // modified (but destined for rollback) causes data loss
+                       return $status;
+               }
+               if ( $this->cleanupBatch ) {
+                       $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
+               }
+               return $status;
+       }
+
+       public function doPostCommitUpdates() {
+               $file = wfLocalFile( $this->title );
+               $file->purgeCache();
+               $file->purgeDescription();
+               return Status::newGood();
+       }
+
+       public function getSuppressBit() {
+               return File::DELETED_RESTRICTED;
+       }
+}
+
+/**
+ * Item class for an oldimage table row
+ */
+class RevDel_FileItem extends RevDel_Item {
+       var $file;
+
+       public function __construct( $list, $row ) {
+               parent::__construct( $list, $row );
+               $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
+       }
+
+       public function getId() {
+               $parts = explode( '!', $this->row->oi_archive_name );
+               return $parts[0];
+       }
+
+       public function canView() {
+               return $this->file->userCan( File::DELETED_RESTRICTED );
+       }
+
+       public function getBits() {
+               /** FIXME: use accessor */
+               return $this->file->deleted;
+       }
+
+       public function setBits( $bits ) {
+               # Queue the file op
+               # FIXME: move to LocalFile.php
+               if ( $this->isDeleted() ) {
+                       if ( $bits & File::DELETED_FILE ) {
+                               # Still deleted
+                       } else {
+                               # Newly undeleted
+                               $key = $this->file->getStorageKey();
+                               $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
+                               $this->list->storeBatch[] = array(
+                                       $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
+                                       'public',
+                                       $this->file->getRel()
+                               );
+                               $this->list->cleanupBatch[] = $key;
+                       }
+               } elseif ( $bits & File::DELETED_FILE ) {
+                       # Newly deleted
+                       $key = $this->file->getStorageKey();
+                       $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
+                       $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel );
+               }
+               
+               # Do the database operations
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->update( 'oldimage',
+                       array( 'oi_deleted' => $bits ),
+                       array( 
+                               'oi_name' => $this->row->oi_name,
+                               'oi_timestamp' => $this->row->oi_timestamp,
+                               'oi_deleted' => $this->getBits()
+                       ),
+                       __METHOD__
+               );
+               return (bool)$dbw->affectedRows();
+       }
+
+       public function isDeleted() {
+               return $this->file->isDeleted( File::DELETED_FILE );
+       }
+
+       /**
+        * Get the link to the file. 
+        * Overridden by RevDel_ArchivedFileItem.
+        */
+       protected function getLink() {
+               global $wgLang;
+               $date = $wgLang->timeanddate( $this->file->getTimestamp(), true  );             
+               if ( $this->isDeleted() ) {
+                       # Hidden files...
+                       if ( !$this->canView() ) {
+                               return $date;
+                       } else {
+                               return $this->special->skin->link( 
+                                       $this->special->getTitle(), 
+                                       $date, array(), 
+                                       array(
+                                               'target' => $this->list->title->getPrefixedText(),
+                                               'file' => $this->file->sha1 . '.' . $this->file->getExtension() 
+                                       )
+                               );
+                       }
+               } else {
+                       # Regular files...
+                       $url = $this->file->getUrl();
+                       return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date );
+               }
+       }
+       /**
+        * Generate a user tool link cluster if the current user is allowed to view it
+        * @return string HTML
+        */
+       protected function getUserTools() {
+               if( $this->file->userCan( Revision::DELETED_USER ) ) {
+                       $link = $this->special->skin->userLink( $this->file->user, $this->file->user_text ) .
+                               $this->special->skin->userToolLinks( $this->file->user, $this->file->user_text );
+               } else {
+                       $link = wfMsgHtml( 'rev-deleted-user' );
+               }
+               if( $this->file->isDeleted( Revision::DELETED_USER ) ) {
+                       return '<span class="history-deleted">' . $link . '</span>';
                }
-               return null; // bad URL type
+               return $link;
+       }
+
+       /**
+        * Wrap and format the file's comment block, if the current
+        * user is allowed to view it.
+        *
+        * @return string HTML
+        */
+       protected function getComment() {
+               if( $this->file->userCan( File::DELETED_COMMENT ) ) {
+                       $block = $this->special->skin->commentBlock( $this->file->description );
+               } else {
+                       $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
+               }
+               if( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
+                       return "<span class=\"history-deleted\">$block</span>";
+               }
+               return $block;
+       }
+
+       public function getHTML() {
+               global $wgLang;
+               $data = 
+                       wfMsg(
+                               'widthheight', 
+                               $wgLang->formatNum( $this->file->getWidth() ),
+                               $wgLang->formatNum( $this->file->getHeight() ) 
+                       ) .
+                       ' (' . 
+                       wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file->getSize() ) ) . 
+                       ')';
+               $pageLink = $this->getLink();
+
+               return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
+                       $data . ' ' . $this->getComment(). '</li>';
+       }
+}
+
+/**
+ * List for filearchive table items
+ */
+class RevDel_ArchivedFileList extends RevDel_FileList {
+       var $type = 'filearchive';
+       var $idField = 'fa_id';
+       var $dateField = 'fa_timestamp';
+       
+       public function doQuery( $db ) {
+               $ids = array_map( 'intval', $this->ids );
+               return $db->select( 'filearchive', '*',
+                       array(
+                               'fa_name' => $this->title->getDBkey(),
+                               'fa_id'   => $ids
+                       ),
+                       __METHOD__
+               );
+       }
+
+       public function newItem( $row ) {
+               return new RevDel_ArchivedFileItem( $this, $row );
+       }
+}
+
+/**
+ * Item class for a filearchive table row
+ */
+class RevDel_ArchivedFileItem extends RevDel_FileItem {
+       public function __construct( $list, $row ) {
+               RevDel_Item::__construct( $list, $row );
+               $this->file = ArchivedFile::newFromRow( $row );
+       }
+
+       public function getId() {
+               return $this->row->fa_id;
+       }
+
+       public function setBits( $bits ) {
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->update( 'filearchive',
+                       array( 'fa_deleted' => $bits ),
+                       array(
+                               'fa_id' => $this->row->fa_id,
+                               'fa_deleted' => $this->getBits(),
+                       ),
+                       __METHOD__
+               );
+               return (bool)$dbw->affectedRows();
+       }
+
+       protected function getLink() {
+               global $wgLang, $wgUser;
+               $date = $wgLang->timeanddate( $this->file->getTimestamp(), true  );
+               $undelete = SpecialPage::getTitleFor( 'Undelete' );
+               $key = $this->file->getKey();
+               return $this->special->skin->link( $undelete, $date, array(),
+                       array(
+                               'target' => $this->list->title->getPrefixedText(),
+                               'file' => $key,
+                               'token' => $wgUser->editToken( $key )
+                       ) );
+       }
+}
+
+/**
+ * List for logging table items
+ */
+class RevDel_LogList extends RevDel_List {
+       var $type = 'logging';
+       var $idField = 'log_id';
+       var $dateField = 'log_timestamp';
+
+       public function doQuery( $db ) {
+               global $wgMessageCache;
+               $wgMessageCache->loadAllMessages();
+               $ids = array_map( 'intval', $this->ids );
+               return $db->select( 'logging', '*',
+                       array( 'log_id' => $ids ),
+                       __METHOD__
+               );
+       }
+
+       public function newItem( $row ) {
+               return new RevDel_LogItem( $this, $row );
+       }
+
+       public function getSuppressBit() {
+               return Revision::DELETED_RESTRICTED;
        }
-}
\ No newline at end of file
+
+       public function getLogAction() {
+               return 'event';
+       }
+
+       public function getLogParams( $params ) {
+               return array(
+                       implode( ',', $params['ids'] ),
+                       "ofield={$params['oldBits']}",
+                       "nfield={$params['newBits']}"
+               );
+       }
+}
+
+/**
+ * Item class for a logging table row
+ */
+class RevDel_LogItem extends RevDel_Item {
+       public function canView() {
+               return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED );
+       }
+
+       public function getBits() {
+               return $this->row->log_deleted;
+       }
+
+       public function setBits( $bits ) {
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->update( 'recentchanges',
+                       array( 
+                               'rc_deleted' => $bits, 
+                               'rc_patrolled' => 1 
+                       ),
+                       array(
+                               'rc_logid' => $this->row->log_id,
+                               'rc_timestamp' => $this->row->log_timestamp
+                       ),
+                       __METHOD__
+               );
+               $dbw->update( 'logging',
+                       array( 'log_deleted' => $bits ),
+                       array(
+                               'log_id' => $this->row->log_id,
+                               'log_deleted' => $this->getBits()
+                       ),
+                       __METHOD__
+               );
+               return (bool)$dbw->affectedRows();
+       }
+
+       public function getHTML() {
+               global $wgLang;
+
+               $date = htmlspecialchars( $wgLang->timeanddate( $this->row->log_timestamp ) );
+               $paramArray = LogPage::extractParams( $this->row->log_params );
+               $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
+
+               $logtitle = SpecialPage::getTitleFor( 'Log' );
+               $loglink = $this->special->skin->link( $logtitle, wfMsgHtml( 'log' ), array(),
+                       array( 'page' => $title->getPrefixedUrl() ) );
+               // Action text
+               if( !$this->canView() ) {
+                       $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
+               } else {
+                       $action = LogPage::actionText( $this->row->log_type, $this->row->log_action, $title,
+                               $this->special->skin, $paramArray, true, true );
+                       if( $this->row->log_deleted & LogPage::DELETED_ACTION )
+                               $action = '<span class="history-deleted">' . $action . '</span>';
+               }
+               // User links
+               $userLink = $this->special->skin->userLink( 
+                       $this->row->log_user, User::WhoIs( $this->row->log_user ) );
+               if( LogEventsList::isDeleted($this->row,LogPage::DELETED_USER) ) {
+                       $userLink = '<span class="history-deleted">' . $userLink . '</span>';
+               }
+               // Comment
+               $comment = $wgLang->getDirMark() . $this->special->skin->commentBlock( $this->row->log_comment );
+               if( LogEventsList::isDeleted($this->row,LogPage::DELETED_COMMENT) ) {
+                       $comment = '<span class="history-deleted">' . $comment . '</span>';
+               }
+               return "<li>($loglink) $date $userLink $action $comment</li>";
+       }
+}
index fba8d99..074a4bd 100644 (file)
@@ -188,20 +188,7 @@ class PageArchive {
                               'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
                        __METHOD__ );
                if( $row ) {
-                       return new Revision( array(
-                               'page'       => $this->title->getArticleId(),
-                               'id'         => $row->ar_rev_id,
-                               'text'       => ($row->ar_text_id
-                                       ? null
-                                       : Revision::getRevisionText( $row, 'ar_' ) ),
-                               'comment'    => $row->ar_comment,
-                               'user'       => $row->ar_user,
-                               'user_text'  => $row->ar_user_text,
-                               'timestamp'  => $row->ar_timestamp,
-                               'minor_edit' => $row->ar_minor_edit,
-                               'text_id'    => $row->ar_text_id,
-                               'deleted'    => $row->ar_deleted,
-                               'len'        => $row->ar_len) );
+                       return Revision::newFromArchiveRow( $row, array( 'page' => $this->title->getArticleId() ) );
                } else {
                        return null;
                }
@@ -475,37 +462,18 @@ class PageArchive {
                $restored = 0;
 
                while( $row = $ret->fetchObject() ) {
-                       if( $row->ar_text_id ) {
-                               // Revision was deleted in 1.5+; text is in
-                               // the regular text table, use the reference.
-                               // Specify null here so the so the text is
-                               // dereferenced for page length info if needed.
-                               $revText = null;
-                       } else {
-                               // Revision was deleted in 1.4 or earlier.
-                               // Text is squashed into the archive row, and
-                               // a new text table entry will be created for it.
-                               $revText = Revision::getRevisionText( $row, 'ar_' );
-                       }
                        // Check for key dupes due to shitty archive integrity.
                        if( $row->ar_rev_id ) {
                                $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
                                if( $exists ) continue; // don't throw DB errors
                        }
-                       
-                       $revision = new Revision( array(
-                               'page'       => $pageId,
-                               'id'         => $row->ar_rev_id,
-                               'text'       => $revText,
-                               'comment'    => $row->ar_comment,
-                               'user'       => $row->ar_user,
-                               'user_text'  => $row->ar_user_text,
-                               'timestamp'  => $row->ar_timestamp,
-                               'minor_edit' => $row->ar_minor_edit,
-                               'text_id'    => $row->ar_text_id,
-                               'deleted'        => $unsuppress ? 0 : $row->ar_deleted,
-                               'len'        => $row->ar_len
+
+                       $revision = Revision::newFromArchiveRow( $row, 
+                               array( 
+                                       'page' => $pageId, 
+                                       'deleted' => $unsuppress ? 0 : $row->ar_deleted
                                ) );
+                       
                        $revision->insertOn( $dbw );
                        $restored++;
 
@@ -527,16 +495,18 @@ class PageArchive {
                        // Attach the latest revision to the page...
                        $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
                        if( $newid || $wasnew ) {
-                               // Update site stats, link tables, etc
-                               $article->createUpdates( $revision );
                                // We don't handle well with top revision deleted
+                               // FIXME: any sysop can unsuppress any revision by just undeleting it into a non-existent page!
                                if( $revision->getVisibility() ) {
                                        $dbw->update( 'revision', 
                                                array( 'rev_deleted' => 0 ),
                                                array( 'rev_id' => $revision->getId() ),
                                                __METHOD__
                                        );
+                                       $revision->mDeleted = 0; // Don't pollute the parser cache
                                }
+                               // Update site stats, link tables, etc
+                               $article->createUpdates( $revision );
                        }
 
                        if( $newid ) {
@@ -883,8 +853,10 @@ class UndeleteForm {
                                        '(' . wfMsgHtml('rev-delundel') . ')' );
                        // Otherwise, show the link...
                        } else {
-                               $query = array( 'target' => $this->mTargetObj->getPrefixedDbkey(),
-                                       'artimestamp' => $rev->getTimestamp() );
+                               $query = array( 
+                                       'type' => 'archive',
+                                       'target' => $this->mTargetObj->getPrefixedDbkey(),
+                                       'ids' => $rev->getTimestamp() );
                                $del = ' ' . $sk->revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
@@ -950,8 +922,11 @@ class UndeleteForm {
                $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
                $wgRequest->response()->header( 'Pragma: no-cache' );
 
-               $store = FileStore::get( 'deleted' );
-               $store->stream( $key );
+               global $IP;
+               require_once( "$IP/includes/StreamFile.php" );
+               $repo = RepoGroup::singleton()->getLocalRepo();         
+               $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
+               wfStreamFile( $path );
        }
 
        private function showHistory( ) {
@@ -1114,16 +1089,8 @@ class UndeleteForm {
        private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
                global $wgUser, $wgLang;
 
-               $rev = new Revision( array(
-                               'page'       => $this->mTargetObj->getArticleId(),
-                               'comment'    => $row->ar_comment,
-                               'user'       => $row->ar_user,
-                               'user_text'  => $row->ar_user_text,
-                               'timestamp'  => $row->ar_timestamp,
-                               'minor_edit' => $row->ar_minor_edit,
-                               'deleted'    => $row->ar_deleted,
-                               'len'        => $row->ar_len ) );
-
+               $rev = Revision::newFromArchiveRow( $row, 
+                       array( 'page' => $this->mTargetObj->getArticleId() ) );
                $stxt = '';
                $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
                if( $this->mAllowed ) {
@@ -1165,8 +1132,10 @@ class UndeleteForm {
                                $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
                                        '('.wfMsgHtml('rev-delundel').')' );
                        } else {
-                               $query = array( 'target' => $this->mTargetObj->getPrefixedDBkey(),
-                                       'artimestamp' => $ts
+                               $query = array(
+                                       'type' => 'archive',
+                                       'target' => $this->mTargetObj->getPrefixedDBkey(),
+                                       'ids' => $ts
                                );
                                $revdlink = $sk->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
@@ -1207,8 +1176,10 @@ class UndeleteForm {
                        // If revision was hidden from sysops
                                $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml('rev-delundel').')' );
                        } else {
-                               $query = array( 'target' => $this->mTargetObj->getPrefixedDBkey(),
-                                       'fileid' => $row->fa_id
+                               $query = array(
+                                       'type' => 'filearchive',
+                                       'target' => $this->mTargetObj->getPrefixedDBkey(),
+                                       'ids' => $row->fa_id
                                );
                                $revdlink = $sk->revDeleteLink( $query, $file->isDeleted( File::DELETED_RESTRICTED ) );
                        }
index fcd19ce..1e4a81a 100644 (file)
@@ -574,7 +574,9 @@ class UploadForm {
                if( !$this->mForReUpload ) {
                        $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
                                $this->mCopyrightStatus, $this->mCopyrightSource );
-               }       
+               } else {
+                       $pageText = false;
+               }
 
                $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
                        File::DELETE_SOURCE, $this->mFileProps );
index 1858d1a..cef8504 100644 (file)
@@ -1284,10 +1284,11 @@ As an administrator you can still [$1 view this diff] if you wish to proceed.",
 function, the specified revision does not exist, or you are attempting to hide the current revision.',
 'revdelete-nologtype-title'      => 'No log type given',
 'revdelete-nologtype-text'       => 'You have not specified a log type to perform this action on.',
-'revdelete-toomanytargets-title' => 'Too many targets',
-'revdelete-toomanytargets-text'  => 'You have specified too many types of targets to perform this action on.',
 'revdelete-nologid-title'        => 'Invalid log entry',
 'revdelete-nologid-text'         => 'You have either not specified a target log event to perform this function or the specified entry does not exist.',
+'revdelete-no-file'              => 'The file specified does not exist.',
+'revdelete-show-file-confirm'    => 'Are you sure you want to view a deleted revision of the file "<nowiki>$1</nowiki>" from $2 at $3?',
+'revdelete-show-file-submit'     => 'Yes',
 'revdelete-selected'             => "'''{{PLURAL:$2|Selected revision|Selected revisions}} of [[:$1]]:'''",
 'logdelete-selected'             => "'''{{PLURAL:$1|Selected log event|Selected log events}}:'''",
 'revdelete-text'                 => "'''Deleted revisions and events will still appear in the page history and logs, but parts of their content will be inaccessible to the public.'''
@@ -1311,8 +1312,11 @@ Please confirm that you intend to do this, that you understand the consequences,
 'revdelete-logentry'             => 'changed revision visibility of [[$1]]',
 'logdelete-logentry'             => 'changed event visibility of [[$1]]',
 'revdelete-success'              => "'''Revision visibility successfully set.'''",
-'revdelete-failure'              => "'''Revision visibility could not be set.'''",
+'revdelete-failure'              => "'''Revision visibility could not be set: '''
+$1",
 'logdelete-success'              => "'''Log visibility successfully set.'''",
+'logdelete-failure'              => "'''Log visibility could not be set: '''
+$1",
 'revdel-restore'                 => 'change visibility',
 'pagehist'                       => 'Page history',
 'deletedhist'                    => 'Deleted history',
@@ -1325,6 +1329,13 @@ Please confirm that you intend to do this, that you understand the consequences,
 'revdelete-unhid'                => 'unhid $1',
 'revdelete-log-message'          => '$1 for $2 {{PLURAL:$2|revision|revisions}}',
 'logdelete-log-message'          => '$1 for $2 {{PLURAL:$2|event|events}}',
+'revdelete-hide-current'         => 'Error hiding the item dated $1: this is the current revision and so can\'t be hidden.',
+'revdelete-show-no-access'       => 'Error showing the item dated $1: this item has been marked "restricted", you do not have access to it.',
+'revdelete-modify-no-access'     => 'Error modifying the item dated $1: this item has been marked "restrited", you do not have access to it.',
+'revdelete-modify-missing'       => 'Error modifying item ID $1: it\'s missing from the database!',
+'revdelete-no-change'            => 'Warning: the item dated $1 already had the requested visibility settings.',
+'revdelete-concurrent-change'    => 'Error modifying the item dated $1: its status appears to have been changed by someone else while we were attempting to modify it. Please check the logs.',
+'revdelete-only-restricted'      => 'You cannot suppress items from view by administrators without also selecting one of the other suppression options.',
 
 # Suppression log
 'suppressionlog'     => 'Suppression log',
@@ -1991,6 +2002,7 @@ A click on a column header changes the sorting.',
 'filehist-dimensions'       => 'Dimensions',
 'filehist-filesize'         => 'File size',
 'filehist-comment'          => 'Comment',
+'filehist-missing'          => 'File missing',
 'imagelinks'                => 'File links',
 'linkstoimage'              => 'The following {{PLURAL:$1|page links|$1 pages link}} to this file:',
 'linkstoimage-more'         => 'More than $1 {{PLURAL:$1|page links|pages link}} to this file.