Addshore has uploaded a new change for review.

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

Change subject: Add datatypes to API output for all types of Snak
......................................................................

Add datatypes to API output for all types of Snak

Prior to this change only snaks with a type 'value'
will have had the datatype injected.

To me there is little point in limiting this and the
datatype can also be usefull for somevalue and novalue
snaks so always add it..

As well as changing the API output this will also
change the output of the EntityDataSerializationService
which uses the ResultBuilder.

Change-Id: Id880a2da8dbac08e8b88fe6ac51205e5673a85c4
---
M repo/includes/api/ResultBuilder.php
M repo/tests/phpunit/includes/api/ResultBuilderTest.php
2 files changed, 13 insertions(+), 22 deletions(-)


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

diff --git a/repo/includes/api/ResultBuilder.php 
b/repo/includes/api/ResultBuilder.php
index dbeba62..a6f1608 100644
--- a/repo/includes/api/ResultBuilder.php
+++ b/repo/includes/api/ResultBuilder.php
@@ -1061,15 +1061,7 @@
                        foreach ( $array as $propertyIdGroupKey => &$snakGroup 
) {
                                $dataType = 
$dtLookup->getDataTypeIdForProperty( new PropertyId( $propertyIdGroupKey ) );
                                foreach ( $snakGroup as &$snak ) {
-                                       /**
-                                        * TODO: We probably want to return the 
datatype for NoValue and SomeValue snaks too
-                                        *       but this is not done by the 
LibSerializers thus not done here.
-                                        * TODO: Also DataModelSerialization 
has a TypedSnak object and serializer which we
-                                        *       might be able to use in some 
way here
-                                        */
-                                       if ( $snak['snaktype'] === 'value' ) {
-                                               $snak['datatype'] = $dataType;
-                                       }
+                                       $snak['datatype'] = $dataType;
                                }
                        }
                        return $array;
@@ -1080,15 +1072,7 @@
                $dtLookup = $this->dataTypeLookup;
                return function ( $array ) use ( $dtLookup ) {
                        $dataType = $dtLookup->getDataTypeIdForProperty( new 
PropertyId( $array['property'] ) );
-                       /**
-                        * TODO: We probably want to return the datatype for 
NoValue and SomeValue snaks too
-                        *       but this is not done by the LibSerializers 
thus not done here.
-                        * TODO: Also DataModelSerialization has a TypedSnak 
object and serializer which we
-                        *       might be able to use in some way here
-                        */
-                       if ( $array['snaktype'] === 'value' ) {
-                               $array['datatype'] = $dataType;
-                       }
+                       $array['datatype'] = $dataType;
                        return $array;
                };
        }
diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php 
b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
index 2c2135d..9083ca8 100644
--- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php
+++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php
@@ -208,6 +208,7 @@
                                                                                
        'hash' => '210b00274bf03247a89de918f15b12142ebf9e56',
                                                                                
        'snaktype' => 'somevalue',
                                                                                
        'property' => 'P65',
+                                                                               
        'datatype' => 'DtIdFor_P65',
                                                                                
),
                                                                        ),
                                                                ),
@@ -222,13 +223,15 @@
                                                                                
        'P65' => array(
                                                                                
                array(
                                                                                
                        'snaktype' => 'somevalue',
-                                                                               
                        'property' => 'P65'
+                                                                               
                        'property' => 'P65',
+                                                                               
                        'datatype' => 'DtIdFor_P65',
                                                                                
                )
                                                                                
        ),
                                                                                
        'P68' => array(
                                                                                
                array(
                                                                                
                        'snaktype' => 'somevalue',
-                                                                               
                        'property' => 'P68'
+                                                                               
                        'property' => 'P68',
+                                                                               
                        'datatype' => 'DtIdFor_P68',
                                                                                
                )
                                                                                
        ),
                                                                                
),
@@ -341,6 +344,7 @@
                                                                                
        'hash' => '210b00274bf03247a89de918f15b12142ebf9e56',
                                                                                
        'snaktype' => 'somevalue',
                                                                                
        'property' => 'P65',
+                                                                               
        'datatype' => 'DtIdFor_P65',
                                                                                
),
                                                                                
'_element' => 'qualifiers',
                                                                        ),
@@ -359,7 +363,8 @@
                                                                                
                'id' => 'P65',
                                                                                
                array(
                                                                                
                        'snaktype' => 'somevalue',
-                                                                               
                        'property' => 'P65'
+                                                                               
                        'property' => 'P65',
+                                                                               
                        'datatype' => 'DtIdFor_P65',
                                                                                
                ),
                                                                                
                '_element' => 'snak',
                                                                                
        ),
@@ -367,7 +372,8 @@
                                                                                
                'id' => 'P68',
                                                                                
                array(
                                                                                
                        'snaktype' => 'somevalue',
-                                                                               
                        'property' => 'P68'
+                                                                               
                        'property' => 'P68',
+                                                                               
                        'datatype' => 'DtIdFor_P68',
                                                                                
                ),
                                                                                
                '_element' => 'snak',
                                                                                
        ),
@@ -1191,6 +1197,7 @@
                                                                'mainsnak' => 
array(
                                                                        
'snaktype' => 'somevalue',
                                                                        
'property' => 'P12',
+                                                                       
'datatype' => 'DtIdFor_P12',
                                                                ),
                                                                'type' => 
'statement',
                                                                'rank' => 
'normal',

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

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

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

Reply via email to