From 979b570e2de006900dd30f7d1ea900a33bf67253 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 17 Feb 2014 20:24:13 +0100 Subject: [PATCH] Give alreadyrolled error when rollback will be a null edit When a rollback will not create a new version, the rollback should not be success normally. Raise the alreadyrolled error to indicate this situation. This can happen, when the same user already rolled back his edit in the meantime. Change-Id: I953ae1ca79abb37bc44f3f8244a42a34111e6ab8 --- includes/WikiPage.php | 16 ++++++--- tests/phpunit/includes/WikiPageTest.php | 43 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/includes/WikiPage.php b/includes/WikiPage.php index bcd0f69486..3a19777baa 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2991,6 +2991,16 @@ class WikiPage implements Page, IDBAccessObject { return $status->getErrorsArray(); } + // raise error, when the edit is an edit without a new version + if ( empty( $status->value['revision'] ) ) { + $resultDetails = array( 'current' => $current ); + return array( array( 'alreadyrolled', + htmlspecialchars( $this->mTitle->getPrefixedText() ), + htmlspecialchars( $fromP ), + htmlspecialchars( $current->getUserText() ) + ) ); + } + $set = array(); if ( $bot && $guser->isAllowed( 'markbotedits' ) ) { // Mark all reverted edits as bot @@ -3012,11 +3022,7 @@ class WikiPage implements Page, IDBAccessObject { ); } - if ( !empty( $status->value['revision'] ) ) { - $revId = $status->value['revision']->getId(); - } else { - $revId = false; - } + $revId = $status->value['revision']->getId(); wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index 796adf337a..6cf658f40f 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -886,6 +886,49 @@ more stuff $this->assertEquals( "one", $page->getContent()->getNativeData() ); } + /** + * @covers WikiPage::doRollback + */ + public function testDoRollbackFailureSameContent() { + $admin = new User(); + $admin->setName( "Admin" ); + $admin->addGroup( "sysop" ); #XXX: make the test user a sysop... + + $text = "one"; + $page = $this->newPage( "WikiPageTest_testDoRollback" ); + $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ), + "section one", EDIT_NEW, false, $admin ); + $rev1 = $page->getRevision(); + + $user1 = new User(); + $user1->setName( "127.0.1.11" ); + $user1->addGroup( "sysop" ); #XXX: make the test user a sysop... + $text .= "\n\ntwo"; + $page = new WikiPage( $page->getTitle() ); + $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ), + "adding section two", 0, false, $user1 ); + + # now, do a the rollback from the same user was doing the edit before + $resultDetails = array(); + $token = $user1->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null ); + $errors = $page->doRollback( $user1->getName(), "testing revert same user", $token, false, $resultDetails, $admin ); + + $this->assertEquals( array(), $errors, "Rollback failed same user" ); + + # now, try the rollback + $resultDetails = array(); + $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null ); + $errors = $page->doRollback( $user1->getName(), "testing revert", $token, false, $resultDetails, $admin ); + + $this->assertEquals( array( array( 'alreadyrolled', 'WikiPageTest testDoRollback', + '127.0.1.11', 'Admin' ) ), $errors, "Rollback not failed" ); + + $page = new WikiPage( $page->getTitle() ); + $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(), + "rollback did not revert to the correct revision" ); + $this->assertEquals( "one", $page->getContent()->getNativeData() ); + } + public static function provideGetAutosummary() { return array( array( -- 2.20.1