jenkins-bot has submitted this change and it was merged.

Change subject: Add new messages indicator from a hook
......................................................................


Add new messages indicator from a hook

So it works for users without JavaScript

Bug: 56974
Change-Id: I0652a740ca7156257d4459931d80872877339c0d
---
M Echo.php
M Hooks.php
D modules/alert/ext.echo.alert.js
3 files changed, 33 insertions(+), 42 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Echo.php b/Echo.php
index e814af2..d78262b 100644
--- a/Echo.php
+++ b/Echo.php
@@ -203,16 +203,10 @@
                'position' => 'top',
        ),
        'ext.echo.alert' => $echoResourceTemplate + array(
-               'scripts' => array(
-                       'alert/ext.echo.alert.js',
-               ),
                'styles' => 'alert/ext.echo.alert.css',
                'skinStyles' => array(
                        'modern' => 'alert/ext.echo.alert.modern.css',
                        'monobook' => 'alert/ext.echo.alert.monobook.css',
-               ),
-               'messages' => array(
-                       'echo-new-messages',
                ),
        ),
        'ext.echo.badge' => $echoResourceTemplate + array(
diff --git a/Hooks.php b/Hooks.php
index 36cf479..b2637a1 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -627,7 +627,6 @@
         * @return bool true in all cases
         */
        static function beforePageDisplay( $out, $skin ) {
-               global $wgEchoNewMsgAlert;
                $user = $out->getUser();
 
                // Don't show the alert message and badge if echo is disabled 
for this user
@@ -641,9 +640,7 @@
                        // Load the styles for the Notifications badge
                        $out->addModuleStyles( 'ext.echo.badge' );
                }
-               if ( $wgEchoNewMsgAlert && $user->isLoggedIn() && 
$user->getOption( 'echo-show-alert' ) ) {
-                       $out->addModules( array( 'ext.echo.alert' ) );
-               }
+
                return true;
        }
 
@@ -653,32 +650,44 @@
         * @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
         * @param &$personal_urls Array of URLs to append to.
         * @param &$title Title of page being visited.
+        * @param SkinTemplate $sk
         * @return bool true in all cases
         */
-       static function onPersonalUrls( &$personal_urls, &$title ) {
-               global $wgUser;
-               // Add a "My notifications" item to personal URLs
-               if ( $wgUser->isAnon() || self::isEchoDisabled( $wgUser ) || 
!$wgUser->getOption( 'echo-notify-show-link' ) ) {
+       static function onPersonalUrls( &$personal_urls, &$title, $sk ) {
+               global $wgEchoNewMsgAlert;
+               $user = $sk->getUser();
+               if ( $user->isAnon() || self::isEchoDisabled( $user ) ) {
                        return true;
                }
 
-               $notificationCount = MWEchoNotifUser::newFromUser( $wgUser 
)->getNotificationCount();
-               $text = EchoNotificationController::formatNotificationCount( 
$notificationCount );
-               $url = SpecialPage::getTitleFor( 'Notifications' 
)->getLocalURL();
-               if ( $notificationCount == 0 ) {
-                       $linkClasses = array( 'mw-echo-notifications-badge' );
-               } else {
-                       $linkClasses = array( 'mw-echo-unread-notifications', 
'mw-echo-notifications-badge' );
-               }
-               $notificationsLink = array(
-                       'href' => $url,
-                       'text' => $text,
-                       'active' => ( $url == $title->getLocalUrl() ),
-                       'class' => $linkClasses,
-               );
+               // Add a "My notifications" item to personal URLs
+               if ( $user->getOption( 'echo-notify-show-link' ) ) {
+                       $notificationCount = MWEchoNotifUser::newFromUser( 
$user )->getNotificationCount();
+                       $text = 
EchoNotificationController::formatNotificationCount( $notificationCount );
+                       $url = SpecialPage::getTitleFor( 'Notifications' 
)->getLocalURL();
+                       if ( $notificationCount == 0 ) {
+                               $linkClasses = array( 
'mw-echo-notifications-badge' );
+                       } else {
+                               $linkClasses = array( 
'mw-echo-unread-notifications', 'mw-echo-notifications-badge' );
+                       }
+                       $notificationsLink = array(
+                               'href' => $url,
+                               'text' => $text,
+                               'active' => ( $url == $title->getLocalUrl() ),
+                               'class' => $linkClasses,
+                       );
 
-               $insertUrls = array( 'notifications' => $notificationsLink );
-               $personal_urls = wfArrayInsertAfter( $personal_urls, 
$insertUrls, 'userpage' );
+                       $insertUrls = array( 'notifications' => 
$notificationsLink );
+                       $personal_urls = wfArrayInsertAfter( $personal_urls, 
$insertUrls, 'userpage' );
+               }
+
+               // If the user has new messages, display a talk page alert
+               if ( $wgEchoNewMsgAlert && $user->getOption( 'echo-show-alert' 
) && $user->getNewtalk() ) {
+                       $personal_urls['mytalk']['text'] = $sk->msg( 
'echo-new-messages' )->text();
+                       $personal_urls['mytalk']['class'] = array( 
'mw-echo-alert' );
+                       $sk->getOutput()->addModuleStyles( 'ext.echo.alert' );
+               }
+
                return true;
        }
 
diff --git a/modules/alert/ext.echo.alert.js b/modules/alert/ext.echo.alert.js
deleted file mode 100644
index a53321d..0000000
--- a/modules/alert/ext.echo.alert.js
+++ /dev/null
@@ -1,12 +0,0 @@
-( function ( $, mw ) {
-       'use strict';
-       // TODO: What is this extra echoNewMsgAlertDisplayed check for? This 
should only run once
-       // and that variable isn't used anywhere else in the repository.
-       if ( mw.config.get( 'wgUserNewMsgRevisionId' ) && !mw.config.get( 
'echoNewMsgAlertDisplayed' ) ) {
-               $( '#pt-mytalk a' )
-                       .text( mw.msg( 'echo-new-messages' ) )
-                       .addClass( 'mw-echo-alert' );
-
-               mw.config.set( 'echoNewMsgAlertDisplayed', true );
-       }
-} )( jQuery, mediaWiki );

-- 
To view, visit https://gerrit.wikimedia.org/r/95102
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0652a740ca7156257d4459931d80872877339c0d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to