In order to create runner for maintenance scripts that also works for scripts defined by extensions, extensions need to be able to register classes with the autoloader before we try to instantiate the Maintenance script object. This would also allow extensions to register alias names for scripts.
This is however tricky because of the sequence of initialization in Setup.php, and how maintenance scripts and extensions interact with it.
The requirements for the sequence are:
- ExtensionRegistry::loadFromQueue() must be called after $wgSettings->finalize(), because extensions need to back-fill defaults, and add stuff to config variables. This is expected to happen last.
- MaintenanceRunner::init needs to happen after ExtensionRegistry::loadFromQueue(), because only at this point will the extensions have registered their classes with the autoloader.
- MaintenanceRunner::overrideConfig has to be called before $wgSettings->finalize(), because it changes config settings. It must be called after MaintenanceRunner::init, because otherwise there is no Maintenance object.
So we have MaintenanceRunner::init < overrideConfig < $wgSettings->finalize < loadFromQueue(), but also loadFromQueue() < MaintenanceRunner::init, which is a contradiction. Something's got to give.
Proposed solution: move the config update logic out of ExtensionRegistry::loadFromQueue(), but keep the autoloader logic in it. Create a new method ExtensionRegistry::applyConfig or some such that applies changes to configuration (and also runs the extension callbacks).
Then we can do:
- ExtensionRegistry::loadFromQueue()
- MaintenanceRunner::init and MaintenanceRunner::overrideConfig (via MW_SETUP_CALLBACK)
- $wgSettings->finalize
- ExtensionRegistry::applyConfig
Basically, we call loadFromQueue() earlier, before MW_SETUP_CALLBACK; but at that time we only apply the extensions autoloader integration. Other effects of loading extensions are applied later, after $wgSettings->finalize, at the point we used to call loadFromQueue().