MediaWiki master
MediaWiki\Rest\Handler\ActionModuleBasedHandler Class Reference

Base class for REST handlers that are implemented by mapping to an existing ApiModule. More...

Inherits MediaWiki\Rest\Handler.

Inherited by MediaWiki\Rest\Handler\EditHandler.

Collaboration diagram for MediaWiki\Rest\Handler\ActionModuleBasedHandler:

Public Member Functions

 execute ()
 Main execution method, implemented to delegate execution to ApiMain.
 
 getApiMain ()
 
 overrideActionModule (string $name, string $group, ApiBase $module)
 Overrides an action API module.
 
 setApiMain (ApiMain $apiMain)
 Set main action API entry point for testing.
 
- Public Member Functions inherited from MediaWiki\Rest\Handler
 applyCacheControl (ResponseInterface $response)
 Apply cache control to enforce privacy.
 
 applyConditionalResponseHeaders (ResponseInterface $response)
 Apply verifier headers to the response, per RFC 7231 ยง7.2.
 
 checkPreconditions ()
 Check the conditional request headers and generate a response if appropriate.
 
 checkSession ()
 Check the session (and session provider)
 
 getAuthority ()
 Get the current acting authority.
 
 getBodyValidator ( $contentType)
 Fetch the BodyValidator.
 
 getConfig ()
 Get the configuration array for the current route.
 
 getOpenApiSpec (string $method)
 Returns an OpenAPI Operation Object specification structure as an associative array.
 
 getParamSettings ()
 Fetch ParamValidator settings for parameters.
 
 getPath ()
 Returns the path this handler is bound to, including path variables.
 
 getRequest ()
 Get the current request.
 
 getResponseFactory ()
 Get the ResponseFactory which can be used to generate Response objects.
 
 getSession ()
 Get the Session.
 
 getSupportedPathParams ()
 Get a list of parameter placeholders present in the route's path as returned by getPath().
 
 getValidatedBody ()
 Fetch the validated body.
 
 getValidatedParams ()
 Fetch the validated parameters.
 
 init (Router $router, RequestInterface $request, array $config, Authority $authority, ResponseFactory $responseFactory, HookContainer $hookContainer, Session $session)
 Initialise with dependencies from the Router.
 
 initContext (Router $router, array $routeConfig)
 Injects information about the handler's context in the Router.
 
 needsReadAccess ()
 Indicates whether this route requires read rights.
 
 needsWriteAccess ()
 Indicates whether this route requires write access.
 
 parseBodyData (RequestInterface $request)
 Returns the parsed body of the request.
 
 requireSafeAgainstCsrf ()
 Indicates whether this route can be accessed only by session providers safe vs csrf.
 
 validate (Validator $restValidator)
 Validate the request parameters/attributes and body.
 

Protected Member Functions

 getActionModuleParameters ()
 Maps a REST API request to an action API request.
 
 getUser ()
 
 makeMessageValue (IApiMessage $msg)
 Constructs a MessageValue from an IApiMessage.
 
 mapActionModuleResponse (WebResponse $actionModuleResponse, array $actionModuleResult, Response $response)
 Transfers relevant information, such as header values, from the WebResponse constructed by the action API call to a REST Response object.
 
 mapActionModuleResult (array $data)
 Maps an action API result to a REST API result.
 
 throwHttpExceptionForActionModuleError (IApiMessage $msg, $statusCode=400)
 Throws a HttpException for a given IApiMessage that represents an error.
 
- Protected Member Functions inherited from MediaWiki\Rest\Handler
 detectExtraneousBodyFields (Validator $restValidator)
 Subclasses may override this to disable or modify checks for extraneous body fields.
 
 getConditionalHeaderUtil ()
 Get a ConditionalHeaderUtil object.
 
 getETag ()
 The subclass should override this to provide an ETag for the current state of the requested resource.
 
 getHookContainer ()
 Get a HookContainer, for running extension hooks or for hook metadata.
 
 getHookRunner ()
 Get a HookRunner for running core hooks.
 
 getLastModified ()
 The subclass should override this to provide the maximum last modified timestamp of the requested resource.
 
 getRequestSpec ()
 Returns an OpenAPI Request Body Object specification structure as an associative array.
 
 getResponseBodySchema ()
 Returns an OpenAPI Schema Object specification structure as an associative array.
 
 getResponseSpec ()
 Returns an OpenAPI Responses Object specification structure as an associative array.
 
 getRouter ()
 Get the Router.
 
 getRouteUrl ( $pathParams=[], $queryParams=[])
 Get the URL of this handler's endpoint.
 
 hasRepresentation ()
 The subclass should override this to indicate whether the resource exists.
 
 postInitSetup ()
 The handler can override this to do any necessary setup after init() is called to inject the dependencies.
 
 postValidationSetup ()
 The handler can override this to do any necessary setup after validate() has been called.
 
 urlEncodeTitle ( $title)
 URL-encode titles in a "pretty" way.
 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\Rest\Handler
const KNOWN_PARAM_SOURCES = Validator::KNOWN_PARAM_SOURCES
 
const PARAM_DESCRIPTION = Validator::PARAM_DESCRIPTION
 
