Debian Codegraph @

extensions/Echo/includes/Special/NotificationPager.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Special;
4
5 use LogicException;
6 use MediaWiki\Context\IContextSource;
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 public function __construct( IContextSource $context ) {
20 $dbFactory = DbFactory::newFromDefault();
21 $this->mDb = $dbFactory->getEchoDb( DB_REPLICA );
22
23 parent::__construct( $context );
24 }
25
26 public function formatRow( $row ) {
27 // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation
28 throw new LogicException( "This pager does not support row formatting. " .
29 "Use 'getNotifications()' to get a list of Notification objects." );
30 }
31
32 public function getQueryInfo() {
33 $attributeManager = Services::getInstance()->getAttributeManager();
34 $eventTypes = $attributeManager->getUserEnabledEvents( $this->getUser(), 'web' );
35
36 return [
37 'tables' => [ 'echo_notification', 'echo_event' ],
38 'fields' => Notification::selectFields(),
39 'conds' => [
40 'notification_user' => $this->getUser()->getId(),
41 'event_type' => $eventTypes,
42 'event_deleted' => 0,
43 ],
44 'options' => [],
45 'join_conds' =>
46 [ 'echo_event' =>
47 [
48 'JOIN',
49 'notification_event=event_id',
50 ],
51 ],
52 ];
53 }
54
55 public function getNotifications() {
56 if ( !$this->mQueryDone ) {
57 $this->doQuery();
58 }
59
60 $notifications = [];
61 foreach ( $this->mResult as $row ) {
62 $notifications[] = Notification::newFromRow( $row );
63 }
64
65 // get rid of the overfetched
66 if ( count( $notifications ) > $this->getLimit() ) {
67 array_pop( $notifications );
68 }
69
70 if ( $this->mIsBackwards ) {
71 $notifications = array_reverse( $notifications );
72 }
73
74 return $notifications;
75 }
76
77 public function getIndexField() {
78 return 'notification_event';
79 }
80 }