2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 00:30:41 +00:00
|
|
|
use MediaWiki\Extension\Notifications\OOUI\LabelIconWidget;
|
|
|
|
|
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();
|
|
|
|
$out->setPageTitle( $this->msg( 'echo-specialpage' )->text() );
|
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 ) {
|
2015-11-11 02:23:03 +00:00
|
|
|
$output = EchoDataOutputFormatter::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;
|
2015-08-24 23:43:38 +00:00
|
|
|
$echoSeenTime = EchoSeenTime::newFromUser( $user );
|
|
|
|
$seenTime = $echoSeenTime->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'];
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifArray[ $dateHeader ] = [
|
|
|
|
'unread' => [],
|
|
|
|
'notices' => []
|
|
|
|
];
|
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() );
|
2017-08-12 14:00:35 +00:00
|
|
|
|
|
|
|
$markAllAsReadText = $this->msg( 'echo-mark-all-as-read' )->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()
|
|
|
|
);
|
|
|
|
|
|
|
|
$formHtml = $markAllAsReadForm->prepareForm()->getHTML( /* First submission attempt */ false );
|
|
|
|
|
|
|
|
$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
|
2018-06-17 16:59:03 +00:00
|
|
|
if ( $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()
|
|
|
|
);
|
|
|
|
|
|
|
|
$formHtml = $markSectionAsReadForm->prepareForm()->getHTML( /* First submission attempt */ 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 )
|
|
|
|
->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
|
|
|
] );
|
2016-08-04 21:51:59 +00:00
|
|
|
|
|
|
|
// Log visit
|
2016-08-22 20:33:34 +00:00
|
|
|
MWEchoEventLogging::logSpecialPageVisit( $user, $out->getSkin()->getSkinName() );
|
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() {
|
|
|
|
return 'users';
|
|
|
|
}
|
2012-07-26 17:23:18 +00:00
|
|
|
}
|