2016-05-16 20:35:15 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 21:15:29 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Special;
|
|
|
|
|
|
|
|
use EchoNotification;
|
|
|
|
use EchoServices;
|
|
|
|
use Exception;
|
|
|
|
use IContextSource;
|
|
|
|
use MWEchoDbFactory;
|
|
|
|
use ReverseChronologicalPager;
|
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
/**
|
|
|
|
* This pager is used by Special:Notifications (NO-JS).
|
|
|
|
* The heavy-lifting is done by IndexPager (grand-parent to this class).
|
2016-07-25 16:20:38 +00:00
|
|
|
* It paginates on notification_event for a specific user, only for the enabled event types.
|
2016-05-16 20:35:15 +00:00
|
|
|
*/
|
|
|
|
class NotificationPager extends ReverseChronologicalPager {
|
2019-02-15 20:28:25 +00:00
|
|
|
/**
|
|
|
|
* @param IContextSource $context
|
|
|
|
*/
|
|
|
|
public function __construct( IContextSource $context ) {
|
2016-06-01 22:03:58 +00:00
|
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
2017-09-24 05:23:47 +00:00
|
|
|
$this->mDb = $dbFactory->getEchoDb( DB_REPLICA );
|
2016-06-01 22:03:58 +00:00
|
|
|
|
2019-02-15 20:28:25 +00:00
|
|
|
parent::__construct( $context );
|
2016-06-01 22:03:58 +00:00
|
|
|
}
|
2016-05-16 20:35:15 +00:00
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function formatRow( $row ) {
|
2021-09-08 18:36:35 +00:00
|
|
|
// @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation
|
2020-06-27 10:05:03 +00:00
|
|
|
throw new Exception( "This pager does not support row formatting. " .
|
|
|
|
"Use 'getNotifications()' to get a list of EchoNotification objects." );
|
2016-05-16 20:35:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function getQueryInfo() {
|
2021-02-25 01:55:40 +00:00
|
|
|
$attributeManager = EchoServices::getInstance()->getAttributeManager();
|
2016-05-16 20:35:15 +00:00
|
|
|
$eventTypes = $attributeManager->getUserEnabledEvents( $this->getUser(), 'web' );
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
'tables' => [ 'echo_notification', 'echo_event' ],
|
2019-03-02 20:25:33 +00:00
|
|
|
'fields' => EchoNotification::selectFields(),
|
2016-12-05 18:51:07 +00:00
|
|
|
'conds' => [
|
2016-05-16 20:35:15 +00:00
|
|
|
'notification_user' => $this->getUser()->getId(),
|
|
|
|
'event_type' => $eventTypes,
|
2016-07-25 16:20:38 +00:00
|
|
|
'event_deleted' => 0,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
'options' => [],
|
2016-05-16 20:35:15 +00:00
|
|
|
'join_conds' =>
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'echo_event' =>
|
|
|
|
[
|
2016-05-16 20:35:15 +00:00
|
|
|
'JOIN',
|
|
|
|
'notification_event=event_id',
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2016-05-16 20:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getNotifications() {
|
|
|
|
if ( !$this->mQueryDone ) {
|
|
|
|
$this->doQuery();
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = [];
|
2016-05-16 20:35:15 +00:00
|
|
|
foreach ( $this->mResult as $row ) {
|
|
|
|
$notifications[] = EchoNotification::newFromRow( $row );
|
|
|
|
}
|
|
|
|
|
|
|
|
// get rid of the overfetched
|
|
|
|
if ( count( $notifications ) > $this->getLimit() ) {
|
|
|
|
array_pop( $notifications );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->mIsBackwards ) {
|
|
|
|
$notifications = array_reverse( $notifications );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifications;
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function getIndexField() {
|
2016-05-16 20:35:15 +00:00
|
|
|
return 'notification_event';
|
|
|
|
}
|
|
|
|
}
|