Merge "Allow hidden skins to show up in preferences"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index c6d9fc7..56f5c8f 100644 (file)
@@ -110,7 +110,14 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
        }
 
-       public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
+       /**
+        * @see ChangesListSpecialPage::checkStructuredFilterUiEnabled
+        */
+       public static function checkStructuredFilterUiEnabled( $user ) {
+               if ( $user instanceof Config ) {
+                       wfDeprecated( __METHOD__ . ' with Config argument', '1.34' );
+                       $user = func_get_arg( 1 );
+               }
                return !$user->getOption( 'wlenhancedfilters-disable' );
        }
 
@@ -192,13 +199,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                        'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
                                        'cssClassSuffix' => 'watchedunseen',
                                        'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
-                                               $changeTs = $rc->getAttribute( 'rc_timestamp' );
-                                               $lastVisitTs = $this->watchStore->getLatestNotificationTimestamp(
-                                                       $rc->getAttribute( 'wl_notificationtimestamp' ),
-                                                       $rc->getPerformer(),
-                                                       $rc->getTitle()
-                                               );
-                                               return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
+                                               return !$this->isChangeEffectivelySeen( $rc );
                                        },
                                ],
                                [
@@ -206,16 +207,23 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                        'label' => 'rcfilters-filter-watchlistactivity-seen-label',
                                        'description' => 'rcfilters-filter-watchlistactivity-seen-description',
                                        'cssClassSuffix' => 'watchedseen',
-                                       'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                               $changeTs = $rc->getAttribute( 'rc_timestamp' );
-                                               $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
-                                               return $lastVisitTs === null || $changeTs < $lastVisitTs;
+                                       'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
+                                               return $this->isChangeEffectivelySeen( $rc );
                                        }
                                ],
                        ],
                        'default' => ChangesListStringOptionsFilterGroup::NONE,
-                       'queryCallable' => function ( $specialPageClassName, $context, $dbr,
-                                       &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
+                       'queryCallable' => function (
+                               $specialPageClassName,
+                               $context,
+                               IDatabase $dbr,
+                               &$tables,
+                               &$fields,
+                               &$conds,
+                               &$query_options,
+                               &$join_conds,
+                               $selectedValues
+                       ) {
                                if ( $selectedValues === [ 'seen' ] ) {
                                        $conds[] = $dbr->makeList( [
                                                'wl_notificationtimestamp IS NULL',
@@ -534,9 +542,9 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                        $rc->counter = $counter++;
 
                        if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
-                               $updated = $obj->wl_notificationtimestamp;
+                               $unseen = !$this->isChangeEffectivelySeen( $rc );
                        } else {
-                               $updated = false;
+                               $unseen = false;
                        }
 
                        if ( isset( $watchedItemStore ) ) {
@@ -546,7 +554,10 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                $rc->numberofWatchingusers = 0;
                        }
 
-                       $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
+                       // XXX: this treats pages with no unseen changes as "not on the watchlist" since
+                       // everything is on the watchlist and it is an easy way to make pages with unseen
+                       // changes appear bold. @TODO: clean this up.
+                       $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
                        if ( $changeLine !== false ) {
                                $s .= $changeLine;
                        }
@@ -598,11 +609,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 )
@@ -850,4 +862,26 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $count = $store->countWatchedItems( $this->getUser() );
                return floor( $count / 2 );
        }
+
+       /**
+        * @param RecentChange $rc
+        * @return bool User viewed the revision or a newer one
+        */
+       protected function isChangeEffectivelySeen( RecentChange $rc ) {
+               $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
+
+               return ( $firstUnseen === null || $firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
+       }
+
+       /**
+        * @param RecentChange $rc
+        * @return string|null TS_MW timestamp of first unseen revision or null if there isn't one
+        */
+       private function getLatestNotificationTimestamp( RecentChange $rc ) {
+               return $this->watchStore->getLatestNotificationTimestamp(
+                       $rc->getAttribute( 'wl_notificationtimestamp' ),
+                       $rc->getPerformer(),
+                       $rc->getTitle()
+               );
+       }
 }