From ac44b370651f38c87a23aec4183d25612d17175a Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Wed, 12 May 2004 22:01:25 +0000 Subject: [PATCH] fix collapsing problem with templates (templates would be expanded and 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 | 3 ++- includes/Parser.php | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index fcfa05ad1e..71ffb693ab 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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. diff --git a/includes/Parser.php b/includes/Parser.php index 28ffb86046..dfba14d2b9 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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]; -- 2.20.1