__FORCETOC__ to display a TOC even on pages with less than 4 headings, written by...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 3 Apr 2004 04:38:09 +0000 (04:38 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 3 Apr 2004 04:38:09 +0000 (04:38 +0000)
includes/Parser.php
languages/Language.php

index 85198b0..7fc5037 100644 (file)
@@ -1392,13 +1392,26 @@ class Parser
                        $doShowToc = 0;
                }
 
+               # Get all headlines for numbering them and adding funky stuff like [edit]
+               # links - this is for later, but we need the number of headlines right now
+               $numMatches = preg_match_all( "/<H([1-6])(.*?" . ">)(.*?)<\/H[1-6]>/i", $text, $matches );
+
+               # if there are fewer than 4 headlines in the article, do not show TOC
+               if( $numMatches < 4 ) {
+                       $doShowToc = 0;
+               }
+
+               # if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
+               # override above conditions and always show TOC
+               $mw =& MagicWord::get( MAG_FORCETOC );
+               if ($mw->matchAndRemove( $text ) ) {
+                       $doShowToc = 1;
+               }
+
+
                # We need this to perform operations on the HTML
                $sk =& $this->mOptions->getSkin();
 
-               # Get all headlines for numbering them and adding funky stuff like [edit]
-               # links
-               preg_match_all( "/<H([1-6])(.*?" . ">)(.*?)<\/H[1-6]>/i", $text, $matches );
-               
                # headline counter
                $headlineCount = 0;
 
@@ -1527,7 +1540,7 @@ class Parser
                                $full .= $sk->editSectionLink(0);
                        }
                        $full .= $block;
-                       if( $doShowToc && $toclines>3 && !$i) {
+                       if( $doShowToc && !$i) {
                                # Let's add a top anchor just in case we want to link to the top of the page
                                $full = "<a name=\"top\"></a>".$full.$toc;
                        }
index c8663ca..fd16df8 100644 (file)
@@ -39,6 +39,7 @@ define("MAG_IMG_NONE",       19);
 define("MAG_IMG_WIDTH",      20);
 define("MAG_IMG_CENTER",      21);
 define("MAG_INT", 22);
+define("MAG_FORCETOC", 23);
 
 $wgVariableIDs = array(
        MAG_CURRENTMONTH,
@@ -372,6 +373,7 @@ $wgLanguageNamesEn =& $wgLanguageNames;
 #   ID                                 CASE  SYNONYMS
     MAG_REDIRECT             => array( 0,    "#redirect"              ),
     MAG_NOTOC                => array( 0,    "__NOTOC__"              ),
+    MAG_FORCETOC             => array( 0,    "__FORCETOC__"           ),
     MAG_NOEDITSECTION        => array( 0,    "__NOEDITSECTION__"      ),
     MAG_START                => array( 0,    "__START__"              ),
     MAG_CURRENTMONTH         => array( 1,    "CURRENTMONTH"           ),