dépôts
/
lhc
/
web
/
wiklou.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
5457ecc
)
Reverted r84357 and r90461 and fixed the bug in a better way: in an empty document...
author
Tim Starling
<tstarling@users.mediawiki.org>
Mon, 5 Sep 2011 06:56:08 +0000
(06:56 +0000)
committer
Tim Starling
<tstarling@users.mediawiki.org>
Mon, 5 Sep 2011 06:56:08 +0000
(06:56 +0000)
includes/parser/Parser.php
patch
|
blob
|
history
diff --git
a/includes/parser/Parser.php
b/includes/parser/Parser.php
index
e168eca
..
6ff1e44
100644
(file)
--- a/
includes/parser/Parser.php
+++ b/
includes/parser/Parser.php
@@
-5291,12
+5291,14
@@
class Parser {
* pull the given section along with its lower-level subsections. If the section is
* not found, $mode=get will return $newtext, and $mode=replace will return $text.
*
* pull the given section along with its lower-level subsections. If the section is
* not found, $mode=get will return $newtext, and $mode=replace will return $text.
*
+ * Section 0 is always considered to exist, even if it only contains the empty
+ * string. If $text is the empty string and section 0 is replaced, $newText is
+ * returned.
+ *
* @param $mode String: one of "get" or "replace"
* @param $newText String: replacement text for section data.
* @return String: for "get", the extracted section text.
* for "replace", the whole page with the section replaced.
* @param $mode String: one of "get" or "replace"
* @param $newText String: replacement text for section data.
* @return String: for "get", the extracted section text.
* for "replace", the whole page with the section replaced.
- * If the page is empty and section 0 is requested, $text (as '')
- * is returned
*/
private function extractSections( $text, $section, $mode, $newText='' ) {
global $wgTitle; # not generally used but removes an ugly failure mode
*/
private function extractSections( $text, $section, $mode, $newText='' ) {
global $wgTitle; # not generally used but removes an ugly failure mode
@@
-5313,6
+5315,25
@@
class Parser {
$flags |= self::PTD_FOR_INCLUSION;
}
}
$flags |= self::PTD_FOR_INCLUSION;
}
}
+
+ # Check for empty input
+ if ( strval( $text ) === '' ) {
+ # Only sections 0 and T-0 exist in an empty document
+ if ( $sectionIndex == 0 ) {
+ if ( $mode === 'get' ) {
+ return '';
+ } else {
+ return $newText;
+ }
+ } else {
+ if ( $mode === 'get' ) {
+ return $newText;
+ } else {
+ return $text;
+ }
+ }
+ }
+
# Preprocess the text
$root = $this->preprocessToDom( $text, $flags );
# Preprocess the text
$root = $this->preprocessToDom( $text, $flags );
@@
-5324,10
+5345,6
@@
class Parser {
if ( $sectionIndex == 0 ) {
# Section zero doesn't nest, level=big
$targetLevel = 1000;
if ( $sectionIndex == 0 ) {
# Section zero doesn't nest, level=big
$targetLevel = 1000;
- if ( !$node ) {
- # The page definitely exists - we checked that earlier - so it must be blank: see bug #14005
- return $text;
- }
} else {
while ( $node ) {
if ( $node->getName() === 'h' ) {
} else {
while ( $node ) {
if ( $node->getName() === 'h' ) {
@@
-5410,7
+5427,8
@@
class Parser {
/**
* This function returns $oldtext after the content of the section
/**
* This function returns $oldtext after the content of the section
- * specified by $section has been replaced with $text.
+ * specified by $section has been replaced with $text. If the target
+ * section does not exist, $oldtext is returned unchanged.
*
* @param $oldtext String: former text of the article
* @param $section Numeric: section identifier
*
* @param $oldtext String: former text of the article
* @param $section Numeric: section identifier