Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -5291,12 +5291,14 @@ |
5292 | 5292 | * pull the given section along with its lower-level subsections. If the section is |
5293 | 5293 | * not found, $mode=get will return $newtext, and $mode=replace will return $text. |
5294 | 5294 | * |
| 5295 | + * Section 0 is always considered to exist, even if it only contains the empty |
| 5296 | + * string. If $text is the empty string and section 0 is replaced, $newText is |
| 5297 | + * returned. |
| 5298 | + * |
5295 | 5299 | * @param $mode String: one of "get" or "replace" |
5296 | 5300 | * @param $newText String: replacement text for section data. |
5297 | 5301 | * @return String: for "get", the extracted section text. |
5298 | 5302 | * for "replace", the whole page with the section replaced. |
5299 | | - * If the page is empty and section 0 is requested, $text (as '') |
5300 | | - * is returned |
5301 | 5303 | */ |
5302 | 5304 | private function extractSections( $text, $section, $mode, $newText='' ) { |
5303 | 5305 | global $wgTitle; # not generally used but removes an ugly failure mode |
— | — | @@ -5313,6 +5315,25 @@ |
5314 | 5316 | $flags |= self::PTD_FOR_INCLUSION; |
5315 | 5317 | } |
5316 | 5318 | } |
| 5319 | + |
| 5320 | + # Check for empty input |
| 5321 | + if ( strval( $text ) === '' ) { |
| 5322 | + # Only sections 0 and T-0 exist in an empty document |
| 5323 | + if ( $sectionIndex == 0 ) { |
| 5324 | + if ( $mode === 'get' ) { |
| 5325 | + return ''; |
| 5326 | + } else { |
| 5327 | + return $newText; |
| 5328 | + } |
| 5329 | + } else { |
| 5330 | + if ( $mode === 'get' ) { |
| 5331 | + return $newText; |
| 5332 | + } else { |
| 5333 | + return $text; |
| 5334 | + } |
| 5335 | + } |
| 5336 | + } |
| 5337 | + |
5317 | 5338 | # Preprocess the text |
5318 | 5339 | $root = $this->preprocessToDom( $text, $flags ); |
5319 | 5340 | |
— | — | @@ -5324,10 +5345,6 @@ |
5325 | 5346 | if ( $sectionIndex == 0 ) { |
5326 | 5347 | # Section zero doesn't nest, level=big |
5327 | 5348 | $targetLevel = 1000; |
5328 | | - if ( !$node ) { |
5329 | | - # The page definitely exists - we checked that earlier - so it must be blank: see bug #14005 |
5330 | | - return $text; |
5331 | | - } |
5332 | 5349 | } else { |
5333 | 5350 | while ( $node ) { |
5334 | 5351 | if ( $node->getName() === 'h' ) { |
— | — | @@ -5410,7 +5427,8 @@ |
5411 | 5428 | |
5412 | 5429 | /** |
5413 | 5430 | * This function returns $oldtext after the content of the section |
5414 | | - * specified by $section has been replaced with $text. |
| 5431 | + * specified by $section has been replaced with $text. If the target |
| 5432 | + * section does not exist, $oldtext is returned unchanged. |
5415 | 5433 | * |
5416 | 5434 | * @param $oldtext String: former text of the article |
5417 | 5435 | * @param $section Numeric: section identifier |