Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
HookHandler | |
0.00% |
0 / 42 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
onSkinTemplateNavigation__Universal | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |||
onGetBetaFeaturePreferences | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
onAPIQuerySiteInfoGeneralInfo | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ReadingLists; |
4 | |
5 | use MediaWiki\Api\ApiQuerySiteinfo; |
6 | use MediaWiki\Api\Hook\APIQuerySiteInfoGeneralInfoHook; |
7 | use MediaWiki\Extension\BetaFeatures\BetaFeatures; |
8 | use MediaWiki\Hook\SkinTemplateNavigation__UniversalHook; |
9 | use MediaWiki\MainConfigNames; |
10 | use MediaWiki\MediaWikiServices; |
11 | use MediaWiki\Registration\ExtensionRegistry; |
12 | use MediaWiki\Skin\SkinTemplate; |
13 | use MediaWiki\SpecialPage\SpecialPage; |
14 | use MediaWiki\User\User; |
15 | |
16 | /** |
17 | * Static entry points for hooks. |
18 | */ |
19 | class HookHandler implements APIQuerySiteInfoGeneralInfoHook, SkinTemplateNavigation__UniversalHook { |
20 | /** |
21 | * Handler for SkinTemplateNavigation::Universal hook. |
22 | * Adds "Notifications" items to the notifications content navigation. |
23 | * SkinTemplate automatically merges these into the personal tools for older skins. |
24 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation::Universal |
25 | * @param SkinTemplate $skinTemplate |
26 | * @param array &$links Array of URLs to append to. |
27 | */ |
28 | public function onSkinTemplateNavigation__Universal( $skinTemplate, &$links ): void { |
29 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
30 | if ( |
31 | $config->get( 'ReadingListBetaFeature' ) && |
32 | ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && |
33 | // @phan-suppress-next-line PhanUndeclaredClassMethod BetaFeatures is not necessarily installed. |
34 | BetaFeatures::isFeatureEnabled( $skinTemplate->getUser(), Constants::PREF_KEY_BETA_FEATURES ) |
35 | ) { |
36 | $out = $skinTemplate->getOutput(); |
37 | $out->addModuleStyles( 'readinglist.page.styles' ); |
38 | $out->addModules( 'readinglist.page.scripts' ); |
39 | $rlUrl = SpecialPage::getTitleFor( |
40 | 'ReadingLists' |
41 | )->getLinkURL(); |
42 | $userMenu = $links['user-menu'] ?? []; |
43 | $links['actions']['readinglists-bookmark'] = [ |
44 | 'class' => 'reading-list-bookmark', |
45 | 'href' => $rlUrl, |
46 | 'icon' => 'bookmark', |
47 | ]; |
48 | $links['user-menu'] = wfArrayInsertAfter( $userMenu, [ |
49 | // The following messages are generated upstream |
50 | // * tooltip-pt-betafeatures |
51 | 'readinglist' => [ |
52 | 'text' => wfMessage( 'readinglists-menu-item' )->text(), |
53 | 'href' => $rlUrl, |
54 | 'icon' => 'bookmark', |
55 | ], |
56 | ], 'watchlist' ); |
57 | } |
58 | } |
59 | |
60 | /** |
61 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences |
62 | * |
63 | * @param User $user |
64 | * @param array[] &$prefs |
65 | */ |
66 | public static function onGetBetaFeaturePreferences( $user, array &$prefs ) { |
67 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
68 | if ( $config->get( 'ReadingListBetaFeature' ) ) { |
69 | $path = $config->get( MainConfigNames::ExtensionAssetsPath ); |
70 | $prefs[Constants::PREF_KEY_BETA_FEATURES] = [ |
71 | 'label-message' => 'readinglists-beta-feature-name', |
72 | 'desc-message' => 'readinglists-beta-feature-description', |
73 | 'screenshot' => "$path/ReadingLists/resources/beta.png", |
74 | 'info-link' |
75 | => 'https://www.mediawiki.org/wiki/Extension:ReadingLists/Beta_Feature', |
76 | 'discussion-link' |
77 | => 'https://www.mediawiki.org/wiki/Extension_talk:ReadingLists/Beta_Feature', |
78 | ]; |
79 | } |
80 | } |
81 | |
82 | /** |
83 | * Add configuration data to the siteinfo API output. |
84 | * Used by the RESTBase proxy for help messages in the Swagger doc. |
85 | * @param ApiQuerySiteinfo $module |
86 | * @param array &$result |
87 | */ |
88 | public function onAPIQuerySiteInfoGeneralInfo( $module, &$result ) { |
89 | global $wgReadingListsMaxListsPerUser, $wgReadingListsMaxEntriesPerList, |
90 | $wgReadingListsDeletedRetentionDays; |
91 | $result['readinglists-config'] = [ |
92 | 'maxListsPerUser' => $wgReadingListsMaxListsPerUser, |
93 | 'maxEntriesPerList' => $wgReadingListsMaxEntriesPerList, |
94 | 'deletedRetentionDays' => $wgReadingListsDeletedRetentionDays, |
95 | ]; |
96 | } |
97 | } |