jenkins-bot has submitted this change and it was merged. Change subject: Add navbar to topic & post history ......................................................................
Add navbar to topic & post history Actually, afaict, post history is currently not even linked to, but hey, now it has pagination! Bug: T67088 Change-Id: Iad211442ebbcc2277c6fd6757bf8b724bea8ccbe --- M handlebars/compiled/flow_block_topic_history.handlebars.php M handlebars/flow_block_topic_history.handlebars M includes/Block/Topic.php M includes/Formatter/PostHistoryQuery.php M includes/Formatter/TopicHistoryQuery.php 5 files changed, 60 insertions(+), 21 deletions(-) Approvals: Mattflaschen: Looks good to me, approved jenkins-bot: Verified diff --git a/handlebars/compiled/flow_block_topic_history.handlebars.php b/handlebars/compiled/flow_block_topic_history.handlebars.php index 61ac787..815a4f4 100644 --- a/handlebars/compiled/flow_block_topic_history.handlebars.php +++ b/handlebars/compiled/flow_block_topic_history.handlebars.php @@ -13,6 +13,7 @@ ), 'constants' => array(), 'helpers' => array( 'l10n' => 'Flow\TemplateHelper::l10n', + 'html' => 'Flow\TemplateHelper::htmlHelper', 'historyTimestamp' => 'Flow\TemplateHelper::historyTimestamp', 'historyDescription' => 'Flow\TemplateHelper::historyDescription', 'showCharacterDifference' => 'Flow\TemplateHelper::showCharacterDifference', @@ -58,6 +59,8 @@ ' : '').' </span> </li> ';}).' </ul> + + '.LCRun3::ch($cx, 'html', array(array(((isset($in['navbar']) && is_array($in)) ? $in['navbar'] : null)),array()), 'encq').' </div> </div> '; diff --git a/handlebars/flow_block_topic_history.handlebars b/handlebars/flow_block_topic_history.handlebars index 4b4f4fb..bcd5f2c 100644 --- a/handlebars/flow_block_topic_history.handlebars +++ b/handlebars/flow_block_topic_history.handlebars @@ -65,5 +65,7 @@ </li> {{/each}} </ul> + + {{html navbar}} </div> </div> diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php index 07c7219..cc5ce8d 100644 --- a/includes/Block/Topic.php +++ b/includes/Block/Topic.php @@ -4,13 +4,15 @@ use Flow\Container; use Flow\Data\ManagerGroup; +use Flow\Data\Pager\HistoryPager; use Flow\Exception\FailCommitException; use Flow\Exception\FlowException; use Flow\Exception\InvalidActionException; use Flow\Exception\InvalidDataException; use Flow\Exception\InvalidInputException; use Flow\Exception\PermissionException; -use Flow\Formatter\FormatterRow; +use Flow\Formatter\TopicHistoryQuery; +use Flow\Formatter\PostHistoryQuery; use Flow\Model\AbstractRevision; use Flow\Model\PostRevision; use Flow\Model\UUID; @@ -646,43 +648,57 @@ if ( $this->workflow->isNew() ) { throw new FlowException( 'No topic history can exist for non-existent topic' ); } - $found = Container::get( 'query.topic.history' )->getResults( $this->workflow->getId() ); - return $this->processHistoryResult( $found, $options ); + return $this->processHistoryResult( Container::get( 'query.topic.history' ), $this->workflow->getId(), $options ); } protected function renderPostHistoryApi( array $options, UUID $postId ) { if ( $this->workflow->isNew() ) { throw new FlowException( 'No post history can exist for non-existent topic' ); } - $found = Container::get( 'query.post.history' )->getResults( $postId ); - return $this->processHistoryResult( $found, $options ); + return $this->processHistoryResult( Container::get( 'query.post.history' ), $postId, $options ); } /** * Process the history result for either topic or post * - * @param FormatterRow[] $found + * @param TopicHistoryQuery|PostHistoryQuery $query + * @param UUID $uuid * @param array $options * @return array */ - protected function processHistoryResult( $found, $options ) { + protected function processHistoryResult( /* TopicHistoryQuery|PostHistoryQuery */ $query, UUID $uuid, $options ) { + global $wgRequest; + $serializer = $this->getRevisionFormatter(); if ( isset( $options['contentFormat'] ) ) { $serializer->setContentFormat( $options['contentFormat'] ); } $serializer->setIncludeHistoryProperties( true ); - $result = array(); - foreach ( $found as $row ) { + list( $limit, /* $offset */ ) = $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 ); // if the user is not allowed to see this row it will return empty if ( $serialized ) { - $result[$serialized['revisionId']] = $serialized; + $revisions[$serialized['revisionId']] = $serialized; } } return array( - 'revisions' => $result + 'revisions' => $revisions, + 'navbar' => $pager->getNavigationBar(), ); } diff --git a/includes/Formatter/PostHistoryQuery.php b/includes/Formatter/PostHistoryQuery.php index d27547a..d7d967b 100644 --- a/includes/Formatter/PostHistoryQuery.php +++ b/includes/Formatter/PostHistoryQuery.php @@ -3,24 +3,33 @@ namespace Flow\Formatter; use Flow\Exception\FlowException; -use Flow\Exception\InvalidDataException; use Flow\Model\UUID; class PostHistoryQuery extends AbstractQuery { /** * @param UUID $postId + * @param int $limit + * @param UUID|null $offset + * @param string $direction 'rev' or 'fwd' * @return FormatterRow[] - * @throws InvalidDataException */ - public function getResults( UUID $postId ) { + public function getResults( UUID $postId, $limit = 50, UUID $offset = null, $direction = 'fwd' ) { $history = $this->storage->find( 'PostRevision', array( 'rev_type_id' => $postId ), - array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' => 100 ) + array( + 'sort' => 'rev_id', + 'order' => 'DESC', + 'limit' => $limit, + 'offset-id' => $offset, + 'offset-dir' => $direction, + 'offset-include' => false, + 'offset-elastic' => false, + ) ); if ( !$history ) { - throw new InvalidDataException( 'Unable to load topic history for post ' . $postId->getAlphadecimal(), 'fail-load-history' ); + return array(); } $this->loadMetadataBatch( $history ); diff --git a/includes/Formatter/TopicHistoryQuery.php b/includes/Formatter/TopicHistoryQuery.php index f3e2b9f..f69aafc 100644 --- a/includes/Formatter/TopicHistoryQuery.php +++ b/includes/Formatter/TopicHistoryQuery.php @@ -3,26 +3,35 @@ namespace Flow\Formatter; use Flow\Exception\FlowException; -use Flow\Exception\InvalidDataException; use Flow\Model\PostRevision; use Flow\Model\UUID; class TopicHistoryQuery extends AbstractQuery { /** * @param UUID $postId + * @param int $limit + * @param UUID|null $offset + * @param string $direction 'rev' or 'fwd' * @return FormatterRow[] - * @throws InvalidDataException */ - public function getResults( UUID $postId ) { + public function getResults( UUID $postId, $limit = 50, UUID $offset = null, $direction = 'fwd' ) { /** @noinspection PhpUnusedLocalVariableInspection */ $section = new \ProfileSection( __METHOD__ ); $history = $this->storage->find( 'TopicHistoryEntry', array( 'topic_root_id' => $postId ), - array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' => 100 ) + array( + 'sort' => 'rev_id', + 'order' => 'DESC', + 'limit' => $limit, + 'offset-id' => $offset, + 'offset-dir' => $direction, + 'offset-include' => false, + 'offset-elastic' => false, + ) ); if ( !$history ) { - throw new InvalidDataException( 'Unable to load topic history for topic ' . $postId->getAlphadecimal(), 'fail-load-history' ); + return array(); } $this->loadMetadataBatch( $history ); -- To view, visit https://gerrit.wikimedia.org/r/187606 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iad211442ebbcc2277c6fd6757bf8b724bea8ccbe Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: SG <shah...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits