* Move headline construction to Linker function (from being hardcoded in Parser)
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 8 Jan 2007 02:11:45 +0000 (02:11 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 8 Jan 2007 02:11:45 +0000 (02:11 +0000)
* Use ?P<title> for capturing in the main headline-munching loop, for readability

Should have no impact on output except whitespace.

includes/Linker.php
includes/Parser.php

index 42ad07b..5f6274a 100644 (file)
@@ -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 = '&section='.$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
index f4679b6..8d67279 100644 (file)
@@ -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 )