const PARAM_SOURCE = Validator::PARAM_SOURCE
 

Detailed Description

Base class for REST handlers that are implemented by mapping to an existing ApiModule.

Stability: stable
to extend

Definition at line 25 of file ActionModuleBasedHandler.php.

Member Function Documentation

◆ execute()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::execute ( )

Main execution method, implemented to delegate execution to ApiMain.

Which action API module gets called is controlled by the parameter array returned by getActionModuleParameters(). The response from the action module is passed to mapActionModuleResult(), any ApiUsageException thrown will be converted to a HttpException by throwHttpExceptionForActionModuleError().

Returns
mixed

Reimplemented from MediaWiki\Rest\Handler.

Definition at line 101 of file ActionModuleBasedHandler.php.

References $params, ApiMain\execute(), MediaWiki\Rest\Handler\ActionModuleBasedHandler\getActionModuleParameters(), MediaWiki\Rest\Handler\ActionModuleBasedHandler\getApiMain(), MediaWiki\Context\ContextSource\getRequest(), MediaWiki\Rest\Handler\getResponseFactory(), ApiMain\getResult(), ApiUsageException\getStatusValue(), MediaWiki\Rest\Handler\ActionModuleBasedHandler\mapActionModuleResponse(), MediaWiki\Rest\Handler\ActionModuleBasedHandler\mapActionModuleResult(), and MediaWiki\Rest\Handler\ActionModuleBasedHandler\throwHttpExceptionForActionModuleError().

◆ getActionModuleParameters()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::getActionModuleParameters ( )
abstractprotected

Maps a REST API request to an action API request.

Implementations typically use information returned by $this->getValidatedBody() and $this->getValidatedParams() to construct the return value.

The return value of this method controls which action module is called by execute().

Returns
array Emulated request parameters to be passed to the ApiModule.

Reimplemented in MediaWiki\Rest\Handler\CreationHandler, and MediaWiki\Rest\Handler\UpdateHandler.

Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().

◆ getApiMain()

◆ getUser()

◆ makeMessageValue()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::makeMessageValue ( IApiMessage $msg)
protected

◆ mapActionModuleResponse()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::mapActionModuleResponse ( WebResponse $actionModuleResponse,
array $actionModuleResult,
Response $response )
protected

Transfers relevant information, such as header values, from the WebResponse constructed by the action API call to a REST Response object.

Subclasses may override this to provide special case handling for header fields. For mapping the response body, override mapActionModuleResult() instead.

Subclasses overriding this method should call this method in the parent class, to preserve baseline behavior.

Stability: stable
to override
Parameters
WebResponse$actionModuleResponse
array$actionModuleResult
Response$response

Reimplemented in MediaWiki\Rest\Handler\CreationHandler, and MediaWiki\Rest\Handler\EditHandler.

Definition at line 183 of file ActionModuleBasedHandler.php.

Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().

◆ mapActionModuleResult()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::mapActionModuleResult ( array $data)
abstractprotected

Maps an action API result to a REST API result.

Parameters
array$dataData structure retrieved from the ApiResult returned by the ApiModule
Returns
mixed Data structure to be converted to JSON and wrapped in a REST Response. Will be processed by ResponseFactory::createFromReturnValue().

Reimplemented in MediaWiki\Rest\Handler\EditHandler, and MediaWiki\Rest\Handler\UpdateHandler.

Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().

◆ overrideActionModule()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::overrideActionModule ( string $name,
string $group,
ApiBase $module )

Overrides an action API module.

Used for testing.

Parameters
string$name
string$group
ApiBase$module

Definition at line 79 of file ActionModuleBasedHandler.php.

References MediaWiki\Rest\Handler\ActionModuleBasedHandler\getApiMain().

◆ setApiMain()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::setApiMain ( ApiMain $apiMain)

Set main action API entry point for testing.

Parameters
ApiMain$apiMain

Definition at line 42 of file ActionModuleBasedHandler.php.

◆ throwHttpExceptionForActionModuleError()

MediaWiki\Rest\Handler\ActionModuleBasedHandler::throwHttpExceptionForActionModuleError ( IApiMessage $msg,
$statusCode = 400 )
protected

Throws a HttpException for a given IApiMessage that represents an error.

Never returns normally.

Subclasses may override this to provide mappings for specific error codes, typically based on $msg->getApiCode(). Subclasses overriding this method must always either throw an exception, or call this method in the parent class, which then throws an exception.

Stability: stable
to override
Parameters
IApiMessage$msgA message object representing an error in an action module, typically from calling getStatusValue()->getErrorsByType( 'error' ) on an ApiUsageException.
int$statusCodeThe HTTP status indicated by the original exception
Exceptions
HttpExceptionalways.

Reimplemented in MediaWiki\Rest\Handler\EditHandler, and MediaWiki\Rest\Handler\UpdateHandler.

Definition at line 209 of file ActionModuleBasedHandler.php.

References IApiMessage\getApiCode(), and MediaWiki\Rest\Handler\ActionModuleBasedHandler\makeMessageValue().

Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().


The documentation for this class was generated from the following file: