Merge "RCFilters: Make 'days' and 'limit' sticky"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 5 Dec 2017 11:46:36 +0000 (11:46 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 5 Dec 2017 11:46:37 +0000 (11:46 +0000)
includes/Preferences.php
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialWatchlist.php
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js
resources/src/mediawiki.rcfilters/mw.rcfilters.init.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesLimitAndDateButtonWidget.js

index 2dd3e2d..cab1e1f 100644 (file)
@@ -926,16 +926,16 @@ class Preferences {
                $defaultPreferences['rcfilters-wl-saved-queries'] = [
                        'type' => 'api',
                ];
-               $defaultPreferences['rcfilters-saved-queries-versionbackup'] = [
+               // Override RCFilters preferences for RecentChanges 'limit'
+               $defaultPreferences['rcfilters-limit'] = [
                        'type' => 'api',
                ];
-               $defaultPreferences['rcfilters-wl-saved-queries-versionbackup'] = [
+               $defaultPreferences['rcfilters-saved-queries-versionbackup'] = [
                        'type' => 'api',
                ];
-               $defaultPreferences['rcfilters-rclimit'] = [
+               $defaultPreferences['rcfilters-wl-saved-queries-versionbackup'] = [
                        'type' => 'api',
                ];
-
                if ( $config->get( 'RCWatchCategoryMembership' ) ) {
                        $defaultPreferences['hidecategorization'] = [
                                'type' => 'toggle',
@@ -1534,6 +1534,14 @@ class Preferences {
                                $formData[$pref] = $user->getOption( $pref, null, true );
                        }
 
+                       // If the user changed the rclimit preference, also change the rcfilters-rclimit preference
+                       if (
+                               isset( $formData['rclimit'] ) &&
+                               intval( $formData[ 'rclimit' ] ) !== $user->getIntOption( 'rclimit' )
+                       ) {
+                               $formData['rcfilters-limit'] = $formData['rclimit'];
+                       }
+
                        // Keep old preferences from interfering due to back-compat code, etc.
                        $user->resetOptions( 'unused', $form->getContext() );
 
index 5194983..cb2ae34 100644 (file)
@@ -39,6 +39,18 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         */
        protected static $savedQueriesPreferenceName;
 
+       /**
+        * Preference name for 'days'. Subclasses should override this.
+        * @var string
+        */
+       protected static $daysPreferenceName;
+
+       /**
+        * Preference name for 'limit'. Subclasses should override this.
+        * @var string
+        */
+       protected static $limitPreferenceName;
+
        /** @var string */
        protected $rcSubpage;
 
@@ -722,6 +734,14 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                'wgStructuredChangeFiltersSavedQueriesPreferenceName',
                                static::$savedQueriesPreferenceName
                        );
+                       $out->addJsConfigVars(
+                               'wgStructuredChangeFiltersLimitPreferenceName',
+                               static::$limitPreferenceName
+                       );
+                       $out->addJsConfigVars(
+                               'wgStructuredChangeFiltersDaysPreferenceName',
+                               static::$daysPreferenceName
+                       );
 
                        $out->addJsConfigVars(
                                'StructuredChangeFiltersLiveUpdatePollingRate',
@@ -1753,11 +1773,10 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                        return true;
                }
 
-               if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
-                       return !$this->getUser()->getOption( 'rcenhancedfilters-disable' );
-               } else {
-                       return $this->getUser()->getOption( 'rcenhancedfilters' );
-               }
+               return self::checkStructuredFilterUiEnabled(
+                       $this->getConfig(),
+                       $this->getUser()
+               );
        }
 
        /**
@@ -1774,14 +1793,42 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                }
        }
 
-       abstract function getDefaultLimit();
+       /**
+        * Static method to check whether StructuredFilter UI is enabled for the given user
+        *
+        * @since 1.31
+        * @param Config $config
+        * @param User $user User object
+        * @return bool
+        */
+       public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
+               if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
+                       return !$user->getOption( 'rcenhancedfilters-disable' );
+               } else {
+                       return $user->getOption( 'rcenhancedfilters' );
+               }
+       }
+
+       /**
+        * Get the default value of the number of changes to display when loading
+        * the result set.
+        *
+        * @since 1.30
+        * @return int
+        */
+       public function getDefaultLimit() {
+               return $this->getUser()->getIntOption( static::$limitPreferenceName );
+       }
 
        /**
         * Get the default value of the number of days to display when loading
         * the result set.
         * Supports fractional values, and should be cast to a float.
         *
+        * @since 1.30
         * @return float
         */
-       abstract function getDefaultDays();
+       public function getDefaultDays() {
+               return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );
+       }
 }
index cfc7a85..50d8571 100644 (file)
@@ -33,6 +33,8 @@ use Wikimedia\Rdbms\FakeResultWrapper;
 class SpecialRecentChanges extends ChangesListSpecialPage {
 
        protected static $savedQueriesPreferenceName = 'rcfilters-saved-queries';
+       protected static $daysPreferenceName = 'rcdays'; // Use general RecentChanges preference
+       protected static $limitPreferenceName = 'rcfilters-limit'; // Use RCFilters-specific preference
 
        private $watchlistFilterGroupDefinition;
 
@@ -974,11 +976,14 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                return 60 * 5;
        }
 
-       function getDefaultLimit() {
-               return $this->getUser()->getIntOption( 'rclimit' );
-       }
+       public function getDefaultLimit() {
+               $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
+               // Prefer the RCFilters-specific preference if RCFilters is enabled
+               if ( $this->isStructuredFilterUiEnabled() ) {
+                       return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
+               }
 
-       function getDefaultDays() {
-               return floatval( $this->getUser()->getOption( 'rcdays' ) );
+               // Otherwise, use the system rclimit preference value
+               return $systemPrefValue;
        }
 }
index ff62e9e..6eec844 100644 (file)
@@ -33,6 +33,8 @@ use Wikimedia\Rdbms\IDatabase;
  */
 class SpecialWatchlist extends ChangesListSpecialPage {
        protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
+       protected static $daysPreferenceName = 'watchlistdays';
+       protected static $limitPreferenceName = 'wllimit';
 
        private $maxDays;
 
@@ -108,10 +110,10 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
        }
 
-       public function isStructuredFilterUiEnabled() {
-               return $this->getRequest()->getBool( 'rcfilters' ) || (
-                       $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
-                       $this->getUser()->getOption( 'rcenhancedfilters' )
+       public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
+               return (
+                       $config->get( 'StructuredChangeFiltersOnWatchlist' ) &&
+                       $user->getOption( 'rcenhancedfilters' )
                );
        }
 
@@ -876,12 +878,4 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $count = $store->countWatchedItems( $this->getUser() );
                return floor( $count / 2 );
        }
-
-       function getDefaultLimit() {
-               return $this->getUser()->getIntOption( 'wllimit' );
-       }
-
-       function getDefaultDays() {
-               return floatval( $this->getUser()->getOption( 'watchlistdays' ) );
-       }
 }
index 0cec3ff..c314f98 100644 (file)
         * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
         * @param {Object} config Additional configuration
         * @cfg {string} savedQueriesPreferenceName Where to save the saved queries
+        * @cfg {string} daysPreferenceName Preference name for the days filter
+        * @cfg {string} limitPreferenceName Preference name for the limit filter
         */
        mw.rcfilters.Controller = function MwRcfiltersController( filtersModel, changesListModel, savedQueriesModel, config ) {
                this.filtersModel = filtersModel;
                this.changesListModel = changesListModel;
                this.savedQueriesModel = savedQueriesModel;
                this.savedQueriesPreferenceName = config.savedQueriesPreferenceName;
+               this.daysPreferenceName = config.daysPreferenceName;
+               this.limitPreferenceName = config.limitPreferenceName;
 
                this.requestCounter = {};
                this.baseFilterState = {};
                                                max: 1000
                                        },
                                        sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); },
