14use MediaWiki\Rest\Handler\Helper\RestStatusTrait;
31 private $apiMain =
null;
43 $this->apiMain = $apiMain;
50 if ( $this->apiMain ) {
51 return $this->apiMain;
54 $context = RequestContext::getMain();
55 $session = $context->getRequest()->getSession();
60 $fauxRequest =
new FauxRequest( [],
true, $session );
61 $fauxRequest->setSessionId( $session->getSessionId() );
64 $fauxContext->setRequest( $fauxRequest );
65 $fauxContext->setUser( $context->getUser() );
66 $fauxContext->setLanguage( $context->getLanguage() );
68 $this->apiMain =
new ApiMain( $fauxContext,
true );
69 return $this->apiMain;
80 $this->
getApiMain()->getModuleManager()->addModule(
84 'class' => get_class( $module ),
85 'factory' =>
static function () use ( $module ) {
107 foreach (
$params as $key => $value ) {
108 $request->setVal( $key, $value );
117 foreach ( $ex->
getStatusValue()->getErrorsByType(
'error' ) as $error ) {
118 $msg = ApiMessage::create( $error );
125 'Unmapped action module error: ' . $ex->getMessage(),
130 $actionModuleResult = $apiMain->
getResult()->getResultData(
null, [
'Strip' =>
'all' ] );
185 array $actionModuleResult,
220 [
'actionModuleErrorCode' => $msg->
getApiCode() ]
232 return $this->getMessageValueConverter()->convertMessage( $msg );
array $params
The job parameters.
This abstract class implements many basic API functions, and is the base of all API classes.
This is the main API class, used for both external and internal processing.
getResult()
Get the ApiResult object associated with current request.
execute()
Execute api request.
Extension of Message implementing IApiMessage.
Exception used to abort API execution with an error.
getStatusValue()
Fetch the error status.
Group all the pieces relevant to the context of a request into one instance.
Interface for messages with machine-readable data for use by the API.
getApiCode()
Returns a machine-readable code for use by the API.