Core changes for NavigableTOC extension:
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 20 Jun 2009 21:47:10 +0000 (21:47 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 20 Jun 2009 21:47:10 +0000 (21:47 +0000)
* Add TOC HTML to ParserOutput
* Add class tocsection-$section to <li> elements in the TOC representing sections in the current page (as opposed to transcluded sections)

includes/Linker.php
includes/parser/Parser.php
includes/parser/ParserOutput.php

index 2b6e674..0f97198 100644 (file)
@@ -1142,8 +1142,11 @@ class Linker {
        /**
         * parameter level defines if we are on an indentation level
         */
-       function tocLine( $anchor, $tocline, $tocnumber, $level ) {
-               return "\n<li class=\"toclevel-$level\"><a href=\"#" .
+       function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
+               $classes = "toclevel-$level";
+               if ( $sectionIndex !== false )
+                       $classes .= " tocsection-$sectionIndex";
+               return "\n<li class=\"$classes\"><a href=\"#" .
                        $anchor . '"><span class="tocnumber">' .
                        $tocnumber . '</span> <span class="toctext">' .
                        $tocline . '</span></a>';
index a0e0a2e..5fe307d 100644 (file)
@@ -3647,7 +3647,8 @@ class Parser
                                $legacyAnchor .= '_' . $refers[$legacyArrayKey];
                        }
                        if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
-                               $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel);
+                               $toc .= $sk->tocLine($anchor, $tocline,
+                                       $numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
                                
                                # Find the DOM node for this header
                                while ( $node && !$isTemplate ) {
@@ -3703,6 +3704,8 @@ class Parser
                        }
                        $toc = $sk->tocList( $toc );
                }
+               
+               $this->mOutput->setTOCHTML( $toc );
 
                # split up and insert constructed headlines
 
index 22c1dfb..46ae1a7 100644 (file)
@@ -24,7 +24,8 @@ class ParserOutput
                $mOutputHooks = array(),      # Hook tags as per $wgParserOutputHooks
                $mWarnings = array(),         # Warning text to be returned to the user. Wikitext formatted, in the key only
                $mSections = array(),         # Table of contents
-               $mProperties = array();       # Name/value pairs to be cached in the DB
+               $mProperties = array(),       # Name/value pairs to be cached in the DB
+               $mTOCHTML = '';               # HTML of the TOC
        private $mIndexPolicy = '';           # 'index' or 'noindex'?  Any other value will result in no change.
 
        /**
@@ -58,6 +59,7 @@ class ParserOutput
        function getOutputHooks()            { return (array)$this->mOutputHooks; }
        function getWarnings()               { return array_keys( $this->mWarnings ); }
        function getIndexPolicy()            { return $this->mIndexPolicy; }
+       function getTOCHTML()                { return $this->mTOCHTML; }
 
        function containsOldMagic()          { return $this->mContainsOldMagic; }
        function setText( $text )            { return wfSetVar( $this->mText, $text ); }
@@ -68,6 +70,7 @@ class ParserOutput
        function setTitleText( $t )          { return wfSetVar( $this->mTitleText, $t ); }
        function setSections( $toc )         { return wfSetVar( $this->mSections, $toc ); }
        function setIndexPolicy( $policy )   { return wfSetVar( $this->mIndexPolicy, $policy ); }
+       function setTOCHTML( $tochtml )      { return wfSetVar( $this->mTOCHTML, $tochtml ); }
 
        function addCategory( $c, $sort )    { $this->mCategories[$c] = $sort; }
        function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }