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
|
|
|
|
*/
|
2012-12-22 00:43:41 +00:00
|
|
|
private static $displayNum = 10;
|
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
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
if ( $user->isAnon() ) {
|
2012-07-26 17:23:18 +00:00
|
|
|
$out->addWikiMsg( 'echo-anon' );
|
2012-04-27 15:14:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
// The timestamp and offset to pull current set of data from, this
|
|
|
|
// would be used for browsers with javascript disabled
|
|
|
|
$timestamp = $offset = 0;
|
|
|
|
$paging = $this->getRequest()->getVal( 'paging', false );
|
|
|
|
if ( $paging ) {
|
|
|
|
$paging = explode( '|', $paging, 2 );
|
|
|
|
$timestamp = intval( $paging[0] );
|
|
|
|
$offset = intval( $paging[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preferences link
|
2012-12-27 15:37:58 +00:00
|
|
|
$html = Html::rawElement( 'a', array(
|
|
|
|
'href' => SpecialPage::getTitleFor( 'Preferences' )->getLinkURL() . '#mw-prefsection-echo',
|
|
|
|
'id' => 'mw-echo-pref-link',
|
|
|
|
'title' => wfMessage( 'preferences' )->text()
|
|
|
|
) );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2013-01-14 23:52:46 +00:00
|
|
|
// Pull the notifications
|
2012-12-07 01:08:33 +00:00
|
|
|
$notif = ApiEchoNotifications::getNotifications( $user, false, 'html', self::$displayNum + 1, $timestamp, $offset );
|
|
|
|
|
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 ) {
|
|
|
|
$out->addHTML( $html );
|
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
|
|
|
// The timestamp and offset to pull next set of data from
|
|
|
|
$nextTimestamp = $nextOffset = 0;
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
// Check if there is more data to load for next request
|
|
|
|
if ( count( $notif ) > self::$displayNum ) {
|
|
|
|
array_pop( $notif );
|
|
|
|
$more = true;
|
|
|
|
} else {
|
|
|
|
$more = false;
|
|
|
|
}
|
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();
|
2012-12-07 01:08:33 +00:00
|
|
|
foreach ( $notif as $row ) {
|
|
|
|
// Output the date header if it has not been displayed
|
|
|
|
if ( $dateHeader !== $row['timestamp']['date'] ) {
|
|
|
|
$dateHeader = $row['timestamp']['date'];
|
2013-02-09 13:03:59 +00:00
|
|
|
$notices .= Html::rawElement( 'li', array( 'class' => 'mw-echo-date-section' ), $dateHeader );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
$class = 'mw-echo-notification';
|
|
|
|
if ( !isset( $row['read'] ) ) {
|
|
|
|
$class .= ' mw-echo-unread';
|
2012-12-15 01:44:07 +00:00
|
|
|
$unread[] = $row['id'];
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
|
|
|
$nextTimestamp = $row['timestamp']['unix'];
|
|
|
|
$nextOffset = $row['id'];
|
2013-03-07 22:51:25 +00:00
|
|
|
$dataNotificationCategory = EchoNotificationController::getNotificationCategory( $row['type'] );
|
|
|
|
$notices .= Html::rawElement( 'li', array( 'class' => $class, 'data-notification-category' => $dataNotificationCategory ), $row['*'] );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-12-13 01:51:13 +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
|
|
|
|
if ( $more ) {
|
|
|
|
// This is for no-javascript fallback
|
|
|
|
$url = Html::element(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => SpecialPage::getTitleFor( 'Notifications' )->getLinkURL(
|
|
|
|
array( 'paging' => intval( $nextTimestamp ) . '|' . intval( $nextOffset ) )
|
|
|
|
)
|
|
|
|
),
|
|
|
|
wfMessage( 'moredotdotdot' )->text()
|
|
|
|
);
|
|
|
|
|
|
|
|
$html .= Html::rawElement( 'div', array( 'id' => 'mw-echo-more' ), $url );
|
|
|
|
}
|
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(
|
|
|
|
'wgEchoDisplayNum' => self::$displayNum,
|
|
|
|
'wgEchoStartTimestamp' => $nextTimestamp,
|
|
|
|
'wgEchoStartOffset' => $nextOffset,
|
|
|
|
'wgEchoDateHeader' => $dateHeader
|
|
|
|
)
|
|
|
|
);
|
|
|
|
// For no-js support
|
|
|
|
global $wgExtensionAssetsPath;
|
|
|
|
$out->addExtensionStyle( "$wgExtensionAssetsPath/Echo/modules/base/ext.echo.base.css" );
|
|
|
|
$out->addExtensionStyle( "$wgExtensionAssetsPath/Echo/modules/icons/icons.css" );
|
2012-12-15 01:44:07 +00:00
|
|
|
// Mark items as read
|
|
|
|
if ( $unread ) {
|
|
|
|
EchoNotificationController::markRead( $user, $unread );
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-12-07 01:08:33 +00:00
|
|
|
|
2012-07-26 17:23:18 +00:00
|
|
|
}
|