Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1031,7 +1031,7 @@ |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** @todo document */ |
1035 | | - function editSectionLinkForOther( $title, $section ) { |
| 1035 | + public function editSectionLinkForOther( $title, $section ) { |
1036 | 1036 | global $wgContLang; |
1037 | 1037 | |
1038 | 1038 | $title = Title::newFromText( $title ); |
— | — | @@ -1047,7 +1047,7 @@ |
1048 | 1048 | * @param $section Integer: section number. |
1049 | 1049 | * @param $hint Link String: title, or default if omitted or empty |
1050 | 1050 | */ |
1051 | | - function editSectionLink( $nt, $section, $hint='' ) { |
| 1051 | + public function editSectionLink( $nt, $section, $hint='' ) { |
1052 | 1052 | global $wgContLang; |
1053 | 1053 | |
1054 | 1054 | $editurl = '§ion='.$section; |
— | — | @@ -1058,6 +1058,22 @@ |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | /** |
| 1062 | + * Create a headline for content |
| 1063 | + * |
| 1064 | + * @param int $level The level of the headline (1-6) |
| 1065 | + * @param string $attribs Any attributes for the headline, starting with a space and ending with '>' |
| 1066 | + * This *must* be at least '>' for no attribs |
| 1067 | + * @param string $anchor The anchor to give the headline (the bit after the #) |
| 1068 | + * @param string $text The text of the header |
| 1069 | + * @param string $link HTML to add for the section edit link |
| 1070 | + * |
| 1071 | + * @return string HTML headline |
| 1072 | + */ |
| 1073 | + public function makeHeadline( $level, $attribs, $anchor, $text, $link ) { |
| 1074 | + return "<a name=\"$anchor\" id=\"$anchor\"></a> <h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>"; |
| 1075 | + } |
| 1076 | + |
| 1077 | + /** |
1062 | 1078 | * Split a link trail, return the "inside" portion and the remainder of the trail |
1063 | 1079 | * as a two-element array |
1064 | 1080 | * |
Index: trunk/phase3/includes/Parser.php |
— | — | @@ -3410,7 +3410,7 @@ |
3411 | 3411 | # Get all headlines for numbering them and adding funky stuff like [edit] |
3412 | 3412 | # links - this is for later, but we need the number of headlines right now |
3413 | 3413 | $matches = array(); |
3414 | | - $numMatches = preg_match_all( '/<H([1-6])(.*?'.'>)(.*?)<\/H[1-6] *>/i', $text, $matches ); |
| 3414 | + $numMatches = preg_match_all( '/<H(?P<level>[1-6])(?P<attrib>.*?'.'>)(?P<header>.*?)<\/H[1-6] *>/i', $text, $matches ); |
3415 | 3415 | |
3416 | 3416 | # if there are fewer than 4 headlines in the article, do not show TOC |
3417 | 3417 | # unless it's been explicitly enabled. |
— | — | @@ -3574,22 +3574,15 @@ |
3575 | 3575 | $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel); |
3576 | 3576 | } |
3577 | 3577 | # give headline the correct <h#> tag |
3578 | | - $head[$headlineCount] = "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount]; |
3579 | | - |
3580 | 3578 | if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) { |
3581 | | - if ( empty( $head[$headlineCount] ) ) { |
3582 | | - $head[$headlineCount] = ''; |
3583 | | - } |
3584 | 3579 | if( $istemplate ) |
3585 | | - $head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection); |
| 3580 | + $editlink = $sk->editSectionLinkForOther($templatetitle, $templatesection); |
3586 | 3581 | else |
3587 | | - $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint); |
| 3582 | + $editlink = $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint); |
| 3583 | + } else { |
| 3584 | + $editlink = ''; |
3588 | 3585 | } |
3589 | | - // Yes, the headline logically goes before the edit section. Why isn't it there |
3590 | | - // in source? Ask the CSS people. The float gets screwed up if you do that. |
3591 | | - // This might be moved to before the editsection at some point so that it will |
3592 | | - // display a bit more prettily without CSS, so please don't rely on the order. |
3593 | | - $head[$headlineCount] .= ' <span class="mw-headline">'.$headline.'</span></h'.$level.'>'; |
| 3586 | + $head[$headlineCount] = $sk->makeHeadline( $level, $matches['attrib'][$headlineCount], $anchor, $headline, $editlink ); |
3594 | 3587 | |
3595 | 3588 | $headlineCount++; |
3596 | 3589 | if( !$istemplate ) |