RCFilters: Respect subpage in RCLinked
authorMoriel Schottlender <moriel@gmail.com>
Tue, 21 Nov 2017 23:59:44 +0000 (15:59 -0800)
committerMoriel Schottlender <moriel@gmail.com>
Wed, 22 Nov 2017 18:02:25 +0000 (10:02 -0800)
Make sure that when we redirect a URL when there's a saved query,
we retain the information about a subpage.

Then, normalize the URL to always use &target=xxx so that the
system knows to correct the value if the user uses the form that
is, for the moment, outside the regular RCFilters interface.

Bug: T181100
Change-Id: I75cfb2b56a4da6357e6117b3f34f3178bfb2c90c

includes/specials/SpecialRecentchangeslinked.php
resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js

index 358a309..e4cc3d1 100644 (file)
@@ -30,6 +30,8 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
        /** @var bool|Title */
        protected $rclTargetTitle;
 
+       protected $rclTarget;
+
        function __construct() {
                parent::__construct( 'Recentchangeslinked' );
        }
@@ -44,6 +46,7 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
 
        public function parseParameters( $par, FormOptions $opts ) {
                $opts['target'] = $par;
+               $this->rclTarget = $par;
        }
 
        /**
@@ -293,4 +296,15 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
        public function prefixSearchSubpages( $search, $limit, $offset ) {
                return $this->prefixSearchString( $search, $limit, $offset );
        }
+
+       /**
+        * Get a self-referential title object
+        * with consideration to the given subpage.
+        *
+        * @return Title
+        * @since 1.23
+        */
+       public function getPageTitle() {
+               return parent::getPageTitle( $this->rclTarget );
+       }
 }
index 621c200..fe806ed 100644 (file)
@@ -63,7 +63,8 @@
         * @return {mw.Uri} Updated Uri
         */
        mw.rcfilters.UriProcessor.prototype.getUpdatedUri = function ( uriQuery ) {
-               var uri = new mw.Uri(),
+               var titlePieces,
+                       uri = new mw.Uri(),
                        unrecognizedParams = this.getUnrecognizedParams( uriQuery || uri.query );
 
                if ( uriQuery ) {
                        uri.query = uriQuery;
                }
 
+               // Normalize subpage to use &target= so we are always
+               // consistent in Special:RecentChangesLinked between the
+               // ?title=Special:RecentChangesLinked/TargetPage and
+               // ?title=Special:RecentChangesLinked&target=TargetPage
+               if ( uri.query.title && uri.query.title.indexOf( '/' ) !== -1 ) {
+                       titlePieces = uri.query.title.split( '/' );
+
+                       unrecognizedParams.title = titlePieces.shift();
+                       unrecognizedParams.target = titlePieces.join( '/' );
+               }
+
                uri.query = this.filtersModel.getMinimizedParamRepresentation(
                        $.extend(
                                true,
@@ -87,7 +99,6 @@
 
                // Reapply unrecognized params and url version
                uri.query = $.extend( true, {}, uri.query, unrecognizedParams, { urlversion: '2' } );
-
                return uri;
        };