2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SpecialNotifications extends SpecialPage {
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of notification records to display per page/load
|
|
|
|
*/
|
2014-10-11 19:15:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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-08-05 13:26:35 +00:00
|
|
|
$out->addJsConfigVars( 'wgNotificationsSpecialPageLinks', array(
|
|
|
|
'help' => '//www.mediawiki.org/wiki/Special:MyLanguage/Help:Notifications/Special:Notifications',
|
|
|
|
'preferences' => SpecialPage::getTitleFor( 'Preferences' )->getLinkURL() . '#mw-prefsection-echo',
|
|
|
|
) );
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
if ( $user->isAnon() ) {
|
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' ) );
|
|
|
|
$pager->setLimit( $this->getRequest()->getVal( 'limit', self::DISPLAY_NUM ) );
|
|
|
|
$notifications = $pager->getNotifications();
|
2012-12-07 01:08:33 +00:00
|
|
|
|
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
|
|
|
|
$msg = new OOUI\LabelWidget( [ 'label' => $this->msg( 'echo-none' ) ] );
|
|
|
|
$out->addHTML( Html::rawElement( 'div', array( 'class' => 'mw-echo-special-nojs' ), $msg ) );
|
2016-07-06 19:24:46 +00:00
|
|
|
$out->addModules( array( 'ext.echo.special' ) );
|
2012-06-08 05:55:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
$notif = array();
|
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 = '';
|
2012-12-15 01:44:07 +00:00
|
|
|
$unread = array();
|
2015-08-24 23:43:38 +00:00
|
|
|
$echoSeenTime = EchoSeenTime::newFromUser( $user );
|
|
|
|
$seenTime = $echoSeenTime->getTime();
|
2016-03-09 20:13:48 +00:00
|
|
|
$notifArray = array();
|
2012-12-07 01:08:33 +00:00
|
|
|
foreach ( $notif as $row ) {
|
2014-02-06 00:53:04 +00:00
|
|
|
$class = 'mw-echo-notification';
|
|
|
|
if ( !isset( $row['read'] ) ) {
|
2016-03-09 20:13:48 +00:00
|
|
|
$class .= ' mw-echo-notification-unread';
|
2015-04-09 23:50:29 +00:00
|
|
|
if ( !$row['targetpages'] ) {
|
2014-08-07 00:55:24 +00:00
|
|
|
$unread[] = $row['id'];
|
|
|
|
}
|
2014-02-06 00:53:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 12:08:30 +00:00
|
|
|
if ( $seenTime !== null && $row['timestamp']['mw'] > $seenTime ) {
|
2016-03-09 20:13:48 +00:00
|
|
|
$class .= ' mw-echo-notification-unseen';
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 18:23:54 +00:00
|
|
|
if ( !$row['*'] ) {
|
|
|
|
continue;
|
|
|
|
}
|
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-03-09 20:13:48 +00:00
|
|
|
$notifArray[ $dateHeader ] = array(
|
2016-03-09 23:41:54 +00:00
|
|
|
'unread' => array(),
|
2016-03-09 20:13:48 +00:00
|
|
|
'notices' => array()
|
|
|
|
);
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 20:13:48 +00:00
|
|
|
// Collect unread IDs
|
|
|
|
if ( !isset( $row['read'] ) ) {
|
|
|
|
$notifArray[ $dateHeader ][ 'unread' ][] = $row['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$notifArray[ $dateHeader ][ 'notices' ][] = Html::rawElement(
|
2013-06-05 20:44:06 +00:00
|
|
|
'li',
|
|
|
|
array(
|
|
|
|
'class' => $class,
|
|
|
|
'data-notification-category' => $row['category'],
|
|
|
|
'data-notification-event' => $row['id'],
|
|
|
|
'data-notification-type' => $row['type']
|
|
|
|
),
|
|
|
|
$row['*']
|
|
|
|
);
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
|
|
|
|
// Build the HTML
|
|
|
|
$notices = '';
|
2016-05-28 00:02:55 +00:00
|
|
|
$markReadSpecialPage = new SpecialNotificationsMarkRead();
|
2016-03-09 20:13:48 +00:00
|
|
|
foreach ( $notifArray as $section => $data ) {
|
2016-05-28 00:02:55 +00:00
|
|
|
$dateSectionText = Html::element( 'span', array( 'class' => 'mw-echo-date-section-text' ), $section );
|
|
|
|
$sectionTitle = $dateSectionText;
|
2016-03-09 23:41:54 +00:00
|
|
|
if ( count( $data[ 'unread' ] ) > 0 ) {
|
2016-05-28 00:02:55 +00:00
|
|
|
$markReadSectionText = $this->msg( 'echo-specialpage-section-markread' )->text();
|
|
|
|
|
|
|
|
$markAsReadLabelIcon = new EchoOOUI\LabelIconWidget( array(
|
|
|
|
'label' => $markReadSectionText,
|
2016-05-16 14:03:13 +00:00
|
|
|
'icon' => 'doubleCheck',
|
2016-03-09 23:41:54 +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 );
|
|
|
|
$formWrapper = Html::rawElement(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'mw-echo-markAsReadSectionButton',
|
|
|
|
),
|
|
|
|
$formHtml
|
|
|
|
);
|
|
|
|
$sectionTitle .= $formWrapper;
|
2016-03-09 23:41:54 +00:00
|
|
|
}
|
2016-03-09 20:13:48 +00:00
|
|
|
|
|
|
|
// Heading
|
|
|
|
$notices .= Html::rawElement( 'li', array( 'class' => 'mw-echo-date-section' ), $sectionTitle );
|
|
|
|
|
|
|
|
// Notices
|
|
|
|
$notices .= join( "\n", $data[ 'notices' ] );
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
$navBar = $pager->getNavigationBar();
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2016-05-16 20:35:15 +00:00
|
|
|
$html = Html::rawElement( 'div', array( 'class' => 'mw-echo-special-navbar-top' ), $navBar );
|
|
|
|
$html .= Html::rawElement( 'ul', array( 'class' => 'mw-echo-special-notifications' ), $notices );
|
|
|
|
$html .= Html::rawElement( 'div', array( 'class' => 'mw-echo-special-navbar-bottom' ), $navBar );
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
$html = Html::rawElement( 'div', array( 'class' => 'mw-echo-special-container' ), $html );
|
|
|
|
$out->addHTML( Html::rawElement( 'div', array( 'class' => 'mw-echo-special-nojs' ), $html ) );
|
|
|
|
|
|
|
|
$out->addModules( array( 'ext.echo.special' ) );
|
2016-07-23 00:23:54 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
// For no-js support
|
2015-09-16 19:48:56 +00:00
|
|
|
$out->addModuleStyles( array( 'ext.echo.styles.notifications', 'ext.echo.styles.special' ) );
|
2016-08-04 21:51:59 +00:00
|
|
|
|
|
|
|
// Log visit
|
2016-08-16 10:59:07 +00:00
|
|
|
MWEchoEventLogging::logEchoInteraction( $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();
|
|
|
|
$subtitleLinks = array();
|
|
|
|
// Preferences link
|
2016-03-09 20:13:48 +00:00
|
|
|
$subtitleLinks[] = Html::element(
|
2013-06-02 20:04:29 +00:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => SpecialPage::getTitleFor( 'Preferences' )->getLinkURL() . '#mw-prefsection-echo',
|
|
|
|
'id' => 'mw-echo-pref-link',
|
|
|
|
'class' => 'mw-echo-special-header-link',
|
2013-10-19 07:58:38 +00:00
|
|
|
'title' => $this->msg( 'preferences' )->text()
|
2013-06-02 20:04:29 +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
|
|
|
}
|