Truncate usernames, titles and excerpts in notifications

Bug: T121822
Change-Id: Ia0a52926133ab7e04d7d9c2a095ef8f9d0871a49
This commit is contained in:
Stephane Bisson 2016-01-20 16:19:54 -05:00
parent cd7edf0378
commit 779b7030d9
9 changed files with 57 additions and 15 deletions

View file

@ -85,7 +85,7 @@ class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
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();

View file

@ -7,6 +7,21 @@
// @todo: once PHP5.3 is no longer supported, this can implement JsonSerializable
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
*/
@ -220,7 +235,7 @@ abstract class EchoEventPresentationModel {
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 @@ abstract class EchoEventPresentationModel {
),
);
}
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 );
}
}

View file

@ -65,15 +65,15 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
$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 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
EchoDiscussionParser::getTextSnippet(
$section,
$this->language,
30
self::SECTION_TITLE_RECOMMENDED_LENGTH
)
);
}

View file

@ -46,8 +46,8 @@ class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
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 );

View file

@ -12,7 +12,7 @@ class EchoRevertedPresentationModel extends EchoEventPresentationModel {
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 @@ class EchoRevertedPresentationModel extends EchoEventPresentationModel {
$html = Linker::formatLinksInComment( Sanitizer::escapeHtmlAllowEntities( $wikitext ) );
return EchoDiscussionParser::getTextSnippet(
$html,
$this->language,
30
$this->language
);
}

View file

@ -34,7 +34,7 @@ class SpecialNotificationsFormatter extends EchoEventFormatter {
$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 @@ class SpecialNotificationsFormatter extends EchoEventFormatter {
}
$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

View file

@ -4,3 +4,9 @@
opacity: 1;
}
}
.mw-echo-ui-mixin-one-line-truncated() {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

View file

@ -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;
}
}
}
}

View file

@ -37,6 +37,7 @@
color: @notification-text-color;
}
&-body {
.mw-echo-ui-mixin-one-line-truncated;
color: @notification-body-color;
}
}