contentHelper = new PageContentHelper( $config, $permissionManager, $revisionLookup, $titleFormatter, $titleFactory ); $this->htmlHelper = new ParsoidHTMLHelper( $parserCacheFactory->getInstance( 'parsoid' ), $wikiPageFactory, $globalIdGenerator ); } protected function postValidationSetup() { // TODO: inject user properly $user = RequestContext::getMain()->getUser(); $this->contentHelper->init( $user, $this->getValidatedParams() ); $title = $this->contentHelper->getTitle(); if ( $title ) { $this->htmlHelper->init( $title ); } } /** * @return Response * @throws LocalizedHttpException */ public function run(): Response { $this->contentHelper->checkAccess(); $titleObj = $this->contentHelper->getTitle(); // The call to $this->contentHelper->getTitle() should not return null if // $this->contentHelper->checkAccess() did not throw. Assert::invariant( $titleObj !== null, 'Title should be known' ); $outputMode = $this->getOutputMode(); switch ( $outputMode ) { case 'html': $parserOutput = $this->htmlHelper->getHtml(); $response = $this->getResponseFactory()->create(); // TODO: need to respect content-type returned by Parsoid. $response->setHeader( 'Content-Type', 'text/html' ); $this->contentHelper->setCacheControl( $response, $parserOutput->getCacheExpiry() ); $response->setBody( new StringStream( $parserOutput->getText() ) ); break; case 'with_html': $parserOutput = $this->htmlHelper->getHtml(); $body = $this->contentHelper->constructMetadata(); $body['html'] = $parserOutput->getText(); $response = $this->getResponseFactory()->createJson( $body ); $this->contentHelper->setCacheControl( $response, $parserOutput->getCacheExpiry() ); break; default: throw new LogicException( "Unknown HTML type $outputMode" ); } return $response; } /** * Returns an ETag representing a page's source. The ETag assumes a page's source has changed * if the latest revision of a page has been made private, un-readable for another reason, * or a newer revision exists. * @return string|null */ protected function getETag(): ?string { if ( !$this->contentHelper->isAccessible() ) { return null; } return $this->htmlHelper->getETag(); } /** * @return string|null */ protected function getLastModified(): ?string { if ( !$this->contentHelper->isAccessible() ) { return null; } return $this->htmlHelper->getLastModified(); } private function getOutputMode(): string { return $this->getConfig()['format']; } public function needsWriteAccess(): bool { return false; } public function getParamSettings(): array { return $this->contentHelper->getParamSettings(); } }