Mooeypoo has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/399310 )
Change subject: RCFilters: Only normalize title with 'target' when it is needed ...................................................................... RCFilters: Only normalize title with 'target' when it is needed We right now only need to normalize titles that are with subpages into target= parameter in the RCLinked page. There's no need to do that in RC or Watchlist, and it might interfere with other (or future) features if we do. This commit sets the normalization as conditional on a config variable, that is given on initialization based on the proper page we're in. Change-Id: I288221edb143e0b3417e161062faf2eb4f9f9a51 --- M resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js M resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js M resources/src/mediawiki.rcfilters/mw.rcfilters.init.js M tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js 4 files changed, 86 insertions(+), 52 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/10/399310/1 diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index 79546b4..1084953 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -20,6 +20,7 @@ this.savedQueriesPreferenceName = config.savedQueriesPreferenceName; this.daysPreferenceName = config.daysPreferenceName; this.limitPreferenceName = config.limitPreferenceName; + this.normalizeTarget = !!config.normalizeTarget; this.requestCounter = {}; this.baseFilterState = {}; @@ -213,7 +214,8 @@ this.filtersModel.initializeFilters( filterStructure, views ); this.uriProcessor = new mw.rcfilters.UriProcessor( - this.filtersModel + this.filtersModel, + { normalizeTarget: this.normalizeTarget } ); if ( !mw.user.isAnon() ) { diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js index 7bb0a22..87aad09 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js @@ -4,9 +4,13 @@ * URI Processor for RCFilters * * @param {mw.rcfilters.dm.FiltersViewModel} filtersModel Filters view model + * @param {Object} [config] Configuration object */ - mw.rcfilters.UriProcessor = function MwRcfiltersController( filtersModel ) { + mw.rcfilters.UriProcessor = function MwRcfiltersController( filtersModel, config ) { + config = config || {}; this.filtersModel = filtersModel; + + this.setNormalizeTarget( !!config.normalizeTarget ); }; /* Initialization */ @@ -102,6 +106,10 @@ var parts, // matches [/wiki/]SpecialNS:RCL/[Namespace:]Title/Subpage/Subsubpage/etc re = /^((?:\/.+?\/)?.*?:.*?)\/(.*)$/; + + if ( !this.normalizeTarget ) { + return uri; + } // target in title param if ( uri.query.title ) { @@ -277,4 +285,13 @@ { urlversion: '2' } ); }; + + /** + * Set the option to normalize 'target' portion of the URL + * + * @param {boolean} isNormalized Target should be normalized + */ + mw.rcfilters.UriProcessor.prototype.setNormalizeTarget = function ( isNormalized ) { + this.normalizeTarget = !!isNormalized; + }; }( mediaWiki, jQuery ) ); diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js index f770899..2fb2262 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js @@ -24,7 +24,7 @@ { savedQueriesPreferenceName: savedQueriesPreferenceName, daysPreferenceName: daysPreferenceName, - limitPreferenceName: limitPreferenceName + limitPreferenceName: limitPreferenceName, } ); diff --git a/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js b/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js index fbd159c..398e5d4 100644 --- a/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js +++ b/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js @@ -278,58 +278,73 @@ } ); 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)' - }, - { - input: 'http://host/wiki/Special:Watchlist', - output: 'http://host/wiki/Special:Watchlist', - message: 'No target specified' - } - ]; + 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, + { + normalizeTarget: testCase.normalizeTarget === undefined ? + true : testCase.normalizeTarget + } + ); + 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 ); -- To view, visit https://gerrit.wikimedia.org/r/399310 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I288221edb143e0b3417e161062faf2eb4f9f9a51 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits