Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
MentorQuestionPoster
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 getSectionHeaderTemplate
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 getDirectTargetTitle
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getQuestionStoragePref
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\HelpPanel\QuestionPoster;
4
5use GrowthExperiments\HomepageModules\Mentorship;
6use GrowthExperiments\Mentorship\MentorManager;
7use GrowthExperiments\WikiConfigException;
8use MediaWiki\Context\IContextSource;
9use MediaWiki\Page\WikiPageFactory;
10use MediaWiki\Permissions\PermissionManager;
11use MediaWiki\Title\TitleFactory;
12use MediaWiki\User\User;
13use UserNotLoggedIn;
14use Wikimedia\Stats\StatsFactory;
15
16/**
17 * QuestionPoster base class for asking a question from the assigned mentor.
18 */
19abstract class MentorQuestionPoster extends QuestionPoster {
20
21    /** @var MentorManager */
22    protected $mentorManager;
23
24    /**
25     * @param WikiPageFactory $wikiPageFactory
26     * @param TitleFactory $titleFactory
27     * @param MentorManager $mentorManager
28     * @param PermissionManager $permissionManager
29     * @param StatsFactory $statsFactory
30     * @param bool $confirmEditInstalled
31     * @param bool $flowInstalled
32     * @param IContextSource $context
33     * @param string $body
34     * @param string $relevantTitleRaw
35     * @throws UserNotLoggedIn
36     */
37    public function __construct(
38        WikiPageFactory $wikiPageFactory,
39        TitleFactory $titleFactory,
40        MentorManager $mentorManager,
41        PermissionManager $permissionManager,
42        StatsFactory $statsFactory,
43        bool $confirmEditInstalled,
44        bool $flowInstalled,
45        IContextSource $context,
46        $body,
47        $relevantTitleRaw = ''
48    ) {
49        $this->mentorManager = $mentorManager;
50        parent::__construct(
51            $wikiPageFactory,
52            $titleFactory,
53            $permissionManager,
54            $statsFactory,
55            $confirmEditInstalled,
56            $flowInstalled,
57            $context,
58            $body,
59            $relevantTitleRaw
60        );
61    }
62
63    /**
64     * @inheritDoc
65     */
66    protected function getSectionHeaderTemplate() {
67        return $this->getWikitextLinkTarget() ?
68            $this->getContext()
69                ->msg( 'growthexperiments-homepage-mentorship-question-subject-with-title' )
70                ->plaintextParams( $this->getContext()->getUser()->getName() )
71                ->params( $this->getWikitextLinkTarget() )
72                ->inContentLanguage()->text() :
73            $this->getContext()
74                ->msg( 'growthexperiments-homepage-mentorship-question-subject' )
75                ->plaintextParams( $this->getContext()->getUser()->getName() )
76                ->inContentLanguage()->text();
77    }
78
79    /**
80     * @inheritDoc
81     * @throws WikiConfigException If there's anything wrong with the current user's mentor
82     */
83    protected function getDirectTargetTitle() {
84        $mentor = $this->mentorManager->getEffectiveMentorForUser( $this->getContext()->getUser() );
85        return User::newFromIdentity( $mentor->getUserIdentity() )->getTalkPage();
86    }
87
88    /**
89     * @inheritDoc
90     */
91    protected function getQuestionStoragePref() {
92        return Mentorship::QUESTION_PREF;
93    }
94}