jenkins-bot has submitted this change and it was merged. ( 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/i18n/en.json M client/i18n/qqq.json 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 7 files changed, 42 insertions(+), 0 deletions(-) Approvals: WMDE-leszek: Looks good to me, but someone else must approve jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, approved diff --git a/client/i18n/en.json b/client/i18n/en.json index a98e542..3d06608 100644 --- a/client/i18n/en.json +++ b/client/i18n/en.json @@ -112,6 +112,7 @@ "wikibase-pageinfo-entity-usage-S": "Sitelink", "wikibase-pageinfo-entity-usage-L": "Label: $1", "wikibase-pageinfo-entity-usage-T": "Title", + "wikibase-pageinfo-entity-usage-C": "Statement: $1", "wikibase-pageinfo-entity-usage-X": "All entity data", "wikibase-pageinfo-entity-usage-O": "Other (Statements)", "wikibase-property-render-error": "Failed to render property $1: $2", diff --git a/client/i18n/qqq.json b/client/i18n/qqq.json index ad291ef..8afc175 100644 --- a/client/i18n/qqq.json +++ b/client/i18n/qqq.json @@ -123,6 +123,7 @@ "wikibase-pageinfo-entity-usage-S": "Name for ''sitelink'' entity usage\n{{Identical|Sitelink}}", "wikibase-pageinfo-entity-usage-L": "Name for ''label'' entity usage\n{{Identical|Label}}", "wikibase-pageinfo-entity-usage-T": "Name for ''title'' entity usage\n{{Identical|Title}}", + "wikibase-pageinfo-entity-usage-C": "Name for ''statement'' entity usage\n", "wikibase-pageinfo-entity-usage-X": "Name for ''all'' entity usage", "wikibase-pageinfo-entity-usage-O": "Name for ''other'' entity usage", "wikibase-property-render-error": "Error message shown when the #property parser function fails to render a property value.\n\nParameters:\n* $1 - the property ID or name\n* $2 - the original error message (this is typically in English and may be rather technical)", 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..597878b 100644 --- a/client/includes/Usage/EntityUsage.php +++ b/client/includes/Usage/EntityUsage.php @@ -41,6 +41,14 @@ const TITLE_USAGE = 'T'; /** + * Usage flag indicating that certain statements (identified by their property id) + * from the entity were used. + * This currently implies that we also have an OTHER_USAGE or an ALL_USAGE + * for the same entity (STATEMENT_USAGE is never used alone). + */ + const STATEMENT_USAGE = 'C'; + + /** * Usage flag indicating that any and all aspects of the entity * were (or may have been) used. */ @@ -63,6 +71,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..7ede1de 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. @@ -34,6 +35,7 @@ public function testAddGetUsage() { $this->testAddAndGetLabelUsage(); $this->testAddAndGetTitleUsage(); + $this->testAddAndGetStatementUsage(); $this->testAddAndGetSiteLinksUsage(); $this->testAddAndGetOtherUsage(); $this->testAddAndGetAllUsage(); @@ -43,6 +45,7 @@ $expected = array( new EntityUsage( $q2, EntityUsage::LABEL_USAGE, 'xx' ), new EntityUsage( $q2, EntityUsage::TITLE_USAGE ), + new EntityUsage( $q3, EntityUsage::STATEMENT_USAGE, 'P42' ), new EntityUsage( $q2, EntityUsage::SITELINK_USAGE ), new EntityUsage( $q2, EntityUsage::OTHER_USAGE ), new EntityUsage( $q3, EntityUsage::ALL_USAGE ), @@ -72,6 +75,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 testAddAndGetSiteLinksUsage() { $q2 = new ItemId( 'Q2' ); $this->usageAccumulator->addSiteLinksUsage( $q2 ); -- To view, visit https://gerrit.wikimedia.org/r/353154 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia4c53a021917d16ad719c29b8b8f86e7216eb3fd Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits