Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
MentorDashboardHooks
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 onGetPreferences
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 onUserGetDefaultOptions
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 onResourceLoaderExcludeUserOptions
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getTagsToFilterBy
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\MentorDashboard;
4
5use ChangeTags;
6use GrowthExperiments\HomepageModules\Mentorship;
7use GrowthExperiments\MentorDashboard\MenteeOverview\MenteeOverviewDataUpdater;
8use GrowthExperiments\MentorDashboard\MenteeOverview\StarredMenteesStore;
9use GrowthExperiments\MentorDashboard\Modules\MenteeOverview;
10use MediaWiki\Json\FormatJson;
11use MediaWiki\Preferences\Hook\GetPreferencesHook;
12use MediaWiki\ResourceLoader\Context;
13use MediaWiki\ResourceLoader\Hook\ResourceLoaderExcludeUserOptionsHook;
14use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
15
16class MentorDashboardHooks implements
17    GetPreferencesHook,
18    UserGetDefaultOptionsHook,
19    ResourceLoaderExcludeUserOptionsHook
20{
21    /**
22     * @inheritDoc
23     */
24    public function onGetPreferences( $user, &$preferences ) {
25        $preferences[ StarredMenteesStore::STARRED_MENTEES_PREFERENCE ] = [
26            'type' => 'api',
27        ];
28        $preferences[ MentorDashboardDiscoveryHooks::MENTOR_DASHBOARD_SEEN_PREF ] = [
29            'type' => 'api',
30        ];
31        $preferences[ MenteeOverviewDataUpdater::LAST_UPDATE_PREFERENCE ] = [
32            'type' => 'api',
33        ];
34        $preferences[ MenteeOverview::PRESETS_PREF ] = [
35            'type' => 'api',
36        ];
37    }
38
39    /**
40     * @inheritDoc
41     */
42    public function onUserGetDefaultOptions( &$defaultOptions ) {
43        // This is here to make use of the constant
44        $defaultOptions += [
45            StarredMenteesStore::STARRED_MENTEES_PREFERENCE => '',
46            MentorDashboardDiscoveryHooks::MENTOR_DASHBOARD_SEEN_PREF => 0,
47            MenteeOverviewDataUpdater::LAST_UPDATE_PREFERENCE => null,
48            MenteeOverview::PRESETS_PREF => FormatJson::encode( [
49                'usersToShow' => 10,
50                'filters' => [
51                    'minedits' => 1,
52                    'maxedits' => 500,
53                ]
54            ] ),
55        ];
56    }
57
58    /** @inheritDoc */
59    public function onResourceLoaderExcludeUserOptions(
60        array &$keysToExclude,
61        Context $context
62    ): void {
63        $keysToExclude = array_merge( $keysToExclude, [
64            StarredMenteesStore::STARRED_MENTEES_PREFERENCE,
65            MentorDashboardDiscoveryHooks::MENTOR_DASHBOARD_SEEN_PREF,
66            MenteeOverviewDataUpdater::LAST_UPDATE_PREFERENCE,
67        ] );
68    }
69
70    /**
71     * Tags mentee overview module uses to filter edits made by mentees
72     *
73     * @param Context $context
74     * @return array[]
75     */
76    public static function getTagsToFilterBy( Context $context ) {
77        return [
78            'reverted' => [ ChangeTags::TAG_REVERTED ],
79            'questions' => [
80                Mentorship::MENTORSHIP_HELPPANEL_QUESTION_TAG,
81                Mentorship::MENTORSHIP_MODULE_QUESTION_TAG
82            ]
83        ];
84    }
85}