2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 21:15:29 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Special;
|
|
|
|
|
2022-11-13 07:48:43 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DataOutputFormatter;
|
|
|
|
use MediaWiki\Extension\Notifications\NotifUser;
|
2022-04-08 00:30:41 +00:00
|
|
|
use MediaWiki\Extension\Notifications\OOUI\LabelIconWidget;
|
2022-11-13 06:43:40 +00:00
|
|
|
use MediaWiki\Extension\Notifications\SeenTime;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2022-11-02 21:15:29 +00:00
|
|
|
use OOUI;
|
2022-04-08 00:30:41 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
class SpecialNotifications extends SpecialPage {
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of notification records to display per page/load
|
|
|
|
*/
|
2020-09-19 18:55:32 +00:00
|
|
|
private const DISPLAY_NUM = 20;
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
public function __construct() {
|
2012-08-30 16:04:39 +00:00
|
|
|
parent::__construct( 'Notifications' );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 02:01:44 +00:00
|
|
|
/**
|
2019-10-23 10:45:51 +00:00
|
|
|
* @param string|null $par
|
2018-09-14 02:01:44 +00:00
|
|
|
*/
|
2012-07-26 17:23:18 +00:00
|
|
|
public function execute( $par ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
2012-07-26 17:23:18 +00:00
|
|
|
$out = $this->getOutput();
|
2023-08-10 14:02:39 +00:00
|
|
|
$out->setPageTitleMsg( $this->msg( 'echo-specialpage' ) );
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2016-06-22 19:38:38 +00:00
|
|
|
$this->addHelpLink( 'Help:Notifications/Special:Notifications' );
|
2016-05-27 12:55:43 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addJsConfigVars( 'wgNotificationsSpecialPageLinks', [
|
2022-08-05 22:54:37 +00:00
|
|
|
'preferences' => SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )->getLinkURL(),
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2016-08-05 13:26:35 +00:00
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
$user = $this->getUser();
|
2020-12-22 15:36:58 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2015-12-08 18:54:44 +00:00
|
|
|
// Redirect to login page and inform user of the need to login
|
|
|
|
$this->requireLogin( 'echo-notification-loginrequired' );
|
2012-04-27 15:14:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-02 20:04:29 +00:00
|
|
|
$out->addSubtitle( $this->buildSubtitle() );
|
|
|
|
|
2016-03-09 20:13:48 +00:00
|
|
|
$out->enableOOUI();
|
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
$pager = new NotificationPager( $this->getContext() );
|
|
|
|
$pager->setOffset( $this->getRequest()->getVal( 'offset' ) );
|
2019-12-13 21:28:57 +00:00
|
|
|
$pager->setLimit( $this->getRequest()->getInt( 'limit', self::DISPLAY_NUM ) );
|
2016-05-16 20:35:15 +00:00
|
|
|
$notifications = $pager->getNotifications();
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
$noJSDiv = new OOUI\Tag();
|
|
|
|
$noJSDiv->addClasses( [ 'mw-echo-special-nojs' ] );
|
|
|
|
|
2013-01-14 23:52:46 +00:00
|
|
|
// If there are no notifications, display a message saying so
|
2015-11-18 10:06:20 +00:00
|
|
|
if ( !$notifications ) {
|
2016-08-17 00:25:14 +00:00
|
|
|
// Wrap this with nojs so it is still hidden if JS is loading
|
2016-08-31 18:46:25 +00:00
|
|
|
$noJSDiv->appendContent(
|
|
|
|
new OOUI\LabelWidget( [ 'label' => $this->msg( 'echo-none' )->text() ] )
|
|
|
|
);
|
|
|
|
$out->addHTML( $noJSDiv );
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addModules( [ 'ext.echo.special' ] );
|
2012-06-08 05:55:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$notif = [];
|
2015-11-18 10:06:20 +00:00
|
|
|
foreach ( $notifications as $notification ) {
|
2022-11-13 07:48:43 +00:00
|
|
|
$output = DataOutputFormatter::formatOutput( $notification, 'special', $user, $this->getLanguage() );
|
2015-11-18 10:06:20 +00:00
|
|
|
if ( $output ) {
|
|
|
|
$notif[] = $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 23:52:46 +00:00
|
|
|
// Add the notifications to the page (interspersed with date headers)
|
2012-12-07 01:08:33 +00:00
|
|
|
$dateHeader = '';
|
2017-08-12 14:00:35 +00:00
|
|
|
$anyUnread = false;
|
2022-11-13 06:43:40 +00:00
|
|
|
$seenTime = SeenTime::newFromUser( $user )->getTime();
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifArray = [];
|
2012-12-07 01:08:33 +00:00
|
|
|
foreach ( $notif as $row ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
if ( !$row['*'] ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$classes = [ 'mw-echo-notification' ];
|
2016-08-31 18:46:25 +00:00
|
|
|
|
2015-04-29 12:08:30 +00:00
|
|
|
if ( $seenTime !== null && $row['timestamp']['mw'] > $seenTime ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
$classes[] = 'mw-echo-notification-unseen';
|
2014-02-05 18:23:54 +00:00
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
// Output the date header if it has not been displayed
|
|
|
|
if ( $dateHeader !== $row['timestamp']['date'] ) {
|
|
|
|
$dateHeader = $row['timestamp']['date'];
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
// Collect unread IDs
|
|
|
|
if ( !isset( $row['read'] ) ) {
|
2022-06-23 09:17:10 +00:00
|
|
|
$classes[] = 'mw-echo-notification-unread';
|
2017-08-12 14:00:35 +00:00
|
|
|
$anyUnread = true;
|
2016-03-09 20:13:48 +00:00
|
|
|
$notifArray[ $dateHeader ][ 'unread' ][] = $row['id'];
|
|
|
|
}
|
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
$li = new OOUI\Tag( 'li' );
|
|
|
|
$li
|
|
|
|
->addClasses( $classes )
|
|
|
|
->setAttributes( [
|
2013-06-05 20:44:06 +00:00
|
|
|
'data-notification-category' => $row['category'],
|
|
|
|
'data-notification-event' => $row['id'],
|
|
|
|
'data-notification-type' => $row['type']
|
2016-08-31 18:46:25 +00:00
|
|
|
] )
|
|
|
|
->appendContent( new OOUI\HtmlSnippet( $row['*'] ) );
|
|
|
|
|
|
|
|
// Store
|
|
|
|
$notifArray[ $dateHeader ][ 'notices' ][] = $li;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
|
2017-08-12 14:00:35 +00:00
|
|
|
$markAllAsReadFormWrapper = '';
|
|
|
|
// Ensure there are some unread notifications
|
|
|
|
if ( $anyUnread ) {
|
|
|
|
$markReadSpecialPage = new SpecialNotificationsMarkRead();
|
2019-02-15 20:28:25 +00:00
|
|
|
$markReadSpecialPage->setContext( $this->getContext() );
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2023-04-21 11:53:26 +00:00
|
|
|
$unreadCount = $notifUser->getAlertCount() + $notifUser->getMessageCount();
|
2017-08-12 14:00:35 +00:00
|
|
|
|
2023-04-21 11:53:26 +00:00
|
|
|
$markAllAsReadText = $this
|
|
|
|
->msg( 'echo-mark-all-as-read' )
|
|
|
|
->numParams( $unreadCount )
|
|
|
|
->text();
|
2022-04-08 00:30:41 +00:00
|
|
|
$markAllAsReadLabelIcon = new LabelIconWidget( [
|
2017-08-12 14:00:35 +00:00
|
|
|
'label' => $markAllAsReadText,
|
2018-03-22 21:21:06 +00:00
|
|
|
'icon' => 'checkAll',
|
2017-08-12 14:00:35 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
$markAllAsReadForm = $markReadSpecialPage->getMinimalForm(
|
|
|
|
[ 'ALL' ],
|
|
|
|
$markAllAsReadText,
|
|
|
|
true,
|
|
|
|
$markAllAsReadLabelIcon->toString()
|
|
|
|
);
|
|
|
|
|
2022-11-12 06:37:37 +00:00
|
|
|
// First submission attempt
|
|
|
|
$formHtml = $markAllAsReadForm->prepareForm()->getHTML( false );
|
2017-08-12 14:00:35 +00:00
|
|
|
|
|
|
|
$markAllAsReadFormWrapper = new OOUI\Tag();
|
|
|
|
$markAllAsReadFormWrapper
|
|
|
|
->addClasses( [ 'mw-echo-special-markAllReadButton' ] )
|
|
|
|
->appendContent( new OOUI\HtmlSnippet( $formHtml ) );
|
|
|
|
}
|
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
// Build the list
|
|
|
|
$notices = new OOUI\Tag( 'ul' );
|
|
|
|
$notices->addClasses( [ 'mw-echo-special-notifications' ] );
|
|
|
|
|
2016-05-28 00:02:55 +00:00
|
|
|
$markReadSpecialPage = new SpecialNotificationsMarkRead();
|
2019-02-15 20:28:25 +00:00
|
|
|
$markReadSpecialPage->setContext( $this->getContext() );
|
2016-03-09 20:13:48 +00:00
|
|
|
foreach ( $notifArray as $section => $data ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
$heading = ( new OOUI\Tag( 'li' ) )->addClasses( [ 'mw-echo-date-section' ] );
|
|
|
|
|
|
|
|
$dateTitle = new OOUI\LabelWidget( [
|
|
|
|
'classes' => [ 'mw-echo-date-section-text' ],
|
|
|
|
'label' => $section
|
|
|
|
] );
|
|
|
|
|
|
|
|
$heading->appendContent( $dateTitle );
|
|
|
|
|
|
|
|
// Mark all read button
|
2022-11-21 12:53:38 +00:00
|
|
|
if ( isset( $data[ 'unread' ] ) ) {
|
2017-04-19 13:13:11 +00:00
|
|
|
// tell the UI to show 'unread' notifications only (instead of 'all')
|
|
|
|
$out->addJsConfigVars( 'wgEchoReadState', 'unread' );
|
|
|
|
|
2016-05-28 00:02:55 +00:00
|
|
|
$markReadSectionText = $this->msg( 'echo-specialpage-section-markread' )->text();
|
2022-04-08 00:30:41 +00:00
|
|
|
$markAsReadLabelIcon = new LabelIconWidget( [
|
2016-05-28 00:02:55 +00:00
|
|
|
'label' => $markReadSectionText,
|
2018-03-22 21:21:06 +00:00
|
|
|
'icon' => 'checkAll',
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2016-05-28 00:02:55 +00:00
|
|
|
|
|
|
|
// There are unread notices. Add the 'mark section as read' button
|
|
|
|
$markSectionAsReadForm = $markReadSpecialPage->getMinimalForm(
|
|
|
|
$data[ 'unread' ],
|
|
|
|
$markReadSectionText,
|
|
|
|
true,
|
|
|
|
$markAsReadLabelIcon->toString()
|
|
|
|
);
|
|
|
|
|
2022-11-12 06:37:37 +00:00
|
|
|
// First submission attempt
|
|
|
|
$formHtml = $markSectionAsReadForm->prepareForm()->getHTML( false );
|
2016-03-09 20:13:48 +00:00
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
$formWrapper = new OOUI\Tag();
|
|
|
|
$formWrapper
|
|
|
|
->addClasses( [ 'mw-echo-markAsReadSectionButton' ] )
|
|
|
|
->appendContent( new OOUI\HtmlSnippet( $formHtml ) );
|
|
|
|
|
|
|
|
$heading->appendContent( $formWrapper );
|
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
// These two must be separate, because $data[ 'notices' ]
|
|
|
|
// is an array
|
|
|
|
$notices
|
|
|
|
->appendContent( $heading )
|
2022-10-09 03:40:45 +00:00
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset https://github.com/phan/phan/issues/4735
|
2016-08-31 18:46:25 +00:00
|
|
|
->appendContent( $data[ 'notices' ] );
|
2016-03-09 20:13:48 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
$navBar = $pager->getNavigationBar();
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
$navTop = new OOUI\Tag();
|
|
|
|
$navBottom = new OOUI\Tag();
|
|
|
|
$container = new OOUI\Tag();
|
|
|
|
|
|
|
|
$navTop
|
|
|
|
->addClasses( [ 'mw-echo-special-navbar-top' ] )
|
|
|
|
->appendContent( new OOUI\HtmlSnippet( $navBar ) );
|
|
|
|
$navBottom
|
|
|
|
->addClasses( [ 'mw-echo-special-navbar-bottom' ] )
|
|
|
|
->appendContent( new OOUI\HtmlSnippet( $navBar ) );
|
|
|
|
|
|
|
|
// Put it all together
|
|
|
|
$container
|
|
|
|
->addClasses( [ 'mw-echo-special-container' ] )
|
|
|
|
->appendContent(
|
|
|
|
$navTop,
|
2017-08-12 14:00:35 +00:00
|
|
|
$markAllAsReadFormWrapper,
|
2016-08-31 18:46:25 +00:00
|
|
|
$notices,
|
|
|
|
$navBottom
|
|
|
|
);
|
|
|
|
|
|
|
|
// Wrap with nojs div
|
|
|
|
$noJSDiv->appendContent( $container );
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2016-08-31 18:46:25 +00:00
|
|
|
$out->addHTML( $noJSDiv );
|
2016-03-16 22:47:20 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addModules( [ 'ext.echo.special' ] );
|
2016-07-23 00:23:54 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
// For no-js support
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addModuleStyles( [
|
2016-11-24 00:31:23 +00:00
|
|
|
'ext.echo.styles.notifications',
|
|
|
|
'ext.echo.styles.special',
|
2021-06-01 21:02:59 +00:00
|
|
|
'oojs-ui.styles.icons-alerts',
|
|
|
|
'oojs-ui.styles.icons-interactions',
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2013-06-02 20:04:29 +00:00
|
|
|
/**
|
|
|
|
* Build the subtitle (more info and preference links)
|
|
|
|
* @return string HTML for the subtitle
|
|
|
|
*/
|
|
|
|
public function buildSubtitle() {
|
|
|
|
$lang = $this->getLanguage();
|
2016-12-05 18:51:07 +00:00
|
|
|
$subtitleLinks = [];
|
2013-06-02 20:04:29 +00:00
|
|
|
// Preferences link
|
2016-03-09 20:13:48 +00:00
|
|
|
$subtitleLinks[] = Html::element(
|
2013-06-02 20:04:29 +00:00
|
|
|
'a',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2022-08-05 22:54:37 +00:00
|
|
|
'href' => SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )->getLinkURL(),
|
2013-06-02 20:04:29 +00:00
|
|
|
'id' => 'mw-echo-pref-link',
|
|
|
|
'class' => 'mw-echo-special-header-link',
|
2013-10-19 07:58:38 +00:00
|
|
|
'title' => $this->msg( 'preferences' )->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2013-10-19 07:58:38 +00:00
|
|
|
$this->msg( 'preferences' )->text()
|
2013-06-02 20:04:29 +00:00
|
|
|
);
|
2016-05-27 12:55:43 +00:00
|
|
|
// using pipeList to make it easier to add some links in the future
|
2013-06-02 20:04:29 +00:00
|
|
|
return $lang->pipeList( $subtitleLinks );
|
|
|
|
}
|
2015-05-15 20:41:09 +00:00
|
|
|
|
|
|
|
protected function getGroupName() {
|
2023-03-24 19:08:17 +00:00
|
|
|
return 'login';
|
2015-05-15 20:41:09 +00:00
|
|
|
}
|
2012-07-26 17:23:18 +00:00
|
|
|
}
|