Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377798 )

Change subject: [WIP] Diffing and Patching Lexeme forms and nextFormId
......................................................................

[WIP] Diffing and Patching Lexeme forms and nextFormId

Change-Id: Icfa5d5bfcbe7e48cab9f1d4c99eeba1bd656d39f
---
M docs/federation.wiki
M docs/options.wiki
M lib/includes/RepositoryDefinitions.php
M repo/includes/Specials/SpecialEntityData.php
M repo/includes/Store/Sql/SqlStore.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
M repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
M repo/tests/phpunit/includes/Store/StoreTest.php
M repo/tests/phpunit/includes/WikibaseRepoTest.php
10 files changed, 136 insertions(+), 271 deletions(-)


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

diff --git a/docs/federation.wiki b/docs/federation.wiki
index 3b0ed1e..240e1f6 100644
--- a/docs/federation.wiki
+++ b/docs/federation.wiki
@@ -4,8 +4,8 @@
 * Foreign EntityIds and mappings are documented in the file 
docs/foreign-entity-ids.wiki in the wikibase/data-model component.
 
 As of March 2017, in order to enable access to entities from federated 
repositories both Repo and Client components must be enabled. Also as of March 
2017, accessing data of foreign entities relies on the shared database access 
(databases of federated repositories must be in the same database cluster).
-* Local repository is configured as documented in docs/options.wiki. Note that 
as of March 2017, database of the local repository is configured based on 
Client's settings (''repoDatabase'' setting).
-* Configuration of foreign repositories is done using the 
''foreignRepositories'' setting in $wgWBClientSettings, as documented in the 
file docs/options.wiki.
+* Local repository is configured as documented in docs/options.wiki.
+* Configuration of foreign repositories is done using the 
''foreignRepositories'' setting in $wgWBRepoSettings or $wgWBClientSettings, as 
documented in the file docs/options.wiki.
 * In order to correctly link entities from foreign repositories, the local 
wiki must have MediaWiki interwiki prefixes configured for each foreign 
repository. As of March 2017, the interwiki prefix must be the same as the name 
used for the foreign repository. If there is no interwiki prefix configured for 
the wiki containing the foreign repository, it can be added e.g. by adding a 
row to the <code>interwiki</code> database table, or by using 
[[Special:Interwiki]] if the Interwiki extension is enabled on the local wiki.
 
 Note that as of March 2017 it is only possible for Wikibase to use entities 
from a single repository, either local or foreign. For instance, it is not 
possible to use both local and foreign items in statements.
@@ -17,7 +17,7 @@
 Note that as only foreign properties from the repository "prop" are to be 
used, this example configuration only enables local items explicitly.
 
 <pre>
