/**
  * @param string $action
  * @param OutputPage|null $output
  * @throws ErrorPageError
  * @throws FlowException
  */
 public function showForAction($action, OutputPage $output = null)
 {
     $container = Container::getContainer();
     $occupationController = \FlowHooks::getOccupationController();
     if ($output === null) {
         $output = $this->context->getOutput();
     }
     // Check if this is actually a Flow page.
     if (!$this->page instanceof WikiPage && !$this->page instanceof Article) {
         throw new ErrorPageError('nosuchaction', 'flow-action-unsupported');
     }
     $title = $this->page->getTitle();
     if (!$occupationController->isTalkpageOccupied($title)) {
         throw new ErrorPageError('nosuchaction', 'flow-action-unsupported');
     }
     // @todo much of this seems to duplicate BoardContent::getParserOutput
     $view = new View($container['url_generator'], $container['lightncandy'], $output, $container['flow_actions']);
     $request = $this->context->getRequest();
     // BC for urls pre july 2014 with workflow query parameter
     $redirect = $this->getRedirectUrl($request, $title);
     if ($redirect) {
         $output->redirect($redirect);
         return;
     }
     $action = $request->getVal('action', 'view');
     try {
         /** @var WorkflowLoaderFactory $factory */
         $factory = $container['factory.loader.workflow'];
         $loader = $factory->createWorkflowLoader($title);
         if ($title->getNamespace() === NS_TOPIC && $loader->getWorkflow()->getType() !== 'topic') {
             // @todo better error handling
             throw new FlowException('Invalid title: uuid is not a topic');
         }
         $view->show($loader, $action);
     } catch (FlowException $e) {
         $e->setOutput($output);
         throw $e;
     }
 }
 /**
  * Parse the Content object and generate a ParserOutput from the result.
  * $result->getText() can be used to obtain the generated HTML. If no HTML
  * is needed, $generateHtml can be set to false; in that case,
  * $result->getText() may return null.
  *
  * @note To control which options are used in the cache key for the
  *       generated parser output, implementations of this method
  *       may call ParserOutput::recordOption() on the output object.
  *
  * @param Title $title The page title to use as a context for rendering.
  * @param int $revId Optional revision ID being rendered.
  * @param ParserOptions $options Any parser options.
  * @param bool $generateHtml Whether to generate HTML (default: true). If false,
  *        the result of calling getText() on the ParserOutput object returned by
  *        this method is undefined.
  *
  * @since 1.21
  *
  * @return ParserOutput
  */
 public function getParserOutput(Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true)
 {
     $parserOutput = new ParserOutput();
     $parserOutput->updateCacheExpiry(0);
     if ($revId === null) {
         $wikiPage = new WikiPage($title);
         $timestamp = $wikiPage->getTimestamp();
     } else {
         $timestamp = Revision::getTimestampFromId($title, $revId);
     }
     $parserOutput->setTimestamp($timestamp);
     if ($generateHtml) {
         // Set up a derivative context (which inherits the current request)
         // to hold the output modules + text
         $childContext = new DerivativeContext(RequestContext::getMain());
         $childContext->setOutput(new OutputPage($childContext));
         $childContext->setRequest(new FauxRequest());
         // Create a View set up to output to our derivative context
         $view = new View(Container::get('url_generator'), Container::get('lightncandy'), $childContext->getOutput(), Container::get('flow_actions'));
         $loader = $this->getWorkflowLoader($title);
         $view->show($loader, 'view');
         // Extract data from derivative context
         $parserOutput->setText($childContext->getOutput()->getHTML());
         $parserOutput->addModules($childContext->getOutput()->getModules());
         $parserOutput->addModuleStyles($childContext->getOutput()->getModuleStyles());
         $parserOutput->addModuleScripts($childContext->getOutput()->getModuleScripts());
     }
     /** @var LinksTableUpdater $updater */
     $updater = Container::get('reference.updater.links-tables');
     $updater->mutateParserOutput($title, $parserOutput);
     return $parserOutput;
 }