Florianschmidtwelzow has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/327313 )

Change subject: PoC: ConfigRepository: Add extension configurations
......................................................................

PoC: ConfigRepository: Add extension configurations

This commit adds all configuration options of extensions loaded through
ExtensionRegistry to the ConfigRepository.

Change-Id: I7fcf094988d15a9a2f931307fd73e14156ec99cd
---
M includes/config/ConfigItemImpl.php
M includes/registration/ExtensionProcessor.php
M includes/registration/ExtensionRegistry.php
3 files changed, 45 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/13/327313/1

diff --git a/includes/config/ConfigItemImpl.php 
b/includes/config/ConfigItemImpl.php
index 856e697..ad01dbc 100644
--- a/includes/config/ConfigItemImpl.php
+++ b/includes/config/ConfigItemImpl.php
@@ -51,6 +51,11 @@
        private $valueProvider;
 
        /**
+        * @var string
+        */
+       private $configFactoryName;
+
+       /**
         * @var ConfigProvider
         */
        private $provider;
@@ -60,12 +65,12 @@
        }
 
        public function getValue() {
-               if ( $this->valueProvider === null ) {
+               if ( $this->getValueProvider() === null ) {
                        throw new \ConfigException(
                                'No provider set to retrieve the value of the 
config item: ' . $this->getName() );
                }
 
-               return $this->valueProvider->get( $this->getName() );
+               return $this->getValueProvider()->get( $this->getName() );
        }
 
        public function getDefaultValue() {
@@ -85,7 +90,12 @@
        }
 
        public function getValueProvider() {
-               return $this->getValueProvider();
+               if ( $this->valueProvider === null && $this->configFactoryName 
!== null ) {
+                       $this->valueProvider = 
\MediaWiki\MediaWikiServices::getInstance()
+                               ->getConfigFactory()
+                               ->makeConfig( $this->configFactoryName );
+               }
+               return $this->valueProvider;
        }
 
        public function setProvider( ConfigProvider $provider ) {
@@ -119,6 +129,9 @@
                if ( isset( $arr['valueprovider'] ) ) {
                        $retval->valueProvider = $arr['valueprovider'];
                }
+               if ( isset( $arr['config'] ) ) {
+                       $retval->configFactoryName = $arr['config'];
+               }
 
                return $retval;
        }
diff --git a/includes/registration/ExtensionProcessor.php 
b/includes/registration/ExtensionProcessor.php
index d967132..66c3305 100644
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -153,6 +153,11 @@
        protected $credits = [];
 
        /**
+        * @var array
+        */
+       protected $configItems = [];
+
+       /**
         * Any thing else in the $info that hasn't
         * already been processed
         *
@@ -208,6 +213,7 @@
 
                return [
                        'globals' => $this->globals,
+                       'config' => $this->configItems,
                        'defines' => $this->defines,
                        'callbacks' => $this->callbacks,
                        'credits' => $this->credits,
@@ -383,6 +389,7 @@
                        foreach ( $info['config'] as $key => $val ) {
                                if ( $key[0] !== '@' ) {
                                        $this->globals["$prefix$key"] = $val;
+                                       $this->addConfigItem( $key, $val, $info 
);
                                }
                        }
                }
@@ -411,10 +418,27 @@
                                        $value = "$dir/$value";
                                }
                                $this->globals["$prefix$key"] = $value;
+                               $this->addConfigItem( $key, $value, $info );
                        }
                }
        }
 
+       private function addConfigItem( $key, $value, $info ) {
+               $provider = new 
\MediaWiki\ConfigProvider\ExtensionConfigProvider();
+               $provider->setName( $info['name'] );
+               $config = [
+                       'name' => $key,
+                       'defaultvalue' => $value,
+                       'provider' => $provider,
+               ];
+               if ( isset( $info['ConfigRegistry'] ) ) {
+                       $config['config'] = key( $info['ConfigRegistry'] );
+               }
+               $configItem = \MediaWiki\Config\ConfigItemImpl::newFromArray( 
$config );
+
+               $this->configItems[] = $configItem;
+       }
+
        protected function extractServiceWiringFiles( $dir, array $info ) {
                if ( isset( $info['ServiceWiringFiles'] ) ) {
                        foreach ( $info['ServiceWiringFiles'] as $path ) {
diff --git a/includes/registration/ExtensionRegistry.php 
b/includes/registration/ExtensionRegistry.php
index 70dc624..7bcf2a5 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -31,7 +31,7 @@
        /**
         * Bump whenever the registration cache needs resetting
         */
-       const CACHE_VERSION = 4;
+       const CACHE_VERSION = 6;
 
        /**
         * Special key that defines the merge strategy
@@ -312,6 +312,10 @@
                foreach ( $info['autoloaderPaths'] as $path ) {
                        require_once $path;
                }
+               $configRepo = 
MediaWikiServices::getInstance()->getConfigRepository();
+               foreach ( $info['config'] as $configItem ) {
+                       $configRepo->add( $configItem );
+               }
 
                $this->loaded += $info['credits'];
                if ( $info['attributes'] ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7fcf094988d15a9a2f931307fd73e14156ec99cd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

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

Reply via email to