-$wgWBClientSettings['foreignRepositories'] = [
+$wgWBRepoSettings['foreignRepositories'] = [
        'prop' => [
                'repoDatabase' => 'propwiki',
                'entityNamespaces' => [ 'property' => WB_NS_PROPERTY ],
@@ -25,5 +25,5 @@
                'baseUri' => 'http://prop.wiki/entity/',
        ],
 ];
-$wgWBClientSettings['repoNamespaces'] = [ 'item' => WB_NS_ITEM ];
+$wgWBRepoSettings['entityNamespaces'] = [ 'item' => WB_NS_ITEM ];
 </pre>
diff --git a/docs/options.wiki b/docs/options.wiki
index e2b8f95..fb35a24 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki
@@ -12,6 +12,11 @@
 ;siteLinkGroups: The site groups to use in sitelinks. Must correspond to a 
value used to give the site group in the MediaWiki <code>sites</code> table. 
Default is <code>array( 'wikipedia' )</code>. This defines which groups of 
sites can be linked to Wikibase items.
 :'''Note''' that this setting replaces the old ''siteLinkGroup'' setting, 
which only allowed for a single group.
 ;specialSiteLinkGroups: This maps one or more site groups into a single 
"special" group. This is useful if sites from multiple site groups should be 
shown in a single "special" section on item pages, instead of one section per 
site group. To show these site-groups you have to add the group "special" to 
the '''siteLinkGroups''' setting (see above).
+;foreignRepositories: An associative array mapping foreign repository names to 
settings relevant to the particular repository. Each repository's settings are 
an associative array containing the following keys:
+:;'entityNamespaces': A map of entity type identifiers (strings) that the 
local wiki supports from the foreign repository to namespaces identifiers 
(numbers) related to pages of entities of the given type on foreign 
repository's wiki..
+:;'repoDatabase': A symbolic database identifier (string) that MediaWiki's 
LBFactory class understands.
+:;'baseUri': A base URI (string) for concept URIs. It should contain scheme 
and authority part of the URI.
+:;'prefixMapping': A prefix mapping array, see also: 
docs/foreign-entity-ids.wiki in the DataModel component.
 
 === Expert Settings ===
 
@@ -100,11 +105,6 @@
 ;otherProjectsLinksByDefault: Whether to show links to other projects per 
default. If not set, the links can be enabled as a beta feature (see 
'''otherProjectsLinksBeta''').
 ;otherProjectsLinksBeta: If this is set to true links to other projects will 
be available as beta feature, enabling every user to turn them on/off if 
wanted. (Only applies if other project links aren't enabled per default and the 
BetaFeatures extension is installed)
 ;propertyOrderUrl: URL to use for retrieving the property order used for 
sorting properties by property ID. Will be ignored if set to null.
-;foreignRepositories: An associative array mapping foreign repository names to 
settings relevant to the particular repository. Each repository's settings are 
an associative array containing the following keys:
-:;'entityNamespaces': A map of entity type identifiers (strings) that the 
local wiki supports from the foreign repository to namespaces identifiers 
(numbers) related to pages of entities of the given type on foreign 
repository's wiki..
-:;'repoDatabase': A symbolic database identifier (string) that MediaWiki's 
LBFactory class understands.
-:;'baseUri': A base URI (string) for concept URIs. It should contain scheme 
and authority part of the URI.
-:;'prefixMapping': A prefix mapping array, see also: 
docs/foreign-entity-ids.wiki in the DataModel component.
 
 === Expert Settings ===
 ;showExternalRecentChanges: Whether changes on the repository should be 
displayed on Special:RecentChanges, Special:Watchlist, etc on the client wiki.
diff --git a/lib/includes/RepositoryDefinitions.php 
b/lib/includes/RepositoryDefinitions.php
index 060a924..03047ca 100644
--- a/lib/includes/RepositoryDefinitions.php
+++ b/lib/includes/RepositoryDefinitions.php
@@ -23,7 +23,7 @@
  * Note: currently single entity type is mapped to a single repository. This 
might change in the future
  * and a particular entity type might be provided by multiple repositories.
  *
- * @see docs/options.wiki for documentation on Client's "foreignRepositories" 
settings defining configuration
+ * @see docs/options.wiki for documentation on "foreignRepositories" settings 
defining configuration
  * of foreign repositories..
  *
  * @license GPL-2.0+
diff --git a/repo/includes/Specials/SpecialEntityData.php 
b/repo/includes/Specials/SpecialEntityData.php
index c9dbddc..c4cb0c5 100644
--- a/repo/includes/Specials/SpecialEntityData.php
+++ b/repo/includes/Specials/SpecialEntityData.php
@@ -90,7 +90,7 @@
                        $wikibaseRepo->getEntityRdfBuilderFactory(),
                        $wikibaseRepo->getSiteLookup()->getSites(),
                        $this->entityDataFormatProvider,
-                       $wikibaseRepo->getCompactSerializerFactory(),
+                       
$wikibaseRepo->getCompactBaseDataModelSerializerFactory(),
                        $wikibaseRepo->getCompactEntitySerializer(),
                        $wikibaseRepo->getSiteLookup(),
                        $wikibaseRepo->getRdfVocabulary()
diff --git a/repo/includes/Store/Sql/SqlStore.php 
b/repo/includes/Store/Sql/SqlStore.php
index 2089253..6bb448a 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -35,10 +35,6 @@
 use Wikibase\Lib\Store\SiteLinkStore;
 use Wikibase\Lib\Store\Sql\SiteLinkTable;
 use Wikibase\Lib\Store\Sql\PrefetchingWikiPageEntityMetaDataAccessor;
-use Wikibase\Lib\Store\Sql\SqlEntityInfoBuilderFactory;
-use Wikibase\Lib\Store\Sql\WikiPageEntityMetaDataAccessor;
-use Wikibase\Lib\Store\Sql\WikiPageEntityMetaDataLookup;
-use Wikibase\Lib\Store\Sql\WikiPageEntityRevisionLookup;
 use Wikibase\Repo\Store\DispatchingEntityStoreWatcher;
 use Wikibase\Repo\Store\EntityPerPage;
 use Wikibase\Repo\Store\EntitiesWithoutTermFinder;
@@ -106,11 +102,6 @@
        private $entityStoreWatcher = null;
 
        /**
-        * @var EntityInfoBuilderFactory|null
-        */
-       private $entityInfoBuilderFactory = null;
-
-       /**
         * @var PropertyInfoLookup|null
         */
        private $propertyInfoLookup = null;
@@ -156,9 +147,9 @@
        private $entityNamespaceLookup;
 
        /**
-        * @var WikibaseServices|null
+        * @var WikibaseServices
         */
-       private $wikibaseServices = null;
+       private $wikibaseServices;
 
        /**
         * @var string
@@ -198,7 +189,7 @@
         * @param EntityIdLookup $entityIdLookup
         * @param EntityTitleStoreLookup $entityTitleLookup
         * @param EntityNamespaceLookup $entityNamespaceLookup
-        * @param WikibaseServices|null $wikibaseServices Optional service 
container providing data access services
+        * @param WikibaseServices $wikibaseServices Service container 
providing data access services
         */
        public function __construct(
                EntityChangeFactory $entityChangeFactory,
@@ -208,7 +199,7 @@
                EntityIdLookup $entityIdLookup,
                EntityTitleStoreLookup $entityTitleLookup,
                EntityNamespaceLookup $entityNamespaceLookup,
-               WikibaseServices $wikibaseServices = null
+               WikibaseServices $wikibaseServices
        ) {
                $this->entityChangeFactory = $entityChangeFactory;
                $this->contentCodec = $contentCodec;
@@ -473,15 +464,8 @@
                /** @var WikiPageEntityStore $dispatcher */
                $dispatcher = $this->getEntityStoreWatcher();
 
-               if ( $this->wikibaseServices !== null ) {
-                       $dispatcher->registerWatcher( 
$this->wikibaseServices->getEntityStoreWatcher() );
-                       $nonCachingLookup = 
$this->wikibaseServices->getEntityRevisionLookup();
-               } else {
-                       // Watch for entity changes
-                       $metaDataFetcher = $this->getEntityPrefetcher();
-                       $dispatcher->registerWatcher( $metaDataFetcher );
-                       $nonCachingLookup = $this->getRawEntityRevisionLookup( 
$metaDataFetcher );
-               }
+               $dispatcher->registerWatcher( 
$this->wikibaseServices->getEntityStoreWatcher() );
+               $nonCachingLookup = 
$this->wikibaseServices->getEntityRevisionLookup();
 
                // Lower caching layer using persistent cache (e.g. memcached).
                $persistentCachingLookup = new CachingEntityRevisionLookup(
@@ -506,46 +490,13 @@
                return [ $nonCachingLookup, $hashCachingLookup ];
        }
 
-       private function getRawEntityRevisionLookup( 
WikiPageEntityMetaDataAccessor $metaDataFetcher ) {
-               return new WikiPageEntityRevisionLookup(
-                       $this->contentCodec,
-                       $metaDataFetcher,
-                       false
-               );
-       }
-
        /**
         * @see Store::getEntityInfoBuilderFactory
         *
         * @return EntityInfoBuilderFactory
         */
        public function getEntityInfoBuilderFactory() {
-               if ( !$this->entityInfoBuilderFactory ) {
-                       $this->entityInfoBuilderFactory = 
$this->newEntityInfoBuilderFactory();
-               }
-
-               return $this->entityInfoBuilderFactory;
-       }
-
-       /**
-        * Creates a new EntityInfoBuilderFactory
-        *
-        * @return EntityInfoBuilderFactory
-        */
-       private function newEntityInfoBuilderFactory() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getEntityInfoBuilderFactory();
-               }
-
-               $factory = new SqlEntityInfoBuilderFactory(
-                       $this->entityIdParser,
-                       $this->entityIdComposer,
-                       $this->entityNamespaceLookup
-               );
-
-               $factory->setReadFullEntityIdColumn( 
$this->readFullEntityIdColumn );
-
-               return $factory;
+               return $this->wikibaseServices->getEntityInfoBuilderFactory();
        }
 
        /**
@@ -569,16 +520,12 @@
         * @return PropertyInfoLookup
         */
        private function newPropertyInfoLookup() {
-               if ( $this->wikibaseServices !== null ) {
-                       $table = 
$this->wikibaseServices->getPropertyInfoLookup();
-               } else {
-                       $table = $this->getPropertyInfoTable();
-               }
+               $nonCachingLookup = 
$this->wikibaseServices->getPropertyInfoLookup();
 
                $cacheKey = $this->cacheKeyPrefix . 
':CacheAwarePropertyInfoStore';
 
                return new CachingPropertyInfoLookup(
-                       $table,
+                       $nonCachingLookup,
                        ObjectCache::getInstance( $this->cacheType ),
                        $this->cacheDuration,
                        $cacheKey
@@ -659,12 +606,7 @@
         * @return EntityPrefetcher
         */
        private function newEntityPrefetcher() {
-               if ( $this->wikibaseServices !== null ) {
-                       return $this->wikibaseServices->getEntityPrefetcher();
-               }
-               return new PrefetchingWikiPageEntityMetaDataAccessor(
-                       new WikiPageEntityMetaDataLookup( 
$this->entityNamespaceLookup )
-               );
+               return $this->wikibaseServices->getEntityPrefetcher();
        }
 
        /**
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index f67aadc..6b1297d 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -9,7 +9,6 @@
 use DataValues\Geo\Values\GlobeCoordinateValue;
 use DataValues\MonolingualTextValue;
 use DataValues\QuantityValue;
-use DataValues\Serializers\DataValueSerializer;
 use DataValues\StringValue;
 use DataValues\TimeValue;
 use DataValues\UnknownValue;
@@ -23,7 +22,6 @@
 use MediaWiki\Site\MediaWikiPageNameNormalizer;
 use MWException;
 use RequestContext;
-use Serializers\DispatchingSerializer;
 use Serializers\Serializer;
 use SiteLookup;
 use StubObject;
@@ -31,9 +29,10 @@
 use User;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
+use Wikibase\DataAccess\DataAccessSettings;
+use Wikibase\DataAccess\MultipleRepositoryAwareWikibaseServices;
 use Wikibase\Lib\Store\PropertyInfoLookup;
 use Wikibase\Repo\ChangeOp\ChangeOpFactoryProvider;
-use Wikibase\Client\WikibaseClient;
 use Wikibase\DataAccess\WikibaseServices;
 use Wikibase\DataModel\DeserializerFactory;
 use Wikibase\DataModel\Entity\DispatchingEntityIdParser;
@@ -143,7 +142,6 @@
 use Wikibase\SettingsArray;
 use Wikibase\SqlStore;
 use Wikibase\Store;
-use Wikibase\Store\BufferingTermLookup;
 use Wikibase\Store\EntityIdLookup;
 use Wikibase\StringNormalizer;
 use Wikibase\SummaryFormatter;
@@ -187,11 +185,6 @@
        private $propertyDataTypeLookup = null;
 
        /**
-        * @var LanguageFallbackChainFactory|null
-        */
-       private $languageFallbackChainFactory = null;
-
-       /**
         * @var StatementGuidValidator|null
         */
        private $statementGuidValidator = null;
@@ -202,16 +195,6 @@
        private $entityDeserializer = null;
 
        /**
-        * @var Serializer|null
-        */
-       private $entitySerializer = null;
-
-       /**
-        * @var Serializer|null
-        */
-       private $compactEntitySerializer = null;
-
-       /**
         * @var EntityIdParser|null
         */
        private $entityIdParser = null;
@@ -220,11 +203,6 @@
         * @var EntityIdComposer|null
         */
        private $entityIdComposer = null;
-
-       /**
-        * @var StringNormalizer|null
-        */
-       private $stringNormalizer = null;
 
        /**
         * @var OutputFormatSnakFormatterFactory|null
@@ -255,16 +233,6 @@
         * @var Store|null
         */
        private $store = null;
-
-       /**
-        * @var EntityNamespaceLookup|null
-        */
-       private $entityNamespaceLookup = null;
-
-       /**
-        * @var TermLookup|null
-        */
-       private $termLookup = null;
 
        /**
         * @var ContentLanguages|null
@@ -333,16 +301,6 @@
 
                $settings = WikibaseSettings::getRepoSettings();
 
-               $repositoryDefinitions = 
self::getRepositoryDefinitionsFromSettings( $settings );
-
-               $dataRetrievalServices = null;
-
-               // If client functionality is enabled, use it to enable 
federation.
-               if ( WikibaseSettings::isClientEnabled() ) {
-                       $dataRetrievalServices = 
WikibaseClient::getDefaultInstance()->getWikibaseServices();
-                       $repositoryDefinitions = 
WikibaseClient::getDefaultInstance()->getRepositoryDefinitions();
-               }
-
                return new self(
                        $settings,
                        new DataTypeDefinitions(
@@ -350,8 +308,7 @@
                                $settings->getSetting( 'disabledDataTypes' )
                        ),
                        new EntityTypeDefinitions( $entityTypeDefinitions ),
-                       $repositoryDefinitions,
-                       $dataRetrievalServices
+                       self::getRepositoryDefinitionsFromSettings( $settings )
                );
        }
 
@@ -361,12 +318,25 @@
         * @return RepositoryDefinitions
         */
        private static function getRepositoryDefinitionsFromSettings( 
SettingsArray $settings ) {
-               return new RepositoryDefinitions( [ '' => [
+               // FIXME: It might no longer be needed to check different 
settings (e.g. changesDatabase vs foreignRepositories)
+               // once repository-related settings are unified, see: T153767.
+               $definitions = [ '' => [
                        'database' => $settings->getSetting( 'changesDatabase' 
),
                        'base-uri' => $settings->getSetting( 'conceptBaseUri' ),
                        'prefix-mapping' => [ '' => '' ],
                        'entity-namespaces' => $settings->getSetting( 
'entityNamespaces' ),
-               ] ] );
+               ] ];
+
+               foreach ( $settings->getSetting( 'foreignRepositories' ) as 
$repository => $repositorySettings ) {
+                       $definitions[$repository] = [
+                               'database' => 
$repositorySettings['repoDatabase'],
+                               'base-uri' => $repositorySettings['baseUri'],
+                               'entity-namespaces' => 
$repositorySettings['entityNamespaces'],
+                               'prefix-mapping' => 
$repositorySettings['prefixMapping'],
+                       ];
+               }
+
+               return new RepositoryDefinitions( $definitions );
        }
 
        /**
@@ -508,35 +478,21 @@
        }
 
        /**
-        * FIXME: Optional $wikibaseServices makes it possible to access
-        * entities from foreign repositories from Repo component but they also 
introduce the optional
-        * dependency on the Client component. Such dependency is bad and in 
the long run it should be removed
-        * by making WikibaseServices implementation provided to WikibaseRepo 
not be bound to WikibaseClient.
-        * WikibaseServices provided by WikibaseClient instance is only used in 
the transition period until
-        * WikibaseServices no longer depends on services from Wikibase\Client 
namespace.
-        *
         * @param SettingsArray $settings
         * @param DataTypeDefinitions $dataTypeDefinitions
         * @param EntityTypeDefinitions $entityTypeDefinitions
         * @param RepositoryDefinitions $repositoryDefinitions
-        * @param WikibaseServices|null $wikibaseServices optional container of 
service providing the
-        *        access to the entity data that will be used by the Repo 
instead of it creating
-        *        instances of those services itself.
-        *        This container could be provided in order to allow Repo make 
use of Dispatching services
-        *        and access data of entities from foreign repositories.
         */
        public function __construct(
                SettingsArray $settings,
                DataTypeDefinitions $dataTypeDefinitions,
                EntityTypeDefinitions $entityTypeDefinitions,
-               RepositoryDefinitions $repositoryDefinitions,
-               WikibaseServices $wikibaseServices = null
+               RepositoryDefinitions $repositoryDefinitions
        ) {
                $this->settings = $settings;
                $this->dataTypeDefinitions = $dataTypeDefinitions;
                $this->entityTypeDefinitions = $entityTypeDefinitions;
                $this->repositoryDefinitions = $repositoryDefinitions;
-               $this->wikibaseServices = $wikibaseServices;
        }
 
        /**
@@ -746,16 +702,7 @@
         * @return TermIndexSearchInteractor
         */
        public function newTermSearchInteractor( $displayLanguageCode ) {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getTermSearchInteractorFactory()->newInteractor(
-                               $displayLanguageCode
-                       );
-               }
-
-               return new TermIndexSearchInteractor(
-                       $this->getStore()->getTermIndex(),
-                       $this->getLanguageFallbackChainFactory(),
-                       $this->getPrefetchingTermLookup(),
+               return 
$this->getWikibaseServices()->getTermSearchInteractorFactory()->newInteractor(
                        $displayLanguageCode
                );
        }
@@ -787,15 +734,7 @@
         * @return StringNormalizer
         */
        public function getStringNormalizer() {
-               if ( $this->wikibaseServices !== null ) {
-                       return $this->wikibaseServices->getStringNormalizer();
-               }
-
-               if ( $this->stringNormalizer === null ) {
-                       $this->stringNormalizer = new StringNormalizer();
-               }
-
-               return $this->stringNormalizer;
+               return $this->getWikibaseServices()->getStringNormalizer();
        }
 
        /**
@@ -920,15 +859,7 @@
         * @return LanguageFallbackChainFactory
         */
        public function getLanguageFallbackChainFactory() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getLanguageFallbackChainFactory();
-               }
-
-               if ( $this->languageFallbackChainFactory === null ) {
-                       $this->languageFallbackChainFactory = new 
LanguageFallbackChainFactory();
-               }
-
-               return $this->languageFallbackChainFactory;
+               return 
$this->getWikibaseServices()->getLanguageFallbackChainFactory();
        }
 
        /**
@@ -973,7 +904,7 @@
                                $this->getEntityIdLookup(),
                                $this->getEntityTitleLookup(),
                                $this->getEntityNamespaceLookup(),
-                               $this->wikibaseServices
+                               $this->getWikibaseServices()
                        );
                }
 
@@ -1017,24 +948,7 @@
         * @return PrefetchingTermLookup
         */
        public function getPrefetchingTermLookup() {
-               if ( !$this->termLookup ) {
-                       $this->termLookup = $this->newPrefetchingTermLookup();
-               }
-
-               return $this->termLookup;
-       }
-
-       /**
-        * @return PrefetchingTermLookup
-        */
-       private function newPrefetchingTermLookup() {
-               if ( $this->wikibaseServices !== null ) {
-                       return $this->wikibaseServices->getTermBuffer();
-               }
-               return new BufferingTermLookup(
-                       $this->getStore()->getTermIndex(),
-                       1000 // @todo: configure buffer size
-               );
+               return $this->getWikibaseServices()->getTermBuffer();
        }
 
        /**
@@ -1399,11 +1313,7 @@
         *  (expanded) serialization.
         */
        public function getBaseDataModelSerializerFactory() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getBaseDataModelSerializerFactory();
