1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SWL; |
4
|
|
|
|
5
|
|
|
use SWL\MediaWiki\Hooks\PersonalUrls; |
6
|
|
|
use SWL\MediaWiki\Hooks\UserSaveOptions; |
7
|
|
|
use SWL\MediaWiki\Hooks\GetPreferences; |
8
|
|
|
use SWL\MediaWiki\Hooks\ExtensionSchemaUpdater; |
9
|
|
|
use SWL\TableUpdater; |
10
|
|
|
|
11
|
|
|
use User; |
12
|
|
|
use Title; |
13
|
|
|
use Language; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 1.0 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class HookRegistry { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $configuration; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @since 1.0 |
30
|
|
|
* |
31
|
|
|
* @param array $configuration |
32
|
|
|
*/ |
33
|
2 |
|
public function __construct( array $configuration ) { |
34
|
2 |
|
$this->configuration = $configuration; |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @since 1.0 |
39
|
|
|
* |
40
|
|
|
* @param array &$wgHooks |
41
|
|
|
*/ |
42
|
1 |
|
public function register( &$wgHooks ) { |
43
|
|
|
|
44
|
1 |
|
$configuration = $this->configuration; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls |
48
|
|
|
*/ |
49
|
|
|
$wgHooks['PersonalUrls'][] = function( array &$personal_urls, \Title $title, \SkinTemplate $skin ) use ( $configuration ) { |
50
|
|
|
|
51
|
1 |
|
$personalUrls = new PersonalUrls( |
52
|
1 |
|
$personal_urls, |
53
|
1 |
|
$title, |
54
|
1 |
|
$skin->getUser() |
55
|
1 |
|
); |
56
|
|
|
|
57
|
1 |
|
$personalUrls->setConfiguration( $configuration ); |
58
|
|
|
|
59
|
1 |
|
return $personalUrls->execute(); |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions |
64
|
|
|
*/ |
65
|
|
|
$wgHooks['UserSaveOptions'][] = function( \User $user, array &$options ) use ( $configuration ) { |
66
|
|
|
|
67
|
1 |
|
$tableUpdater = new TableUpdater( wfGetDB( DB_MASTER ) ); |
68
|
|
|
|
69
|
1 |
|
$userSaveOptions = new UserSaveOptions( |
70
|
1 |
|
$tableUpdater, |
71
|
1 |
|
$user, |
72
|
|
|
$options |
73
|
1 |
|
); |
74
|
|
|
|
75
|
1 |
|
return $userSaveOptions->execute(); |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates |
80
|
|
|
*/ |
81
|
|
|
$wgHooks['LoadExtensionSchemaUpdates'][] = function( \DatabaseUpdater $databaseUpdater ) use ( $configuration ) { |
82
|
|
|
|
83
|
1 |
|
$extensionSchemaUpdater = new ExtensionSchemaUpdater( |
84
|
|
|
$databaseUpdater |
85
|
1 |
|
); |
86
|
|
|
|
87
|
1 |
|
$extensionSchemaUpdater->setConfiguration( $configuration ); |
88
|
|
|
|
89
|
1 |
|
return $extensionSchemaUpdater->execute(); |
90
|
|
|
}; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences |
94
|
|
|
*/ |
95
|
|
|
$wgHooks['GetPreferences'][] = function( User $user, array &$preferences ) use ( $configuration ) { |
96
|
|
|
|
97
|
1 |
|
$userLanguage = Language::factory( |
98
|
1 |
|
$configuration['wgLang']->getCode() |
99
|
1 |
|
); |
100
|
|
|
|
101
|
1 |
|
$getPreferences = new GetPreferences( |
102
|
1 |
|
$user, |
103
|
1 |
|
$userLanguage, |
104
|
|
|
$preferences |
105
|
1 |
|
); |
106
|
|
|
|
107
|
1 |
|
$getPreferences->setConfiguration( $configuration ); |
108
|
|
|
|
109
|
1 |
|
return $getPreferences->execute(); |
110
|
|
|
}; |
111
|
|
|
|
112
|
1 |
|
$wgHooks['AdminLinks'][] = 'SWLHooks::addToAdminLinks'; |
113
|
1 |
|
$wgHooks['SMWStore::updateDataBefore'][] = 'SWLHooks::onDataUpdate'; |
114
|
|
|
|
115
|
1 |
|
if ( $configuration['egSWLEnableEmailNotify'] ) { |
116
|
|
|
$wgHooks['SWLGroupNotify'][] = 'SWLHooks::onGroupNotify'; |
117
|
|
|
} |
118
|
1 |
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|