Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodeStatusChangeTablePager
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 6
306
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
 getFieldNames
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 formatValue
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
110
 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 CodeRevisionListView
12 */
13class CodeStatusChangeTablePager extends SvnTablePager {
14
15    public function isFieldSortable( $field ) {
16        return $field == 'cpc_timestamp';
17    }
18
19    public function getDefaultSort() {
20        return 'cpc_timestamp';
21    }
22
23    public function getQueryInfo() {
24        $query = [
25            'tables' => [ 'code_prop_changes', 'code_rev' ],
26            'fields' => array_keys( $this->getFieldNames() ),
27            'conds' => [ 'cpc_repo_id' => $this->mRepo->getId(), 'cpc_attrib' => 'status' ],
28            'join_conds' => [
29                'code_rev' => [ 'LEFT JOIN', 'cpc_repo_id = cr_repo_id AND cpc_rev_id = cr_id' ]
30            ],
31            'options' => [],
32        ];
33
34        if ( count( $this->mView->mPath ) ) {
35            $query['tables'][] = 'code_paths';
36            $query['join_conds']['code_paths'] = [
37                'INNER JOIN', 'cpc_repo_id = cp_repo_id AND cpc_rev_id = cp_rev_id'
38            ];
39            $query['conds']['cp_path'] = $this->mView->mPath;
40        }
41        if ( $this->mView->mAuthor ) {
42            $query['conds']['cpc_user_text'] = User::newFromName( $this->mView->mAuthor )->getName();
43        }
44
45        return $query;
46    }
47
48    public function getFieldNames() {
49        return [
50            'cpc_timestamp' => $this->msg( 'code-field-timestamp' )->text(),
51            'cpc_user_text' => $this->msg( 'code-field-user' )->text(),
52            'cpc_rev_id' => $this->msg( 'code-field-id' )->text(),
53            'cr_author' => $this->msg( 'code-field-author' )->text(),
54            'cr_message' => $this->msg( 'code-field-message' )->text(),
55            'cpc_removed' => $this->msg( 'code-old-status' )->text(),
56            'cpc_added' => $this->msg( 'code-new-status' )->text(),
57            'cr_status' => $this->msg( 'code-field-status' )->text(),
58        ];
59    }
60
61    public function formatValue( $name, $value ) {
62        $linkRenderer = \MediaWiki\MediaWikiServices::getInstance()->getLinkRenderer();
63        // Give grep a chance to find the usages:
64        // code-status-new, code-status-fixme, code-status-reverted, code-status-resolved,
65        // code-status-ok, code-status-deferred, code-status-old
66        switch ( $name ) {
67        case 'cpc_rev_id':
68            return $linkRenderer->makeLink(
69                SpecialPage::getTitleFor( 'Code',
70                    $this->mRepo->getName() . '/' . $value . '#code-changes' ),
71                $value
72            );
73        case 'cr_author':
74            return $this->mView->authorLink( $value );
75        case 'cr_message':
76            return $this->mView->messageFragment( $value );
77        case 'cr_status':
78            return $linkRenderer->makeLink(
79                SpecialPage::getTitleFor( 'Code',
80                    $this->mRepo->getName() . '/status/' . $value ),
81                $this->mView->statusDesc( $value ) );
82        case 'cpc_user_text':
83            return Linker::userLink( -1, $value );
84        case 'cpc_removed':
85            return $this->msg( $value ? "code-status-$value" : 'code-status-new' )->escaped();
86        case 'cpc_added':
87            return $this->msg( "code-status-$value" )->escaped();
88        case 'cpc_timestamp':
89            return $this->getLanguage()->timeanddate( $value, true );
90        }
91
92        throw new Exception( '$name is invalid input.' );
93    }
94
95    public function getTitle() {
96        return SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/statuschanges' );
97    }
98}