mediawiki-extensions-Echo/special/SpecialNotifications.php
bsitu cd349b11ac (bug 41866) Fix invalid notification in the flyout and page
1. Skip invalid notification events
2. Add formatting to notifcation count, for example, if the count is over 99, we just show 99+

patch set 2:
	* fix trailing whitespace
patch set 3:
	* remove extra whitespace and indentation
patch set 4:
	* change function name from gatherValidEchoEvent() to gatherValidEchoEvents()
	* add more descriptive documentation

Change-Id: I81a135c24f64fa1aace4dd2631e9b88bbe22d3d0
2012-12-03 11:41:16 -08:00

65 lines
1.5 KiB
PHP

<?php
class SpecialNotifications extends SpecialPage {
public function __construct() {
parent::__construct( 'Notifications' );
}
public function execute( $par ) {
$this->setHeaders();
$out = $this->getOutput();
$out->setPageTitle( $this->msg( 'echo-specialpage' )->text() );
$out->addModules( array( 'ext.echo.special' ) );
$user = $this->getUser();
if ( $user->isAnon() ) {
$out->addWikiMsg( 'echo-anon' );
return;
}
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
array( 'echo_notification', 'echo_event' ),
'*',
array(
'notification_user' => $user->getID(),
'event_type' => EchoEvent::gatherValidEchoEvents(),
),
__METHOD__,
array(
'ORDER BY' => 'notification_timestamp DESC',
'LIMIT' => 50,
),
array(
'echo_event' => array( 'left join', 'notification_event=event_id' ),
)
);
if ( !$res->numRows() ) {
$out->addWikiMsg( 'echo-none' );
return;
}
$html = '';
foreach ( $res as $row ) {
$event = EchoEvent::newFromRow( $row );
$class = 'mw-echo-notification';
// Retrieve the formatted notification to display
$formatted = EchoNotificationController::formatNotification( $event, $user, 'html' );
if ( $row->notification_read_timestamp === null ) {
$class .= ' mw-echo-unread';
}
$eventType = htmlspecialchars( $event->getType() );
$html .= "\t<li class=\"$class\" data-notification-type=\"$eventType\">$formatted</li>\n";
}
$html = "<ul>\n$html\n</ul>\n";
$out->addHTML( $html );
}
}