From 7ac7ffc2b3c4d093d1fe9d4e0d19bfd28dbde851 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 6 Apr 2019 01:50:55 +0100 Subject: [PATCH] specials: Add $subpage param to RedirectSpecialPage::getRedirectQuery 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 | 2 +- includes/specialpage/RedirectSpecialPage.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 990ed4e358..69bafafb7f 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -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 ); diff --git a/includes/specialpage/RedirectSpecialPage.php b/includes/specialpage/RedirectSpecialPage.php index 23a868e363..c28b89ea2c 100644 --- a/includes/specialpage/RedirectSpecialPage.php +++ b/includes/specialpage/RedirectSpecialPage.php @@ -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(); -- 2.20.1