Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PerformanceInspectorHooks | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
onBeforePageDisplay | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
onBaseTemplateToolbox | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
onGetPreferences | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | |
5 | /** |
6 | * Hooks for PerformanceInspector extension |
7 | * |
8 | * @file |
9 | * @ingroup Extensions |
10 | */ |
11 | |
12 | class PerformanceInspectorHooks { |
13 | /** |
14 | * @param OutputPage &$out |
15 | * @param Skin &$skin |
16 | */ |
17 | public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) { |
18 | $title = $out->getTitle(); |
19 | $user = $out->getUser(); |
20 | |
21 | if ( $title->inNamespace( NS_MAIN ) && MediaWikiServices::getInstance() |
22 | ->getUserOptionsLookup() |
23 | ->getOption( $user, 'performanceinspector' ) |
24 | ) { |
25 | $out->addModuleStyles( [ 'ext.PerformanceInspector.noscript' ] ); |
26 | $out->addModules( [ 'ext.PerformanceInspector.startup' ] ); |
27 | } |
28 | } |
29 | |
30 | /** |
31 | * @param BaseTemplate $baseTemplate |
32 | * @param array &$toolbox |
33 | */ |
34 | public static function onBaseTemplateToolbox( BaseTemplate $baseTemplate, array &$toolbox ) { |
35 | $title = $baseTemplate->getSkin()->getTitle(); |
36 | $user = $baseTemplate->getSkin()->getUser(); |
37 | |
38 | if ( $title->inNamespace( NS_MAIN ) && MediaWikiServices::getInstance() |
39 | ->getUserOptionsLookup() |
40 | ->getOption( $user, 'performanceinspector' ) |
41 | ) { |
42 | $toolbox['performanceinspector'] = [ |
43 | 'text' => $baseTemplate->getMsg( 'performanceinspector-portlet-link' )->text(), |
44 | 'href' => '#', |
45 | 'id' => 't-performanceinspector' |
46 | ]; |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * Handler for the GetPreferences hook. |
52 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences |
53 | * |
54 | * @param \User $user |
55 | * @param array &$defaultPreferences |
56 | * @return bool |
57 | */ |
58 | public static function onGetPreferences( $user, &$defaultPreferences ) { |
59 | $defaultPreferences['performanceinspector'] = [ |
60 | 'type' => 'toggle', |
61 | 'label-message' => 'performanceinspector-pref-label', |
62 | 'help-message' => 'performanceinspector-pref-help', |
63 | 'section' => 'editing/developertools' |
64 | ]; |
65 | return true; |
66 | } |
67 | } |