Merge "RCFilters: Only normalize title with 'target' when it is needed"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 10 Jan 2018 14:04:58 +0000 (14:04 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 10 Jan 2018 14:04:58 +0000 (14:04 +0000)
1  2 
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js
resources/src/mediawiki.rcfilters/mw.rcfilters.init.js
tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js

@@@ -12,6 -12,9 +12,9 @@@
         * @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
+        * @cfg {boolean} [normalizeTarget] Dictates whether or not to go through the
+        *  title normalization to separate title subpage/parts into the target= url
+        *  parameter
         */
        mw.rcfilters.Controller = function MwRcfiltersController( filtersModel, changesListModel, savedQueriesModel, config ) {
                this.filtersModel = filtersModel;
@@@ -20,6 -23,7 +23,7 @@@
                this.savedQueriesPreferenceName = config.savedQueriesPreferenceName;
                this.daysPreferenceName = config.daysPreferenceName;
                this.limitPreferenceName = config.limitPreferenceName;
+               this.normalizeTarget = !!config.normalizeTarget;
  
                this.requestCounter = {};
                this.baseFilterState = {};
                this.filtersModel.initializeFilters( filterStructure, views );
  
                this.uriProcessor = new mw.rcfilters.UriProcessor(
-                       this.filtersModel
+                       this.filtersModel,
+                       { normalizeTarget: this.normalizeTarget }
                );
  
                if ( !mw.user.isAnon() ) {
                } );
        };
  
 -      /**
 -       * Switch the view of the filters model
 -       *
 -       * @param {string} view Requested view
 -       */
 -      mw.rcfilters.Controller.prototype.switchView = function ( view ) {
 -              this.filtersModel.switchView( view );
 -      };
 -
        /**
         * Reset to default filters
         */
                        this.updateChangesList( null, 'markSeen' );
                }.bind( this ) );
        };
 +
 +      /**
 +       * Set the current search for the system.
 +       *
 +       * @param {string} searchQuery Search query, including triggers
 +       */
 +      mw.rcfilters.Controller.prototype.setSearch = function ( searchQuery ) {
 +              this.filtersModel.setSearch( searchQuery );
 +      };
 +
 +      /**
 +       * Switch the view by changing the search query trigger
 +       * without changing the search term
 +       *
 +       * @param  {string} view View to change to
 +       */
 +      mw.rcfilters.Controller.prototype.switchView = function ( view ) {
 +              this.setSearch(
 +                      this.filtersModel.getViewTrigger( view ) +
 +                      this.filtersModel.removeViewTriggers( this.filtersModel.getSearch() )
 +              );
 +      };
 +
 +      /**
 +       * Reset the search for a specific view. This means we null the search query
 +       * and replace it with the relevant trigger for the requested view
 +       *
 +       * @param  {string} [view='default'] View to change to
 +       */
 +      mw.rcfilters.Controller.prototype.resetSearchForView = function ( view ) {
 +              view = view || 'default';
 +
 +              this.setSearch(
 +                      this.filtersModel.getViewTrigger( view )
 +              );
 +      };
  }( mediaWiki, jQuery ) );
@@@ -24,7 -24,8 +24,8 @@@
                                        {
                                                savedQueriesPreferenceName: savedQueriesPreferenceName,
                                                daysPreferenceName: daysPreferenceName,
-                                               limitPreferenceName: limitPreferenceName
+                                               limitPreferenceName: limitPreferenceName,
+                                               normalizeTarget: specialPage === 'Recentchangeslinked'
                                        }
                                );
  
                                conditionalViews
                        );
  
 +                      mainWrapperWidget.initFormWidget( specialPage );
 +
                        $( 'a.mw-helplink' ).attr(
                                'href',
                                'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:New_filters_for_edit_review'
@@@ -62,7 -62,7 +62,7 @@@
                var uriProcessor,
                        filtersModel = new mw.rcfilters.dm.FiltersViewModel(),
                        makeUri = function ( queryParams ) {
 -                              var uri = new mw.Uri();
 +                              var uri = new mw.Uri( 'http://server/wiki/Special:RC' );
                                uri.query = queryParams;
                                return uri;
                        };
        } );
  
        QUnit.test( '_normalizeTargetInUri', function ( assert ) {
-               var uriProcessor = new mw.rcfilters.UriProcessor( null ),
-                       cases = [
-                               {
-                                       input: 'http://host/wiki/Special:RecentChangesLinked/Moai',
-                                       output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai',
-                                       message: 'Target as subpage in path'
-                               },
-                               {
-                                       input: 'http://host/wiki/Special:RecentChangesLinked/Château',
-                                       output: 'http://host/wiki/Special:RecentChangesLinked?target=Château',
-                                       message: 'Target as subpage in path with special characters'
-                               },
-                               {
-                                       input: 'http://host/wiki/Special:RecentChangesLinked/Moai/Sub1',
-                                       output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai/Sub1',
-                                       message: 'Target as subpage also has a subpage'
-                               },
-                               {
-                                       input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo',
-                                       output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo',
-                                       message: 'Target as subpage in path (with namespace)'
-                               },
-                               {
-                                       input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo/Bar',
-                                       output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo/Bar',
-                                       message: 'Target as subpage in path also has a subpage (with namespace)'
-                               },
-                               {
-                                       input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai',
-                                       output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai',
-                                       message: 'Target as subpage in title param'
-                               },
-                               {
-                                       input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai/Sub1',
-                                       output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai/Sub1',
-                                       message: 'Target as subpage in title param also has a subpage'
-                               },
-                               {
-                                       input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Category:Foo/Bar',
-                                       output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Category:Foo/Bar',
-                                       message: 'Target as subpage in title param also has a subpage (with namespace)'
-                               },
+               var cases = [
+                       {
+                               input: 'http://host/wiki/Special:RecentChangesLinked/Moai',
+                               output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai',
+                               message: 'Target as subpage in path'
+                       },
+                       {
+                               input: 'http://host/wiki/Special:RecentChangesLinked/Château',
+                               output: 'http://host/wiki/Special:RecentChangesLinked?target=Château',
+                               message: 'Target as subpage in path with special characters'
+                       },
+                       {
+                               input: 'http://host/wiki/Special:RecentChangesLinked/Moai/Sub1',
+                               output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai/Sub1',
+                               message: 'Target as subpage also has a subpage'
+                       },
+                       {
+                               input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo',
+                               output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo',
+                               message: 'Target as subpage in path (with namespace)'
+                       },
+                       {
+                               input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo/Bar',
+                               output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo/Bar',
+                               message: 'Target as subpage in path also has a subpage (with namespace)'
+                       },
+                       {
+                               input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai',
+                               output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai',
+                               message: 'Target as subpage in title param'
+                       },
+                       {
+                               input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai/Sub1',
+                               output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai/Sub1',
+                               message: 'Target as subpage in title param also has a subpage'
+                       },
+                       {
+                               input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Category:Foo/Bar',
+                               output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Category:Foo/Bar',
+                               message: 'Target as subpage in title param also has a subpage (with namespace)'
+                       },
+                       {
+                               input: 'http://host/wiki/Special:Watchlist',
+                               output: 'http://host/wiki/Special:Watchlist',
+                               message: 'No target specified'
+                       },
+                       {
+                               normalizeTarget: false,
+                               input: 'http://host/wiki/Special:RecentChanges/Foo',
+                               output: 'http://host/wiki/Special:RecentChanges/Foo',
+                               message: 'Do not normalize if "normalizeTarget" is false.'
+                       }
+               ];
+               cases.forEach( function ( testCase ) {
+                       var uriProcessor = new mw.rcfilters.UriProcessor(
+                               null,
                                {
-                                       input: 'http://host/wiki/Special:Watchlist',
-                                       output: 'http://host/wiki/Special:Watchlist',
-                                       message: 'No target specified'
+                                       normalizeTarget: testCase.normalizeTarget === undefined ?
+                                               true : testCase.normalizeTarget
                                }
-                       ];
+                       );
  
-               cases.forEach( function ( testCase ) {
                        assert.equal(
-                               uriProcessor._normalizeTargetInUri( new mw.Uri( testCase.input ) ).toString(),
+                               uriProcessor._normalizeTargetInUri(
+                                       new mw.Uri( testCase.input )
+                               ).toString(),
                                new mw.Uri( testCase.output ).toString(),
                                testCase.message
                        );