1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use SESP\PropertyRegistry; |
6
|
|
|
use SESP\Annotator\ExtraPropertyAnnotator; |
7
|
|
|
use SESP\Annotator\ShortUrlAnnotator; |
8
|
|
|
use Hooks; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.3 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class HookRegistry { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private $handlers = array(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @since 1.0 |
25
|
|
|
* |
26
|
|
|
* @param array $configuration |
27
|
|
|
*/ |
28
|
|
|
public function __construct( $configuration ) { |
29
|
|
|
$this->registerCallbackHandlers( $configuration ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @since 1.0 |
34
|
|
|
*/ |
35
|
|
|
public function register() { |
36
|
|
|
foreach ( $this->handlers as $name => $callback ) { |
37
|
|
|
Hooks::register( $name, $callback ); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @since 1.0 |
43
|
|
|
*/ |
44
|
|
|
public function deregister() { |
45
|
|
|
foreach ( array_keys( $this->handlers ) as $name ) { |
46
|
|
|
|
47
|
|
|
Hooks::clear( $name ); |
48
|
|
|
|
49
|
|
|
// Remove registered `wgHooks` hooks that are not cleared by the |
50
|
|
|
// previous call |
51
|
|
|
if ( isset( $GLOBALS['wgHooks'][$name] ) ) { |
52
|
|
|
unset( $GLOBALS['wgHooks'][$name] ); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @since 1.0 |
59
|
|
|
* |
60
|
|
|
* @param string $name |
61
|
|
|
* |
62
|
|
|
* @return boolean |
63
|
|
|
*/ |
64
|
|
|
public function isRegistered( $name ) { |
65
|
|
|
return Hooks::isRegistered( $name ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @since 1.0 |
70
|
|
|
* |
71
|
|
|
* @param string $name |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getHandlers( $name ) { |
76
|
|
|
return Hooks::getHandlers( $name ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @since 1.0 |
81
|
|
|
* |
82
|
|
|
* @param array &$config |
83
|
|
|
*/ |
84
|
|
|
public static function onBeforeConfigCompletion( &$config ) { |
85
|
|
|
|
86
|
|
|
if ( !isset( $config['smwgFulltextSearchPropertyExemptionList'] ) ) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Exclude those properties from indexing |
91
|
|
|
$config['smwgFulltextSearchPropertyExemptionList'] = array_merge( |
92
|
|
|
$config['smwgFulltextSearchPropertyExemptionList'], |
93
|
|
|
array( '___EUSER', '___CUSER', '___SUBP', '___EXIFDATA' ) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function registerCallbackHandlers( $configuration ) { |
98
|
|
|
|
99
|
|
|
$this->handlers['smwInitProperties'] = function () { |
100
|
|
|
return PropertyRegistry::getInstance()->registerPropertiesAndAliases(); |
101
|
|
|
}; |
102
|
|
|
|
103
|
|
|
$this->handlers['SMW::SQLStore::updatePropertyTableDefinitions'] = function ( &$propertyTableDefinitions ) use( $configuration ) { |
104
|
|
|
return PropertyRegistry::getInstance()->registerAsFixedTables( $propertyTableDefinitions, $configuration ); |
105
|
|
|
}; |
106
|
|
|
|
107
|
|
|
$this->handlers['SMWStore::updateDataBefore'] = function ( $store, $semanticData ) use ( $configuration ) { |
108
|
|
|
|
109
|
|
|
$appFactory = new AppFactory( $configuration['wgShortUrlPrefix'] ); |
110
|
|
|
|
111
|
|
|
$propertyAnnotator = new ExtraPropertyAnnotator( |
112
|
|
|
$semanticData, |
113
|
|
|
$appFactory, |
114
|
|
|
$configuration |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
return $propertyAnnotator->addAnnotation(); |
118
|
|
|
}; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|