From 2478dbdec47f47eba21733f4ea70f93d44467c96 Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Tue, 21 Sep 2004 08:31:25 +0000 Subject: [PATCH] make section headers in templates have edit links that point to the template. --- includes/Parser.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index bebf3d3bca..5e4915434c 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -52,6 +52,8 @@ define( 'EXT_IMAGE_REGEX', '('.EXT_IMAGE_FNAME_CLASS.'+)\\.((?i)'.EXT_IMAGE_EXTENSIONS.')$/S' # Filename ); +$wgCurrentSectionNumber = 0; # XXX + /** * PHP Parser * @@ -99,6 +101,7 @@ class Parser // multiple SQL queries for the same string $mTemplatePath; // stores an unsorted hash of all the templates already loaded // in this path. Used for loop detection. + /**#@-*/ /** @@ -1846,10 +1849,15 @@ class Parser # replace ==section headers== # XXX this needs to go away once we have a better parser. if ( $this->mOutputType != OT_WIKI ) { + $encodedname = base64_encode($title->getPrefixedDBkey()); + $wfCurrentSectionNumber = 0; for ( $i = 1; $i <= 6; ++$i ) { $h = substr( '======', 0, $i ); - $text = preg_replace( "/^{$h}([^=].*){$h}\\s?$/m", - "${h}\\1 __MWTEMPLATESECTION__${h}\\2", $text ); + $text = preg_replace_callback( "/^({$h})([^=].*){$h}\\s?$/m", + create_function('$matches', +'return "${matches[1]}$matches[2] __MWTEMPLATESECTION='.$encodedname. +'&" . wfGetSectionNumber() . "__${matches[1]}";' + ), $text); } } return $text; @@ -2141,10 +2149,16 @@ class Parser $prevlevel = 0; foreach( $matches[3] as $headline ) { $istemplate = 0; - if (strstr($headline, "__MWTEMPLATESECTION__")) { + $templatetitle = ""; + $templatesection = 0; + + if (preg_match("/__MWTEMPLATESECTION=([^&]+)&([^_]+)__/", $headline, $mat)) { $istemplate = 1; - $headline = str_replace("__MWTEMPLATESECTION__", "", $headline); + $templatetitle = base64_decode($mat[1]); + $templatesection = 1 + (int)base64_decode($mat[2]); + $headline = preg_replace("/__MWTEMPLATESECTION=([^&]+)&([^_]+)__/", "", $headline); } + $numbering = ''; if( $level ) { $prevlevel = $level; @@ -2225,11 +2239,14 @@ class Parser if( $doShowToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) { $toc .= $sk->tocLine($anchor,$tocline,$toclevel); } - if( $showEditLink && !$istemplate ) { + if( $showEditLink ) { if ( empty( $head[$headlineCount] ) ) { $head[$headlineCount] = ''; } - $head[$headlineCount] .= $sk->editSectionLink($sectionCount+1); + if( $istemplate ) + $head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection); + else + $head[$headlineCount] .= $sk->editSectionLink($sectionCount+1); } # Add the edit section span @@ -2783,5 +2800,10 @@ function wfEscapeHTMLTagsOnly( $in ) { $in ); } - +function wfGetSectionNumber() { + global $wgCurrentSectionNumber; + $str = base64_encode("$wgCurrentSectionNumber"); + $wgCurrentSectionNumber++; + return $str; +} ?> -- 2.20.1