33 private $apiMain =
null;
45 $this->apiMain = $apiMain;
52 if ( $this->apiMain ) {
53 return $this->apiMain;
56 $context = RequestContext::getMain();
57 $session = $context->getRequest()->getSession();
62 $fauxRequest =
new FauxRequest( [],
true, $session );
63 $fauxRequest->setSessionId( $session->getSessionId() );
66 $fauxContext->setRequest( $fauxRequest );
67 $fauxContext->setUser( $context->getUser() );
68 $fauxContext->setLanguage( $context->getLanguage() );
70 $this->apiMain =
new ApiMain( $fauxContext,
true );
71 return $this->apiMain;
82 $this->
getApiMain()->getModuleManager()->addModule(
86 'class' => get_class( $module ),
87 'factory' =>
static function () use ( $module ) {
109 foreach ( $params as $key => $value ) {
110 $request->setVal( $key, $value );
119 foreach ( $ex->
getStatusValue()->getErrorsByType(
'error' ) as $error ) {
120 $msg = ApiMessage::create( $error );
127 'Unmapped action module error: ' . $ex->getMessage(),
132 $actionModuleResult = $apiMain->
getResult()->getResultData(
null, [
'Strip' =>
'all' ] );
187 array $actionModuleResult,
222 [
'actionModuleErrorCode' => $msg->
getApiCode() ]
238 $params[] = $this->makeMessageParam( $p );
249 private function makeMessageParam( $param ) {
250 if ( is_array( $param ) ) {
251 foreach ( $param as
$type => $value ) {
252 if (
$type ===
'list' ) {
255 foreach ( $value as $v ) {
256 $paramList[] = $this->makeMessageParam( $v );
259 return new ListParam( ParamType::TEXT, $paramList );
261 return new ScalarParam(
$type, $value );
265 return new ScalarParam( ParamType::TEXT, $param );
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.
WebRequest clone which takes values from a provided array.
Group all the pieces relevant to the context of a request into one instance.
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
Interface for messages with machine-readable data for use by the API.
getApiCode()
Returns a machine-readable code for use by the API.
getParams()
Returns the message parameters.
getKey()
Returns the message key.