Make UserNotLoggedIn redirect to login page
authorTyler Romeo <tylerromeo@gmail.com>
Tue, 15 Jul 2014 18:48:09 +0000 (14:48 -0400)
committerTyler Romeo <tylerromeo@gmail.com>
Tue, 15 Jul 2014 18:48:09 +0000 (14:48 -0400)
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

index 9d89009..f7a56b5 100644 (file)
@@ -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();
+       }
 }