r62559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62558‎ | r62559 | r62560 >
Date:23:56, 15 February 2010
Author:reedy
Status:ok
Tags:
Comment:
Remove a couple of duplicated errors from ApiEditPage getPossibleErrors

Unindent one level in ApiMain substituteResultWithError
Modified paths:
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -350,11 +350,9 @@
351351 array( 'nosuchrevid', 'undo' ),
352352 array( 'nosuchrevid', 'undoafter' ),
353353 array( 'revwrongpage', 'id', 'text' ),
354 - array( 'revwrongpage', 'id', 'text' ),
355354 array( 'undo-failure' ),
356355 array( 'hashcheckfailed' ),
357356 array( 'hookaborted' ),
358 - array( 'hookaborted' ),
359357 array( 'noimageredirect-anon' ),
360358 array( 'noimageredirect-logged' ),
361359 array( 'spamdetected', 'spam' ),
Index: trunk/phase3/includes/api/ApiMain.php
@@ -339,54 +339,54 @@
340340 */
341341 protected function substituteResultWithError( $e ) {
342342
343 - // Printer may not be initialized if the extractRequestParams() fails for the main module
344 - if ( !isset ( $this->mPrinter ) ) {
345 - // The printer has not been created yet. Try to manually get formatter value.
346 - $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
347 - if ( !in_array( $value, $this->mFormatNames ) )
348 - $value = self::API_DEFAULT_FORMAT;
 343+ // Printer may not be initialized if the extractRequestParams() fails for the main module
 344+ if ( !isset ( $this->mPrinter ) ) {
 345+ // The printer has not been created yet. Try to manually get formatter value.
 346+ $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
 347+ if ( !in_array( $value, $this->mFormatNames ) )
 348+ $value = self::API_DEFAULT_FORMAT;
349349
350 - $this->mPrinter = $this->createPrinterByName( $value );
351 - if ( $this->mPrinter->getNeedsRawData() )
352 - $this->getResult()->setRawMode();
353 - }
 350+ $this->mPrinter = $this->createPrinterByName( $value );
 351+ if ( $this->mPrinter->getNeedsRawData() )
 352+ $this->getResult()->setRawMode();
 353+ }
354354
355 - if ( $e instanceof UsageException ) {
356 - //
357 - // User entered incorrect parameters - print usage screen
358 - //
359 - $errMessage = $e->getMessageArray();
 355+ if ( $e instanceof UsageException ) {
 356+ //
 357+ // User entered incorrect parameters - print usage screen
 358+ //
 359+ $errMessage = $e->getMessageArray();
360360
361 - // Only print the help message when this is for the developer, not runtime
362 - if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
363 - ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
 361+ // Only print the help message when this is for the developer, not runtime
 362+ if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
 363+ ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
364364
 365+ } else {
 366+ global $wgShowSQLErrors, $wgShowExceptionDetails;
 367+ //
 368+ // Something is seriously wrong
 369+ //
 370+ if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
 371+ $info = "Database query error";
365372 } else {
366 - global $wgShowSQLErrors, $wgShowExceptionDetails;
367 - //
368 - // Something is seriously wrong
369 - //
370 - if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
371 - $info = "Database query error";
372 - } else {
373 - $info = "Exception Caught: {$e->getMessage()}";
374 - }
375 -
376 - $errMessage = array (
377 - 'code' => 'internal_api_error_' . get_class( $e ),
378 - 'info' => $info,
379 - );
380 - ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
 373+ $info = "Exception Caught: {$e->getMessage()}";
381374 }
382375
383 - $this->getResult()->reset();
384 - $this->getResult()->disableSizeCheck();
385 - // Re-add the id
386 - $requestid = $this->getParameter( 'requestid' );
387 - if ( !is_null( $requestid ) )
388 - $this->getResult()->addValue( null, 'requestid', $requestid );
389 - $this->getResult()->addValue( null, 'error', $errMessage );
 376+ $errMessage = array (
 377+ 'code' => 'internal_api_error_' . get_class( $e ),
 378+ 'info' => $info,
 379+ );
 380+ ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
 381+ }
390382
 383+ $this->getResult()->reset();
 384+ $this->getResult()->disableSizeCheck();
 385+ // Re-add the id
 386+ $requestid = $this->getParameter( 'requestid' );
 387+ if ( !is_null( $requestid ) )
 388+ $this->getResult()->addValue( null, 'requestid', $requestid );
 389+ $this->getResult()->addValue( null, 'error', $errMessage );
 390+
391391 return $errMessage['code'];
392392 }
393393

Status & tagging log