Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| RevisionSelectQueryBuilder | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| joinUser | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| joinPage | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| joinComment | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Revision; |
| 8 | |
| 9 | use Wikimedia\Rdbms\IReadableDatabase; |
| 10 | use Wikimedia\Rdbms\SelectQueryBuilder; |
| 11 | |
| 12 | /** |
| 13 | * Help and centralize querying revision table. |
| 14 | * |
| 15 | * @since 1.41 |
| 16 | */ |
| 17 | class RevisionSelectQueryBuilder extends SelectQueryBuilder { |
| 18 | |
| 19 | /** |
| 20 | * @internal use RevisionStore::newSelectQueryBuilder() instead. |
| 21 | * @param IReadableDatabase $db |
| 22 | */ |
| 23 | public function __construct( IReadableDatabase $db ) { |
| 24 | parent::__construct( $db ); |
| 25 | |
| 26 | $this->select( [ |
| 27 | 'rev_id', |
| 28 | 'rev_page', |
| 29 | 'rev_timestamp', |
| 30 | 'rev_minor_edit', |
| 31 | 'rev_deleted', |
| 32 | 'rev_len', |
| 33 | 'rev_parent_id', |
| 34 | 'rev_user' => 'actor_rev_user.actor_user', |
| 35 | 'rev_user_text' => 'actor_rev_user.actor_name', |
| 36 | 'rev_actor' => 'rev_actor' |
| 37 | ] ) |
| 38 | ->from( 'revision' ) |
| 39 | ->join( 'actor', 'actor_rev_user', 'actor_rev_user.actor_id = rev_actor' ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Join the query with user table and add user_name field. |
| 44 | * |
| 45 | * @return $this |
| 46 | */ |
| 47 | public function joinUser() { |
| 48 | $this->field( 'user_name' ) |
| 49 | ->leftJoin( |
| 50 | 'user', |
| 51 | null, |
| 52 | [ $this->db->expr( 'actor_rev_user.actor_user', '!=', 0 ), "user_id = actor_rev_user.actor_user" ] |
| 53 | ); |
| 54 | |
| 55 | return $this; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Join the query with page table and several fields to allow easier query. |
| 60 | * |
| 61 | * @return $this |
| 62 | */ |
| 63 | public function joinPage() { |
| 64 | $this->fields( [ |
| 65 | 'page_namespace', |
| 66 | 'page_title', |
| 67 | 'page_id', |
| 68 | 'page_latest', |
| 69 | 'page_is_redirect', |
| 70 | 'page_len', |
| 71 | ] ) |
| 72 | ->join( 'page', null, 'page_id = rev_page' ); |
| 73 | |
| 74 | return $this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Join the query with comment table and several fields to allow easier query. |
| 79 | * |
| 80 | * @return $this |
| 81 | */ |
| 82 | public function joinComment() { |
| 83 | $this->fields( [ |
| 84 | 'rev_comment_text' => 'comment_rev_comment.comment_text', |
| 85 | 'rev_comment_data' => 'comment_rev_comment.comment_data', |
| 86 | 'rev_comment_cid' => 'comment_rev_comment.comment_id', |
| 87 | ] ); |
| 88 | $this->join( 'comment', "comment_rev_comment", 'comment_rev_comment.comment_id = rev_comment_id' ); |
| 89 | return $this; |
| 90 | } |
| 91 | } |