/**
  * Formats the response
  *
  * @param Workflow $listWorkflow Workflow corresponding to board/list of topics
  * @param array $topicRootRevisionsByWorkflowId Associative array mapping topic ID (in alphadecimal form)
  *  to PostRevision for the topic root.
  * @param array $workflowsByWorkflowId Associative array mapping topic ID (in alphadecimal form) to
  *  workflow
  * @param PagerPage $page page from query, to support pagination
  *
  * @return array Array formatted for response
  */
 public function formatApi(Workflow $listWorkflow, $topicRootRevisionsByWorkflowId, $workflowsByWorkflowId, PagerPage $page)
 {
     $result = $this->buildEmptyResult($listWorkflow);
     foreach ($topicRootRevisionsByWorkflowId as $topicId => $postRevision) {
         $result['roots'][] = $topicId;
         $revisionId = $postRevision->getRevisionId()->getAlphadecimal();
         $result['posts'][$topicId] = array($revisionId);
         $contentFormat = 'plaintext';
         $workflow = $workflowsByWorkflowId[$topicId];
         $result['revisions'][$revisionId] = array('content' => array('content' => $this->templating->getContent($postRevision, $contentFormat), 'format' => $contentFormat), 'last_updated' => $workflow->getLastModifiedObj()->getTimestamp() * 1000);
     }
     $pagingOption = $page->getPagingLinksOptions();
     $result['links']['pagination'] = $this->buildPaginationLinks($listWorkflow, $pagingOption);
     return $result;
 }
 /**
  * Mimic Echo parameter formatting
  *
  * @param string $param The requested i18n parameter
  * @param AbstractRevision|AbstractRevision[] $revision The revision or
  *  revisions to format or an array of revisions
  * @param UUID $workflowId The UUID of the workflow $revision belongs tow
  * @param IContextSource $ctx
  * @param FormatterRow|null $row
  * @return mixed A valid parameter for a core Message instance. These
  *  parameters will be used with Message::parse
  * @throws FlowException
  */
 public function processParam($param, $revision, UUID $workflowId, IContextSource $ctx, FormatterRow $row = null)
 {
     switch ($param) {
         case 'creator-text':
             if ($revision instanceof PostRevision) {
                 return $this->usernames->getFromTuple($revision->getCreatorTuple());
             } else {
                 return '';
             }
         case 'user-text':
             return $this->usernames->getFromTuple($revision->getUserTuple());
         case 'user-links':
             return Message::rawParam($this->templating->getUserLinks($revision));
         case 'summary':
             if (!$this->permissions->isAllowed($revision, 'view')) {
                 return '';
             }
             /*
              * Fetch in HTML; unparsed wikitext in summary is pointless.
              * Larger-scale wikis will likely also store content in html, so no
              * Parsoid roundtrip is needed then (and if it *is*, it'll already
              * be needed to render Flow discussions, so this is manageable)
              */
             $content = $this->templating->getContent($revision, 'fixed-html');
             // strip html tags and decode to plaintext
             $content = Utils::htmlToPlaintext($content, 140, $ctx->getLanguage());
             return Message::plaintextParam($content);
         case 'wikitext':
             if (!$this->permissions->isAllowed($revision, 'view')) {
                 return '';
             }
             $content = $this->templating->getContent($revision, 'wikitext');
             // This must be escaped and marked raw to prevent special chars in
             // content, like $1, from changing the i18n result
             return Message::plaintextParam($content);
             // This is potentially two networked round trips, much too expensive for
             // the rendering loop
         // This is potentially two networked round trips, much too expensive for
         // the rendering loop
         case 'prev-wikitext':
             if ($revision->isFirstRevision()) {
                 return '';
             }
             if ($row === null) {
                 $previousRevision = $revision->getCollection()->getPrevRevision($revision);
             } else {
                 $previousRevision = $row->previousRevision;
             }
             if (!$previousRevision) {
                 return '';
             }
             if (!$this->permissions->isAllowed($previousRevision, 'view')) {
                 return '';
             }
             $content = $this->templating->getContent($previousRevision, 'wikitext');
             return Message::plaintextParam($content);
         case 'workflow-url':
             return $this->urlGenerator->workflowLink(null, $workflowId)->getFullUrl();
         case 'post-url':
             if (!$revision instanceof PostRevision) {
                 throw new FlowException('Expected PostRevision but received' . get_class($revision));
             }
             return $this->urlGenerator->postLink(null, $workflowId, $revision->getPostId())->getFullUrl();
         case 'moderated-reason':
             // don-t parse wikitext in the moderation reason
             return Message::plaintextParam($revision->getModeratedReason());
         case 'topic-of-post':
             if (!$revision instanceof PostRevision) {
                 throw new FlowException('Expected PostRevision but received ' . get_class($revision));
             }
             $root = $revision->getRootPost();
             if (!$this->permissions->isAllowed($root, 'view')) {
                 return '';
             }
             $content = $this->templating->getContent($root, 'wikitext');
             return Message::plaintextParam($content);
         case 'post-of-summary':
             if (!$revision instanceof PostSummary) {
                 throw new FlowException('Expected PostSummary but received ' . get_class($revision));
             }
             /** @var PostRevision $post */
             $post = $revision->getCollection()->getPost()->getLastRevision();
             if (!$this->permissions->isAllowed($post, 'view')) {
                 return '';
             }
             if ($post->isTopicTitle()) {
                 return Message::plaintextParam($this->templating->getContent($post, 'wikitext'));
             } else {
                 return Message::rawParam($this->templating->getContent($post, 'fixed-html'));
             }
         case 'bundle-count':
             return Message::numParam(count($revision));
         default:
             wfWarn(__METHOD__ . ': Unknown formatter parameter: ' . $param);
             return '';
     }
 }