Ladsgroup has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386406 )

Change subject: Allow specifying a replacement usage type in 
disabledUsageAspects
......................................................................

Allow specifying a replacement usage type in disabledUsageAspects

Bug: T178153
Change-Id: Ifb81c35ced6d5973ce882e317391c36494c6221a
---
M extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php
M 
extensions/Wikibase/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
M extensions/Wikibase/docs/options.wiki
3 files changed, 24 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikidata 
refs/changes/06/386406/1

diff --git a/extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php 
b/extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php
index 7a58f8b..7dbb1dd 100644
--- a/extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php
+++ b/extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php
@@ -34,6 +34,9 @@
        private $connectionManager;
 
        /**
+        * Usage aspects in this array won't be persisted. If string keys are 
used, this
+        * is treated as [ 'usage-aspect-to-replace' => 'replacement' ].
+        *
         * @var string[]
         */
        private $disabledUsageAspects;
@@ -121,14 +124,22 @@
         * @throws InvalidArgumentException
         * @return EntityUsage[]
         */
-       private function removeBlacklistedUsages( array $usages ) {
+       private function handleBlacklistedUsages( array $usages ) {
                $newUsages = [];
 
                foreach ( $usages as $usage ) {
                        if ( !( $usage instanceof EntityUsage ) ) {
                                throw new InvalidArgumentException( '$usages 
must contain EntityUsage objects.' );
                        }
-                       if ( in_array( $usage->getAspect(), 
$this->disabledUsageAspects ) ) {
+
+                       // Disabled usage with replacement
+                       if ( isset( 
$this->disabledUsageAspects[$usage->getAspect()] ) ) {
+                               $newUsages[] = new EntityUsage( 
$usage->getEntityId(), $this->disabledUsageAspects[$usage->getAspect()] );
+                               continue;
+                       }
+
+                       // Disabled usage aspects without replacement (integer 
key, no replace from -> to map)
+                       if ( is_int( array_search( $usage->getAspect(), 
$this->disabledUsageAspects ) ) ) {
                                continue;
                        }
 
@@ -152,7 +163,7 @@
                        throw new InvalidArgumentException( '$pageId must be an 
int.' );
                }
 
-               $usages = $this->removeBlacklistedUsages( $usages );
+               $usages = $this->handleBlacklistedUsages( $usages );
                if ( empty( $usages ) ) {
                        return;
                }
@@ -204,7 +215,7 @@
                        // queryUsages guarantees this to be identity string => 
EntityUsage
                        $oldUsages = $usageTable->queryUsages( $pageId );
 
-                       $usages = $this->removeBlacklistedUsages( $usages );
+                       $usages = $this->handleBlacklistedUsages( $usages );
                        $newUsages = $this->reindexEntityUsages( $usages );
 
                        $removed = array_diff_key( $oldUsages, $newUsages );
diff --git 
a/extensions/Wikibase/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
 
b/extensions/Wikibase/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
index d0d90c2..15d0c4f 100644
--- 
a/extensions/Wikibase/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
+++ 
b/extensions/Wikibase/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
@@ -72,26 +72,31 @@
                $this->trackerTester->testAddUsedEntities();
        }
 
-       public function testAddUsedEntitiesBlacklist() {
+       public function testAddUsedEntitiesDisabledAspects() {
                $q3 = new ItemId( 'Q3' );
                $q4 = new ItemId( 'Q4' );
+               $q5 = new ItemId( 'Q5' );
 
                $usages = [
                        new EntityUsage( $q3, EntityUsage::SITELINK_USAGE ),
                        new EntityUsage( $q3, EntityUsage::STATEMENT_USAGE, 
'P12' ),
+                       new EntityUsage( $q3, EntityUsage::DESCRIPTION_USAGE, 
'es' ),
                        new EntityUsage( $q4, EntityUsage::LABEL_USAGE, 'de' ),
+                       new EntityUsage( $q4, EntityUsage::OTHER_USAGE ),
+                       new EntityUsage( $q5, EntityUsage::OTHER_USAGE ),
+                       new EntityUsage( $q5, EntityUsage::DESCRIPTION_USAGE, 
'ru' ),
                ];
 
                $sqlUsageTracker = new SqlUsageTracker(
                        new ItemIdParser(),
                        new SessionConsistentConnectionManager( wfGetLB() ),
-                       [ EntityUsage::STATEMENT_USAGE ]
+                       [ EntityUsage::STATEMENT_USAGE, 
EntityUsage::DESCRIPTION_USAGE => EntityUsage::OTHER_USAGE ]
                );
                $sqlUsageTracker->addUsedEntities( 23, $usages );
 
                // All entries but the blacklisted should be set
                $this->assertEquals(
-                       [ 'Q3#S', 'Q4#L.de' ],
+                       [ 'Q3#S', 'Q3#O', 'Q4#L.de', 'Q4#O', 'Q5#O' ],
                        array_keys( $this->getUsages( 23 ) )
                );
        }
diff --git a/extensions/Wikibase/docs/options.wiki 
b/extensions/Wikibase/docs/options.wiki
index 1f97998..47dc767 100644
--- a/extensions/Wikibase/docs/options.wiki
+++ b/extensions/Wikibase/docs/options.wiki
@@ -115,7 +115,7 @@
 ;showExternalRecentChanges: Whether changes on the repository should be 
displayed on Special:RecentChanges, Special:Watchlist, etc on the client wiki. 
In contrast to <code>injectRecentChanges</code>, this setting just removes the 
changes from the user interface. The default is <code>false</code>. This is 
intended to temporarily prevent external changes from showing in order to find 
or fix some issue on a live site.
 ;sendEchoNotification: If true, allows users on the client wiki to get a 
notification when a page they created is connected to a repo item. This 
requires the Echo extension.
 ;echoIcon: If <code>sendEchoNotification</code> is set to <code>true</code>, 
you can also provide what icon the user will see. The correct syntax is <code>[ 
'url' => '...' ]</code> or <code>[ 'path' => '...' ]</code> where 
<code>path</code> is relative to <code>$wgExtensionAssetsPath</code>. Defaults 
to <code>false</code> which means that there will be the default Echo icon.
-;disabledUsageAspects: Array of usage aspects that should not be saved in the 
<code>wbc_entity_usage</code> table. This currently only supports aspect codes 
(like "T", "L" or "X"), but not full aspect keys (like "L.de").
+;disabledUsageAspects: Array of usage aspects that should not be saved in the 
<code>wbc_entity_usage</code> table. This supports aspect codes (like "T", "L" 
or "X"), but not full aspect keys (like "L.de"). For example <code>[ 'D', 'C' 
]</code> can be used to disable description and statement usages. Also a 
replacement usage type can be given in the form of <code>[ 
'usage-type-to-replace' => 'replacement' ]</code>.
 ;wikiPageUpdaterDbBatchSize: DEPRECATED. If set, acts as a default for 
purgeCacheBatchSize and recentChangesBatchSize.
 ;purgeCacheBatchSize: Number of pages to process in each HTMLCacheUpdateJob, a 
job used to send client wikis notifications about relevant changes to entities. 
Higher value mean fewer jobs but longer run-time per job. Defaults to 
wikiPageUpdaterDbBatchSize (for backwards compatibility) or MediaWiki core's 
$wgUpdateRowsPerJob (which currently defaults to 300).
 ;recentChangesBatchSize: Number of <code>recentchanges</code> table rows to 
create in each InjectRCRecordsJob, a job used to send client wikis 
notifications about relevant changes to entities. Higher value mean fewer jobs 
but longer run-time per job. Defaults to wikiPageUpdaterDbBatchSize (for 
backwards compatibility) or MediaWiki core's $wgUpdateRowsPerJob (which 
currently defaults to 300).

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb81c35ced6d5973ce882e317391c36494c6221a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikidata
Gerrit-Branch: wmf/1.31.0-wmf.4
Gerrit-Owner: Ladsgroup <[email protected]>

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

Reply via email to