[ self::PARAM_SOURCE => 'path', ParamValidator::PARAM_TYPE => 'string', ParamValidator::PARAM_REQUIRED => true, ], 'format' => [ self::PARAM_SOURCE => 'path', ParamValidator::PARAM_TYPE => 'string', ParamValidator::PARAM_REQUIRED => true, ], 'title' => [ self::PARAM_SOURCE => 'path', ParamValidator::PARAM_TYPE => 'string', ParamValidator::PARAM_REQUIRED => true, ], 'revision' => [ self::PARAM_SOURCE => 'path', ParamValidator::PARAM_TYPE => 'string', ParamValidator::PARAM_REQUIRED => false, ], ]; } /** @inheritDoc */ public function execute(): Response { $request = $this->getRequest(); $format = $request->getPathParam( 'format' ); if ( !in_array( $format, ParsoidFormatHelper::VALID_PAGE, true ) ) { throw new HttpException( "Invalid page format: {$format}", 404 ); } $attribs = $this->getRequestAttributes(); if ( !$this->acceptable( $attribs ) ) { // mutates $attribs throw new HttpException( 'Not acceptable', 406 ); } $pageConfig = $this->tryToCreatePageConfig( $attribs ); if ( $format === ParsoidFormatHelper::FORMAT_WIKITEXT ) { return $this->getPageContentResponse( $pageConfig, $attribs ); } else { return $this->wt2html( $pageConfig, $attribs ); } } /** * Return the content of a page. This is the case when GET /page/ is * called with format=wikitext. * * @param PageConfig $pageConfig * @param array $attribs Request attributes from getRequestAttributes() * @return Response * @throws HttpException */ protected function getPageContentResponse( PageConfig $pageConfig, array $attribs ) { $content = $pageConfig->getRevisionContent(); if ( !$content ) { throw new HttpException( 'The specified revision does not exist.', 404 ); } $response = $this->getResponseFactory()->create(); $response->setStatus( 200 ); $response->setHeader( 'X-ContentModel', $content->getModel( SlotRecord::MAIN ) ); ParsoidFormatHelper::setContentType( $response, ParsoidFormatHelper::FORMAT_WIKITEXT, $attribs['envOptions']['outputContentVersion'] ); $response->getBody()->write( $content->getContent( SlotRecord::MAIN ) ); return $response; } }