'imagerotate' => 'ApiImageRotate',
'revisiondelete' => 'ApiRevisionDelete',
'managetags' => 'ApiManageTags',
+ 'tag' => 'ApiTag',
);
/**
*/
private $mPrinter;
- private $mModuleMgr, $mResult;
+ private $mModuleMgr, $mResult, $mErrorFormatter, $mContinuationManager;
private $mAction;
private $mEnableWrite;
private $mInternalMode, $mSquidMaxage, $mModule;
Hooks::run( 'ApiMain::moduleManager', array( $this->mModuleMgr ) );
- $this->mResult = new ApiResult( $this );
+ $this->mResult = new ApiResult( $this->getConfig()->get( 'APIMaxResultSize' ) );
+ $this->mErrorFormatter = new ApiErrorFormatter_BackCompat( $this->mResult );
+ $this->mResult->setErrorFormatter( $this->mErrorFormatter );
+ $this->mResult->setMainForContinuation( $this );
+ $this->mContinuationManager = null;
$this->mEnableWrite = $enableWrite;
$this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
return $this->mResult;
}
+ /**
+ * Get the ApiErrorFormatter object associated with current request
+ * @return ApiErrorFormatter
+ */
+ public function getErrorFormatter() {
+ return $this->mErrorFormatter;
+ }
+
+ /**
+ * Get the continuation manager
+ * @return ApiContinuationManager|null
+ */
+ public function getContinuationManager() {
+ return $this->mContinuationManager;
+ }
+
+ /**
+ * Set the continuation manager
+ * @param ApiContinuationManager|null
+ */
+ public function setContinuationManager( $manager ) {
+ if ( $manager !== null ) {
+ if ( !$manager instanceof ApiContinuationManager ) {
+ throw new InvalidArgumentException( __METHOD__ . ': Was passed ' .
+ is_object( $manager ) ? get_class( $manager ) : gettype( $manager )
+ );
+ }
+ if ( $this->mContinuationManager !== null ) {
+ throw new UnexpectedValueException(
+ __METHOD__ . ': tried to set manager from ' . $manager->getSource() .
+ ' when a manager is already set from ' . $this->mContinuationManager->getSource()
+ );
+ }
+ }
+ $this->mContinuationManager = $manager;
+ }
+
/**
* Get the API module object. Only works after executeAction()
*
* Execute api request. Any errors will be handled if the API was called by the remote client.
*/
public function execute() {
- $this->profileIn();
if ( $this->mInternalMode ) {
$this->executeAction();
} else {
$this->executeActionWithErrorHandling();
}
-
- $this->profileOut();
}
/**
// Bug 63145: Rollback any open database transactions
if ( !( $e instanceof UsageException ) ) {
// UsageExceptions are intentional, so don't rollback if that's the case
- MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+ try {
+ MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+ } catch ( DBError $e2 ) {
+ // Rollback threw an exception too. Log it, but don't interrupt
+ // our regularly scheduled exception handling.
+ MWExceptionHandler::logException( $e2 );
+ }
}
// Allow extra cleanup and logging
// Reset and print just the error message
ob_clean();
- // If the error occurred during printing, do a printer->profileOut()
- $this->mPrinter->safeProfileOut();
$this->printResult( true );
}
// Printer may not be able to handle errors. This is particularly
// likely if the module returns something for getCustomPrinter().
if ( !$this->mPrinter->canPrintErrors() ) {
- $this->mPrinter->safeProfileOut();
$this->mPrinter = $this->createPrinterByName( self::API_DEFAULT_FORMAT );
}
// User entered incorrect parameters - generate error response
$errMessage = $e->getMessageArray();
$link = wfExpandUrl( wfScript( 'api' ) );
- ApiResult::setContent( $errMessage, "See $link for API usage" );
+ ApiResult::setContentValue( $errMessage, 'docref', "See $link for API usage" );
} else {
// Something is seriously wrong
if ( ( $e instanceof DBQueryError ) && !$config->get( 'ShowSQLErrors' ) ) {
'info' => '[' . MWExceptionHandler::getLogId( $e ) . '] ' . $info,
);
if ( $config->get( 'ShowExceptionDetails' ) ) {
- ApiResult::setContent(
+ ApiResult::setContentValue(
$errMessage,
+ 'trace',
MWExceptionHandler::getRedactedTraceAsString( $e )
);
}
}
// Remember all the warnings to re-add them later
- $oldResult = $result->getData();
- $warnings = isset( $oldResult['warnings'] ) ? $oldResult['warnings'] : null;
+ $warnings = $result->getResultData( array( 'warnings' ) );
$result->reset();
// Re-add the id
$this->checkAsserts( $params );
// Execute
- $module->profileIn();
$module->execute();
Hooks::run( 'APIAfterExecute', array( &$module ) );
- $module->profileOut();
$this->reportUnusedParams();
$this->setWarning( 'SECURITY WARNING: $wgDebugAPI is enabled' );
}
- $this->getResult()->cleanUpUTF8();
$printer = $this->mPrinter;
- $printer->profileIn();
-
$printer->initPrinter( false );
-
$printer->execute();
$printer->closePrinter();
- $printer->profileOut();
}
/**
}
$help[$k] = $v;
}
+ $help['datatypes'] = '';
$help['credits'] = '';
// Fill 'permissions'
$help['permissions'] .= Html::closeElement( 'dl' );
$help['permissions'] .= Html::closeElement( 'div' );
- // Fill 'credits', if applicable
+ // Fill 'datatypes' and 'credits', if applicable
if ( empty( $options['nolead'] ) ) {
- $help['credits'] .= Html::element( 'h' . min( 6, $options['headerlevel'] + 1 ),
- array( 'id' => '+credits', 'class' => 'apihelp-header' ),
+ $help['datatypes'] .= Html::rawelement( 'h' . min( 6, $options['headerlevel'] + 1 ),
+ array( 'id' => 'main/datatypes', 'class' => 'apihelp-header' ),
+ Html::element( 'span', array( 'id' => Sanitizer::escapeId( 'main/datatypes' ) ) ) .
+ $this->msg( 'api-help-datatypes-header' )->parse()
+ );
+ $help['datatypes'] .= $this->msg( 'api-help-datatypes' )->parseAsBlock();
+
+ $help['credits'] .= Html::rawelement( 'h' . min( 6, $options['headerlevel'] + 1 ),
+ array( 'id' => 'main/credits', 'class' => 'apihelp-header' ),
+ Html::element( 'span', array( 'id' => Sanitizer::escapeId( 'main/credits' ) ) ) .
$this->msg( 'api-credits-header' )->parse()
);
$help['credits'] .= $this->msg( 'api-credits' )->useDatabase( false )->parseAsBlock();