Update language in watchlist expiry
Update watchlist expiry language indicators (dropdowns, tooltips, watch via star, watch via edit): * Change "Permanently" to "Permanent" * Change "XX days left" and "Expires in X days" to "XX days left in watchlist" * Update the "Click.." sentence by star to "Click to remove it." * Change watch period for a page that is less than "1 day left" to "A few hours left" Bug: T253135 Bug: T255632 Change-Id: I114c6f77e86ad81b1810fedcd49f52c88700ca16
This commit is contained in:
parent
0de9d89e37
commit
0c2cc49bdc
12 changed files with 130 additions and 39 deletions
|
|
@ -2309,9 +2309,15 @@ class Linker {
|
|||
$skin->getRelevantTitle() );
|
||||
if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
|
||||
$diffInDays = $watchedItem->getExpiryInDays();
|
||||
$msgParams = [ $diffInDays ];
|
||||
// Resolves to tooltip-ca-unwatch-expiring message
|
||||
$tooltipTitle = 'ca-unwatch-expiring';
|
||||
|
||||
if ( $diffInDays ) {
|
||||
$msgParams = [ $diffInDays ];
|
||||
// Resolves to tooltip-ca-unwatch-expiring message
|
||||
$tooltipTitle = 'ca-unwatch-expiring';
|
||||
} else { // Resolves to tooltip-ca-unwatch-expiring-hours message
|
||||
$tooltipTitle = 'ca-unwatch-expiring-hours';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,8 +131,7 @@ class WatchAction extends FormAction {
|
|||
// If it's already being temporarily watched,
|
||||
// add the existing expiry as the default option in the dropdown.
|
||||
$expiry = MWTimestamp::getInstance( $watchedItem->getExpiry() );
|
||||
$diffInDays = $watchedItem->getExpiryInDays();
|
||||
$daysLeft = $msgLocalizer->msg( 'watchlist-expiry-days-left', [ $diffInDays ] )->text();
|
||||
$daysLeft = $watchedItem->getExpiryInDaysText( $msgLocalizer, true );
|
||||
$expiryOptions = array_merge(
|
||||
[ $daysLeft => $expiry->getTimestamp( TS_MW ) ],
|
||||
$expiryOptions
|
||||
|
|
|
|||
|
|
@ -594,12 +594,11 @@ class ChangesList extends ContextSource {
|
|||
if ( $item->isExpired() ) {
|
||||
return '';
|
||||
}
|
||||
$daysLeft = $item->getExpiryInDays();
|
||||
$daysLeftMsg = $this->msg( 'watchlist-expires-in', $daysLeft );
|
||||
$daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
|
||||
// Matching widget is also created in ChangesListSpecialPage, for the legend.
|
||||
$widget = new IconWidget( [
|
||||
'icon' => 'clock',
|
||||
'title' => $daysLeftMsg->text(),
|
||||
'title' => $daysLeftText,
|
||||
'classes' => [ 'mw-changesList-watchlistExpiry' ],
|
||||
] );
|
||||
// Add labels for assistive technologies.
|
||||
|
|
|
|||
|
|
@ -430,13 +430,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
|
|||
);
|
||||
|
||||
$lb = new LinkBatch();
|
||||
$context = $this->getContext();
|
||||
|
||||
foreach ( $watchedItems as $watchedItem ) {
|
||||
$namespace = $watchedItem->getLinkTarget()->getNamespace();
|
||||
$dbKey = $watchedItem->getLinkTarget()->getDBkey();
|
||||
$lb->add( $namespace, $dbKey );
|
||||
if ( !$services->getNamespaceInfo()->isTalk( $namespace ) ) {
|
||||
$titles[$namespace][$dbKey] = $watchedItem->getExpiryInDays();
|
||||
$titles[$namespace][$dbKey] = $watchedItem->getExpiryInDaysText( $context );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -619,11 +620,11 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
|
|||
|
||||
foreach ( $watchlistInfo as $namespace => $pages ) {
|
||||
$options = [];
|
||||
foreach ( $pages as $dbkey => $expiryDays ) {
|
||||
foreach ( $pages as $dbkey => $expiryDaysText ) {
|
||||
$title = Title::makeTitleSafe( $namespace, $dbkey );
|
||||
|
||||
if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
|
||||
$text = $this->buildRemoveLine( $title, $expiryDays );
|
||||
$text = $this->buildRemoveLine( $title, $expiryDaysText );
|
||||
$options[$text] = $title->getPrefixedText();
|
||||
$count++;
|
||||
}
|
||||
|
|
@ -680,11 +681,11 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
|
|||
* Build the label for a checkbox, with a link to the title, and various additional bits
|
||||
*
|
||||
* @param Title $title
|
||||
* @param int|null $expiryDays Number of days a title has remaining in a user's watchlist. If int is passed
|
||||
* then include a message that states the time remaining in a watchlist.
|
||||
* @param string $expiryDaysText message shows the number of days a title has remaining in a user's watchlist.
|
||||
* If this param is not empty then include a message that states the time remaining in a watchlist.
|
||||
* @return string
|
||||
*/
|
||||
private function buildRemoveLine( $title, ?int $expiryDays = null ): string {
|
||||
private function buildRemoveLine( $title, string $expiryDaysText = '' ): string {
|
||||
$linkRenderer = $this->getLinkRenderer();
|
||||
$link = $linkRenderer->makeLink( $title );
|
||||
|
||||
|
|
@ -719,11 +720,11 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
|
|||
}
|
||||
|
||||
$watchlistExpiringMessage = '';
|
||||
if ( $this->isWatchlistExpiryEnabled && $expiryDays !== null ) {
|
||||
$watchlistExpiringMessage = Html::element( 'span', [ 'class' => 'watchlistexpiry-msg' ],
|
||||
$expiryDays > 0 ?
|
||||
$this->msg( 'watchlist-expiring-msg', $expiryDays )->text() :
|
||||
$this->msg( 'watchlist-expiring-hours-msg' )->text()
|
||||
if ( $this->isWatchlistExpiryEnabled && $expiryDaysText ) {
|
||||
$watchlistExpiringMessage = Html::element(
|
||||
'span',
|
||||
[ 'class' => 'watchlistexpiry-msg' ],
|
||||
$expiryDaysText
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -525,7 +525,12 @@ class SpecialWatchlist extends ChangesListSpecialPage {
|
|||
$watchedItem = $this->watchStore->getWatchedItem( $this->getUser(), $rc->getTitle() );
|
||||
if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
|
||||
$diffInDays = $watchedItem->getExpiryInDays();
|
||||
$unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring';
|
||||
|
||||
if ( $diffInDays > 0 ) {
|
||||
$unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring';
|
||||
} else {
|
||||
$unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring-hours';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -173,4 +173,34 @@ class WatchedItem {
|
|||
|
||||
return (int)ceil( $diffInDays );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get days remaining until a watched item expires as a text.
|
||||
*
|
||||
* @since 1.35
|
||||
* @param MessageLocalizer $msgLocalizer
|
||||
* @param bool $isDropdownOption Whether the text is being displayed as a dropdown option.
|
||||
* The text is different as a dropdown option from when it is used in other
|
||||
* places as a watchlist indicator.
|
||||
* @return string days remaining text and '' if no expiration is present
|
||||
*/
|
||||
public function getExpiryInDaysText( MessageLocalizer $msgLocalizer, $isDropdownOption = false ): string {
|
||||
$expiryInDays = $this->getExpiryInDays();
|
||||
if ( $expiryInDays === null ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( $expiryInDays < 1 ) {
|
||||
if ( $isDropdownOption ) {
|
||||
return $msgLocalizer->msg( 'watchlist-expiry-hours-left' )->text();
|
||||
}
|
||||
return $msgLocalizer->msg( 'watchlist-expiring-hours-full-text' )->text();
|
||||
}
|
||||
|
||||
if ( $isDropdownOption ) {
|
||||
return $msgLocalizer->msg( 'watchlist-expiry-days-left', [ $expiryInDays ] )->text();
|
||||
}
|
||||
|
||||
return $msgLocalizer->msg( 'watchlist-expiring-days-full-text', [ $expiryInDays ] )->text();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2399,8 +2399,10 @@
|
|||
"notanarticle": "Not a content page",
|
||||
"notvisiblerev": "The last revision by a different user has been deleted",
|
||||
"watchlist-details": "{{PLURAL:$1|$1 page is|$1 pages are}} on your Watchlist (plus talk pages).",
|
||||
"watchlist-expiring-msg": "{{PLURAL:$1|1 day|$1 days}} left in your watchlist",
|
||||
"watchlist-expiring-hours-msg": "A few hours left",
|
||||
"watchlist-expiry-days-left": "{{PLURAL:$1|$1 day|$1 days}} left",
|
||||
"watchlist-expiring-days-full-text": "{{PLURAL:$1|1 day|$1 days}} left in your watchlist",
|
||||
"watchlist-expiry-hours-left": "A few hours left",
|
||||
"watchlist-expiring-hours-full-text": "A few hours left in your watchlist",
|
||||
"wlheader-enotif": "Email notification is enabled.",
|
||||
"wlheader-showupdated": "Pages that have been changed since you last visited them are shown in <strong>bold</strong>.",
|
||||
"wlnote": "Below {{PLURAL:$1|is the last change|are the last <strong>$1</strong> changes}} in the last {{PLURAL:$2|hour|<strong>$2</strong> hours}}, as of $3, $4.",
|
||||
|
|
@ -3106,7 +3108,8 @@
|
|||
"tooltip-ca-move": "Move this page",
|
||||
"tooltip-ca-watch": "Add this page to your watchlist",
|
||||
"tooltip-ca-unwatch": "Remove this page from your watchlist",
|
||||
"tooltip-ca-unwatch-expiring": "{{PLURAL:$1|1 day|$1 days}} left. Click to remove this page from your watchlist.",
|
||||
"tooltip-ca-unwatch-expiring": "{{PLURAL:$1|1 day|$1 days}} left in your watchlist. Click to remove it.",
|
||||
"tooltip-ca-unwatch-expiring-hours": "A few hours left in your watchlist. Click to remove it.",
|
||||
"tooltip-search": "Search {{SITENAME}}",
|
||||
"tooltip-search-go": "Go to a page with this exact name if it exists",
|
||||
"tooltip-search-fulltext": "Search the pages for this text",
|
||||
|
|
@ -3426,9 +3429,7 @@
|
|||
"confirm-watch-button": "OK",
|
||||
"confirm-watch-top": "Add this page to your watchlist?",
|
||||
"confirm-watch-label": "Watchlist time period:",
|
||||
"watchlist-expiry-options": "Permanently:infinite,1 week:1 week,1 month:1 month,3 months:3 months,6 months:6 months",
|
||||
"watchlist-expiry-days-left": "{{PLURAL:$1|$1 day|$1 days}} left",
|
||||
"watchlist-expires-in": "{{PLURAL:$1|$1 day|$1 days}} left in your watchlist",
|
||||
"watchlist-expiry-options": "Permanent:infinite,1 week:1 week,1 month:1 month,3 months:3 months,6 months:6 months",
|
||||
"watchlist-expires-in-aria-label": "Expiring watchlist item",
|
||||
"confirm-watch-button-expiry": "Watch",
|
||||
"confirm-unwatch-button": "OK",
|
||||
|
|
|
|||
|
|
@ -2615,9 +2615,11 @@
|
|||
"notanarticle": "A 'content page' is a page that forms part of the purpose of the wiki. It includes the main page and pages in the main namespace and any other namespaces that are included when the wiki is customised. For example on Wikimedia Commons 'content pages' include pages in the file and category namespaces. On Wikinews 'content pages' include pages in the Portal namespace. For technical definition of 'content namespaces' see [[mw:Manual:Using_custom_namespaces#Content_namespaces|MediaWiki]].\n\nPossible alternatives to the word 'content' are 'subject matter' or 'wiki subject' or 'wiki purpose'.\n\n{{Identical|Content page}}",
|
||||
"notvisiblerev": "Used as error message when rolling back.\n\nSee also:\n* {{msg-mw|Cantrollback}}",
|
||||
"watchlist-details": "Message on [[Special:Watchlist]]. Parameters:\n* $1 - number of pages in your watchlist\nThis is paired with the message {{msg-mw|Nowatchlist}} which appears instead of Watchlist-details when $1 is 0.\nSee also:\n* {{msg-mw|Watchlist-options|fieldset}}\n* {{msg-mw|Wlheader-enotif|watchlist header}}\n* {{msg-mw|enotif reset|Submit button text}}\n* {{msg-mw|Watchlistcontains}}",
|
||||
"watchlist-expiring-msg": "Used on [[Special:EditWatchlist]] to indicate when a watchlist is expiring.\n\nParameters:\n* $1 - number of days left in your watchlist",
|
||||
"watchlist-expiring-hours-msg": "Used on [[Special:EditWatchlist]] to indicate when a watchlist is expiring in a few hours.",
|
||||
"wlheader-enotif": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.\n\nSee also:\n* {{msg-mw|Watchlist-options|fieldset}}\n* {{msg-mw|enotif reset|Submit button text}}",
|
||||
"watchlist-expiry-days-left": "Used on watchlist expiry dropdown as an option to show when a watchlist is expiring.\n\nParameters:\n* $1 - number of days left in your watchlist",
|
||||
"watchlist-expiring-days-full-text": "Used as label for clock icon in [[Special:Watchlist]] and as a legend in [[Special:EditWatchlist]] to indicate when a watchlist is expiring.\n\nParameters:\n* $1 - number of days left in your watchlist",
|
||||
"watchlist-expiry-hours-left": "Used on watchlist expiry dropdown as an option to show when a watchlist is expiring in a few hours.",
|
||||
"watchlist-expiring-hours-full-text": "Used as label for clock icon in [[Special:Watchlist]] and as a legend in [[Special:EditWatchlist]] to show when a watchlist is expiring in a few hours.",
|
||||
"wlheader-enotif": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.\n\nSee also:\n* {{msg-mw|Watchlist-options|fieldset}}\n* {{msg-mw|enotif reset|Submit button text}}",
|
||||
"wlheader-showupdated": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.",
|
||||
"wlnote": "Used on [[Special:Watchlist]] when a maximum number of hours or days is specified.\n\nParameters:\n* $1 - the number of changes shown\n* $2 - the number of hours for which the changes are shown\n* $3 - a date alone\n* $4 - a time alone",
|
||||
"watchlist-hide": "Appears on [[Special:Watchlist]]. It is the first word on a new line with checkboxes to hide/unhide options\n{{Identical|Hide}}",
|
||||
|
|
@ -3322,7 +3324,8 @@
|
|||
"tooltip-ca-move": "See also:\n* {{msg-mw|Move}}\n* {{msg-mw|Accesskey-ca-move}}\n* {{msg-mw|Tooltip-ca-move}}\n{{Identical|Move this page}}",
|
||||
"tooltip-ca-watch": "See also:\n* {{msg-mw|Watch}}\n* {{msg-mw|Accesskey-ca-watch}}\n* {{msg-mw|Tooltip-ca-watch}}\n{{Identical|Add this page to your watchlist}}",
|
||||
"tooltip-ca-unwatch": "Tooltip shown when hovering over the {{msg-mw|Unwatch}} tab and the page is being watched indefinitely.\n\nSee also:\n* {{msg-mw|Unwatch}}\n* {{msg-mw|Accesskey-ca-unwatch}}\n* {{msg-mw|Tooltip-ca-unwatch-expiring}}",
|
||||
"tooltip-ca-unwatch-expiring": "Tooltip shown when hovering over the {{msg-mw|Unwatch}} tab and the page is being watched temporarily.\n\nSee also:\n* {{msg-mw|Unwatch}}\n* {{msg-mw|Accesskey-ca-unwatch}}\n* {{msg-mw|Tooltip-ca-unwatch}}",
|
||||
"tooltip-ca-unwatch-expiring": "Tooltip shown when hovering over the {{msg-mw|Unwatch}} tab and the page is being watched temporarily.\n\nParemeter:\n* $1 - the number of days left in watchlist.\n\nSee also:\n* {{msg-mw|Unwatch}}\n* {{msg-mw|Accesskey-ca-unwatch}}\n* {{msg-mw|Tooltip-ca-unwatch}}",
|
||||
"tooltip-ca-unwatch-expiring-hours": "Tooltip shown when hovering over the {{msg-mw|Unwatch}} tab and when the watchlist is expiring in a few hours.\n\nSee also:\n* {{msg-mw|Unwatch}}\n* {{msg-mw|Accesskey-ca-unwatch}}\n* {{msg-mw|Tooltip-ca-unwatch}}",
|
||||
"tooltip-search": "The tooltip when hovering over the search menu.\n\nSee also:\n* {{msg-mw|Search}}\n* {{msg-mw|Accesskey-search}}\n* {{msg-mw|Tooltip-search}}\n{{Identical|Search}}",
|
||||
"tooltip-search-go": "This is the text of the tooltip displayed when hovering the mouse over the {{msg-mw|Go}} button next to the search box.\n\nSee also:\n* {{msg-mw|Go}}\n* {{msg-mw|Accesskey-search-go}}\n* {{msg-mw|Tooltip-search-go}}",
|
||||
"tooltip-search-fulltext": "This is the text of the tooltip displayed when hovering the mouse over the {{msg-mw|Search}} button under the search box.\n\nSee also:\n* {{msg-mw|Search}}\n* {{msg-mw|Accesskey-search-fulltext}}\n* {{msg-mw|Tooltip-search-fulltext}}",
|
||||
|
|
@ -3643,8 +3646,6 @@
|
|||
"confirm-watch-top": "Used as confirmation message.",
|
||||
"confirm-watch-label": "Label for select list of watchlist expiry options.",
|
||||
"watchlist-expiry-options": "Options for the expiry of watchlist items.\n\n{{doc-mediawiki-options-list}}",
|
||||
"watchlist-expiry-days-left": "Select-list option used to display the remaining number of days for a watchlist item that's due to expire.\n\nParemeter:\n* $1 - the integer number of days.",
|
||||
"watchlist-expires-in": "Tooltip for clock icon in Special:Watchlist shown on expiring items.\n\nParemeter:\n* $1 - the integer number of days.",
|
||||
"watchlist-expires-in-aria-label": "ARIA label for the clock icon in expiring entries in Special:Watchlist.",
|
||||
"confirm-watch-button-expiry": "Used as Submit button text.",
|
||||
"confirm-unwatch-button": "Used as Submit button text.\n{{Identical|OK}}",
|
||||
|
|
|
|||
|
|
@ -1509,6 +1509,7 @@ return [
|
|||
'tooltip-ca-watch',
|
||||
'tooltip-ca-unwatch',
|
||||
'tooltip-ca-unwatch-expiring',
|
||||
'tooltip-ca-unwatch-expiring-hours',
|
||||
'addedwatchtext',
|
||||
'addedwatchtext-talk',
|
||||
'removedwatchtext',
|
||||
|
|
@ -2187,6 +2188,7 @@ return [
|
|||
'tooltip-ca-watch',
|
||||
'tooltip-ca-unwatch',
|
||||
'tooltip-ca-unwatch-expiring',
|
||||
'tooltip-ca-unwatch-expiring-hours',
|
||||
'watchlist-unwatch',
|
||||
'watchlist-unwatch-undo',
|
||||
],
|
||||
|
|
|
|||
|
|
@ -65,13 +65,20 @@
|
|||
// Checking to see what if the expiry is set or indefinite to display the correct message
|
||||
if ( isWatchlistExpiryEnabled && action === 'unwatch' ) {
|
||||
if ( expiry === null || expiry === 'infinity' ) {
|
||||
// Resolves to tooltip-ca-unwatch message
|
||||
tooltipAction = 'unwatch';
|
||||
} else {
|
||||
expiryDate = new Date( expiry );
|
||||
// Using the Math.ceil function instead of floor so when, for example, a user selects one week
|
||||
// the tooltip shows 7 days instead of 6 days (see Phab ticket T253936)
|
||||
daysLeftExpiry = Math.ceil( ( expiryDate - currentDate ) / ( 1000 * 60 * 60 * 24 ) );
|
||||
tooltipAction = 'unwatch-expiring';
|
||||
if ( daysLeftExpiry > 0 ) {
|
||||
// Resolves to tooltip-ca-unwatch-expiring message
|
||||
tooltipAction = 'unwatch-expiring';
|
||||
} else {
|
||||
// Resolves to tooltip-ca-unwatch-expiring-hours message
|
||||
tooltipAction = 'unwatch-expiring-hours';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,10 +90,9 @@
|
|||
// * tooltip-ca-watching
|
||||
// * unwatch
|
||||
// * tooltip-ca-unwatch
|
||||
// * unwatch-expiring
|
||||
// * tooltip-ca-unwatch-expiring
|
||||
// * tooltip-ca-unwatch-expiring-hours
|
||||
// * unwatching
|
||||
// * tooltip-ca-unwatching
|
||||
.text( mw.msg( msgKey ) )
|
||||
.attr( 'title', mw.msg( 'tooltip-ca-' + tooltipAction, daysLeftExpiry ) )
|
||||
.updateTooltipAccessKeys()
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase {
|
|||
$optionsNoExpiry = WatchAction::getExpiryOptions( $this->context, false );
|
||||
$expectedNoExpiry = [
|
||||
'options' => [
|
||||
'Permanently' => 'infinite',
|
||||
'Permanent' => 'infinite',
|
||||
'1 week' => '1 week',
|
||||
'1 month' => '1 month',
|
||||
'3 months' => '3 months',
|
||||
|
|
@ -392,7 +392,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase {
|
|||
$expectedExpiryOneMonth = [
|
||||
'options' => [
|
||||
'30 days left' => '20200710000000',
|
||||
'Permanently' => 'infinite',
|
||||
'Permanent' => 'infinite',
|
||||
'1 week' => '1 week',
|
||||
'1 month' => '1 month',
|
||||
'3 months' => '3 months',
|
||||
|
|
@ -409,7 +409,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase {
|
|||
$expectedOneWeek = [
|
||||
'options' => [
|
||||
'7 days left' => '20200617000000',
|
||||
'Permanently' => 'infinite',
|
||||
'Permanent' => 'infinite',
|
||||
'1 week' => '1 week',
|
||||
'1 month' => '1 month',
|
||||
'3 months' => '3 months',
|
||||
|
|
@ -424,7 +424,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase {
|
|||
$optionsNoExpiryWIFalse = WatchAction::getExpiryOptions( $this->context, true );
|
||||
$expectedNoExpiryWIFalse = [
|
||||
'options' => [
|
||||
'Permanently' => 'infinite',
|
||||
'Permanent' => 'infinite',
|
||||
'1 week' => '1 week',
|
||||
'1 month' => '1 month',
|
||||
'3 months' => '3 months',
|
||||
|
|
|
|||
|
|
@ -55,4 +55,45 @@ class WatchedItemUnitTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertSame( null, $days );
|
||||
}
|
||||
|
||||
public function testgetExpiryInDaysText() {
|
||||
$user = new UserIdentityValue( 7, 'MockUser', 0 );
|
||||
$target = new TitleValue( 0, 'SomeDbKey' );
|
||||
$context = RequestContext::getMain();
|
||||
|
||||
// Fake current time to be 2020-05-27T00:00:00Z
|
||||
$fakeTime = ConvertibleTimestamp::setFakeTime( '20200527000000' );
|
||||
|
||||
// Adding a watched item with an expiry of a month from the frozen time
|
||||
$watchedItemMonth = new WatchedItem( $user, $target, null, '20200627000000' );
|
||||
$daysRemainingMonthText = $watchedItemMonth->getExpiryInDaysText( $context );
|
||||
$this->assertSame( '31 days left in your watchlist', $daysRemainingMonthText );
|
||||
|
||||
// Adding a watched item with an expiry of 7 days from the frozen time
|
||||
$watchedItemWeek = new WatchedItem( $user, $target, null, '20200603000000' );
|
||||
$daysRemainingWeekText = $watchedItemWeek->getExpiryInDaysText( $context );
|
||||
$this->assertSame( '7 days left in your watchlist', $daysRemainingWeekText );
|
||||
|
||||
// Show a watched item with an expiry of 7 days from the frozen time in a dropdown option
|
||||
$daysRemainingWeekText = $watchedItemWeek->getExpiryInDaysText( $context, true );
|
||||
$this->assertSame( '7 days left', $daysRemainingWeekText );
|
||||
|
||||
// Adding a watched item with an expiry of 1 day from the frozen time
|
||||
$watchedItemDay = new WatchedItem( $user, $target, null, '20200528000000' );
|
||||
$daysRemainingDayText = $watchedItemDay->getExpiryInDaysText( $context );
|
||||
$this->assertSame( '1 day left in your watchlist', $daysRemainingDayText );
|
||||
|
||||
// Adding a watched item with an expiry in less than 1 day from the frozen time
|
||||
$watchedItemSoon = new WatchedItem( $user, $target, null, '20200527010001' );
|
||||
$daysRemainingSoonText = $watchedItemSoon->getExpiryInDaysText( $context );
|
||||
$this->assertSame( 'A few hours left in your watchlist', $daysRemainingSoonText );
|
||||
// Text is for a watchlist expiry dropdown
|
||||
$daysRemainingSoonText = $watchedItemSoon->getExpiryInDaysText( $context, true );
|
||||
$this->assertSame( 'A few hours left', $daysRemainingSoonText );
|
||||
|
||||
// Adding a watched item with no expiry
|
||||
$permamentlyWatchedItem = new WatchedItem( $user, $target, null, null );
|
||||
$daysText = $permamentlyWatchedItem->getExpiryInDaysText( $context );
|
||||
$this->assertSame( '', $daysText );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue