From 265b7839d522be539656b1c2965606d26aa9c9c7 Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Sat, 8 Nov 2003 12:12:50 +0000 Subject: [PATCH] Heading numbers are no longer displayed if there is only the one header. Also tidied up some parts of the code and added comments. --- includes/OutputPage.php | 50 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 995187da8a..2681301e8f 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1433,7 +1433,8 @@ $t[] = "" ; } } } - + + // The canonized header is a version of the header text safe to use for links $canonized_headline=preg_replace("/<.*?>/","",$headline); // strip out HTML $tocline=$canonized_headline; @@ -1442,12 +1443,20 @@ $t[] = "" ; $refer[$c]=$canonized_headline; $refers[$canonized_headline]++; // count how many in assoc. array so we can track dupes in anchors $refcount[$c]=$refers[$canonized_headline]; + + // Prepend the number to the heading text + if($nh||$st) { $tocline=$numbering ." ". $tocline; - if($nh) { + + // Don't number the heading if it is the only one (looks silly) + if($nh && count($matches[3]) > 1) { $headline=$numbering . " " . $headline; // the two are different if the line contains a link - } + } } + + // Create the anchor for linking from the TOC to the section + $anchor=$canonized_headline; if($refcount[$c]>1) {$anchor.="_".$refcount[$c];} if($st) { @@ -1456,14 +1465,21 @@ $t[] = "" ; if($es && !isset($wpPreview)) { $head[$c].=$sk->editSectionLink($c+1); } - $head[$c].="" .$headline ."" - .""; + .""; + + // Add the edit section link + if($esr && !isset($wpPreview)) { $head[$c]=$sk->editSectionScript($c+1,$head[$c]); } + $numbering=""; $c++; $dot=0; @@ -1480,12 +1496,11 @@ $t[] = "" ; $blocks=preg_split("/.*?<\/H[1-6]>/i",$text); $i=0; - foreach($blocks as $block) { if(($es) && !isset($wpPreview) && $c>0 && $i==0) { # This is the [edit] link that appears for the top block of text when # section editing is enabled - $full.=$sk->editSectionLink(0); + $full.=$sk->editSectionLink(0); } $full.=$block; if($st && $toclines>3 && !$i) { @@ -1496,6 +1511,7 @@ $t[] = "" ; $full.=$head[$i]; $i++; } + return $full; } @@ -1506,30 +1522,30 @@ $t[] = "" ; $a = split( "ISBN ", " $text" ); if ( count ( $a ) < 2 ) return $text; $text = substr( array_shift( $a ), 1); - $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ"; foreach ( $a as $x ) { $isbn = $blank = "" ; while ( " " == $x{0} ) { - $blank .= " "; - $x = substr( $x, 1 ); + $blank .= " "; + $x = substr( $x, 1 ); } - while ( strstr( $valid, $x{0} ) != false ) { + while ( strstr( $valid, $x{0} ) != false ) { $isbn .= $x{0}; $x = substr( $x, 1 ); } - $num = str_replace( "-", "", $isbn ); - $num = str_replace( " ", "", $num ); + $num = str_replace( "-", "", $isbn ); + $num = str_replace( " ", "", $num ); - if ( "" == $num ) { + if ( "" == $num ) { $text .= "ISBN $blank$x"; - } else { + } else { $text .= "specialPage( - "Booksources"), "isbn={$num}" ) . "\" CLASS=\"internal\">ISBN $isbn"; + "Booksources"), "isbn={$num}" ) . "\" class=\"internal\">ISBN $isbn"; $text .= $x; } } - return $text; + return $text; } /* private */ function magicRFC( $text ) -- 2.20.1