2016-05-16 20:35:15 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 21:15:29 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Special;
|
|
|
|
|
|
|
|
use IContextSource;
|
2024-02-12 23:36:03 +00:00
|
|
|
use LogicException;
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Notification;
|
2022-11-13 07:53:42 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Services;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Pager\ReverseChronologicalPager;
|
2022-11-02 21:15:29 +00:00
|
|
|
|
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 ) {
|
2022-11-12 07:19:00 +00:00
|
|
|
$dbFactory = DbFactory::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
|
2024-02-12 23:36:03 +00:00
|
|
|
throw new LogicException( "This pager does not support row formatting. " .
|
2022-11-02 21:34:17 +00:00
|
|
|
"Use 'getNotifications()' to get a list of Notification objects." );
|
2016-05-16 20:35:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function getQueryInfo() {
|
2022-11-13 07:53:42 +00:00
|
|
|
$attributeManager = Services::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' ],
|
2022-11-02 21:34:17 +00:00
|
|
|
'fields' => Notification::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 ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$notifications[] = Notification::newFromRow( $row );
|
2016-05-16 20:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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';
|
|
|
|
}
|
|
|
|
}
|