-               }
-
-               return new SerializerFactory( new DataValueSerializer(), 
SerializerFactory::OPTION_DEFAULT );
+               return 
$this->getWikibaseServices()->getBaseDataModelSerializerFactory();
        }
 
        /**
@@ -1411,16 +1321,8 @@
         *  they are made of, but no other entity types. Returns serializers 
that generate the most
         *  compact serialization.
         */
-       public function getCompactSerializerFactory() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getCompactBaseDataModelSerializerFactory();
-               }
-
-               return new SerializerFactory(
-                       new DataValueSerializer(),
-                       
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH +
-                               
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH
-               );
+       public function getCompactBaseDataModelSerializerFactory() {
+               return 
$this->getWikibaseServices()->getCompactBaseDataModelSerializerFactory();
        }
 
        /**
@@ -1457,46 +1359,14 @@
         * @return Serializer Entity serializer that generates the full 
(expanded) serialization.
         */
        public function getAllTypesEntitySerializer() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getFullEntitySerializer();
-               }
-
-               if ( !isset( $this->entitySerializer ) ) {
-                       $serializerFactoryCallbacks = 
$this->entityTypeDefinitions->getSerializerFactoryCallbacks();
-                       $baseSerializerFactory = 
$this->getBaseDataModelSerializerFactory();
-                       $serializers = [];
-
-                       foreach ( $serializerFactoryCallbacks as $callback ) {
-                               $serializers[] = call_user_func( $callback, 
$baseSerializerFactory );
-                       }
-
-                       $this->entitySerializer = new DispatchingSerializer( 
$serializers );
-               }
-
-               return $this->entitySerializer;
+               return $this->getWikibaseServices()->getFullEntitySerializer();
        }
 
        /**
         * @return Serializer Entity serializer that generates the most compact 
serialization.
         */
        public function getCompactEntitySerializer() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getCompactEntitySerializer();
