From a5e10a4cbcced463855eb2291e7e65c0b584349d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 12 Mar 2005 12:50:43 +0000 Subject: [PATCH] Get rollback working on new schema --- includes/Article.php | 60 ++++++++++++++++++++++++------------------- includes/Revision.php | 7 +++++ 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index c9be37a064..c885c59982 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1684,70 +1684,76 @@ class Article { $n = $this->mTitle->getNamespace(); # Get the last editor, lock table exclusively - $s = $dbw->selectRow( array( 'page', 'revision' ), - array( 'page_id','rev_user','rev_user_text','rev_comment' ), - array( 'page_title' => $tt, 'page_namespace' => $n ), - $fname, 'FOR UPDATE' - ); - if( $s === false ) { - # Something wrong + $dbw->begin(); + $current = Revision::newFromTitle( $this->mTitle ); + if( is_null( $current ) ) { + # Something wrong... no page? + $dbw->rollback(); $wgOut->addHTML( wfMsg( 'notanarticle' ) ); return; } - $ut = $dbw->strencode( $s->cur_user_text ); - $uid = $s->rev_user; - $pid = $s->page_id; $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) ); - if( $from != $s->rev_user_text ) { + if( $from != $current->getUserText() ) { $wgOut->setPageTitle(wfmsg('rollbackfailed')); $wgOut->addWikiText( wfMsg( 'alreadyrolled', htmlspecialchars( $this->mTitle->getPrefixedText()), htmlspecialchars( $from ), - htmlspecialchars( $s->rev_user_text ) ) ); - if($s->rev_comment != '') { + htmlspecialchars( $current->getUserText() ) ) ); + if( $current->getComment() != '') { $wgOut->addHTML( - wfMsg('editcomment', - htmlspecialchars( $s->rev_comment ) ) ); + wfMsg( 'editcomment', + htmlspecialchars( $current->getComment() ) ) ); } return; } # Get the last edit not by this guy - $s = $dbw->selectRow( 'old', - array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ), + $user = IntVal( $current->getUser() ); + $user_text = $dbw->addQuotes( $current->getUserText() ); + $s = $dbw->selectRow( 'revision', + array( 'rev_id', 'rev_timestamp' ), array( - 'old_namespace' => $n, - 'old_title' => $tt, - "old_user <> {$uid} OR old_user_text <> '{$ut}'" - ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' ) - ); + 'rev_page' => $current->getPage(), + "rev_user <> {$user} OR rev_user_text <> {$user_text}" + ), $fname, + array( + 'USE INDEX' => 'page_timestamp', + 'ORDER BY' => 'rev_timestamp DESC' ) + ); if( $s === false ) { # Something wrong + $dbw->rollback(); $wgOut->setPageTitle(wfMsg('rollbackfailed')); $wgOut->addHTML( wfMsg( 'cantrollback' ) ); return; } - + if ( $bot ) { # Mark all reverted edits as bot $dbw->update( 'recentchanges', array( /* SET */ 'rc_bot' => 1 ), array( /* WHERE */ - 'rc_user' => $uid, - "rc_timestamp > '{$s->old_timestamp}'", + 'rc_cur_id' => $current->getPage(), + 'rc_user_text' => $current->getUserText(), + "rc_timestamp > '{$s->rev_timestamp}'", ), $fname ); } # Save it! - $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from ); + $target = Revision::newFromId( $s->rev_id ); + $newcomment = wfMsg( 'revertpage', $target->getUserText(), $from ); + $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addHTML( '

' . htmlspecialchars( $newcomment ) . "

\n
\n" ); - $this->updateArticle( Revision::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot ); + + $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot ); Article::onArticleEdit( $this->mTitle ); + + $dbw->commit(); $wgOut->returnToMain( false ); } diff --git a/includes/Revision.php b/includes/Revision.php index 30f0e65539..6b099ff054 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -210,6 +210,13 @@ class Revision { return $this->mTitle; } + /** + * @return int + */ + function getPage() { + return $this->mPage; + } + /** * @return int */ -- 2.20.1