Currently, Setup.php implements dynmiac default values for various config settings by manipulating global variables (see the part of the file that starts with the comment "Expand dynamic defaults and shortcuts"). Since we want to move away from having configuration in global variables, this should be changed. There are several cases to consider:
- Some config variables are used only in a single class. For these, the computation of the default value can be moved into the code that uses the configuration (in service wiring or actual application logic). E.g. seems to be used only in ServiceWiring, in the instantiator function for MainWANObjectCache. And ForeignFileRepos is only used in FileBackendGroup.
- Config variables that are used in multiple places should be initialized by a separate class, called something like DynamicConfigDefaults. It would have an applyDefaults() method that takes a SettingsBuilder. On the SettingsBuilder it calls getConfig() to get the configuration to inspect. It then computes an array that contains all the defaults to set. Finally, it calls overrideConfigValues() on the SettingsBuilder.
- Some Config variables are currently set late in Setup.php, after MediaWikiServices::allowGlobalInstance() has been called. These need special consideration, since the pose a paradox: they need access to a service object in order to determine their value. But configuration should not be changed after the MediaWikiServices has been initialized, since we don't know if aservice that used that config setting has already been created. Also, setting the variables after the service container has been created will stop working once we move away from using globals. The solution may be to move the determination of the default into the service wiring code that constructs the respective service.
Prior art: