* (bug 2614) Fix section edit links on diff-to-current with oldid set
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 29 Jun 2005 23:44:03 +0000 (23:44 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 29 Jun 2005 23:44:03 +0000 (23:44 +0000)
  Also fix navigation links on current-with-oldid view.

RELEASE-NOTES
includes/Article.php
includes/DifferenceEngine.php
includes/Linker.php

index fb594b3..bab6f0b 100644 (file)
@@ -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 ===
index 054c2e4..810b058 100644 (file)
@@ -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 );
        }
index 42df967..938b64f 100644 (file)
@@ -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( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
+
+               if( !$this->newRev->isCurrent() ) {
+                       $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
+               }
                $wgOut->addWikiText( $this->mNewtext );
+               if( !$this->newRev->isCurrent() ) {
+                       $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting );
+               }
 
                wfProfileOut( $fname );
        }
index 3feed2d..c174573 100644 (file)
@@ -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 = '&section='.$section;
                $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);