Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
addModules | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
onApiParseMakeOutputPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onBeforePageDisplay | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onGetPreferences | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Some hooks for TocTree extension. |
5 | */ |
6 | |
7 | namespace MediaWiki\Extension\TocTree; |
8 | |
9 | use MediaWiki\Api\ApiBase; |
10 | use MediaWiki\Api\Hook\ApiParseMakeOutputPageHook; |
11 | use MediaWiki\Output\Hook\BeforePageDisplayHook; |
12 | use MediaWiki\Output\OutputPage; |
13 | use MediaWiki\Preferences\Hook\GetPreferencesHook; |
14 | use MediaWiki\User\User; |
15 | use Skin; |
16 | |
17 | class Hooks implements |
18 | ApiParseMakeOutputPageHook, |
19 | BeforePageDisplayHook, |
20 | GetPreferencesHook |
21 | { |
22 | /** |
23 | * @param OutputPage $out |
24 | */ |
25 | private function addModules( OutputPage $out ) { |
26 | if ( $out->isTOCEnabled() ) { |
27 | $out->addModules( 'ext.toctree' ); |
28 | } |
29 | } |
30 | |
31 | /** |
32 | * Hook: ApiParseMakeOutputPage |
33 | * |
34 | * @param ApiBase $module ApiBase object |
35 | * @param OutputPage $out OutputPage object |
36 | * @return bool|void True or no return value to continue or false to abort |
37 | */ |
38 | public function onApiParseMakeOutputPage( $module, $out ) { |
39 | $this->addModules( $out ); |
40 | } |
41 | |
42 | /** |
43 | * Hook: BeforePageDisplay |
44 | * |
45 | * @param OutputPage $out OutputPage object |
46 | * @param Skin $skin Skin object |
47 | */ |
48 | public function onBeforePageDisplay( $out, $skin ): void { |
49 | $this->addModules( $out ); |
50 | } |
51 | |
52 | /** |
53 | * Hook: GetPreferences |
54 | * |
55 | * @param User $user User whose preferences are being modified |
56 | * @param array &$preferences Preferences description array |
57 | */ |
58 | public function onGetPreferences( $user, &$preferences ) { |
59 | $preferences['toc-expand'] = [ |
60 | 'type' => 'toggle', |
61 | 'label-message' => 'toctree-tog-expand', |
62 | 'section' => 'misc/toctree', |
63 | ]; |
64 | |
65 | $preferences['toc-floated'] = [ |
66 | 'type' => 'toggle', |
67 | 'label-message' => 'toctree-tog-floated', |
68 | 'section' => 'misc/toctree', |
69 | ]; |
70 | } |
71 | } |