[MediaWiki-commits] [Gerrit] (Bug 47288) Use EntityUsageIndex on the client. - change (mediawiki...Wikibase)

2013-05-08 Thread Aude (Code Review)
Aude has submitted this change and it was merged.

Change subject: (Bug 47288) Use EntityUsageIndex on the client.
..


(Bug 47288) Use EntityUsageIndex on the client.

This also overhauls the way the SiteLinkTable is used, for
consistency.

Change-Id: Ide20d01f2c38047e6a640f1b3910df3b3cc9e69a
---
M client/includes/ChangeHandler.php
M client/includes/WikibaseLibrary.php
M client/includes/parserhooks/NoLangLinkHandler.php
M client/includes/parserhooks/PropertyParserFunction.php
M client/includes/store/ClientStore.php
M client/includes/store/sql/CachingSqlStore.php
M client/includes/store/sql/DirectSqlStore.php
M client/tests/phpunit/includes/ChangeHandlerTest.php
M lib/tests/phpunit/store/EntityUsageIndexTest.php
M lib/tests/phpunit/store/SiteLinkLookupTest.php
10 files changed, 154 insertions(+), 28 deletions(-)

Approvals:
  Aude: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/includes/ChangeHandler.php 
b/client/includes/ChangeHandler.php
index 0df9c64..3f3a627 100644
--- a/client/includes/ChangeHandler.php
+++ b/client/includes/ChangeHandler.php
@@ -108,7 +108,7 @@
 
public function __construct( PageUpdater $updater = null,
EntityLookup $entityLookup = null,
-   SiteLinkLookup $siteLinkLookup = null,
+   EntityUsageIndex $entityUsageIndex = null,
\Site $localSite = null ) {
 
wfProfileIn( __METHOD__ );
@@ -123,8 +123,8 @@
$entityLookup = 
WikibaseClient::getDefaultInstance()-getStore()-getEntityLookup();
}
 
