/
ExtensionRegistryHelper.php
94 lines (76 loc) · 2.22 KB
/
ExtensionRegistryHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @copyright 2018 - 2019, Stephan Gambke
* @license GNU General Public License, version 3 (or any later version)
*
* @file
*/
namespace ExtensionRegistryHelper;
/**
* Class ExtensionRegistryHelper
*
* @package ExtensionRegistryHelper
*/
class ExtensionRegistryHelper {
private static $singleton;
/**
* ExtensionRegistryHelper constructor.
*
* @throws \Exception
*/
public function __construct() {
if ( ! isset( $GLOBALS[ 'wgVersion' ] ) || version_compare( $GLOBALS[ 'wgVersion' ], '1.27', '<' ) ) {
throw new \Exception( 'ExtensionRegistryHelper requires MediaWiki 1.27 or above.' );
}
}
/**
* @return ExtensionRegistryHelper
* @throws \Exception
*/
public static function singleton() {
if ( !self::$singleton ) {
self::$singleton = new self();
}
return self::$singleton;
}
/**
* @param $extensionName
* @param string|null $path
*
* @throws \Exception
*/
public function loadExtensionRecursive( $extensionName, $path = null ) {
$path = $path ?: $GLOBALS[ 'wgExtensionDirectory' ] . '/' . $extensionName . '/extension.json';
$this->loadModuleRecursive( $extensionName, $path );
}
/**
* @param $skinName
* @param string|null $path
*
* @throws \Exception
*/
public function loadSkinRecursive( $skinName, $path = null ) {
$path = $path ?: $GLOBALS[ 'wgStyleDirectory' ] . '/' . $skinName . '/skin.json';
$this->loadModuleRecursive( $skinName, $path );
}
/**
* @param $moduleName
*
* @throws \Exception
*/
protected function loadModuleRecursive( $moduleName, $path ) {
$extensionRegistry = \ExtensionRegistry::getInstance();
if ( !$extensionRegistry->isLoaded( $moduleName ) && !array_key_exists( $path, $extensionRegistry->getQueue() ) ) {
$subregistry = new \ExtensionRegistry();
$subregistry->queue( $path );
$subregistry->loadFromQueue();
try {
$loadedRefl = new \ReflectionProperty( \ExtensionRegistry::class, 'loaded' );
$loadedRefl->setAccessible( true );
$loadedRefl->setValue( $extensionRegistry, $extensionRegistry->getAllThings() + $subregistry->getAllThings() );
} catch ( \Exception $e ) {
throw new \Exception( 'This version of MediaWiki does not support ExtensionRegistryHelper.', 0, $e );
}
}
}
}