Mattflaschen has uploaded a new change for review. https://gerrit.wikimedia.org/r/276096
Change subject: WIP: Make plural support for large values (100 or more) explicit in l10n ...................................................................... WIP: Make plural support for large values (100 or more) explicit in l10n This involves: * Making this value no longer admin-configurable. * Changing getNotificationCountForOutput to return only a single value Since there is no + in the formatted value anymore, we can actually use the same value for both. This is a B/C break, but hopefully worth it to simplify the method call. For now, the excess parameter is just marked unused. It could be removed at some point if the translations are updated. This must be merged at the same time as: * Flow - Ibfa56b1af9e8c56b4c5f900e0d487bc09688b2a2 * MobileFrontend - Ibf784b279d56773a227ff261b75f2b26125bbb63 (well, MF can be merged first) * translatewiki - Iabeaae747f99980c0610d552f6b38f89d940b890 Also, remove reference to no-longer-existent notification-page-linked-bundle Change-Id: Iabeaae747f99980c0610d552f6b38f89d940b890 --- M Echo.php M Hooks.php M Resources.php M i18n/en.json M i18n/qqq.json M includes/EmailBatch.php M includes/NotifUser.php M includes/controller/NotificationController.php M includes/formatters/BasicFormatter.php M includes/formatters/EditUserTalkPresentationModel.php M includes/formatters/EventPresentationModel.php M includes/formatters/PageLinkFormatter.php M includes/formatters/PageLinkedPresentationModel.php M includes/gateway/UserNotificationGateway.php M modules/ooui/mw.echo.ui.NotificationBadgeWidget.js M tests/phpunit/NotifUserTest.php 16 files changed, 91 insertions(+), 114 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/96/276096/1 diff --git a/Echo.php b/Echo.php index dd24a9b..4f9434e 100644 --- a/Echo.php +++ b/Echo.php @@ -150,10 +150,6 @@ // main one. Must be a key defined in $wgExternalServers $wgEchoSharedTrackingCluster = false; -// The max notification count showed in badge -// The max number showed in bundled message, eg, <user> and 99+ others <action> -$wgEchoMaxNotificationCount = 99; - // The max number of notifications allowed for a user to do a live update, // this is also the number of max notifications allowed for a user to have // @FIXME - the name is not intuitive, probably change it when the deleteJob patch @@ -400,8 +396,6 @@ 'formatter-class' => 'EchoPageLinkFormatter', 'title-message' => 'notification-page-linked', 'title-params' => array( 'agent', 'title', 'link-from-page' ), - 'bundle-message' => 'notification-page-linked-bundle', - 'bundle-params' => array( 'agent', 'title', 'link-from-page', 'link-from-page-other-display', 'link-from-page-other-count' ), 'email-subject-message' => 'notification-page-linked-email-subject', 'email-subject-params' => array(), 'email-body-batch-message' => 'notification-page-linked-email-batch-body', diff --git a/Hooks.php b/Hooks.php index b326795..0f40780 100644 --- a/Hooks.php +++ b/Hooks.php @@ -740,8 +740,12 @@ // Add a "My notifications" item to personal URLs $notifUser = MWEchoNotifUser::newFromUser( $user ); - $msgCount = $notifUser->getMessageCount(); - $alertCount = $notifUser->getAlertCount(); + $msgCount = EchoNotificationController::getCappedNotificationCount( + $notifUser->getMessageCount() + ); + $alertCount = EchoNotificationController::getCappedNotificationCount( + $notifUser->getAlertCount() + ); $msgNotificationTimestamp = $notifUser->getLastUnreadMessageTime(); $alertNotificationTimestamp = $notifUser->getLastUnreadAlertTime(); @@ -754,8 +758,8 @@ 'message' => $seenMsgTime ) ); - $msgText = EchoNotificationController::formatNotificationCount( $msgCount ); - $alertText = EchoNotificationController::formatNotificationCount( $alertCount ); + $msgText = $sk->msg( 'echo-badge-count' )->numParams( $msgCount )->text(); + $alertText = $sk->msg( 'echo-badge-count' )->numParams( $alertCount )->text(); $url = SpecialPage::getTitleFor( 'Notifications' )->getLocalURL(); @@ -1168,8 +1172,7 @@ } public static function onResourceLoaderGetConfigVars( &$vars ) { - global $wgEchoMaxNotificationCount; - $vars['wgEchoMaxNotificationCount'] = $wgEchoMaxNotificationCount; + $vars['wgEchoMaxNotificationCount'] = MWEchoNotifUser::MAX_NOTIFICATION_COUNT; return true; } diff --git a/Resources.php b/Resources.php index 10889ca..f6a5b92 100644 --- a/Resources.php +++ b/Resources.php @@ -87,7 +87,7 @@ 'oojs-ui.styles.icons-content', ), 'messages' => array( - 'echo-notification-count', + 'echo-badge-count', 'echo-overlay-link', 'echo-mark-all-as-read', 'echo-more-info', diff --git a/i18n/en.json b/i18n/en.json index 4e5269e..341ea3d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -76,7 +76,7 @@ "notification-body-edit-user-talk-with-section": "$1", "notification-page-linked": "[[:$2]] was {{GENDER:$1|linked}} from [[:$3]]. [[Special:WhatLinksHere/$2|See all links to this page]].", "notification-header-page-linked": "A link was made from '''$4''' to '''$3'''.", - "notification-bundle-header-page-linked": "Links were made from '''$4''' and $5 other {{PLURAL:$6|page|pages}} to '''$3'''.", + "notification-bundle-header-page-linked": "Links were made from '''$4''' and {{PLURAL:$5|one other page|$5 other pages|100=99+ other pages}} to '''$3'''.", "notification-link-text-what-links-here": "All links to this page", "notification-add-comment2": "[[User:$1|$1]] {{GENDER:$1|commented}} on \"[[$3|$2]]\" on the \"$4\" talk page.", "notification-add-talkpage-topic2": "[[User:$1|$1]] {{GENDER:$1|posted}} a new topic \"$2\" on [[$3]].", @@ -136,7 +136,6 @@ "notification-timestamp-ago-days": "{{PLURAL:$1|$1d}}", "notification-timestamp-ago-months": "{{PLURAL:$1|$1mo}}", "notification-timestamp-ago-years": "{{PLURAL:$1|$1yr}}", - "echo-notification-count": "$1+", "echo-email-subject-default": "New notification at {{SITENAME}}", "echo-email-body-default": "You have a new notification at {{SITENAME}}:\n\n$1", "echo-email-batch-body-default": "You have a new notification.", @@ -153,10 +152,10 @@ "echo-date-today": "Today", "echo-date-yesterday": "Yesterday", "echo-load-more-error": "An error occurred while fetching more results.", - "notification-edit-talk-page-bundle": "$1 and $3 {{PLURAL:$4|other|others}} {{GENDER:$1|left}} messages on your [[User talk:$2|talk page]].", - "notification-bundle-header-edit-user-talk-v2": "$1 new {{PLURAL:$2|message|messages}} on {{GENDER:$3|your}} talk page.", - "notification-edit-user-talk-email-batch-bundle-body": "$1 and $2 {{PLURAL:$3|other|others}} {{GENDER:$1|left}} a message on your talk page.", - "notification-page-linked-email-batch-bundle-body": "$2 was {{GENDER:$1|linked}} from $3 and $4 other {{PLURAL:$5|page|pages}}.", + "notification-edit-talk-page-bundle": "$1 and {{PLURAL:$3|one other|$3 others|100=99+ others}} {{GENDER:$1|left}} messages on your [[User talk:$2|talk page]].", + "notification-bundle-header-edit-user-talk-v2": "{{PLURAL:$1|one new message|$1 new messages|100=99+ new messages}} on {{GENDER:$3|your}} talk page.", + "notification-edit-user-talk-email-batch-bundle-body": "$1 and {{PLURAL:$2|one other|$2 others|100=99+ others}} {{GENDER:$1|left}} a message on your talk page.", + "notification-page-linked-email-batch-bundle-body": "$2 was {{GENDER:$1|linked}} from $3 and {{PLURAL:$4|one other page|$4 other pages|100=99+ other pages}}.", "echo-email-batch-separator": "--", "echo-email-batch-bullet": "•", "echo-email-batch-subject-daily": "You have {{PLURAL:$2|a new notification|new notifications}} at {{SITENAME}}", @@ -169,6 +168,7 @@ "notification-header-foreign-message": "More messages from {{PLURAL:$5|another wiki|$5 other wikis}}", "notification-body-foreign": "$1", "echo-foreign-wiki-lang": "$1 - $2", + "echo-badge-count": "{{PLURAL:$1|$1|100=99+}}", "apihelp-echomarkread-description": "Mark notifications as read for the current user.", "apihelp-echomarkread-param-list": "A list of notification IDs to mark as read.", "apihelp-echomarkread-param-all": "If set, marks all of a user's notifications as read.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 058695c..ed3e097 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -97,7 +97,7 @@ "notification-body-edit-user-talk-with-section": "{{optional}}\nFlyout-specific format for displaying notification body of a user talk page being edited with a new section or new comment.\n\nParameters:\n* $1 - comment left on the user talk page.\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-add-talkpage-topic2}}", "notification-page-linked": "Format for displaying notifications of articles being linked. Parameters:\n* $1 - the username of the person who linked the page, plain text. Can be used for GENDER.\n* $2 - the page being linked\n* $3 - the page linked from\nSee also:\n* {{msg-mw|Notification-page-linked-flyout}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}", "notification-header-page-linked": "Flyout-specific format for displaying notifications of articles being linked.\n\nParameters:\n* $1 - the formatted username of the person who linked the page. \n* $2 - the username for GENDER\n* $3 - the page being linked\n* $4 - the page linked from\nSee also:\n* {{msg-mw|Notification-page-linked}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}", - "notification-bundle-header-page-linked": "Bundled message for page-linked notification. Parameters:\n* $1 - the formatted username of the person who linked the page. \n* $2 - the username for GENDER\n* $3 - the page title\n* $4 - the page linked from\n* $5 - the count of other action performers, could be number or {{msg-mw|Echo-notification-count}}. e.g. 7 or 99+\n* $6 - a number used for plural support (numeric version of $5)\nSee also:\n* {{msg-mw|Notification-page-linked}}\n* {{msg-mw|Notification-page-linked-flyout}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}\n{{Related|Notification-bundle}}", + "notification-bundle-header-page-linked": "Bundled message for page-linked notification. Parameters:\n* $1 - the formatted username of the person who linked the page. \n* $2 - the username for GENDER\n* $3 - the page title\n* $4 - the page linked from\n* $5 - The number of other pages that link to this page, except that if the count is greater than 99, this value will be 100; uses standard number formatting and used for PLURAL\n* $6 - Unused\nSee also:\n* {{msg-mw|Notification-page-linked}}\n* {{msg-mw|Notification-page-linked-flyout}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}\n{{Related|Notification-bundle}}", "notification-link-text-what-links-here": "Label for link to the WhatLinksHere special page for the page being linked in this notification.", "notification-add-comment2": "Format for displaying notifications of a comment being added to an existing discussion.\n\nParameters:\n* $1 - the username of the person who edited, plain text. Can be used for GENDER.\n* $2 - the section title of the discussion\n* $3 - a link to a page and section\n* $4 - the page on which the discussion exists, plain text\nSee also:\n* {{msg-mw|Notification-add-comment-yours2}}", "notification-add-talkpage-topic2": "Format for displaying notifications of a new discussion being added. Parameters:\n* $1 - the username of the person who edited, plain text. Can be used for GENDER.\n* $2 - the section title of the discussion\n* $3 - the page on which the discussion was added, plain text\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-flyout2}}", @@ -157,7 +157,6 @@ "notification-timestamp-ago-days": "Label for the amount of time since a notification has arrived in the case where it is in order of days. This should be a very short string. $1 - Number of days", "notification-timestamp-ago-months": "Label for the amount of time since a notification has arrived in the case where it is in order of months. This should be a very short string. $1 - Number of months", "notification-timestamp-ago-years": "Label for the amount of time since a notification has arrived in the case where it is in order of years. This should be a very short string. $1 - Number of years", - "echo-notification-count": "{{optional}}\nThe new notification count next to notification link, for example: 99+\n\nParameters:\n* $1 - the count", "echo-email-subject-default": "Default subject for Echo e-mail notifications", "echo-email-body-default": "Default message content for Echo email notifications. Parameters:\n* $1 - a plain text description of the notification", "echo-email-batch-body-default": "Default message for Echo e-mail digest notifications", @@ -174,14 +173,14 @@ "echo-date-today": "The header text for today's notification section.\n{{Identical|Today}}", "echo-date-yesterday": "The header text for yesterday's notification section.\n{{Identical|Yesterday}}", "echo-load-more-error": "Error message for errors in loading more notifications", - "notification-edit-talk-page-bundle": "Bundled message for edit-user-talk notification. Parameters:\n* $1 - the name of the user who performed the action, which can be used for gender support\n* $2 - the name of the user being addressed\n* $3 - the count of other action performers, could be a number or {{msg-mw|Echo-notification-count}}. e.g. \"7\" or \"99+\"\n* $4 - a number used for plural support relating to $3 (likely identical to $3 it that is a number, and 100 otherwise)\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n* {{msg-mw|Notification-edit-talk-page-email-subject2}}", - "notification-bundle-header-edit-user-talk-v2": "Bundled header message for edit-user-talk notification. Parameters:\n* $1 - the formatted number of new messages\n* $2 - the number of new messages for PLURAL\n* $3 - the name of the user being addressed, can be used for GENDER\n{{Related|Notification-bundle}}", - "notification-edit-user-talk-email-batch-bundle-body": "Bundled message for edit-user-talk email digest notification. Parameters:\n* $1 - the username who performs the action, which can be used for gender support\n* $2 - the count of other action performers, could be number or {{msg-mw|echo-notification-count}}\n* $3 - a number used for plural support\n\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-flyout2}}\n* {{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n* {{msg-mw|Notification-edit-talk-page-email-subject2}}", - "notification-page-linked-email-batch-bundle-body": "Bundled message for page-linked email digest notification. Parameters:\n* $1 - the username who performs the action, which can be used for gender support\n* $2 - the link-to page title\n* $3 - the link-from page title\n* $4 - the count of other link-from page title, can be number or {{msg-mw|echo-notification-count}}\n* $5 - a number used for plural support (numeric version of $4)\n\nSee also:\n* {{msg-mw|Notification-page-linked}}\n* {{msg-mw|Notification-page-linked-flyout}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}", + "notification-edit-talk-page-bundle": "Bundled message for edit-user-talk notification. Parameters:\n* $1 - the name of the user who performed the action, which can be used for gender support\n* $2 - the name of the user being addressed\n* $3 - The count of other action performers, except that if the count is greater than 99, this value will be 100; uses standard number formatting and used for PLURAL\n* $4 - Unused.\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n* {{msg-mw|Notification-edit-talk-page-email-subject2}}", + "notification-bundle-header-edit-user-talk-v2": "Bundled header message for edit-user-talk notification. Parameters:\n* $1 - the number of new messages, except that if the count is greater than 99, this value will be 100; uses standard number formatting and used for PLURAL\n* $2 - Unused\n* $3 - the name of the user being addressed, can be used for GENDER\n{{Related|Notification-bundle}}", + "notification-edit-user-talk-email-batch-bundle-body": "Bundled message for edit-user-talk email digest notification. Parameters:\n* $1 - the username who performs the action, which can be used for gender support\n* $2 - The count of other action performers, except that if the count is greater than 99, this value will be 100; uses standard number formatting and used for PLURAL\n* $3 - Unused.\n\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-flyout2}}\n* {{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n* {{msg-mw|Notification-edit-talk-page-email-subject2}}", + "notification-page-linked-email-batch-bundle-body": "Bundled message for page-linked email digest notification. Parameters:\n* $1 - the username who performs the action, which can be used for gender support\n* $2 - the link-to page title\n* $3 - the link-from page title\n* $4 - The count of other pages that link to the page mentioned in the notifications, except that if the count is greater than 99, this value will be 100; uses standard number formatting and used for PLURAL\n* $5 - Unused\n\nSee also:\n* {{msg-mw|Notification-page-linked}}\n* {{msg-mw|Notification-page-linked-flyout}}\n* {{msg-mw|Notification-page-linked-email-batch-body}}\n* {{msg-mw|Notification-page-linked-email-subject}}", "echo-email-batch-separator": "{{optional}}\nEmail batch content separator", "echo-email-batch-bullet": "{{optional}}", - "echo-email-batch-subject-daily": "Daily email batch subject.\n* $1 - (Unused) could be a numeric count or \"10+\". See also: {{msg-mw|Echo-notification-count|optional message}}.\n* $2 - a numeric count, this is used for plural support\nSee also:\n* {{msg-mw|Echo-email-batch-subject-weekly}}", - "echo-email-batch-subject-weekly": "Weekly email batch subject. Parameters:\n* $1 - (Unused) could be a numeric count or \"10+\". See also: {{msg-mw|Echo-notification-count|optional message|notext=1}}\n* $2 - a numeric count, this is used for plural support\nSee also:\n* {{msg-mw|Echo-email-batch-subject-daily}}", + "echo-email-batch-subject-daily": "Daily email batch subject.\n* $1 - (Unused, Compatibility) Same as $2. \n* $2 - a numeric count, this is used for plural support\nSee also:\n* {{msg-mw|Echo-email-batch-subject-weekly}}", + "echo-email-batch-subject-weekly": "Weekly email batch subject. Parameters:\n* $1 - (Unused, Compatibility) Same as $2\n* $2 - a numeric count, this is used for plural support\nSee also:\n* {{msg-mw|Echo-email-batch-subject-daily}}", "echo-email-batch-body-intro-daily": "Introduction text for daily email digest. Parameters:\n* $1 - a username\nSee also:\n* {{msg-mw|Echo-email-batch-body-intro-weekly}}", "echo-email-batch-body-intro-weekly": "Introduction text for weekly email digest. Parameters:\n* $1 - a username\nSee also:\n* {{msg-mw|Echo-email-batch-body-intro-daily}}", "echo-email-batch-link-text-view-all-notifications": "The link text for the primary action in daily and weekly email digest", @@ -190,6 +189,7 @@ "notification-header-foreign-message": "Flyout-specific format for displaying notification header of having message notifications on foreign wikis.\n\nParameters:\n* $1 - the formatted username of the current user.\n* $2 - the username for GENDER\n* $3 (deprecated) - 1 of the foreign wikis you have notifications on\n* $4 (deprecated) - the number of remaining other wikis you have notifications on\n*$5 - the number of other wikis you have notifications on", "notification-body-foreign": "{{notranslate}}", "echo-foreign-wiki-lang": "Title of the wiki for which you're seeing foreign notifications:\n\nParameters:\n* $1 - the name of the site (e.g. 'Wikipedia', 'Wikiversity', ...)\n* $2 - the language of the website (e.g. 'English', 'Deutsch', ...)", + "echo-badge-count": "Used only for the two Echo badges shown on the personal toolbar.\nParameters:\n* $1 - Unformatted notification count. However, for 100 or greater, 100 will be passed.\n* $2 - Formatted notification count. The number from $1, formatted by MediaWiki", "apihelp-echomarkread-description": "{{doc-apihelp-description|echomarkread}}", "apihelp-echomarkread-param-list": "{{doc-apihelp-param|echomarkread|list}}", "apihelp-echomarkread-param-all": "{{doc-apihelp-param|echomarkread|all}}", diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php index 8dd895a..0f16918 100644 --- a/includes/EmailBatch.php +++ b/includes/EmailBatch.php @@ -265,19 +265,11 @@ ); } - // email subject - if ( $this->count > self::$displaySize ) { - $count = wfMessage( 'echo-notification-count' ) - ->inLanguage( $this->mUser->getOption( 'language' ) ) - ->params( self::$displaySize )->text(); - } else { - $count = $this->count; - } // Give grep a chance to find the usages: // echo-email-batch-subject-daily, echo-email-batch-subject-weekly $subject = wfMessage( 'echo-email-batch-subject-' . $frequency ) ->inLanguage( $this->mUser->getOption( 'language' ) ) - ->params( $count, $this->count )->text(); + ->params( $this->count, $this->count )->text(); $toAddress = MailAddress::newFromUser( $this->mUser ); $fromAddress = new MailAddress( $wgNotificationSender, EchoHooks::getNotificationSenderName() ); diff --git a/includes/NotifUser.php b/includes/NotifUser.php index 0d6211c..30462ae 100644 --- a/includes/NotifUser.php +++ b/includes/NotifUser.php @@ -40,6 +40,15 @@ */ private $foreignNotifications; + // The max notification count shown in badge + // + // The max number shown in bundled message, eg, <user> and 99+ others <action>. + // This is really a totally separate thing, and could be its own constant. + // + // WARNING: If you change this, you should also change all references in the + // i18n messages (100 and 99) in all repositories using Echo. + const MAX_NOTIFICATION_COUNT = 99; + /** * Usually client code doesn't need to initialize the object directly * because it could be obtained from factory method newFromUser() @@ -139,9 +148,7 @@ * @return bool */ public function notifCountHasReachedMax() { - global $wgEchoMaxNotificationCount; - - if ( $this->getNotificationCount() > $wgEchoMaxNotificationCount ) { + if ( $this->getNotificationCount() >= self::MAX_NOTIFICATION_COUNT ) { return true; } else { return false; @@ -178,7 +185,7 @@ /** * Retrieves number of unread notifications that a user has, would return - * $wgEchoMaxNotificationCount + 1 at most + * MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1 at most * * @param boolean $cached Set to false to bypass the cache. (Optional. Defaults to true) * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_SLAVE) diff --git a/includes/controller/NotificationController.php b/includes/controller/NotificationController.php index 8ac744b..b417095 100644 --- a/includes/controller/NotificationController.php +++ b/includes/controller/NotificationController.php @@ -22,25 +22,18 @@ static protected $userWhitelist; /** - * Format the notification count with Language::formatNum(). In addition, for large count, - * return abbreviated version, e.g. 99+ + * Returns the count passed in, or MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1, + * whichever is less. * * @param int $count - * @return string + * @return int Notification count, with ceiling applied */ - public static function formatNotificationCount( $count ) { - global $wgLang, $wgEchoMaxNotificationCount; - - if ( $count > $wgEchoMaxNotificationCount ) { - $count = wfMessage( - 'echo-notification-count', - $wgLang->formatNum( $wgEchoMaxNotificationCount ) - )->escaped(); + public static function getCappedNotificationCount( $count ) { + if ( $count <= MWEchoNotifUser::MAX_NOTIFICATION_COUNT ) { + return $count; } else { - $count = $wgLang->formatNum( $count ); + return MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1; } - - return $count; } /** diff --git a/includes/formatters/BasicFormatter.php b/includes/formatters/BasicFormatter.php index e353db6..f0af8c3 100644 --- a/includes/formatters/BasicFormatter.php +++ b/includes/formatters/BasicFormatter.php @@ -848,20 +848,15 @@ } // example: {7} others, {99+} others } elseif ( $param === 'agent-other-display' ) { - global $wgEchoMaxNotificationCount; - - if ( $this->bundleData['agent-other-count'] > $wgEchoMaxNotificationCount ) { - $message->params( - $this->getMessage( 'echo-notification-count' ) - ->numParams( $wgEchoMaxNotificationCount ) - ->text() - ); - } else { - $message->numParams( $this->bundleData['agent-other-count'] ); - } + $message->numParams( + EchoNotificationController::getCappedNotificationCount( $this->bundleData['agent-other-count'] ) + ); + } // the number used for plural support } elseif ( $param === 'agent-other-count' ) { - $message->params( $this->bundleData['agent-other-count'] ); + $message->params( + EchoNotificationController::getCappedNotificationCount( $this->bundleData['agent-other-count'] ) + ); } elseif ( $param === 'user' ) { $message->params( $user->getName() ); } elseif ( $param === 'title' ) { diff --git a/includes/formatters/EditUserTalkPresentationModel.php b/includes/formatters/EditUserTalkPresentationModel.php index 1af5ea1..1ed2bc4 100644 --- a/includes/formatters/EditUserTalkPresentationModel.php +++ b/includes/formatters/EditUserTalkPresentationModel.php @@ -45,9 +45,10 @@ public function getHeaderMessage() { if ( $this->isBundled() ) { $msg = $this->msg( "notification-bundle-header-{$this->type}-v2" ); - list( $formattedCount, $countForPlural ) = $this->getNotificationCountForOutput(); - $msg->params( $formattedCount ); - $msg->params( $countForPlural ); + $count = $this->getNotificationCountForOutput(); + + // Repeat is B/C until unused parameter is removed from translations + $msg->numParams( $count, $count ); $msg->params( $this->getViewingUserForGender() ); return $msg; } elseif ( $this->hasSection() ) { diff --git a/includes/formatters/EventPresentationModel.php b/includes/formatters/EventPresentationModel.php index fd4dffa..094faf2 100644 --- a/includes/formatters/EventPresentationModel.php +++ b/includes/formatters/EventPresentationModel.php @@ -184,22 +184,12 @@ * * @param bool $includeCurrent * @param callable $groupCallback - * @return array ['number for display', 'number for PLURAL'] + * @return count */ final protected function getNotificationCountForOutput( $includeCurrent = true, $groupCallback = null ) { - global $wgEchoMaxNotificationCount; $count = $this->getBundleCount( $includeCurrent, $groupCallback ); - if ( $count > $wgEchoMaxNotificationCount ) { - return array( - $this->msg( 'echo-notification-count' )->numParams( $wgEchoMaxNotificationCount )->text(), - $wgEchoMaxNotificationCount - ); - } else { - return array( - $this->language->formatNum( $count ), - $count - ); - } + $cappedCount = EchoNotificationController::getCappedNotificationCount( $count ); + return $cappedCount; } /** diff --git a/includes/formatters/PageLinkFormatter.php b/includes/formatters/PageLinkFormatter.php index 778c476..c2bfd27 100644 --- a/includes/formatters/PageLinkFormatter.php +++ b/includes/formatters/PageLinkFormatter.php @@ -41,8 +41,6 @@ * @param $type string deprecated */ protected function generateBundleData( $event, $user, $type ) { - global $wgEchoMaxNotificationCount; - $data = $this->getRawBundleData( $event, $user, $type ); if ( !$data ) { @@ -73,7 +71,7 @@ $count++; } } - if ( $count > $wgEchoMaxNotificationCount + 1 ) { + if ( $count > MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1 ) { break; } } @@ -142,22 +140,16 @@ // example: {7} other page, {99+} other pages case 'link-from-page-other-display': - global $wgEchoMaxNotificationCount; - - if ( $this->bundleData['link-from-page-other-count'] > $wgEchoMaxNotificationCount ) { - $message->params( - $this->getMessage( 'echo-notification-count' ) - ->numParams( $wgEchoMaxNotificationCount ) - ->text() - ); - } else { - $message->numParams( $this->bundleData['link-from-page-other-count'] ); - } + $message->numParams( + EchoNotificationController::getCappedNotificationCount( $this->bundleData['link-from-page-other-count'] ); + ); break; // the number used for plural support case 'link-from-page-other-count': - $message->params( $this->bundleData['link-from-page-other-count'] ); + $message->params( + EchoNotificationController::getCappedNotificationCount( $this->bundleData['link-from-page-other-count'] ) + ); break; default: diff --git a/includes/formatters/PageLinkedPresentationModel.php b/includes/formatters/PageLinkedPresentationModel.php index c94ac39..de1f86a 100644 --- a/includes/formatters/PageLinkedPresentationModel.php +++ b/includes/formatters/PageLinkedPresentationModel.php @@ -48,10 +48,11 @@ $msg = parent::getHeaderMessage(); $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); $msg->params( $this->getTruncatedTitleText( $this->getPageFrom(), true ) ); - list( $formattedCount, $countForPlural ) = + $count = $this->getNotificationCountForOutput( false, array( $this, 'getLinkedPageId' ) ); - $msg->params( $formattedCount ); - $msg->params( $countForPlural ); + + // Repeat is B/C until unused parameter is removed from translations + $msg->numParams( $count, $count ); return $msg; } diff --git a/includes/gateway/UserNotificationGateway.php b/includes/gateway/UserNotificationGateway.php index 264c6c4..052be82 100644 --- a/includes/gateway/UserNotificationGateway.php +++ b/includes/gateway/UserNotificationGateway.php @@ -92,8 +92,6 @@ return 0; } - global $wgEchoMaxNotificationCount; - $db = $this->dbFactory->getEchoDb( $dbSource ); $res = $db->select( array( @@ -108,7 +106,7 @@ 'event_type' => $eventTypesToLoad, ), __METHOD__, - array( 'LIMIT' => $wgEchoMaxNotificationCount + 1 ), + array( 'LIMIT' => MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1 ), array( 'echo_event' => array( 'LEFT JOIN', 'notification_event=event_id' ), ) @@ -123,7 +121,7 @@ /** * IMPORTANT: should only call this function if the number of unread notification * is reasonable, for example, unread notification count is less than the max - * display defined in $wgEchoMaxNotificationCount + * display defined in MWEchoNotifUser::MAX_NOTIFICATION_COUNT * @param string * @return int[] */ diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js index 840ba12..7f28ab3 100644 --- a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js +++ b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js @@ -46,6 +46,7 @@ this.notificationsModel = model; this.type = this.notificationsModel.getType(); + this.maxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' ); this.numItems = config.numItems || 0; this.markReadWhenSeen = !!config.markReadWhenSeen; this.badgeIcon = config.badgeIcon || {}; @@ -212,14 +213,30 @@ this.popupHeadIcon.setIcon( icon ); }; + // Client-side version of NotificationController::getCappedNotificationCount. + /** + * Gets the count to use for display + * + * @param {number} count Count before cap is applied + * + * @return {number} Count with cap applied + */ + mw.echo.ui.NotificationBadgeWidget.prototype.getCappedNotificationCount = function ( count ) { + if ( count <= this.maxNotificationCount ) { + return count; + } else { + return this.maxNotificationCount + 1; + } + }; + /** * Update the badge state and label based on changes to the model */ mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () { var unseenCount = this.notificationsModel.getUnseenCount(), unreadCount = this.notificationsModel.getUnreadCount(), + cappedUnreadCount, nonBundledUnreadCount = this.notificationsModel.getNonbundledUnreadCount(), - wgEchoMaxNotificationCount, badgeLabel; // Update numbers and seen/unseen state @@ -237,12 +254,8 @@ // Update badge count if ( !this.markReadWhenSeen || !this.popup.isVisible() || unreadCount < this.currentUnreadCountInBadge ) { - wgEchoMaxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' ); - if ( unreadCount > wgEchoMaxNotificationCount ) { - badgeLabel = mw.message( 'echo-notification-count', wgEchoMaxNotificationCount ).text(); - } else { - badgeLabel = mw.language.convertNumber( unreadCount ); - } + cappedUnreadCount = this.getCappedNotificationCount( unreadCount ); + badgeLabel = mw.message( 'echo-badge-count', cappedUnreadCount ).text(); this.badgeButton.setLabel( badgeLabel ); } diff --git a/tests/phpunit/NotifUserTest.php b/tests/phpunit/NotifUserTest.php index e4b29ea..06cb97a 100644 --- a/tests/phpunit/NotifUserTest.php +++ b/tests/phpunit/NotifUserTest.php @@ -44,11 +44,9 @@ } public function testNotifCountHasReachedMax() { - global $wgEchoMaxNotificationCount; - $notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) ); - if ( $notifUser->getNotificationCount() > $wgEchoMaxNotificationCount ) { + if ( $notifUser->getNotificationCount() > MWEchoNotifUser::MAX_NOTIFICATION_COUNT ) { $this->assertTrue( $notifUser->notifCountHasReachedMax() ); } else { $this->assertFalse( $notifUser->notifCountHasReachedMax() ); -- To view, visit https://gerrit.wikimedia.org/r/276096 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iabeaae747f99980c0610d552f6b38f89d940b890 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits