From fc7e18ba8eb4b6731ec6845775bb0f00f24a32d7 Mon Sep 17 00:00:00 2001 From: theopolisme Date: Wed, 20 Nov 2013 15:52:14 -0600 Subject: [PATCH] Mention: notify correctly if there is no section title If a user is mentioned in an area that does not have a section title (for example, the lead section of a talk page), use the new 'notification-mention-nosection' message, to avoid an awkward and incorrect "[[Page#|]]". Bug: 52507 Change-Id: I40628b76c460c79008053222c9780bb23549731d --- Echo.i18n.php | 30 +++++++++++++++++++++++++----- Echo.php | 3 ++- formatters/EditFormatter.php | 2 ++ formatters/MentionFormatter.php | 27 +++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 formatters/MentionFormatter.php diff --git a/Echo.i18n.php b/Echo.i18n.php index 332fa89e3..c7635624a 100644 --- a/Echo.i18n.php +++ b/Echo.i18n.php @@ -82,8 +82,10 @@ $messages['en'] = array( 'notification-add-talkpage-topic2' => '[[User:$1|$1]] {{GENDER:$1|posted}} a new topic "$2" on [[$3]].', 'notification-add-talkpage-topic-yours2' => '[[User:$1|$1]] {{GENDER:$1|sent}} you a message: "[[$3#$2|$2]]".', 'notification-add-comment-yours2' => '[[User:$1|$1]] {{GENDER:$1|commented}} on "[[$3#$2|$2]]" on your talk page.', - 'notification-mention' => '[[User:$1|$1]] {{GENDER:$1|mentioned}} you on $5 talk page in "[[$3#$2|$4]]".', - 'notification-mention-flyout' => '$1 {{GENDER:$1|mentioned}} you on $5 talk page in "[[$3#$2|$4]]".', + 'notification-mention' => '[[User:$1|$1]] {{GENDER:$1|mentioned}} you on the $5 talk page in "[[$3#$2|$4]]".', + 'notification-mention-flyout' => '$1 {{GENDER:$1|mentioned}} you on the $5 talk page in "[[$3#$2|$4]]".', + 'notification-mention-nosection' => '[[User:$1|$1]] {{GENDER:$1|mentioned}} you on the [[$3|$2 talk page]].', + 'notification-mention-nosection-flyout' => '$1 {{GENDER:$1|mentioned}} you on the [[$3|$2 talk page]].', 'notification-user-rights' => 'Your user rights [[Special:Log/rights/$1|were {{GENDER:$1|changed}}]] by [[User:$1|$1]]. $2. [[Special:ListGroupRights|Learn more]]', 'notification-user-rights-flyout' => 'Your user rights were {{GENDER:$1|changed}} by $1. $2. [[Special:ListGroupRights|Learn more]]', 'notification-user-rights-add' => 'You are now a member of {{PLURAL:$2|this group|these groups}}: $1', @@ -99,7 +101,8 @@ $messages['en'] = array( 'notification-reverted-email-subject2' => 'Your {{PLURAL:$3|edit was|edits were}} {{GENDER:$1|reverted}} on {{SITENAME}}', 'notification-reverted-email-batch-body2' => 'Your {{PLURAL:$3|edit on $2 has been|edits on $2 have been}} {{GENDER:$1|reverted}} by $1.', 'notification-mention-email-subject' => '$1 {{GENDER:$1|mentioned}} you on {{SITENAME}}', - 'notification-mention-email-batch-body' => '$1 {{GENDER:$1|mentioned}} you on $4 talk page in "$3".', + 'notification-mention-email-batch-body' => '$1 {{GENDER:$1|mentioned}} you on the $4 talk page in "$3".', + 'notification-mention-nosection-email-batch-body' => '$1 {{GENDER:$1|mentioned}} you on the $2 talk page.', 'notification-user-rights-email-subject' => 'Your user rights have changed on {{SITENAME}}', 'notification-user-rights-email-batch-body' => 'Your user rights were {{GENDER:$1|changed}} by $1. $2.', 'echo-notification-count' => '$1+', @@ -373,19 +376,28 @@ See also: * $3 - link to user talk page See also: * {{msg-mw|Notification-add-comment2}}', - 'notification-mention' => "Format for displaying notifications of a comment including a link to another user's user page. Parameters: + 'notification-mention' => "Format for displaying notifications of a comment in a specific section including a link to another user's user page. Parameters: * $1 - the username of the person who edited, plain text. Can be used for GENDER * $2 - the section title of the discussion * $3 - the page title of the discussion * $4 - the raw section title text * $5 - the title text without namespace (a page title in any namespace)", - 'notification-mention-flyout' => "Flyout-specific format for displaying notifications of a comment including a link to another user's user page. + 'notification-mention-flyout' => "Flyout-specific format for displaying notifications of a comment in a specific section. Parameters: * $1 - the username of the person who mentioned you, plain text. Can be used for GENDER. * $2 - the section title of the discussion * $3 - the page title of the discussion * $4 - the raw section title text * $5 - the title text without namespace (a page title in any namespace)", + 'notification-mention-nosection' => "Format for displaying notifications of a comment including a link to another user's user page. Parameters: +* $1 - the username of the person who edited, plain text. Can be used for GENDER +* $2 - the title text without namespace (a page title in any namespace) +* $3 - the page title of the discussion", + 'notification-mention-nosection-flyout' => "Flyout-specific format for displaying notifications of a comment. +Parameters: +* $1 - the username of the person who edited, plain text. Can be used for GENDER +* $2 - the title text without namespace (a page title in any namespace) +* $3 - the page title of the discussion", 'notification-user-rights' => 'Format for displaying notifications of a user right change in notification page. Parameters: * $1 is the username of the person who made the user right change. Can be used for GENDER support * $2 is a semicolon separated list of {{msg-mw|notification-user-rights-add}}, {{msg-mw|notification-user-rights-remove}}', @@ -473,6 +485,14 @@ See also: See also: * {{msg-mw|Notification-mention}} * {{msg-mw|Notification-mention-flyout}} +* {{msg-mw|Notification-mention-email-subject}}', + 'notification-mention-nosection-email-batch-body' => 'E-mail notification batch body. Parameters: +* $1 - a username, plaintext. Can be used for gender support +* $2 - the title text without namespace (a page title in any namespace) + +See also: +* {{msg-mw|Notification-mention-nosection}} +* {{msg-mw|Notification-mention-nosection-flyout}} * {{msg-mw|Notification-mention-email-subject}}', 'notification-user-rights-email-subject' => 'E-mail subject for user rights notification diff --git a/Echo.php b/Echo.php index ab502c8be..e814af26a 100644 --- a/Echo.php +++ b/Echo.php @@ -60,6 +60,7 @@ $wgAutoloadClasses['EchoNotificationFormatter'] = $dir . 'formatters/Notificatio $wgAutoloadClasses['EchoBasicFormatter'] = $dir . 'formatters/BasicFormatter.php'; $wgAutoloadClasses['EchoEditFormatter'] = $dir . 'formatters/EditFormatter.php'; $wgAutoloadClasses['EchoCommentFormatter'] = $dir . 'formatters/CommentFormatter.php'; +$wgAutoloadClasses['EchoMentionFormatter'] = $dir . 'formatters/MentionFormatter.php'; $wgAutoloadClasses['EchoUserRightsFormatter'] = $dir . 'formatters/UserRightsFormatter.php'; $wgAutoloadClasses['EchoPageLinkFormatter'] = $dir . 'formatters/PageLinkFormatter.php'; $wgAutoloadClasses['EchoEditUserTalkFormatter'] = $dir . 'formatters/EditUserTalkFormatter.php'; @@ -494,7 +495,7 @@ $wgEchoNotifications = array( 'secondary-link' => array( 'message' => 'notification-link-text-view-changes', 'destination' => 'diff' ), 'category' => 'mention', 'group' => 'interactive', - 'formatter-class' => 'EchoCommentFormatter', + 'formatter-class' => 'EchoMentionFormatter', 'title-message' => 'notification-mention', 'title-params' => array( 'agent', 'subject-anchor', 'title', 'section-title', 'main-title-text' ), 'flyout-message' => 'notification-mention-flyout', diff --git a/formatters/EditFormatter.php b/formatters/EditFormatter.php index eb5474aad..4c9058bd1 100644 --- a/formatters/EditFormatter.php +++ b/formatters/EditFormatter.php @@ -64,6 +64,8 @@ class EchoEditFormatter extends EchoBasicFormatter { if ( !empty( $extra['section-title'] ) ) { if ( $event->userCan( Revision::DELETED_TEXT, $user ) ) { return EchoDiscussionParser::getTextSnippet( $extra['section-title'], 30 ); + } else { + return $this->getMessage( 'echo-rev-deleted-text-view' )->text(); } } diff --git a/formatters/MentionFormatter.php b/formatters/MentionFormatter.php new file mode 100644 index 000000000..2bd98ae21 --- /dev/null +++ b/formatters/MentionFormatter.php @@ -0,0 +1,27 @@ +getSectionTitle( $event, $user ) ) { + $this->title = array( + 'message' => 'notification-mention-nosection', + 'params' => array( 'agent', 'main-title-text', 'title' ) + ); + $this->flyoutTitle = array( + 'message' => 'notification-mention-nosection-flyout', + 'params' => array( 'agent', 'main-title-text', 'title' ) + ); + $this->email['batch-body'] = array( + 'message' => 'notification-mention-nosection-email-batch-body', + 'params' => array( 'agent', 'main-title-text' ) + ); + } + } +}