r18948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r18947‎ | r18948 | r18949 >
Date:02:11, 8 January 2007
Author:simetrical
Status:old
Tags:
Comment:
* Move headline construction to Linker function (from being hardcoded in Parser)
* Use ?P<title> for capturing in the main headline-munching loop, for readability

Should have no impact on output except whitespace.
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -1031,7 +1031,7 @@
10321032 }
10331033
10341034 /** @todo document */
1035 - function editSectionLinkForOther( $title, $section ) {
 1035+ public function editSectionLinkForOther( $title, $section ) {
10361036 global $wgContLang;
10371037
10381038 $title = Title::newFromText( $title );
@@ -1047,7 +1047,7 @@
10481048 * @param $section Integer: section number.
10491049 * @param $hint Link String: title, or default if omitted or empty
10501050 */
1051 - function editSectionLink( $nt, $section, $hint='' ) {
 1051+ public function editSectionLink( $nt, $section, $hint='' ) {
10521052 global $wgContLang;
10531053
10541054 $editurl = '&section='.$section;
@@ -1058,6 +1058,22 @@
10591059 }
10601060
10611061 /**
 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+ /**
10621078 * Split a link trail, return the "inside" portion and the remainder of the trail
10631079 * as a two-element array
10641080 *
Index: trunk/phase3/includes/Parser.php
@@ -3410,7 +3410,7 @@
34113411 # Get all headlines for numbering them and adding funky stuff like [edit]
34123412 # links - this is for later, but we need the number of headlines right now
34133413 $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 );
34153415
34163416 # if there are fewer than 4 headlines in the article, do not show TOC
34173417 # unless it's been explicitly enabled.
@@ -3574,22 +3574,15 @@
35753575 $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel);
35763576 }
35773577 # give headline the correct <h#> tag
3578 - $head[$headlineCount] = "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount];
3579 -
35803578 if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) {
3581 - if ( empty( $head[$headlineCount] ) ) {
3582 - $head[$headlineCount] = '';
3583 - }
35843579 if( $istemplate )
3585 - $head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection);
 3580+ $editlink = $sk->editSectionLinkForOther($templatetitle, $templatesection);
35863581 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 = '';
35883585 }
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 );
35943587
35953588 $headlineCount++;
35963589 if( !$istemplate )

Follow-up revisions

RevisionCommit summaryAuthorDate
r18950Restore previous heading formatting behavior to fix 12 parser tests broken by...brion09:45, 8 January 2007