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 - I2a4b6938aed49e4101deb6b9351c43656a863490

Also, change 1 to One/one, per Siebrand on the task.  This can easily
be dropped/undone if we don't want it.

Also, remove reference to no-longer-existent notification-page-linked-bundle

Bug: T127288
Change-Id: Iabeaae747f99980c0610d552f6b38f89d940b890
This commit is contained in:
Matthew Flaschen 2016-03-08 23:50:31 -05:00
parent baba8154eb
commit cac85b635f
16 changed files with 98 additions and 118 deletions

View file

@ -150,10 +150,6 @@ $wgEchoSharedTrackingDB = false;
// 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 @@ $wgEchoNotifications = array(
'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',

View file

@ -1197,8 +1197,7 @@ class EchoHooks {
}
public static function onResourceLoaderGetConfigVars( &$vars ) {
global $wgEchoMaxNotificationCount;
$vars['wgEchoMaxNotificationCount'] = $wgEchoMaxNotificationCount;
$vars['wgEchoMaxNotificationCount'] = MWEchoNotifUser::MAX_BADGE_COUNT;
return true;
}

View file

@ -88,7 +88,7 @@ $wgResourceModules += array(
'oojs-ui.styles.icons-interactions',
),
'messages' => array(
'echo-notification-count',
'echo-badge-count',
'echo-overlay-link',
'echo-mark-all-as-read',
'echo-more-info',

View file

@ -77,7 +77,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]].",
@ -137,7 +137,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.",
@ -154,10 +153,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}}",
@ -170,6 +169,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-unreadlist": "A list of notification IDs to mark as unread.",

View file

@ -98,7 +98,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}}",
@ -158,7 +158,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",
@ -175,14 +174,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",
@ -191,6 +190,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 - Formatted notification count. However, for 100 or greater, 100 will be passed.",
"apihelp-echomarkread-description": "{{doc-apihelp-description|echomarkread}}",
"apihelp-echomarkread-param-list": "{{doc-apihelp-param|echomarkread|list}}",
"apihelp-echomarkread-param-unreadlist": "{{doc-apihelp-param|echomarkread|unreadlist}}",

View file

