aboutsummaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authordaniel <dkinzler@wikimedia.org>2022-07-11 18:02:43 +0200
committerdaniel <dkinzler@wikimedia.org>2022-07-15 12:24:20 +0200
commitcf39a40f164799ffed328a5b8d7a42823441f507 (patch)
tree854ebe8dbf0ad068beda2f7306c6b87a406bc040 /includes
parentb19a8272953eeb6464350cc3c09284840c787faf (diff)
downloadmediawikicore-cf39a40f164799ffed328a5b8d7a42823441f507.tar.gz
mediawikicore-cf39a40f164799ffed328a5b8d7a42823441f507.zip
SettingsBuilder: report warnings
This adds functionality to SettingsBuilder for collecting warnings to be logged later, when the logging mechanism has been set up. This also adds a validation step to update.php that aborts the update if any warnings have been registered in SettingsBuilder, or the settings fail to validate against the settings schema. Change-Id: I387905289fb93591f79b96bf4c6cb5ec692b2aff
Diffstat (limited to 'includes')
-rw-r--r--includes/MainConfigNames.php1
-rw-r--r--includes/MainConfigSchema.php5
-rw-r--r--includes/Settings/SettingsBuilder.php60
-rw-r--r--includes/Setup.php11
-rw-r--r--includes/SetupDynamicConfig.php21
-rw-r--r--includes/config-schema.php3
-rw-r--r--includes/config-vars.php1
7 files changed, 86 insertions, 16 deletions
diff --git a/includes/MainConfigNames.php b/includes/MainConfigNames.php
index 5b477ec1ce6f..378f7526a40b 100644
--- a/includes/MainConfigNames.php
+++ b/includes/MainConfigNames.php
@@ -1794,7 +1794,6 @@ class MainConfigNames {
/**
* Name constant for the DummyLanguageCodes setting, for use with Config::get()
* @see MainConfigSchema::DummyLanguageCodes
- * @deprecated since 1.29
*/
public const DummyLanguageCodes = 'DummyLanguageCodes';
diff --git a/includes/MainConfigSchema.php b/includes/MainConfigSchema.php
index cd9a254c0477..b013265d9e59 100644
--- a/includes/MainConfigSchema.php
+++ b/includes/MainConfigSchema.php
@@ -4656,12 +4656,13 @@ class MainConfigSchema {
* Functionally the same as $wgExtraLanguageCodes, but deprecated. Instead of
* appending values to this array, append them to $wgExtraLanguageCodes.
*
- * @deprecated since 1.29
+ * @note Since 1.29, this should not be set directly in LocalSettings,
+ * ExtraLanguageCodes should be set instead. However, DummyLanguageCodes
+ * will be initialized and can be read internally.
*/
public const DummyLanguageCodes = [
'default' => [],
'type' => 'map',
- 'deprecated' => 'since 1.29',
];
/**
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;
+ }
+
}
diff --git a/includes/Setup.php b/includes/Setup.php
index e0c36ba2f3ef..8ecb75a89910 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -566,6 +566,17 @@ if ( !$wgCommandLineMode ) {
Pingback::schedulePingback();
}
+$settingsWarnings = $wgSettings->getWarnings();
+if ( $settingsWarnings ) {
+ $logger = LoggerFactory::getInstance( 'Settings' );
+ foreach ( $settingsWarnings as $msg ) {
+ $logger->warning( $msg );
+ }
+ unset( $logger );
+}
+
+unset( $settingsWarnings );
+
// Explicit globals, so this works with bootstrap.php
global $wgFullyInitialised;
$wgFullyInitialised = true;
diff --git a/includes/SetupDynamicConfig.php b/includes/SetupDynamicConfig.php
index 5b803ba410ca..800874253a10 100644
--- a/includes/SetupDynamicConfig.php
+++ b/includes/SetupDynamicConfig.php
@@ -229,6 +229,10 @@ if ( !$wgLocaltimezone ) {
// to gracefully handle the case of $wgLocaltimezone being the empty string.
// See T305093#8063451.
$wgLocaltimezone = MainConfigSchema::getDefaultLocaltimezone();
+ $wgSettings->warning(
+ 'The Localtimezone setting must a valid timezone string or null. '
+ . 'It must not be an empty string or false.'
+ );
}
// The part after the System| is ignored, but rest of MW fills it out as the local offset.
@@ -247,7 +251,10 @@ if ( is_array( $wgExtraNamespaces ) ) {
// Hard-deprecate setting $wgDummyLanguageCodes in LocalSettings.php
if ( count( $wgDummyLanguageCodes ) !== 0 ) {
- wfDeprecated( '$wgDummyLanguageCodes', '1.29' );
+ $wgSettings->warning(
+ 'Do not add to DummyLanguageCodes directly, ' .
+ 'add to ExtraLanguageCodes instead.'
+ );
}
// Merge in the legacy language codes, incorporating overrides from the config
$wgDummyLanguageCodes += [
@@ -273,10 +280,8 @@ if ( isset( $wgSlaveLagWarning ) ) {
// If the old value is set to something other than the default, use it.
if ( $wgDatabaseReplicaLagWarning === 10 && $wgSlaveLagWarning !== 10 ) {
$wgDatabaseReplicaLagWarning = $wgSlaveLagWarning;
- wfDeprecated(
- '$wgSlaveLagWarning set but $wgDatabaseReplicaLagWarning unchanged; using $wgSlaveLagWarning',
- '1.36'
- );
+ $wgSettings->warning( 'SlaveLagWarning is no longer supported, ' .
+ 'use DatabaseReplicaLagWarning instead!' );
}
} else {
// Backwards-compatibility for extensions that read this value.
@@ -287,10 +292,8 @@ if ( isset( $wgSlaveLagCritical ) ) {
// If the old value is set to something other than the default, use it.
if ( $wgDatabaseReplicaLagCritical === 30 && $wgSlaveLagCritical !== 30 ) {
$wgDatabaseReplicaLagCritical = $wgSlaveLagCritical;
- wfDeprecated(
- '$wgSlaveLagCritical set but $wgDatabaseReplicaLagCritical unchanged; using $wgSlaveLagCritical',
- '1.36'
- );
+ $wgSettings->warning( 'SlaveLagCritical is no longer supported, ' .
+ 'use DatabaseReplicaLagCritical instead!' );
}
} else {
// Backwards-compatibility for extensions that read this value.
diff --git a/includes/config-schema.php b/includes/config-schema.php
index ef4e72a30dbd..13eae4658687 100644
--- a/includes/config-schema.php
+++ b/includes/config-schema.php
@@ -3137,9 +3137,6 @@ return [
'SquidPurgeUseHostHeader' => [
'deprecated' => 'since 1.33',
],
- 'DummyLanguageCodes' => [
- 'deprecated' => 'since 1.29',
- ],
'RawHtmlMessages' => [
'items' => [
'type' => 'string',
diff --git a/includes/config-vars.php b/includes/config-vars.php
index 9b7200b2b8fb..34b101c27a2b 100644
--- a/includes/config-vars.php
+++ b/includes/config-vars.php
@@ -1778,7 +1778,6 @@ $wgExtraLanguageCodes = null;
/**
* Config variable stub for the DummyLanguageCodes setting, for use by phpdoc and IDEs.
* @see MediaWiki\MainConfigSchema::DummyLanguageCodes
- * @deprecated since 1.29
*/
$wgDummyLanguageCodes = null;