Completed
Push — master ( a5b09f...24d151 )
by Jeroen De
04:21 queued 03:05
created

HookRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 97.22%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 102
ccs 35
cts 36
cp 0.9722
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B register() 0 79 2
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 1
		$tableUpdater = new TableUpdater(
47 1
			new LazyDBConnectionProvider( DB_MASTER )
48
		);
49
50
		/**
51
		 * @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
52
		 */
53
		$wgHooks['PersonalUrls'][] = function( array &$personal_urls, \Title $title, \SkinTemplate $skin ) use ( $configuration ) {
54
55 1
			$personalUrls = new PersonalUrls(
56 1
				$personal_urls,
57 1
				$title,
58 1
				$skin->getUser()
59
			);
60
61 1
			$personalUrls->setConfiguration( $configuration );
62
63 1
			return $personalUrls->execute();
64
		};
65
66
		/**
67
		 * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions
68
		 */
69
		$wgHooks['UserSaveOptions'][] = function( \User $user, array &$options ) use ( $configuration, $tableUpdater ) {
70
71 1
			$userSaveOptions = new UserSaveOptions(
72 1
				$tableUpdater,
73 1
				$user,
74 1
				$options
75
			);
76
77 1
			return $userSaveOptions->execute();
78
		};
79
80
		/**
81
		 * @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates
82
		 */
83
		$wgHooks['LoadExtensionSchemaUpdates'][] = function( \DatabaseUpdater $databaseUpdater ) use ( $configuration ) {
84
85 1
			$extensionSchemaUpdater = new ExtensionSchemaUpdater(
86 1
				$databaseUpdater
87
			);
88
89 1
			$extensionSchemaUpdater->setConfiguration( $configuration );
90
91 1
			return $extensionSchemaUpdater->execute();
92
		};
93
94
		/**
95
		 * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
96
		 */
97 1
		$wgHooks['GetPreferences'][] = function( User $user, array &$preferences ) use ( $configuration ) {
98
99 1
			$userLanguage = Language::factory(
100 1
				$GLOBALS['wgLang']->getCode()
101
			);
102
103 1
			$getPreferences = new GetPreferences(
104 1
				$user,
105 1
				$userLanguage,
106 1
				$preferences
107
			);
108
109 1
			$getPreferences->setConfiguration( $configuration );
110
111 1
			return $getPreferences->execute();
112
		};
113
114 1
		$wgHooks['AdminLinks'][] = 'SWLHooks::addToAdminLinks';
115 1
		$wgHooks['SMWStore::updateDataBefore'][] = 'SWLHooks::onDataUpdate';
116
117 1
		if ( $configuration['egSWLEnableEmailNotify'] ) {
118
			$wgHooks['SWLGroupNotify'][] = 'SWLHooks::onGroupNotify';
119
		}
120 1
	}
121
122
}
123