mediawiki-extensions-Echo/includes/special/SpecialNotifications.php

209 lines
5.7 KiB
PHP
Raw Normal View History

<?php
class SpecialNotifications extends SpecialPage {
/**
* Number of notification records to display per page/load
*/
const DISPLAY_NUM = 20;
public function __construct() {
parent::__construct( 'Notifications' );
}
public function execute( $par ) {
$this->setHeaders();
$out = $this->getOutput();
$out->setPageTitle( $this->msg( 'echo-specialpage' )->text() );
$user = $this->getUser();
if ( $user->isAnon() ) {
// Redirect to login page and inform user of the need to login
$this->requireLogin( 'echo-notification-loginrequired' );
return;
}
$out->addSubtitle( $this->buildSubtitle() );
$out->enableOOUI();
// The continue parameter to pull current set of data from, this
// would be used for browsers with javascript disabled
$continue = $this->getRequest()->getVal( 'continue', null );
// Pull the notifications
$notif = array();
$notificationMapper = new EchoNotificationMapper();
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$notifications = $notificationMapper->fetchByUser(
$user,
/* $limit = */self::DISPLAY_NUM + 1,
$continue,
$attributeManager->getUserEnabledEvents( $user, 'web' )
);
// If there are no notifications, display a message saying so
if ( !$notifications ) {
$out->addWikiMsg( 'echo-none' );
return;
}
foreach ( $notifications as $notification ) {
$output = EchoDataOutputFormatter::formatOutput( $notification, 'special', $user, $this->getLanguage() );
if ( $output ) {
$notif[] = $output;
}
}
// Check if there is more data to load for next request
if ( count( $notifications ) > self::DISPLAY_NUM ) {
$lastItem = array_pop( $notif );
$nextContinue = $lastItem['timestamp']['utcunix'] . '|' . $lastItem['id'];
} else {
$nextContinue = null;
}
// Add the notifications to the page (interspersed with date headers)
$dateHeader = '';
$unread = array();
$echoSeenTime = EchoSeenTime::newFromUser( $user );
$seenTime = $echoSeenTime->getTime();
$notifArray = array();
foreach ( $notif as $row ) {
$class = 'mw-echo-notification';
if ( !isset( $row['read'] ) ) {
$class .= ' mw-echo-notification-unread';
if ( !$row['targetpages'] ) {
$unread[] = $row['id'];
}
}
if ( $seenTime !== null && $row['timestamp']['mw'] > $seenTime ) {
$class .= ' mw-echo-notification-unseen';
}
if ( !$row['*'] ) {
continue;
}
// Output the date header if it has not been displayed
if ( $dateHeader !== $row['timestamp']['date'] ) {
$dateHeader = $row['timestamp']['date'];
$notifArray[ $dateHeader ] = array(
'unread' => array(),
'notices' => array()
);
}
// Collect unread IDs
if ( !isset( $row['read'] ) ) {
$notifArray[ $dateHeader ][ 'unread' ][] = $row['id'];
}
$notifArray[ $dateHeader ][ 'notices' ][] = Html::rawElement(
'li',
array(
'class' => $class,
'data-notification-category' => $row['category'],
'data-notification-event' => $row['id'],
'data-notification-type' => $row['type']
),
$row['*']
);
}
// Build the HTML
$notices = '';
$markReadSpecialPage = SpecialPage::getTitleFor( 'NotificationsMarkRead' );
foreach ( $notifArray as $section => $data ) {
$sectionTitle = Html::element( 'span', array( 'class' => 'mw-echo-date-section-text' ), $section );
if ( count( $data[ 'unread' ] ) > 0 ) {
// There are unread notices. Add the 'mark section as read' button
$markSectionAsReadButton = new OOUI\ButtonWidget( array(
'label' => $this->msg( 'echo-specialpage-section-markread' )->text(),
'href' => $markReadSpecialPage->getLocalURL() . '/' . join( ',', $data[ 'unread' ] ),
'classes' => array( 'mw-echo-markAsReadSectionButton' ),
) );
$sectionTitle .= $markSectionAsReadButton;
}
// Heading
$notices .= Html::rawElement( 'li', array( 'class' => 'mw-echo-date-section' ), $sectionTitle );
// Notices
$notices .= join( "\n", $data[ 'notices' ] );
}
$html = Html::rawElement( 'ul', array( 'id' => 'mw-echo-special-container' ), $notices );
// Build the more link
if ( $nextContinue ) {
$html .= Html::element(
'a',
array(
'href' => SpecialPage::getTitleFor( 'Notifications' )->getLinkURL(
array( 'continue' => $nextContinue )
),
Split alerts and messages in Echo Split the notifications into 'alert' and 'message' badget with two different flyouts. Also clean up styling and module behavior. ** Depends on ooui change Id4bbe14ba0bf6c for footers in popups. ** Depends on ooui change Ie93e4d6ed5637c for fixing a bug in inverted icons. ** MobileFrontend must also be updated to support the new modules in this patch I168f485d6e54cb4067 In this change: * Split notifcations into alert and messages and display those in two different badges. * Create two separate flyout/popups for each category with their notifications. * Create a view-model to control notification state and emit events for both the popup and the badge to intercept and react to. * Clean up module load and distribution: * Create an ext.echo.ui module for javascript-ui support and ooui widgets. * Create an ext.echo.nojs module that unifies all base classes that are needed for both nojs and js support, that the js version builds upon. * Create a separate ext.echo.logger module as a singleton that can be called to perform all logging. * Clean up style uses * Move the special page LESS file into nojs module so all styles load properly even in nojs mode. * Transfer some of the styling from JS to LESS for consistency. * Make the 'read more' button load already with the styles it needs to look like a button, since its behavior is similar in nojs and js vesions, but before its classes were applied only by the js, making it inconsistent and also making its appearance 'jump' from a link to a button. * Delete and clean up all old and unused files. * Moved 'Help.png' icon from modules/overlay to modules/icons for later use. Bug: T108190 Change-Id: I55f440ed9f64c46817f620328a6bb522d44c9ca9
2015-08-13 00:54:16 +00:00
'class' => 'mw-ui-button mw-ui-primary',
'id' => 'mw-echo-more'
),
$this->msg( 'moredotdotdot' )->text()
);
}
$out->addHTML( $html );
$out->addJsConfigVars(
array(
'wgEchoDisplayNum' => self::DISPLAY_NUM,
'wgEchoNextContinue' => $nextContinue,
'wgEchoDateHeader' => $dateHeader
)
);
// For no-js support
$out->addModuleStyles( array( 'ext.echo.styles.notifications', 'ext.echo.styles.special' ) );
}
/**
* 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::element(
'a',
array(
'href' => $wgEchoHelpPage,
'id' => 'mw-echo-moreinfo-link',
'class' => 'mw-echo-special-header-link',
'title' => $this->msg( 'echo-more-info' )->text(),
'target' => '_blank'
),
$this->msg( 'echo-more-info' )->text()
);
// Preferences link
$subtitleLinks[] = Html::element(
'a',
array(
'href' => SpecialPage::getTitleFor( 'Preferences' )->getLinkURL() . '#mw-prefsection-echo',
'id' => 'mw-echo-pref-link',
'class' => 'mw-echo-special-header-link',
'title' => $this->msg( 'preferences' )->text()
),
$this->msg( 'preferences' )->text()
);
return $lang->pipeList( $subtitleLinks );
}
protected function getGroupName() {
return 'users';
}
}