-               }
-
-               if ( !isset( $this->compactEntitySerializer ) ) {
-                       $serializerFactoryCallbacks = 
$this->entityTypeDefinitions->getSerializerFactoryCallbacks();
-                       $baseSerializerFactory = 
$this->getCompactSerializerFactory();
-                       $serializers = [];
-
-                       foreach ( $serializerFactoryCallbacks as $callback ) {
-                               $serializers[] = call_user_func( $callback, 
$baseSerializerFactory );
-                       }
-
-                       $this->compactEntitySerializer = new 
DispatchingSerializer( $serializers );
-               }
-
-               return $this->compactEntitySerializer;
+               return 
$this->getWikibaseServices()->getCompactEntitySerializer();
        }
 
        /**
@@ -1535,7 +1405,7 @@
                        'monolingualtext' => MonolingualTextValue::class,
                        'quantity' => QuantityValue::class,
                        'time' => TimeValue::class,
-                       'wikibase-entityid' => function( $value ) {
+                       'wikibase-entityid' => function ( $value ) {
                                return isset( $value['id'] )
                                        ? new EntityIdValue( 
$this->getEntityIdParser()->parse( $value['id'] ) )
                                        : EntityIdValue::newFromArray( $value );
@@ -1683,7 +1553,7 @@
                 *
                 * @return bool True if $blob seems to be using a legacy 
serialization format.
                 */
