From 4d29f7c88e2f3ee8217171f2eb2fb2592318713e Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Wed, 23 Apr 2008 16:08:16 +0000 Subject: [PATCH] * When undoing an edit, make sure it wasn't deleted. * Show a proper error message for non-existant or deleted revisions when undoing. --- includes/Article.php | 2 +- includes/EditPage.php | 42 +++++++++++++++++-------------- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesHe.php | 1 + maintenance/language/messages.inc | 1 + 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 51d5a82fdf..d458d94723 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -660,7 +660,7 @@ class Article { * This is the default action of the script: just view the page of * the given title. */ - function view() { + function view() { global $wgUser, $wgOut, $wgRequest, $wgContLang; global $wgEnableParserCache, $wgStylePath, $wgParser; global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgArticleRobotPolicies; diff --git a/includes/EditPage.php b/includes/EditPage.php index a4218d5219..8103abfa94 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -153,39 +153,43 @@ class EditPage { $oldrev = $undorev ? $undorev->getPrevious() : null; } - #Sanity check, make sure it's the right page. + # Sanity check, make sure it's the right page, + # the revisions exist and they were not deleted. # Otherwise, $text will be left as-is. - if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle->getID() ) { + if( !is_null( $undorev ) && !is_null( $oldrev ) && + $undorev->getPage() == $oldrev->getPage() && + $undorev->getPage() == $this->mArticle->getID() && + !$undorev->isDeleted( Revision::DELETED_TEXT ) && + !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) { $undorev_text = $undorev->getText(); $oldrev_text = $oldrev->getText(); $currev_text = $text; - #No use doing a merge if it's just a straight revert. if ( $currev_text != $undorev_text ) { - $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text); + $result = wfMerge( $undorev_text, $oldrev_text, $currev_text, $text ); } else { + # No use doing a merge if it's just a straight revert. $text = $oldrev_text; $result = true; } + if( $result ) { + # Inform the user of our success and set an automatic edit summary + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) ); + $firstrev = $oldrev->getNext(); + # If we just undid one rev, use an autosummary + if( $firstrev->mId == $undo ) { + $this->summary = wfMsgForContent('undo-summary', $undo, $undorev->getUserText()); + } + $this->formtype = 'diff'; + } else { + # Warn the user that something went wrong + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); + } } else { // Failed basic sanity checks. // Older revisions may have been removed since the link // was created, or we may simply have got bogus input. - $result = false; - } - - if( $result ) { - # Inform the user of our success and set an automatic edit summary - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) ); - $firstrev = $oldrev->getNext(); - # If we just undid one rev, use an autosummary - if ( $firstrev->mId == $undo ) { - $this->summary = wfMsgForContent('undo-summary', $undo, $undorev->getUserText()); - } - $this->formtype = 'diff'; - } else { - # Warn the user that something went wrong - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-norev' ) ); } } else if( $section != '' ) { if( $section == 'new' ) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 35b1619d5c..fd053ff1f4 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1145,6 +1145,7 @@ It should have less than $2, there are now $1.', # "Undo" feature 'undo-success' => 'The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.', 'undo-failure' => 'The edit could not be undone due to conflicting intermediate edits.', +'undo-norev' => 'The edit could not be undone because it does not exist or was deleted.', 'undo-summary' => 'Undo revision $1 by [[Special:Contributions/$2|$2]] ([[User talk:$2|Talk]])', # Account creation failure diff --git a/languages/messages/MessagesHe.php b/languages/messages/MessagesHe.php index c8936cabf6..542ea258d0 100644 --- a/languages/messages/MessagesHe.php +++ b/languages/messages/MessagesHe.php @@ -923,6 +923,7 @@ $2', # "Undo" feature 'undo-success' => 'ניתן לבטל את העריכה. אנא בידקו את השוואת הגרסאות למטה כדי לוודא שזה מה שאתם רוצים לעשות, ואז שמרו את השינויים למטה כדי לבצע את ביטול העריכה.', 'undo-failure' => 'לא ניתן היה לבטל את העריכה עקב התנגשות עם עריכות מאוחרות יותר.', +'undo-norev' => 'לא ניתן היה לבטל את העריכה כיוון שהיא אינה קיימת או שהיא נמחקה.', 'undo-summary' => 'ביטול גרסה $1 של [[Special:Contributions/$2|$2]] ([[User talk:$2|שיחה]])', # Account creation failure diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 8b4ed22ea6..e61c22a815 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -565,6 +565,7 @@ $wgMessageStructure = array( 'undo' => array( 'undo-success', 'undo-failure', + 'undo-norev', 'undo-summary', ), 'cantcreateaccount' => array( -- 2.20.1