From: Andrew Garrett Date: Sun, 26 Nov 2006 10:54:01 +0000 (+0000) Subject: * (bug 6295) Add a 'revision patching' functionality, where an edit can be undone... X-Git-Tag: 1.31.0-rc.0~55078 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=f062b09dc38a0612a92a5dba08dc01746b6f42f2;p=lhc%2Fweb%2Fwiklou.git * (bug 6295) Add a 'revision patching' functionality, where an edit can be undone (with a functionality similar to diff rev1 rev2 | patch -R rev3 -o rev3). This is triggered by including &undo=revid in an edit URL. A link to a URL that will undo a given edit is shown on NEW NON-CURRENT revision headers on diff pages. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 94450e55f8..765d626f88 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -219,6 +219,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN behavior when keys already exist on add (instead of dying with an error...) * Add a hook 'UploadForm:initial' before the upload form is generated, and two member variable for text injection into the form, which can be filled by the hooks. +* (bug 6295) Add a "revision patching" functionality, where an edit can be undone + (with a functionality similar to diff rev1 rev2 | patch -R rev3 -o rev3). + This is triggered by including &undo=revid in an edit URL. A link to a URL + that will undo a given edit is shown on NEW NON-CURRENT revision headers on diff pages. == Languages updated == diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 8a6d9c55cd..fc6d7259f9 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -504,10 +504,12 @@ CONTROL; } else { $newLink = $this->mNewPage->escapeLocalUrl( 'oldid=' . $this->mNewid ); $newEdit = $this->mNewPage->escapeLocalUrl( 'action=edit&oldid=' . $this->mNewid ); + $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undo=' . $this->mNewid ); $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $timestamp ) ); $this->mNewtitle = "{$this->mPagetitle}" - . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")"; + . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")" + . " (" . htmlspecialchars( wfMsg( 'editundo' ) ) . ")"; } // Load the old revision object diff --git a/includes/EditPage.php b/includes/EditPage.php index 28fab28379..cd50c7be53 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -73,6 +73,7 @@ class EditPage { # Get variables from query string :P $section = $wgRequest->getVal( 'section' ); $preload = $wgRequest->getVal( 'preload' ); + $undo = $wgRequest->getVal( 'undo' ); wfProfileIn( __METHOD__ ); @@ -93,8 +94,29 @@ class EditPage { // information. $text = $this->mArticle->getContent(); - - if( $section != '' ) { + + if ( $undo > 0 ) { + #Undoing a specific edit overrides section editing; section-editing + # doesn't work with undoing. + $undorev = Revision::newFromId($undo); + $oldrev = $undorev->getPrevious(); + + #Sanity check, make sure it's the right page. + # Otherwise, $text will be left as-is. + if ($undorev->getPage() == $this->mArticle->getID()) { + $undorev_text = $undorev->getText(); + $oldrev_text = $oldrev->getText(); + $currev_text = $text; + + $result = wfMerge($undorev_text, $oldrev_text, $currev_text, &$text); + + if (!$result) { + #Undoing failed. Bailing out with regular revision text. + $text = $currev_text; + } + } + } + else if( $section != '' ) { if( $section == 'new' ) { $text = $this->getPreloadedText( $preload ); } else { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 1b4f6574a5..a429bdc174 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1082,6 +1082,7 @@ is placed by the site operators.", 'selectnewerversionfordiff' => 'Select a newer version for comparison', 'selectolderversionfordiff' => 'Select an older version for comparison', 'compareselectedversions' => 'Compare selected versions', +'editundo' => 'undo', # Search results #