MediaWiki master
WebUpgradeExtensionsProvider.php
Go to the documentation of this file.
1<?php
2
4
5use AutoLoader;
6use LogicException;
13
22 public function getName() {
23 return 'extensions';
24 }
25
27 public function getAliases() {
28 return 'tables';
29 }
30
32 public function getProvidedNames() {
33 return [ 'HookContainer', 'VirtualDomains', 'ExtensionTaskSpecs' ];
34 }
35
36 public function execute(): Status {
37 $vars = Installer::getExistingLocalSettings();
38
39 $registry = ExtensionRegistry::getInstance();
40 $queue = $registry->getQueue();
41 // Don't accidentally load extensions in the future
42 $registry->clearQueue();
43
44 // Read extension.json files
45 $extInfo = $registry->readFromQueue( $queue );
46
47 // Merge extension attribute hooks with hooks defined by a .php
48 // registration file included from LocalSettings.php
49 $legacySchemaHooks = $extInfo['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ?? [];
50 if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
51 $legacySchemaHooks = array_merge( $legacySchemaHooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
52 }
53
54 // Register classes defined by extensions that are loaded by including of a file that
55 // updates global variables, rather than having an extension.json manifest.
56 if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
57 AutoLoader::registerClasses( $vars['wgAutoloadClasses'] );
58 }
59
60 // Register class definitions from extension.json files
61 if ( !isset( $extInfo['autoloaderPaths'] )
62 || !isset( $extInfo['autoloaderClasses'] )
63 || !isset( $extInfo['autoloaderNS'] )
64 ) {
65 // NOTE: protect against changes to the structure of $extInfo.
66 // It's volatile, and this usage is easy to miss.
67 throw new LogicException( 'Missing autoloader keys from extracted extension info' );
68 }
69 AutoLoader::loadFiles( $extInfo['autoloaderPaths'] );
70 AutoLoader::registerClasses( $extInfo['autoloaderClasses'] );
71 AutoLoader::registerNamespaces( $extInfo['autoloaderNS'] );
72
73 $legacyHooks = $legacySchemaHooks ? [ 'LoadExtensionSchemaUpdates' => $legacySchemaHooks ] : [];
74
75 $this->getContext()->provide( 'HookContainer',
76 new HookContainer(
77 new StaticHookRegistry(
78 $legacyHooks,
79 $extInfo['attributes']['Hooks'] ?? [],
80 $extInfo['attributes']['DeprecatedHooks'] ?? []
81 ),
82 MediaWikiServices::getInstance()->getObjectFactory()
83 )
84 );
85 $this->getContext()->provide( 'VirtualDomains',
86 $extInfo['attributes']['DatabaseVirtualDomains'] ?? [] );
87
88 $this->getContext()->provide( 'ExtensionTaskSpecs', [] );
89 return Status::newGood();
90 }
91
92}
This initializes autoloading for MediaWiki core, extensions, and vendored libraries.
This is a simple immutable HookRegistry which can be used to set up a local HookContainer in tests an...
Base installer class.
Definition Installer.php:70
Base class for installer tasks.
Definition Task.php:24
getContext()
Get the execution context.
Definition Task.php:169
TODO: remove this and run web upgrade with normal startup (T386661)
getProvidedNames()
Get a list of names of objects that this task promises to provide via $this->getContext()->provide()....
getAliases()
Get alternative names of this task.These aliases can be used to fulfill dependencies of other tasks....
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Load JSON files, and uses a Processor to extract information.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44