Addshore has uploaded a new change for review.

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

Change subject: Use DM Serializetion in RB for references
......................................................................

Use DM Serializetion in RB for references

This also now means that the output contains
the individual snak hashes

Change-Id: If89d508e3e27b5e1be7b69922aaa163c2d32e125
---
M repo/includes/LinkedData/EntityDataSerializationService.php
M repo/includes/api/ApiHelperFactory.php
M repo/includes/api/ResultBuilder.php
M repo/tests/phpunit/includes/api/ResultBuilderTest.php
4 files changed, 26 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/22/222622/1

diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php 
b/repo/includes/LinkedData/EntityDataSerializationService.php
index a5be38f..7d4a6cb 100644
--- a/repo/includes/LinkedData/EntityDataSerializationService.php
+++ b/repo/includes/LinkedData/EntityDataSerializationService.php
@@ -432,7 +432,8 @@
                        $this->entityTitleLookup,
                        $this->libSerializerFactory,
                        $this->serializerFactory,
-                       $this->siteStore
+                       $this->siteStore,
+                       $this->propertyLookup
                );
                $resultBuilder->addEntityRevision( null, $entityRevision, 
$options );
 
diff --git a/repo/includes/api/ApiHelperFactory.php 
b/repo/includes/api/ApiHelperFactory.php
index 62e1526..4dd8c97 100644
--- a/repo/includes/api/ApiHelperFactory.php
+++ b/repo/includes/api/ApiHelperFactory.php
@@ -81,7 +81,8 @@
                        $this->titleLookup,
                        $this->getLibSerializerFactory( $defaultOptions ),
                        $this->getSerializerFactory(),
-                       $this->siteStore
+                       $this->siteStore,
+                       $this->dataTypeLookup
                );
        }
 
diff --git a/repo/includes/api/ResultBuilder.php 
b/repo/includes/api/ResultBuilder.php
index d5e724c..bad2450 100644
--- a/repo/includes/api/ResultBuilder.php
+++ b/repo/includes/api/ResultBuilder.php
@@ -11,6 +11,8 @@
 use Wikibase\DataModel\Claim\Claim;
 use Wikibase\DataModel\Claim\Claims;
 use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
+use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Reference;
 use Wikibase\DataModel\SerializerFactory;
 use Wikibase\DataModel\SiteLinkList;
@@ -71,6 +73,7 @@
         * @param LibSerializerFactory $libSerializerFactory
         * @param SerializerFactory $serializerFactory
         * @param SiteStore $siteStore
+        * @param PropertyDataTypeLookup $dataTypeLookup
         *
         * @throws InvalidArgumentException
         */
@@ -79,7 +82,8 @@
                EntityTitleLookup $entityTitleLookup,
                LibSerializerFactory $libSerializerFactory,
                SerializerFactory $serializerFactory,
-               SiteStore $siteStore
+               SiteStore $siteStore,
+               PropertyDataTypeLookup $dataTypeLookup
        ) {
                if ( !$result instanceof ApiResult ) {
                        throw new InvalidArgumentException( 'Result builder 
must be constructed with an ApiWikibase' );
@@ -91,6 +95,7 @@
                $this->serializerFactory = $serializerFactory;
                $this->missingEntityCounter = -1;
                $this->siteStore = $siteStore;
+               $this->dataTypeLookup = $dataTypeLookup;
        }
 
        /**
@@ -577,13 +582,24 @@
         * @since 0.5
         */
        public function addReference( Reference $reference ) {
-               $serializer = 
$this->libSerializerFactory->newReferenceSerializer( $this->getOptions() );
+               $serializer = 
$this->serializerFactory->newReferenceSerializer();
 
                //TODO: this is currently only used to add a Reference as the 
top level structure,
                //      with a null path and a fixed name. Would be nice to 
also allow references
                //      to be added to a list, using a path and a id key or 
index.
 
-               $value = $serializer->getSerialized( $reference );
+               $value = $serializer->serialize( $reference );
+
+               // Inject the 'datatype' into the serialization
+               foreach ( $value['snaks'] as $propertyIdGroup => &$snakGroup ) {
+                       $dataType = 
$this->dataTypeLookup->getDataTypeIdForProperty(
+                               new PropertyId( $propertyIdGroup )
+                       );
+                       foreach ( $snakGroup as &$snak ) {
+                               $snak['datatype'] = $dataType;
+                       }
+               }
+
                $this->setValue( null, 'reference', $value );
        }
 
diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php 
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
index 12a92b9..b42a8d4 100644
--- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -88,7 +88,8 @@
                        $mockEntityTitleLookup,
                        $libSerializerFactory,
                        new SerializerFactory( new DataValueSerializer() ),
-                       new MockSiteStore()
+                       new MockSiteStore(),
+                       $mockPropertyDataTypeLookup
                );
 
                if ( is_array( $options ) ) {
@@ -884,6 +885,7 @@
                                                                'type' => 
'string',
                                                        ),
                                                        'datatype' => 
'DtIdFor_P12',
+                                                       'hash' => 
'9b19cde2d3be5730e55dffc2163b59bea9702727',
                                                )
                                        ),
                                ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If89d508e3e27b5e1be7b69922aaa163c2d32e125
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to