Merge "Replace Pakaran with Punjabi"
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index 22e4ded..bd61895 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' );
+                                       }
                                }
                        }
 
@@ -275,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'] = '';
@@ -324,7 +333,7 @@ class ApiEditPage extends ApiBase {
 
                // The following is needed to give the hook the full content of the
                // new revision rather than just the current section. (Bug 52077)
-               if ( !is_null( $params['section'] ) && $contentHandler->supportsSections() ) {
+               if ( !is_null( $params['section'] ) && $contentHandler->supportsSections() && $titleObj->exists() ) {
 
                        $sectionTitle = '';
                        // If sectiontitle is set, use it, otherwise use the summary as the section title (for