|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticCompoundQueries/ |
|
5
|
|
|
* |
|
6
|
|
|
* @defgroup SemanticCompoundQueries SemanticCompoundQueries |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
SemanticCompoundQueries::load(); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @codeCoverageIgnore |
|
13
|
|
|
*/ |
|
14
|
|
|
class SemanticCompoundQueries { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @since 1.1 |
|
18
|
|
|
* |
|
19
|
|
|
* @note It is expected that this function is loaded before LocalSettings.php |
|
20
|
|
|
* to ensure that settings and global functions are available by the time |
|
21
|
|
|
* the extension is activated. |
|
22
|
|
|
*/ |
|
23
|
|
|
public static function load() { |
|
24
|
|
|
|
|
25
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
|
26
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @since 1.1 |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function initExtension( $credits = [] ) { |
|
34
|
|
|
|
|
35
|
|
|
// See https://phabricator.wikimedia.org/T151136 |
|
36
|
|
|
define( 'SCQ_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' ); |
|
37
|
|
|
|
|
38
|
|
|
// Register message files |
|
39
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n'; |
|
40
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticCompoundQueriesMagic'] = __DIR__ . '/i18n/SemanticCompoundQueries.i18n.magic.php'; |
|
41
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @since 1.1 |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function onExtensionFunction() { |
|
48
|
|
|
|
|
49
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
|
50
|
|
|
|
|
51
|
|
|
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
52
|
|
|
die( "\nThe 'Semantic Compound Queries' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); |
|
53
|
|
|
} else { |
|
54
|
|
|
die( |
|
55
|
|
|
'<b>Error:</b> The <a href="https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Compound_Queries">Semantic Compound Queries</a> ' . |
|
56
|
|
|
'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' . |
|
57
|
|
|
'installed and enabled.<br />' |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// wgAPIModules |
|
63
|
|
|
$GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery'; |
|
64
|
|
|
|
|
65
|
|
|
// wgHooks |
|
66
|
|
|
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
67
|
|
|
$parser->setFunctionHook( 'compound_query', [ '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ] ); |
|
68
|
|
|
|
|
69
|
|
|
// always return true, in order not to stop MW's hook processing! |
|
70
|
|
|
return true; |
|
71
|
|
|
}; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @since 1.1 |
|
76
|
|
|
* |
|
77
|
|
|
* @return string|null |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function getVersion() { |
|
80
|
|
|
return SCQ_VERSION; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|