public function renderApi(array $options) { global $wgRequest; if ($this->workflow->isNew()) { return array('type' => $this->getName(), 'revisions' => array(), 'links' => array()); } /** @var BoardHistoryQuery $query */ $query = Container::get('query.board-history'); /** @var RevisionFormatter $formatter */ $formatter = Container::get('formatter.revision'); $formatter->setIncludeHistoryProperties(true); list($limit, ) = $wgRequest->getLimitOffset(); // don't use offset from getLimitOffset - that assumes an int, which our // UUIDs are not $offset = $wgRequest->getText('offset'); $offset = $offset ? UUID::create($offset) : null; $pager = new HistoryPager($query, $this->workflow->getId()); $pager->setLimit($limit); $pager->setOffset($offset); $pager->doQuery(); $history = $pager->getResult(); $revisions = array(); foreach ($history as $row) { $serialized = $formatter->formatApi($row, $this->context, 'history'); if ($serialized) { $revisions[$serialized['revisionId']] = $serialized; } } return array('type' => $this->getName(), 'revisions' => $revisions, 'navbar' => $pager->getNavigationBar(), 'links' => array()); }
/** * Process the history result for either topic or post * * @param TopicHistoryQuery|PostHistoryQuery $query * @param UUID $uuid * @param array $options * @return array */ protected function processHistoryResult($query, UUID $uuid, $options) { global $wgRequest; $format = isset($options['format']) ? $options['format'] : 'fixed-html'; $serializer = $this->getRevisionFormatter($format); $serializer->setIncludeHistoryProperties(true); list($limit, ) = $wgRequest->getLimitOffset(); // don't use offset from getLimitOffset - that assumes an int, which our // UUIDs are not $offset = $wgRequest->getText('offset'); $offset = $offset ? UUID::create($offset) : null; $pager = new HistoryPager($query, $uuid); $pager->setLimit($limit); $pager->setOffset($offset); $pager->doQuery(); $history = $pager->getResult(); $revisions = array(); foreach ($history as $row) { $serialized = $serializer->formatApi($row, $this->context, 'history'); // if the user is not allowed to see this row it will return empty if ($serialized) { $revisions[$serialized['revisionId']] = $serialized; } } return array('revisions' => $revisions, 'navbar' => $pager->getNavigationBar()); }