jenkins-bot has submitted this change and it was merged.

Change subject: (bug 49742) Hook PropertyInfoStore in service reg.
......................................................................


(bug 49742) Hook PropertyInfoStore in service reg.

This causes the PropertyInfoStore to be used per default
as a backend to the PropertyDataTypeLookup service.

DEPLOYMENT NOTE:
when deploying this without running update.php,
set $wgWBRepoSettings['usePropertyInfoTable'] resp.
$wgWBClientSettings['usePropertyInfoTable'] to false until
lib/includes/store/sql/wb_property_info.sql was run to create
the necessary table.

Change-Id: I6b3b9fb0f400cca80641a78a28e51d742e01024a
---
M client/includes/WikibaseClient.php
M client/includes/store/ClientStore.php
M client/includes/store/sql/CachingSqlStore.php
M client/includes/store/sql/DirectSqlStore.php
M docs/options.wiki
M lib/WikibaseLib.classes.php
M lib/config/WikibaseLib.default.php
A lib/includes/store/DummyPropertyInfoStore.php
M lib/includes/store/TermPropertyLabelResolver.php
A lib/tests/phpunit/store/DummyPropertyInfoStoreTest.php
M lib/tests/phpunit/store/PropertyInfoTableTest.php
M repo/includes/WikibaseRepo.php
M repo/includes/store/sql/SqlStore.php
13 files changed, 246 insertions(+), 15 deletions(-)

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



diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 3415771..18adf6f 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -14,6 +14,7 @@
 use Wikibase\Lib\EntityIdParser;
 use Wikibase\Lib\EntityRetrievingDataTypeLookup;
 use Wikibase\Lib\PropertyDataTypeLookup;
+use Wikibase\Lib\PropertyInfoDataTypeLookup;
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\TypedValueFormatter;
 use Wikibase\Lib\WikibaseDataTypeBuilders;
@@ -48,6 +49,11 @@
  * @author Daniel Kinzler
  */
 final class WikibaseClient {
+
+       /**
+        * @var PropertyDataTypeLookup
+        */
+       public $propertyDataTypeLookup;
 
        /**
         * @since 0.4
@@ -171,10 +177,14 @@
         *
         * @return PropertyDataTypeLookup
         */
-       public function newPropertyDataTypeLookup() {
-               //TODO: remember instance, re-use in getPropertyDataTypeLookup
-               //TODO: make sure in-process and memcached/apc caching is 
applied to property types
-               return new EntityRetrievingDataTypeLookup( 
$this->getEntityLookup() );
+       public function getPropertyDataTypeLookup() {
+               if ( $this->propertyDataTypeLookup === null ) {
+                       $infoStore = $this->getStore()->getPropertyInfoStore();
+                       $retrievingLookup = new EntityRetrievingDataTypeLookup( 
$this->getEntityLookup() );
+                       $this->propertyDataTypeLookup = new 
PropertyInfoDataTypeLookup( $infoStore, $retrievingLookup );
+               }
+
+               return $this->propertyDataTypeLookup;
        }
 
        /**
@@ -184,7 +194,7 @@
         */
        public function newSnakFormatter() {
                return new SnakFormatter(
-                       $this->newPropertyDataTypeLookup(),
+                       $this->getPropertyDataTypeLookup(),
                        new TypedValueFormatter(),
                        $this->getDataTypeFactory()
                );
diff --git a/client/includes/store/ClientStore.php 
b/client/includes/store/ClientStore.php
index 8ed355d..8ca38ef 100644
--- a/client/includes/store/ClientStore.php
+++ b/client/includes/store/ClientStore.php
@@ -90,6 +90,15 @@
        public function newChangesTable();
 
        /**
+        * Returns an PropertyInfoStore
+        *
+        * @since 0.4
+        *
+        * @return PropertyInfoStore
+        */
+       public function getPropertyInfoStore();
+
+       /**
         * Removes all data from the store.
         *
         * @since 0.2
diff --git a/client/includes/store/sql/CachingSqlStore.php 
b/client/includes/store/sql/CachingSqlStore.php
index 919d006..4441402 100644
--- a/client/includes/store/sql/CachingSqlStore.php
+++ b/client/includes/store/sql/CachingSqlStore.php
@@ -3,6 +3,7 @@
 namespace Wikibase;
 
 use Language;
+use LogicException;
 
 /**
  * Implementation of the client store interface using an SQL backend via 
MediaWiki's
@@ -185,7 +186,18 @@
         * @return TermIndex
         */
        public function getTermIndex() {
-               throw new MWException( "Not Implemented, " . __CLASS__ . " is 
incomplete." );
+               throw new LogicException( "Not Implemented, " . __CLASS__ . " 
is incomplete." );
+       }
+
+       /**
+        * @see Store::getPropertyInfoStore
+        *
+        * @since 0.4
+        *
+        * @return PropertyInfoStore
+        */
+       public function getPropertyInfoStore() {
+               throw new LogicException( "Not Implemented, " . __CLASS__ . " 
is incomplete." );
        }
 
        /**
diff --git a/client/includes/store/sql/DirectSqlStore.php 
b/client/includes/store/sql/DirectSqlStore.php
index ffbd9e5..2d0b281 100644
--- a/client/includes/store/sql/DirectSqlStore.php
+++ b/client/includes/store/sql/DirectSqlStore.php
@@ -52,6 +52,11 @@
        private $termIndex = null;
 
        /**
+        * @var PropertyInfoTable
+        */
+       private $propertyInfoTable = null;
+
+       /**
         * @var String|bool $repoWiki
         */
        protected $repoWiki;
@@ -241,4 +246,38 @@
                $this->clear();
        }
 
+
+       /**
+        * @see Store::getPropertyInfoStore
+        *
+        * @since 0.4
+        *
+        * @return PropertyInfoStore
+        */
+       public function getPropertyInfoStore() {
+               if ( !$this->propertyInfoTable ) {
+                       $this->propertyInfoTable = 
$this->newPropertyInfoTable();
+               }
+
+               return $this->propertyInfoTable;
+       }
+
+       /**
+        * Creates a new PropertyInfoTable
+        *
+        * @return PropertyInfoTable
+        */
+       protected function newPropertyInfoTable() {
+               if ( Settings::get( 'usePropertyInfoTable' ) ) {
+                       $table = new PropertyInfoTable( true, $this->repoWiki );
+
+                       //TODO: get cache type etc from config
+                       //TODO: better version ID from config!
+                       $key = $this->repoWiki . 
'/Wikibase/CachingPropertyInfoStore/' . WBL_VERSION;
+                       return new CachingPropertyInfoStore( $table, 
wfGetMainCache(), 3600, $key );
+               } else {
+                       // dummy info store
+                       return new DummyPropertyInfoStore();
+               }
+       }
 }
diff --git a/docs/options.wiki b/docs/options.wiki
index 1dfd557..1c6645c 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki
@@ -54,6 +54,7 @@
 :;length: the maximum length of the string, in characters.
 :Default: <code>array( 'length' => 250 )</code>
 ;multilang-truncate-length: Length of the prefix of overly long strings to be 
included in error messages reporting overly long strings. Defaults is 32 
characters.
+;usePropertyInfoTable: Whether to use the wb_property_info table for quick 
lookup of meta-information about properties. True per default, can be set to 
false in an environment where the necessary database update can't be deployed 
right away. To set up the table manually, run 
lib/includes/store/sql/wb_property_info.sql to create it, then use 
repo/maintenance/rebuildPropertyInfo.php to populate the table.
 
 == Client Settings ==
 
diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index 64893a8..5bad03e 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -138,6 +138,7 @@
                'Wikibase\TermPropertyLabelResolver' => 
'includes/store/TermPropertyLabelResolver.php',
 
                'Wikibase\PropertyInfoStore' => 
'includes/store/PropertyInfoStore.php',
+               'Wikibase\DummyPropertyInfoStore' => 
'includes/store/DummyPropertyInfoStore.php',
                'Wikibase\CachingPropertyInfoStore' => 
'includes/store/CachingPropertyInfoStore.php',
 
                // includes/store/sql
diff --git a/lib/config/WikibaseLib.default.php 
b/lib/config/WikibaseLib.default.php
index 2c4d095..89f5a68 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -39,6 +39,9 @@
                // whether changes get recorded to wb_changes
                'useChangesTable' => true,
 
+               // whether property meta data is available in wb_property_info
+               'usePropertyInfoTable' => true,
+
                'entityPrefixes' => array(
                        'q' => 'item',
                        'p' => 'property',
diff --git a/lib/includes/store/DummyPropertyInfoStore.php 
b/lib/includes/store/DummyPropertyInfoStore.php
new file mode 100644
index 0000000..c890408
--- /dev/null
+++ b/lib/includes/store/DummyPropertyInfoStore.php
@@ -0,0 +1,81 @@
+<?php
+ /**
+ *
+ * Copyright © 26.06.13 by the authors listed below.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @license GPL 2+
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @author Daniel Kinzler
+ */
+
+
+namespace Wikibase;
+
+/**
+ * Class DummyPropertyInfoStore is an implementation of PropertyInfoStore
+ * that does nothing.
+ *
+ * @since 0.4
+ *
+ * @package Wikibase
+ */
+class DummyPropertyInfoStore implements PropertyInfoStore {
+
+       /**
+        * @see   PropertyInfoStore::getPropertyInfo
+        *
+        * @param EntityId $propertyId
+        *
+        * @return null
+        */
+       public function getPropertyInfo( EntityId $propertyId ) {
+               return null;
+       }
+
+       /**
+        * @see   PropertyInfoStore::getAllPropertyInfo
+        *
+        * @return array[]
+        */
+       public function getAllPropertyInfo() {
+               return array();
+       }
+
+       /**
+        * @see PropertyInfoStore::setPropertyInfo
+        *
+        * @param EntityId $propertyId
+        * @param array    $info
+        */
+       public function setPropertyInfo( EntityId $propertyId, array $info ) {
+               // noop
+       }
+
+       /**
+        * @see   PropertyInfoStore::removePropertyInfo
+        *
+        * @param EntityId $propertyId
+        *
+        * @return bool false
+        */
+       public function removePropertyInfo( EntityId $propertyId ) {
+               return false;
+       }
+}
\ No newline at end of file
diff --git a/lib/includes/store/TermPropertyLabelResolver.php 
b/lib/includes/store/TermPropertyLabelResolver.php
index aaafee2..981b212 100644
--- a/lib/includes/store/TermPropertyLabelResolver.php
+++ b/lib/includes/store/TermPropertyLabelResolver.php
@@ -79,6 +79,8 @@
         * @param int         $cacheDuration    Number of seconds to keep the 
cached version for.
         *                                      Defaults to 3600 seconds = 1 
hour.
         * @param string|null $cacheKey         The cache key to use, 
auto-generated based on $lang per default.
+        *                                      Should be set to something 
including the wiki name
+        *                                      of the wiki that maintains the 
properties.
         */
        public function __construct(
                $lang,
diff --git a/lib/tests/phpunit/store/DummyPropertyInfoStoreTest.php 
b/lib/tests/phpunit/store/DummyPropertyInfoStoreTest.php
new file mode 100644
index 0000000..50472b8
--- /dev/null
+++ b/lib/tests/phpunit/store/DummyPropertyInfoStoreTest.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Wikibase\Test;
+
+use Wikibase\DummyPropertyInfoStore;
+use Wikibase\EntityId;
+use Wikibase\Property;
+use Wikibase\Item;
+use Wikibase\PropertyInfoStore;
+
+/**
+ * @covers Wikibase\DummyPropertyInfoStore
+ *
+ * @file
+ * @since 0.4
+ *
+ * @ingroup WikibaseLib
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseLib
+ * @group WikibasePropertyInfo
+ * @group WikibaseStore
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class DummyPropertyInfoStoreTest extends \MediaWikiTestCase {
+
+       public function newDummyPropertyInfoStore() {
+               return new DummyPropertyInfoStore();
+       }
+
+       public function testSetPropertyInfo() {
+               $store = $this->newDummyPropertyInfoStore();
+               $p23 = new EntityId( Property::ENTITY_TYPE, 23 );
+               $info23 = array( PropertyInfoStore::KEY_DATA_TYPE => 'string' );
+
+               // just check that there's no exception
+               $store->setPropertyInfo( $p23, $info23 );
+               $this->assertTrue( true ); // dummy
+       }
+
+       public function testGetPropertyInfo() {
+               $store = $this->newDummyPropertyInfoStore();
+               $p23 = new EntityId( Property::ENTITY_TYPE, 23 );
+
+               $this->assertNull( $store->getPropertyInfo( $p23 ) );
+       }
+
+       public function testGetAllPropertyInfo() {
+               $store = $this->newDummyPropertyInfoStore();
+
+               $this->assertCount( 0, $store->getAllPropertyInfo() );
+       }
+
+       public function testRemovePropertyInfo() {
+               $store = $this->newDummyPropertyInfoStore();
+               $p23 = new EntityId( Property::ENTITY_TYPE, 23 );
+
+               $this->assertFalse( $store->removePropertyInfo( $p23 ) );
+       }
+
+}
diff --git a/lib/tests/phpunit/store/PropertyInfoTableTest.php 
b/lib/tests/phpunit/store/PropertyInfoTableTest.php
index a8856a9..a62a5b0 100644
--- a/lib/tests/phpunit/store/PropertyInfoTableTest.php
+++ b/lib/tests/phpunit/store/PropertyInfoTableTest.php
@@ -46,10 +46,9 @@
                        $this->markTestSkipped( "Skipping because 
WikibaseClient doesn't have a local wb_property_info table." );
                }
 
-               //FIXME: usePropertyInfoTable is defined in a follow-up
-               //if ( !Settings::get( 'usePropertyInfoTable' ) ) {
-               //      $this->markTestSkipped( "Skipping because 
wb_property_info isn't configured." );
-               //}
+               if ( !Settings::get( 'usePropertyInfoTable' ) ) {
+                       $this->markTestSkipped( "Skipping because 
wb_property_info isn't configured." );
+               }
 
                $this->tablesUsed[] = 'wb_property_info';
        }
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index b4df38c..1d4f1d4 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -13,6 +13,7 @@
 use Wikibase\Lib\EntityIdParser;
 use Wikibase\Lib\EntityRetrievingDataTypeLookup;
 use Wikibase\Lib\PropertyDataTypeLookup;
+use Wikibase\Lib\PropertyInfoDataTypeLookup;
 use Wikibase\Lib\SnakConstructionService;
 use Wikibase\Lib\WikibaseDataTypeBuilders;
 use Wikibase\Settings;
@@ -159,7 +160,9 @@
         */
        public function getPropertyDataTypeLookup() {
                if ( $this->propertyDataTypeLookup === null ) {
-                       $this->propertyDataTypeLookup = new 
EntityRetrievingDataTypeLookup( $this->getEntityLookup() );
+                       $infoStore = $this->getStore()->getPropertyInfoStore();
+                       $retrievingLookup = new EntityRetrievingDataTypeLookup( 
$this->getEntityLookup() );
+                       $this->propertyDataTypeLookup = new 
PropertyInfoDataTypeLookup( $infoStore, $retrievingLookup );
                }
 
                return $this->propertyDataTypeLookup;
diff --git a/repo/includes/store/sql/SqlStore.php 
b/repo/includes/store/sql/SqlStore.php
index 7f1c49e..b29c3c2 100644
--- a/repo/includes/store/sql/SqlStore.php
+++ b/repo/includes/store/sql/SqlStore.php
@@ -271,10 +271,17 @@
         * @return PropertyInfoTable
         */
        protected function newPropertyInfoTable() {
-               //FIXME: use usePropertyInfoTable defined in follow-up
-               //FIXME: use CachingPropertyInfoStore defined in follow-up
-               $table = new PropertyInfoTable( false );
-               return $table;
+               if ( Settings::get( 'usePropertyInfoTable' ) ) {
+                       $table = new PropertyInfoTable( false );
+
+                       //TODO: get cache type etc from config
+                       //TODO: better version ID from config!
+                       $key = wfWikiID() . 
'/Wikibase/CachingPropertyInfoStore/' . WBL_VERSION;
+                       return new CachingPropertyInfoStore( $table, 
wfGetMainCache(), 3600, $key );
+               } else {
+                       // dummy info store
+                       return new DummyPropertyInfoStore();
+               }
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6b3b9fb0f400cca80641a78a28e51d742e01024a
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to