Florianschmidtwelzow has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/327312 )
Change subject: PoC: Add new ConfigRepository and ConfigItem architecture
......................................................................
PoC: Add new ConfigRepository and ConfigItem architecture
This, for now, has the focus for holding meta-information to theoretically
each configuration option inside of MediaWiki, e.g. MediaWiki core config
or extension config options. It's very closely to the Config interface and
friends and uses these implementations to retrieve the actual value of the
configuration option which is described in a ConfigItem.
The mid-time goal with this change is to implement a basic architecture to
allow to display the values of the curent configuration of the MediaWiki
installation on-wiki (e.g. on a special page, which has a new user right, for
example).
The long-term goal, of course, would be to get a web-interface to really
configure the MediaWiki installation. But, this is more like a dream, then a
plan (from the point of view of this commit).
Next steps would be:
* Enable ExtensionRegistry to "register" the configuration options of
extensions, so they're available in the repo.
* Find a good way to get mediawiki/core configurations into this repo
* Work out an overall architecture to display the different possible values
(I think about something like different formatters for types).
Change-Id: I9419508eaa85ffc55520db7f33b3e9530fc99f00
---
M autoload.php
M includes/MediaWikiServices.php
M includes/ServiceWiring.php
A includes/config/ConfigItem.php
A includes/config/ConfigItemImpl.php
A includes/config/ConfigRepository.php
A includes/configprovider/AbstractConfigProvider.php
A includes/configprovider/ConfigProvider.php
A includes/configprovider/ExtensionConfigProvider.php
A includes/configprovider/MediaWikiCoreConfigProvider.php
10 files changed, 559 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/12/327312/1
diff --git a/autoload.php b/autoload.php
index e079686..4be21a5 100644
--- a/autoload.php
+++ b/autoload.php
@@ -858,6 +858,13 @@
'MediaWiki\\Auth\\Throttler' => __DIR__ .
'/includes/auth/Throttler.php',
'MediaWiki\\Auth\\UserDataAuthenticationRequest' => __DIR__ .
'/includes/auth/UserDataAuthenticationRequest.php',
'MediaWiki\\Auth\\UsernameAuthenticationRequest' => __DIR__ .
'/includes/auth/UsernameAuthenticationRequest.php',
+ 'MediaWiki\\ConfigProvider\\AbstractConfigProvider' => __DIR__ .
'/includes/configprovider/AbstractConfigProvider.php',
+ 'MediaWiki\\ConfigProvider\\ConfigProvider' => __DIR__ .
'/includes/configprovider/ConfigProvider.php',
+ 'MediaWiki\\ConfigProvider\\ExtensionConfigProvider' => __DIR__ .
'/includes/configprovider/ExtensionConfigProvider.php',
+ 'MediaWiki\\ConfigProvider\\MediaWikiCoreConfigProvider' => __DIR__ .
'/includes/configprovider/MediaWikiCoreConfigProvider.php',
+ 'MediaWiki\\Config\\ConfigItem' => __DIR__ .
'/includes/config/ConfigItem.php',
+ 'MediaWiki\\Config\\ConfigItemImpl' => __DIR__ .
'/includes/config/ConfigItemImpl.php',
+ 'MediaWiki\\Config\\ConfigRepository' => __DIR__ .
'/includes/config/ConfigRepository.php',
'MediaWiki\\Diff\\ComplexityException' => __DIR__ .
'/includes/diff/ComplexityException.php',
'MediaWiki\\Diff\\WordAccumulator' => __DIR__ .
'/includes/diff/WordAccumulator.php',
'MediaWiki\\Interwiki\\ClassicInterwikiLookup' => __DIR__ .
'/includes/interwiki/ClassicInterwikiLookup.php',
diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php
index 7c9363c..b0c7e0b 100644
--- a/includes/MediaWikiServices.php
+++ b/includes/MediaWikiServices.php
@@ -14,6 +14,7 @@
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use LoadBalancer;
use MediaHandlerFactory;
+use MediaWiki\Config\ConfigRepository;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\Services\SalvageableService;
@@ -656,6 +657,14 @@
return $this->getService( 'VirtualRESTServiceClient' );
}
+ /**
+ * @since 1.29
+ * @return ConfigRepository
+ */
+ public function getConfigRepository() {
+ return $this->getService( 'ConfigRepository' );
+ }
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service getter here, don't forget to add a test
// case for it in MediaWikiServicesTest::provideGetters() and in
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 4fec472..145c7c2 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -86,6 +86,13 @@
return $factory;
},
+ 'ConfigRepository' => function( MediaWikiServices $services ) {
+ $repo = new \MediaWiki\Config\ConfigRepository();
+ $repo->setMediaWikiServices( $services );
+
+ return $repo;
+ },
+
'MainConfig' => function( MediaWikiServices $services ) {
// Use the 'main' config from the ConfigFactory service.
return $services->getConfigFactory()->makeConfig( 'main' );
diff --git a/includes/config/ConfigItem.php b/includes/config/ConfigItem.php
new file mode 100644
index 0000000..7cd80f8
--- /dev/null
+++ b/includes/config/ConfigItem.php
@@ -0,0 +1,119 @@
+<?php
+namespace MediaWiki\Config;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+use MediaWiki\ConfigProvider\ConfigProvider;
+
+/**
+ * Interface, which holds information about a specific config item.
+ *
+ * @since 1.29
+ */
+interface ConfigItem {
+ /**
+ * Returns the name of this configuration option.
+ *
+ * @return string
+ */
+ public function getName();
+
+ /**
+ * Returns the current value of the configuration.
+ *
+ * This function may get the current value using a configuration
storage backend.
+ *
+ * @see \Config::get()
+ *
+ * @return mixed
+ */
+ public function getValue();
+
+ /**
+ * Returns the default value of this configuration. This value may be
the same as the value
+ * of this::getValue().
+ *
+ * @return mixed
+ */
+ public function getDefaultValue();
+
+ /**
+ * Returns true, if the current value is the default value. It depends
upon the
+ * implementation of this interface, if this returns true if
this::getValue() ===
+ * this::getDefaultValue().
+ *
+ * @return mixed
+ */
+ public function isDefaultValue();
+
+ /**
+ * Returns the description of this config option or null, if there's no
description.
+ *
+ * @return boolean
+ */
+ public function getDescription();
+
+ /**
+ * Sets the provider which should be used to get the value of this
config option. The
+ * provider may be used by getValue().
+ *
+ * @param \Config $provider
+ */
+ public function setValueProvider( \Config $provider );
+
+ /**
+ * Returns the provider set to this configuration item, or null if
there's no registered
+ * provider.
+ *
+ * @return \Config
+ */
+ public function getValueProvider();
+
+ /**
+ * Sets the ConfigProvider which provides this configurationb object.
+ *
+ * @return ConfigProvider
+ */
+ public function setProvider( ConfigProvider $provider );
+
+ /**
+ * Returns the ConfigProvider which provided this configuration object.
+ *
+ * @return ConfigProvider
+ */
+ public function getProvider();
+
+ /**
+ * Creates a new ConfigItem from the given object, which should contain
at least this required
+ * information:
+ * * name: The name of the configuration
+ * * defaultvalue: The default value of the option
+ * * provider: An object of the context by which this configuration
item is provided
+ *
+ * Other options are:
+ * * description: The description of the configuration
+ * * valueprovider: The provider, from which the value should be
retrieved
+ *
+ * @param array $array
+ * @return ConfigItem
+ */
+ public static function newFromArray( array $array );
+}
\ No newline at end of file
diff --git a/includes/config/ConfigItemImpl.php
b/includes/config/ConfigItemImpl.php
new file mode 100644
index 0000000..856e697
--- /dev/null
+++ b/includes/config/ConfigItemImpl.php
@@ -0,0 +1,129 @@
+<?php
+namespace MediaWiki\Config;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+use MediaWiki\ConfigProvider\ConfigProvider;
+
+/**
+ * A descriptive object for a configuration option.
+ *
+ * @since 1.29
+ */
+class ConfigItemImpl implements ConfigItem {
+
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @var mixed
+ */
+ private $defaultValue;
+
+ /**
+ * @var string
+ */
+ private $description;
+
+ /**
+ * @var \Config
+ */
+ private $valueProvider;
+
+ /**
+ * @var ConfigProvider
+ */
+ private $provider;
+
+ public function getName() {
+ return $this->name;
+ }
+
+ public function getValue() {
+ if ( $this->valueProvider === null ) {
+ throw new \ConfigException(
+ 'No provider set to retrieve the value of the
config item: ' . $this->getName() );
+ }
+
+ return $this->valueProvider->get( $this->getName() );
+ }
+
+ public function getDefaultValue() {
+ return $this->defaultValue;
+ }
+
+ public function isDefaultValue() {
+ return $this->getValue() === $this->getDefaultValue();
+ }
+
+ public function getDescription() {
+ return $this->description;
+ }
+
+ public function setValueProvider( \Config $provider ) {
+ $this->valueProvider = $provider;
+ }
+
+ public function getValueProvider() {
+ return $this->getValueProvider();
+ }
+
+ public function setProvider( ConfigProvider $provider ) {
+ $this->provider = $provider;
+ }
+
+ public function getProvider() {
+ return $this->provider;
+ }
+
+ public static function newFromArray( array $arr ) {
+ if ( !array_key_exists( 'name', $arr ) ) {
+ throw new \ConfigException( 'The name for a ConfigItem
is mandatory. None given.' );
+ }
+ if ( !array_key_exists( 'defaultvalue', $arr ) ) {
+ throw new \ConfigException(
+ 'The default value for a ConfigItem is
mandatory. None given.' );
+ }
+ if ( !array_key_exists( 'provider', $arr ) ) {
+ throw new \ConfigException(
+ 'The provider for a ConfigItem is mandatory.
None given.' );
+ }
+
+ $retval = new self();
+ $retval->name = $arr['name'];
+ $retval->provider = $arr['provider'];
+ $retval->defaultValue = $arr['defaultvalue'];
+ if ( isset( $arr['description'] ) ) {
+ $retval->description = $arr['description'];
+ }
+ if ( isset( $arr['valueprovider'] ) ) {
+ $retval->valueProvider = $arr['valueprovider'];
+ }
+
+ return $retval;
+ }
+
+ public function __toString() {
+ return $this->getName();
+ }
+}
\ No newline at end of file
diff --git a/includes/config/ConfigRepository.php
b/includes/config/ConfigRepository.php
new file mode 100644
index 0000000..5714044
--- /dev/null
+++ b/includes/config/ConfigRepository.php
@@ -0,0 +1,131 @@
+<?php
+namespace MediaWiki\Config;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Services\SalvageableService;
+use Wikimedia\Assert\Assert;
+
+/**
+ * Object which holds currently registered configuration options.
+ *
+ * @since 1.29
+ */
+class ConfigRepository implements \Iterator, SalvageableService {
+ private $services;
+ public static $count = 0;
+
+ public $configItems = [];
+
+ public function setMediaWikiServices( MediaWikiServices $services ) {
+ $this->services = $services;
+ self::$count++;
+ }
+
+ /**
+ * Returns true, if this repository contains a configuration with a
specific name.
+ *
+ * @param $name
+ * @return bool
+ */
+ public function has( $name ) {
+ return isset($configItems[$name]);
+ }
+
+ /**
+ * Returns the ConfigItem with the given name, if there's one. Throws a
ConfigException
+ * otherwise.
+ *
+ * @param $name
+ * @return ConfigItem
+ * @throws \ConfigException
+ */
+ public function get( $name ) {
+ if ( !$this->has( $name ) ) {
+ throw new \ConfigException( 'The configuration option '
. $name . ' does not exist.' );
+ }
+ return $this->configItems[$name];
+ }
+
+ /**
+ * Adds the definition of a configuration to this repository.
+ *
+ * @param ConfigItem $item
+ * @throws \ConfigException
+ */
+ public function add( ConfigItem $item ) {
+ if ($this->has($item->getName())) {
+ throw new \ConfigException( 'A configuration with the
name ' . $item->getName() .
+ 'does already exist. It is provided by: ' .
+ $this->get( $item->getName()
)->getProvider()->getName() );
+ }
+ $this->configItems[] = $item;
+ }
+
+ public function current () {
+ return current( $this->configItems );
+ }
+
+ public function key () {
+ return key( $this->configItems );
+ }
+ public function next () {
+ return next( $this->configItems );
+ }
+ public function rewind () {
+ reset( $this->configItems );
+ }
+ public function valid () {
+ return current( $this->configItems ) !== false;
+ }
+
+ /**
+ * Re-uses existing Cache objects from $other. Cache objects are only
re-used if the
+ * registered factory function for both is the same.
+ *
+ * @see SalvageableService::salvage()
+ *
+ * @param SalvageableService $other The object to salvage state from.
$other must have the
+ * exact same type as $this.
+ */
+ public function salvage( SalvageableService $other ) {
+ Assert::parameterType( self::class, $other, '$other' );
+
+ /** @var ConfigRepository $other */
+ $otherCurrentObj = $other->current();
+ foreach ( $other->configItems as $name => $otherConfig ) {
+ if ( isset( $this->configItems[$name] ) ) {
+ continue;
+ }
+
+ $this->configItems[$name] = $otherConfig;
+
+ // recover the pointer of the other config repository
+ if ($otherCurrentObj === $otherConfig) {
+ end( $this->configItems );
+ }
+ }
+
+ // disable $other
+ $other->configItems = [];
+ }
+}
\ No newline at end of file
diff --git a/includes/configprovider/AbstractConfigProvider.php
b/includes/configprovider/AbstractConfigProvider.php
new file mode 100644
index 0000000..aa06255
--- /dev/null
+++ b/includes/configprovider/AbstractConfigProvider.php
@@ -0,0 +1,40 @@
+<?php
+namespace MediaWiki\ConfigProvider;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+
+/**
+ * Simplest configuration option provider.
+ *
+ * @since 1.29
+ */
+abstract class AbstractConfigProvider implements ConfigProvider {
+ private $name;
+
+ public function getName() {
+ return $this->name;
+ }
+
+ public function setName($name) {
+ $this->name = $name;
+ }
+}
\ No newline at end of file
diff --git a/includes/configprovider/ConfigProvider.php
b/includes/configprovider/ConfigProvider.php
new file mode 100644
index 0000000..8a8a77a
--- /dev/null
+++ b/includes/configprovider/ConfigProvider.php
@@ -0,0 +1,49 @@
+<?php
+namespace MediaWiki\ConfigProvider;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+
+/**
+ * Interface for an object that holds information about the context which
provides configuration
+ * options.
+ *
+ * @since 1.29
+ */
+interface ConfigProvider {
+ /**
+ * Returns the name of the provider.
+ * @return mixed
+ */
+ public function getName();
+
+ /**
+ * Sets the name of this provider.
+ *
+ * @param string $name
+ */
+ public function setName($name);
+
+ /**
+ * Returns the overall group where this configuration belongs to.
+ */
+ public function getGroup();
+}
\ No newline at end of file
diff --git a/includes/configprovider/ExtensionConfigProvider.php
b/includes/configprovider/ExtensionConfigProvider.php
new file mode 100644
index 0000000..7b357e7
--- /dev/null
+++ b/includes/configprovider/ExtensionConfigProvider.php
@@ -0,0 +1,34 @@
+<?php
+namespace MediaWiki\ConfigProvider;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+
+/**
+ * Provider for MediaWiki core configuration options.
+ *
+ * @since 1.29
+ */
+class ExtensionConfigProvider extends AbstractConfigProvider {
+ public function getGroup() {
+ return 'Extension';
+ }
+}
\ No newline at end of file
diff --git a/includes/configprovider/MediaWikiCoreConfigProvider.php
b/includes/configprovider/MediaWikiCoreConfigProvider.php
new file mode 100644
index 0000000..9e602b2
--- /dev/null
+++ b/includes/configprovider/MediaWikiCoreConfigProvider.php
@@ -0,0 +1,34 @@
+<?php
+namespace MediaWiki\ConfigProvider;
+
+/**
+ * Copyright 2016
+ *
+ * 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
+ *
+ * @file
+ */
+
+/**
+ * Provider for MediaWiki core configuration options.
+ *
+ * @since 1.29
+ */
+class MediaWikiCoreConfigProvider extends AbstractConfigProvider {
+ public function getGroup() {
+ return 'MediaWiki';
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/327312
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9419508eaa85ffc55520db7f33b3e9530fc99f00
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