Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
38 / 38 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
GlobalWatchlistGuidedTourHooks | |
100.00% |
38 / 38 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
newFromGlobalState | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
onResourceLoaderRegisterModules | |
100.00% |
34 / 34 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * Hook handler |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; if not, write to the Free Software Foundation, Inc., |
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | * http://www.gnu.org/copyleft/gpl.html |
20 | * |
21 | * @file |
22 | * @ingroup SpecialPage |
23 | */ |
24 | |
25 | namespace MediaWiki\Extension\GlobalWatchlist; |
26 | |
27 | use ExtensionRegistry; |
28 | use MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook; |
29 | use MediaWiki\ResourceLoader\ResourceLoader; |
30 | |
31 | /** |
32 | * @author DannyS712 |
33 | */ |
34 | class GlobalWatchlistGuidedTourHooks implements |
35 | ResourceLoaderRegisterModulesHook |
36 | { |
37 | |
38 | /** @var ExtensionRegistry */ |
39 | private $extensionRegistry; |
40 | |
41 | /** |
42 | * @param ExtensionRegistry $extensionRegistry |
43 | */ |
44 | public function __construct( |
45 | ExtensionRegistry $extensionRegistry |
46 | ) { |
47 | $this->extensionRegistry = $extensionRegistry; |
48 | } |
49 | |
50 | /** |
51 | * Need a factory method to inject ExtensionRegistry, which is not available from |
52 | * the service container |
53 | * |
54 | * @return GlobalWatchlistGuidedTourHooks |
55 | */ |
56 | public static function newFromGlobalState() { |
57 | return new GlobalWatchlistGuidedTourHooks( |
58 | ExtensionRegistry::getInstance() |
59 | ); |
60 | } |
61 | |
62 | /** |
63 | * Register ResourceLoader modules with dynamic dependencies. |
64 | * |
65 | * @param ResourceLoader $resourceLoader |
66 | * @return void |
67 | */ |
68 | public function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ): void { |
69 | $config = $resourceLoader->getConfig(); |
70 | if ( !$config->get( 'GlobalWatchlistEnableGuidedTour' ) || |
71 | !$this->extensionRegistry->isLoaded( 'GuidedTour' ) |
72 | ) { |
73 | return; |
74 | } |
75 | |
76 | // Conditionally registered: only register the GuidedTour for |
77 | // Special:GlobalWatchlistSettings if the GuidedTour extension |
78 | // is available to rely upon and $wgGlobalWatchlistEnableGuidedTour |
79 | // is true |
80 | $resourceLoaderModule = [ |
81 | 'localBasePath' => __DIR__ . '/../modules', |
82 | 'remoteExtPath' => 'GlobalWatchlist/modules', |
83 | 'packageFiles' => [ |
84 | 'SettingsTour.js' |
85 | ], |
86 | 'dependencies' => [ |
87 | 'ext.guidedTour' |
88 | ], |
89 | 'messages' => [ |
90 | 'globalwatchlist-tour-addsite', |
91 | 'globalwatchlist-tour-addsite-description', |
92 | 'globalwatchlist-tour-fastmode', |
93 | 'globalwatchlist-tour-fastmode-description', |
94 | 'globalwatchlist-tour-filters', |
95 | 'globalwatchlist-tour-filters-description', |
96 | 'globalwatchlist-tour-help', |
97 | 'globalwatchlist-tour-help-description', |
98 | 'globalwatchlist-tour-intro', |
99 | 'globalwatchlist-tour-intro-description', |
100 | 'globalwatchlist-tour-sitelist', |
101 | 'globalwatchlist-tour-sitelist-description', |
102 | 'globalwatchlist-tour-types', |
103 | 'globalwatchlist-tour-types-description', |
104 | ] |
105 | ]; |
106 | $resourceLoader->register( |
107 | 'ext.guidedTour.globalWatchlistSettings', |
108 | $resourceLoaderModule |
109 | ); |
110 | } |
111 | |
112 | } |