Jeroen De Dauw has uploaded a new change for review.

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

Change subject: Remove Libregistry
......................................................................

Remove Libregistry

Inlined its remaining code at the only location where it is used.
Cannot get rid of that without first fixing some other things.

Change-Id: I3d47e55eaadf2f008eb443f271280b993783d677
---
D lib/includes/LibRegistry.php
M lib/resources/Resources.php
2 files changed, 29 insertions(+), 121 deletions(-)


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

diff --git a/lib/includes/LibRegistry.php b/lib/includes/LibRegistry.php
deleted file mode 100644
index 501a34d..0000000
--- a/lib/includes/LibRegistry.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-
-namespace Wikibase;
-
-use DataTypes\DataTypeFactory;
-use Wikibase\Client\WikibaseClient;
-use Wikibase\DataModel\Entity\BasicEntityIdParser;
-use Wikibase\DataModel\Entity\DispatchingEntityIdParser;
-use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\Lib\WikibaseDataTypeBuilders;
-use Wikibase\Repo\WikibaseRepo;
-
-/**
- * Application registry for Wikibase Lib.
- *
- * TODO: migrate out this class; code should be in client or repo and
- * use their respective settings. Same rationale as for moving settings out of 
lib.
- *
- * @deprecated
- *
- * NOTE:
- * This application registry is a workaround for design problems in existing 
code.
- * It should only be used to improve existing usage of code and ideally just be
- * a stepping stone towards using proper dependency injection where possible.
- * This means you should be very careful when adding new components to the 
registry.
- *
- * @since 0.4
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-final class LibRegistry {
-
-       /**
-        * @since 0.4
-        *
-        * @var SettingsArray
-        */
-       protected $settings;
-
-       protected $dataTypeFactory = null;
-
-       /**
-        * @since 0.4
-        *
-        * @param SettingsArray $settings
-        */
-       public function __construct( SettingsArray $settings ) {
-               $this->settings = $settings;
-       }
-
-       /**
-        * @since 0.4
-        *
-        * @throws \RuntimeException
-        * @return DataTypeFactory
-        */
-       public function getDataTypeFactory() {
-               if ( $this->dataTypeFactory === null ) {
-
-                       // TODO: extreme uglynes here! Get rid of this method!
-                       if ( defined( 'WB_VERSION' ) ) { // repo mode
-                               $repo = WikibaseRepo::getDefaultInstance();
-                               $entityIdParser = $repo->getEntityIdParser();
-                               $entityLookup = $repo->getEntityLookup();
-                       } elseif ( defined( 'WBC_VERSION' ) ) { // client mode
-                               $client = WikibaseClient::getDefaultInstance();
-                               $entityIdParser = $client->getEntityIdParser();
-                               $entityLookup = 
$client->getStore()->getEntityLookup();
-                       } else {
-                               throw new \RuntimeException( "Neither repo nor 
client found!" );
-                       }
-
-                       $urlSchemes = $this->settings->getSetting( 'urlSchemes' 
);
-                       $builders = new WikibaseDataTypeBuilders( 
$entityLookup, $entityIdParser, $urlSchemes );
-
-                       $typeBuilderSpecs = array_intersect_key(
-                               $builders->getDataTypeBuilders(),
-                               array_flip( $this->settings->getSetting( 
'dataTypes' ) )
-                       );
-
-                       $this->dataTypeFactory = new DataTypeFactory( 
$typeBuilderSpecs );
-               }
-
-               return $this->dataTypeFactory;
-       }
-
-       /**
-        * Returns a new instance constructed from global settings.
-        *
-        * @since 0.4
-        *
-        * @return LibRegistry
-        */
-       protected static function newInstance() {
-               return new self( Settings::singleton() );
-       }
-
-       /**
-        * Returns a default instance constructed from global settings.
-        * IMPORTANT: Use only when it is not feasible to inject an instance 
properly.
-        *
-        * @since 0.4
-        *
-        * @return LibRegistry
-        */
-       public static function getDefaultInstance() {
-               static $instance = null;
-
-               if ( $instance === null ) {
-                       $instance = self::newInstance();
-               }
-
-               return $instance;
-       }
-
-       // Do not add new stuff here without reading the notice at the top 
first.
-
-}
diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index dc89aee..1707abb 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -1,6 +1,10 @@
 <?php
 
-use \Wikibase\LibRegistry;
+use DataTypes\DataTypeFactory;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\Lib\WikibaseDataTypeBuilders;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\Settings;
 
 /**
  * File for Wikibase resourceloader modules.
@@ -183,7 +187,30 @@
                'mw.config.values.wbDataTypes' => $moduleTemplate + array(
                        'class' => 'DataTypes\DataTypesModule',
                        'datatypefactory' => function() {
-                               return 
LibRegistry::getDefaultInstance()->getDataTypeFactory();
+                               // TODO: extreme uglynes here! Get rid of this 
method!
+                               if ( defined( 'WB_VERSION' ) ) { // repo mode
+                                       $repo = 
WikibaseRepo::getDefaultInstance();
+                                       $entityIdParser = 
$repo->getEntityIdParser();
+                                       $entityLookup = 
$repo->getEntityLookup();
+                               } elseif ( defined( 'WBC_VERSION' ) ) { // 
client mode
+                                       $client = 
WikibaseClient::getDefaultInstance();
+                                       $entityIdParser = 
$client->getEntityIdParser();
+                                       $entityLookup = 
$client->getStore()->getEntityLookup();
+                               } else {
+                                       throw new \RuntimeException( "Neither 
repo nor client found!" );
+                               }
+
+                               $settings = Settings::singleton();
+
+                               $urlSchemes = $settings->getSetting( 
'urlSchemes' );
+                               $builders = new WikibaseDataTypeBuilders( 
$entityLookup, $entityIdParser, $urlSchemes );
+
+                               $typeBuilderSpecs = array_intersect_key(
+                                       $builders->getDataTypeBuilders(),
+                                       array_flip( $settings->getSetting( 
'dataTypes' ) )
+                               );
+
+                               return new DataTypeFactory( $typeBuilderSpecs );
                        },
                        'datatypesconfigvarname' => 'wbDataTypes',
                ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d47e55eaadf2f008eb443f271280b993783d677
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

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

Reply via email to