From: Brad Jorsch Date: Sun, 8 Dec 2013 15:14:20 +0000 (-0500) Subject: Detect already-undone edits for undo X-Git-Tag: 1.31.0-rc.0~17024^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=5073379d35df694574cd5be8201f8627bb2329a9;p=lhc%2Fweb%2Fwiklou.git Detect already-undone edits for undo 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 --- diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index cd602a1d58..e9ac0246d8 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -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 diff --git a/includes/EditPage.php b/includes/EditPage.php index fbfe3ededf..9a27d23d21 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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( "
" . wfMessage( 'undo-' . $undoMsg )->plain() . '
', true, /* interface */true ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 5d42c83148..fa0a354e8d 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index d75c838062..aa7d656f64 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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 diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index fd23ea15a8..f9eb6754d0 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -796,6 +796,7 @@ $wgMessageStructure = array( 'undo-success', 'undo-failure', 'undo-norev', + 'undo-nochange', 'undo-summary', 'undo-summary-username-hidden', ),