Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodeCommentsTablePager
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 7
240
0.00% covered (danger)
0.00%
0 / 1
 isFieldSortable
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDefaultSort
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 getCountQuery
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getFieldNames
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 formatValue
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
56
 getTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CodeReview\UI;
4
5use Exception;
6use Linker;
7use SpecialPage;
8use User;
9
10/**
11 * Pager for CodeCommentsListView
12 */
13class CodeCommentsTablePager extends SvnTablePager {
14    public function isFieldSortable( $field ) {
15        return $field == 'cr_timestamp';
16    }
17
18    public function getDefaultSort() {
19        return 'cc_timestamp';
20    }
21
22    public function getQueryInfo() {
23        $query = [
24            'tables' => [ 'code_comment', 'code_rev' ],
25            'fields' => array_keys( $this->getFieldNames() ),
26            'conds' => [ 'cc_repo_id' => $this->mRepo->getId() ],
27            'join_conds' => [
28                'code_rev' => [ 'LEFT JOIN', 'cc_repo_id = cr_repo_id AND cc_rev_id = cr_id' ]
29            ],
30            'options' => [],
31        ];
32
33        if ( count( $this->mView->mPath ) ) {
34            $query['tables'][] = 'code_paths';
35            $query['join_conds']['code_paths'] = [ 'INNER JOIN',
36                'cc_repo_id = cp_repo_id AND cc_rev_id = cp_rev_id' ];
37            $query['conds']['cp_path'] = $this->mView->mPath;
38        }
39        if ( $this->mView->mAuthor ) {
40            $query['conds']['cc_user_text'] = User::newFromName( $this->mView->mAuthor )->getName();
41        }
42
43        return $query;
44    }
45
46    public function getCountQuery() {
47        $query = $this->getQueryInfo();
48
49        $query['fields'] = [ 'COUNT( DISTINCT cc_id ) AS rev_count' ];
50        unset( $query['options']['GROUP BY'] );
51        return $query;
52    }
53
54    public function getFieldNames() {
55        return [
56            'cc_timestamp' => $this->msg( 'code-field-timestamp' )->text(),
57            'cc_user_text' => $this->msg( 'code-field-user' )->text(),
58            'cc_rev_id' => $this->msg( 'code-field-id' )->text(),
59            'cr_status' => $this->msg( 'code-field-status' )->text(),
60            'cr_message' => $this->msg( 'code-field-message' )->text(),
61            'cc_text' => $this->msg( 'code-field-text' )->text()
62        ];
63    }
64
65    public function formatValue( $name, $value ) {
66        $linkRenderer = \MediaWiki\MediaWikiServices::getInstance()->getLinkRenderer();
67        switch ( $name ) {
68        case 'cc_rev_id':
69            return $linkRenderer->makeLink(
70                SpecialPage::getSafeTitleFor( 'Code',
71                    $this->mRepo->getName() . '/' . $value . '#code-comments' ),
72                $value
73            );
74        case 'cr_status':
75            return $linkRenderer->makeLink(
76                SpecialPage::getTitleFor( 'Code',
77                    $this->mRepo->getName() . '/status/' . $value ),
78                $this->mView->statusDesc( $value )
79            );
80        case 'cc_user_text':
81            return Linker::userLink( -1, $value );
82        case 'cr_message':
83            return $this->mView->messageFragment( $value );
84        case 'cc_text':
85            return $this->mView->messageFragment( $value );
86        case 'cc_timestamp':
87            return $this->getLanguage()->timeanddate( $value, true );
88        }
89
90        throw new Exception( '$name is invalid input.' );
91    }
92
93    public function getTitle() {
94        return SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/comments' );
95    }
96}