Bsitu has submitted this change and it was merged.

Change subject: Implementing new prefs system for Echo
......................................................................


Implementing new prefs system for Echo

Change-Id: Id745ed6cf1c92695569597fab6ea662bac8c76c0
---
M Echo.i18n.php
M Echo.php
M Hooks.php
M Notifier.php
M controller/NotificationController.php
M formatters/BasicFormatter.php
M includes/DbEmailBatch.php
M includes/EchoBackend.php
M includes/EmailBatch.php
M model/Event.php
M modules/base/ext.echo.base.css
M modules/base/ext.echo.base.js
M modules/overlay/ext.echo.overlay.js
13 files changed, 265 insertions(+), 211 deletions(-)

Approvals:
  Bsitu: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/Echo.i18n.php b/Echo.i18n.php
index 814c4bd..3c29d7b 100644
--- a/Echo.i18n.php
+++ b/Echo.i18n.php
@@ -31,9 +31,11 @@
        // Dismiss interface
        'echo-dismiss-button' => 'Dismiss',
        'echo-dismiss-message' => 'Turn off all $1 notifications',
+       'echo-dismiss-prefs-message' => 'You can turn these back on in 
Preferences',
        'echo-dismiss-title-edit-user-talk' => 'Talk page post',
        'echo-dismiss-title-article-linked' => 'Page linked',
        'echo-dismiss-title-reverted' => 'Edit reverted',
+       'echo-dismiss-title-mention' => 'Mention',
 
        // Errors
        'echo-no-agent' => '[Nobody]',
