EBernhardson has uploaded a new change for review.

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

Change subject: Add commit metadata to api response and flag for onlymetadata
......................................................................

Add commit metadata to api response and flag for onlymetadata

* The blocks were already passing metadata back but it became unused
   at some point in time. Added this metadata to POST api responses
   as the `committed` top level key.

* Adds a new flag, onlymetadata, to skip returning the bulk of the api
  response for bots that dont care. Unsure how to properly document
  this for discoverability.

* Updated the commit metadata returned by the blocks.  Everything was
  prefixed with new-, so stripped that.  It would have been nice to
  return revision-id from everything, but some blocks like topic
  need to return multiple revision ids.  For consistency everything is
  now in the form of:  post-revision-id, topic-revision-id,
  header-revision-id, etc.

Fixes T78746

Bug: T78746
Change-Id: I175587314ad0db01f32a522b3d7c58fe17c8b82d
---
M includes/Block/Header.php
M includes/Block/Topic.php
M includes/Block/TopicList.php
M includes/Block/TopicSummary.php
M includes/SubmissionHandler.php
M includes/View.php
M includes/api/ApiFlowBaseGet.php
M includes/api/ApiFlowBasePost.php
8 files changed, 40 insertions(+), 17 deletions(-)


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

diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index feac2b6..344246a 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -178,7 +178,7 @@
                                // Reload $this->header for renderApi() after 
save
                                $this->header = $this->newRevision;
                                return array(
-                                       'new-revision-id' => 
$this->newRevision->getRevisionId(),
+                                       'revision-id' => 
$this->newRevision->getRevisionId(),
                                );
 
                        default:
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 1380cc2..07c7219 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -434,9 +434,14 @@
                                $newRevision->setChildren( array() );
                        }
 
-                       return array(
-                               'new-revision-id' => 
$this->newRevision->getRevisionId(),
+                       $returnMetadata = array(
+                               'post-revision-id' => 
$this->newRevision->getRevisionId(),
                        );
+                       if ( $this->newRevision->isFirstRevision() ) {
+                               $returnMetadata['post-id'] = 
$this->newRevision->getPostId();
+                       }
+
+                       return $returnMetadata;
 
                default:
                        throw new InvalidActionException( "Unknown commit 
action: {$this->action}", 'invalid-action' );
diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index 0bf8805..6c2b780 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -125,8 +125,7 @@
        }
 
        /**
-        * Create a new topic attached to the current topic list and write it
-        * out to storage.
+
         */
        public function commit() {
                if ( $this->action !== 'new-topic' ) {
@@ -154,8 +153,11 @@
                $storage->put( $this->topicWorkflow, $metadata );
 
                $output = array(
-                       'created-topic-id' => $this->topicWorkflow->getId(),
-                       'created-post-id' => $this->firstPost ? 
$this->firstPost->getRevisionId() : null,
+                       'topic-page' => 
$this->topicWorkflow->getArticleTitle()->getPrefixedText(),
+                       'topic-id' => $this->topicTitle->getPostId(),
+                       'topic-revision-id' => 
$this->topicTitle->getRevisionId(),
+                       'post-id' => $this->firstPost ? 
$this->firstPost->getPostId() : null,
+                       'post-revision-id' => $this->firstPost ? 
$this->firstPost->getRevisionId() : null,
                );
 
                return $output;
diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php
index d4a0b78..fa2cc2a 100644
--- a/includes/Block/TopicSummary.php
+++ b/includes/Block/TopicSummary.php
@@ -203,7 +203,7 @@
                $this->topicSummary = $this->nextRevision;
 
                return array(
-                       'new-revision-id' => 
$this->nextRevision->getRevisionId(),
+                       'summary-revision-id' => 
$this->nextRevision->getRevisionId(),
                );
        }
 
diff --git a/includes/SubmissionHandler.php b/includes/SubmissionHandler.php
index 8046531..13355e9 100644
--- a/includes/SubmissionHandler.php
+++ b/includes/SubmissionHandler.php
@@ -110,7 +110,8 @@
        /**
         * @param Workflow $workflow
         * @param AbstractBlock[] $blocks
-        * @return array
+        * @return array map from commited block name to an array of metadata 
returned
+        *  about inseted objects.
         * @throws \Exception
         */
        public function commit( Workflow $workflow, array $blocks ) {
diff --git a/includes/View.php b/includes/View.php
index 908293d..23d253c 100644
--- a/includes/View.php
+++ b/includes/View.php
@@ -5,6 +5,7 @@
 use Flow\Block\AbstractBlock;
 use Flow\Exception\InvalidActionException;
 use Flow\Model\Anchor;
+use Flow\Model\UUID;
 use Flow\Model\Workflow;
 use ContextSource;
 use Html;
@@ -156,6 +157,8 @@
 
                        } elseif ( $value instanceof Message ) {
                                $value = $value->text();
+                       } elseif ( $value instanceof UUID ) {
+                               $value = $value->getAlphadecimal();
                        }
                } );
                wfProfileOut( __CLASS__ . '-serialize' );
