* (bug 4686) Fix regression where ?diff=0&oldid=0 caused fatal error on
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 23 Jan 2006 19:41:03 +0000 (19:41 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 23 Jan 2006 19:41:03 +0000 (19:41 +0000)
  pages with only one revision. Fixes message diff link on first edit.

RELEASE-NOTES
includes/DifferenceEngine.php

index 6687745..c1898e4 100644 (file)
@@ -558,6 +558,8 @@ fully support the editing toolbar, but was found to be too confusing.
 * Fix backup dump text prefetch for XMLReader constant changes in PHP 5.1
 * Suppress useless percentage indicator on output from 7za during dumps
 * (bug 4633) Add (previous 200) (next 200) also above catlinks
+* (bug 4686) Fix regression where ?diff=0&oldid=0 caused fatal error on
+  pages with only one revision. Fixes message diff link on first edit.
 
 
 === Caveats ===
index 3a10e8e..a69c505 100644 (file)
@@ -42,6 +42,7 @@ class DifferenceEngine {
         */
        function DifferenceEngine( $titleObj = null, $old = 0, $new = 0, $rcid = 0 ) {
                $this->mTitle = $titleObj;
+               wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
 
                if ( 'prev' == $new ) {
                        # Show diff between revision $old and the previous one.
@@ -105,15 +106,6 @@ CONTROL;
                        return;
                }
 
-               # mOldid is false if the difference engine is called with a "vague" query for
-               # a diff between a version V and its previous version V' AND the version V
-               # is the first version of that article. In that case, V' does not exist.
-               if ( $this->mOldid === false ) {
-                       $this->showFirstRevision();
-                       wfProfileOut( $fname );
-                       return;
-               }
-
                $t = $this->mTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " .
                  "{$this->mNewid})";
                $mtext = wfMsg( 'missingarticle', "<nowiki>$t</nowiki>" );
@@ -129,6 +121,15 @@ CONTROL;
                        $wgOut->setArticleFlag( true );
                }
 
+               # mOldid is false if the difference engine is called with a "vague" query for
+               # a diff between a version V and its previous version V' AND the version V
+               # is the first version of that article. In that case, V' does not exist.
+               if ( $this->mOldid === false ) {
+                       $this->showFirstRevision();
+                       wfProfileOut( $fname );
+                       return;
+               }
+
                $wgOut->suppressQuickbar();
 
                $oldTitle = $this->mOldPage->getPrefixedText();
@@ -441,8 +442,15 @@ CONTROL;
                if( $this->mOldid ) {
                        $this->mOldRev = Revision::newFromId( $this->mOldid );
                } elseif ( $this->mOldid === 0 ) {
-                       $this->mOldRev = $this->mNewRev->getPrevious();
-                       $this->mOldid = $this->mOldRev->getId();
+                       $rev = $this->mNewRev->getPrevious();
+                       if( $rev ) {
+                               $this->mOldid = $rev->getId();
+                               $this->mOldRev = $rev;
+                       } else {
+                               // No previous revision; mark to show as first-version only.
+                               $this->mOldid = false;
+                               $this->mOldRev = false;
+                       }
                }/* elseif ( $this->mOldid === false ) leave mOldRev false; */
 
                if( is_null( $this->mOldRev ) ) {