mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Merge "Truncate secondary link labels"
This commit is contained in:
commit
4b68e4842d
|
@ -11,11 +11,21 @@ abstract class EchoEventPresentationModel implements JsonSerializable {
|
|||
*/
|
||||
const USERNAME_RECOMMENDED_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* Recommended length of usernames used as link label
|
||||
*/
|
||||
const USERNAME_AS_LABEL_RECOMMENDED_LENGTH = 15;
|
||||
|
||||
/**
|
||||
* Recommended length of page names included in messages
|
||||
*/
|
||||
const PAGE_NAME_RECOMMENDED_LENGTH = 50;
|
||||
|
||||
/**
|
||||
* Recommended length of page names used as link label
|
||||
*/
|
||||
const PAGE_NAME_AS_LABEL_RECOMMENDED_LENGTH = 15;
|
||||
|
||||
/**
|
||||
* Recommended length of section titles included in messages
|
||||
*/
|
||||
|
@ -273,28 +283,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable {
|
|||
* Returns null if the current user cannot see the agent.
|
||||
*/
|
||||
final protected function getAgentLink() {
|
||||
$agent = $this->event->getAgent();
|
||||
|
||||
if ( !$this->userCan( Revision::DELETED_USER ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !$agent ) {
|
||||
throw new DomainException(
|
||||
"No agent associated with notification with id '{$this->event->getId()}' of type '{$this->type}'" );
|
||||
}
|
||||
|
||||
$url = $agent->isAnon()
|
||||
? SpecialPage::getTitleFor( 'Contributions', $agent->getName() )->getFullURL()
|
||||
: $agent->getUserPage()->getFullURL();
|
||||
|
||||
return array(
|
||||
'url' => $url,
|
||||
'label' => $agent->getName(),
|
||||
'description' => '',
|
||||
'icon' => 'userAvatar',
|
||||
'prioritized' => true,
|
||||
);
|
||||
return $this->getUserLink( $this->event->getAgent() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,4 +379,57 @@ abstract class EchoEventPresentationModel implements JsonSerializable {
|
|||
$text = $includeNamespace ? $title->getPrefixedText() : $title->getText();
|
||||
return $this->language->truncate( $text, self::PAGE_NAME_RECOMMENDED_LENGTH );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return array|null
|
||||
*/
|
||||
final protected function getUserLink( User $user ) {
|
||||
if ( !$this->userCan( Revision::DELETED_USER ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$url = $user->isAnon()
|
||||
? SpecialPage::getTitleFor( 'Contributions', $user->getName() )->getFullURL()
|
||||
: $user->getUserPage()->getFullURL();
|
||||
|
||||
$label = $user->getName();
|
||||
$truncatedLabel = $this->language->truncate( $label, self::USERNAME_AS_LABEL_RECOMMENDED_LENGTH );
|
||||
$isTruncated = $label !== $truncatedLabel;
|
||||
|
||||
return array(
|
||||
'url' => $url,
|
||||
'label' => $truncatedLabel,
|
||||
'tooltip' => $isTruncated ? $label : '',
|
||||
'description' => '',
|
||||
'icon' => 'userAvatar',
|
||||
'prioritized' => true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Title $title
|
||||
* @param string $description
|
||||
* @param bool $prioritized
|
||||
* @param array $query
|
||||
* @return array
|
||||
*/
|
||||
final protected function getPageLink( Title $title, $description, $prioritized, $query = array() ) {
|
||||
$ns = $title->getNamespace();
|
||||
if ( $ns === NS_USER_TALK ) {
|
||||
$icon = 'userSpeechBubble';
|
||||
} elseif ( $ns === NS_TALK ) {
|
||||
$icon = 'speechBubbles';
|
||||
} else {
|
||||
$icon = 'article';
|
||||
}
|
||||
return array(
|
||||
'url' => $title->getFullURL( $query ),
|
||||
'label' => $this->language->truncate( $title->getText(), self::PAGE_NAME_AS_LABEL_RECOMMENDED_LENGTH ),
|
||||
'tooltip' => $title->getPrefixedText(),
|
||||
'description' => $description,
|
||||
'icon' => $icon,
|
||||
'prioritized' => $prioritized,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,12 +141,8 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
|||
'prioritized' => true,
|
||||
);
|
||||
|
||||
$pageLink = array(
|
||||
'url' => $title->getFullURL(),
|
||||
'label' => $this->isArticle() ? $title->getText() : $title->getPrefixedText(),
|
||||
'description' => '',
|
||||
'icon' => $this->isTalk() ? 'speechBubbles' : 'article',
|
||||
'prioritized' => true,
|
||||
$pageLink = $this->getPageLink(
|
||||
$title, '', true
|
||||
);
|
||||
|
||||
return array( $this->getAgentLink(), $pageLink, $viewChangesLink );
|
||||
|
|
|
@ -48,7 +48,11 @@ class EchoRevertedPresentationModel extends EchoEventPresentationModel {
|
|||
}
|
||||
|
||||
public function getSecondaryLinks() {
|
||||
return array( $this->getAgentLink(), $this->getTitleLink() );
|
||||
$revertedTitleLink = $this->getPageLink(
|
||||
$this->event->getTitle()->getTalkPage(), null, true
|
||||
);
|
||||
|
||||
return array( $this->getAgentLink(), $revertedTitleLink );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,17 +69,6 @@ class EchoRevertedPresentationModel extends EchoEventPresentationModel {
|
|||
}
|
||||
}
|
||||
|
||||
private function getTitleLink() {
|
||||
$talkpage = $this->event->getTitle()->getTalkPage();
|
||||
return array(
|
||||
'label' => $talkpage->getPrefixedText(),
|
||||
'url' => $talkpage->getFullURL(),
|
||||
'icon' => 'speechBubbles',
|
||||
'prioritized' => true,
|
||||
'description' => null,
|
||||
);
|
||||
}
|
||||
|
||||
private function isAutomaticSummary( $summary ) {
|
||||
$autoSummaryMsg = wfMessage( 'undo-summary' )->inContentLanguage();
|
||||
$autoSummaryMsg->params( $this->event->getExtraParam( 'reverted-revision-id' ) );
|
||||
|
|
|
@ -44,7 +44,15 @@ class SpecialNotificationsFormatter extends EchoEventFormatter {
|
|||
}
|
||||
$links = array_merge( $links, array_filter( $model->getSecondaryLinks() ) );
|
||||
foreach ( $links as $link ) {
|
||||
$footerItems[] = Html::element( 'a', array( 'href' => $link['url'], 'class' => 'mw-echo-notification-footer-element' ), $link['label'] );
|
||||
$footerItems[] = Html::element(
|
||||
'a',
|
||||
array(
|
||||
'href' => $link['url'],
|
||||
'title' => $link['tooltip'],
|
||||
'class' => 'mw-echo-notification-footer-element',
|
||||
),
|
||||
$link['label']
|
||||
);
|
||||
}
|
||||
|
||||
$pipe = wfMessage( 'pipe-separator' )->inLanguage( $this->language )->escaped();
|
||||
|
|
|
@ -39,6 +39,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
$user = $this->getOptionUser( 'user' );
|
||||
$agent = $this->getOptionUser( 'agent' );
|
||||
$otherUser = $this->getOptionUser( 'other' );
|
||||
$title = Title::newFromText( 'This is a pretty long page title lets see if it is going to be truncated' );
|
||||
|
||||
$this->confirm();
|
||||
|
||||
|
@ -46,7 +47,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
|
||||
$this->generateWelcome( $user );
|
||||
$this->generateEditUserTalk( $user, $agent );
|
||||
$this->generateMention( $user, $agent, $otherUser );
|
||||
$this->generateMention( $user, $agent, $otherUser, $title );
|
||||
$this->generatePageLink( $user, $agent );
|
||||
$this->generateReverted( $user, $agent );
|
||||
$this->generateEmail( $user, $agent );
|
||||
|
@ -117,13 +118,12 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
}
|
||||
}
|
||||
|
||||
private function generateMention( User $user, User $agent, User $otherUser ) {
|
||||
$moai = Title::newFromText( 'Moai' );
|
||||
private function generateMention( User $user, User $agent, User $otherUser, Title $title ) {
|
||||
$mention = "== section {$this->generateRandomString()} ==\nHello [[User:{$user->getName()}]] \n~~~~\n";
|
||||
|
||||
// article talk
|
||||
$this->output( "{$agent->getName()} is mentioning {$user->getName()} on {$moai->getTalkPage()->getPrefixedText()}\n" );
|
||||
$this->addToPageContent( $moai->getTalkPage(), $agent, $mention );
|
||||
$this->output( "{$agent->getName()} is mentioning {$user->getName()} on {$title->getTalkPage()->getPrefixedText()}\n" );
|
||||
$this->addToPageContent( $title->getTalkPage(), $agent, $mention );
|
||||
|
||||
// agent tak
|
||||
$this->output( "{$agent->getName()} is mentioning {$user->getName()} on {$agent->getTalkPage()->getPrefixedText()}\n" );
|
||||
|
@ -134,8 +134,8 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
$this->addToPageContent( $otherUser->getTalkPage(), $agent, $mention );
|
||||
|
||||
// any other page
|
||||
$this->output( "{$agent->getName()} is mentioning {$user->getName()} on {$moai->getPrefixedText()}\n" );
|
||||
$this->addToPageContent( $moai, $agent, $mention );
|
||||
$this->output( "{$agent->getName()} is mentioning {$user->getName()} on {$title->getPrefixedText()}\n" );
|
||||
$this->addToPageContent( $title, $agent, $mention );
|
||||
}
|
||||
|
||||
private function generatePageLink( User $user, User $agent ) {
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
$( '<a>' )
|
||||
.addClass( 'mw-echo-ui-menuItemWidget-linkWrapper' )
|
||||
.attr( 'href', config.url )
|
||||
.attr( 'title', config.tooltip )
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
linkButton = new mw.echo.ui.MenuItemWidget( {
|
||||
icon: urlObj.icon || 'next',
|
||||
label: urlObj.label,
|
||||
tooltip: urlObj.tooltip,
|
||||
description: urlObj.description,
|
||||
url: urlObj.url,
|
||||
prioritized: isInsideMenu
|
||||
|
|
Loading…
Reference in a new issue