API: Check for nosuchsection in all code paths
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 11 Sep 2013 17:54:22 +0000 (10:54 -0700)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 11 Sep 2013 18:03:08 +0000 (11:03 -0700)
nosuchsection is currently checked only in the appendtext/prependtext
code path. Add a check for out of range section numbers in the main code
path too.

Bug: 53884
Change-Id: I5bafe8625122ca66415602c37cbca7d7f4c17742

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

index e503e30..a2a53e0 100644 (file)
@@ -347,6 +347,8 @@ production.
 * (bug 49090) Token-getting functions will fail when using jsonp callbacks.
 * (bug 52699) action=upload returns normalized file name on warning
   "exists-normalized" instead of filename to be uploaded to.
+* (bug 53884) action=edit will now return an error when the specified section
+  does not exist in the page.
 
 === Languages updated in 1.22===
 
index d14219f..bd61895 100644 (file)
@@ -280,6 +280,10 @@ class ApiEditPage extends ApiBase {
                        if ( $section == 0 && $params['section'] != '0' && $params['section'] != 'new' ) {
                                $this->dieUsage( "The section parameter must be set to an integer or 'new'", "invalidsection" );
                        }
+                       $content = $pageObj->getContent();
+                       if ( $section !== 0 && ( !$content || !$content->getSection( $section ) ) ) {
+                               $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
+                       }
                        $requestArray['wpSection'] = $params['section'];
                } else {
                        $requestArray['wpSection'] = '';