-                                       'default': displayConfig.limitDefault,
-                                       // Temporarily making this not sticky until we resolve the problem
-                                       // with the misleading preference. Note that if this is to be permanent
-                                       // we should remove all sticky behavior methods completely
-                                       // See T172156
-                                       // isSticky: true,
+                                       'default': mw.user.options.get( this.limitPreferenceName, displayConfig.limitDefault ),
+                                       isSticky: true,
                                        excludedFromSavedQueries: true,
                                        filters: displayConfig.limitArray.map( function ( num ) {
                                                return controller._createFilterDataFromNumber( num, num );
                                                        ( Number( i ) * 24 ).toFixed( 2 ) :
                                                        Number( i );
                                        },
-                                       'default': displayConfig.daysDefault,
-                                       // Temporarily making this not sticky while limit is not sticky, see above
-                                       // isSticky: true,
+                                       'default': mw.user.options.get( this.daysPreferenceName, displayConfig.daysDefault ),
+                                       isSticky: true,
                                        excludedFromSavedQueries: true,
                                        filters: [
                                                // Hours (1, 2, 6, 12)
        /**
         * Update the limit default value
         *
-        * param {number} newValue New value
+        * @param {number} newValue New value
         */
-       mw.rcfilters.Controller.prototype.updateLimitDefault = function ( /* newValue */ ) {
-               // HACK: Temporarily remove this from being sticky
-               // See T172156
-
-               /*
-               if ( !$.isNumeric( newValue ) ) {
-                       return;
-               }
-
-               newValue = Number( newValue );
-
-               if ( mw.user.options.get( 'rcfilters-rclimit' ) !== newValue ) {
-                       // Save the preference
-                       new mw.Api().saveOption( 'rcfilters-rclimit', newValue );
-                       // Update the preference for this session
-                       mw.user.options.set( 'rcfilters-rclimit', newValue );
-               }
-               */
-               return;
+       mw.rcfilters.Controller.prototype.updateLimitDefault = function ( newValue ) {
+               this.updateNumericPreference( this.limitPreferenceName, newValue );
        };
 
        /**
         * Update the days default value
         *
-        * param {number} newValue New value
+        * @param {number} newValue New value
         */
-       mw.rcfilters.Controller.prototype.updateDaysDefault = function ( /* newValue */ ) {
-               // HACK: Temporarily remove this from being sticky
-               // See T172156
-
-               /*
-               if ( !$.isNumeric( newValue ) ) {
-                       return;
-               }
-
-               newValue = Number( newValue );
-
-               if ( mw.user.options.get( 'rcdays' ) !== newValue ) {
-                       // Save the preference
-                       new mw.Api().saveOption( 'rcdays', newValue );
-                       // Update the preference for this session
-                       mw.user.options.set( 'rcdays', newValue );
-               }
-               */
-               return;
+       mw.rcfilters.Controller.prototype.updateDaysDefault = function ( newValue ) {
+               this.updateNumericPreference( this.daysPreferenceName, newValue );
        };
 
        /**
         * Update the group by page default value
         *
-        * @param {number} newValue New value
+        * @param {boolean} newValue New value
         */
        mw.rcfilters.Controller.prototype.updateGroupByPageDefault = function ( newValue ) {
+               this.updateNumericPreference( 'usenewrc', Number( newValue ) );
+       };
+
+       /**
+        * Update a numeric preference with a new value
+        *
+        * @param {string} prefName Preference name
+        * @param {number|string} newValue New value
+        */
+       mw.rcfilters.Controller.prototype.updateNumericPreference = function ( prefName, newValue ) {
                if ( !$.isNumeric( newValue ) ) {
                        return;
                }
 
                newValue = Number( newValue );
 
-               if ( mw.user.options.get( 'usenewrc' ) !== newValue ) {
+               if ( mw.user.options.get( prefName ) !== newValue ) {
                        // Save the preference
-                       new mw.Api().saveOption( 'usenewrc', newValue );
+                       new mw.Api().saveOption( prefName, newValue );
                        // Update the preference for this session
-                       mw.user.options.set( 'usenewrc', newValue );
+                       mw.user.options.set( prefName, newValue );
                }
        };
 
index 14f0f6b..10bbcf6 100644 (file)
                                wlTopSection,
                                namespaces,
                                savedQueriesPreferenceName = mw.config.get( 'wgStructuredChangeFiltersSavedQueriesPreferenceName' ),
+                               daysPreferenceName = mw.config.get( 'wgStructuredChangeFiltersDaysPreferenceName' ),
+                               limitPreferenceName = mw.config.get( 'wgStructuredChangeFiltersLimitPreferenceName' ),
                                filtersModel = new mw.rcfilters.dm.FiltersViewModel(),
                                changesListModel = new mw.rcfilters.dm.ChangesListViewModel(),
                                savedQueriesModel = new mw.rcfilters.dm.SavedQueriesModel( filtersModel ),
                                controller = new mw.rcfilters.Controller(
                                        filtersModel, changesListModel, savedQueriesModel,
                                        {
-                                               savedQueriesPreferenceName: savedQueriesPreferenceName
+                                               savedQueriesPreferenceName: savedQueriesPreferenceName,
+                                               daysPreferenceName: daysPreferenceName,
+                                               limitPreferenceName: limitPreferenceName
                                        }
                                ),
                                $overlay = $( '<div>' )
index cd22e89..6be6968 100644 (file)
         */
        mw.rcfilters.ui.ChangesLimitAndDateButtonWidget.prototype.onPopupGroupByPage = function ( isGrouped ) {
                this.controller.toggleFilterSelect( this.groupByPageItemModel.getName(), isGrouped );
-               this.controller.updateGroupByPageDefault( Number( isGrouped ) );
+               this.controller.updateGroupByPageDefault( isGrouped );
                this.button.popup.toggle( false );
        };