From 7478ad3576559e28db3450bef93b638f5978468e Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Mon, 15 Feb 2010 23:56:09 +0000 Subject: [PATCH] Remove a couple of duplicated errors from ApiEditPage getPossibleErrors Unindent one level in ApiMain substituteResultWithError --- includes/api/ApiEditPage.php | 2 - includes/api/ApiMain.php | 82 ++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 5c434d330c..3a52405e81 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -350,11 +350,9 @@ class ApiEditPage extends ApiBase { array( 'nosuchrevid', 'undo' ), array( 'nosuchrevid', 'undoafter' ), array( 'revwrongpage', 'id', 'text' ), - array( 'revwrongpage', 'id', 'text' ), array( 'undo-failure' ), array( 'hashcheckfailed' ), array( 'hookaborted' ), - array( 'hookaborted' ), array( 'noimageredirect-anon' ), array( 'noimageredirect-logged' ), array( 'spamdetected', 'spam' ), diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 0686fe540e..712037fd6c 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -339,53 +339,53 @@ class ApiMain extends ApiBase { */ protected function substituteResultWithError( $e ) { - // Printer may not be initialized if the extractRequestParams() fails for the main module - if ( !isset ( $this->mPrinter ) ) { - // The printer has not been created yet. Try to manually get formatter value. - $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT ); - if ( !in_array( $value, $this->mFormatNames ) ) - $value = self::API_DEFAULT_FORMAT; - - $this->mPrinter = $this->createPrinterByName( $value ); - if ( $this->mPrinter->getNeedsRawData() ) - $this->getResult()->setRawMode(); - } + // Printer may not be initialized if the extractRequestParams() fails for the main module + if ( !isset ( $this->mPrinter ) ) { + // The printer has not been created yet. Try to manually get formatter value. + $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT ); + if ( !in_array( $value, $this->mFormatNames ) ) + $value = self::API_DEFAULT_FORMAT; + + $this->mPrinter = $this->createPrinterByName( $value ); + if ( $this->mPrinter->getNeedsRawData() ) + $this->getResult()->setRawMode(); + } - if ( $e instanceof UsageException ) { - // - // User entered incorrect parameters - print usage screen - // - $errMessage = $e->getMessageArray(); + if ( $e instanceof UsageException ) { + // + // User entered incorrect parameters - print usage screen + // + $errMessage = $e->getMessageArray(); - // Only print the help message when this is for the developer, not runtime - if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) - ApiResult :: setContent( $errMessage, $this->makeHelpMsg() ); + // Only print the help message when this is for the developer, not runtime + if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) + ApiResult :: setContent( $errMessage, $this->makeHelpMsg() ); + } else { + global $wgShowSQLErrors, $wgShowExceptionDetails; + // + // Something is seriously wrong + // + if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) { + $info = "Database query error"; } else { - global $wgShowSQLErrors, $wgShowExceptionDetails; - // - // Something is seriously wrong - // - if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) { - $info = "Database query error"; - } else { - $info = "Exception Caught: {$e->getMessage()}"; - } - - $errMessage = array ( - 'code' => 'internal_api_error_' . get_class( $e ), - 'info' => $info, - ); - ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" ); + $info = "Exception Caught: {$e->getMessage()}"; } - $this->getResult()->reset(); - $this->getResult()->disableSizeCheck(); - // Re-add the id - $requestid = $this->getParameter( 'requestid' ); - if ( !is_null( $requestid ) ) - $this->getResult()->addValue( null, 'requestid', $requestid ); - $this->getResult()->addValue( null, 'error', $errMessage ); + $errMessage = array ( + 'code' => 'internal_api_error_' . get_class( $e ), + 'info' => $info, + ); + ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" ); + } + + $this->getResult()->reset(); + $this->getResult()->disableSizeCheck(); + // Re-add the id + $requestid = $this->getParameter( 'requestid' ); + if ( !is_null( $requestid ) ) + $this->getResult()->addValue( null, 'requestid', $requestid ); + $this->getResult()->addValue( null, 'error', $errMessage ); return $errMessage['code']; } -- 2.20.1