(bug 41352) restore pre-ContentHandler version of mergeChangesInto()
authoraude <aude.wiki@gmail.com>
Wed, 24 Oct 2012 20:28:07 +0000 (20:28 +0000)
committerChad Horohoe <chadh@wikimedia.org>
Wed, 24 Oct 2012 20:34:39 +0000 (16:34 -0400)
New implementation using ContentHandler is buggy and needs repair

Change-Id: I4c2055bed3e660be255621e4d476d7c489f4c371

includes/EditPage.php

index e4759fa..7ebcde0 100644 (file)
@@ -1469,10 +1469,10 @@ class EditPage {
                                $content = $textbox_content; // do not try to merge here!
                        } elseif ( $this->isConflict ) {
                                # Attempt merge
-                               if ( $this->mergeChangesIntoContent( $textbox_content ) ) {
+                               if ( $this->mergeChangesInto( $content ) ) {
                                        // Successful merge! Maybe we should tell the user the good news?
                                        $this->isConflict = false;
-                                       $content = $textbox_content;
+                                       $content = $this->toEditContent( $content );
                                        wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
                                } else {
                                        $this->section = '';
@@ -1660,15 +1660,37 @@ class EditPage {
        function mergeChangesInto( &$editText ){
                ContentHandler::deprecated( __METHOD__, "1.21" );
 
-               $editContent = $this->toEditContent( $editText );
+               wfProfileIn( __METHOD__ );
+
+               $db = wfGetDB( DB_MASTER );
+
+               // This is the revision the editor started from
+               $baseRevision = $this->getBaseRevision();
+               if ( is_null( $baseRevision ) ) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+               $baseText = $baseRevision->getText();
+
+               // The current state, we want to merge updates into it
+               $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
+               if ( is_null( $currentRevision ) ) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+               $currentText = $currentRevision->getText();
 
-               $ok = $this->mergeChangesIntoContent( $editContent );
+               $result = '';
+               $editText = $this->toEditText( $editText );
 
-               if ( $ok ) {
-                       $editText = $this->toEditText( $editContent );
+               if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
+                       $editText = $result;
+                       wfProfileOut( __METHOD__ );
                        return true;
+               } else {
+                       wfProfileOut( __METHOD__ );
+                       return false;
                }
-               return false;
        }
 
        /**