-               return function( $blob, $format ) {
+               return function ( $blob, $format ) {
                        // The legacy serialization uses something like 
"entity":["item",21] or
                        // even "entity":"p21" for the entity ID.
                        return preg_match( '/"entity"\s*:/', $blob ) > 0;
@@ -1761,17 +1631,7 @@
         * @return EntityNamespaceLookup
         */
        public function getEntityNamespaceLookup() {
-               if ( $this->wikibaseServices !== null ) {
-                       return 
$this->wikibaseServices->getEntityNamespaceLookup();
-               }
-
-               if ( $this->entityNamespaceLookup === null ) {
-                       $this->entityNamespaceLookup = new 
EntityNamespaceLookup(
-                               $this->getLocalEntityNamespaces()
-                       );
-               }
-
-               return $this->entityNamespaceLookup;
+               return $this->getWikibaseServices()->getEntityNamespaceLookup();
        }
 
        /**
@@ -1852,7 +1712,6 @@
         * @return DataTypeValidatorFactory
         */
        public function getDataTypeValidatorFactory() {
-
                return new BuilderBasedDataTypeValidatorFactory(
                        
$this->dataTypeDefinitions->getValidatorFactoryCallbacks()
                );
@@ -2079,4 +1938,39 @@
                return new PropertyValueExpertsModule( 
$this->getDataTypeDefinitions() );
        }
 
+       /**
+        * @return WikibaseServices
+        */
+       public function getWikibaseServices() {
+               if ( $this->wikibaseServices === null ) {
+                       $this->wikibaseServices = new 
MultipleRepositoryAwareWikibaseServices(
+                               $this->getEntityIdParser(),
+                               $this->getEntityIdComposer(),
+                               $this->repositoryDefinitions,
+                               $this->entityTypeDefinitions,
+                               $this->getDataAccessSettings(),
+                               $this->getMultiRepositoryServiceWiring(),
+                               $this->getPerRepositoryServiceWiring()
+                       );
+               }
+
+               return $this->wikibaseServices;
+       }
+
+       private function getDataAccessSettings() {
+               $repoSettings = $this->getSettings();
+               return new DataAccessSettings(
+                       $repoSettings->getSetting( 'maxSerializedEntitySize' ),
+                       $repoSettings->getSetting( 'readFullEntityIdColumn' )
+               );
+       }
+
+       private function getMultiRepositoryServiceWiring() {
+               return require __DIR__ . 
'/../../data-access/src/MultiRepositoryServiceWiring.php';
+       }
+
+       private function getPerRepositoryServiceWiring() {
+               return require __DIR__ . 
'/../../data-access/src/PerRepositoryServiceWiring.php';
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 1dbe75f..c38daa7 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -61,16 +61,20 @@
                        $repoSettings = array_merge( $repoSettings, 
$settings->getArrayCopy() );
                }
 
-               /** @var RepositoryDefinitions $repositoryDefinitions */
-               $repositoryDefinitions = $this->getMockBuilder( 
RepositoryDefinitions::class )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
                return new WikibaseRepo(
                        new SettingsArray( $repoSettings ),
                        new DataTypeDefinitions( [] ),
                        new EntityTypeDefinitions( require __DIR__ . 
'/../../../../../lib/WikibaseLib.entitytypes.php' ),
-                       $repositoryDefinitions
+                       $this->getRepositoryDefinitions()
+               );
+       }
+
+       /**
+        * @return RepositoryDefinitions
+        */
+       private function getRepositoryDefinitions() {
+               return new RepositoryDefinitions(
+                       [ '' => [ 'database' => '', 'base-uri' => '', 
'entity-namespaces' => [], 'prefix-mapping' => [] ] ]
                );
        }
 
@@ -293,7 +297,6 @@
                EntityContent $expected = null,
                $message
        ) {
-
                $handler = $this->getHandler();
                $undo = $handler->getUndoContent( $latestRevision, 
$newerRevision, $olderRevision );
 
diff --git a/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php 
b/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
index a35f49e..fab24d6 100644
--- a/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
+++ b/repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\Tests\Store\Sql;
 
 use MediaWikiTestCase;
+use Wikibase\DataAccess\WikibaseServices;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\DataModel\Services\Lookup\EntityRedirectLookup;
@@ -16,6 +17,7 @@
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityStore;
 use Wikibase\Lib\Store\EntityStoreWatcher;
+use Wikibase\Lib\Tests\Store\MockPropertyInfoLookup;
 use Wikibase\Repo\Store\EntityTitleStoreLookup;
 use Wikibase\Lib\Store\LabelConflictFinder;
 use Wikibase\Lib\Store\PropertyInfoLookup;
@@ -53,6 +55,23 @@
                        ->disableOriginalConstructor()
                        ->getMock();
 
+               $prefetchingAccessor = $this->getMockBuilder( 
PrefetchingWikiPageEntityMetaDataAccessor::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $wikibaseServices = $this->getMock( WikibaseServices::class );
+
+               $wikibaseServices->method( 'getEntityInfoBuilderFactory' )
+                       ->willReturn( $this->getMock( 
EntityInfoBuilderFactory::class ) );
+               $wikibaseServices->method( 'getEntityPrefetcher' )
+                       ->willReturn( $prefetchingAccessor );
+               $wikibaseServices->method( 'getEntityRevisionLookup' )
+                       ->willReturn( $this->getMock( 
EntityRevisionLookup::class ) );
+               $wikibaseServices->method( 'getEntityStoreWatcher' )
+                       ->willReturn( $this->getMock( EntityStoreWatcher::class 
) );
+               $wikibaseServices->method( 'getPropertyInfoLookup' )
+                       ->willReturn( new MockPropertyInfoLookup() );
+
                return new SqlStore(
                        $changeFactory,
                        $contentCodec,
@@ -60,7 +79,8 @@
                        $entityIdComposer,
                        $this->getMock( EntityIdLookup::class ),
                        $this->getMock( EntityTitleStoreLookup::class ),
-                       new EntityNamespaceLookup( [] )
+                       new EntityNamespaceLookup( [] ),
+                       $wikibaseServices
                );
        }
 
diff --git a/repo/tests/phpunit/includes/Store/StoreTest.php 
b/repo/tests/phpunit/includes/Store/StoreTest.php
index 7c4cec1..bee6045 100644
--- a/repo/tests/phpunit/includes/Store/StoreTest.php
+++ b/repo/tests/phpunit/includes/Store/StoreTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Tests\Store;
 
+use Wikibase\DataAccess\WikibaseServices;
 use Wikibase\IdGenerator;
 use Wikibase\Lib\Store\Sql\EntityChangeLookup;
 use Wikibase\Lib\Store\EntityNamespaceLookup;
@@ -44,7 +45,8 @@
                                $wikibaseRepo->getEntityIdComposer(),
                                $this->getMock( EntityIdLookup::class ),
                                $this->getMock( EntityTitleStoreLookup::class ),
-                               new EntityNamespaceLookup( [] )
+                               new EntityNamespaceLookup( [] ),
+                               $this->getMock( WikibaseServices::class )
                        )
                ];
 