-   if ( !$siteLinkLookup ) {
-   $siteLinkLookup = 
WikibaseClient::getDefaultInstance()-getStore()-newSiteLinkTable();
+   if ( !$entityUsageIndex ) {
+   $entityUsageIndex = 
WikibaseClient::getDefaultInstance()-getStore()-getEntityUsageIndex();
}
 
if ( !$localSite ) {
@@ -140,7 +140,7 @@
$this-site = $localSite;
$this-updater = $updater;
$this-entityLookup = $entityLookup;
-   $this-siteLinkLookup = $siteLinkLookup;
+   $this-entityUsageIndex = $entityUsageIndex;
 
// TODO: allow these to be passed in as parameters!
$this-setNamespaces(
@@ -549,15 +549,12 @@
if ( $change instanceof ItemChange ) {
// update local pages connected to a relevant data item.
 
-   $itemId = $change-getEntityId()-getNumericId();
+   $itemId = $change-getEntityId();
 
$siteGlobalId = $this-site-getGlobalId();
 
-   // @todo: getLinks is a bit ugly, need a getter for a 
pair of item id + site key
-   $siteLinks = $this-siteLinkLookup-getLinks( array( 
$itemId ), array( $siteGlobalId ) );
-   if ( !empty( $siteLinks ) ) {
-   $pagesToUpdate[] = $siteLinks[0][1];
-   }
+   $usedOnPages = $this-entityUsageIndex-getEntityUsage( 
array( $itemId ) );
+   $pagesToUpdate = array_merge( $pagesToUpdate, 
$usedOnPages );
 
// if an item's sitelinks change, update the old and 
the new target
$siteLinkDiff = ( $change instanceof ItemChange ) ? 
$change-getSiteLinkDiff() : null;
diff --git a/client/includes/WikibaseLibrary.php 
b/client/includes/WikibaseLibrary.php
index 96eb9bb..8039c60 100644
--- a/client/includes/WikibaseLibrary.php
+++ b/client/includes/WikibaseLibrary.php
@@ -94,7 +94,7 @@
public function getEntityId( $pageTitle = null ) {
$this-checkType( 'getEntityByTitle', 1, $pageTitle, 'string' );
$globalSiteId = \Wikibase\Settings::get( 'siteGlobalID' );
-   $table = WikibaseClient::getDefaultInstance()-getStore( 
'sqlstore' )-newSiteLinkTable();
+   $table = 
WikibaseClient::getDefaultInstance()-getStore()-getSiteLinkTable();
if ( $table == null ) {
return array( null );
}
diff --git a/client/includes/parserhooks/NoLangLinkHandler.php 
b/client/includes/parserhooks/NoLangLinkHandler.php
index 9008e36..e81608d 100644
--- a/client/includes/parserhooks/NoLangLinkHandler.php
+++ b/client/includes/parserhooks/NoLangLinkHandler.php
@@ -48,7 +48,7 @@
Settings::get( 'siteGlobalID' ),
Settings::get( 'namespaces' ),
Settings::get( 'excludeNamespaces' ),
-   
WikibaseClient::getDefaultInstance()-getStore()-newSiteLinkTable(),
+   
WikibaseClient::getDefaultInstance()-getStore()-getSiteLinkTable(),
\Sites::singleton()
);
 

[MediaWiki-commits] [Gerrit] (Bug 47288) Use EntityUsageIndex on the client. - change (mediawiki...Wikibase)

2013-04-16 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review.

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


Change subject: (Bug 47288) Use EntityUsageIndex on the client.
..

(Bug 47288) Use EntityUsageIndex on the client.

This also overhauls the way the SiteLinkTable is used, for
consistency.

Change-Id: Ide20d01f2c38047e6a640f1b3910df3b3cc9e69a
---
M client/WikibaseClient.hooks.php
M client/includes/ChangeHandler.php
M client/includes/WikibaseLibrary.php
M client/includes/parserhooks/NoLangLinkHandler.php
M client/includes/parserhooks/PropertyParserFunction.php
M client/includes/store/ClientStore.php
M client/includes/store/sql/CachingSqlStore.php
M client/includes/store/sql/DirectSqlStore.php
M client/tests/phpunit/includes/ChangeHandlerTest.php
M lib/tests/phpunit/store/EntityUsageIndexTest.php
M lib/tests/phpunit/store/SiteLinkLookupTest.php
11 files changed, 160 insertions(+), 30 deletions(-)


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

diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 3579b95..2d6120b 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -178,7 +178,7 @@
 * @return bool
 */
public static function onSpecialMovepageAfterMove( \MovePageForm 
$movePage, \Title $oldTitle, \Title $newTitle ) {
-   $siteLinkCache = 
ClientStoreFactory::getStore()-newSiteLinkTable();
+   $siteLinkCache = 
ClientStoreFactory::getStore()-getSiteLinkTable();
$globalId = Settings::get( 'siteGlobalID' );
$itemId = $siteLinkCache-getItemIdForLink(
$globalId,
@@ -374,7 +374,7 @@
Settings::get( 'siteGlobalID' ),
Settings::get( 'namespaces' ),
Settings::get( 'excludeNamespaces' ),
-   ClientStoreFactory::getStore()-newSiteLinkTable(),
+   ClientStoreFactory::getStore()-getSiteLinkTable(),
\Sites::singleton() );
 
$useRepoLinks = $langLinkHandler-useRepoLinks( 
$parser-getTitle(), $parser-getOutput() );
@@ -460,7 +460,7 @@
Settings::get( 'siteGlobalID' ),
Settings::get( 'namespaces' ),
Settings::get( 'excludeNamespaces' ),
-   ClientStoreFactory::getStore()-newSiteLinkTable(),
+   ClientStoreFactory::getStore()-getSiteLinkTable(),
\Sites::singleton() );
 
$noExternalLangLinks = 
$langLinkHandler-getNoExternalLangLinks( $pout );
diff --git a/client/includes/ChangeHandler.php 
b/client/includes/ChangeHandler.php
index 8837be8..6c5246e 100644
--- a/client/includes/ChangeHandler.php
+++ b/client/includes/ChangeHandler.php
@@ -106,7 +106,7 @@
 
public function __construct( PageUpdater $updater = null,
EntityLookup $entityLookup = null,
-   SiteLinkLookup $siteLinkLookup = null,
+   EntityUsageIndex $entityUsageIndex = null,
\Site $localSite = null ) {
 
wfProfileIn( __METHOD__ );
@@ -121,8 +121,8 @@
$entityLookup = 
ClientStoreFactory::getStore()-getEntityLookup();
}
 
-   if ( !$siteLinkLookup ) {
-   $siteLinkLookup = 
ClientStoreFactory::getStore()-newSiteLinkTable();
+   if ( !$entityUsageIndex ) {
+   $entityUsageIndex = 
ClientStoreFactory::getStore()-getEntityUsageIndex();
}
 
if ( !$localSite ) {
@@ -138,7 +138,7 @@
$this-site = $localSite;
$this-updater = $updater;
$this-entityLookup = $entityLookup;
-   $this-siteLinkLookup = $siteLinkLookup;
+   $this-entityUsageIndex = $entityUsageIndex;
 
// TODO: allow these to be passed in as parameters!
$this-setNamespaces(
@@ -547,15 +547,12 @@
if ( $change instanceof ItemChange ) {
// update local pages connected to a relevant data item.
 
-   $itemId = $change-getEntityId()-getNumericId();
+   $itemId = $change-getEntityId();
 
$siteGlobalId = $this-site-getGlobalId();
 
-   // @todo: getLinks is a bit ugly, need a getter for a 
pair of item id + site key
-   $siteLinks = $this-siteLinkLookup-getLinks( array( 
$itemId ), array( $siteGlobalId ) );
-   if ( !empty( $siteLinks ) ) {
-   $pagesToUpdate[] = $siteLinks[0][1];
-   }
+   $usedOnPages = $this-entityUsageIndex-getEntityUsage( 
array( $itemId ) );
+