Completed
Push — master ( eef04e...e38093 )
by Jeroen De
05:20
created

HookRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 100
ccs 24
cts 25
cp 0.96
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B register() 0 77 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
		/**
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
				$personal_urls,
53
				$title,
54 1
				$skin->getUser()
55
			);
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
				$tableUpdater,
71
				$user,
72
				$options
73
			);
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
			);
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
			);
100
101 1
			$getPreferences = new GetPreferences(
102
				$user,
103
				$userLanguage,
104
				$preferences
105
			);
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