Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
LqtNewMessagesPager | |
0.00% |
0 / 44 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getThreads | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |||
getQueryInfo | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
getPageLimit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultDirections | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\User\User; |
5 | |
6 | class LqtNewMessagesPager extends LqtDiscussionPager { |
7 | /** @var User */ |
8 | private $user; |
9 | |
10 | public function __construct( $user ) { |
11 | $this->user = $user; |
12 | |
13 | parent::__construct( false, false ); |
14 | } |
15 | |
16 | /** |
17 | * Returns an array of structures. Each structure has the keys 'top' and 'posts'. |
18 | * 'top' contains the top-level thread to display. |
19 | * 'posts' contains an array of integer post IDs which should be highlighted. |
20 | * @return false|array |
21 | */ |
22 | public function getThreads() { |
23 | $rows = $this->getRows(); |
24 | |
25 | if ( !count( $rows ) ) { |
26 | return false; |
27 | } |
28 | |
29 | $threads = Thread::bulkLoad( $rows ); |
30 | $thread_ids = array_keys( $threads ); |
31 | $output = []; |
32 | |
33 | foreach ( $threads as $id => $thread ) { |
34 | $output[$id] = [ 'top' => $thread, 'posts' => [] ]; |
35 | } |
36 | |
37 | $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
38 | |
39 | $res = $dbr->newSelectQueryBuilder() |
40 | ->select( [ 'ums_thread', 'ums_conversation' ] ) |
41 | ->from( 'user_message_state' ) |
42 | ->where( [ |
43 | 'ums_user' => $this->user->getId(), |
44 | 'ums_conversation' => $thread_ids |
45 | ] ) |
46 | ->caller( __METHOD__ ) |
47 | ->fetchResultSet(); |
48 | |
49 | foreach ( $res as $row ) { |
50 | $top = $row->ums_conversation; |
51 | $thread = $row->ums_thread; |
52 | $output[$top]['posts'][] = $thread; |
53 | } |
54 | |
55 | return $output; |
56 | } |
57 | |
58 | public function getQueryInfo() { |
59 | $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
60 | |
61 | $queryInfo = [ |
62 | 'tables' => [ 'thread', 'user_message_state' ], |
63 | 'fields' => [ 'thread.*', 'ums_conversation' ], |
64 | 'conds' => [ |
65 | 'ums_user' => $this->user->getId(), |
66 | $this->mDb->expr( 'thread_type', '!=', Threads::TYPE_DELETED ), |
67 | ], |
68 | 'join_conds' => [ |
69 | 'thread' => [ 'join', 'ums_conversation=thread_id' ] |
70 | ], |
71 | 'options' => [ |
72 | 'group by' => 'ums_conversation' |
73 | ] |
74 | ]; |
75 | |
76 | return $queryInfo; |
77 | } |
78 | |
79 | public function getPageLimit() { |
80 | return 25; |
81 | } |
82 | |
83 | public function getDefaultDirections() { |
84 | return true; // Descending |
85 | } |
86 | |
87 | public function getIndexField() { |
88 | return [ 'ums_conversation' ]; |
89 | } |
90 | } |