* (bug 6295) Add a 'revision patching' functionality, where an edit can be undone...
authorAndrew Garrett <werdna@users.mediawiki.org>
Sun, 26 Nov 2006 10:54:01 +0000 (10:54 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Sun, 26 Nov 2006 10:54:01 +0000 (10:54 +0000)
RELEASE-NOTES
includes/DifferenceEngine.php
includes/EditPage.php
languages/messages/MessagesEn.php

index 94450e5..765d626 100644 (file)
@@ -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 ==
 
index 8a6d9c5..fc6d725 100644 (file)
@@ -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 = "<strong><a href='$newLink'>{$this->mPagetitle}</a></strong>"
-                               . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)";
+                               . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)"
+                               . " (<a href='$newUndo'>" . htmlspecialchars( wfMsg( 'editundo' ) ) . "</a>)";
                }
 
                // Load the old revision object
index 28fab28..cd50c7b 100644 (file)
@@ -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 {
index 1b4f657..a429bdc 100644 (file)
@@ -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
 #