Merge "Follow-up Ib2b8dfb8 (803abc7): fix a typo in a variable name"
authorReedy <reedy@wikimedia.org>
Sat, 10 Nov 2012 16:15:56 +0000 (16:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 10 Nov 2012 16:15:56 +0000 (16:15 +0000)
includes/Article.php
includes/EditPage.php
includes/Revision.php
tests/phpunit/includes/RevisionStorageTest.php

index 8403bc6..169dd03 100644 (file)
@@ -704,9 +704,8 @@ class Article extends Page {
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
-                                       // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
-                                       $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
-                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
+                                       $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
+                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
 
                                        if ( !$poolArticleView->execute() ) {
                                                $error = $poolArticleView->getError();
index 963b4af..21a100f 100644 (file)
@@ -1473,16 +1473,14 @@ class EditPage {
                                $this->isConflict = true;
                                $content = $textbox_content; // do not try to merge here!
                        } elseif ( $this->isConflict ) {
-                               $contentObj = $content;
                                # Attempt merge
-                               if ( $this->mergeChangesInto( $content ) ) {
+                               if ( $this->mergeChangesIntoContent( $content ) ) {
                                        // Successful merge! Maybe we should tell the user the good news?
                                        $this->isConflict = false;
-                                       $content = $this->toEditContent( $content );
                                        wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
                                } else {
                                        $this->section = '';
-                                       $this->textbox1 = ContentHandler::getContentText( $contentObj );
+                                       $this->textbox1 = ContentHandler::getContentText( $content );
                                        wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
                                }
                        }
@@ -1666,37 +1664,15 @@ class EditPage {
        function mergeChangesInto( &$editText ){
                ContentHandler::deprecated( __METHOD__, "1.21" );
 
-               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();
+               $editContent = $this->toEditContent( $editText );
 
-               $result = '';
-               $editText = $this->toEditText( $editText );
+               $ok = $this->mergeChangesIntoContent( $editContent );
 
-               if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
-                       $editText = $result;
-                       wfProfileOut( __METHOD__ );
+               if ( $ok ) {
+                       $editText = $this->toEditText( $editContent );
                        return true;
-               } else {
-                       wfProfileOut( __METHOD__ );
-                       return false;
                }
+               return false;
        }
 
        /**
index df02b16..fd356e1 100644 (file)
@@ -52,7 +52,7 @@ class Revision implements IDBAccessObject {
        protected $mContentFormat;
 
        /**
-        * @var Content
+        * @var Content|null|bool
         */
        protected $mContent;
 
@@ -982,28 +982,34 @@ class Revision implements IDBAccessObject {
        }
 
        /**
-        * Gets the content object for the revision
+        * Gets the content object for the revision (or null on failure).
+        *
+        * Note that for mutable Content objects, each call to this method will return a
+        * fresh clone.
         *
         * @since 1.21
-        * @return Content
+        * @return Content|null the Revision's content, or null on failure.
         */
        protected function getContentInternal() {
                if( is_null( $this->mContent ) ) {
                        // Revision is immutable. Load on demand:
-
-                       $handler = $this->getContentHandler();
-                       $format = $this->getContentFormat();
-
                        if( is_null( $this->mText ) ) {
-                               // Load text on demand:
                                $this->mText = $this->loadText();
                        }
 
-                       $this->mContent = ( $this->mText === null || $this->mText === false ) ? null
-                               : $handler->unserializeContent( $this->mText, $format );
+                       if ( $this->mText !== null && $this->mText !== false ) {
+                               // Unserialize content
+                               $handler = $this->getContentHandler();
+                               $format = $this->getContentFormat();
+
+                               $this->mContent = $handler->unserializeContent( $this->mText, $format );
+                       } else {
+                               $this->mContent = false; // negative caching!
+                       }
                }
 
-               return $this->mContent->copy(); // NOTE: copy() will return $this for immutable content objects
+               // NOTE: copy() will return $this for immutable content objects
+               return $this->mContent ? $this->mContent->copy() : null;
        }
 
        /**
@@ -1398,7 +1404,11 @@ class Revision implements IDBAccessObject {
         * Lazy-load the revision's text.
         * Currently hardcoded to the 'text' table storage engine.
         *
+<<<<<<< HEAD
         * @return String|boolean the revision text, or false on failure
+=======
+        * @return String|bool the revision's text, or false on failure
+>>>>>>> (Bug 41244) Gracefully handle failure to load text blob.
         */
        protected function loadText() {
                wfProfileIn( __METHOD__ );
index fbaa34c..4fa42f3 100644 (file)
@@ -268,6 +268,25 @@ class RevisionStorageTest extends MediaWikiTestCase {
                $this->assertEquals( 'hello hello.', $rev->getText() );
        }
 
+       /**
+        * @covers Revision::getContent
+        */
+       public function testGetContent_failure()
+       {
+               $rev = new Revision( array(
+                       'page'       =>  $this->the_page->getId(),
+                       'content_model' => $this->the_page->getContentModel(),
+                       'text_id' => 123456789, // not in the test DB
+               ) );
+
+               $this->assertNull( $rev->getContent(),
+                       "getContent() should return null if the revision's text blob could not be loaded." );
+
+               //NOTE: check this twice, once for lazy initialization, and once with the cached value.
+               $this->assertNull( $rev->getContent(),
+                       "getContent() should return null if the revision's text blob could not be loaded." );
+       }
+
        /**
         * @covers Revision::getContent
         */