| 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 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 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 |
|
| 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 |
} |