Detect already-undone edits for undo
authorBrad Jorsch <bjorsch@wikimedia.org>
Sun, 8 Dec 2013 15:14:20 +0000 (10:14 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 4 Feb 2014 19:47:40 +0000 (14:47 -0500)
When an edit has already been undone by a later edit, the current
behavior of displaying undo-success with an empty diff tends to confuse
users. It seems it would be better to detect this situation and display
a message along the lines of "This edit has already been undone".

Bug: 29762
Change-Id: Ia40a06046a72b0de52a2b75165ca105bbf4e2e6a

RELEASE-NOTES-1.23
includes/EditPage.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index cd602a1..e9ac024 100644 (file)
@@ -117,6 +117,8 @@ production.
 * (bug 56199) Raw option of parser functions must now match complete word,
   to take effect.
 * (bug 60543) Special:PrefixIndex forgot stripprefix=1 for "Next page" link
+* (bug 29762) Undoing an already-undone edit will now display an appropriate
+  message instead of leading the user to make a null edit.
 
 === Web API changes in 1.23 ===
 * (bug 54884) action=parse&prop=categories now indicates hidden and missing
index fbfe3ed..9a27d23 100644 (file)
@@ -892,7 +892,7 @@ class EditPage {
         * @since 1.21
         */
        protected function getContentObject( $def_content = null ) {
-               global $wgOut, $wgRequest;
+               global $wgOut, $wgRequest, $wgUser, $wgContLang;
 
                wfProfileIn( __METHOD__ );
 
@@ -947,34 +947,45 @@ class EditPage {
                                                        # Warn the user that something went wrong
                                                        $undoMsg = 'failure';
                                                } else {
-                                                       # Inform the user of our success and set an automatic edit summary
-                                                       $undoMsg = 'success';
-
-                                                       # If we just undid one rev, use an autosummary
-                                                       $firstrev = $oldrev->getNext();
-                                                       if ( $firstrev && $firstrev->getId() == $undo ) {
-                                                               $userText = $undorev->getUserText();
-                                                               if ( $userText === '' ) {
-                                                                       $undoSummary = wfMessage(
-                                                                               'undo-summary-username-hidden',
-                                                                               $undo
-                                                                       )->inContentLanguage()->text();
-                                                               } else {
-                                                                       $undoSummary = wfMessage(
-                                                                               'undo-summary',
-                                                                               $undo,
-                                                                               $userText
-                                                                       )->inContentLanguage()->text();
+                                                       $oldContent = $this->mArticle->getPage()->getContent( Revision::RAW );
+                                                       $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+                                                       $newContent = $content->preSaveTransform( $this->mTitle, $wgUser, $popts );
+
+                                                       if ( $newContent->equals( $oldContent ) ) {
+                                                               # Tell the user that the undo results in no change,
+                                                               # i.e. the revisions were already undone.
+                                                               $undoMsg = 'nochange';
+                                                               $content = false;
+                                                       } else {
+                                                               # Inform the user of our success and set an automatic edit summary
+                                                               $undoMsg = 'success';
+
+                                                               # If we just undid one rev, use an autosummary
+                                                               $firstrev = $oldrev->getNext();
+                                                               if ( $firstrev && $firstrev->getId() == $undo ) {
+                                                                       $userText = $undorev->getUserText();
+                                                                       if ( $userText === '' ) {
+                                                                               $undoSummary = wfMessage(
+                                                                                       'undo-summary-username-hidden',
+                                                                                       $undo
+                                                                               )->inContentLanguage()->text();
+                                                                       } else {
+                                                                               $undoSummary = wfMessage(
+                                                                                       'undo-summary',
+                                                                                       $undo,
+                                                                                       $userText
+                                                                               )->inContentLanguage()->text();
+                                                                       }
+                                                                       if ( $this->summary === '' ) {
+                                                                               $this->summary = $undoSummary;
+                                                                       } else {
+                                                                               $this->summary = $undoSummary . wfMessage( 'colon-separator' )
+                                                                                       ->inContentLanguage()->text() . $this->summary;
+                                                                       }
+                                                                       $this->undidRev = $undo;
                                                                }
-                                                               if ( $this->summary === '' ) {
-                                                                       $this->summary = $undoSummary;
-                                                               } else {
-                                                                       $this->summary = $undoSummary . wfMessage( 'colon-separator' )
-                                                                               ->inContentLanguage()->text() . $this->summary;
-                                                               }
-                                                               $this->undidRev = $undo;
+                                                               $this->formtype = 'diff';
                                                        }
-                                                       $this->formtype = 'diff';
                                                }
                                        } else {
                                                // Failed basic sanity checks.
@@ -983,7 +994,7 @@ class EditPage {
                                                $undoMsg = 'norev';
                                        }
 
-                                       // Messages: undo-success, undo-failure, undo-norev
+                                       // Messages: undo-success, undo-failure, undo-norev, undo-nochange
                                        $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
                                        $this->editFormPageTop .= $wgOut->parse( "<div class=\"{$class}\">" .
                                                wfMessage( 'undo-' . $undoMsg )->plain() . '</div>', true, /* interface */true );
index 5d42c83..fa0a354 100644 (file)
@@ -1616,6 +1616,7 @@ These arguments have been omitted.",
 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-nochange'                => 'The edit appears to have already been undone.',
 'undo-summary'                 => 'Undo revision $1 by [[Special:Contributions/$2|$2]] ([[User talk:$2|talk]])',
 'undo-summary-username-hidden' => 'Undo revision $1 by a hidden user',
 
index d75c838..aa7d656 100644 (file)
@@ -2300,6 +2300,9 @@ See also:
 {{Identical|Undo}}',
 'undo-norev' => 'Message appears if an attempt to revert an edit by clicking the "undo" link on the page history fails.
 
+{{Identical|Undo}}',
+'undo-nochange' => 'Message appears if an attempt to revert an edit by clicking the "undo" link results in an edit making no change to the current version of the page.
+
 {{Identical|Undo}}',
 'undo-summary' => 'Edit summary for an undo action. Parameters:
 * $1 - revision ID
index fd23ea1..f9eb675 100644 (file)
@@ -796,6 +796,7 @@ $wgMessageStructure = array(
                'undo-success',
                'undo-failure',
                'undo-norev',
+               'undo-nochange',
                'undo-summary',
                'undo-summary-username-hidden',
        ),