From e0af129cbdb7421b4d9d7858cc63125e12f35a4a Mon Sep 17 00:00:00 2001 From: Tyler Romeo Date: Tue, 15 Jul 2014 14:48:09 -0400 Subject: [PATCH] Make UserNotLoggedIn redirect to login page For pages like Special:Watchlist that throw a UserNotLoggedIn exception when the user is anonymous, this patch makes the page redirect to the login page automatically. This is instead of the current behavior of showing a link to the login page that the user must click. (Also, Special:Userlogin has existing functionality that will redirect the user back once they are logged in.) Bug: 15484 Change-Id: Ic7e1d5a8984e1b42c8f2ebceff094106a3ed1efa --- includes/exception/UserNotLoggedIn.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/exception/UserNotLoggedIn.php b/includes/exception/UserNotLoggedIn.php index 9d89009100..f7a56b5091 100644 --- a/includes/exception/UserNotLoggedIn.php +++ b/includes/exception/UserNotLoggedIn.php @@ -62,4 +62,20 @@ class UserNotLoggedIn extends ErrorPageError { ) { parent::__construct( $titleMsg, $reasonMsg, $params ); } + + /** + * Redirect to Special:Userlogin + */ + public function report() { + $context = RequestContext::getMain(); + + $output = $context->getOutput(); + $output->redirect( SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( array( + // Return to this page when the user logs in + 'returnto' => $context->getTitle()->getText(), + 'returntoquery' => wfArrayToCgi( $context->getRequest()->getValues() ) + ) ) ); + + $output->output(); + } } -- 2.20.1