Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
RevisionSelectQueryBuilder
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
 joinUser
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 joinPage
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 joinComment
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Revision;
22
23use Wikimedia\Rdbms\IReadableDatabase;
24use Wikimedia\Rdbms\SelectQueryBuilder;
25
26/**
27 * Help and centralize querying revision table.
28 *
29 * @since 1.41
30 */
31class RevisionSelectQueryBuilder extends SelectQueryBuilder {
32
33    /**
34     * @internal use RevisionStore::newSelectQueryBuilder() instead.
35     * @param IReadableDatabase $db
36     */
37    public function __construct( IReadableDatabase $db ) {
38        parent::__construct( $db );
39
40        $this->select( [
41            'rev_id',
42            'rev_page',
43            'rev_timestamp',
44            'rev_minor_edit',
45            'rev_deleted',
46            'rev_len',
47            'rev_parent_id',
48            'rev_sha1',
49            'rev_user' => 'actor_rev_user.actor_user',
50            'rev_user_text' => 'actor_rev_user.actor_name',
51            'rev_actor' => 'rev_actor'
52        ] )
53            ->from( 'revision' )
54            ->join( 'actor', 'actor_rev_user', 'actor_rev_user.actor_id = rev_actor' );
55    }
56
57    /**
58     * Join the query with user table and add user_name field.
59     *
60     * @return $this
61     */
62    public function joinUser() {
63        $this->field( 'user_name' )
64            ->leftJoin(
65                'user',
66                null,
67                [ "actor_rev_user.actor_user != 0", "user_id = actor_rev_user.actor_user" ]
68            );
69
70        return $this;
71    }
72
73    /**
74     * Join the query with page table and several fields to allow easier query.
75     *
76     * @return $this
77     */
78    public function joinPage() {
79        $this->fields( [
80            'page_namespace',
81            'page_title',
82            'page_id',
83            'page_latest',
84            'page_is_redirect',
85            'page_len',
86        ] )
87        ->join( 'page', null, 'page_id = rev_page' );
88
89        return $this;
90    }
91
92    /**
93     * Join the query with comment table and several fields to allow easier query.
94     *
95     * @return $this
96     */
97    public function joinComment() {
98        $this->fields( [
99            'rev_comment_text' => 'comment_rev_comment.comment_text',
100            'rev_comment_data' => 'comment_rev_comment.comment_data',
101            'rev_comment_cid' => 'comment_rev_comment.comment_id',
102        ] );
103        $this->join( 'comment', "comment_rev_comment", 'comment_rev_comment.comment_id = rev_comment_id' );
104        return $this;
105    }
106}