contentHelper = $helperFactory->newRevisionContentHelper(); } protected function postValidationSetup() { $this->contentHelper->init( $this->getAuthority(), $this->getValidatedParams() ); } /** * @param RevisionRecord $rev * @return string */ private function constructHtmlUrl( RevisionRecord $rev ): string { return $this->getRouter()->getRouteUrl( '/v1/revision/{id}/html', [ 'id' => $rev->getId() ] ); } /** * @return Response * @throws LocalizedHttpException */ public function run() { $this->contentHelper->checkAccess(); $outputMode = $this->getOutputMode(); switch ( $outputMode ) { case 'bare': $revisionRecord = $this->contentHelper->getTargetRevision(); $body = $this->contentHelper->constructMetadata(); // @phan-suppress-next-line PhanTypeMismatchArgumentNullable revisionRecord is set when used $body['html_url'] = $this->constructHtmlUrl( $revisionRecord ); $response = $this->getResponseFactory()->createJson( $body ); $this->contentHelper->setCacheControl( $response ); break; case 'source': $content = $this->contentHelper->getContent(); $body = $this->contentHelper->constructMetadata(); $body['source'] = $content->getText(); break; default: throw new LogicException( "Unknown output mode $outputMode" ); } $response = $this->getResponseFactory()->createJson( $body ); $this->contentHelper->setCacheControl( $response ); return $response; } protected function getResponseBodySchema(): array { $schema = $this->contentHelper->getResponseBodySchema(); // TODO: add fields based on the output mode return $schema; } /** * @return string|null */ protected function getETag(): ?string { return $this->contentHelper->getETag(); } /** * @return string|null */ protected function getLastModified(): ?string { return $this->contentHelper->getLastModified(); } private function getOutputMode(): string { return $this->getConfig()['format']; } public function needsWriteAccess(): bool { return false; } public function getParamSettings(): array { return $this->contentHelper->getParamSettings(); } /** * @return bool */ protected function hasRepresentation() { return $this->contentHelper->hasContent(); } }