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

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

Allow specifying a replacement usage type in disabledUsageAspects

Bug: T178153
Change-Id: I7a0391953a9b2915f99a6052ec1c274748f73c57
---
M client/includes/Usage/Sql/SqlUsageTracker.php
M client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
M docs/options.wiki
3 files changed, 20 insertions(+), 7 deletions(-)


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

diff --git a/client/includes/Usage/Sql/SqlUsageTracker.php 
b/client/includes/Usage/Sql/SqlUsageTracker.php
index 7a58f8b..7dbb1dd 100644
--- a/client/includes/Usage/Sql/SqlUsageTracker.php
+++ b/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/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php 
b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
index d0d90c2..84ba96d 100644
--- a/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
+++ b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php
@@ -79,19 +79,21 @@
                $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 ),
                ];
 
                $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' ],
                        array_keys( $this->getUsages( 23 ) )
                );
        }
diff --git a/docs/options.wiki b/docs/options.wiki
index 1f97998..47dc767 100644
--- a/docs/options.wiki
+++ b/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/384671
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a0391953a9b2915f99a6052ec1c274748f73c57
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

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

Reply via email to