specials: Add $subpage param to RedirectSpecialPage::getRedirectQuery
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 6 Apr 2019 00:50:55 +0000 (01:50 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 15 Apr 2019 14:44:38 +0000 (14:44 +0000)
This will make it easier to create redirects where $subpage is the title,
e.g. "Special:Example/Foo?x=y" to "index.php?title=Foo&x=y".

To do that conveniently, getRedirectQuery() needs access to $subpage.
The alternative is to do Title-parsing inside getRedirect(), which then
complicates this significantly as one has to deal with absence of a title
(null) and invalid titles (illegal chars etc.).

By using it plainly as query parameter (defaulting to null/omitted), this
is all deferred to index.php, which seems like a better separation of
concerns.

Motivated by SpecialMobileHistory in MobileFrontend (Ic0aea7ee340a).

Change-Id: I9fe78f479053fb55952ba78850d2fc281a039fe3

includes/MediaWiki.php
includes/specialpage/RedirectSpecialPage.php

index 990ed4e..69bafaf 100644 (file)
@@ -262,7 +262,7 @@ class MediaWiki {
                                                $target = $specialPage->getRedirect( $subpage );
                                                // target can also be true. We let that case fall through to normal processing.
                                                if ( $target instanceof Title ) {
-                                                       $query = $specialPage->getRedirectQuery() ?: [];
+                                                       $query = $specialPage->getRedirectQuery( $subpage ) ?: [];
                                                        $request = new DerivativeRequest( $this->context->getRequest(), $query );
                                                        $request->setRequestURL( $this->context->getRequest()->getRequestURL() );
                                                        $this->context->setRequest( $request );
index 23a868e..c28b89e 100644 (file)
@@ -38,7 +38,7 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
         */
        public function execute( $subpage ) {
                $redirect = $this->getRedirect( $subpage );
-               $query = $this->getRedirectQuery();
+               $query = $this->getRedirectQuery( $subpage );
 
                if ( $redirect instanceof Title ) {
                        // Redirect to a page title with possible query parameters
@@ -66,9 +66,10 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
         * Return part of the request string for a special redirect page
         * This allows passing, e.g. action=history to Special:Mypage, etc.
         *
+        * @param string|null $subpage
         * @return array|bool
         */
-       public function getRedirectQuery() {
+       public function getRedirectQuery( $subpage ) {
                $params = [];
                $request = $this->getRequest();