Hoo man has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353154 )

Change subject: Add EntityUsage::STATEMENT_USAGE and adopt UsageAccumulator
......................................................................

Add EntityUsage::STATEMENT_USAGE and adopt UsageAccumulator

This allows adding entity usages for specific (groups of)
Statements identified by their property id.

I chose "C" as aspect key for the old "Claim" (:/), because "S"
is already used for Sitelinks.

Bug: T151717
Change-Id: Ia4c53a021917d16ad719c29b8b8f86e7216eb3fd
---
M client/includes/Api/ApiListEntityUsage.php
M client/includes/Api/ApiPropsEntityUsage.php
M client/includes/Usage/EntityUsage.php
M client/includes/Usage/UsageAccumulator.php
M client/tests/phpunit/includes/Usage/UsageAccumulatorContractTester.php
5 files changed, 38 insertions(+), 0 deletions(-)


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

diff --git a/client/includes/Api/ApiListEntityUsage.php 
b/client/includes/Api/ApiListEntityUsage.php
index 0bd57b7..6296626 100644
--- a/client/includes/Api/ApiListEntityUsage.php
+++ b/client/includes/Api/ApiListEntityUsage.php
@@ -254,6 +254,7 @@
                                        EntityUsage::SITELINK_USAGE,
                                        EntityUsage::LABEL_USAGE,
                                        EntityUsage::TITLE_USAGE,
+                                       EntityUsage::STATEMENT_USAGE,
                                        EntityUsage::ALL_USAGE,
                                        EntityUsage::OTHER_USAGE,
                                ]
diff --git a/client/includes/Api/ApiPropsEntityUsage.php 
b/client/includes/Api/ApiPropsEntityUsage.php
index 7053e2b..a67a820 100644
--- a/client/includes/Api/ApiPropsEntityUsage.php
+++ b/client/includes/Api/ApiPropsEntityUsage.php
@@ -178,6 +178,7 @@
                                        EntityUsage::SITELINK_USAGE,
                                        EntityUsage::LABEL_USAGE,
                                        EntityUsage::TITLE_USAGE,
+                                       EntityUsage::STATEMENT_USAGE,
                                        EntityUsage::ALL_USAGE,
                                        EntityUsage::OTHER_USAGE,
                                ]
diff --git a/client/includes/Usage/EntityUsage.php 
b/client/includes/Usage/EntityUsage.php
index e4784b4..719a2e6 100644
--- a/client/includes/Usage/EntityUsage.php
+++ b/client/includes/Usage/EntityUsage.php
@@ -41,6 +41,12 @@
        const TITLE_USAGE = 'T';
 
        /**
+        * Usage flag indicating that a Statement from the entity was used.
+        * This currently implies OTHER_USAGE or ALL_USAGE.
+        */
+       const STATEMENT_USAGE = 'C';
+
+       /**
         * Usage flag indicating that any and all aspects of the entity
         * were (or may have been) used.
         */
@@ -63,6 +69,7 @@
                self::SITELINK_USAGE => null,
                self::LABEL_USAGE => null,
                self::TITLE_USAGE => null,
+               self::STATEMENT_USAGE => null,
                self::OTHER_USAGE => null,
                self::ALL_USAGE => null,
        );
diff --git a/client/includes/Usage/UsageAccumulator.php 
b/client/includes/Usage/UsageAccumulator.php
index b10dff2..4cdf999 100644
--- a/client/includes/Usage/UsageAccumulator.php
+++ b/client/includes/Usage/UsageAccumulator.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Client\Usage;
 
 use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\PropertyId;
 
 /**
  * Interface and base class for objects accumulating usage tracking 
information for a given page.
@@ -50,6 +51,16 @@
        }
 
        /**
+        * Registers the usage of statements from an entity (identified by 
their property id).
+        *
+        * @param EntityId $id
+        * @param PropertyId $propertyId The PropertyId of Statements that are 
used.
+        */
+       public function addStatementUsage( EntityId $id, PropertyId $propertyId 
) {
+               $this->addUsage( new EntityUsage( $id, 
EntityUsage::STATEMENT_USAGE, $propertyId->getSerialization() ) );
+       }
+
+       /**
         * Registers the usage of other (i.e. not label, sitelink, or title) of 
an
         * entity (e.g. access to statements or labels in labels a language 
other
         * than the content language).
diff --git 
a/client/tests/phpunit/includes/Usage/UsageAccumulatorContractTester.php 
b/client/tests/phpunit/includes/Usage/UsageAccumulatorContractTester.php
index 769ab25..dc3ba2c 100644
--- a/client/tests/phpunit/includes/Usage/UsageAccumulatorContractTester.php
+++ b/client/tests/phpunit/includes/Usage/UsageAccumulatorContractTester.php
@@ -6,6 +6,7 @@
 use Wikibase\Client\Usage\EntityUsage;
 use Wikibase\Client\Usage\UsageAccumulator;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
 
 /**
  * Contract tester for implementations of the UsageAccumulator interface.
@@ -35,6 +36,7 @@
                $this->testAddAndGetLabelUsage();
                $this->testAddAndGetTitleUsage();
                $this->testAddAndGetSiteLinksUsage();
+               $this->testAddAndGetStatementUsage();
                $this->testAddAndGetOtherUsage();
                $this->testAddAndGetAllUsage();
 
@@ -44,6 +46,7 @@
                        new EntityUsage( $q2, EntityUsage::LABEL_USAGE, 'xx' ),
                        new EntityUsage( $q2, EntityUsage::TITLE_USAGE ),
                        new EntityUsage( $q2, EntityUsage::SITELINK_USAGE ),
+                       new EntityUsage( $q3, EntityUsage::STATEMENT_USAGE, 
'P42' ),
                        new EntityUsage( $q2, EntityUsage::OTHER_USAGE ),
                        new EntityUsage( $q3, EntityUsage::ALL_USAGE ),
                );
@@ -82,6 +85,21 @@
                $this->assertContainsUsage( $expected, $entityUsages );
        }
 
+       private function testAddAndGetStatementUsage() {
+               $q3 = new ItemId( 'Q3' );
+               $p42 = new PropertyId( 'P42' );
+               $this->usageAccumulator->addStatementUsage( $q3, $p42 );
+
+               $expected = new EntityUsage(
+                       $q3,
+                       EntityUsage::STATEMENT_USAGE,
+                       $p42->getSerialization()
+               );
+
+               $usages = $this->usageAccumulator->getUsages();
+               $this->assertContainsUsage( $expected, $usages );
+       }
+
        private function testAddAndGetOtherUsage() {
                $q2 = new ItemId( 'Q2' );
                $this->usageAccumulator->addOtherUsage( $q2 );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4c53a021917d16ad719c29b8b8f86e7216eb3fd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>

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

Reply via email to