Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
NotificationPager | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
formatRow | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |||
getNotifications | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Special; |
4 | |
5 | use IContextSource; |
6 | use LogicException; |
7 | use MediaWiki\Extension\Notifications\DbFactory; |
8 | use MediaWiki\Extension\Notifications\Model\Notification; |
9 | use MediaWiki\Extension\Notifications\Services; |
10 | use MediaWiki\Pager\ReverseChronologicalPager; |
11 | |
12 | /** |
13 | * This pager is used by Special:Notifications (NO-JS). |
14 | * The heavy-lifting is done by IndexPager (grand-parent to this class). |
15 | * It paginates on notification_event for a specific user, only for the enabled event types. |
16 | */ |
17 | class NotificationPager extends ReverseChronologicalPager { |
18 | /** |
19 | * @param IContextSource $context |
20 | */ |
21 | public function __construct( IContextSource $context ) { |
22 | $dbFactory = DbFactory::newFromDefault(); |
23 | $this->mDb = $dbFactory->getEchoDb( DB_REPLICA ); |
24 | |
25 | parent::__construct( $context ); |
26 | } |
27 | |
28 | public function formatRow( $row ) { |
29 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation |
30 | throw new LogicException( "This pager does not support row formatting. " . |
31 | "Use 'getNotifications()' to get a list of Notification objects." ); |
32 | } |
33 | |
34 | public function getQueryInfo() { |
35 | $attributeManager = Services::getInstance()->getAttributeManager(); |
36 | $eventTypes = $attributeManager->getUserEnabledEvents( $this->getUser(), 'web' ); |
37 | |
38 | return [ |
39 | 'tables' => [ 'echo_notification', 'echo_event' ], |
40 | 'fields' => Notification::selectFields(), |
41 | 'conds' => [ |
42 | 'notification_user' => $this->getUser()->getId(), |
43 | 'event_type' => $eventTypes, |
44 | 'event_deleted' => 0, |
45 | ], |
46 | 'options' => [], |
47 | 'join_conds' => |
48 | [ 'echo_event' => |
49 | [ |
50 | 'JOIN', |
51 | 'notification_event=event_id', |
52 | ], |
53 | ], |
54 | ]; |
55 | } |
56 | |
57 | public function getNotifications() { |
58 | if ( !$this->mQueryDone ) { |
59 | $this->doQuery(); |
60 | } |
61 | |
62 | $notifications = []; |
63 | foreach ( $this->mResult as $row ) { |
64 | $notifications[] = Notification::newFromRow( $row ); |
65 | } |
66 | |
67 | // get rid of the overfetched |
68 | if ( count( $notifications ) > $this->getLimit() ) { |
69 | array_pop( $notifications ); |
70 | } |
71 | |
72 | if ( $this->mIsBackwards ) { |
73 | $notifications = array_reverse( $notifications ); |
74 | } |
75 | |
76 | return $notifications; |
77 | } |
78 | |
79 | public function getIndexField() { |
80 | return 'notification_event'; |
81 | } |
82 | } |