follow up for edit conflicts
[lhc/web/wiklou.git] / includes / EditPage.php
index e4759fa..88afb66 100644 (file)
@@ -1468,15 +1468,16 @@ class EditPage {
                                $this->isConflict = true;
                                $content = $textbox_content; // do not try to merge here!
                        } elseif ( $this->isConflict ) {
+                               $contentObj = $content;
                                # 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 = '';
-                                       $this->textbox1 = ContentHandler::getContentText( $content );
+                                       $this->textbox1 = ContentHandler::getContentText( $contentObj );
                                        wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
                                }
                        }
@@ -1660,15 +1661,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;
        }
 
        /**