1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use Hooks; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @license GNU GPL v2+ |
9
|
|
|
* @since 1.3 |
10
|
|
|
* |
11
|
|
|
* @author mwjames |
12
|
|
|
*/ |
13
|
|
|
class HookRegistry { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private $handlers = array(); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @since 1.0 |
22
|
|
|
* |
23
|
|
|
* @param array $configuration |
24
|
|
|
*/ |
25
|
2 |
|
public function __construct( $configuration ) { |
26
|
2 |
|
$this->registerCallbackHandlers( $configuration ); |
27
|
2 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
1 |
|
public function register() { |
33
|
1 |
|
foreach ( $this->handlers as $name => $callback ) { |
34
|
1 |
|
Hooks::register( $name, $callback ); |
35
|
1 |
|
} |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 1.0 |
40
|
|
|
*/ |
41
|
1 |
|
public function deregister() { |
42
|
1 |
|
foreach ( array_keys( $this->handlers ) as $name ) { |
43
|
|
|
|
44
|
1 |
|
Hooks::clear( $name ); |
45
|
|
|
|
46
|
|
|
// Remove registered `wgHooks` hooks that are not cleared by the |
47
|
|
|
// previous call |
48
|
1 |
|
if ( isset( $GLOBALS['wgHooks'][$name] ) ) { |
49
|
|
|
unset( $GLOBALS['wgHooks'][$name] ); |
50
|
|
|
} |
51
|
1 |
|
} |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @since 1.0 |
56
|
|
|
* |
57
|
|
|
* @param string $name |
58
|
|
|
* |
59
|
|
|
* @return boolean |
60
|
|
|
*/ |
61
|
1 |
|
public function isRegistered( $name ) { |
62
|
1 |
|
return Hooks::isRegistered( $name ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @since 1.0 |
67
|
|
|
* |
68
|
|
|
* @param string $name |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
1 |
|
public function getHandlers( $name ) { |
73
|
1 |
|
return Hooks::getHandlers( $name ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @since 1.4 |
78
|
|
|
* |
79
|
|
|
* @param array &$config |
80
|
|
|
*/ |
81
|
1 |
|
public static function onBeforeConfigCompletion( &$config ) { |
82
|
|
|
|
83
|
|
|
$exemptionlist = array( |
84
|
1 |
|
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS', |
85
|
1 |
|
'___NREV', '___NTREV', '___USEREDITCNT', '___EXIFDATA' |
86
|
1 |
|
); |
87
|
|
|
|
88
|
|
|
// Exclude listed properties from indexing |
89
|
1 |
|
if ( isset( $config['smwgFulltextSearchPropertyExemptionList'] ) ) { |
90
|
1 |
|
$config['smwgFulltextSearchPropertyExemptionList'] = array_merge( |
91
|
1 |
|
$config['smwgFulltextSearchPropertyExemptionList'], |
92
|
|
|
$exemptionlist |
93
|
1 |
|
); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
// Exclude listed properties from dependency detection as each of the |
97
|
|
|
// selected object would trigger an automatic change without the necessary |
98
|
|
|
// human intervention and can therefore produce unwanted query updates |
99
|
1 |
|
if ( isset( $config['smwgQueryDependencyPropertyExemptionlist'] ) ) { |
100
|
|
|
$config['smwgQueryDependencyPropertyExemptionlist'] = array_merge( |
101
|
|
|
$config['smwgQueryDependencyPropertyExemptionlist'], |
102
|
|
|
$exemptionlist |
103
|
|
|
); |
104
|
|
|
} |
105
|
1 |
|
} |
106
|
|
|
|
107
|
2 |
|
private function registerCallbackHandlers( $configuration ) { |
108
|
|
|
|
109
|
2 |
|
$appFactory = new AppFactory( |
110
|
2 |
|
wfGetDB( DB_SLAVE ), |
111
|
|
|
$configuration |
112
|
2 |
|
); |
113
|
|
|
|
114
|
2 |
|
$appFactory->setLogger( |
115
|
2 |
|
\SMW\ApplicationFactory::getInstance()->getMediaWikiLogger() |
116
|
2 |
|
); |
117
|
|
|
|
118
|
2 |
|
$extensionPropertyRegistry = new ExtensionPropertyRegistry( |
119
|
|
|
$appFactory |
120
|
2 |
|
); |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMW::Property::initProperties |
124
|
|
|
*/ |
125
|
|
|
$this->handlers['SMW::Property::initProperties'] = function ( $propertyRegistry ) use ( $extensionPropertyRegistry ) { |
126
|
|
|
|
127
|
1 |
|
$extensionPropertyRegistry->registerOn( |
128
|
|
|
$propertyRegistry |
129
|
1 |
|
); |
130
|
|
|
|
131
|
1 |
|
return true; |
132
|
|
|
}; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMW::SQLStore::AddCustomFixedPropertyTables |
136
|
|
|
*/ |
137
|
|
|
$this->handlers['SMW::SQLStore::AddCustomFixedPropertyTables'] = function( array &$customFixedProperties, &$fixedPropertyTablePrefix ) use( $extensionPropertyRegistry ) { |
138
|
|
|
|
139
|
1 |
|
$extensionPropertyRegistry->registerAsFixedProperties( |
140
|
1 |
|
$customFixedProperties, |
141
|
|
|
$fixedPropertyTablePrefix |
142
|
1 |
|
); |
143
|
|
|
|
144
|
1 |
|
return true; |
145
|
|
|
}; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMWStore::updateDataBefore |
149
|
|
|
*/ |
150
|
1 |
|
$this->handlers['SMWStore::updateDataBefore'] = function ( $store, $semanticData ) use ( $appFactory ) { |
151
|
|
|
|
152
|
1 |
|
$extraPropertyAnnotator = new ExtraPropertyAnnotator( |
153
|
|
|
$appFactory |
154
|
1 |
|
); |
155
|
|
|
|
156
|
1 |
|
$extraPropertyAnnotator->addAnnotation( $semanticData ); |
157
|
|
|
|
158
|
1 |
|
return true; |
159
|
|
|
}; |
160
|
2 |
|
} |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
|