MediaWiki
master
Toggle main menu visibility
ExtensionsProvider.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Installer\Task;
4
5
use AutoLoader;
6
use MediaWiki\HookContainer\HookContainer;
7
use MediaWiki\HookContainer\StaticHookRegistry;
8
use MediaWiki\MainConfigSchema;
9
use MediaWiki\MediaWikiServices;
10
use MediaWiki\Registration\ExtensionProcessor;
11
use MediaWiki\Status\Status;
12
18
class
ExtensionsProvider
extends
Task
{
20
public
function
getName
() {
21
return
'extensions'
;
22
}
23
25
public
function
getProvidedNames
() {
26
return
[
'HookContainer'
,
'ExtensionTaskSpecs'
];
27
}
28
29
public
function
execute
():
Status
{
30
if
( !$this->
getOption
(
'Extensions'
) ) {
31
$this->
getContext
()->provide(
'ExtensionTaskSpecs'
, [] );
32
return
Status::newGood();
33
}
34
35
// Marker for DatabaseUpdater::loadExtensions so we don't
36
// double load extensions
37
define(
'MW_EXTENSIONS_LOADED'
,
true
);
38
39
$legacySchemaHooks = $this->getAutoExtensionLegacySchemaHooks();
40
$data = $this->getAutoExtensionData();
41
if
( isset( $data[
'globals'
][
'wgHooks'
][
'LoadExtensionSchemaUpdates'
] ) ) {
42
$legacySchemaHooks = array_merge( $legacySchemaHooks,
43
$data[
'globals'
][
'wgHooks'
][
'LoadExtensionSchemaUpdates'
] );
44
}
45
$extDeprecatedHooks = $data[
'attributes'
][
'DeprecatedHooks'
] ?? [];
46
47
$legacyHooks = $legacySchemaHooks ? [
'LoadExtensionSchemaUpdates'
=> $legacySchemaHooks ] : [];
48
$this->
getContext
()->provide(
'HookContainer'
,
49
new
HookContainer
(
50
new
StaticHookRegistry(
51
$legacyHooks,
52
$data[
'attributes'
][
'Hooks'
] ?? [],
53
$extDeprecatedHooks
54
),
55
MediaWikiServices::getInstance
()->getObjectFactory()
56
)
57
);
58
$this->
getContext
()->provide(
'ExtensionTaskSpecs'
,
59
$data[
'attributes'
][
'InstallerTasks'
] ?? [] );
60
61
return
Status::newGood();
62
}
63
67
protected
function
getExtensionsDir
() {
68
return
MW_INSTALL_PATH .
'/extensions'
;
69
}
70
74
protected
function
getSkinsDir
() {
75
return
MW_INSTALL_PATH .
'/skins'
;
76
}
77
84
private
function
getAutoExtensionLegacySchemaHooks() {
85
$exts = $this->getOption(
'Extensions'
);
86
$extensionsDir = $this->getExtensionsDir();
87
$files = [];
88
foreach
( $exts as $e ) {
89
if
( file_exists(
"$extensionsDir/$e/$e.php"
) ) {
90
$files[] =
"$extensionsDir/$e/$e.php"
;
91
}
92
}
93
94
if
( $files ) {
95
return
$this->includeExtensionFiles( $files );
96
}
else
{
97
return
[];
98
}
99
}
100
108
private
function
includeExtensionFiles( $files ) {
117
// Extract the defaults into the current scope
118
foreach
(
MainConfigSchema::listDefaultValues
(
'wg'
) as $var =>
$value
) {
119
$$var =
$value
;
120
}
121
122
// phpcs:ignore MediaWiki.VariableAnalysis.UnusedGlobalVariables
123
global
$IP
,
$wgAutoloadClasses
,
$wgExtensionDirectory
,
$wgStyleDirectory
;
124
$wgExtensionDirectory
= $this->getExtensionsDir();
125
$wgStyleDirectory
= $this->getSkinsDir();
126
127
foreach
( $files as $file ) {
128
require_once $file;
129
}
130
131
// Ignore everyone else's hooks. Lord knows what someone might be doing
132
// in ParserFirstCallInit (see T29171)
133
// @phpcs:disable MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgHooks
134
// @phpcs:ignore Generic.Files.LineLength.TooLong
135
// @phan-suppress-next-line PhanUndeclaredVariable,PhanCoalescingAlwaysNull $wgHooks is defined by MainConfigSchema
136
$hooksWeWant =
$wgHooks
[
'LoadExtensionSchemaUpdates'
] ?? [];
137
// @phpcs:enable MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgHooks
138
return
$hooksWeWant;
139
}
140
147
private
function
getAutoExtensionData() {
148
$exts = $this->getOption(
'Extensions'
);
149
150
$extensionProcessor =
new
ExtensionProcessor();
151
foreach
( $exts as $e ) {
152
$jsonPath = $this->getExtensionsDir() .
"/$e/extension.json"
;
153
if
( file_exists( $jsonPath ) ) {
154
$extensionProcessor->extractInfoFromFile( $jsonPath );
155
}
156
}
157
158
$autoload = $extensionProcessor->getExtractedAutoloadInfo();
159
AutoLoader::loadFiles
( $autoload[
'files'
] );
160
AutoLoader::registerClasses
( $autoload[
'classes'
] );
161
AutoLoader::registerNamespaces
( $autoload[
'namespaces'
] );
162
163
return
$extensionProcessor->getExtractedInfo();
164
}
165
166
}
$wgAutoloadClasses
$wgAutoloadClasses
Definition
Setup.php:139
$IP
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) $IP
Environment checks.
Definition
Setup.php:102
if
if(!defined('MW_SETUP_CALLBACK'))
Definition
WebStart.php:72
AutoLoader\registerClasses
static registerClasses(array $files)
Register a file to load the given class from.
Definition
AutoLoader.php:69
AutoLoader\loadFiles
static loadFiles(array $files)
Batch version of loadFile().
Definition
AutoLoader.php:102
AutoLoader\registerNamespaces
static registerNamespaces(array $dirs)
Register a directory to load the classes of a given namespace from, per PSR4.
Definition
AutoLoader.php:59
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition
HookContainer.php:42
MediaWiki\Installer\Task\ExtensionsProvider
A scheduled provider which loads extensions.
Definition
ExtensionsProvider.php:18
MediaWiki\Installer\Task\ExtensionsProvider\execute
execute()
Execute the task.
Definition
ExtensionsProvider.php:29
MediaWiki\Installer\Task\ExtensionsProvider\getName
getName()
Get the symbolic name of the task.string
Definition
ExtensionsProvider.php:20
MediaWiki\Installer\Task\ExtensionsProvider\getSkinsDir
getSkinsDir()
Definition
ExtensionsProvider.php:74
MediaWiki\Installer\Task\ExtensionsProvider\getExtensionsDir
getExtensionsDir()
Definition
ExtensionsProvider.php:67
MediaWiki\Installer\Task\ExtensionsProvider\getProvidedNames
getProvidedNames()
Get a list of names of objects that this task promises to provide via $this->getContext()->provide()....
Definition
ExtensionsProvider.php:25
MediaWiki\Installer\Task\Task
Base class for installer tasks.
Definition
Task.php:24
MediaWiki\Installer\Task\Task\getOption
getOption(string $name)
Get an installer option value.
Definition
Task.php:190
MediaWiki\Installer\Task\Task\getContext
getContext()
Get the execution context.
Definition
Task.php:169
MediaWiki\MainConfigSchema\listDefaultValues
static listDefaultValues(string $prefix='')
Returns a generator for iterating over all config settings and their default values.
Definition
MainConfigSchema.php:160
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:361
MediaWiki\Status\Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition
Status.php:44
StatusValue\$value
T $value
Definition
StatusValue.php:63
$wgStyleDirectory
$wgStyleDirectory
Config variable stub for the StyleDirectory setting, for use by phpdoc and IDEs.
Definition
config-vars.php:115
$wgHooks
$wgHooks
Config variable stub for the Hooks setting, for use by phpdoc and IDEs.
Definition
config-vars.php:4062
$wgExtensionDirectory
$wgExtensionDirectory
Config variable stub for the ExtensionDirectory setting, for use by phpdoc and IDEs.
Definition
config-vars.php:109
includes
Installer
Task
ExtensionsProvider.php
Generated on
for MediaWiki by
1.18.0