Daniel Kinzler has uploaded a new change for review.

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


Change subject: Sort statements in EntityView by rank.
......................................................................

Sort statements in EntityView by rank.

Also provides a sorting mode to ClaimsSerializer.
This is not really needed yet, but could/should be used
in wbgetentities.

Change-Id: I6e40cfdbf3838aae5ee40e9dd9795a4407d49ca4
---
M lib/WikibaseLib.classes.php
M lib/includes/serializers/ByPropertyListSerializer.php
A lib/includes/serializers/ByRankSorter.php
M lib/includes/serializers/SerializationOptions.php
M lib/tests/phpunit/claim/DiffOpValueFormatterTest.php
M lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php
A lib/tests/phpunit/serializers/ByRankSorterTest.php
M lib/tests/phpunit/serializers/ClaimsSerializerTest.php
M repo/includes/EntityView.php
M repo/tests/phpunit/includes/EntityViewTest.php
10 files changed, 322 insertions(+), 58 deletions(-)


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

diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index 4bb20af..44c45c0 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -146,6 +146,7 @@
                // includes/api/serializers
                'Wikibase\Lib\Serializers\ByPropertyListSerializer' => 
'includes/serializers/ByPropertyListSerializer.php',
                'Wikibase\Lib\Serializers\ByPropertyListUnserializer' => 
'includes/serializers/ByPropertyListUnserializer.php',
+               'Wikibase\Lib\Serializers\ByRankSorter' => 
'includes/serializers/ByRankSorter.php',
                'Wikibase\Lib\Serializers\ClaimSerializer' => 
'includes/serializers/ClaimSerializer.php',
                'Wikibase\Lib\Serializers\ClaimsSerializer' => 
'includes/serializers/ClaimsSerializer.php',
                'Wikibase\Lib\Serializers\DispatchingEntitySerializer' => 
'includes/serializers/DispatchingEntitySerializer.php',
diff --git a/lib/includes/serializers/ByPropertyListSerializer.php 
b/lib/includes/serializers/ByPropertyListSerializer.php
index f62c928..a33a7e5 100644
--- a/lib/includes/serializers/ByPropertyListSerializer.php
+++ b/lib/includes/serializers/ByPropertyListSerializer.php
@@ -14,10 +14,9 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
  */
 class ByPropertyListSerializer extends SerializerObject {
-
-       const OPT_ADD_LOWER_CASE_KEYS = 'addLowerCaseKeys';
 
        /**
         * @since 0.2
@@ -34,6 +33,11 @@
        protected $elementSerializer;
 
        /**
+        * @var ByRankSorter|null
+        */
+       protected $sorter = null;
+
+       /**
         * Constructor.
         *
         * @since 0.2
@@ -47,6 +51,11 @@
 
                $this->elementName = $elementName;
                $this->elementSerializer = $elementSerializer;
+
+               if ( $this->options->hasOption( 
SerializationOptions::OPT_SORT_BY_RANK )
+                       && $this->options->getOption( 
SerializationOptions::OPT_SORT_BY_RANK ) ) {
+                       $this->sorter = new ByRankSorter();
+               }
        }
 
        /**
@@ -73,9 +82,14 @@
                $objects->buildIndex();
 
                foreach ( $objects->getPropertyIds() as $propertyId ) {
-                       $serializedObjects = array();
+                       $objectsForId = $objects->getByPropertyId( $propertyId 
);
 
-                       foreach ( $objects->getByPropertyId( $propertyId ) as 
$object ) {
+                       if ( $this->sorter ) {
+                               $objectsForId = $this->sorter->sort( 
$objectsForId );
+                       }
+
+                       $serializedObjects = array();
+                       foreach ( $objectsForId as $object ) {
                                $serializedObjects[] = 
$this->elementSerializer->getSerialized( $object );
                        }
 
diff --git a/lib/includes/serializers/ByRankSorter.php 
b/lib/includes/serializers/ByRankSorter.php
new file mode 100644
index 0000000..41127e2
--- /dev/null
+++ b/lib/includes/serializers/ByRankSorter.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Wikibase\Lib\Serializers;
+use Wikibase\Claim;
+use Wikibase\Statement;
+
+/**
+ * Sorts claims according to their rank (and property).
+ *
+ * @since 0.5
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class ByRankSorter {
+
+       /**
+        * Sorts claims according to their rank.
+        * The association of array keys with their respective values are 
maintained.
+        * This uses a stable bubble sort, so the original order of claims with 
the
+        * same rank is not changed.
+        *
+        * @param Claim[] $claims
+        *
+        * @return Claim[]
+        */
+       public function sort( $claims ) {
+               $keys = array_keys( $claims );
+
+               foreach ( $keys as $i => $keyI ) {
+                       /* @var Claim $claim */
+                       $claimI = $claims[$keyI];
+
+                       // bubble up
+                       for ( $j = $i-1; $j >= 0; $j-- ) {
+                               $keyJ =  $keys[$j];
+                               $claimJ =  $claims[$keyJ];
+
+                               $comp = $this->compare( $claimI, $claimJ );
+
+                               if ( $comp > 0 ) {
+                                       $keys[$j+1] = $keyJ;
+                                       $keys[$j] = $keyI;
+                               } else {
+                                       break;
+                               }
+                       }
+               }
+
+               $sorted = array();
+
+               foreach ( $keys as $key ) {
+                       $sorted[$key] = $claims[$key];
+               }
+
+               return $sorted;
+       }
+
+       /**
+        * Returns a positive number if $a's rank is larger than $b's,
+        * and a negative number if $b's rank is larger than $a's.
+        *
+        * @param Claim $a
+        * @param Claim $b
+        *
+        * @return Claim|Statement
+        */
+       protected function compare( Claim $a, Claim $b ) {
+               $rankA = ( $a instanceof Statement ) ? $a->getRank() : 
Claim::RANK_TRUTH;
+               $rankB = ( $b instanceof Statement ) ? $b->getRank() : 
Claim::RANK_TRUTH;
+
+               return $rankA - $rankB;
+       }
+
+
+}
diff --git a/lib/includes/serializers/SerializationOptions.php 
b/lib/includes/serializers/SerializationOptions.php
index 41cffa2..312c48f 100644
--- a/lib/includes/serializers/SerializationOptions.php
+++ b/lib/includes/serializers/SerializationOptions.php
@@ -63,6 +63,12 @@
        const OPT_GROUP_BY_PROPERTIES = 'groupByProperties';
 
        /**
+        * @since 0.5
+        * @const key for the sortByRank option
+        */
+       const OPT_SORT_BY_RANK = 'sortByRank';
+
+       /**
         * @var array
         */
        protected $options = array();
