|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WNBY; |
|
4
|
|
|
|
|
5
|
|
|
use Hooks; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @license GNU GPL v2+ |
|
9
|
|
|
* @since 1.0 |
|
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 = array () ) { |
|
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
|
1 |
|
Hooks::clear( $name ); |
|
44
|
1 |
|
} |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @since 1.0 |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $name |
|
51
|
|
|
* |
|
52
|
|
|
* @return Callable|false |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function getHandlerFor( $name ) { |
|
55
|
1 |
|
return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @since 1.0 |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $name |
|
62
|
|
|
* |
|
63
|
|
|
* @return boolean |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function isRegistered( $name ) { |
|
66
|
1 |
|
return Hooks::isRegistered( $name ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
private function registerCallbackHandlers( $configuration ) { |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit |
|
73
|
|
|
*/ |
|
74
|
2 |
|
$this->handlers['ParserFirstCallInit'] = function ( &$parser ) { |
|
75
|
|
|
|
|
76
|
1 |
|
$parserFunctionFactory = new ParserFunctionFactory(); |
|
77
|
|
|
|
|
78
|
1 |
|
list( $name, $definition, $flag ) = $parserFunctionFactory->newNearbyParserFunctionDefinition(); |
|
79
|
|
|
|
|
80
|
1 |
|
$parser->setFunctionHook( $name, $definition, $flag ); |
|
81
|
|
|
|
|
82
|
1 |
|
return true; |
|
83
|
|
|
}; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars |
|
87
|
|
|
*/ |
|
88
|
2 |
|
$this->handlers['ResourceLoaderGetConfigVars'] = function ( &$vars ) { |
|
89
|
|
|
|
|
90
|
1 |
|
$vars['whats-nearby'] = array( |
|
91
|
1 |
|
'wgCachePrefix' => $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix'], |
|
92
|
1 |
|
'wgLanguageCode' => $GLOBALS['wgLang']->getCode() |
|
93
|
1 |
|
); |
|
94
|
|
|
|
|
95
|
1 |
|
return true; |
|
96
|
|
|
}; |
|
97
|
2 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.