$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',
$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() );
*/
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;
'wgStructuredChangeFiltersSavedQueriesPreferenceName',
static::$savedQueriesPreferenceName
);
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersLimitPreferenceName',
+ static::$limitPreferenceName
+ );
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersDaysPreferenceName',
+ static::$daysPreferenceName
+ );
$out->addJsConfigVars(
'StructuredChangeFiltersLiveUpdatePollingRate',
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()
+ );
}
/**
}
}
- 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 ) );
+ }
}
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;
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;
}
}
*/
class SpecialWatchlist extends ChangesListSpecialPage {
protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
+ protected static $daysPreferenceName = 'watchlistdays';
+ protected static $limitPreferenceName = 'wllimit';
private $maxDays;
}
}
- 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' )
);
}
$count = $store->countWatchedItems( $this->getUser() );
return floor( $count / 2 );
}
-
- function getDefaultLimit() {
- return $this->getUser()->getIntOption( 'wllimit' );
- }
-
- function getDefaultDays() {
- return floatval( $this->getUser()->getOption( 'watchlistdays' ) );
- }
}
* @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 );
}
};
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>' )
*/
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 );
};