@ -266,20 +266,11 @@ class MWEchoEmailBatch {
);
}
$userLangCode = $this->mUser->getOption( 'language' );
// email subject
if ( $this->count > self::$displaySize ) {
$count = wfMessage( 'echo-notification-count' )
->inLanguage( $userLangCode )
->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( $userLangCode )
->params( $count, $this->count )->text();
->inLanguage( $this->mUser->getOption( 'language' ) )
->params( $this->count, $this->count )->text();
$toAddress = MailAddress::newFromUser( $this->mUser );
$fromAddress = new MailAddress( $wgNotificationSender, EchoHooks::getNotificationSenderName() );

View file

@ -40,6 +40,15 @@ class MWEchoNotifUser {
*/
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_BADGE_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 @@ class MWEchoNotifUser {
* @return bool
*/
public function notifCountHasReachedMax() {
global $wgEchoMaxNotificationCount;
if ( $this->getNotificationCount() > $wgEchoMaxNotificationCount ) {
if ( $this->getNotificationCount() >= self::MAX_BADGE_COUNT ) {
return true;
} else {
return false;
@ -178,7 +185,7 @@ class MWEchoNotifUser {
/**
* Retrieves number of unread notifications that a user has, would return
* $wgEchoMaxNotificationCount + 1 at most
* MWEchoNotifUser::MAX_BADGE_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)

View file

@ -22,25 +22,34 @@ class EchoNotificationController {
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_BADGE_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_BADGE_COUNT ) {
return $count;
} else {
$count = $wgLang->formatNum( $count );
return MWEchoNotifUser::MAX_BADGE_COUNT + 1;
}
}
return $count;
/**
* Format the notification count as a string. This should only be used for an
* isolated string count, e.g. as displayed in personal tools or returned by the API.
*
* If using it in sentence context, pass the value from getCappedNotificationCount
* into a message and use PLURAL. Example: notification-bundle-header-page-linked
*
* @param int count Notification count
* @return string Formatted count, after applying cap then formatting to string
*/
public static function formatNotificationCount( $count ) {
$cappedCount = self::getCappedNotificationCount( $count );
return wfMessage( 'echo-badge-count' )->numParams( $cappedCount )->text();
}
/**

View file

@ -847,21 +847,12 @@ class EchoBasicFormatter extends EchoNotificationFormatter {
}
}
// 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'] );
}
// the number used for plural support
} elseif ( $param === 'agent-other-count' ) {
$message->params( $this->bundleData['agent-other-count'] );
// agent-other-display is no longer needed for new messags, but kept for
// backwards compatibility.
} elseif ( $param === 'agent-other-count' || $param === 'agent-other-display' ) {
$message->numParams(
EchoNotificationController::getCappedNotificationCount( $this->bundleData['agent-other-count'] )
);
} elseif ( $param === 'user' ) {
$message->params( $user->getName() );
} elseif ( $param === 'title' ) {

View file

@ -45,9 +45,10 @@ class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
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() ) {

View file

@ -184,22 +184,12 @@ abstract class EchoEventPresentationModel implements JsonSerializable {
*
* @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;
}
/**

View file

@ -41,8 +41,6 @@ class EchoPageLinkFormatter extends EchoBasicFormatter {
* @param $type string deprecated
*/
protected function generateBundleData( $event, $user, $type ) {
global $wgEchoMaxNotificationCount;
$data = $this->getRawBundleData( $event, $user, $type );
if ( !$data ) {
@ -73,7 +71,7 @@ class EchoPageLinkFormatter extends EchoBasicFormatter {
$count++;
}
}
if ( $count > $wgEchoMaxNotificationCount + 1 ) {
if ( $count > MWEchoNotifUser::MAX_BADGE_COUNT + 1 ) {
break;
}
}
@ -140,24 +138,13 @@ class EchoPageLinkFormatter extends EchoBasicFormatter {
}
break;
// example: {7} other page, {99+} other pages
// example: {7} other pages, {99+} other pages
// link-from-page-other-display is no longer needed for new messages, but kept for backwards-compatibility
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'] );
}
break;
// the number used for plural support
case 'link-from-page-other-count':
$message->params( $this->bundleData['link-from-page-other-count'] );
$message->numParams(
EchoNotificationController::getCappedNotificationCount( $this->bundleData['link-from-page-other-count'] )
);
break;
default:

View file

@ -48,10 +48,11 @@ class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
$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;
}

View file

@ -116,8 +116,6 @@ class EchoUserNotificationGateway {
return 0;
}
global $wgEchoMaxNotificationCount;
$db = $this->dbFactory->getEchoDb( $dbSource );
$res = $db->select(
array(
@ -132,7 +130,7 @@ class EchoUserNotificationGateway {
'event_type' => $eventTypesToLoad,
),
__METHOD__,
array( 'LIMIT' => $wgEchoMaxNotificationCount + 1 ),
array( 'LIMIT' => MWEchoNotifUser::MAX_BADGE_COUNT + 1 ),
array(
'echo_event' => array( 'LEFT JOIN', 'notification_event=event_id' ),
)
@ -147,7 +145,7 @@ class EchoUserNotificationGateway {
/**
* 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_BADGE_COUNT
* @param string
* @return int[]
*/

View file

@ -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,9 @@
// 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 );
cappedUnreadCount = mw.language.convertNumber( cappedUnreadCount );
badgeLabel = mw.message( 'echo-badge-count', cappedUnreadCount ).text();
this.badgeButton.setLabel( badgeLabel );
}

View file

@ -44,11 +44,9 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
}
public function testNotifCountHasReachedMax() {
global $wgEchoMaxNotificationCount;
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
if ( $notifUser->getNotificationCount() > $wgEchoMaxNotificationCount ) {
if ( $notifUser->getNotificationCount() > MWEchoNotifUser::MAX_BADGE_COUNT ) {
$this->assertTrue( $notifUser->notifCountHasReachedMax() );
} else {
$this->assertFalse( $notifUser->notifCountHasReachedMax() );