Daniel Kinzler has uploaded a new change for review.

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


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.

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 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/Wikibase.classes.php
M repo/includes/WikibaseRepo.php
M repo/includes/store/sql/SqlStore.php
13 files changed, 247 insertions(+), 15 deletions(-)


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

diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index a7767a2..61f35e7 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -13,6 +13,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;
@@ -47,6 +48,11 @@
  * @author Daniel Kinzler
  */
 final class WikibaseClient {
+
+       /**
+        * @var PropertyDataTypeLookup
+        */
+       public $propertyDataTypeLookup;
 
        /**
         * @since 0.4
@@ -169,10 +175,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;
        }
 
        /**
@@ -182,7 +192,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/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index b226735..4cdde82 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -136,6 +136,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/Wikibase.classes.php b/repo/Wikibase.classes.php
index 63f62e1..9a3706c 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -143,6 +143,7 @@
                'Wikibase\EntityPerPageTable' => 
'includes/store/sql/EntityPerPageTable.php',
                'Wikibase\DispatchStats' => 
'includes/store/sql/DispatchStats.php',
                'Wikibase\TermSearchKeyBuilder' => 
'includes/store/sql/TermSearchKeyBuilder.php',
+               'Wikibase\PropertyInfoTableBuilder' => 
'includes/store/sql/PropertyInfoTableBuilder.php',
 
                // includes/updates
                'Wikibase\EntityDeletionUpdate' => 
'includes/updates/EntityDeletionUpdate.php',
@@ -158,6 +159,7 @@
                // maintenance
                'Wikibase\RebuildTermsSearchKey' => 
'maintenance/rebuildTermsSearchKey.php',
                'Wikibase\RebuildEntityPerPage' => 
'maintenance/rebuildEntityPerPage.php',
+               'Wikibase\RebuildPropertyInfo' => 
'maintenance/rebuildPropertyInfo.php',
 
                // tests
                'Wikibase\Test\TestItemContents' => 
'tests/phpunit/TestItemContents.php',
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 3b87e11..b81ba02 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -12,6 +12,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;
@@ -153,7 +154,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: newchange
Gerrit-Change-Id: I6b3b9fb0f400cca80641a78a28e51d742e01024a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to