RCLFilters: support target page with a subpage
authorStephane Bisson <sbisson@wikimedia.org>
Wed, 13 Dec 2017 18:29:43 +0000 (13:29 -0500)
committerStephane Bisson <sbisson@wikimedia.org>
Wed, 13 Dec 2017 18:29:43 +0000 (13:29 -0500)
Correctly extract the target page when it has a subpage.
Examples (taken from unit tests):
http://host/wiki/Special:RecentChangesLinked/Moai/Sub1
http://host/wiki/Special:RecentChangesLinked/Category:Foo/Bar
http://host/w/index.php?title=Special:RecentChangesLinked/Moai/Sub1

Bug: T182734
Change-Id: Id6909728f461a3cd687185abd304f2fac5dc6000

resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js
tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js

index 3e1191f..05aa2fc 100644 (file)
         */
        mw.rcfilters.UriProcessor.prototype._normalizeTargetInUri = function ( uri ) {
                var parts,
-                       re = /^((?:\/.+\/)?.+:.+)\/(.+)$/; // matches [namespace:]Title/Subpage
+                       // matches [/wiki/]SpecialNS:RCL/[Namespace:]Title/Subpage/Subsubpage/etc
+                       re = /^((?:\/.+?\/)?.*?:.*?)\/(.*)$/;
 
                // target in title param
                if ( uri.query.title ) {
index 674bf07..a234d1a 100644 (file)
                                        output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai',
                                        message: 'Target as subpage in path'
                                },
+                               {
+                                       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',