-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSemanticCompoundQueries.php
83 lines (66 loc) · 2.16 KB
/
SemanticCompoundQueries.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
<?php
/**
* @see https://github.com/SemanticMediaWiki/SemanticCompoundQueries/
*
* @defgroup SemanticCompoundQueries SemanticCompoundQueries
*/
SemanticCompoundQueries::load();
/**
* @codeCoverageIgnore
*/
class SemanticCompoundQueries {
/**
* @since 1.1
*
* @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 ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
}
}
/**
* @since 1.1
*/
public static function initExtension( $credits = [] ) {
// See https://phabricator.wikimedia.org/T151136
define( 'SCQ_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
// Register message files
$GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticCompoundQueriesMagic'] = __DIR__ . '/i18n/SemanticCompoundQueries.i18n.magic.php';
}
/**
* @since 1.1
*/
public static function onExtensionFunction() {
if ( !defined( 'SMW_VERSION' ) ) {
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
die( "\nThe 'Semantic Compound Queries' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
} else {
die(
'<b>Error:</b> The <a href="https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Compound_Queries">Semantic Compound Queries</a> ' .
'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' .
'installed and enabled.<br />'
);
}
}
// wgAPIModules
$GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery';
// wgHooks
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$parser->setFunctionHook( 'compound_query', [ '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ] );
// always return true, in order not to stop MW's hook processing!
return true;
};
}
/**
* @since 1.1
*
* @return string|null
*/
public static function getVersion() {
return SCQ_VERSION;
}
}