From: Aaron Schulz Date: Fri, 24 Jul 2009 12:21:41 +0000 (+0000) Subject: (bug 19905) Clean up revdelete/restore interaction X-Git-Tag: 1.31.0-rc.0~40745 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=f0d05ddbc38be3e2e662fa3ee0ed12ad468e9ba2;p=lhc%2Fweb%2Fwiklou.git (bug 19905) Clean up revdelete/restore interaction --- diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index f7b62cda26..d6f6d74631 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -386,13 +386,14 @@ class PageArchive { # Does this page already exist? We'll have to update it... $article = new Article( $this->title ); - $options = 'FOR UPDATE'; + $options = 'FOR UPDATE'; // lock page $page = $dbw->selectRow( 'page', array( 'page_id', 'page_latest' ), array( 'page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey() ), __METHOD__, - $options ); + $options + ); if( $page ) { $makepage = false; # Page already exists. Import the history, and if necessary @@ -449,13 +450,34 @@ class PageArchive { $oldones ), __METHOD__, /* options */ array( 'ORDER BY' => 'ar_timestamp' ) - ); + ); $ret = $dbw->resultObject( $result ); $rev_count = $dbw->numRows( $result ); + if( !$rev_count ) { + wfDebug( __METHOD__.": no revisions to restore\n" ); + return false; // ??? + } + + $ret->seek( $rev_count - 1 ); // move to last + $row = $ret->fetchObject(); // get newest archived rev + $ret->seek( 0 ); // move back if( $makepage ) { + // Check the state of the newest to-be version... + if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) { + return false; // we can't leave the current revision like this! + } + // Safe to insert now... $newid = $article->insertOn( $dbw ); $pageId = $newid; + } else { + // Check if a deleted revision will become the current revision... + if( $row->ar_timestamp > $previousTimestamp ) { + // Check the state of the newest to-be version... + if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) { + return false; // we can't leave the current revision like this! + } + } } $revision = null; @@ -467,7 +489,8 @@ class PageArchive { $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ ); if( $exists ) continue; // don't throw DB errors } - + // Insert one revision at a time...maintaining deletion status + // unless we are specifically removing all restrictions... $revision = Revision::newFromArchiveRow( $row, array( 'page' => $pageId, @@ -495,16 +518,6 @@ class PageArchive { // Attach the latest revision to the page... $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId ); if( $newid || $wasnew ) { - // 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 ); }