Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
SvnRevTablePager
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 9
812
0.00% covered (danger)
0.00%
0 / 1
 getSVNPath
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
6
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
 getCountQuery
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getSelectFields
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getFieldNames
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 formatValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 formatRevValue
0.00% covered (danger)
0.00%
0 / 47
0.00% covered (danger)
0.00%
0 / 1
240
 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 SpecialPage;
6use Title;
7use Xml;
8
9/**
10 * Pager for CodeRevisionListView
11 */
12class SvnRevTablePager extends SvnTablePager {
13    public function getSVNPath() {
14        return $this->mView->mPath;
15    }
16
17    public function getDefaultSort() {
18        return count( $this->mView->mPath ) ? 'cp_rev_id' : 'cr_id';
19    }
20
21    public function getQueryInfo() {
22        $defaultSort = $this->getDefaultSort();
23        // Path-based query...
24        if ( $defaultSort === 'cp_rev_id' ) {
25            $query = [
26                'tables' => [ 'code_paths', 'code_rev', 'code_comment' ],
27                'fields' => $this->getSelectFields(),
28                'conds' => [
29                    'cp_repo_id' => $this->mRepo->getId(),
30                    'cp_path' => $this->getSVNPath(),
31                ],
32                'options' => [
33                    'GROUP BY' =>
34                        $defaultSort . ', cr_id, cr_repo_id, cr_status, cr_path, cr_message, cr_author, cr_timestamp',
35                    'USE INDEX' => [ 'code_path' => 'cp_repo_id' ]
36                ],
37                'join_conds' => [
38                    'code_rev' => [ 'INNER JOIN',
39                        'cr_repo_id = cp_repo_id AND cr_id = cp_rev_id' ],
40                    'code_comment' => [ 'LEFT JOIN',
41                        'cc_repo_id = cp_repo_id AND cc_rev_id = cp_rev_id' ],
42                ]
43            ];
44        // No path; entire repo...
45        } else {
46            $query = [
47                'tables' => [ 'code_rev', 'code_comment' ],
48                'fields' => $this->getSelectFields(),
49                'conds' => [ 'cr_repo_id' => $this->mRepo->getId() ],
50                'options' => [
51                    'GROUP BY' => $defaultSort . ', cr_repo_id, cr_status, cr_path, cr_message, cr_author, cr_timestamp'
52                ],
53                'join_conds' => [
54                    'code_comment' => [ 'LEFT JOIN',
55                        'cc_repo_id = cr_repo_id AND cc_rev_id = cr_id' ],
56                ]
57            ];
58        }
59
60        if ( $this->mView->mAuthor ) {
61            $query['conds']['cr_author'] = $this->mView->mAuthor;
62        }
63
64        if ( $this->mView->mStatus ) {
65            $query['conds']['cr_status'] = $this->mView->mStatus;
66        }
67        return $query;
68    }
69
70    public function getCountQuery() {
71        $query = $this->getQueryInfo();
72
73        $query['fields'] = [ 'COUNT( DISTINCT cr_id ) AS rev_count' ];
74        unset( $query['options']['GROUP BY'] );
75        return $query;
76    }
77
78    public function getSelectFields() {
79        return array_unique(
80            [
81                $this->getDefaultSort(),
82                'cr_id',
83                'cr_repo_id',
84                'cr_status',
85                'COUNT(DISTINCT cc_id) AS comments',
86                'cr_path',
87                'cr_message',
88                'cr_author',
89                'cr_timestamp'
90            ]
91        );
92    }
93
94    public function getFieldNames() {
95        $fields = [
96            'cr_id' => $this->msg( 'code-field-id' )->text(),
97            'cr_status' => $this->msg( 'code-field-status' )->text(),
98            'comments' => $this->msg( 'code-field-comments' )->text(),
99            'cr_path' => $this->msg( 'code-field-path' )->text(),
100            'cr_message' => $this->msg( 'code-field-message' )->text(),
101            'cr_author' => $this->msg( 'code-field-author' )->text(),
102            'cr_timestamp' => $this->msg( 'code-field-timestamp' )->text()
103        ];
104        # Only show checkboxen as needed
105        if ( $this->mView->batchForm ) {
106            $fields = [ 'selectforchange' => $this->msg( 'code-field-select' )->text() ] + $fields;
107        }
108        return $fields;
109    }
110
111    public function formatValue( $name, $value ) {
112        // unused
113    }
114
115    public function formatRevValue( $name, $value, $row ) {
116        $pathQuery = count( $this->mView->mPath )
117            ? [ 'path' => $this->mView->getPathsAsString() ] : [];
118
119        $linkRenderer = \MediaWiki\MediaWikiServices::getInstance()->getLinkRenderer();
120        switch ( $name ) {
121        case 'selectforchange':
122            $sort = $this->getDefaultSort();
123            return Xml::check( "wpRevisionSelected[]", false, [ 'value' => $row->$sort ] );
124        case 'cr_id':
125            return $linkRenderer->makeLink(
126                SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/' . $value ),
127                $value,
128                [],
129                []
130            );
131        case 'cr_status':
132            $options = $pathQuery;
133            if ( $this->mView->mAuthor ) {
134                $options['author'] = $this->mView->mAuthor;
135            }
136            $options['status'] = $value;
137            return $linkRenderer->makeLink(
138                SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() ),
139                $this->mView->statusDesc( $value ),
140                [],
141                $options
142            );
143        case 'cr_author':
144            $options = $pathQuery;
145            if ( $this->mView->mStatus ) {
146                $options['status'] = $this->mView->mStatus;
147            }
148            $options['author'] = $value;
149            return $linkRenderer->makeLink(
150                SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() ),
151                $value,
152                [],
153                $options
154            );
155        case 'cr_message':
156            return $this->mView->messageFragment( $value );
157        case 'cr_timestamp':
158            return $this->getLanguage()->timeanddate( $value, true );
159        case 'comments':
160            if ( $value ) {
161                $special = SpecialPage::getTitleFor(
162                    'Code',
163                    $this->mRepo->getName() . '/' . $row->{$this->getDefaultSort()},
164                    'code-comments'
165                );
166                return $linkRenderer->makeLink(
167                    $special, $this->getLanguage()->formatNum( $value ) );
168            } else {
169                return '-';
170            }
171        case 'cr_path':
172            $title = $this->mRepo->getName();
173
174            $options = [ 'path' => (string)$value ];
175            if ( $this->mView->mAuthor ) {
176                $options['author'] = $this->mView->mAuthor;
177            }
178            if ( $this->mView->mStatus ) {
179                $options['status'] = $this->mView->mStatus;
180            }
181
182            return Xml::openElement( 'div', [ 'title' => (string)$value, 'dir' => 'ltr' ] ) .
183                $linkRenderer->makeLink(
184                    SpecialPage::getTitleFor( 'Code', $title ),
185                    $this->getLanguage()->truncateForVisual( (string)$value, 50 ),
186                    [ 'title' => (string)$value ],
187                    $options
188                ) . '</div>';
189        }
190
191        return '';
192    }
193
194    /**
195     * @return Title
196     */
197    public function getTitle() {
198        return SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() );
199    }
200}