MediaWiki REL1_35
|
Base class for REST route handlers. More...
Public Member Functions | |
applyConditionalResponseHeaders (ResponseInterface $response) | |
Modify the response, adding Last-Modified and ETag headers as indicated the values previously returned by ETag and getLastModified(). | |
checkPreconditions () | |
Check the conditional request headers and generate a response if appropriate. | |
execute () | |
Execute the handler. | |
getBodyValidator ( $contentType) | |
Fetch the BodyValidator. | |
getConfig () | |
Get the configuration array for the current route. | |
getParamSettings () | |
Fetch ParamValidator settings for parameters. | |
getRequest () | |
Get the current request. | |
getResponseFactory () | |
Get the ResponseFactory which can be used to generate Response objects. | |
getValidatedBody () | |
Fetch the validated body. | |
getValidatedParams () | |
Fetch the validated parameters. | |
init (Router $router, RequestInterface $request, array $config, ResponseFactory $responseFactory, HookContainer $hookContainer) | |
Initialise with dependencies from the Router. | |
needsReadAccess () | |
Indicates whether this route requires read rights. | |
needsWriteAccess () | |
Indicates whether this route requires write access. | |
validate (Validator $restValidator) | |
Validate the request parameters/attributes and body. | |
Public Attributes | |
const | PARAM_SOURCE = 'rest-param-source' |
(string) ParamValidator constant to specify the source of the parameter. | |
Protected Member Functions | |
getConditionalHeaderUtil () | |
Get a ConditionalHeaderUtil object. | |
getETag () | |
The subclass should override this to provide an ETag for the current request. | |
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 for the current request. | |
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. | |
urlEncodeTitle ( $title) | |
URL-encode titles in a "pretty" way. | |
Private Attributes | |
ConditionalHeaderUtil | $conditionalHeaderUtil |
array | $config |
HookContainer | $hookContainer |
HookRunner | $hookRunner |
RequestInterface | $request |
ResponseFactory | $responseFactory |
Router | $router |
mixed | $validatedBody |
array null | $validatedParams |
MediaWiki\Rest\Handler::applyConditionalResponseHeaders | ( | ResponseInterface | $response | ) |
Modify the response, adding Last-Modified and ETag headers as indicated the values previously returned by ETag and getLastModified().
This is called after execute() returns, and may be overridden.
Stable to override
ResponseInterface | $response |
Definition at line 219 of file Handler.php.
MediaWiki\Rest\Handler::checkPreconditions | ( | ) |
Check the conditional request headers and generate a response if appropriate.
This is called by the Router before execute() and may be overridden.
Stable to override
Definition at line 199 of file Handler.php.
|
abstract |
Execute the handler.
This is called after parameter validation. The return value can either be a Response or any type accepted by ResponseFactory::createFromReturnValue().
To automatically construct an error response, execute() should throw a RestException. Such exceptions will not be logged like a normal exception.
If execute() throws any other kind of exception, the exception will be logged and a generic 500 error page will be shown.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\ActionModuleBasedHandler, MediaWiki\Rest\Handler\CompareHandler, MediaWiki\Rest\Handler\ContributionsCountHandler, MediaWiki\Rest\Handler\SearchHandler, MediaWiki\Rest\Handler\UserContributionsHandler, and MediaWiki\Rest\SimpleHandler.
MediaWiki\Rest\Handler::getBodyValidator | ( | $contentType | ) |
Fetch the BodyValidator.
Stable to override
string | $contentType | Content type of the request. |
Reimplemented in MediaWiki\Rest\Handler\CreationHandler, and MediaWiki\Rest\Handler\UpdateHandler.
Definition at line 246 of file Handler.php.
Referenced by MediaWiki\Rest\Validator\Validator\validateBody().
|
protected |
Get a ConditionalHeaderUtil object.
On the first call to this method, the object will be initialized with validator values by calling getETag(), getLastModified() and hasRepresentation().
Definition at line 180 of file Handler.php.
References MediaWiki\Rest\ConditionalHeaderUtil\setValidators().
MediaWiki\Rest\Handler::getConfig | ( | ) |
Get the configuration array for the current route.
The return type declaration causes it to raise a fatal error if init() has not been called.
Definition at line 140 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\SearchHandler\postInitSetup(), and MediaWiki\Rest\Handler\UserContributionsHandler\postInitSetup().
|
protected |
The subclass should override this to provide an ETag for the current request.
This is called before execute() in order to decide whether to send a 304.
This must be a complete ETag, including double quotes.
See RFC 7232 ยง 2.3 for semantics.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\LanguageLinksHandler, MediaWiki\Rest\Handler\MediaFileHandler, MediaWiki\Rest\Handler\MediaLinksHandler, MediaWiki\Rest\Handler\PageHistoryHandler, MediaWiki\Rest\Handler\PageHTMLHandler, MediaWiki\Rest\Handler\PageSourceHandler, and MediaWiki\Rest\Handler\RevisionHandler.
Definition at line 324 of file Handler.php.
|
protected |
Get a HookContainer, for running extension hooks or for hook metadata.
Definition at line 279 of file Handler.php.
|
protected |
Get a HookRunner for running core hooks.
Definition at line 291 of file Handler.php.
|
protected |
The subclass should override this to provide the maximum last modified timestamp for the current request.
This is called before execute() in order to decide whether to send a 304.
The timestamp can be in any format accepted by ConvertibleTimestamp, or null to indicate that the timestamp is unknown.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\LanguageLinksHandler, MediaWiki\Rest\Handler\MediaFileHandler, MediaWiki\Rest\Handler\MediaLinksHandler, MediaWiki\Rest\Handler\PageHistoryCountHandler, MediaWiki\Rest\Handler\PageHistoryHandler, MediaWiki\Rest\Handler\PageHTMLHandler, MediaWiki\Rest\Handler\PageSourceHandler, and MediaWiki\Rest\Handler\RevisionHandler.
Definition at line 307 of file Handler.php.
MediaWiki\Rest\Handler::getParamSettings | ( | ) |
Fetch ParamValidator settings for parameters.
Every setting must include self::PARAM_SOURCE to specify which part of the request is to contain the parameter.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\CompareHandler, MediaWiki\Rest\Handler\ContributionsCountHandler, MediaWiki\Rest\Handler\LanguageLinksHandler, MediaWiki\Rest\Handler\LatestPageContentHandler, MediaWiki\Rest\Handler\MediaFileHandler, MediaWiki\Rest\Handler\MediaLinksHandler, MediaWiki\Rest\Handler\PageHistoryCountHandler, MediaWiki\Rest\Handler\PageHistoryHandler, MediaWiki\Rest\Handler\RevisionHandler, MediaWiki\Rest\Handler\SearchHandler, MediaWiki\Rest\Handler\UpdateHandler, and MediaWiki\Rest\Handler\UserContributionsHandler.
Definition at line 234 of file Handler.php.
Referenced by MediaWiki\Rest\SimpleHandler\execute().
MediaWiki\Rest\Handler::getRequest | ( | ) |
Get the current request.
The return type declaration causes it to raise a fatal error if init() has not yet been called.
Definition at line 129 of file Handler.php.
Referenced by MediaWiki\Rest\SimpleHandler\execute().
MediaWiki\Rest\Handler::getResponseFactory | ( | ) |
Get the ResponseFactory which can be used to generate Response objects.
This will raise a fatal error if init() has not been called.
Definition at line 151 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute(), MediaWiki\Rest\Handler\CompareHandler\execute(), MediaWiki\Rest\Handler\RevisionHandler\run(), MediaWiki\Rest\Handler\LanguageLinksHandler\run(), MediaWiki\Rest\Handler\MediaFileHandler\run(), MediaWiki\Rest\Handler\MediaLinksHandler\run(), MediaWiki\Rest\Handler\PageHistoryHandler\run(), and MediaWiki\Rest\Handler\PageHistoryCountHandler\run().
|
protected |
Get the Router.
The return type declaration causes it to raise a fatal error if init() has not yet been called.
Definition at line 77 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\CreationHandler\mapActionModuleResponse().
|
protected |
Get the URL of this handler's endpoint.
Supports the substitution of path parameters, and additions of query parameters.
string[] | $pathParams | Path parameters to be injected into the path |
string[] | $queryParams | Query parameters to be attached to the URL |
Definition at line 92 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\UserContributionsHandler\constructURLs(), and MediaWiki\Rest\Handler\PageHistoryHandler\processDbResults().
MediaWiki\Rest\Handler::getValidatedBody | ( | ) |
Fetch the validated body.
Definition at line 269 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\CreationHandler\getActionModuleParameters(), MediaWiki\Rest\Handler\UpdateHandler\getActionModuleParameters(), MediaWiki\Rest\Handler\EditHandler\getActionModuleToken(), MediaWiki\Rest\Handler\UpdateHandler\getConflictData(), and MediaWiki\Rest\Handler\CreationHandler\getTitleParameter().
MediaWiki\Rest\Handler::getValidatedParams | ( | ) |
Fetch the validated parameters.
This must be called after validate() is called. During execute() is fine.
\RuntimeException If validate() has not been called
Definition at line 257 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\UserContributionsHandler\constructURLs(), MediaWiki\Rest\Handler\SearchHandler\createSearchEngine(), MediaWiki\Rest\Handler\SearchHandler\doSearch(), MediaWiki\Rest\Handler\ContributionsCountHandler\execute(), MediaWiki\Rest\Handler\UserContributionsHandler\execute(), MediaWiki\Rest\SimpleHandler\execute(), MediaWiki\Rest\Handler\UpdateHandler\getConflictData(), MediaWiki\Rest\Handler\PageHistoryCountHandler\getCount(), MediaWiki\Rest\Handler\CompareHandler\getRevision(), MediaWiki\Rest\Handler\RevisionHandler\getRevision(), MediaWiki\Rest\Handler\UserContributionsHandler\getTargetUser(), MediaWiki\Rest\Handler\LanguageLinksHandler\getTitle(), MediaWiki\Rest\Handler\LatestPageContentHandler\getTitle(), MediaWiki\Rest\Handler\MediaFileHandler\getTitle(), MediaWiki\Rest\Handler\MediaLinksHandler\getTitle(), MediaWiki\Rest\Handler\PageHistoryCountHandler\getTitle(), MediaWiki\Rest\Handler\PageHistoryHandler\getTitle(), MediaWiki\Rest\Handler\UpdateHandler\getTitleParameter(), MediaWiki\Rest\Handler\PageHistoryHandler\run(), and MediaWiki\Rest\Handler\PageHistoryCountHandler\validateParameterCombination().
|
protected |
The subclass should override this to indicate whether the resource exists.
This is used for wildcard validators, for example "If-Match: *" fails if the resource does not exist.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\LanguageLinksHandler, MediaWiki\Rest\Handler\MediaFileHandler, MediaWiki\Rest\Handler\MediaLinksHandler, MediaWiki\Rest\Handler\PageHistoryHandler, and MediaWiki\Rest\Handler\RevisionHandler.
Definition at line 337 of file Handler.php.
|
final |
Initialise with dependencies from the Router.
This is called after construction.
Definition at line 60 of file Handler.php.
References MediaWiki\Rest\Handler\postInitSetup().
MediaWiki\Rest\Handler::needsReadAccess | ( | ) |
Indicates whether this route requires read rights.
The handler should override this if it does not need to read from the wiki. This is uncommon, but may be useful for login and other account management APIs.
Stable to override
Definition at line 352 of file Handler.php.
MediaWiki\Rest\Handler::needsWriteAccess | ( | ) |
Indicates whether this route requires write access.
The handler should override this if the route does not need to write to the database.
This should return true for routes that may require synchronous database writes. Modules that do not need such writes should also not rely on master database access, since only read queries are needed and each master DB is a single point of failure.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\EditHandler, MediaWiki\Rest\Handler\LanguageLinksHandler, MediaWiki\Rest\Handler\LatestPageContentHandler, MediaWiki\Rest\Handler\MediaFileHandler, MediaWiki\Rest\Handler\MediaLinksHandler, MediaWiki\Rest\Handler\PageHistoryCountHandler, MediaWiki\Rest\Handler\PageHistoryHandler, MediaWiki\Rest\Handler\RevisionHandler, and MediaWiki\Rest\Handler\SearchHandler.
Definition at line 370 of file Handler.php.
|
protected |
The handler can override this to do any necessary setup after init() is called to inject the dependencies.
Stable to override
Reimplemented in MediaWiki\Rest\Handler\SearchHandler, and MediaWiki\Rest\Handler\UserContributionsHandler.
Definition at line 380 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\init().
|
protected |
URL-encode titles in a "pretty" way.
Keeps intact ;$!*(),~: (urlencode does not, but wfUrlencode does). Encodes spaces as underscores (wfUrlencode does not). Encodes slashes (wfUrlencode does not, but keeping them messes with REST pathes). Encodes pluses (this is not necessary, and may change).
string | $title |
Definition at line 111 of file Handler.php.
References $title.
Referenced by MediaWiki\Rest\Handler\CreationHandler\mapActionModuleResponse().
MediaWiki\Rest\Handler::validate | ( | Validator | $restValidator | ) |
Validate the request parameters/attributes and body.
If there is a validation failure, a response with an error message should be returned or an HttpException should be thrown.
Stable to override
Validator | $restValidator |
HttpException | On validation failure. |
Definition at line 164 of file Handler.php.
References MediaWiki\Rest\Validator\Validator\validateBody(), and MediaWiki\Rest\Validator\Validator\validateParams().
|
private |
Definition at line 43 of file Handler.php.
|
private |
Definition at line 31 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\SearchHandler\__construct().
|
private |
Definition at line 46 of file Handler.php.
|
private |
Definition at line 49 of file Handler.php.
|
private |
Definition at line 28 of file Handler.php.
Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().
|
private |
Definition at line 34 of file Handler.php.
|
private |
Definition at line 25 of file Handler.php.
|
private |
Definition at line 40 of file Handler.php.
|
private |
Definition at line 37 of file Handler.php.
Referenced by MediaWiki\Rest\SimpleHandler\execute().
const MediaWiki\Rest\Handler::PARAM_SOURCE = 'rest-param-source' |
(string) ParamValidator constant to specify the source of the parameter.
Value must be 'path', 'query', or 'post'.
Definition at line 22 of file Handler.php.
Referenced by MediaWiki\Rest\SimpleHandler\execute(), MediaWiki\Rest\Handler\CompareHandler\getParamSettings(), and MediaWiki\Rest\Validator\Validator\validateParams().