From cc357845fc6fa3faf42a630deeb270d75ab83eaa Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Wed, 12 May 2004 21:38:01 +0000 Subject: [PATCH] fix a couple of section collapsing bugs --- includes/Article.php | 13 +++++-------- includes/Parser.php | 8 +++++--- languages/Language.php | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 0713258149..fcfa05ad1e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -73,6 +73,7 @@ class Article { $action = $wgRequest->getText( 'action', 'view' ); $section = $wgRequest->getText( 'section' ); $sectiontitle = $wgRequest->getText( 'sectiontitle' ); + $oid = $wgRequest->getInt( 'oldid' ); if ( 0 == $this->getID() ) { if ( "edit" == $action ) { @@ -96,6 +97,7 @@ class Article { if( $wgRequest->getText( 'collapse' ) == 'false') { $collapse=false; } + if($oid) { $collapse=false; } $wgOut->setCollapse($collapse); # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page @@ -110,13 +112,8 @@ 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=="") { - $secs = - preg_split( - "/(^=+.*?=+|^.*?<\/h[1-6].*?" . ">)/mi", - $this->mContent, -1, - PREG_SPLIT_DELIM_CAPTURE); - $wgOut->setToc(Parser::getTocFromSource($this->mContent)); - $rv=$secs[0]; + $rv=$this->getSection($this->mContent,0,""); + $wgOut->setToc(Parser::getTocFromSource($this->mContent)); if($anontalk) { $rv = $rv . "\n" . wfMsg("anontalkpage"); } return $rv; } @@ -739,7 +736,7 @@ class Article { } $text=join("",$secs); # reinsert the stuff that we stripped out earlier - $text=$parser->unstrip($text,$striparray,true); + $text=$parser->unstrip($text,$striparray); } } diff --git a/includes/Parser.php b/includes/Parser.php index 8116e3e222..28ffb86046 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1857,6 +1857,7 @@ class Parser if ($collapsedtoc && !$i) { $full = $full.$collapsedtoc; } + $wgOut->setToc(""); if( !empty( $head[$i] ) ) { $full .= $head[$i]; @@ -1870,8 +1871,7 @@ class Parser /* Generates a HTML-formatted table of contents which links to individual sections from the wikisource. Used for collapsing long pages. */ - /* static */ function getTocFromSource( $text ) { - #$numMatches = preg_match_all( "/)(.*?)<\/H[1-6]>/i", $text, $matches ); + /* static */ function getTocFromSource( $text ) { global $wgUser,$wgInputEncoding,$wgTitle,$wgOut,$wgParser; $sk = $wgUser->getSkin(); @@ -1896,6 +1896,7 @@ class Parser $combined_html=$myout->getText(); $headlines=array(); $headlines=explode("!@@@!",$combined_html); + # headline counter $headlineCount = 0; $toclevel = 0; @@ -1906,6 +1907,7 @@ class Parser $level = 0; $prevlevel = 0; foreach( $headlines as $headline ) { + $headline=trim($headline); $numbering = ""; if( $level ) { $prevlevel = $level; @@ -1961,7 +1963,7 @@ class Parser $tocline = $numbering . " " . $tocline; # Create the anchor for linking from the TOC to the section - $anchor = $canonized_headline; + $anchor = trim($canonized_headline); if($refcount[$headlineCount] > 1 ) { $anchor .= "_" . $refcount[$headlineCount]; diff --git a/languages/Language.php b/languages/Language.php index 4aa2336391..e8b5312370 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -49,7 +49,7 @@ if($wgMetaNamespace === FALSE) "cols" => 80, "rows" => 25, "searchlimit" => 20, "contextlines" => 5, "contextchars" => 50, "skin" => $wgDefaultSkin, "math" => 1, "rcdays" => 7, "rclimit" => 50, - "highlightbroken" => 1, "stubthreshold" => 0, "collapsethreshold" => 30000, + "highlightbroken" => 1, "stubthreshold" => 0, "collapsethreshold" => 5000, "previewontop" => 1, "editsection"=>1,"editsectiononrightclick"=>0, "showtoc"=>1, "showtoolbar" =>1, "date" => 0 -- 2.20.1