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
|
|
|
|
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-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 ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
if ( !$row['*'] ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array( 'mw-echo-notification' );
|
|
|
|
|
2014-02-06 00:53:04 +00:00
|
|
|
if ( !isset( $row['read'] ) ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
$classes[] = '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-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-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'];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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();
|
2016-03-09 20:13:48 +00:00
|
|
|
foreach ( $notifArray as $section => $data ) {
|
2016-08-31 18:46:25 +00:00
|
|
|
// Heading
|
|
|
|
$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
|
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 );
|
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,
|
|
|
|
$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
|
|
|
|
|
|
|
$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
|
2016-11-24 00:31:23 +00:00
|
|
|
$out->addModuleStyles( array(
|
|
|
|
'ext.echo.styles.notifications',
|
|
|
|
'ext.echo.styles.special',
|
|
|
|
// We already load badgeicons in the BeforePageDisplay hook, but not for minerva
|
|
|
|
'ext.echo.badgeicons'
|
|
|
|
) );
|
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();
|
|
|
|
$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
|
|
|
}
|