@@ -78,6 +84,7 @@
                $this->initOption( self::OPT_ID_KEY_MODE, self::ID_KEYS_UPPER );
                $this->initOption( self::OPT_INDEX_TAGS, false );
                $this->initOption( self::OPT_GROUP_BY_PROPERTIES, array( 
'claims', 'qualifiers', 'references' ) );
+               $this->initOption( self::OPT_SORT_BY_RANK, false );
        }
 
        protected function checkKey( $key) {
diff --git a/lib/tests/phpunit/claim/DiffOpValueFormatterTest.php 
b/lib/tests/phpunit/claim/DiffOpValueFormatterTest.php
index 8e7b203..3ff557e 100644
--- a/lib/tests/phpunit/claim/DiffOpValueFormatterTest.php
+++ b/lib/tests/phpunit/claim/DiffOpValueFormatterTest.php
@@ -14,7 +14,7 @@
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
  */
-class DiffOpValueFormatterTest extends \PHPUnit_Framework_TestCase {
+class DiffOpValueFormatterTest extends \MediaWikiTestCase {
 
        /**
         * @dataProvider provideGenerateHtml
@@ -28,6 +28,8 @@
                $formatter = new DiffOpValueFormatter( $name, $oldValues, 
$newValues );
 
                $html = $formatter->generateHtml();
+
+               $this->assertValidHtml( '<table>' . $html . '</table><' );
                $this->assertRegExp( $pattern, $html );
        }
 
diff --git a/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php 
b/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php
index f182d70..eb60ba9 100644
--- a/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php
+++ b/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php
@@ -3,14 +3,18 @@
 namespace Wikibase\Test;
 
 use DataValues\StringValue;
+use Wikibase\Claim;
+use Wikibase\Claims;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\Lib\Serializers\ByPropertyListSerializer;
+use Wikibase\Lib\Serializers\ClaimSerializer;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\Serializers\SnakSerializer;
 use Wikibase\PropertyNoValueSnak;
 use Wikibase\PropertySomeValueSnak;
 use Wikibase\PropertyValueSnak;
 use Wikibase\SnakList;
+use Wikibase\Statement;
 
 /**
  * @covers Wikibase\Lib\Serializers\ByPropertyListSerializer
@@ -23,6 +27,7 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
  */
 class ByPropertyListSerializerTest extends SerializerBaseTest {
 
@@ -199,4 +204,33 @@
 
                return $validArgs;
        }
+
+       public function testSortByRank() {
+               $claims = array(
+                       new Statement( new PropertySomeValueSnak( new 
PropertyId( 'P2' ) ) ),
+                       new Statement( new PropertyNoValueSnak( new PropertyId( 
'P2' ) ) ),
+                       new Claim( new PropertySomeValueSnak( new PropertyId( 
'P1' ) ) ),
+               );
+
+               $claims[1]->setRank( Claim::RANK_PREFERRED );
+
+               foreach ( $claims as $i => $claim ) {
+                       $claim->setGuid( 'ClaimsSerializerTest$claim-' . $i );
+               }
+
+               $opts = new SerializationOptions();
+               $opts->setOption( SerializationOptions::OPT_SORT_BY_RANK, true 
);
+
+               $serializer = new ByPropertyListSerializer( 'claim', new 
ClaimSerializer( new SnakSerializer( null, $opts ), $opts ), $opts );
+               $serialized = $serializer->getSerialized( new Claims( $claims ) 
);
+
+               $this->assertEquals( array( 'P2', 'P1' ), array_keys( 
$serialized ) );
+               $this->assertArrayHasKey( '0', $serialized['P2'] );
+               $this->assertArrayHasKey( '1', $serialized['P2'] );
+               $this->assertArrayHasKey( '0', $serialized['P1'] );
+
+               // make sure they got sorted
+               $this->assertEquals( $serialized['P2'][0]['id'], 
'ClaimsSerializerTest$claim-1' );
+               $this->assertEquals( $serialized['P2'][1]['id'], 
'ClaimsSerializerTest$claim-0' );
+       }
 }
diff --git a/lib/tests/phpunit/serializers/ByRankSorterTest.php 
b/lib/tests/phpunit/serializers/ByRankSorterTest.php
new file mode 100644
index 0000000..c6df113
--- /dev/null
+++ b/lib/tests/phpunit/serializers/ByRankSorterTest.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace Wikibase\Test;
+use Wikibase\Claim;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\Lib\Serializers\ByRankSorter;
+use Wikibase\PropertyNoValueSnak;
+use Wikibase\Statement;
+
+/**
+ * @covers Wikibase\Lib\Serializers\ByRankSorter
+ *
+ * @since 0.5
+ *
+ * @group WikibaseLib
+ * @group Wikibase
+ * @group WikibaseSerialization
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class ByRankSorterTest extends \MediaWikiTestCase {
+
+       public function provideSort() {
+               $pref1 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P11' ) ) );
+               $pref1->setRank( Claim::RANK_PREFERRED );
+
+               $pref2 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P12' ) ) );
+               $pref2->setRank( Claim::RANK_PREFERRED );
+
+               $norm1 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P21' ) ) );
+               $norm1->setRank( Claim::RANK_NORMAL );
+
+               $norm2 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P22' ) ) );
+               $norm2->setRank( Claim::RANK_NORMAL );
+
+               $depr1 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P31' ) ) );
+               $depr1->setRank( Claim::RANK_DEPRECATED );
+
+               $depr2 = new Statement( new PropertyNoValueSnak( new 
PropertyId( 'P32' ) ) );
+               $depr2->setRank( Claim::RANK_DEPRECATED );
+
+               $claim1 = new Claim( new PropertyNoValueSnak( new PropertyId( 
'P41' ) ) );
+               $claim2 = new Claim( new PropertyNoValueSnak( new PropertyId( 
'P42' ) ) );
+
+               return array(
+                       'empty' => array(
+                               array(),
+                               array(),
+                       ),
+                       'singleton' => array(
+                               array( 'x' => $pref1 ),
+                               array( 'x' => $pref1 ),
+                       ),
+                       'same' => array(
+                               array( $norm1, $norm2 ),
+                               array( $norm1, $norm2 ),
+                       ),
+                       'sorted' => array(
+                               array( $claim1, $claim2, $pref1, $pref2, 
$norm1, $norm2, $depr1, $depr2 ),
+                               array( $claim1, $claim2, $pref1, $pref2, 
$norm1, $norm2, $depr1, $depr2 ),
+                       ),
+                       'one off, tagged' => array(
+                               array( $claim1, 'x' => $pref1, $pref2, $norm1, 
$norm2, 'y' => $claim2, $depr1, $depr2 ),
+                               array( $claim1, 'y' => $claim2, 'x' => $pref1, 
$pref2, $norm1, $norm2, $depr1, $depr2 ),
+                       ),
+                       'mixed' => array(
+                               array( 'd1' => $depr1, 'n1' => $norm1, 'p1' => 
$pref1, 'c1' => $claim1, 'n2' => $norm2, 'c2' => $claim2, 'd2' => $depr2, 'p2' 
=> $pref2 ),
+                               array( 'c1' => $claim1, 'c2' => $claim2, 'p1' 
=> $pref1, 'p2' => $pref2, 'n1' => $norm1, 'n2' => $norm2, 'd1' => $depr1, 'd2' 
=> $depr2 ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideSort
+        *
+        * @param Claim[] $input
+        * @param Claim[] $expected
+        */
+       public function testSort( $input, $expected ) {
+               $sorter = new ByRankSorter();
+               $actual = $sorter->sort( $input );
+
+               $this->assertArrayEquals( $this->getIdMap( $expected ), 
$this->getIdMap( $actual ), true, true );
+       }
+
+       protected function getIdMap( $claims ) {
+               $ids = array_map( function( Claim $claim ) {
+                       return 
$claim->getMainSnak()->getPropertyId()->getSerialization();
+               }, $claims );
+
+               return $ids;
+       }
+}
diff --git a/lib/tests/phpunit/serializers/ClaimsSerializerTest.php 
b/lib/tests/phpunit/serializers/ClaimsSerializerTest.php
index d752128..f69f641 100644
--- a/lib/tests/phpunit/serializers/ClaimsSerializerTest.php
+++ b/lib/tests/phpunit/serializers/ClaimsSerializerTest.php
@@ -24,6 +24,7 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
  */
 class ClaimsSerializerTest extends SerializerBaseTest {
 
@@ -59,10 +60,12 @@
                $propertyId = new PropertyId( 'P42' );
 
                $claims = array(
-                       new Claim( new PropertyNoValueSnak( $propertyId ) ),
+                       new Statement( new PropertySomeValueSnak( $propertyId ) 
),
                        new Statement( new PropertyNoValueSnak( $propertyId ) ),
                        new Claim( new PropertySomeValueSnak( new PropertyId( 
'P1' ) ) ),
                );
+
+               $claims[1]->setRank( Claim::RANK_PREFERRED );
 
                foreach ( $claims as $i => $claim ) {
                        $claim->setGuid( 'ClaimsSerializerTest$claim-' . $i );
@@ -99,4 +102,33 @@
                return $validArgs;
        }
 
+       public function testSortByRank() {
+               $claims = array(
+                       new Statement( new PropertySomeValueSnak( new 
PropertyId( 'P2' ) ) ),
+                       new Statement( new PropertyNoValueSnak( new PropertyId( 
'P2' ) ) ),
+                       new Claim( new PropertySomeValueSnak( new PropertyId( 
'P1' ) ) ),
+               );
+
+               $claims[1]->setRank( Claim::RANK_PREFERRED );
+
+               foreach ( $claims as $i => $claim ) {
+                       $claim->setGuid( 'ClaimsSerializerTest$claim-' . $i );
+               }
+
+               $opts = new SerializationOptions();
+               $opts->setOption( SerializationOptions::OPT_SORT_BY_RANK, true 
);
+
+               $serializer = new ClaimsSerializer( new ClaimSerializer( new 
SnakSerializer( null, $opts ), $opts ), $opts );
+               $serialized = $serializer->getSerialized( new Claims( $claims ) 
);
+
+               $this->assertEquals( array( 'P2', 'P1' ), array_keys( 
$serialized ) );
+               $this->assertArrayHasKey( '0', $serialized['P2'] );
+               $this->assertArrayHasKey( '1', $serialized['P2'] );
+               $this->assertArrayHasKey( '0', $serialized['P1'] );
+
+               // make sure they got sorted
+               $this->assertEquals( $serialized['P2'][0]['id'], 
'ClaimsSerializerTest$claim-1' );
+               $this->assertEquals( $serialized['P2'][1]['id'], 
'ClaimsSerializerTest$claim-0' );
+       }
+
 }
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index 91ae138..eccd32b 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -14,6 +14,7 @@
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\Lib\PropertyDataTypeLookup;
+use Wikibase\Lib\Serializers\ByRankSorter;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\Serializers\SerializerFactory;
 use Wikibase\Lib\SnakFormatter;
@@ -565,24 +566,21 @@
                        'claims' // ID - TODO: should not be added if output 
page is not the entity's page
                );
 
-               // aggregate claims by properties
-               $claimsByProperty = array();
-               foreach( $claims as $claim ) {
-                       $propertyId = $claim->getMainSnak()->getPropertyId();
-                       $claimsByProperty[$propertyId->getNumericId()][] = 
$claim;
-               }
-
                $labels = $this->getPropertyLabels( $entity, $languageCode );
+               $byRankSorter = new ByRankSorter();
 
-               /**
-                * @var string $claimsHtml
-                * @var Claim[] $claims
-                */
+               // aggregate claims by properties
+               $claimsByProperty = new ByPropertyIdArray( $claims );
+               $claimsByProperty->buildIndex();
+
                $claimsHtml = '';
-               foreach( $claimsByProperty as $claims ) {
+               foreach ( $claimsByProperty->getPropertyIds() as $propertyId ) {
                        $propertyHtml = '';
 
-                       $propertyId = 
$claims[0]->getMainSnak()->getPropertyId();
+                       /* @var Claim[] $claims */
+                       $claims = $claimsByProperty->getByPropertyId( 
$propertyId );
+                       $claims = $byRankSorter->sort( $claims );
+
                        $propertyKey = $propertyId->getSerialization();
                        $propertyLabel = isset( $labels[$propertyKey] ) ? 
$labels[$propertyKey] : $propertyKey;
                        $propertyLink = \Linker::link(
@@ -796,6 +794,7 @@
                // TODO: use injected id formatter
                $serializationOptions = new SerializationOptions();
                $serializationOptions->setLanguages( Utils::getLanguageCodes() 
+ array( $langCode => $this->languageFallbackChain ) );
+               $serializationOptions->setOption( 
SerializationOptions::OPT_SORT_BY_RANK, true );
 
                $serializerFactory = new SerializerFactory( 
$serializationOptions );
                $serializer = $serializerFactory->newSerializerForObject( 
$entity, $serializationOptions );
diff --git a/repo/tests/phpunit/includes/EntityViewTest.php 
b/repo/tests/phpunit/includes/EntityViewTest.php
index e0e35d9..f81a7f1 100644
--- a/repo/tests/phpunit/includes/EntityViewTest.php
+++ b/repo/tests/phpunit/includes/EntityViewTest.php
@@ -27,6 +27,7 @@
 use Wikibase\PropertySomeValueSnak;
 use Wikibase\PropertyValueSnak;
 use Wikibase\Snak;
+use Wikibase\Statement;
 
 /**
  * @covers Wikibase\EntityView
@@ -154,14 +155,14 @@
         */
        public function getHtmlForClaimsProvider() {
                $item = $this->makeItem( 'Q33', array(
-                       $this->makeClaim( new PropertyNoValueSnak(
+                       $this->makeStatement( new PropertyNoValueSnak(
                                new PropertyId( 'P11' )
                        ) ),
-                       $this->makeClaim( new PropertyValueSnak(
+                       $this->makeStatement( new PropertyValueSnak(
                                new PropertyId( 'P11' ),
                                new EntityIdValue( new ItemId( 'Q22' ) )
-                       ) ),
-                       $this->makeClaim( new PropertyValueSnak(
+                       ), Claim::RANK_PREFERRED ),
+                       $this->makeStatement( new PropertyValueSnak(
                                new PropertyId( 'P23' ),
                                new StringValue( 'test' )
                        ) ),
@@ -255,14 +256,15 @@
                return $property;
        }
 
-       protected function makeClaim( Snak $mainSnak, $guid = null ) {
+       protected function makeStatement( Snak $mainSnak, $rank = 
Claim::RANK_NORMAL, $guid = null ) {
                if ( $guid === null ) {
                        $this->guidCounter++;
                        $guid = 'EntityViewTest$' . $this->guidCounter;
                }
 
-               $claim = new Claim( $mainSnak );
+               $claim = new Statement( $mainSnak );
                $claim->setGuid( $guid );
+               $claim->setRank( $rank );
 
                return $claim;
        }
@@ -282,28 +284,28 @@
                        array() );
 
                $argLists["PropertyNoValueSnak"] = array(
-                       array( $this->makeClaim( new PropertyNoValueSnak( $p44 
) ) ),
+                       array( $this->makeStatement( new PropertyNoValueSnak( 
$p44 ) ) ),
                        array( $p44 ) );
 
                $argLists["PropertySomeValueSnak"] = array(
-                       array( $this->makeClaim( new PropertySomeValueSnak( 
$p44 ) ) ),
+                       array( $this->makeStatement( new PropertySomeValueSnak( 
$p44 ) ) ),
                        array( $p44 ) );
 
                $argLists["PropertyValueSnak with string value"] = array(
-                       array( $this->makeClaim( new PropertyValueSnak( $p23, 
new StringValue( 'onoez' ) ) ) ),
+                       array( $this->makeStatement( new PropertyValueSnak( 
$p23, new StringValue( 'onoez' ) ) ) ),
                        array( $p23 ) );
 
                $argLists["PropertyValueSnak with EntityId"] = array(
-                       array( $this->makeClaim( new PropertyValueSnak( $p44, 
new EntityIdValue( $q23 ) ) ) ),
+                       array( $this->makeStatement( new PropertyValueSnak( 
$p44, new EntityIdValue( $q23 ) ) ) ),
                        array( $p44, $q23 ) );
 
                $argLists["Mixed Snaks"] = array(
                        array(
-                               $this->makeClaim( new PropertyValueSnak( $p11, 
new EntityIdValue( $q23 ) ) ),
-                               $this->makeClaim( new PropertyNoValueSnak( $p44 
) ),
-                               $this->makeClaim( new PropertySomeValueSnak( 
$p44 ) ),
-                               $this->makeClaim( new PropertyValueSnak( $p44, 
new StringValue( 'onoez' ) ) ),
-                               $this->makeClaim( new PropertyValueSnak( $p44, 
new EntityIdValue( $q24 ) ) ),
+                               $this->makeStatement( new PropertyValueSnak( 
$p11, new EntityIdValue( $q23 ) ) ),
+                               $this->makeStatement( new PropertyNoValueSnak( 
$p44 ) ),
+                               $this->makeStatement( new 
PropertySomeValueSnak( $p44 ) ),
+                               $this->makeStatement( new PropertyValueSnak( 
$p44, new StringValue( 'onoez' ) ) ),
+                               $this->makeStatement( new PropertyValueSnak( 
$p44, new EntityIdValue( $q24 ) ) ),
                        ),
                        array( $p11, $q23, $p44, $q24 ) );
 
@@ -343,19 +345,19 @@
                        array() );
 
                $argLists["PropertyNoValueSnak"] = array(
-                       array( $this->makeClaim( new PropertyNoValueSnak( $p42 
) ) ),
+                       array( $this->makeStatement( new PropertyNoValueSnak( 
$p42 ) ) ),
                        array());
 
                $argLists["PropertySomeValueSnak"] = array(
-                       array( $this->makeClaim( new PropertySomeValueSnak( 
$p42 ) ) ),
+                       array( $this->makeStatement( new PropertySomeValueSnak( 
$p42 ) ) ),
                        array() );
 
                $argLists["PropertyValueSnak with string value"] = array(
-                       array( $this->makeClaim( new PropertyValueSnak( $p23, 
new StringValue( 'http://not/a/url' )  ) ) ),
+                       array( $this->makeStatement( new PropertyValueSnak( 
$p23, new StringValue( 'http://not/a/url' )  ) ) ),
                        array() );
 
                $argLists["PropertyValueSnak with URL"] = array(
-                       array( $this->makeClaim( new PropertyValueSnak( $p42, 
new StringValue( 'http://acme.com/test' ) ) ) ),
+                       array( $this->makeStatement( new PropertyValueSnak( 
$p42, new StringValue( 'http://acme.com/test' ) ) ) ),
                        array( 'http://acme.com/test' ) );
 
                return $argLists;
@@ -441,9 +443,9 @@
                $p11 = new PropertyId( 'p11' );
                $p77 = new PropertyId( 'p77' ); // unknown property
 
-               $entity->addClaim( $this->makeClaim( new PropertyValueSnak( 
$p11, new EntityIdValue( $q33 ) ) ) );
-               $entity->addClaim( $this->makeClaim( new PropertyValueSnak( 
$p11, new EntityIdValue( $q44 ) ) ) );
-               $entity->addClaim( $this->makeClaim( new PropertyValueSnak( 
$p77, new EntityIdValue( $q33 ) ) ) );
+               $entity->addClaim( $this->makeStatement( new PropertyValueSnak( 
$p11, new EntityIdValue( $q33 ) ) ) );
+               $entity->addClaim( $this->makeStatement( new PropertyValueSnak( 
$p11, new EntityIdValue( $q44 ) ), Claim::RANK_PREFERRED ) );
+               $entity->addClaim( $this->makeStatement( new PropertyValueSnak( 
$p77, new EntityIdValue( $q33 ) ) ) );
 
                $revision = new EntityRevision( $entity, 1234567, 
'20130505333333' );
 
@@ -482,6 +484,22 @@
                                'claims' =>
                                array(
                                        'P11' => array(
+                                               array( // preferred statement 
first
+                                                       'id' => 
'EntityViewTest$2',
+                                                       'mainsnak' => array(
+                                                               'snaktype' => 
'value',
+                                                               'property' => 
'P11',
+                                                               'datavalue' => 
array(
+                                                                       'value' 
=> array(
+                                                                               
'entity-type' => 'item',
+                                                                               
'numeric-id' => 44,
+                                                                       ),
+                                                                       'type' 
=> 'wikibase-entityid',
+                                                               ),
+                                                       ),
+                                                       'type' => 'statement',
+                                                       'rank' => 'preferred',
+                                               ),
                                                array(
                                                        'id' => 
'EntityViewTest$1',
                                                        'mainsnak' => array(
@@ -495,22 +513,8 @@
                                                                        'type' 
=> 'wikibase-entityid',
                                                                ),
                                                        ),
-                                                       'type' => 'claim',
-                                               ),
-                                               array(
-                                                       'id' => 
'EntityViewTest$2',
-                                                       'mainsnak' => array(
-                                                               'snaktype' => 
'value',
-                                                               'property' => 
'P11',
-                                                               'datavalue' => 
array(
-                                                                       'value' 
=> array(
-                                                                               
'entity-type' => 'item',
-                                                                               
'numeric-id' => 44,
-                                                                       ),
-                                                                       'type' 
=> 'wikibase-entityid',
-                                                               ),
-                                                       ),
-                                                       'type' => 'claim',
+                                                       'type' => 'statement',
+                                                       'rank' => 'normal',
                                                ),
                                        ),
                                        'P77' => array(
@@ -527,7 +531,8 @@
                                                                        'type' 
=> 'wikibase-entityid',
                                                                ),
                                                        ),
-                                                       'type' => 'claim',
+                                                       'type' => 'statement',
+                                                       'rank' => 'normal',
                                                ),
                                        ),
                                ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e40cfdbf3838aae5ee40e9dd9795a4407d49ca4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to