http://www.mediawiki.org/wiki/Special:Code/MediaWiki/92506

Revision: 92506
Author:   raindrift
Date:     2011-07-18 23:23:14 +0000 (Mon, 18 Jul 2011)
Log Message:
-----------
Refactored section assembly code to be more readable
Added a hook that's called for each section.  This allows sections to be 
addressed separately at the document level, for example by wrapping each in a 
div (as in the reverted r50769).  This in-turn enables richer section-specific 
UI, like highlighting or in-line editing.

Modified Paths:
--------------
    trunk/phase3/includes/parser/Parser.php

Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php     2011-07-18 23:14:17 UTC (rev 
92505)
+++ trunk/phase3/includes/parser/Parser.php     2011-07-18 23:23:14 UTC (rev 
92506)
@@ -4188,30 +4188,42 @@
                }
 
                # split up and insert constructed headlines
-
                $blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text 
);
                $i = 0;
-
-               foreach ( $blocks as $block ) {
-                       if ( $showEditLink && $headlineCount > 0 && $i == 0 && 
$block !== "\n" ) {
-                               # This is the [edit] link that appears for the 
top block of text when
-                               # section editing is enabled
-
-                               # Disabled because it broke block formatting
-                               # For example, a bullet point in the top line
-                               # $full .= $sk->editSectionLink(0);
+               
+               // build an array of document sections
+               $sections = array();
+               foreach ( $blocks as $block ) {                 
+                       // $head is zero-based, sections aren't.
+                       if ( empty( $head[$i - 1] ) ) {
+                               $sections[$i] = $block;
+                       } else {
+                               $sections[$i] = $head[$i - 1] . $block;
                        }
-                       $full .= $block;
-                       if ( $enoughToc && !$i && $isMain && 
!$this->mForceTocPosition ) {
-                               # Top anchor now in skin
-                               $full = $full.$toc;
-                       }
 
-                       if ( !empty( $head[$i] ) ) {
-                               $full .= $head[$i];
-                       }
+                       /**
+                        * Send a hook, one per section.
+                        * The idea here is to be able to make section-level 
DIVs, but to do so in a
+                        * lower-impact, more correct way than r50769
+                        *
+                        * $this : caller
+                        * $section : the section number
+                        * &$sectionContent : ref to the content of the section
+                        * $showEditLinks : boolean describing whether this 
section has an edit link
+                        */
+                       wfRunHooks( 'ParserSectionCreate', array( $this, $i, 
&$sections[$i], $showEditLink ) );
+               
                        $i++;
                }
+
+               if ( $enoughToc && $isMain && !$this->mForceTocPosition ) {
+                       // append the TOC at the beginning
+                       // Top anchor now in skin
+                       $sections[0] = $sections[0] . $toc . "\n";
+               }
+               
+               $full .= join( '', $sections );
+               
                if ( $this->mForceTocPosition ) {
                        return str_replace( '<!--MWTOC-->', $toc, $full );
                } else {


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to