fix collapsing problem with templates (templates would be expanded and
authorErik Moeller <erik@users.mediawiki.org>
Wed, 12 May 2004 22:01:25 +0000 (22:01 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Wed, 12 May 2004 22:01:25 +0000 (22:01 +0000)
formatted first and thus cause a duplicate TOC, the internal parser now has
an isMain parameter to specify whether it is called from the main article
text, or from a template.

includes/Article.php
includes/Parser.php

index fcfa05a..71ffb69 100644 (file)
@@ -112,9 +112,10 @@ class Article {
                        # When a page is viewed in collapsed mode, only the intro section and, for
                        # pages with multiple sections, a table of contents are shown.                  
                        if($collapse && $action=="view" && $section=="") {
-                               $rv=$this->getSection($this->mContent,0,"");                            
+                               $rv=$this->getSection($this->mContent,0,$sectiontitle);                         
                                $wgOut->setToc(Parser::getTocFromSource($this->mContent));                              
                                if($anontalk) { $rv = $rv . "\n" . wfMsg("anontalkpage"); }
+                               wfProfileOut( $fname ); 
                                return $rv;
                        }
                        # $section contains a section number and is used for section viewing and editing.
index 28ffb86..dfba14d 100644 (file)
@@ -547,7 +547,9 @@ class Parser
                return $t ;
        }
 
-       function internalParse( $text, $linestart, $args = array() )
+       // set isMain=false if you call from a template etc. and don't want to do stuff
+       // like TOC insertion for that content
+       function internalParse( $text, $linestart, $args = array(), $isMain=true )
        {
                $fname = "Parser::internalParse";
                wfProfileIn( $fname );
@@ -565,7 +567,7 @@ class Parser
                $text = $this->replaceExternalLinks( $text );
                $text = $this->doTokenizedParser ( $text );
                $text = $this->doTableStuff ( $text ) ;
-               $text = $this->formatHeadings( $text );
+               $text = $this->formatHeadings( $text, $isMain );
                $sk =& $this->mOptions->getSkin();
                $text = $sk->transformContent( $text );
 
@@ -1507,7 +1509,7 @@ class Parser
 
                        # Run full parser on the included text
                        $text = $this->strip( $text, $this->mStripState );
-                       $text = $this->internalParse( $text, (bool)$newline, $assocArgs );
+                       $text = $this->internalParse( $text, (bool)$newline, $assocArgs, false );
                        if(!empty($newline)) $text = "\n".$text;
 
                        # Add the result to the strip state for re-inclusion after
@@ -1673,7 +1675,7 @@ class Parser
  *
  */
 
-       /* private */ function formatHeadings( $text )
+       /* private */ function formatHeadings( $text, $isMain=true )
        {
                global $wgInputEncoding,$wgRequest,$wgOut;
                
@@ -1854,10 +1856,9 @@ class Parser
                        # from the wikisource is stored in the title object.
                        # This TOC is now fetched and inserted here if it exists.
                        $collapsedtoc=$wgOut->getToc();
-                       if ($collapsedtoc && !$i) {
+                       if ($collapsedtoc && !$i && $isMain) {
                                $full = $full.$collapsedtoc;            
-                       }
-                       $wgOut->setToc("");
+                       }                       
 
                        if( !empty( $head[$i] ) ) {
                                $full .= $head[$i];