Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4188,30 +4188,42 @@ |
4189 | 4189 | } |
4190 | 4190 | |
4191 | 4191 | # split up and insert constructed headlines |
4192 | | - |
4193 | 4192 | $blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text ); |
4194 | 4193 | $i = 0; |
4195 | | - |
4196 | | - foreach ( $blocks as $block ) { |
4197 | | - if ( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) { |
4198 | | - # This is the [edit] link that appears for the top block of text when |
4199 | | - # section editing is enabled |
4200 | | - |
4201 | | - # Disabled because it broke block formatting |
4202 | | - # For example, a bullet point in the top line |
4203 | | - # $full .= $sk->editSectionLink(0); |
| 4194 | + |
| 4195 | + // build an array of document sections |
| 4196 | + $sections = array(); |
| 4197 | + foreach ( $blocks as $block ) { |
| 4198 | + // $head is zero-based, sections aren't. |
| 4199 | + if ( empty( $head[$i - 1] ) ) { |
| 4200 | + $sections[$i] = $block; |
| 4201 | + } else { |
| 4202 | + $sections[$i] = $head[$i - 1] . $block; |
4204 | 4203 | } |
4205 | | - $full .= $block; |
4206 | | - if ( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) { |
4207 | | - # Top anchor now in skin |
4208 | | - $full = $full.$toc; |
4209 | | - } |
4210 | 4204 | |
4211 | | - if ( !empty( $head[$i] ) ) { |
4212 | | - $full .= $head[$i]; |
4213 | | - } |
| 4205 | + /** |
| 4206 | + * Send a hook, one per section. |
| 4207 | + * The idea here is to be able to make section-level DIVs, but to do so in a |
| 4208 | + * lower-impact, more correct way than r50769 |
| 4209 | + * |
| 4210 | + * $this : caller |
| 4211 | + * $section : the section number |
| 4212 | + * &$sectionContent : ref to the content of the section |
| 4213 | + * $showEditLinks : boolean describing whether this section has an edit link |
| 4214 | + */ |
| 4215 | + wfRunHooks( 'ParserSectionCreate', array( $this, $i, &$sections[$i], $showEditLink ) ); |
| 4216 | + |
4214 | 4217 | $i++; |
4215 | 4218 | } |
| 4219 | + |
| 4220 | + if ( $enoughToc && $isMain && !$this->mForceTocPosition ) { |
| 4221 | + // append the TOC at the beginning |
| 4222 | + // Top anchor now in skin |
| 4223 | + $sections[0] = $sections[0] . $toc . "\n"; |
| 4224 | + } |
| 4225 | + |
| 4226 | + $full .= join( '', $sections ); |
| 4227 | + |
4216 | 4228 | if ( $this->mForceTocPosition ) { |
4217 | 4229 | return str_replace( '<!--MWTOC-->', $toc, $full ); |
4218 | 4230 | } else { |