MediaWiki master
RevisionSelectQueryBuilder.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Revision;
22
25
32
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
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
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
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}
Help and centralize querying revision table.
joinUser()
Join the query with user table and add user_name field.
joinPage()
Join the query with page table and several fields to allow easier query.
joinComment()
Join the query with comment table and several fields to allow easier query.
join( $table, $alias=null, $conds=[])
Inner join a table or group of tables.
Build SELECT queries with a fluent interface.
IReadableDatabase IReadableDatabase $db
select( $fields)
Add a field or an array of fields to the query.
field( $field, $alias=null)
Add a single field to the query, optionally with an alias.
fields( $fields)
Add a field or an array of fields to the query.
A database connection without write operations.