From 2493e3df03577439ca3fb4c04d3a9e2fb505ec7b Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 8 Jan 2007 02:11:45 +0000 Subject: [PATCH] * Move headline construction to Linker function (from being hardcoded in Parser) * Use ?P for capturing in the main headline-munching loop, for readability Should have no impact on output except whitespace. --- includes/Linker.php | 20 ++++++++++++++++++-- includes/Parser.php | 19 ++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 42ad07ba40..5f6274a9ab 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1031,7 +1031,7 @@ class Linker { } /** @todo document */ - function editSectionLinkForOther( $title, $section ) { + public function editSectionLinkForOther( $title, $section ) { global $wgContLang; $title = Title::newFromText( $title ); @@ -1047,7 +1047,7 @@ class Linker { * @param $section Integer: section number. * @param $hint Link String: title, or default if omitted or empty */ - function editSectionLink( $nt, $section, $hint='' ) { + public function editSectionLink( $nt, $section, $hint='' ) { global $wgContLang; $editurl = '§ion='.$section; @@ -1057,6 +1057,22 @@ class Linker { return "<span class=\"editsection\">[".$url."]</span>"; } + /** + * Create a headline for content + * + * @param int $level The level of the headline (1-6) + * @param string $attribs Any attributes for the headline, starting with a space and ending with '>' + * This *must* be at least '>' for no attribs + * @param string $anchor The anchor to give the headline (the bit after the #) + * @param string $text The text of the header + * @param string $link HTML to add for the section edit link + * + * @return string HTML headline + */ + public function makeHeadline( $level, $attribs, $anchor, $text, $link ) { + return "<a name=\"$anchor\" id=\"$anchor\"></a> <h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>"; + } + /** * Split a link trail, return the "inside" portion and the remainder of the trail * as a two-element array diff --git a/includes/Parser.php b/includes/Parser.php index f4679b6b3e..8d67279dbe 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -3410,7 +3410,7 @@ class Parser # 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 $matches = array(); - $numMatches = preg_match_all( '/<H([1-6])(.*?'.'>)(.*?)<\/H[1-6] *>/i', $text, $matches ); + $numMatches = preg_match_all( '/<H(?P<level>[1-6])(?P<attrib>.*?'.'>)(?P<header>.*?)<\/H[1-6] *>/i', $text, $matches ); # if there are fewer than 4 headlines in the article, do not show TOC # unless it's been explicitly enabled. @@ -3574,22 +3574,15 @@ class Parser $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel); } # give headline the correct <h#> tag - $head[$headlineCount] = "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount]; - if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) { - if ( empty( $head[$headlineCount] ) ) { - $head[$headlineCount] = ''; - } if( $istemplate ) - $head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection); + $editlink = $sk->editSectionLinkForOther($templatetitle, $templatesection); else - $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint); + $editlink = $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint); + } else { + $editlink = ''; } - // Yes, the headline logically goes before the edit section. Why isn't it there - // in source? Ask the CSS people. The float gets screwed up if you do that. - // This might be moved to before the editsection at some point so that it will - // display a bit more prettily without CSS, so please don't rely on the order. - $head[$headlineCount] .= ' <span class="mw-headline">'.$headline.'</span></h'.$level.'>'; + $head[$headlineCount] = $sk->makeHeadline( $level, $matches['attrib'][$headlineCount], $anchor, $headline, $editlink ); $headlineCount++; if( !$istemplate ) -- 2.20.1