r96271 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96270‎ | r96271 | r96272 >
Date:06:56, 5 September 2011
Author:tstarling
Status:ok
Tags:
Comment:
Reverted r84357 and r90461 and fixed the bug in a better way: in an empty document, consider section zero to exist, and to be empty, effectively representing the whole document. This allows section zero of a blank page to be viewed and edited with no updates to EditPage.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -5291,12 +5291,14 @@
52925292 * pull the given section along with its lower-level subsections. If the section is
52935293 * not found, $mode=get will return $newtext, and $mode=replace will return $text.
52945294 *
 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+ *
52955299 * @param $mode String: one of "get" or "replace"
52965300 * @param $newText String: replacement text for section data.
52975301 * @return String: for "get", the extracted section text.
52985302 * 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
53015303 */
53025304 private function extractSections( $text, $section, $mode, $newText='' ) {
53035305 global $wgTitle; # not generally used but removes an ugly failure mode
@@ -5313,6 +5315,25 @@
53145316 $flags |= self::PTD_FOR_INCLUSION;
53155317 }
53165318 }
 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+
53175338 # Preprocess the text
53185339 $root = $this->preprocessToDom( $text, $flags );
53195340
@@ -5324,10 +5345,6 @@
53255346 if ( $sectionIndex == 0 ) {
53265347 # Section zero doesn't nest, level=big
53275348 $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 - }
53325349 } else {
53335350 while ( $node ) {
53345351 if ( $node->getName() === 'h' ) {
@@ -5410,7 +5427,8 @@
54115428
54125429 /**
54135430 * 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.
54155433 *
54165434 * @param $oldtext String: former text of the article
54175435 * @param $section Numeric: section identifier

Follow-up revisions

RevisionCommit summaryAuthorDate
r965111.18: MFT r96163, r96174, r96212, r96217, r96218, r96271, r96273, r96306, r96...catrope22:07, 7 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84357* (Bug 14005) editing section 0 of an existing but empty page gives no such s...reedy23:23, 19 March 2011
r90461Expand return documentation for r84357reedy13:57, 20 June 2011

Status & tagging log