Bsitu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/158302

Change subject: Implement post history
......................................................................

Implement post history

Link like the following would throw exception:

https://www.mediawiki.org/w/index.php?title=Topic:S1jkmjn3hg6w6mkn&action=history&topic_postId=s1lpteic8yh7s1ds

Change-Id: Idb6e83ba97259ad9a4cd912fc983c617b19a78e3
---
M Flow.php
M container.php
M includes/Block/Topic.php
A includes/Formatter/PostHistoryQuery.php
4 files changed, 64 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/02/158302/1

diff --git a/Flow.php b/Flow.php
index 53a3065..e39423b 100755
--- a/Flow.php
+++ b/Flow.php
@@ -189,6 +189,7 @@
 $wgAutoloadClasses['Flow\Formatter\PostSummaryQuery'] = $dir . 
'includes/Formatter/PostSummaryQuery.php';
 $wgAutoloadClasses['Flow\Formatter\TopicListQuery'] = $dir . 
'includes/Formatter/TopicListQuery.php';
 $wgAutoloadClasses['Flow\Formatter\TopicHistoryQuery'] = $dir . 
'includes/Formatter/TopicHistoryQuery.php';
+$wgAutoloadClasses['Flow\Formatter\PostHistoryQuery'] = $dir . 
'includes/Formatter/PostHistoryQuery.php';
 $wgAutoloadClasses['Flow\Formatter\TopicRow'] = $dir . 
'includes/Formatter/TopicRow.php';
 $wgAutoloadClasses['Flow\Formatter\IRCLineUrlFormatter'] = $dir . 
'includes/Formatter/IRCLineUrlFormatter.php';
 $wgAutoloadClasses['Flow\Formatter\RevisionViewFormatter'] = $dir . 
'includes/Formatter/RevisionViewFormatter.php';
diff --git a/container.php b/container.php
index 3698f2b..59619cc 100644
--- a/container.php
+++ b/container.php
@@ -715,6 +715,12 @@
                $c['repository.tree']
        );
 } );
+$c['query.post.history'] = $c->share( function( $c ) {
+       return new Flow\Formatter\PostHistoryQuery(
+               $c['storage'],
+               $c['repository.tree']
+       );
+} );
 $c['query.recentchanges'] = $c->share( function( $c ) {
        $query = new Flow\Formatter\RecentChangesQuery(
                $c['storage'],
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index da363c8..7377279 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -11,6 +11,7 @@
 use Flow\Exception\InvalidDataException;
 use Flow\Exception\InvalidInputException;
 use Flow\Exception\PermissionException;
+use Flow\Formatter\FormatterRow;
 use Flow\Model\AbstractRevision;
 use Flow\Model\PostRevision;
 use Flow\Model\UUID;
@@ -445,7 +446,7 @@
                        // single post history or full topic?
                        if ( isset( $options['postId'] ) ) {
                                // singular post history
-                               $output = $this->renderPostHistoryAPI( 
$templating, $options );
+                               $output = $this->renderPostHistoryAPI( 
$templating, $options, UUID::create( $options['postId'] ) );
                        } else {
                                // post history for full topic
                                $output = $this->renderTopicHistoryAPI( 
$templating, $options );
@@ -626,6 +627,23 @@
                        throw new FlowException( 'No topic history can exist 
for non-existant topic' );
                }
                $found = Container::get( 'query.topic.history' )->getResults( 
$this->workflow->getId() );
+               return $this->processHistoryResult( $found, $options );
+       }
+
+       protected function renderPostHistoryAPI( Templating $templating, array 
$options, UUID $postId ) {
+               if ( $this->workflow->isNew() ) {
+                       throw new FlowException( 'No post history can exist for 
non-existant topic' );
+               }
+               $found = Container::get( 'query.post.history' )->getResults( 
$postId );
+               return $this->processHistoryResult( $found, $options );
+       }
+
+       /**
+        * Process the history result for either topic or post
+        * @param FormatterRow
+        * @param array
+        */
+       protected function processHistoryResult( $found, $options ) {
                $serializer = $this->getRevisionFormatter();
                if ( isset( $options['contentFormat'] ) ) {
                        $serializer->setContentFormat( 
$options['contentFormat'] );
@@ -645,10 +663,6 @@
                return array(
                        'revisions' => $result
                );
-       }
-
-       protected function renderPostHistoryAPI( Templating $templating, array 
$options ) {
-               throw new FlowException( 'Not implemented yet' );
        }
 
        /**
diff --git a/includes/Formatter/PostHistoryQuery.php 
b/includes/Formatter/PostHistoryQuery.php
new file mode 100644
index 0000000..b7543b5
--- /dev/null
+++ b/includes/Formatter/PostHistoryQuery.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Flow\Formatter;
+
+use Flow\Model\UUID;
+
+class PostHistoryQuery extends AbstractQuery {
+
+       /**
+        * @param UUID $postId
+        * @return FormatterRow[]
+        * @throws InvalidDataException
+        */
+       public function getResults( UUID $postId ) {
+               $history = $this->storage->find(
+                       'PostRevision',
+                       array( 'rev_type_id' => $postId ),
+                       array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' 
=> 100 )
+               );
+               if ( !$history ) {
+                       throw new InvalidDataException( 'Unable to load topic 
history for post ' . $postId->getAlphadecimal(), 'fail-load-history' );
+               }
+
+               $this->loadMetadataBatch( $history );
+               $results = array();
+               foreach ( $history as $revision ) {
+                       try {
+                               $results[] = $row = new FormatterRow;
+                               $this->buildResult( $revision, null, $row );
+                       } catch ( FlowException $e ) {
+                               \MWExceptionHandler::logException( $e );
+                       }
+               }
+
+               return $results;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/158302
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb6e83ba97259ad9a4cd912fc983c617b19a78e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to