* (bug 1982) Fix loading of old text for section merging on edits.
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 26 Apr 2005 09:52:11 +0000 (09:52 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 26 Apr 2005 09:52:11 +0000 (09:52 +0000)
includes/Article.php
includes/EditPage.php
includes/Revision.php

index 9666c98..8a9ad87 100644 (file)
@@ -957,6 +957,8 @@ class Article {
        /**
         * Fetch and uncompress the text for a given revision.
         * Can ask by rev_id number or timestamp (set $field)
+        * FIXME: This function is broken. Eliminate all uses and remove.
+        * Use Revision class in place.
         */
        function fetchRevisionText( $revId = null, $field = 'rev_id' ) {
                $fname = 'Article::fetchRevisionText';
@@ -986,12 +988,15 @@ class Article {
        
        function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
                $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
-               if( is_null( $edittime ) ) {
-                       $oldtext = $this->fetchRevisionText();
-               } else {
-                       $oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' );
-               }
                if ($section != '') {
+                       if( is_null( $edittime ) ) {
+                               $rev = Revision::newFromTitle( $this->mTitle );
+                       } else {
+                               $dbw =& wfGetDB( DB_MASTER );
+                               $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+                       }
+                       $oldtext = $rev->getText();
+                       
                        if($section=='new') {
                                if($summary) $subject="== {$summary} ==\n\n";
                                $text=$oldtext."\n\n".$subject.$text;
index 1eb87ab..eccf09b 100644 (file)
@@ -365,10 +365,12 @@ class EditPage {
                        $userid = $wgUser->getID();
 
                        if ( $isConflict) {
+                               wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime'\n" );
                                $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
                                        $this->section, $this->textbox1, $this->summary, $this->edittime);
                        }
                        else {
+                               wfDebug( "EditPage::editForm getting section '$this->section'\n" );
                                $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
                                        $this->section, $this->textbox1, $this->summary);
                        }
index 67eb4be..a42ccac 100644 (file)
@@ -36,6 +36,7 @@ class Revision {
         * @param int $id
         * @return Revision
         * @access public
+        * @static
         */
        function &newFromTitle( &$title, $id = 0 ) {
                if( $id ) {
@@ -74,6 +75,27 @@ class Revision {
                               'page_id=rev_page' ) );
        }
        
+       /**
+        * Load the revision for the given title with the given timestamp.
+        * WARNING: Timestamps may in some circumstances not be unique,
+        * so this isn't the best key to use.
+        *
+        * @param Database $db
+        * @param Title $title
+        * @param string $timestamp
+        * @return Revision
+        * @access public
+        * @static
+        */
+       function &loadFromTimestamp( &$db, &$title, $timestamp ) {
+               return Revision::loadFromConds(
+                       $db,
+                       array( 'rev_timestamp'  => $db->timestamp( $timestamp ),
+                              'page_id=rev_page',
+                              'page_namespace' => $title->getNamespace(),
+                              'page_title'     => $title->getDbkey() ) );
+       }
+       
        /**
         * Given a set of conditions, fetch a revision.
         *