RCFilters: display timestamp of new changes in refresh link
authorStephane Bisson <sbisson@wikimedia.org>
Thu, 11 Apr 2019 14:58:38 +0000 (10:58 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Wed, 17 Apr 2019 00:51:25 +0000 (17:51 -0700)
The timestamp displayed in the link is not from the last refresh
but from when new changes are available.
I don't think this distinction is consequential. The fundamental
meaning is that clicking the link will bring changes newer than
the timestamp.

I considered using a relative timestamp (2h ago) like is
proposed in the task but I didn't think it was worth it
for the following reasons:
1. Client-side formatting with momentjs is hacky
   at best and I couldn't find a way to have it
   respect user's preferences.
2. I don't think it makes the meaning of the timestamp
   in the message any clearer. I'll admit the meaning
   of the current timestamp is not explicit but I think
   it works when you don't think too much about it.
3. A relative timestamp requires a setInterval with
   decreasing interval to keep it up to date.
   ("A few seconds ago" -> "2 minutes ago", "1h ago", etc)

Bug: T200353
Change-Id: I9058d47645914783227d1520adb78e75399b5504

includes/specials/SpecialRecentChanges.php
includes/specials/SpecialWatchlist.php
languages/i18n/en.json
languages/i18n/qqq.json
resources/src/mediawiki.rcfilters/dm/ChangesListViewModel.js
resources/src/mediawiki.rcfilters/ui/FilterWrapperWidget.js

index d0846b3..9102f81 100644 (file)
@@ -918,7 +918,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                        [ 'class' => 'rclistfrom' ],
                        $this->makeOptionsLink(
                                $this->msg( 'rclistfrom' )->plaintextParams( $now, $timenow, $datenow )->parse(),
-                               [ 'from' => $timestamp ],
+                               [ 'from' => $timestamp, 'fromFormatted' => $now ],
                                $nondefaults
                        )
                );
index c6d9fc7..a97859f 100644 (file)
@@ -598,11 +598,12 @@ class SpecialWatchlist extends ChangesListSpecialPage {
 
                $lang = $this->getLanguage();
                $timestamp = wfTimestampNow();
+               $now = $lang->userTimeAndDate( $timestamp, $user );
                $wlInfo = Html::rawElement(
                        'span',
                        [
                                'class' => 'wlinfo',
-                               'data-params' => json_encode( [ 'from' => $timestamp ] ),
+                               'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
                        ],
                        $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
                                $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
index 56ff467..41f8c99 100644 (file)
        "rcfilters-savedqueries-already-saved": "These filters are already saved. Change your settings to create a new Saved Filter.",
        "rcfilters-restore-default-filters": "Restore default filters",
        "rcfilters-clear-all-filters": "Clear all filters",
-       "rcfilters-show-new-changes": "View newest changes",
+       "rcfilters-show-new-changes": "View new changes since $1",
        "rcfilters-search-placeholder": "Filter changes (use menu or search for filter name)",
        "rcfilters-invalid-filter": "Invalid filter",
        "rcfilters-empty-filter": "No active filters. All contributions are shown.",
index c7f2733..f778a08 100644 (file)
        "rcfilters-savedqueries-already-saved": "Title for the popup in [[Special:RecentChanges]] that indicates that current set of filters is already saved. This is for a small popup, please try to use a short string.",
        "rcfilters-restore-default-filters": "Label for the button that resets filters to defaults",
        "rcfilters-clear-all-filters": "Title for the button that clears all filters",
-       "rcfilters-show-new-changes": "Label for the button to show new changes.",
+       "rcfilters-show-new-changes": "Label for the button to show new changes. Parameters:\n* $1 - timestamp from which new changes are available. It indicates that clicking the refresh link will bring changes newer than (or equal to) this timestamp. It is formatted according to the user's date, time and timezone preferences",
        "rcfilters-search-placeholder": "Placeholder for the filter search input. The first \"Filter\" is a verb, and the second \"filter\" is a noun.",
        "rcfilters-invalid-filter": "A label for an invalid filter.",
        "rcfilters-empty-filter": "Placeholder for the filter list when no filters were chosen.",
index 70677b9..d5357e0 100644 (file)
@@ -117,6 +117,7 @@ ChangesListViewModel.prototype.extractNextFrom = function ( $fieldset ) {
        var data = $fieldset.find( '.rclistfrom > a, .wlinfo' ).data( 'params' );
        if ( data && data.from ) {
                this.nextFrom = data.from;
+               this.nextFromFormatted = data.fromFormatted;
        }
 };
 
@@ -127,6 +128,13 @@ ChangesListViewModel.prototype.getNextFrom = function () {
        return this.nextFrom;
 };
 
+/**
+ * @return {string} The 'from' parameter formatted per the user's datetime format preference
+ */
+ChangesListViewModel.prototype.getNextFromFormatted = function () {
+       return this.nextFromFormatted;
+};
+
 /**
  * Toggle the 'live update' feature on/off
  *
index ce9656e..a0f098c 100644 (file)
@@ -67,7 +67,6 @@ FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget(
        this.showNewChangesLink = new OO.ui.ButtonWidget( {
                icon: 'reload',
                framed: false,
-               label: mw.msg( 'rcfilters-show-new-changes' ),
                flags: [ 'progressive' ],
                classes: [ 'mw-rcfilters-ui-filterWrapperWidget-showNewChanges' ]
        } );
@@ -131,6 +130,14 @@ FilterWrapperWidget.prototype.onShowNewChangesClick = function () {
  * @param {boolean} newChangesExist Whether new changes exist
  */
 FilterWrapperWidget.prototype.onNewChangesExist = function ( newChangesExist ) {
+       if ( newChangesExist ) {
+               this.showNewChangesLink.setLabel(
+                       mw.message(
+                               'rcfilters-show-new-changes',
+                               this.changesListModel.getNextFromFormatted()
+                       ).text()
+               );
+       }
        this.showNewChangesLink.toggle( newChangesExist );
 };