From 02914ea8c8e887dcbd3fafe2a79cd23e1809a16e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 3 Apr 2004 04:38:09 +0000 Subject: [PATCH] __FORCETOC__ to display a TOC even on pages with less than 4 headings, written by Silsor --- includes/Parser.php | 23 ++++++++++++++++++----- languages/Language.php | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 85198b0e0c..7fc503794a 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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]>/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]>/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 = "".$full.$toc; } diff --git a/languages/Language.php b/languages/Language.php index c8663ca997..fd16df826f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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" ), -- 2.20.1