wiki.techinc.nl/includes/exception/UserNotLoggedIn.php
Tyler Romeo e0af129cbd
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
2014-07-15 14:48:09 -04:00

81 lines
2.4 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
/**
* Shows a generic "user is not logged in" error page.
*
* This is essentially an ErrorPageError exception which by default uses the
* 'exception-nologin' as a title and 'exception-nologin-text' for the message.
* @see bug 37627
* @since 1.20
*
* @par Example:
* @code
* if( $user->isAnon() ) {
* throw new UserNotLoggedIn();
* }
* @endcode
*
* Note the parameter order differs from ErrorPageError, this allows you to
* simply specify a reason without overriding the default title.
*
* @par Example:
* @code
* if( $user->isAnon() ) {
* throw new UserNotLoggedIn( 'action-require-loggedin' );
* }
* @endcode
*
* @ingroup Exception
*/
class UserNotLoggedIn extends ErrorPageError {
/**
* @param string $reasonMsg A message key containing the reason for the error.
* Optional, default: 'exception-nologin-text'
* @param string $titleMsg A message key to set the page title.
* Optional, default: 'exception-nologin'
* @param array $params Parameters to wfMessage().
* Optional, default: array()
*/
public function __construct(
$reasonMsg = 'exception-nologin-text',
$titleMsg = 'exception-nologin',
$params = array()
) {
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();
}
}