don't put edit links on sections from included templates.
authorRiver Tarnell <kateturner@users.mediawiki.org>
Tue, 21 Sep 2004 04:33:51 +0000 (04:33 +0000)
committerRiver Tarnell <kateturner@users.mediawiki.org>
Tue, 21 Sep 2004 04:33:51 +0000 (04:33 +0000)
template section headings have __MWTEMPLATESECTION__ added to them;
formatHeadings removes this and doesn't add the edit link for
such sections.  this is a rather hackish fix, but is probably
the best we can do with the current parser setup.

it would be nice (but not important) if this could be extended to
let users prevent edit links for certain sections.

fixes bug #266

includes/Parser.php

index e467942..48f4496 100644 (file)
@@ -1710,6 +1710,13 @@ class Parser
                if ( !$found ) {
                        return $matches[0];
                } else {
+                       # replace ==section headers==
+                       # XXX this needs to go away once we have a better parser.
+                       for ( $i = 1; $i <= 6; ++$i ) {
+                               $h = substr( '======', 0, $i );
+                               $text = preg_replace( "/^{$h}([^=].*){$h}\\s?$/m",
+                                 "${h}\\1 __MWTEMPLATESECTION__${h}\\2", $text );
+                       }
                        return $text;
                }
        }
@@ -1973,6 +1980,7 @@ class Parser
 
                # headline counter
                $headlineCount = 0;
+               $sectionCount = 0; # headlineCount excluding template sections
 
                # Ugh .. the TOC should have neat indentation levels which can be
                # passed to the skin functions. These are determined here
@@ -1984,6 +1992,11 @@ class Parser
                $level = 0;
                $prevlevel = 0;
                foreach( $matches[3] as $headline ) {
+                       $istemplate = 0;
+                       if (strstr($headline, "__MWTEMPLATESECTION__")) {
+                               $istemplate = 1;
+                               $headline = str_replace("__MWTEMPLATESECTION__", "", $headline);
+                       }
                        $numbering = '';
                        if( $level ) {
                                $prevlevel = $level;
@@ -2064,22 +2077,24 @@ class Parser
                        if( $doShowToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
                                $toc .= $sk->tocLine($anchor,$tocline,$toclevel);
                        }
-                       if( $showEditLink ) {
+                       if( $showEditLink && !$istemplate ) {
                                if ( empty( $head[$headlineCount] ) ) {
                                        $head[$headlineCount] = '';
                                }
-                               $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1);
+                               $head[$headlineCount] .= $sk->editSectionLink($sectionCount+1);
                        }
 
                        # Add the edit section span
                        if( $rightClickHack ) {
-                               $headline = $sk->editSectionScript($headlineCount+1,$headline);
+                               $headline = $sk->editSectionScript($sectionCount+1,$headline);
                        }
 
                        # give headline the correct <h#> tag
                        @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline.'</h'.$level.'>';
 
                        $headlineCount++;
+                       if( !$istemplate )
+                               $sectionCount++;
                }
 
                if( $doShowToc ) {