From 5185b09395b3b68c6cfe392ad0458c165f690c74 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 23 Jan 2006 19:41:03 +0000 Subject: [PATCH] * (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. --- RELEASE-NOTES | 2 ++ includes/DifferenceEngine.php | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6687745dc3..c1898e4fac 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 3a10e8e62b..a69c505c20 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -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', "$t" ); @@ -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 ) ) { -- 2.20.1