From 814778dcf901891f97889f4b0c3d4341da5683d2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 29 Jun 2005 23:44:03 +0000 Subject: [PATCH] * (bug 2614) Fix section edit links on diff-to-current with oldid set Also fix navigation links on current-with-oldid view. --- RELEASE-NOTES | 2 ++ includes/Article.php | 47 +++++++++++++++++++++++++++++------ includes/DifferenceEngine.php | 9 ++++++- includes/Linker.php | 8 ------ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fb594b3920..bab6f0bf60 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -423,6 +423,8 @@ Various bugfixes, small features, and a few experimental things: * (bug 2548) Keep summary on 'show changes' of section edit * Move center on toc to title part to avoid breaking .toc style usage * HTML sanitizer: correct multiple attributes by keeping last, not first +* (bug 2614) Fix section edit links on diff-to-current with oldid set + Also fix navigation links on current-with-oldid view. === Caveats === diff --git a/includes/Article.php b/includes/Article.php index 054c2e4329..810b058601 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -490,6 +490,14 @@ class Article { return 0; } } + + /** + * Returns true if this article exists in the database. + * @return bool + */ + function exists() { + return $this->getId() != 0; + } /** * Get the view count for this article @@ -533,6 +541,17 @@ class Article { return $titleObj !== NULL; } + /** + * Returns true if the currently-referenced revision is the current edit + * to this page (and it exists). + * @return bool + */ + function isCurrent() { + return $this->exists() && + isset( $this->mRevision ) && + $this->mRevision->isCurrent(); + } + /** * Loads everything except the text * This isn't necessary for all uses, so it's only done if needed. @@ -675,11 +694,11 @@ class Article { } } # Should the parser cache be used? - if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) && $this->getID() ) { - $pcache = true; - } else { - $pcache = false; - } + $pcache = $wgEnableParserCache && + intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 && + $this->exists() && + empty( $oldid ); + wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" ); $outputDone = false; if ( $pcache ) { @@ -750,7 +769,16 @@ class Article { $wgOut->addPrimaryWikiText( $text, $this ); } else { # Display content, don't attempt to save to parser cache + + # Don't show section-edit links on old revisions... this way lies madness. + if( !$this->isCurrent() ) { + $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false ); + } $wgOut->addWikiText( $text ); + + if( !$this->isCurrent() ) { + $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting ); + } } } /* title may have been set from the cache */ @@ -1985,11 +2013,16 @@ class Article { function setOldSubtitle( $oldid=0 ) { global $wgLang, $wgOut, $wgUser; + $current = ( $oldid == $this->mLatest ); $td = $wgLang->timeanddate( $this->mTimestamp, true ); $sk = $wgUser->getSkin(); - $lnk = $sk->makeKnownLinkObj ( $this->mTitle, wfMsg( 'currentrevisionlink' ) ); + $lnk = $current + ? wfMsg( 'currentrevisionlink' ) + : $lnk = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) ); $prevlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid ); - $nextlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid ); + $nextlink = $current + ? wfMsg( 'nextrevision' ) + : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid ); $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink ); $wgOut->setSubtitle( $r ); } diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 42df9675ad..938b64f0bc 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -170,7 +170,7 @@ CONTROL; } $prevlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'previousdiff' ), 'diff=prev&oldid='.$this->mOldid ); - if ( $this->mNewid == 0 ) { + if ( $this->newRev->isCurrent() ) { $nextlink = ''; } else { $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid ); @@ -186,7 +186,14 @@ CONTROL; DifferenceEngine::showDiff( $this->mOldtext, $this->mNewtext, $oldHeader, $newHeader ); $wgOut->addHTML( "

{$this->mPagetitle}

\n" ); + + if( !$this->newRev->isCurrent() ) { + $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false ); + } $wgOut->addWikiText( $this->mNewtext ); + if( !$this->newRev->isCurrent() ) { + $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting ); + } wfProfileOut( $fname ); } diff --git a/includes/Linker.php b/includes/Linker.php index 3feed2d5cd..c174573653 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -790,16 +790,8 @@ class Linker { /** @todo document */ function editSectionLink( $nt, $section ) { - global $wgRequest; global $wgContLang; - if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) { - # Section edit links would be out of sync on an old page. - # But, if we're diffing to the current page, they'll be - # correct. - return ''; - } - $editurl = '§ion='.$section; $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl); -- 2.20.1