r5341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5340‎ | r5341 | r5342 >
Date:04:33, 21 September 2004
Author:kateturner
Status:old
Tags:
Comment:
don't put edit links on sections from included templates.
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
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1710,6 +1710,13 @@
17111711 if ( !$found ) {
17121712 return $matches[0];
17131713 } else {
 1714+ # replace ==section headers==
 1715+ # XXX this needs to go away once we have a better parser.
 1716+ for ( $i = 1; $i <= 6; ++$i ) {
 1717+ $h = substr( '======', 0, $i );
 1718+ $text = preg_replace( "/^{$h}([^=].*){$h}\\s?$/m",
 1719+ "${h}\\1 __MWTEMPLATESECTION__${h}\\2", $text );
 1720+ }
17141721 return $text;
17151722 }
17161723 }
@@ -1973,6 +1980,7 @@
19741981
19751982 # headline counter
19761983 $headlineCount = 0;
 1984+ $sectionCount = 0; # headlineCount excluding template sections
19771985
19781986 # Ugh .. the TOC should have neat indentation levels which can be
19791987 # passed to the skin functions. These are determined here
@@ -1984,6 +1992,11 @@
19851993 $level = 0;
19861994 $prevlevel = 0;
19871995 foreach( $matches[3] as $headline ) {
 1996+ $istemplate = 0;
 1997+ if (strstr($headline, "__MWTEMPLATESECTION__")) {
 1998+ $istemplate = 1;
 1999+ $headline = str_replace("__MWTEMPLATESECTION__", "", $headline);
 2000+ }
19882001 $numbering = '';
19892002 if( $level ) {
19902003 $prevlevel = $level;
@@ -2064,22 +2077,24 @@
20652078 if( $doShowToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
20662079 $toc .= $sk->tocLine($anchor,$tocline,$toclevel);
20672080 }
2068 - if( $showEditLink ) {
 2081+ if( $showEditLink && !$istemplate ) {
20692082 if ( empty( $head[$headlineCount] ) ) {
20702083 $head[$headlineCount] = '';
20712084 }
2072 - $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1);
 2085+ $head[$headlineCount] .= $sk->editSectionLink($sectionCount+1);
20732086 }
20742087
20752088 # Add the edit section span
20762089 if( $rightClickHack ) {
2077 - $headline = $sk->editSectionScript($headlineCount+1,$headline);
 2090+ $headline = $sk->editSectionScript($sectionCount+1,$headline);
20782091 }
20792092
20802093 # give headline the correct <h#> tag
20812094 @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline.'</h'.$level.'>';
20822095
20832096 $headlineCount++;
 2097+ if( !$istemplate )
 2098+ $sectionCount++;
20842099 }
20852100
20862101 if( $doShowToc ) {

Status & tagging log