@@ -155,10 +157,11 @@
 
 $5',
        'echo-email-batch-category-header-edit-user-talk' => '$1 talk page 
{{PLURAL:$1|message|messages}}',
-       'echo-email-batch-category-header-edit-revert' => '$1 edit 
{{PLURAL:$1|revert|reverts}}',
-       'echo-email-batch-category-header-cross-reference' => '$1 
{{PLURAL:$1|cross reference|cross references}}',
+       'echo-email-batch-category-header-reverted' => '$1 
{{PLURAL:$1|edit|edits}} reverted',
+       'echo-email-batch-category-header-article-linked' => '$1 
{{PLURAL:$1|page|pages}} linked',
        'echo-email-batch-category-header-mention' => '$1 
{{PLURAL:$1|mention|mentions}}',
-       'echo-email-batch-category-header-other' => '$1 
{{PLURAL:$1|other|others}}',
+       'echo-email-batch-category-header-other' => '$1 uncategorized 
{{PLURAL:$1|notification|notifications}}',
+       'echo-email-batch-category-header-system' => '$1 system 
{{PLURAL:$1|notification|notifications}}',
 );
 
 /** Message documentation (Message documentation)
@@ -456,20 +459,20 @@
        'echo-email-batch-category-header-edit-user-talk' => 'E-mail batch 
section title for edit-user-talk category
 * $1 is the numeric count
 See also:
-* {{msg-mw|Echo-email-batch-category-header-edit-revert}}
-* {{msg-mw|Echo-email-batch-category-header-cross-reference}}
+* {{msg-mw|Echo-email-batch-category-header-reverted}}
+* {{msg-mw|Echo-email-batch-category-header-article-linked}}
 * {{msg-mw|Echo-email-batch-category-header-other}}',
-       'echo-email-batch-category-header-edit-revert' => 'E-mail batch section 
title for edit-revert category
+       'echo-email-batch-category-header-reverted' => 'E-mail batch section 
title for reverted category
 * $1 is the numeric count
 See also:
 * {{msg-mw|Echo-email-batch-category-header-edit-user-talk}}
-* {{msg-mw|Echo-email-batch-category-header-cross-reference}}
+* {{msg-mw|Echo-email-batch-category-header-article-linked}}
 * {{msg-mw|Echo-email-batch-category-header-other}}',
-       'echo-email-batch-category-header-cross-reference' => 'E-mail batch 
section title for cross-reference category
+       'echo-email-batch-category-header-article-linked' => 'E-mail batch 
section title for article-linked category
 * $1 is the numeric count
 See also:
 * {{msg-mw|Echo-email-batch-category-header-edit-user-talk}}
-* {{msg-mw|Echo-email-batch-category-header-edit-revert}}
+* {{msg-mw|Echo-email-batch-category-header-reverted}}
 * {{msg-mw|Echo-email-batch-category-header-other}}',
        'echo-email-batch-category-header-mention' => 'E-mail batch section 
title for mention category
 * $1 is the numeric count',
@@ -477,8 +480,15 @@
 * $1 is the numeric count
 See also:
 * {{msg-mw|Echo-email-batch-category-header-edit-user-talk}}
-* {{msg-mw|Echo-email-batch-category-header-edit-revert}}
-* {{msg-mw|Echo-email-batch-category-header-cross-reference}}',
+* {{msg-mw|Echo-email-batch-category-header-reverted}}
+* {{msg-mw|Echo-email-batch-category-header-article-linked}}',
+       'echo-email-batch-category-header-system' => 'E-mail batch section 
title for system events category (events without user agents)
+* $1 is the numeric count
+See also:
+* {{msg-mw|Echo-email-batch-category-header-edit-user-talk}}
+* {{msg-mw|Echo-email-batch-category-header-reverted}}
+* {{msg-mw|Echo-email-batch-category-header-article-linked}}
+* {{msg-mw|Echo-email-batch-category-header-other}}',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/Echo.php b/Echo.php
index 4581504..4f81fc2 100644
--- a/Echo.php
+++ b/Echo.php
@@ -209,11 +209,12 @@
 // The max notification count showed in badge
 $wgEchoMaxNotificationCount = 99;
 
+// Define which output formats are available for each notification category
 $wgEchoDefaultNotificationTypes = array(
        'all' => array(
                'web' => true,
                'email' => true,
-       )
+       ),
 );
 
 // Definitions of the different types of notification delivery that are 
possible.
@@ -224,65 +225,58 @@
        'email' => array( 'EchoNotifier', 'notifyWithEmail' ),
 );
 
-// Event types that should have notifications enabled.
-// The list here only includes event types handled by Echo itself. Other
-// extensions can add to this list through the BeforeCreateEchoEvent hook.
-$wgEchoEnabledEvents = array(
-       'welcome', // A user created an account
-       'edit-user-talk', // User talk page is edited
-       'reverted', // An edit is undone or rolled-back
-       'article-linked', // A page a user created is linked from another page
-       'mention', // Username is mentioned with a link on a talk page (other 
than the mentioned user)
-       // These aren't ready yet, specifically they have no means of 
subscription
-#      'add-comment', // A signed comment is added to an existing section
-#      'add-talkpage-topic', // A new section is added to a talk page
-);
-
-// This array stores the configuration info for enabled events.
-// Possible parameters include category, priority, and usergroups.
-// If an event is not specified, it means the event belongs to the
-// 'other' category with priority 10, which is the lowest,
-// priority is ranging from 1 to 10.
+// Define the categories that notifications can belong to. Categories can be
+// assigned the following parameters: priority, nodismiss, and usergroups. All
+// parameters are optional.
+// If a notifications type doesn't have a category parameter, it is
+// automatically assigned to the 'other' category which is lowest priority and
+// has no preferences or dismissibility.
+// The priority parameter controls the order in which notifications are
+// displayed in preferences and batch emails. Priority ranges from 1 to 10. If
+// the priority is not specified, it defaults to 10, which is the lowest.
 // The usergroups param specifies an array of usergroups eligible to recieve 
the
-// notification type. If no usergroups parameter exists, all groups are 
eligible.
-$wgEchoEventDetails = array(
-       'welcome' => array(
-               'nodismiss' => array( 'web', 'email' ),
-               'group' => 'positive',
+// notifications in the category. If no usergroups parameter is specified, all
+// groups are eligible.
+// The nodismiss parameter disables the dismissability of notifications in the
+// category. It can either be set to an array of output formats (see
+// $wgEchoNotifiers) or an array containing 'all'.
+$wgEchoNotificationCategories = array(
+       'system' => array(
+               'priority' => 9,
+               'no-dismiss' => array( 'all' ),
+       ),
+       'other' => array(
+               'no-dismiss' => array( 'all' ),
        ),
        'edit-user-talk' => array(
-               'category' => 'edit-user-talk',
                'priority' => 1,
-               'nodismiss' => array( 'web' ),
-               'group' => 'interactive',
+               'no-dismiss' => array( 'web' ),
        ),
        'reverted' => array(
-               'category' => 'edit-revert',
                'priority' => 9,
-               'group' => 'negative',
        ),
        'article-linked' => array(
-               'category' => 'cross-reference',
                'priority' => 5,
-               'group' => 'positive',
        ),
        'mention' => array(
-               'category' => 'mention',
                'priority' => 4,
-               'group' => 'interactive',
        ),
 );
 
 // Definitions of the notification event types built into Echo.
 // If formatter-class isn't specified, defaults to EchoBasicFormatter.
-$wgEchoNotificationFormatters = array(
+$wgEchoNotifications = array(
        'welcome' => array(
+               'category' => 'system',
+               'group' => 'positive',
                'title-message' => 'notification-new-user',
                'title-params' => array( 'agent' ),
                'payload' => array( 'welcome' ),
                'icon' => 'w',
        ),
        'edit-user-talk' => array(
+               'category' => 'edit-user-talk',
+               'group' => 'interactive',
                'formatter-class' => 'EchoEditFormatter',
                'title-message' => 'notification-edit-talk-page2',
                'title-params' => array( 'agent', 'user' ),
@@ -296,23 +290,9 @@
                'email-body-batch-params' => array( 'agent', 'difflink', 
'summary' ),
                'icon' => 'chat',
        ),
-       'add-comment' => array(
-               'formatter-class' => 'EchoCommentFormatter',
-               'title-message' => 'notification-add-comment2',
-               'title-message-yours' => 'notification-add-comment-yours2',
-               'title-params' => array( 'agent', 'subject', 'title', 
'content-page' ),
-               'payload' => array( 'snippet' ),
-               'icon' => 'chat',
-       ),
-       'add-talkpage-topic' => array(
-               'formatter-class' => 'EchoCommentFormatter',
-               'title-message' => 'notification-add-talkpage-topic2',
-               'title-message-yours' => 
'notification-add-talkpage-topic-yours2',
-               'title-params' => array( 'agent', 'subject', 'title', 
'content-page' ),
-               'payload' => array( 'snippet' ),
-               'icon' => 'chat',
-       ),
        'reverted' => array(
+               'category' => 'reverted',
+               'group' => 'negative',
                'formatter-class' => 'EchoEditFormatter',
                'title-message' => 'notification-reverted2',
                'title-params' => array( 'agent', 'title', 'difflink', 'number' 
),
@@ -328,6 +308,8 @@
                'icon' => 'revert',
        ),
        'article-linked' => array(
+               'category' => 'article-linked',
+               'group' => 'positive',
                'formatter-class' => 'EchoArticleLinkedFormatter',
                'title-message' => 'notification-article-linked2',
                'title-params' => array( 'agent', 'title',  'title-linked' ),
@@ -343,6 +325,8 @@
                'icon' => 'linked',
        ),
        'mention' => array(
+               'category' => 'mention',
+               'group' => 'interactive',
                'formatter-class' => 'EchoCommentFormatter',
                'title-message' => 'notification-mention',
                'title-params' => array( 'agent', 'subject', 'title' ),
@@ -368,15 +352,16 @@
 $wgDefaultUserOptions['echo-email-frequency'] = EchoHooks::EMAIL_IMMEDIATELY;
 
 // Set all of the events to notify by web and email by default (won't affect 
events that don't email)
-foreach ( $wgEchoEnabledEvents as $wgEchoEnabledEvent ) {
-       $wgDefaultUserOptions['echo-email-notifications' . $wgEchoEnabledEvent] 
= true;
-       $wgDefaultUserOptions['echo-web-notifications' . $wgEchoEnabledEvent] = 
true;
+foreach ( $wgEchoNotifications as $notification => $notificationData ) {
+       foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
+               
$wgDefaultUserOptions["echo-subscriptions-{$notifierType}-{$notification}"] = 
true;
+       }
 }
 // unset default email for reverted, article-linked (change them to opt-in)
-$wgDefaultUserOptions['echo-email-notificationsreverted'] = false;
-$wgDefaultUserOptions['echo-email-notificationsarticle-linked'] = false;
+$wgDefaultUserOptions['echo-subscriptions-email-reverted'] = false;
+$wgDefaultUserOptions['echo-subscriptions-email-article-linked'] = false;
 
-// Echo Configuration
+// Echo Configuration for EventLogging
 $wgEchoConfig = array(
        'version' => '1.0',
        'eventlogging' => array (
diff --git a/Hooks.php b/Hooks.php
index 801dcb6..121be5e 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -11,7 +11,12 @@
         * from $wgExtensionFunctions
         */
        public static function initEchoExtension() {
-               global $wgEchoBackend, $wgEchoBackendName;
+               global $wgEchoBackend, $wgEchoBackendName, $wgEchoNotifications,
+                       $wgEchoNotificationCategories;
+
+               // allow extensions to define their own event
+               wfRunHooks( 'BeforeCreateEchoEvent', array( 
&$wgEchoNotifications, &$wgEchoNotificationCategories ) );
+
                $wgEchoBackend = MWEchoBackend::factory( $wgEchoBackendName );
        }
 
