(This is mostly just the same as T173476 but just includes the interesting bits.)
For MediaWiki-extensions-GlobalPreferences, we need a way to work with all preferences.
- Be able to get a list of all registered preferences.
Current solutions are unsuitable:
- Hook GetPreferences is intended to modify or register additional preferences. Can also be used to read the current registry, but there's no way to be the last extension to do so, and so we wouldn't get all extensions' preferences.
- Hook GetPreferences via ExtensionFunctions (by late-modifying $wgHooks['GetPreferences']). Still another extension could reasonably do the same. Given that this method has no semantic meaning to indicate that hooks registered here would only get instead adding preferences.
New hook after GetPreferences (and possibly after Preferences::loadPreferenceValues() ran). Would be able to access to all defined preferences.
This would work, but wouldn't give us extra functionality such as being able to add new resource modules to Special:Preferences.
The proposed solution (see https://gerrit.wikimedia.org/r/#/c/374451 ) is to add a new PreferencesFactory service, which can then be overridden by an extension wanting to provide a custom subclass of Preferences. This seems like the most flexible and least hacky way to do this. It would also be a step towards Preferences being a more object-oriented class (and not just a collection of public static methods as it currently is; for example, almost every method in it takes a $user and a $context; in the proposed patch these become member variables and so consolidate the existing idea that a Preference depends on these).
It'd be great if TechCom could help CommTech with this. :-)