diff --git a/repo/tests/phpunit/includes/WikibaseRepoTest.php 
b/repo/tests/phpunit/includes/WikibaseRepoTest.php
index ea3dc2c..123c59c 100644
--- a/repo/tests/phpunit/includes/WikibaseRepoTest.php
+++ b/repo/tests/phpunit/includes/WikibaseRepoTest.php
@@ -21,6 +21,7 @@
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\Lib\Store\PropertyInfoLookup;
 use Wikibase\Lib\Store\PropertyInfoStore;
+use Wikibase\Lib\Interactors\TermSearchInteractor;
 use Wikibase\Repo\ChangeOp\ChangeOpFactoryProvider;
 use Wikibase\DataModel\DeserializerFactory;
 use Wikibase\DataModel\Entity\EntityId;
@@ -41,7 +42,6 @@
 use Wikibase\Lib\ContentLanguages;
 use Wikibase\Lib\DataTypeDefinitions;
 use Wikibase\Lib\EntityTypeDefinitions;
-use Wikibase\Lib\Interactors\TermIndexSearchInteractor;
 use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\OutputFormatValueFormatterFactory;
 use Wikibase\Lib\RepositoryDefinitions;
@@ -247,7 +247,7 @@
 
        public function testNewTermSearchInteractorReturnType() {
                $returnValue = 
$this->getWikibaseRepo()->newTermSearchInteractor( '' );
-               $this->assertInstanceOf( TermIndexSearchInteractor::class, 
$returnValue );
+               $this->assertInstanceOf( TermSearchInteractor::class, 
$returnValue );
        }
 
        public function testGetEntityStoreReturnType() {
@@ -449,7 +449,7 @@
        }
 
        public function testGetCompactSerializerFactory() {
-               $serializerFactory = 
$this->getWikibaseRepo()->getCompactSerializerFactory();
+               $serializerFactory = 
$this->getWikibaseRepo()->getCompactBaseDataModelSerializerFactory();
                $this->assertInstanceOf( SerializerFactory::class, 
$serializerFactory );
        }
 
@@ -536,17 +536,21 @@
         * @return WikibaseRepo
         */
        private function getWikibaseRepo( $entityTypeDefinitions = [] ) {
-               /** @var RepositoryDefinitions $repositoryDefinitions */
-               $repositoryDefinitions = $this->getMockBuilder( 
RepositoryDefinitions::class )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
                $settings = new SettingsArray( 
WikibaseRepo::getDefaultInstance()->getSettings()->getArrayCopy() );
                return new WikibaseRepo(
                        $settings,
                        new DataTypeDefinitions( [] ),
                        new EntityTypeDefinitions( $entityTypeDefinitions ),
-                       $repositoryDefinitions
+                       $this->getRepositoryDefinitions()
+               );
+       }
+
+       /**
+        * @return RepositoryDefinitions
+        */
+       private function getRepositoryDefinitions() {
+               return new RepositoryDefinitions(
+                       [ '' => [ 'database' => '', 'base-uri' => '', 
'entity-namespaces' => [], 'prefix-mapping' => [] ] ]
                );
        }
 
@@ -656,7 +660,7 @@
                return $this->getWikibaseRepo( [
                        'item' => [
                                'entity-id-pattern' => ItemId::PATTERN,
-                               'entity-id-builder' => function( $serialization 
) {
+                               'entity-id-builder' => function ( 
$serialization ) {
                                        return new ItemId( $serialization );
                                },
                        ],

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icfa5d5bfcbe7e48cab9f1d4c99eeba1bd656d39f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to