API: DWIM for action=edit&section=new&appendtext=...
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 5 Aug 2013 15:26:49 +0000 (11:26 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 5 Aug 2013 15:26:49 +0000 (11:26 -0400)
While it doesn't make a whole lot of sense to prepend or append with
section=new, the user certainly doesn't intend to be copying the
contents of section 0. In the spirit of "do what I mean", we should
probably prepend/append to empty text in this situation.

Bug: 52538
Change-Id: I9b03635906ca665a4f68b3bd35d05ae9108e2356

RELEASE-NOTES-1.22
includes/api/ApiEditPage.php

index a36d8cf..51ea254 100644 (file)
@@ -293,6 +293,8 @@ production.
   with the content.
 * (bug 51342) prop=imageinfo iicontinue now contains the dbkey, not the text
   version of the title.
+* (bug 52538) action=edit will now use empty text instead of the contents
+  of section 0 when passed prependtext or appendtext with section=new.
 
 === Languages updated in 1.22===
 
index 22e4ded..9c079da 100644 (file)
@@ -159,12 +159,17 @@ class ApiEditPage extends ApiBase {
                                        $this->dieUsage( "Sections are not supported for this content model: $modelName.", 'sectionsnotsupported' );
                                }
 
-                               // Process the content for section edits
-                               $section = intval( $params['section'] );
-                               $content = $content->getSection( $section );
+                               if ( $params['section'] == 'new' ) {
+                                       // DWIM if they're trying to prepend/append to a new section.
+                                       $content = null;
+                               } else {
+                                       // Process the content for section edits
+                                       $section = intval( $params['section'] );
+                                       $content = $content->getSection( $section );
 
-                               if ( !$content ) {
-                                       $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
+                                       if ( !$content ) {
+                                               $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
+                                       }
                                }
                        }