phpcs fixups for line length
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index c1598c8..f697b6f 100644 (file)
@@ -48,8 +48,12 @@ 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 ( $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;
@@ -195,9 +199,9 @@ class ApiEditPage extends ApiBase {
                                        list( $params['undo'], $params['undoafter'] ) =
                                                array( $params['undoafter'], $params['undo'] );
                                }
-                               $undoafterRev = Revision::newFromID( $params['undoafter'] );
+                               $undoafterRev = Revision::newFromId( $params['undoafter'] );
                        }
-                       $undoRev = Revision::newFromID( $params['undo'] );
+                       $undoRev = Revision::newFromId( $params['undo'] );
                        if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) );
                        }
@@ -252,8 +256,10 @@ class ApiEditPage extends ApiBase {
                        'format' => $contentFormat,
                        'model' => $contentHandler->getModelID(),
                        'wpEditToken' => $params['token'],
-                       'wpIgnoreBlankSummary' => '',
-                       'wpIgnoreBlankArticle' => true
+                       'wpIgnoreBlankSummary' => true,
+                       'wpIgnoreBlankArticle' => true,
+                       'wpIgnoreSelfRedirect' => true,
+                       'bot' => $params['bot'],
                );
 
                if ( !is_null( $params['summary'] ) ) {
@@ -294,10 +300,13 @@ class ApiEditPage extends ApiBase {
                if ( !is_null( $params['section'] ) ) {
                        $section = $params['section'];
                        if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
-                               $this->dieUsage( "The section parameter must be a valid section id or 'new'", "invalidsection" );
+                               $this->dieUsage( "The section parameter must be a valid section id or 'new'",
+                                       "invalidsection" );
                        }
                        $content = $pageObj->getContent();
-                       if ( $section !== '0' && $section != 'new' && ( !$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'];
@@ -381,7 +390,7 @@ class ApiEditPage extends ApiBase {
                // Run hooks
                // Handle APIEditBeforeSave parameters
                $r = array();
-               if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
+               if ( !Hooks::run( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
                        if ( count( $r ) ) {
                                $r['result'] = 'Failure';
                                $apiResult->addValue( null, $this->getModuleName(), $r );
@@ -400,13 +409,20 @@ class ApiEditPage extends ApiBase {
                $oldRequest = $wgRequest;
                $wgRequest = $req;
 
-               $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
+               $status = $ep->attemptSave( $result );
                $wgRequest = $oldRequest;
 
                switch ( $status->value ) {
                        case EditPage::AS_HOOK_ERROR:
                        case EditPage::AS_HOOK_ERROR_EXPECTED:
-                               $this->dieUsageMsg( 'hookaborted' );
+                               if ( isset( $status->apiHookResult ) ) {
+                                       $r = $status->apiHookResult;
+                                       $r['result'] = 'Failure';
+                                       $apiResult->addValue( null, $this->getModuleName(), $r );
+                                       return;
+                               } else {
+                                       $this->dieUsageMsg( 'hookaborted' );
+                               }
 
                        case EditPage::AS_PARSE_ERROR:
                                $this->dieUsage( $status->getMessage(), 'parseerror' );
@@ -454,7 +470,6 @@ class ApiEditPage extends ApiBase {
                        case EditPage::AS_CONFLICT_DETECTED:
                                $this->dieUsageMsg( 'editconflict' );
 
-                       // case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
                        case EditPage::AS_TEXTBOX_EMPTY:
                                $this->dieUsageMsg( 'emptynewsection' );
 
@@ -479,6 +494,7 @@ class ApiEditPage extends ApiBase {
                                break;
 
                        case EditPage::AS_SUMMARY_NEEDED:
+                               // Shouldn't happen since we set wpIgnoreBlankSummary, but just in case
                                $this->dieUsageMsg( 'summaryrequired' );
 
                        case EditPage::AS_END: