RCFilters: Always put highlight values in the URL
authorMoriel Schottlender <moriel@gmail.com>
Sat, 13 May 2017 18:21:14 +0000 (11:21 -0700)
committerMooeypoo <moriel@gmail.com>
Sun, 14 May 2017 02:23:56 +0000 (02:23 +0000)
Up until now, we only populated highlights in the URL if the item had
a highlight, otherwise it was not in the url at all. However, now that
the system can load defaults from saved queries that can have highlights
themselves, then every time we reload the page (and the system checks
to get defaults merged with the URL query) nothing actively overrides
the default highlight value if it exists.

This meant that if you have a saved query default with any highlights
in it, every time you load the page from the URL it will **also add**
the default highlights that you have saved.

To prevent this, the URL now needs to always populate items with
highlight value, even if that value is null. When we literally ask
for defaults or when we actively load a saved query, that value will
be overridden, but if we have a URL with highlights enabled at all,
the defaults will not override and add a redundany unneeded highlight
just because it existed in your saved query.

Bug: T165231
Change-Id: Ia43b5c777c0b4e238e99818696a3a60dda0daca9

resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

index 81b9dc3..4a9e780 100644 (file)
                        highlightedItems[ item.getName() ] = highlightEnabled ?
                                item.getHighlightColor() : null;
                } );
-               highlightedItems.highlight = this.filtersModel.isHighlightEnabled();
+               // Stored as a string '0' or '1'
+               highlightedItems.highlight = String( Number( this.filtersModel.isHighlightEnabled() ) );
 
                // Add item
                this.savedQueriesModel.addNewQuery(
                // highlight params
                uri.query.highlight = Number( this.filtersModel.isHighlightEnabled() );
                Object.keys( highlightParams ).forEach( function ( paramName ) {
-                       if ( highlightParams[ paramName ] ) {
-                               uri.query[ paramName ] = highlightParams[ paramName ];
-                       } else {
-                               delete uri.query[ paramName ];
-                       }
+                       // Always have some value (either the color or null) so that
+                       // if we have something in the URL that doesn't have the highlight
+                       // intentionally, it can override default with highlight.
+                       // Otherwise, the $.extend will always add the highlight that
+                       // exists in the default even if the URL query that is being
+                       // refreshed has different highlights, or has highlights enabled
+                       // but no active highlights anywhere
+                       uri.query[ paramName ] = highlightParams[ paramName ] ?
+                               highlightParams[ paramName ] : null;
                } );
 
                return uri;