Merge "browser acceptance tests"
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index 73eebca..884306a 100644 (file)
@@ -48,6 +48,9 @@ class ApiEditPage extends ApiBase {
                $apiResult = $this->getResult();
 
                if ( $params['redirect'] ) {
+                       if ( $params['prependtext'] === null && $params['appendtext'] === null && $params['section'] !== 'new' ) {
+                               $this->dieUsage( 'You have attempted to edit using the "redirect"-following mode, which must be used in conjuction with section=new, prependtext, or appendtext.', 'redirect-appendonly' );
+                       }
                        if ( $titleObj->isRedirect() ) {
                                $oldTitle = $titleObj;
 
@@ -167,7 +170,7 @@ class ApiEditPage extends ApiBase {
                                        $content = null;
                                } else {
                                        // Process the content for section edits
-                                       $section = intval( $params['section'] );
+                                       $section = $params['section'];
                                        $content = $content->getSection( $section );
 
                                        if ( !$content ) {
@@ -288,12 +291,12 @@ class ApiEditPage extends ApiBase {
                }
 
                if ( !is_null( $params['section'] ) ) {
-                       $section = intval( $params['section'] );
-                       if ( $section == 0 && $params['section'] != '0' && $params['section'] != 'new' ) {
-                               $this->dieUsage( "The section parameter must be set to an integer or 'new'", "invalidsection" );
+                       $section = $params['section'];
+                       if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
+                               $this->dieUsage( "The section parameter must be a valid section id or 'new'", "invalidsection" );
                        }
                        $content = $pageObj->getContent();
-                       if ( $section !== 0 && ( !$content || !$content->getSection( $section ) ) ) {
+                       if ( $section !== '0' && $section != 'new' && ( !$content || !$content->getSection( $section ) ) ) {
                                $this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
                        }
                        $requestArray['wpSection'] = $params['section'];
@@ -396,7 +399,6 @@ class ApiEditPage extends ApiBase {
 
                $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
                $wgRequest = $oldRequest;
-               global $wgMaxArticleSize;
 
                switch ( $status->value ) {
                        case EditPage::AS_HOOK_ERROR:
@@ -420,7 +422,7 @@ class ApiEditPage extends ApiBase {
 
                        case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
                        case EditPage::AS_CONTENT_TOO_BIG:
-                               $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) );
+                               $this->dieUsageMsg( array( 'contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) ) );
 
                        case EditPage::AS_READ_ONLY_PAGE_ANON:
                                $this->dieUsageMsg( 'noedit-anon' );
@@ -496,8 +498,6 @@ class ApiEditPage extends ApiBase {
        }
 
        public function getPossibleErrors() {
-               global $wgMaxArticleSize;
-
                return array_merge( parent::getPossibleErrors(),
                        $this->getTitleOrPageIdErrorMessage(),
                        array(
@@ -516,7 +516,7 @@ class ApiEditPage extends ApiBase {
                                array( 'spamdetected', 'spam' ),
                                array( 'summaryrequired' ),
                                array( 'blockedtext' ),
-                               array( 'contenttoobig', $wgMaxArticleSize ),
+                               array( 'contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) ),
                                array( 'noedit-anon' ),
                                array( 'noedit' ),
                                array( 'actionthrottledtext' ),
@@ -526,10 +526,10 @@ class ApiEditPage extends ApiBase {
                                array( 'editconflict' ),
                                array( 'emptynewsection' ),
                                array( 'unknownerror', 'retval' ),
-                               array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
+                               array( 'code' => 'nosuchsection', 'info' => 'There is no such section.' ),
                                array(
                                        'code' => 'invalidsection',
-                                       'info' => 'The section parameter must be set to an integer or \'new\''
+                                       'info' => 'The section parameter must be a valid section id or \'new\''
                                ),
                                array(
                                        'code' => 'sectionsnotsupported',
@@ -542,6 +542,10 @@ class ApiEditPage extends ApiBase {
                                array(
                                        'code' => 'appendnotsupported',
                                        'info' => 'This type of page can not be edited by appending or prepending text.' ),
+                               array(
+                                       'code' => 'redirect-appendonly',
+                                       'info' => 'You have attempted to edit using the "redirect"-following mode, which must be used in conjuction with section=new, prependtext, or appendtext.',
+                               ),
                                array(
                                        'code' => 'badformat',
                                        'info' => 'The requested serialization format can not be applied to the page\'s content model'