forked from SemanticMediaWiki/SemanticMediaWiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SemanticMediaWiki.php
127 lines (105 loc) · 3.49 KB
/
SemanticMediaWiki.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
use SMW\NamespaceManager;
use SMW\Services\ServicesFactory;
use SMW\Setup;
use SMW\SetupCheck;
/**
* @codeCoverageIgnore
*
* ExtensionRegistry only maps classes and functions after all extensions have
* been queued from the LocalSettings.php resulting in DefaultSettings not being
* loaded in-time.
*
* When changing the load order, please ensure that this function is run either
* via Composer's autoloading or as part of your internal registration.
*/
SemanticMediaWiki::load();
/**
* @codeCoverageIgnore
*
* This documentation group collects source code files belonging to Semantic
* MediaWiki.
*
* For documenting extensions of SMW, please do not use groups starting with
* "SMW" but make your own groups instead. Browsing at
* https://doc.semantic-mediawiki.org/ is assumed to be easier this way.
*
* @defgroup SMW Semantic MediaWiki
*/
class SemanticMediaWiki {
/**
* @since 2.5
*
* @note It is expected that this function is loaded before LocalSettings.php
* to ensure that settings and global functions are available by the time
* the extension is activated.
*/
public static function load() {
if ( !defined( 'MEDIAWIKI' ) ) {
return;
}
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
}
include_once __DIR__ . '/src/Aliases.php';
include_once __DIR__ . '/src/Defines.php';
include_once __DIR__ . '/src/GlobalFunctions.php';
// If the function is called more than once then this will fail on
// purpose
foreach ( include __DIR__ . '/DefaultSettings.php' as $key => $value ) {
if ( !isset( $GLOBALS[$key] ) ) {
$GLOBALS[$key] = $value;
}
}
/**
* @see https://www.mediawiki.org/wiki/Localisation#Localising_namespaces_and_special_page_aliases
*/
$GLOBALS['wgMessagesDirs']['SemanticMediaWiki'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = __DIR__ . '/i18n/extra/SemanticMediaWiki.alias.php';
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = __DIR__ . '/i18n/extra/SemanticMediaWiki.magic.php';
// Registration point before any `extension.json` invocation
// takes place
Setup::registerExtensionCheck( $GLOBALS );
}
/**
* @since 2.4
*/
public static function initExtension( $credits = [] ) {
if ( !defined( 'SMW_VERSION' ) && isset( $credits['version'] ) ) {
define( 'SMW_VERSION', $credits['version'] );
}
// https://phabricator.wikimedia.org/T212738
if ( !defined( 'MW_VERSION' ) ) {
define( 'MW_VERSION', $GLOBALS['wgVersion'] );
}
// Only allow to set the loading state while being part of the test
// environment
if ( defined( 'MW_PHPUNIT_TEST' ) && !defined( 'SMW_EXTENSION_LOADED' ) ) {
define( 'SMW_EXTENSION_LOADED', true );
}
// Release the check after the extension was successfully loaded
Setup::releaseExtensionCheck( $GLOBALS );
// Registration point for required early registration
Setup::initExtension( $GLOBALS );
}
/**
* Setup and initialization
*
* @note $wgExtensionFunctions variable is an array that stores
* functions to be called after most of MediaWiki initialization
* has finalized
*
* @see https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions
*
* @since 1.9
*/
public static function onExtensionFunction() {
$namespace = new NamespaceManager();
$namespace->init( $GLOBALS );
$setup = new Setup();
$setup->setHookDispatcher(
ServicesFactory::getInstance()->getHookDispatcher()
);
$setup->init( $GLOBALS, __DIR__ );
}
}