diff --git a/Echo.php b/Echo.php index 29d78ced7..d4777f5ad 100644 --- a/Echo.php +++ b/Echo.php @@ -152,6 +152,16 @@ $wgResourceModules += array( ), 'targets' => array( 'desktop', 'mobile' ), ), + 'ext.echo.desktop' => $echoResourceTemplate + array( + 'scripts' => 'desktop/ext.echo.desktop.js', + 'dependencies' => array( + 'ext.echo.base', + 'mediawiki.api', + 'mediawiki.Uri', + 'mediawiki.jqueryMsg', + 'mediawiki.user', + ), + ), 'ext.echo.overlay' => $echoResourceTemplate + array( 'scripts' => array( 'overlay/ext.echo.overlay.js', @@ -162,12 +172,8 @@ $wgResourceModules += array( 'monobook' => 'overlay/ext.echo.overlay.monobook.css', ), 'dependencies' => array( - 'ext.echo.base', - 'mediawiki.api', - 'mediawiki.Uri', + 'ext.echo.desktop', 'mediawiki.util', - 'mediawiki.jqueryMsg', - 'mediawiki.user', ), 'messages' => array( 'echo-overlay-title', @@ -185,12 +191,8 @@ $wgResourceModules += array( ), 'styles' => 'special/ext.echo.special.css', 'dependencies' => array( - 'ext.echo.base', - 'mediawiki.api', - 'mediawiki.Uri', + 'ext.echo.desktop', 'mediawiki.ui', - 'mediawiki.jqueryMsg', - 'mediawiki.user', ), 'messages' => array( 'echo-load-more-error', diff --git a/api/ApiEchoMarkRead.php b/api/ApiEchoMarkRead.php index 5467af764..6183e0534 100644 --- a/api/ApiEchoMarkRead.php +++ b/api/ApiEchoMarkRead.php @@ -29,7 +29,13 @@ class ApiEchoMarkRead extends ApiBase { } } - $result = array( 'result' => 'success', 'count' => $notifUser->getFormattedNotificationCount() ); + $rawCount = $notifUser->getNotificationCount(); + + $result = array( + 'result' => 'success', + 'rawcount' => $rawCount, + 'count' => EchoNotificationController::formatNotificationCount( $rawCount ), + ); $this->getResult()->addValue( 'query', $this->getModuleName(), $result ); } @@ -45,6 +51,7 @@ class ApiEchoMarkRead extends ApiBase { 'token' => array( ApiBase::PARAM_REQUIRED => true, ), + 'uselang' => null ); } @@ -53,6 +60,7 @@ class ApiEchoMarkRead extends ApiBase { 'list' => 'A list of notification IDs to mark as read', 'all' => "If set to true, marks all of a user's notifications as read", 'token' => 'edit token', + 'uselang' => 'the desired language to format the output' ); } diff --git a/api/ApiEchoNotifications.php b/api/ApiEchoNotifications.php index af827f106..a570b61e6 100644 --- a/api/ApiEchoNotifications.php +++ b/api/ApiEchoNotifications.php @@ -50,7 +50,9 @@ class ApiEchoNotifications extends ApiQueryBase { } if ( in_array( 'count', $prop ) ) { - $result['count'] = $notifUser->getFormattedNotificationCount(); + $rawCount = $notifUser->getNotificationCount(); + $result['rawcount'] = $rawCount; + $result['count'] = EchoNotificationController::formatNotificationCount( $rawCount ); } if ( in_array( 'index', $prop ) ) { diff --git a/modules/desktop/ext.echo.desktop.js b/modules/desktop/ext.echo.desktop.js new file mode 100644 index 000000000..d2be57f7f --- /dev/null +++ b/modules/desktop/ext.echo.desktop.js @@ -0,0 +1,20 @@ +( function ( $, mw ) { + 'use strict'; + + // Functions that are only available to echo desktop version + mw.echo.desktop = { + /** + * Append uselang param to API get/post data if applicable + * @param apiData {Object} + */ + appendUseLang: function ( apiData ) { + var curUri = new mw.Uri(); + if ( curUri.query.uselang !== undefined ) { + apiData.uselang = curUri.query.uselang; + } + + return apiData; + } + }; + +} )( jQuery, mediaWiki ); diff --git a/modules/overlay/ext.echo.overlay.js b/modules/overlay/ext.echo.overlay.js index 8d5c60e74..55ddda8fc 100644 --- a/modules/overlay/ext.echo.overlay.js +++ b/modules/overlay/ext.echo.overlay.js @@ -4,12 +4,15 @@ mw.echo.overlay = { - updateCount: function ( newCount ) { + /** + * @param newCount formatted count + * @param rawCount unformatted count + */ + updateCount: function ( newCount, rawCount ) { var $badge = $( '.mw-echo-notifications-badge' ); $badge.text( newCount ); - // newCount could be '99+' or another string. - // Checking for number as well just to be paranoid. - if ( newCount !== '0' && newCount !== 0 ) { + + if ( rawCount !== '0' && rawCount !== 0 ) { $badge.addClass( 'mw-echo-unread-notifications' ); } else { $badge.removeClass( 'mw-echo-unread-notifications' ); @@ -24,7 +27,6 @@ $prefLink = $( '#pt-preferences a' ), count = 0, apiData, - curUri = new mw.Uri(), api = new mw.Api( { ajax: { cache: false } } ); // Set notification limit based on height of the window @@ -44,14 +46,11 @@ 'notprop' : 'index|list|count' }; - if ( curUri.query.uselang !== undefined ) { - apiData.uselang = curUri.query.uselang; - } - - api.get( apiData ).done( function ( result ) { + api.get( mw.echo.desktop.appendUseLang( apiData ) ).done( function ( result ) { var notifications = result.query.notifications, unread = [], unreadTotalCount = result.query.notifications.count, + unreadRawTotalCount = result.query.notifications.rawcount, $title = $( '
' ), $ul = $( '