|
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
|
2 |
|
public function __construct( $configuration ) { |
|
29
|
2 |
|
$this->registerCallbackHandlers( $configuration ); |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @since 1.0 |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function register() { |
|
36
|
1 |
|
foreach ( $this->handlers as $name => $callback ) { |
|
37
|
1 |
|
Hooks::register( $name, $callback ); |
|
38
|
1 |
|
} |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @since 1.0 |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function deregister() { |
|
45
|
1 |
|
foreach ( array_keys( $this->handlers ) as $name ) { |
|
46
|
|
|
|
|
47
|
1 |
|
Hooks::clear( $name ); |
|
48
|
|
|
|
|
49
|
|
|
// Remove registered `wgHooks` hooks that are not cleared by the |
|
50
|
|
|
// previous call |
|
51
|
1 |
|
if ( isset( $GLOBALS['wgHooks'][$name] ) ) { |
|
52
|
|
|
unset( $GLOBALS['wgHooks'][$name] ); |
|
53
|
|
|
} |
|
54
|
1 |
|
} |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @since 1.0 |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* |
|
62
|
|
|
* @return boolean |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function isRegistered( $name ) { |
|
65
|
1 |
|
return Hooks::isRegistered( $name ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @since 1.0 |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $name |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function getHandlers( $name ) { |
|
76
|
1 |
|
return Hooks::getHandlers( $name ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @since 1.4 |
|
81
|
|
|
* |
|
82
|
|
|
* @param array &$config |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public static function onBeforeConfigCompletion( &$config ) { |
|
85
|
|
|
|
|
86
|
1 |
|
// Exclude listed properties from indexing |
|
87
|
|
|
if ( isset( $config['smwgFulltextSearchPropertyExemptionList'] ) ) { |
|
88
|
|
|
$config['smwgFulltextSearchPropertyExemptionList'] = array_merge( |
|
89
|
|
|
$config['smwgFulltextSearchPropertyExemptionList'], |
|
90
|
|
|
array( |
|
91
|
1 |
|
'___EUSER', '___CUSER', '___SUBP', '___REVID', '___VIEWS', |
|
92
|
1 |
|
'___NREV', '___NTREV', '___USEREDITCNT', '___EXIFDATA' |
|
93
|
1 |
|
) |
|
94
|
1 |
|
); |
|
95
|
1 |
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
// Exclude listed properties from dependency detection as each of the |
|
98
|
|
|
// selected object would trigger an automatic change without the necessary |
|
99
|
2 |
|
// human intervention and can therefore produce unwanted query updates |
|
100
|
1 |
|
if ( isset( $config['smwgQueryDependencyPropertyExemptionlist'] ) ) { |
|
101
|
|
|
$config['smwgQueryDependencyPropertyExemptionlist'] = array_merge( |
|
102
|
|
|
$config['smwgQueryDependencyPropertyExemptionlist'], |
|
103
|
|
|
array( |
|
104
|
1 |
|
'___REVID', '___VIEWS', '___NREV', '___NTREV', |
|
105
|
|
|
'___USEREDITCNT', '___EXIFDATA' |
|
106
|
|
|
) |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
1 |
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
private function registerCallbackHandlers( $configuration ) { |
|
112
|
1 |
|
|
|
113
|
1 |
|
$this->handlers['smwInitProperties'] = function () { |
|
114
|
|
|
return PropertyRegistry::getInstance()->registerPropertiesAndAliases(); |
|
115
|
1 |
|
}; |
|
116
|
|
|
|
|
117
|
1 |
|
$this->handlers['SMW::SQLStore::updatePropertyTableDefinitions'] = function ( &$propertyTableDefinitions ) use( $configuration ) { |
|
118
|
|
|
return PropertyRegistry::getInstance()->registerAsFixedTables( $propertyTableDefinitions, $configuration ); |
|
119
|
2 |
|
}; |
|
120
|
|
|
|
|
121
|
|
|
$this->handlers['SMWStore::updateDataBefore'] = function ( $store, $semanticData ) use ( $configuration ) { |
|
122
|
|
|
|
|
123
|
|
|
$appFactory = new AppFactory( $configuration['wgShortUrlPrefix'] ); |
|
124
|
|
|
|
|
125
|
|
|
$propertyAnnotator = new ExtraPropertyAnnotator( |
|
126
|
|
|
$semanticData, |
|
127
|
|
|
$appFactory, |
|
128
|
|
|
$configuration |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
|
|
return $propertyAnnotator->addAnnotation(); |
|
132
|
|
|
}; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|