fix a couple of section collapsing bugs
authorErik Moeller <erik@users.mediawiki.org>
Wed, 12 May 2004 21:38:01 +0000 (21:38 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Wed, 12 May 2004 21:38:01 +0000 (21:38 +0000)
includes/Article.php
includes/Parser.php
languages/Language.php

index 0713258..fcfa05a 100644 (file)
@@ -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].*?" . ">.*?<\/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);      
                        }
                                                                
                }
index 8116e3e..28ffb86 100644 (file)
@@ -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])(.*?" . ">)(.*?)<\/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];
index 4aa2336..e8b5312 100644 (file)
@@ -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