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 ) {
|
2013-04-10 01:30:30 +00:00
|
|
|
|
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
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
if ( $user->isAnon() ) {
|
2014-07-22 21:33:22 +00:00
|
|
|
// return to this title upon login
|
|
|
|
$returnTo = array( 'returnto' => $this->getPageTitle()->getPrefixedDBkey() );
|
|
|
|
// the html message for anon users
|
|
|
|
$anonMsgHtml = $this->msg(
|
|
|
|
'echo-anon',
|
2015-07-08 09:25:29 +00:00
|
|
|
SpecialPage::getTitleFor( 'Userlogin', 'signup' )->getFullURL( $returnTo ),
|
|
|
|
SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( $returnTo )
|
2014-07-22 21:33:22 +00:00
|
|
|
)->parse();
|
2013-08-20 01:29:21 +00:00
|
|
|
$out->addHTML( Html::rawElement( 'span', array( 'class' => 'plainlinks' ), $anonMsgHtml ) );
|
2012-04-27 15:14:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-02 20:04:29 +00:00
|
|
|
$out->addSubtitle( $this->buildSubtitle() );
|
|
|
|
|
2013-05-03 23:58:56 +00:00
|
|
|
// The continue parameter to pull current set of data from, this
|
2012-12-07 01:08:33 +00:00
|
|
|
// would be used for browsers with javascript disabled
|
2013-05-03 23:58:56 +00:00
|
|
|
$continue = $this->getRequest()->getVal( 'continue', null );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2013-01-14 23:52:46 +00:00
|
|
|
// Pull the notifications
|
2014-07-18 03:58:21 +00:00
|
|
|
$notif = array();
|
2014-08-14 18:46:26 +00:00
|
|
|
$notificationMapper = new EchoNotificationMapper();
|
2014-07-22 21:33:22 +00:00
|
|
|
|
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
$notifications = $notificationMapper->fetchByUser(
|
|
|
|
$user,
|
2014-10-11 19:15:30 +00:00
|
|
|
/* $limit = */self::DISPLAY_NUM + 1,
|
2014-07-22 21:33:22 +00:00
|
|
|
$continue,
|
|
|
|
$attributeManager->getUserEnabledEvents( $user, 'web' )
|
|
|
|
);
|
2014-07-18 03:58:21 +00:00
|
|
|
foreach ( $notifications as $notification ) {
|
|
|
|
$notif[] = EchoDataOutputFormatter::formatOutput( $notification, 'html', $user );
|
|
|
|
}
|
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
|
2012-12-07 01:08:33 +00:00
|
|
|
if ( !$notif ) {
|
2012-07-26 17:23:18 +00:00
|
|
|
$out->addWikiMsg( 'echo-none' );
|
2012-06-08 05:55:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
// Check if there is more data to load for next request
|
2014-10-11 19:15:30 +00:00
|
|
|
if ( count( $notif ) > self::DISPLAY_NUM ) {
|
2013-05-03 23:58:56 +00:00
|
|
|
$lastItem = array_pop( $notif );
|
2013-06-13 18:07:06 +00:00
|
|
|
$nextContinue = $lastItem['timestamp']['utcunix'] . '|' . $lastItem['id'];
|
2012-12-07 01:08:33 +00:00
|
|
|
} else {
|
2013-05-03 23:58:56 +00:00
|
|
|
$nextContinue = null;
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
|
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-13 01:51:13 +00:00
|
|
|
$notices = '';
|
2012-12-15 01:44:07 +00:00
|
|
|
$unread = array();
|
2015-04-29 12:08:30 +00:00
|
|
|
$seenTime = $user->getOption( 'echo-seen-time' );
|
2012-12-07 01:08:33 +00:00
|
|
|
foreach ( $notif as $row ) {
|
2014-02-06 00:53:04 +00:00
|
|
|
$class = 'mw-echo-notification';
|
2015-04-29 12:08:30 +00:00
|
|
|
|
2014-02-06 00:53:04 +00:00
|
|
|
if ( !isset( $row['read'] ) ) {
|
|
|
|
$class .= ' mw-echo-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 ) {
|
|
|
|
$class .= ' mw-echo-unseen';
|
|
|
|
}
|
|
|
|
|
2014-02-05 18:23:54 +00:00
|
|
|
if ( !$row['*'] ) {
|
|
|
|
continue;
|
|
|
|
}
|
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'];
|
2013-07-02 22:08:06 +00:00
|
|
|
$notices .= Html::rawElement( 'li', array( 'class' => 'mw-echo-date-section' ), $dateHeader );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 20:44:06 +00:00
|
|
|
$notices .= Html::rawElement(
|
|
|
|
'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
|
|
|
}
|
2013-06-02 20:04:29 +00:00
|
|
|
$html = Html::rawElement( 'ul', array( 'id' => 'mw-echo-special-container' ), $notices );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
// Build the more link
|
2013-05-03 23:58:56 +00:00
|
|
|
if ( $nextContinue ) {
|
2013-04-09 22:38:36 +00:00
|
|
|
$html .= Html::element(
|
2012-12-07 01:08:33 +00:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => SpecialPage::getTitleFor( 'Notifications' )->getLinkURL(
|
2013-05-03 23:58:56 +00:00
|
|
|
array( 'continue' => $nextContinue )
|
2013-04-09 22:38:36 +00:00
|
|
|
),
|
|
|
|
'id' => 'mw-echo-more'
|
2012-12-07 01:08:33 +00:00
|
|
|
),
|
2013-10-19 07:58:38 +00:00
|
|
|
$this->msg( 'moredotdotdot' )->text()
|
2012-12-07 01:08:33 +00:00
|
|
|
);
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2012-07-26 17:23:18 +00:00
|
|
|
$out->addHTML( $html );
|
2012-12-07 01:08:33 +00:00
|
|
|
$out->addModules( 'ext.echo.special' );
|
|
|
|
$out->addJsConfigVars(
|
|
|
|
array(
|
2014-10-11 19:15:30 +00:00
|
|
|
'wgEchoDisplayNum' => self::DISPLAY_NUM,
|
2013-05-03 23:58:56 +00:00
|
|
|
'wgEchoNextContinue' => $nextContinue,
|
2012-12-07 01:08:33 +00:00
|
|
|
'wgEchoDateHeader' => $dateHeader
|
|
|
|
)
|
|
|
|
);
|
|
|
|
// For no-js support
|
2014-08-06 00:08:10 +00:00
|
|
|
$out->addModuleStyles( "ext.echo.base" );
|
2012-12-15 01:44:07 +00:00
|
|
|
// Mark items as read
|
|
|
|
if ( $unread ) {
|
2013-05-24 22:51:47 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $user )->markRead( $unread );
|
2012-12-15 01:44:07 +00:00
|
|
|
}
|
2015-04-29 12:08:30 +00:00
|
|
|
|
|
|
|
// Record time notifications have been seen
|
|
|
|
$timestamp = wfTimestamp( TS_MW );
|
|
|
|
$user->setOption( 'echo-seen-time', $timestamp );
|
|
|
|
$user->saveSettings();
|
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() {
|
|
|
|
global $wgEchoHelpPage;
|
|
|
|
$lang = $this->getLanguage();
|
|
|
|
$subtitleLinks = array();
|
|
|
|
// More info link
|
|
|
|
$subtitleLinks[] = Html::rawElement(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $wgEchoHelpPage,
|
|
|
|
'id' => 'mw-echo-moreinfo-link',
|
|
|
|
'class' => 'mw-echo-special-header-link',
|
2013-10-19 07:58:38 +00:00
|
|
|
'title' => $this->msg( 'echo-more-info' )->text(),
|
2013-06-02 20:04:29 +00:00
|
|
|
'target' => '_blank'
|
|
|
|
),
|
2013-10-19 07:58:38 +00:00
|
|
|
$this->msg( 'echo-more-info' )->text()
|
2013-06-02 20:04:29 +00:00
|
|
|
);
|
|
|
|
// Preferences link
|
|
|
|
$subtitleLinks[] = Html::rawElement(
|
|
|
|
'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
|
|
|
);
|
|
|
|
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
|
|
|
}
|