aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Settings/SettingsBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/Settings/SettingsBuilder.php')
-rw-r--r--includes/Settings/SettingsBuilder.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/includes/Settings/SettingsBuilder.php b/includes/Settings/SettingsBuilder.php
index 3a31345eb1ed..47e807099276 100644
--- a/includes/Settings/SettingsBuilder.php
+++ b/includes/Settings/SettingsBuilder.php
@@ -80,6 +80,9 @@ class SettingsBuilder {
*/
private $defaultsNeedMerging = false;
+ /** @var string[] */
+ private $warnings = [];
+
/**
* @param string $baseDir
* @param ExtensionRegistry $extensionRegistry
@@ -196,6 +199,37 @@ class SettingsBuilder {
}
/**
+ * Detect usage of deprecated settings. A setting is counted as used if
+ * it has a value other than the default.
+ *
+ * @note this is slow, so you probably don't want to do this on every request.
+ *
+ * @return array<string,string> an associative array mapping config keys
+ * to the deprecation messages from the schema.
+ */
+ public function detectDeprecatedConfig(): array {
+ $config = $this->getConfig();
+ $keys = $this->getDefinedConfigKeys();
+ $deprecated = [];
+
+ foreach ( $keys as $key ) {
+ $sch = $this->configSchema->getSchemaFor( $key );
+ if ( !isset( $sch['deprecated'] ) ) {
+ continue;
+ }
+
+ $default = $sch['default'] ?? null;
+ $value = $config->get( $key );
+
+ if ( $value !== $default ) {
+ $deprecated[$key] = $sch['deprecated'];
+ }
+ }
+
+ return $deprecated;
+ }
+
+ /**
* Return a Config object with default for all settings from all schemas loaded so far.
* If the schema for a setting doesn't specify a default, null is assumed.
*
@@ -579,4 +613,30 @@ class SettingsBuilder {
return $this->configSink;
}
+ /**
+ * Log a settings related warning, such as a deprecated config variable.
+ *
+ * This can be used during bootstrapping, when the regular logger is not yet available.
+ * The warnings will be passed to a regular logger after bootstrapping is complete.
+ * In addition, the updater will fail if it finds any warnings.
+ * This allows us to warn about deprecated settings, and make sure they are
+ * replaced before the update proceeds.
+ *
+ * @param string $msg
+ */
+ public function warning( string $msg ) {
+ $this->assertNotFinished();
+ $this->warnings[] = trim( $msg );
+ }
+
+ /**
+ * Returns any warnings logged by calling warning().
+ *
+ * @internal
+ * @return string[]
+ */
+ public function getWarnings(): array {
+ return $this->warnings;
+ }
+
}