@@ -230,7 +235,8 @@
         * @return bool true in all cases
         */
        public static function getPreferences( $user, &$preferences ) {
-               global $wgEchoDefaultNotificationTypes, $wgAuth, 
$wgEchoEnableEmailBatch, $wgEchoEventDetails;
+               global $wgEchoDefaultNotificationTypes, $wgAuth, 
$wgEchoEnableEmailBatch,
+                       $wgEchoNotifiers, $wgEchoNotificationCategories;
 
                // Show email frequency options
                $never = wfMessage( 'echo-pref-email-frequency-never' 
)->plain();
@@ -281,62 +287,74 @@
                        'section' => 'echo/emailfrequency'
                );
 
-               // Sort events by priority
-               $eventsAndPriorities = array();
-               foreach ( EchoEvent::gatherValidEchoEvents() as $enabledEvent ) 
{
-                       if ( isset( 
$wgEchoEventDetails[$enabledEvent]['priority'] ) ) {
-                               $eventsAndPriorities[$enabledEvent] = 
$wgEchoEventDetails[$enabledEvent]['priority'];
-                       } else {
-                               $eventsAndPriorities[$enabledEvent] = 10;
+               // Sort notification categories by priority
+               $categoriesAndPriorities = array();
+               foreach ( $wgEchoNotificationCategories as $category => 
$categoryData ) {
+                       // See if the category is not dismissable at all. Must 
do strict
+                       // comparison to true since no-dismiss can also be an 
array
+                       if ( isset( $categoryData['no-dismiss'] ) && in_array( 
'all' , $categoryData['no-dismiss'] ) ) {
+                               continue;
+                       }
+                       // See if user is eligible to recieve this notification 
(per user group restrictions)
+                       if ( 
EchoNotificationController::getCategoryEligibility( $user, $category ) ) {
+                               $categoriesAndPriorities[$category] = 
EchoNotificationController::getCategoryPriority( $category );
                        }
                }
-               asort( $eventsAndPriorities );
-               $eventsAndPriorities = array_keys( $eventsAndPriorities );
+               asort( $categoriesAndPriorities );
+               $validSortedCategories = array_keys( $categoriesAndPriorities );
 
                // Show subscription options
+
+               // $oldPrefs are prefs that we are replacing
                $oldPrefs['email']['edit-user-talk'] = 'enotifusertalkpages';
-               $subTypes = array( 'web', 'email' );
-               foreach ( $subTypes as $subType ) {
-                       $options = array();
-                       foreach ( $eventsAndPriorities as $enabledEvent ) {
-                               if ( isset( 
$wgEchoEventDetails[$enabledEvent]['nodismiss'] )
-                                       && in_array( $subType, 
$wgEchoEventDetails[$enabledEvent]['nodismiss'] ) )
-                               {
-                                       continue;
-                               }
-                               // Make sure notifications of this subtype are 
possible for this event
-                               if ( isset( 
$wgEchoDefaultNotificationTypes[$enabledEvent] ) ) {
-                                       if ( 
!$wgEchoDefaultNotificationTypes[$enabledEvent][$subType] ) {
-                                               continue;
-                                       }
-                               // Make sure this subtype is an available 
notification type
-                               } elseif ( 
!$wgEchoDefaultNotificationTypes['all'][$subType] ) {
-                                       continue;
-                               }
-                               // Make sure the user is eligible to recieve 
this type of notification
-                               if ( 
!EchoNotificationController::getNotificationEligibility( $user, $enabledEvent ) 
) {
-                                       continue;
-                               }
-                               $eventMessage = wfMessage( 
'echo-pref-subscription-' . $enabledEvent )->plain();
-                               $options[$eventMessage] = $enabledEvent;
-                               // overwrite other preferences, if necessary
-                               if ( isset( $oldPrefs[$subType][$enabledEvent] 
) ) {
-                                       unset( 
$preferences[$oldPrefs[$subType][$enabledEvent]] );
-                               }
-                       }
-                       $preferences['echo-' . $subType . '-notifications'] = 
array(
-                               'type' => 'multiselect',
-                               'label-message' => 'echo-pref-' . $subType,
-                               'section' => 'echo/echosubscriptions',
-                               'options' => $options,
-                       );
+
+               // Build the columns (output formats)
+               $columns = array();
+               foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
+                       $formatMessage = wfMessage( 'echo-pref-' . 
$notifierType )->plain();
+                       $columns[$formatMessage] = $notifierType;
                }
 
-               // Show fly-out display prefs
-               $preferences['echo-notify-hide-link'] = array(
-                       'type' => 'toggle',
-                       'label-message' => 'echo-pref-notify-hide-link',
-                       'section' => 'echo/displaynotifications',
+               // Build the rows (notification categories)
+               $rows = array();
+               foreach ( $validSortedCategories as $category ) {
+                       $categoryMessage = wfMessage( 'echo-pref-subscription-' 
. $category )->plain();
+                       $rows[$categoryMessage] = $category;
+               }
+
+               // Figure out the individual exceptions in the matrix and make 
them disabled
+               $removeOptions = array();
+               foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
+                       foreach ( $validSortedCategories as $category ) {
+                               // See if this output format is non-dismissable
+                               if ( isset( 
$wgEchoNotificationCategories[$category]['no-dismiss'] )
+                                       && in_array( $notifierType, 
$wgEchoNotificationCategories[$category]['no-dismiss'] ) )
+                               {
+                                       $removeOptions[] = 
"$notifierType-$category";
+                               }
+
+                               // Make sure this output format is possible for 
this notification category
+                               if ( isset( 
$wgEchoDefaultNotificationTypes[$category] ) ) {
+                                       if ( 
!$wgEchoDefaultNotificationTypes[$category][$notifierType] ) {
+                                               $removeOptions[] = 
"$notifierType-$category";
+                                       }
+                               } elseif ( 
!$wgEchoDefaultNotificationTypes['all'][$notifierType] ) {
+                                       $removeOptions[] = 
"$notifierType-$category";
+                               }
+
+                               // Unset redundant prefs while we're cycling 
through the matrix
+                               if ( isset( $oldPrefs[$notifierType][$category] 
) ) {
+                                       unset( 
$preferences[$oldPrefs[$notifierType][$category]] );
+                               }
+                       }
+               }
+
+               $preferences['echo-subscriptions'] = array(
+                       'class' => 'HTMLCheckMatrix',
+                       'section' => 'echo/echosubscriptions',
+                       'rows' => $rows,
+                       'columns' => $columns,
+                       'remove-options' => $removeOptions,
                );
                return true;
        }
@@ -357,7 +375,7 @@
         * @return bool true in all cases
         */
        public static function onArticleSaved( &$article, &$user, $text, 
$summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status 
) {
-               global $wgEchoEnabledEvents, $wgRequest;
+               global $wgEchoNotifications, $wgRequest;
                if ( $revision ) {
                        EchoEvent::create( array(
                                'type' => 'edit',
@@ -372,7 +390,7 @@
 
                        // Handle the case of someone undoing an edit, either 
through the
                        // 'undo' link in the article history or via the API.
-                       if ( in_array( 'reverted', $wgEchoEnabledEvents ) ) {
+                       if ( isset( $wgEchoNotifications['reverted'] ) ) {
                                $undidRevId = $wgRequest->getVal( 
'wpUndidRevision' );
                                if ( $undidRevId ) {
                                        $undidRevision = Revision::newFromId( 
$undidRevId );
@@ -525,8 +543,8 @@
         * @return bool true in all cases
         */
        static function disableStandUserTalkEnotif() {
-               global $wgEchoEnabledEvents, $wgEnotifUserTalk;
-               if ( in_array( 'edit-user-talk', $wgEchoEnabledEvents ) ) {
+               global $wgEchoNotifications, $wgEnotifUserTalk;
+               if ( isset( $wgEchoNotifications['edit-user-talk'] ) ) {
                        // Disable the standard email notification for talk 
page messages
                        $wgEnotifUserTalk = false;
                }
@@ -579,11 +597,11 @@
         * @return bool
         */
        static function abortNewTalkNotification( $page ) {
-               global $wgUser, $wgEchoEnabledEvents;
+               global $wgUser, $wgEchoNotifications;
                // If the user has the notifications flyout turned on and is 
receiving
                // notifications for talk page messages, disable the 
yellow-bar-style notice.
                if ( !$wgUser->getOption( 'echo-notify-hide-link' )
-                       && in_array( 'edit-user-talk', $wgEchoEnabledEvents ) )
+                       && isset( $wgEchoNotifications['edit-user-talk'] ) )
                {
                        return false;
                } else {
diff --git a/Notifier.php b/Notifier.php
index a3615fe..5029c2a 100644
--- a/Notifier.php
+++ b/Notifier.php
@@ -10,18 +10,23 @@
         * @param $event EchoEvent to notify about.
         */
        public static function notifyWithNotification( $user, $event ) {
-               global $wgEchoConfig, $wgEchoEventDetails;
+               global $wgEchoConfig, $wgEchoNotifications;
 
-               $notif = EchoNotification::create( array( 'user' => $user, 
'event' => $event ) );
+               EchoNotification::create( array( 'user' => $user, 'event' => 
$event ) );
 
                // Attempt event logging if Echo schema is enabled
                if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) {
-                       $event  = $notif->getEvent();
-                       $sender = $event->getAgent();
-                       $user   = $notif->getUser();
+                       $agent = $event->getAgent();
+                       // Typically an event should always have an agent, but 
agent could be
+                       // null if the data is corrupted
+                       if ( $agent ) {
+                               $sender = $agent->isAnon() ? $agent->getName() 
: $agent->getId();
+                       } else {
+                               $sender = 0;
+                       }
 
-                       if ( isset( 
$wgEchoEventDetails[$event->getType()]['group'] ) ) {
-                               $group = 
$wgEchoEventDetails[$event->getType()]['group'];
+                       if ( isset( 
$wgEchoNotifications[$event->getType()]['group'] ) ) {
+                               $group = 
$wgEchoNotifications[$event->getType()]['group'];
                        } else {
                                $group = 'neutral';
                        }
@@ -31,7 +36,7 @@
                                'eventId' => $event->getId(),
                                'notificationType' => $event->getType(),
                                'notificationGroup' => $group,
-                               'sender' => (string)( $sender->isAnon() ? 
$sender->getName() : $sender->getId() ),
+                               'sender' => (string)$sender,
                                'recipientUserId' => $user->getId(),
                                'recipientEditCount' => 
(int)$user->getEditCount()
                        );
@@ -54,16 +59,12 @@
                        return false;
                }
                // See if the user wants to receive emails for this type of 
event
-               if ( $user->getOption( 'echo-email-notifications' . 
$event->getType() ) ) {
-                       global $wgEchoEnableEmailBatch, $wgEchoEventDetails, 
$wgPasswordSender, $wgPasswordSenderName;
+               if ( $user->getOption( 'echo-subscriptions-email-' . 
$event->getType() ) ) {
+                       global $wgEchoEnableEmailBatch, $wgPasswordSender, 
$wgPasswordSenderName;
        
                        // batched email notification
                        if ( $wgEchoEnableEmailBatch && $user->getOption( 
'echo-email-frequency' ) > 0 ) {
-                               // default priority is 10
-                               $priority = 10;
-                               if ( isset( 
$wgEchoEventDetails[$event->getType()]['priority'] ) ) {
-                                       $priority = 
$wgEchoEventDetails[$event->getType()]['priority'];
-                               }
+                               $priority = 
EchoNotificationController::getNotificationPriority( $event->getType() );
                                MWEchoEmailBatch::addToQueue( $user->getId(), 
$event->getId(), $priority );
                                return true;
                        }
diff --git a/controller/NotificationController.php 
b/controller/NotificationController.php
index 9acea57..a3eb474 100644
--- a/controller/NotificationController.php
+++ b/controller/NotificationController.php
@@ -40,19 +40,78 @@
         * (based on user groups, not user preferences)
         *
         * @param $user User object
-        * @param $notificationType string A notification type defined in 
$wgEchoEventDetails
+        * @param $notificationType string A notification type defined in 
$wgEchoNotifications
         * @return boolean
         */
        public static function getNotificationEligibility( $user, 
$notificationType ) {
-               global $wgEchoEventDetails;
+               $category = 
EchoNotificationController::getNotificationCategory( $notificationType );
+               return EchoNotificationController::getCategoryEligibility( 
$user, $category );
+       }
+
+       /**
+        * See if a user is eligible to recieve a certain type of notification
+        * (based on user groups, not user preferences)
+        *
+        * @param $user User object
+        * @param $category string A notification category defined in 
$wgEchoNotificationCategories
+        * @return boolean
+        */
+       public static function getCategoryEligibility( $user, $category ) {
+               global $wgEchoNotificationCategories;
                $usersGroups = $user->getGroups();
-               if ( isset( 
$wgEchoEventDetails[$notificationType]['usergroups'] ) ) {
-                       $allowedGroups = 
$wgEchoEventDetails[$notificationType]['usergroups'];
+               if ( isset( 
$wgEchoNotificationCategories[$category]['usergroups'] ) ) {
+                       $allowedGroups = 
$wgEchoNotificationCategories[$category]['usergroups'];
                        if ( !array_intersect( $usersGroups, $allowedGroups ) ) 
{
                                return false;
                        }
                }
                return true;
+       }
+
+       /**
+        * Get the priority for a specific notification type
+        *
+        * @param $notificationType string A notification type defined in 
$wgEchoNotifications
+        * @return integer From 1 to 10 (10 is default)
+        */
+       public static function getNotificationPriority( $notificationType ) {
+               $category = $this->getNotificationCategory( $notificationType );
+               return EchoNotificationController::getCategoryPriority( 
$category );
+       }
+
+       /**
+        * Get the priority for a notification category
+        *
+        * @param $category string A notification category defined in 
$wgEchoNotificationCategories
+        * @return integer From 1 to 10 (10 is default)
+        */
+       public static function getCategoryPriority( $category ) {
+               global $wgEchoNotificationCategories;
+               if ( isset( 
$wgEchoNotificationCategories[$category]['priority'] ) ) {
+                       $priority = 
$wgEchoNotificationCategories[$category]['priority'];
+                       if ( $priority >= 1 && $priority <= 10 ) {
+                               return $priority;
+                       }
+               }
+               return 10;
+       }
+
+       /**
+        * Get the notification category for a notification type
+        *
+        * @param $notificationType string A notification type defined in 
$wgEchoNotifications
+        * @return String The name of the notification category or 'other' if no
+        *     category is explicitly assigned.
+        */
+       public static function getNotificationCategory( $notificationType ) {
+               global $wgEchoNotifications, $wgEchoNotificationCategories;
+               if ( isset( $wgEchoNotifications[$notificationType]['category'] 
) ) {
+                       $category = 
$wgEchoNotifications[$notificationType]['category'];
+                       if ( isset( $wgEchoNotificationCategories[$category] ) 
) {
+                               return $category;
+                       }
+               }
+               return 'other';
        }
 
        /**
@@ -240,19 +299,12 @@
         *     and body (for emails), or an error message
         */
        public static function formatNotification( $event, $user, $format = 
'text', $type = 'web' ) {
-               global $wgEchoNotificationFormatters;
+               global $wgEchoNotifications;
 
                $eventType = $event->getType();
 
-               static $runHook = true;
-               // this hook should only be executed once to gather valid 
formatter
-               if ( $runHook ) {
-                       // allow extensions to define their own notification 
formatter
-                       wfRunHooks( 'BeforeFormatEchoNotification', array( 
&$wgEchoNotificationFormatters ) );
-                       $runHook = false;
-               }
-               if ( isset( $wgEchoNotificationFormatters[$eventType] ) ) {
-                       $params = $wgEchoNotificationFormatters[$eventType];
+               if ( isset( $wgEchoNotifications[$eventType] ) ) {
+                       $params = $wgEchoNotifications[$eventType];
                        $notifier = EchoNotificationFormatter::factory( $params 
);
                        $notifier->setOutputFormat( $format );
 
diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php
index ac1721d..c45fbd4 100644
--- a/formatters/BasicFormatter.php
+++ b/formatters/BasicFormatter.php
@@ -101,7 +101,7 @@
         * @return array|string
         */
        public function format( $event, $user, $type ) {
-               global $wgEchoEventDetails;
+               global $wgEchoNotificationCategories;
 
                if ( $this->outputFormat === 'email' ) {
                        return $this->formatEmail( $event, $user, $type );
@@ -125,9 +125,13 @@
                ) . $output;
 
                // Add the hidden dismiss interface if the notification is 
dismissable
-               if ( !isset( $wgEchoEventDetails[$event->type]['nodismiss'] )
-                       || !in_array( 'web', 
$wgEchoEventDetails[$event->type]['nodismiss'] ) )
-               {
+               $category = 
EchoNotificationController::getNotificationCategory( $event->type );
+               if ( isset( 
$wgEchoNotificationCategories[$category]['no-dismiss'] ) ) {
+                       $noDismiss = 
$wgEchoNotificationCategories[$category]['no-dismiss'];
+               } else {
+                       $noDismiss = array();
+               }
+               if ( !in_array( 'web', $noDismiss ) && !in_array( 'all' , 
$noDismiss ) ) {
                        $output .= $this->formatDismissInterface( $event, $user 
);
                }
 
@@ -185,10 +189,14 @@
                $dismissTitle = wfMessage( 'echo-dismiss-title-' . $event->type 
)
                        ->inLanguage( $user->getOption( 'language' ) )
                        ->escaped();
-               $dismiss = wfMessage( 'echo-dismiss-message', $dismissTitle )
+               $dismissMessage = wfMessage( 'echo-dismiss-message', 
$dismissTitle )
                        ->inLanguage( $user->getOption( 'language' ) )
                        ->text();
-               $dismiss = Xml::tags( 'div', array( 'class' => 
'mw-echo-dismiss-message' ), $dismiss ) . "\n";
+               $dismiss = Xml::tags( 'div', array( 'class' => 
'mw-echo-dismiss-message' ), $dismissMessage ) . "\n";
+               $prefsMessage = wfMessage( 'echo-dismiss-prefs-message' )
+                       ->inLanguage( $user->getOption( 'language' ) )
+                       ->text();
+               $dismiss .= Xml::tags( 'div', array( 'class' => 
'mw-echo-prefs-dismiss-message' ), $prefsMessage ) . "\n";
                $dismiss = Xml::tags( 'div', array( 'class' => 
'mw-echo-dismiss', 'style' => 'display:none;' ), $dismiss ) . "\n";
                return $dismiss;
        }
diff --git a/includes/DbEmailBatch.php b/includes/DbEmailBatch.php
index 044b8bc..9e7b54c 100644
--- a/includes/DbEmailBatch.php
+++ b/includes/DbEmailBatch.php
@@ -33,9 +33,11 @@
         * @return array
         */
        protected function getEvents() {
+               global $wgEchoNotifications;
+
                $events = array();
 
-               $validEvents = EchoEvent::gatherValidEchoEvents();
+               $validEvents = array_keys( $wgEchoNotifications );
 
                if ( $validEvents ) {
                        $dbr = wfGetDB( DB_SLAVE );
diff --git a/includes/EchoBackend.php b/includes/EchoBackend.php
index 20b8a55..6002e36 100644
--- a/includes/EchoBackend.php
+++ b/includes/EchoBackend.php
@@ -39,18 +39,19 @@
         * @return array
         */
        protected function getUserEnabledEvents( $user, $outputFormat ) {
-               $eventTypesToLoad = EchoEvent::gatherValidEchoEvents();
-               foreach ( $eventTypesToLoad as $key => $eventType ) {
+               global $wgEchoNotifications;
+               $eventTypesToLoad = $wgEchoNotifications;
+               foreach ( $eventTypesToLoad as $eventType => $eventData ) {
                        // Make sure the user is eligible to recieve this type 
of notification
                        if ( 
!EchoNotificationController::getNotificationEligibility( $user, $eventType ) ) {
-                               unset( $eventTypesToLoad[$key] );
+                               unset( $eventTypesToLoad[$eventType] );
                        }
-                       if ( !$user->getOption( 'echo-' . $outputFormat . 
'-notifications' . $eventType ) ) {
-                               unset( $eventTypesToLoad[$key] );
+                       if ( !$user->getOption( 'echo-subscriptions-' . 
$outputFormat . '-' . $eventType ) ) {
+                               unset( $eventTypesToLoad[$eventType] );
                        }
                }
 
-               return $eventTypesToLoad;
+               return array_keys( $eventTypesToLoad );
        }
 
        /**
diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php
index 4aedf6f..fa791d7 100644
--- a/includes/EmailBatch.php
+++ b/includes/EmailBatch.php
@@ -145,13 +145,8 @@
         * Add individual event template to the big email content
         */
        protected function appendContent( $event ) {
-               global $wgEchoEventDetails;
-
                // get the category for this event
-               $category = 'other';
-               if ( isset( $wgEchoEventDetails[$event->getType()]['category'] 
) ) {
-                       $category = 
$wgEchoEventDetails[$event->getType()]['category'];
-               }
+               $category = 
EchoNotificationController::getNotificationCategory( $event->getType() );
 
                $email = EchoNotificationController::formatNotification( 
$event, $this->mUser, 'email' );
                if ( !isset( $this->content[$category] ) ) {
diff --git a/model/Event.php b/model/Event.php
index 8fc709c..ceb181a 100644
--- a/model/Event.php
+++ b/model/Event.php
@@ -60,6 +60,8 @@
         * @return EchoEvent
         */
        public static function create( $info = array() ) {
+               global $wgEchoNotifications;
+
                $obj = new EchoEvent;
                static $validFields = array( 'type', 'variant', 'agent', 
'title', 'extra' );
 
@@ -67,7 +69,7 @@
                        throw new MWException( "'type' parameter is mandatory" 
);
                }
 
-               if ( !in_array( $info['type'], self::gatherValidEchoEvents() ) 
) {
+               if ( !isset( $wgEchoNotifications[$info['type']] ) ) {
                        return false;
                }
 
@@ -101,35 +103,12 @@
        }
 
        /**
-        * Get a list of enabled Echo events, allow extensions to create their 
own events
-        */
-       public static function gatherValidEchoEvents() {
-               global $wgEchoEnabledEvents, $wgEchoEventDetails;
-
-               static $runHook = true;
-               // this hook should only be executed once to gather valid echo 
events
-               if ( $runHook ) {
-                       // allow extensions to define their own event
-                       wfRunHooks( 'BeforeCreateEchoEvent', array( 
&$wgEchoEnabledEvents, &$wgEchoEventDetails ) );
-
-                       foreach ( $wgEchoEventDetails as $event => $detail ) {
-                               if ( isset( $detail['priority'] ) && 
$detail['priority'] < 1 && $detail['priority'] > 10 ) {
-                                       throw new MWException( "$event: Valid 
event priority is ranging from 1 to 10" );
-                               }
-                       }
-
-                       $runHook = false;
-               }
-
-               return $wgEchoEnabledEvents;
-       }
-
-       /**
         * Check whether the echo event is an enabled event
         * @return bool
         */
        public function isEnabledEvent() {
-               if ( in_array( $this->getType(), self::gatherValidEchoEvents() 
) ) {
+               global $wgEchoNotifications;
+               if ( isset( $wgEchoNotifications[$this->getType()] ) ) {
                        return true;
                } else {
                        return false;
diff --git a/modules/base/ext.echo.base.css b/modules/base/ext.echo.base.css
index 8b1ae9e..01bb7b3 100644
--- a/modules/base/ext.echo.base.css
+++ b/modules/base/ext.echo.base.css
@@ -25,7 +25,7 @@
        color: #6D6D6D;
        line-height: 90%;
        margin: 0;
-       min-height: 40px;
+       min-height: 60px;
        background-color: white;
        position: relative;
        /* Force container to expand to height of floated contents */
@@ -48,10 +48,18 @@
        background-image: url(DismissOnHover.png);
 }
 .mw-echo-dismiss {
-       padding-left: 45px;
+       padding: 10px 40px 5px 60px;
        background-color: #EDEDEE;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
 }
+.mw-echo-prefs-dismiss-message {
+       font-size: 10px;
+       line-height: 14px;
+}
+.mw-echo-cancel-link {
+       margin-left: 1em;
+       cursor: pointer;
+}
diff --git a/modules/base/ext.echo.base.js b/modules/base/ext.echo.base.js
index a520c22..fb3e352 100644
--- a/modules/base/ext.echo.base.js
+++ b/modules/base/ext.echo.base.js
@@ -95,15 +95,11 @@
                        var $notification = $( closeBox ).parent();
                        $( closeBox ).hide();
                        $notification.data( 'dismiss', true );
+                       $notification.height( $notification.find( 
'.mw-echo-dismiss' ).height() - 10 );
                        $notification.find( '.mw-echo-dismiss' )
                                // Make sure the dismiss interface exactly 
covers the notification
-                               .height( $notification.height() )
                                // Icon adds 45px to the notification
                                .width( $notification.width() - 45 )
-                               .css( 'padding-top', $notification.css( 
'padding-top' ) )
-                               .css( 'padding-bottom', $notification.css( 
'padding-bottom' ) )
-                               .css( 'padding-right', $notification.css( 
'padding-right' ) )
-                               .css( 'padding-left', parseInt( 
$notification.css( 'padding-left' ) ) + 45 )
                                .show();
                        // Temprorarily ungrey-out read notifications
                        if ( !$notification.hasClass( 'mw-echo-unread' ) ) {
@@ -138,14 +134,13 @@
                                .click( function () {
                                        _this.setOptionsToken( _this.dismiss, 
$notification );
                                } );
-                       $cancelButton = $( '<button/>' )
+                       $cancelButton = $( '<a/>' )
                                .text( mw.msg( 'cancel' ) )
-                               .addClass( 'mw-echo-cancel-button' )
-                               .addClass( 'ui-button-red' )
-                               .button()
+                               .addClass( 'mw-echo-cancel-link' )
                                .click( function () {
                                        $notification.data( 'dismiss', false );
                                        $notification.find( '.mw-echo-dismiss' 
).hide();
+                                       $notification.css( 'height', 'auto' );
                                        $closebox.show();
                                        // Restore greyed-out state for read 
notifications
                                        if ( !$notification.hasClass( 
'mw-echo-unread' ) ) {
diff --git a/modules/overlay/ext.echo.overlay.js 
b/modules/overlay/ext.echo.overlay.js
index 09c0052..106c1e8 100644
--- a/modules/overlay/ext.echo.overlay.js
+++ b/modules/overlay/ext.echo.overlay.js
@@ -55,7 +55,7 @@
                                                $ul = $( '<ul 
class="mw-echo-notifications"></ul>' ),
                                                titleText = '';
 
-                                       $ul.css( 'max-height', 
notificationLimit * 85 + 'px' );
+                                       $ul.css( 'max-height', 
notificationLimit * 95 + 'px' );
                                        $.each( notifications.index, function( 
index, id ) {
                                                var data = 
notifications.list[id];
                                                var $li = $( '<li></li>' )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id745ed6cf1c92695569597fab6ea662bac8c76c0
Gerrit-PatchSet: 17
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Lwelling <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to