From: Moriel Schottlender Date: Wed, 2 Aug 2017 20:44:11 +0000 (-0700) Subject: RCFilters: Normalize user-generated default values X-Git-Tag: 1.31.0-rc.0~2493^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=684b0dc227777739b29cb8596275bdb9a4658628;p=lhc%2Fweb%2Fwiklou.git RCFilters: Normalize user-generated default values Bug: T172026 Change-Id: Id75116cf22a31f8b762801fc0a6aee554a9ca6b2 --- diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js index c4cce8d64b..f7021e2bb9 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js @@ -736,11 +736,11 @@ this.getType() === 'single_option' && !oneWasSelected ) { + item = this.getItems()[ 0 ]; if ( defaultParams[ this.getName() ] ) { item = this.getItemByParamName( defaultParams[ this.getName() ] ); - } else { - item = this.getItems()[ 0 ]; } + result[ item.getName() ] = true; } diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index f07d3f1f59..16822d8810 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -92,7 +92,7 @@ // 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 = { @@ -280,20 +280,28 @@ * @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