// Convert the default from the old preference
// since the limit preference actually affects more
// than just the RecentChanges page
- limitDefault = Number( mw.user.options.get( 'rcfilters-rclimit', mw.user.options.get( 'rclimit', '50' ) ) );
+ limitDefault = Number( mw.user.options.get( 'rclimit', '50' ) );
// Add parameter range operations
views.range = {
allowArbitrary: true,
validate: $.isNumeric,
range: {
- min: 1,
+ min: 0, // The server normalizes negative numbers to 0 results
max: 1000
},
sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); },
// we should remove all sticky behavior methods completely
// See T172156
// isSticky: true,
- filters: displayConfig.arrayLimit.map( function ( num ) {
+ filters: displayConfig.limitArray.map( function ( num ) {
return controller._createFilterDataFromNumber( num, num );
} )
},
validate: $.isNumeric,
range: {
min: 0,
- max: displayConfig.maxLimit
+ max: displayConfig.maxDays
},
sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); },
numToLabelFunc: function ( i ) {
// Hours (1, 2, 6, 12)
0.04166, 0.0833, 0.25, 0.5
// Days
- ].concat( displayConfig.arrayDays )
+ ].concat( displayConfig.daysArray )
.map( function ( num ) {
return controller._createFilterDataFromNumber(
num,
]
};
+ views.display = {
+ groups: [
+ {
+ name: 'display',
+ type: 'boolean',
+ title: '', // Because it's a hidden group, this title actually appears nowhere
+ hidden: true,
+ isSticky: true,
+ filters: [
+ {
+ name: 'enhanced',
+ 'default': String( mw.user.options.get( 'usenewrc', 0 ) )
+ }
+ ]
+ }
+ ]
+ };
+
// Before we do anything, we need to see if we require additional items in the
// groups that have 'AllowArbitrary'. For the moment, those are only single_option
// groups; if we ever expand it, this might need further generalization:
* @param {string|string[]} arbitraryValues An array of arbitrary values to add to the group
*/
mw.rcfilters.Controller.prototype.addNumberValuesToGroup = function ( groupData, arbitraryValues ) {
- var controller = this;
+ var controller = this,
+ normalizeWithinRange = function ( range, val ) {
+ if ( val < range.min ) {
+ return range.min; // Min
+ } else if ( val >= range.max ) {
+ return range.max; // Max
+ }
+ return val;
+ };
arbitraryValues = Array.isArray( arbitraryValues ) ? arbitraryValues : [ arbitraryValues ];
- // Normalize the arbitrary values
+ // Normalize the arbitrary values and the default value for a range
if ( groupData.range ) {
arbitraryValues = arbitraryValues.map( function ( val ) {
- if ( val < 0 ) {
- return groupData.range.min; // Min
- } else if ( val >= groupData.range.max ) {
- return groupData.range.max; // Max
- }
- return val;
+ return normalizeWithinRange( groupData.range, val );
} );
+
+ // Normalize the default, since that's user defined
+ if ( groupData.default !== undefined ) {
+ groupData.default = String( normalizeWithinRange( groupData.range, groupData.default ) );
+ }
}
// This is only true for single_option group
// the initial defaults or from the URL value that is being normalized
this.updateDaysDefault( this.filtersModel.getGroup( 'days' ).getSelectedItems()[ 0 ].getParamName() );
this.updateLimitDefault( this.filtersModel.getGroup( 'limit' ).getSelectedItems()[ 0 ].getParamName() );
+
+ // TODO: Make these automatic by having the model go over sticky
+ // items and update their default values automatically
};
/**
return;
};
+ /**
+ * Update the group by page default value
+ *
+ * @param {number} newValue New value
+ */
+ mw.rcfilters.Controller.prototype.updateGroupByPageDefault = function ( newValue ) {
+ if ( !$.isNumeric( newValue ) ) {
+ return;
+ }
+
+ newValue = Number( newValue );
+
+ if ( mw.user.options.get( 'usenewrc' ) !== newValue ) {
+ // Save the preference
+ new mw.Api().saveOption( 'usenewrc', newValue );
+ // Update the preference for this session
+ mw.user.options.set( 'usenewrc', newValue );
+ }
+ };
+
/**
* Synchronize the URL with the current state of the filters
* without adding an history entry.