diff --git a/includes/api/ApiFlowBaseGet.php b/includes/api/ApiFlowBaseGet.php
index 1337766..2a0bc92 100644
--- a/includes/api/ApiFlowBaseGet.php
+++ b/includes/api/ApiFlowBaseGet.php
@@ -54,6 +54,8 @@
                                $value = $value->toArray();
                        } elseif ( $value instanceof Message ) {
                                $value = $value->text();
+                       } elseif ( $value instanceof UUID ) {
+                               $value = $value->getAlphadecimal();
                        }
                } );
 
diff --git a/includes/api/ApiFlowBasePost.php b/includes/api/ApiFlowBasePost.php
index 0271d06..71ee6b6 100644
--- a/includes/api/ApiFlowBasePost.php
+++ b/includes/api/ApiFlowBasePost.php
@@ -1,6 +1,7 @@
 <?php
 
 use Flow\Model\Anchor;
+use Flow\Model\UUID;
 
 abstract class ApiFlowBasePost extends ApiFlowBase {
        public function execute() {
@@ -33,7 +34,7 @@
                        );
                }
 
-               $loader->commit( $workflow, $blocksToCommit );
+               $commitMetadata = $loader->commit( $workflow, $blocksToCommit );
                $savedBlocks = array();
                $result->setIndexedTagName( $savedBlocks, 'block' );
 
@@ -42,17 +43,24 @@
                }
 
                $output = array( $action => array(
-                       'result' => array(),
                        'status' => 'ok',
                        'workflow' => $workflow->isNew() ? '' : 
$workflow->getId()->getAlphadecimal(),
+                       'committed' => $commitMetadata,
                ) );
 
-               foreach( $blocksToCommit as $block ) {
-                       // Always return parsed text to client after successful 
submission?
-                       // @Todo - hacky, maybe have contentformat in the 
request to overwrite
-                       // requiredWikitext
-                       $block->unsetRequiresWikitext( $action );
-                       $output[$action]['result'][$block->getName()] = 
$block->renderApi( $params[$block->getName()] );
+               // User frontends need this data, but bots do not.  When they
+               // pass onlymetadata=1 we will skip this data and return a 
slimmer
+               // response in a shorter timeframe.
+               // @todo how to document for ApiSandbox?
+               if ( !$this->getMain()->getVal( 'onlymetadata' ) ) {
+                       $output[$action]['result'] = array();
+                       foreach( $blocksToCommit as $block ) {
+                               // Always return parsed text to client after 
successful submission?
+                               // @Todo - hacky, maybe have contentformat in 
the request to overwrite
+                               // requiredWikitext
+                               $block->unsetRequiresWikitext( $action );
+                               $output[$action]['result'][$block->getName()] = 
$block->renderApi( $params[$block->getName()] );
+                       }
                }
 
                // required until php5.4 which has the JsonSerializable 
interface
@@ -61,6 +69,8 @@
                                $value = $value->toArray();
                        } elseif ( $value instanceof Message ) {
                                $value = $value->text();
+                       } elseif ( $value instanceof UUID ) {
+                               $value = $value->getAlphadecimal();
                        }
                } );
 

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

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

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

Reply via email to