|
MediaWiki master
|
Base class for Parsoid handlers. More...
Inherits MediaWiki\Rest\Handler.
Inherited by MediaWiki\Rest\Handler\TransformHandler.

Public Member Functions | |
| __construct (private readonly RevisionLookup $revisionLookup, protected readonly SiteConfig $siteConfig, protected readonly PageConfigFactory $pageConfigFactory, protected readonly DataAccess $dataAccess, private readonly PageBundleParserOutputConverter $pageBundleParserOutputConverter,) | |
| execute () | |
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 \MediaWiki\Rest\HttpException. 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.
| |
| getSupportedRequestTypes () | |
| Returns the content types that should be accepted by parseBodyData(). | |
| 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. | |
| applyDeprecationHeader (ResponseInterface $response) | |
| Apply Deprecation header per RFC 9745. | |
| 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. | |
| getBodyParamSettings () | |
| Fetch ParamValidator settings for body fields. | |
| getBodyValidator ( $contentType) | |
| Fetch the BodyValidator. | |
| getConfig () | |
| Get the configuration array for the current route. | |
| getHeaderParamSettings () | |
| Fetch ParamValidator settings for request headers. | |
| getHttpMethod () | |
| Returns the http method for which this module was registered. | |
| 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 relative to the module prefix. | |
| getRequest () | |
| Get the current request. | |
| getRequestBodyDescription () | |
| Returns a description for the OpenAPI Request Body Object, or null if no description should be included. | |
| getRequestBodyExample (string $mediaType) | |
| Returns an example value for the OpenAPI Media Type Object, or null if no example should be included. | |
| getResponseFactory () | |
| Get the ResponseFactory which can be used to generate Response objects. | |
| getResponseHeaderSettings () | |
| Fetch the settings array mapping response headers to their descriptions and schemas. | |
| getRoutePath () | |
| Returns the path this handler is bound to relative to the base router prefix. | |
| 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. | |
| getValidatedBodyArray () | |
| Fetch the validated body, asserting that it is an array. | |
| getValidatedParams () | |
| Fetch the validated parameters. | |
| initContext (Module $module, string $path, array $routeConfig, array $openApiSpec=[]) | |
| Injects information about the handler's context in the Module. | |
| initForExecute (RequestInterface $request, ResponseFactory $responseFactory) | |
| Initialise for execution based on the given request. | |
| initServices (Authority $authority, HookContainer $hookContainer) | |
| Inject service objects. | |
| initSession (Session $session) | |
| Inject session information. | |
| needsReadAccess () | |
| Indicates whether this route requires read rights. | |
| needsWriteAccess () | |
| Indicates whether this route requires write access to the wiki. | |
| 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. | |
Static Public Member Functions | |
| static | factory () |
Protected Member Functions | |
| acceptable (array &$attribs) | |
| This method checks if we support the requested content formats As a side-effect, it updates $attribs to set outputContentVersion that Parsoid should generate based on request headers. | |
| assertDomainIsCorrect ( $domain) | |
| Verify that the {domain} path parameter matches the actual domain. | |
| getHtmlInputTransformHelper (array $attribs, string $html, PageIdentity $page) | |
| getOpts (array $body, RequestInterface $request) | |
| getPageContentEndpoint (string $format=ParsoidFormatHelper::FORMAT_HTML) | |
| Get the path for the page content endpoint. | |
| getParsedBody () | |
| Get the parsed body by content-type. | |
| & | getRequestAttributes () |
| Rough equivalent of req.local from Parsoid-JS. | |
| getRevisionContentEndpoint (string $format=ParsoidFormatHelper::FORMAT_HTML) | |
| Get the path for the page content endpoint. | |
| getTransformEndpoint (string $format=ParsoidFormatHelper::FORMAT_HTML) | |
| Get the path for the transform endpoint. | |
| html2wt ( $page, array $attribs, string $html) | |
| languageConversion (PageConfig $pageConfig, array $attribs, array $revision) | |
| Do variant conversion on a document. | |
| newParsoid () | |
| parseHTML (string $html, bool $validateXMLNames=false) | |
| pb2pb (array $attribs) | |
| Pagebundle -> pagebundle helper. | |
| tryToCreatePageConfig (array $attribs, ?string $wikitextOverride=null, bool $html2WtMode=false) | |
| Try to create a PageConfig object. | |
| tryToCreatePageIdentity (array $attribs) | |
| Try to create a PageIdentity object. | |
| updateRedLinks (PageConfig $pageConfig, array $attribs, array $revision) | |
| Update red links on a document. | |
| wt2html (PageConfig $pageConfig, array $attribs, ?string $wikitext=null) | |
| Wikitext -> HTML helper. | |
| Protected Member Functions inherited from MediaWiki\Rest\Handler | |
| detectExtraneousBodyFields (Validator $restValidator) | |
| Subclasses may override this to disable or modify checks for extraneous body fields. | |
| generateResponseSpec (string $method) | |
| Returns an OpenAPI Responses Object specification structure as an associative array. | |
| getConditionalHeaderUtil () | |
| Get a ConditionalHeaderUtil object. | |
| getDeprecatedDate () | |
| Returns the timestamp at which this was or will be deprecated, or null if none. | |
| 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. | |
| getJsonLocalizer () | |
| Get a JsonLocalizer object. | |
| getLastModified () | |
| The subclass should override this to provide the maximum last modified timestamp of the requested resource. | |
| getModule () | |
| Get the Module this handler belongs to. | |
| getModulePathPrefix () | |
| Get the path prefix of the Module this handler belongs to. | |
| getRequestBodySchema (string $mediaType) | |
| Returns a content schema per the OpenAPI spec. | |
| getRequestSpec (string $method) | |
| Returns an OpenAPI Request Body Object specification structure as an associative array. | |
| getResponseBodyExample (string $method) | |
| Returns an example response body for use in the OpenAPI description. | |
| getResponseBodyExampleFileName (string $method) | |
| Returns the absolute path of a JSON file containing an example response body. | |
| getResponseBodySchema (string $method) | |
| Returns an OpenAPI Schema Object specification structure as an associative array. | |
| getResponseBodySchemaFileName (string $method) | |
| Returns the absolute path of a JSON file containing an OpenAPI Schema Object specification structure describing the response body. | |
| getRouter () | |
| Get the Router of the Module that this handler belongs to. | |
| getRouteUrl ( $pathParams=[], $queryParams=[]) | |
| Get the URL of this handler's endpoint. | |
| hasRepresentation () | |
| The subclass should override this to indicate whether the resource exists. | |
| isDeprecated () | |
| Indicates whether this is deprecated. | |
| postInitSetup () | |
| The handler can override this to do any necessary setup after the init functions are called to inject 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. | |
Protected Attributes | |
| readonly ExtensionRegistry | $extensionRegistry |
Additional Inherited Members | |
| Public Attributes inherited from MediaWiki\Rest\Handler | |
| const | KNOWN_PARAM_SOURCES = Validator::KNOWN_PARAM_SOURCES |
| const | OPENAPI_DESCRIPTION_KEY = 'description' |
| const | PARAM_DESCRIPTION = Validator::PARAM_DESCRIPTION |
| const | PARAM_EXAMPLE = Validator::PARAM_EXAMPLE |
| const | PARAM_SOURCE = Validator::PARAM_SOURCE |
Base class for Parsoid handlers.
Definition at line 69 of file ParsoidHandler.php.
| MediaWiki\Rest\Handler\ParsoidHandler::__construct | ( | private readonly RevisionLookup | $revisionLookup, |
| protected readonly SiteConfig | $siteConfig, | ||
| protected readonly PageConfigFactory | $pageConfigFactory, | ||
| protected readonly DataAccess | $dataAccess, | ||
| private readonly PageBundleParserOutputConverter | $pageBundleParserOutputConverter ) |
Definition at line 88 of file ParsoidHandler.php.
|
protected |
This method checks if we support the requested content formats As a side-effect, it updates $attribs to set outputContentVersion that Parsoid should generate based on request headers.
| array | &$attribs | Request attributes from getRequestAttributes() |
Definition at line 422 of file ParsoidHandler.php.
References MediaWiki\Rest\Handler\getRequest().
|
protected |
Verify that the {domain} path parameter matches the actual domain.
| string | $domain | Domain name parameter to validate |
Definition at line 112 of file ParsoidHandler.php.
References MediaWiki\Rest\Handler\getConfig().
|
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 \MediaWiki\Rest\HttpException. 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.
Reimplemented from MediaWiki\Rest\Handler.
Reimplemented in MediaWiki\Rest\Handler\TransformHandler.
|
static |
Definition at line 76 of file ParsoidHandler.php.
|
protected |
| array | $attribs | |
| string | $html | |
| PageIdentity | $page |
Definition at line 382 of file ParsoidHandler.php.
Referenced by html2wt().
|
protected |
Reimplemented in MediaWiki\Rest\Handler\TransformHandler.
Definition at line 178 of file ParsoidHandler.php.
References return.
|
protected |
Get the path for the page content endpoint.
May be overwritten to override the path.
This is done in the parsoid extension, for backwards compatibility with the old endpoint URLs.
| string | $format | The format the endpoint is expected to return. |
Definition at line 629 of file ParsoidHandler.php.
References if.
|
protected |
Get the parsed body by content-type.
Definition at line 156 of file ParsoidHandler.php.
References MediaWiki\Rest\Handler\getRequest().
|
protected |
Rough equivalent of req.local from Parsoid-JS.
FIXME most of these should be replaced with more native ways of handling the request.
Reimplemented in MediaWiki\Rest\Handler\TransformHandler.
Definition at line 190 of file ParsoidHandler.php.
References if.
|
protected |
Get the path for the page content endpoint.
May be overwritten to override the path.
This is done in the parsoid extension, for backwards compatibility with the old endpoint URLs.
| string | $format | The format the endpoint is expected to return. |
Definition at line 648 of file ParsoidHandler.php.
References if.
| MediaWiki\Rest\Handler\ParsoidHandler::getSupportedRequestTypes | ( | ) |
Returns the content types that should be accepted by parseBodyData().
Subclasses that support request types other than application/json should override this method.
If "application/x-www-form-urlencoded" or "multipart/form-data" are returned, parseBodyData() will use $request->getPostParams() to determine the body data.
Reimplemented from MediaWiki\Rest\Handler.
Definition at line 98 of file ParsoidHandler.php.
References getSupportedRequestTypes(), and return.
Referenced by getSupportedRequestTypes().
|
protected |
Get the path for the transform endpoint.
May be overwritten to override the path.
This is done in the parsoid extension, for backwards compatibility with the old endpoint URLs.
| string | $format | The format the endpoint is expected to return. |
Definition at line 613 of file ParsoidHandler.php.
References return.
|
protected |
| PageConfig | PageIdentity | $page | |
| array | $attribs | Attributes gotten from requests |
| string | $html | Original HTML |
| HttpException |
Definition at line 879 of file ParsoidHandler.php.
References getHtmlInputTransformHelper(), and MediaWiki\Rest\Handler\getResponseFactory().
|
protected |
Do variant conversion on a document.
| PageConfig | $pageConfig | |
| array | $attribs | |
| array | $revision |
| HttpException |
Definition at line 1037 of file ParsoidHandler.php.
References $source, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Rest\Handler\getResponseFactory(), and tryToCreatePageIdentity().
Referenced by pb2pb().
|
protected |
Definition at line 863 of file ParsoidHandler.php.
References return.
Referenced by updateRedLinks(), and wt2html().
|
protected |
Definition at line 867 of file ParsoidHandler.php.
References parseHTML(), and return.
Referenced by parseHTML(), and pb2pb().
|
protected |
Pagebundle -> pagebundle helper.
| array<string,array|string> | $attribs |
| HttpException |
Definition at line 907 of file ParsoidHandler.php.
References MediaWiki\Rest\Handler\getResponseFactory(), languageConversion(), parseHTML(), tryToCreatePageConfig(), updateRedLinks(), and wt2html().
|
protected |
Try to create a PageConfig object.
If we get an exception (because content may be missing or inaccessible), throw an appropriate HTTP response object for callers to handle.
| array | $attribs | |
| ?string | $wikitextOverride | Custom wikitext to use instead of the real content of the page. |
| bool | $html2WtMode |
| HttpException |
Definition at line 492 of file ParsoidHandler.php.
Referenced by pb2pb().
|
protected |
Try to create a PageIdentity object.
If no page is specified in the request, this will return the wiki's main page. If an invalid page is requested, this throws an appropriate HTTPException.
| array | $attribs |
| HttpException |
Definition at line 581 of file ParsoidHandler.php.
References if.
Referenced by languageConversion().
|
protected |
Update red links on a document.
| PageConfig | $pageConfig | |
| array | $attribs | |
| array | $revision |
Definition at line 1002 of file ParsoidHandler.php.
References MediaWiki\Rest\Handler\getResponseFactory(), and newParsoid().
Referenced by pb2pb().
|
protected |
Wikitext -> HTML helper.
Spec'd in https://phabricator.wikimedia.org/T75955 and the API tests.
| PageConfig | $pageConfig | |
| array | $attribs | Request attributes from getRequestAttributes() |
| ?string | $wikitext | Wikitext to transform (or null to use the page specified in the request attributes). |
Definition at line 686 of file ParsoidHandler.php.
References MediaWiki\Rest\ResponseHeaders\CACHE_CONTROL, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Rest\Handler\getRequest(), MediaWiki\Rest\Handler\getResponseFactory(), and newParsoid().
Referenced by pb2pb().
|
protected |
Definition at line 71 of file ParsoidHandler.php.