Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 81
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialNewcomerTasksInfo
0.00% covered (danger)
0.00%
0 / 81
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3namespace GrowthExperiments\Specials;
4
5use GrowthExperiments\NewcomerTasks\NewcomerTasksInfo;
6use MediaWiki\SpecialPage\SpecialPage;
7use OOUI\Tag;
8
9class SpecialNewcomerTasksInfo extends SpecialPage {
10
11    /** @var NewcomerTasksInfo */
12    private $cachedSuggestionsInfo;
13
14    /**
15     * @param NewcomerTasksInfo $cachedSuggestionsInfo
16     */
17    public function __construct( NewcomerTasksInfo $cachedSuggestionsInfo ) {
18        parent::__construct( 'NewcomerTasksInfo' );
19        $this->cachedSuggestionsInfo = $cachedSuggestionsInfo;
20    }
21
22    /** @inheritDoc */
23    protected function getGroupName() {
24        return 'growth-tools';
25    }
26
27    /** @inheritDoc */
28    public function execute( $subPage ) {
29        parent::execute( $subPage );
30        $this->addHelpLink( 'mw:Growth/Personalized_first_day/Newcomer_tasks' );
31        $info = $this->cachedSuggestionsInfo->getInfo();
32        $out = $this->getOutput();
33        $out->addWikiMsg( 'newcomertasksinfo-config-form-info' );
34        if ( !isset( $info['tasks'] ) || !isset( $info[ 'topics' ] ) ) {
35            $out->addHTML(
36                ( new Tag( 'p' ) )
37                    ->addClasses( [ 'error' ] )
38                    ->appendContent( $out->msg( 'newcomertasksinfo-no-data' )->text() )
39            );
40            return;
41        }
42        $taskTypeTableRows = [];
43        foreach ( $info['tasks'] as $taskTypeId => $taskTypeData ) {
44            $taskTypeTableRows[] = ( new Tag( 'tr' ) )->appendContent(
45                ( new Tag( 'td' ) )->appendContent(
46                    $out->msg( 'growthexperiments-homepage-suggestededits-tasktype-name-' . $taskTypeId )->text()
47                ),
48                ( new Tag( 'td' ) )->appendContent( ( new Tag( 'code' ) )->appendContent( $taskTypeId ) ),
49                ( new Tag( 'td' ) )->appendContent(
50                    $out->msg( 'newcomertasksinfo-task-count' )
51                        ->numParams( $taskTypeData['totalCount'] )
52                        ->text() )
53            );
54        }
55        $taskTypeTableRows[] = ( new Tag( 'tr' ) )->appendContent(
56            ( new Tag( 'td' ) ),
57            ( new Tag( 'td' ) ),
58            ( new Tag( 'td' ) )->appendContent(
59                $out->msg( 'newcomertasksinfo-task-count' )
60                    ->numParams( $info['totalCount'] )
61                    ->text()
62            )
63        );
64        $taskTypeTable = ( new Tag( 'table' ) )->addClasses( [ 'wikitable' ] )
65            ->appendContent( ( new Tag( 'thead' ) )->appendContent(
66                ( new Tag( 'th' ) )->appendContent( $out->msg( 'newcomertasksinfo-table-header-task-type' )->text() ),
67                ( new Tag( 'th' ) )->appendContent(
68                    $out->msg( 'newcomertasksinfo-table-header-task-type-id' )->text()
69                ),
70                ( new Tag( 'th' ) )->appendContent(
71                    $out->msg( 'newcomertasksinfo-table-header-task-count' )->text()
72                )
73            ) )
74            ->appendContent( ( new Tag( 'tbody' ) )->appendContent( $taskTypeTableRows ) );
75
76        $out->addHTML( $taskTypeTable );
77
78        $topicsTableHeaders = [
79            ( new Tag( 'th' ) )->appendContent( $out->msg( 'newcomertasksinfo-table-header-topic-type' )->text() )
80        ];
81        foreach ( array_keys( $info['tasks'] ) as $taskTypeId ) {
82            $topicsTableHeaders[] = ( new Tag( 'th' ) )->appendContent( $taskTypeId );
83        }
84        $topicsTableHeaders[] = ( new Tag( 'th' ) )->appendContent(
85            $out->msg( 'newcomertasksinfo-table-header-task-count' )->text()
86        );
87
88        $topicsTableRows = [];
89        foreach ( $info['topics'] as $topicId => $topicData ) {
90            $topicsTableRowData = [
91                ( new Tag( 'td' ) )->appendContent( ( new Tag( 'code' ) )->appendContent( $topicId ) )
92            ];
93            foreach ( array_keys( $info['tasks'] ) as $taskTypeId ) {
94                $topicsTableRowData[] = ( new Tag( 'td' ) )->appendContent(
95                    $out->msg( 'newcomertasksinfo-task-count' )
96                    ->numParams( $topicData['tasks'][$taskTypeId] )
97                    ->text()
98                );
99            }
100            $topicsTableRowData[] = ( new Tag( 'td' ) )->appendContent(
101                $out->msg( 'newcomertasksinfo-task-count' )
102                ->numParams( $topicData['totalCount'] )
103                ->text()
104            );
105            $topicsTableRows[] = ( new Tag( 'tr' ) )->appendContent(
106                $topicsTableRowData
107            );
108        }
109        $topicsTable = ( new Tag( 'table' ) )->addClasses( [ 'wikitable' ] )
110            ->appendContent( ( new Tag( 'thead' ) )->appendContent(
111                $topicsTableHeaders
112            ) )
113            ->appendContent( ( new Tag( 'tbody' ) )->appendContent( $topicsTableRows ) );
114
115        $out->addHTML( $topicsTable );
116    }
117}