* (bug 2548) Keep summary on 'show changes' of section edit
[lhc/web/wiklou.git] / includes / EditPage.php
index 1291a4c..1b53ba1 100644 (file)
@@ -381,7 +381,8 @@ class EditPage {
                        $userid = $wgUser->getID();
 
                        if ( $isConflict) {
-                               wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime'\n" );
+                               wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
+                                       $this->mArticle->getTimestamp() . "'\n" );
                                $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
                                        $this->section, $this->textbox1, $this->summary, $this->edittime);
                        }
@@ -393,6 +394,7 @@ class EditPage {
                        # Suppress edit conflict with self
 
                        if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
+                               wfDebug( "Suppressing edit conflict, same user.\n" );
                                $isConflict = false;
                        } else {
                                # switch from section editing to normal editing in edit conflict
@@ -401,9 +403,11 @@ class EditPage {
                                        if( $this->mergeChangesInto( $text ) ){
                                                // Successful merge! Maybe we should tell the user the good news?
                                                $isConflict = false;
+                                               wfDebug( "Suppressing edit conflict, successful merge.\n" );
                                        } else {
                                                $this->section = '';
                                                $this->textbox1 = $text;
+                                               wfDebug( "Keeping edit conflict, failed merge.\n" );
                                        }
                                }
                        }
@@ -475,7 +479,7 @@ class EditPage {
                                } else {
                                        $s = wfMsg('editingsection', $this->mTitle->getPrefixedText() );
                                }
-                               if(!$this->preview) {
+                               if( !$this->preview && !$this->diff ) {
                                        preg_match( "/^(=+)(.+)\\1/mi",
                                                $this->textbox1,
                                                $matches );
@@ -491,7 +495,9 @@ class EditPage {
                                $this->mArticle->setOldSubtitle();
                                $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
                        }
-                       if ( $this->oldid ) {
+                       if ( isset( $this->mArticle )
+                            && isset( $this->mArticle->mRevision )
+                            && !$this->mArticle->mRevision->isCurrent() ) {
                                $this->mArticle->setOldSubtitle();
                                $wgOut->addWikiText( wfMsg( 'editingold' ) );
                        }
@@ -875,16 +881,27 @@ END
         * @access private
         * @todo document
         */
-       function mergeChangesInto( &$text ){
-               $yourtext = $this->mArticle->fetchRevisionText();
-               
+       function mergeChangesInto( &$editText ){
                $db =& wfGetDB( DB_MASTER );
-               $oldText = $this->mArticle->fetchRevisionText(
-                       $db->timestamp( $this->edittime ),
-                       'rev_timestamp' );
                
-               if(wfMerge($oldText, $text, $yourtext, $result)){
-                       $text = $result;
+               // This is the revision the editor started from
+               $baseRevision = Revision::loadFromTimestamp(
+                       $db, $this->mArticle->mTitle, $this->edittime );
+               if( is_null( $baseRevision ) ) {
+                       return false;
+               }
+               $baseText = $baseRevision->getText();
+
+               // The current state, we want to merge updates into it
+               $currentRevision =  Revision::loadFromTitle(
+                       $db, $this->mArticle->mTitle );
+               if( is_null( $currentRevision ) ) {
+                       return false;
+               }
+               $currentText = $currentRevision->getText();
+               
+               if( wfMerge( $baseText, $editText, $currentText, $result ) ){
+                       $editText = $result;
                        return true;
                } else {
                        return false;
@@ -1085,7 +1102,7 @@ END
         */
        function getDiff() {
                require_once( 'DifferenceEngine.php' );
-               $oldtext = $this->mArticle->getContent( true );
+               $oldtext = $this->mArticle->fetchContent();
                $newtext = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
                $oldtitle = wfMsg( 'currentrev' );