jenkins-bot has submitted this change and it was merged.
Change subject: Truncate usernames, titles and excerpts in notifications
......................................................................
Truncate usernames, titles and excerpts in notifications
Bug: T121822
Change-Id: Ia0a52926133ab7e04d7d9c2a095ef8f9d0871a49
---
M includes/formatters/EditUserTalkPresentationModel.php
M includes/formatters/EventPresentationModel.php
M includes/formatters/MentionPresentationModel.php
M includes/formatters/PageLinkedPresentationModel.php
M includes/formatters/RevertedPresentationModel.php
M includes/formatters/SpecialNotificationsFormatter.php
M modules/echo.mixins.less
M modules/nojs/mw.echo.notifications.less
M modules/ooui/styles/mw.echo.ui.NotificationItemWidget.less
9 files changed, 57 insertions(+), 15 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/formatters/EditUserTalkPresentationModel.php
b/includes/formatters/EditUserTalkPresentationModel.php
index a5fc922..9847909 100644
--- a/includes/formatters/EditUserTalkPresentationModel.php
+++ b/includes/formatters/EditUserTalkPresentationModel.php
@@ -85,7 +85,7 @@
return EchoDiscussionParser::getTextSnippet(
$this->event->getExtraParam( 'section-title' ),
$this->language,
- 30
+ self::SECTION_TITLE_RECOMMENDED_LENGTH
);
} else {
return $this->msg( 'echo-rev-deleted-text-view'
)->text();
diff --git a/includes/formatters/EventPresentationModel.php
b/includes/formatters/EventPresentationModel.php
index c7d00c9..e2a914b 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -8,6 +8,21 @@
abstract class EchoEventPresentationModel {
/**
+ * Recommended length of usernames included in messages
+ */
+ const USERNAME_RECOMMENDED_LENGTH = 30;
+
+ /**
+ * Recommended length of page names included in messages
+ */
+ const PAGE_NAME_RECOMMENDED_LENGTH = 50;
+
+ /**
+ * Recommended length of section titles included in messages
+ */
+ const SECTION_TITLE_RECOMMENDED_LENGTH = 30;
+
+ /**
* @var EchoEvent
*/
protected $event;
@@ -220,7 +235,7 @@
if ( $this->userCan( Revision::DELETED_USER ) ) {
// Not deleted
- return array( $agent->getName(), $agent->getName() );
+ return array( $this->getTruncatedUsername( $agent ),
$agent->getName() );
} else {
// Deleted/hidden
$msg = $this->msg( 'rev-deleted-user' )->plain();
@@ -367,4 +382,13 @@
),
);
}
+
+ protected function getTruncatedUsername( User $user ) {
+ return $this->language->truncate( $user->getName(),
self::USERNAME_RECOMMENDED_LENGTH );
+ }
+
+ protected function getTruncatedTitleText( Title $title,
$includeNamespace = false ) {
+ $text = $includeNamespace ? $title->getPrefixedText() :
$title->getText();
+ return $this->language->truncate( $text,
self::PAGE_NAME_RECOMMENDED_LENGTH );
+ }
}
diff --git a/includes/formatters/MentionPresentationModel.php
b/includes/formatters/MentionPresentationModel.php
index d81aca5..c504ed6 100644
--- a/includes/formatters/MentionPresentationModel.php
+++ b/includes/formatters/MentionPresentationModel.php
@@ -65,15 +65,15 @@
$msg->params( $this->getViewingUserForGender() );
if ( $this->onArticleTalkpage() ) {
- $msg->params( $this->event->getTitle()->getText() );
+ $msg->params( $this->getTruncatedTitleText(
$this->event->getTitle() ) );
} elseif ( $this->onAgentTalkpage() ) {
// No params to add here.
// If we remove this check, onUserTalkpage() has to
// make sure it is a user talk page but NOT the agent's
talk page.
} elseif ( $this->onUserTalkpage() ) {
- $msg->params( $this->event->getTitle()->getText() );
+ $msg->params( $this->getTruncatedTitleText(
$this->event->getTitle() ) );
} else {
- $msg->params(
$this->event->getTitle()->getPrefixedText() );
+ $msg->params( $this->getTruncatedTitleText(
$this->event->getTitle(), true ) );
}
$section = $this->getSection();
@@ -82,7 +82,7 @@
EchoDiscussionParser::getTextSnippet(
$section,
$this->language,
- 30
+
self::SECTION_TITLE_RECOMMENDED_LENGTH
)
);
}
diff --git a/includes/formatters/PageLinkedPresentationModel.php
b/includes/formatters/PageLinkedPresentationModel.php
index a4b53ef..c94ac39 100644
--- a/includes/formatters/PageLinkedPresentationModel.php
+++ b/includes/formatters/PageLinkedPresentationModel.php
@@ -46,8 +46,8 @@
public function getHeaderMessage() {
$msg = parent::getHeaderMessage();
- $msg->params( $this->event->getTitle()->getPrefixedText() );
- $msg->params( $this->getPageFrom()->getPrefixedText() );
+ $msg->params( $this->getTruncatedTitleText(
$this->event->getTitle(), true ) );
+ $msg->params( $this->getTruncatedTitleText(
$this->getPageFrom(), true ) );
list( $formattedCount, $countForPlural ) =
$this->getNotificationCountForOutput( false, array(
$this, 'getLinkedPageId' ) );
$msg->params( $formattedCount );
diff --git a/includes/formatters/RevertedPresentationModel.php
b/includes/formatters/RevertedPresentationModel.php
index 3e39c50..809ea32 100644
--- a/includes/formatters/RevertedPresentationModel.php
+++ b/includes/formatters/RevertedPresentationModel.php
@@ -12,7 +12,7 @@
public function getHeaderMessage() {
$msg = parent::getHeaderMessage();
- $msg->params( $this->event->getTitle()->getPrefixedText() );
+ $msg->params( $this->getTruncatedTitleText(
$this->event->getTitle(), true ) );
$msg->params( $this->getNumberOfEdits() );
return $msg;
}
@@ -32,8 +32,7 @@
$html = Linker::formatLinksInComment(
Sanitizer::escapeHtmlAllowEntities( $wikitext ) );
return EchoDiscussionParser::getTextSnippet(
$html,
- $this->language,
- 30
+ $this->language
);
}
diff --git a/includes/formatters/SpecialNotificationsFormatter.php
b/includes/formatters/SpecialNotificationsFormatter.php
index 94d3780..4b192af 100644
--- a/includes/formatters/SpecialNotificationsFormatter.php
+++ b/includes/formatters/SpecialNotificationsFormatter.php
@@ -34,7 +34,7 @@
$this->user
);
- $footerItems = array( $ts );
+ $footerItems = array( Html::element( 'span', array( 'class' =>
'mw-echo-notification-footer-element' ), $ts ) );
// Add links to the footer, primary goes first, then secondary
ones
$links = array();
@@ -44,13 +44,14 @@
}
$links = array_merge( $links, array_filter(
$model->getSecondaryLinks() ) );
foreach ( $links as $link ) {
- $footerItems[] = Html::element( 'a', array( 'href' =>
$link['url'] ), $link['label'] );
+ $footerItems[] = Html::element( 'a', array( 'href' =>
$link['url'], 'class' => 'mw-echo-notification-footer-element' ),
$link['label'] );
}
+ $pipe = wfMessage( 'pipe-separator' )->inLanguage(
$this->language )->escaped();
$html .= Xml::tags(
'div',
array( 'class' => 'mw-echo-notification-footer' ),
- $this->language->pipeList( $footerItems )
+ implode( Html::element( 'span', array( 'class' =>
'mw-echo-notification-footer-element' ), $pipe ), $footerItems )
) . "\n";
// Wrap everything in mw-echo-content class
diff --git a/modules/echo.mixins.less b/modules/echo.mixins.less
index c0bffb0..11a7f26 100644
--- a/modules/echo.mixins.less
+++ b/modules/echo.mixins.less
@@ -4,3 +4,9 @@
opacity: 1;
}
}
+
+.mw-echo-ui-mixin-one-line-truncated() {
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
diff --git a/modules/nojs/mw.echo.notifications.less
b/modules/nojs/mw.echo.notifications.less
index e0051da..48bef99 100644
--- a/modules/nojs/mw.echo.notifications.less
+++ b/modules/nojs/mw.echo.notifications.less
@@ -1,4 +1,5 @@
@import '../echo.variables';
+@import '../echo.mixins';
// This needs to be outside the upper selector 'NotificationItemWidget'
// because the same styles also apply (for the moment, at least) to the
notification
@@ -57,6 +58,7 @@
}
.mw-echo-payload {
+ .mw-echo-ui-mixin-one-line-truncated;
color: @notification-body-color;
}
@@ -75,10 +77,19 @@
}
}
- .mw-echo-timestamp, .mw-echo-notification-footer {
+ .mw-echo-notification-footer {
color: #6D6D6D;
font-size: 11px;
margin-top: 0.2em;
+
+ .mw-echo-notification-footer-element {
+ display: inline-block;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ max-width: 15em;
+ margin-right: 0.5em;
+ }
}
}
}
diff --git a/modules/ooui/styles/mw.echo.ui.NotificationItemWidget.less
b/modules/ooui/styles/mw.echo.ui.NotificationItemWidget.less
index 71eb16c..f153208 100644
--- a/modules/ooui/styles/mw.echo.ui.NotificationItemWidget.less
+++ b/modules/ooui/styles/mw.echo.ui.NotificationItemWidget.less
@@ -37,6 +37,7 @@
color: @notification-text-color;
}
&-body {
+ .mw-echo-ui-mixin-one-line-truncated;
color: @notification-body-color;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/265495
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia0a52926133ab7e04d7d9c2a095ef8f9d0871a49
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Mooeypoo <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits