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