1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SMW\NamespaceManager; |
4
|
|
|
use SMW\ApplicationFactory; |
5
|
|
|
use SMW\Setup; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This documentation group collects source code files belonging to Semantic |
9
|
|
|
* MediaWiki. |
10
|
|
|
* |
11
|
|
|
* For documenting extensions of SMW, please do not use groups starting with |
12
|
|
|
* "SMW" but make your own groups instead. Browsing at |
13
|
|
|
* http://doc.semantic-mediawiki.org/ is assumed to be easier this way. |
14
|
|
|
* |
15
|
|
|
* @defgroup SMW Semantic MediaWiki |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
19
|
|
|
die( 'Not an entry point.' ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if ( defined( 'SMW_VERSION' ) ) { |
23
|
|
|
// Do not load SMW more than once |
24
|
|
|
return 1; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
define( 'SMW_VERSION', '2.4.0-alpha' ); |
28
|
|
|
|
29
|
|
|
if ( version_compare( $GLOBALS['wgVersion'], '1.19c', '<' ) ) { |
30
|
|
|
die( '<b>Error:</b> This version of Semantic MediaWiki requires MediaWiki 1.19 or above; use SMW 1.8.x for MediaWiki 1.18.x or 1.17.x.' ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
SemanticMediaWiki::initExtension(); |
34
|
|
|
|
35
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
36
|
|
|
SemanticMediaWiki::onExtensionFunction(); |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @codeCoverageIgnore |
41
|
|
|
*/ |
42
|
|
|
class SemanticMediaWiki { |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* As soon as Composer is autoloading this file, start the init process for some |
46
|
|
|
* components. |
47
|
|
|
* |
48
|
|
|
* @since 2.4 |
49
|
|
|
*/ |
50
|
|
|
public static function initExtension() { |
|
|
|
|
51
|
|
|
|
52
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
53
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Registration of the extension credits, see Special:Version. |
57
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][] = array( |
58
|
|
|
'path' => __FILE__, |
59
|
|
|
'name' => 'Semantic MediaWiki', |
60
|
|
|
'version' => SMW_VERSION, |
61
|
|
|
'author' => array( |
62
|
|
|
'[http://korrekt.org Markus Krötzsch]', |
63
|
|
|
'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]', |
64
|
|
|
'James Hong Kong', |
65
|
|
|
'[https://www.semantic-mediawiki.org/wiki/Contributors ...]' |
66
|
|
|
), |
67
|
|
|
'url' => 'https://www.semantic-mediawiki.org', |
68
|
|
|
'descriptionmsg' => 'smw-desc', |
69
|
|
|
'license-name' => 'GPL-2.0+' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
// A flag used to indicate SMW defines a semantic extension type for extension credits. |
73
|
|
|
// @deprecated, removal in SMW 3.0 |
74
|
|
|
define( 'SEMANTIC_EXTENSION_TYPE', true ); |
75
|
|
|
|
76
|
|
|
// Load class_alias |
77
|
|
|
require_once __DIR__ . '/includes/Aliases.php'; |
78
|
|
|
|
79
|
|
|
// Load global constants |
80
|
|
|
require_once __DIR__ . '/includes/Defines.php'; |
81
|
|
|
|
82
|
|
|
// Temporary measure to ease Composer/MW 1.22 migration |
83
|
|
|
require_once __DIR__ . '/includes/NamespaceManager.php'; |
84
|
|
|
|
85
|
|
|
// Load global functions |
86
|
|
|
require_once __DIR__ . '/includes/GlobalFunctions.php'; |
87
|
|
|
|
88
|
|
|
// Load default settings |
89
|
|
|
require_once __DIR__ . '/SemanticMediaWiki.settings.php'; |
90
|
|
|
|
91
|
|
|
// Because of MW 1.19 we need to register message files here |
92
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'i18n'; |
93
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'languages/SMW_Messages.php'; |
94
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $GLOBALS['smwgIP'] . 'languages/SMW_Aliases.php'; |
95
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $GLOBALS['smwgIP'] . 'languages/SMW_Magic.php'; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Setup and initialization |
100
|
|
|
* |
101
|
|
|
* @note $wgExtensionFunctions variable is an array that stores |
102
|
|
|
* functions to be called after most of MediaWiki initialization |
103
|
|
|
* has finalized |
104
|
|
|
* |
105
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions |
106
|
|
|
* |
107
|
|
|
* @since 1.9 |
108
|
|
|
*/ |
109
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
110
|
|
|
|
111
|
|
|
// 3.x reverse the order to ensure that smwgMainCacheType is used |
112
|
|
|
// as main and smwgCacheType being deprecated with 3.x |
113
|
|
|
$GLOBALS['smwgMainCacheType'] = $GLOBALS['smwgCacheType']; |
114
|
|
|
|
115
|
|
|
$applicationFactory = ApplicationFactory::getInstance(); |
116
|
|
|
|
117
|
|
|
$namespace = new NamespaceManager( $GLOBALS ); |
118
|
|
|
$namespace->init(); |
119
|
|
|
|
120
|
|
|
$setup = new Setup( $applicationFactory, $GLOBALS, __DIR__ ); |
121
|
|
|
$setup->run(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @since 2.4 |
126
|
|
|
* |
127
|
|
|
* @return string|null |
128
|
|
|
*/ |
129
|
|
|
public static function getVersion() { |
130
|
|
|
return SMW_VERSION; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @since 2.4 |
135
|
|
|
* |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
|
|
public static function getExtendedVersion() { |
|
|
|
|
139
|
|
|
|
140
|
|
|
$store = ''; |
141
|
|
|
|
142
|
|
|
if ( isset( $GLOBALS['smwgDefaultStore'] ) ) { |
143
|
|
|
$store = $GLOBALS['smwgDefaultStore'] . ( strpos( $GLOBALS['smwgDefaultStore'], 'SQL' ) ? '' : ' ['. $GLOBALS['smwgSparqlDatabaseConnector'] .']' ); |
144
|
|
|
}; |
145
|
|
|
|
146
|
|
|
return array( |
147
|
|
|
'store' => $store, |
148
|
|
|
'db' => isset( $GLOBALS['wgDBtype'] ) ? $GLOBALS['wgDBtype'] : 'N/A' |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.