MediaWiki master
UserNotLoggedIn Class Reference

Redirect a user to the login page or account creation page. More...

Inherits ErrorPageError.

Collaboration diagram for UserNotLoggedIn:

Public Member Functions

 __construct ( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', $params=[], bool $alwaysRedirectToLoginPage=false)
 
 report ( $action=self::SEND_OUTPUT)
 Redirect to Special:Userlogin or Special:CreateAccount if the specified message is compatible.
 
- Public Member Functions inherited from ErrorPageError
 __construct ( $title, $msg, $params=[])
 Note: these arguments are keys into wfMessage(), not text!
 
 getMessageObject ()
 Return a Message object for this exception.
 
- Public Member Functions inherited from MWException
 hasOverriddenHandler ()
 
 isLoggable ()
 Whether to log this exception in the exception debug log.
 
 msg ( $key, $fallback,... $params)
 Get a message from i18n.
 
 report ()
 Output a report about the exception and takes care of formatting.
 
 useMessageCache ()
 Can the extension use the Message class/wfMessage to get i18n-ed messages?
 

Additional Inherited Members

- Static Public Member Functions inherited from MWException
static isCommandLine ()
 Check whether we are in command line mode or not to report the exception in the correct format.
 
- Public Attributes inherited from ErrorPageError
string MessageSpecifier $msg
 
array $params
 
string MessageSpecifier $title
 
const SEND_OUTPUT = 0
 
const STAGE_OUTPUT = 1
 

Detailed Description

Redirect a user to the login page or account creation page.

This is essentially an ErrorPageError exception which by default uses the 'exception-nologin' as a title and 'exception-nologin-text' for the message.

When the user is a temporary account, the redirect will point to the Special:CreateAccount page unless specifically set not to. In all other cases, the redirect is to the Special:UserLogin page.

The message key for the reason will be modified to include '-for-temp-user' when the user is logged in to a temporary account and this message key exists (i.e. defined and not empty).

Note
In order for this exception to redirect, the error message passed to the constructor has to be explicitly added to LoginHelper::validErrorMessages or with the LoginFormValidErrorMessages hook. Otherwise, the user will just be shown the message rather than redirected.
Example:
if ( $user->isAnon() ) {
throw new UserNotLoggedIn();
}
Redirect a user to the login page or account creation page.

Note the parameter order differs from ErrorPageError, this allows you to simply specify a reason without overriding the default title.

Example:
if ( $user->isAnon() ) {
throw new UserNotLoggedIn( 'action-require-loggedin' );
}

You can use SpecialPage::requireLogin and SpecialPage::requireNamedUser to throw this exception when the user is an anon user or not named respectively.

Stability: newable
See also
T39627
Since
1.20

Definition at line 66 of file UserNotLoggedIn.php.

Constructor & Destructor Documentation

◆ __construct()

UserNotLoggedIn::__construct ( $reasonMsg = 'exception-nologin-text',
$titleMsg = 'exception-nologin',
$params = [],
bool $alwaysRedirectToLoginPage = false )
Stability: stable
to call
Note
The value of the $reasonMsg parameter must be set with the LoginFormValidErrorMessages hook if you want the user to be automatically redirected to the login form.
Parameters
string$reasonMsgA message key containing the reason for the error. '-for-temp-user' will be appended to the end of the message key if the user is a temporary account and the redirect is to the Special:CreateAccount page. The modification is skipped if the message key does not exist. Optional, default: 'exception-nologin-text'
string$titleMsgA message key to set the page title. Optional, default: 'exception-nologin'
array$paramsParameters to wfMessage() for $reasonMsg and $tempUserReasonMsg Optional, default: []
bool$alwaysRedirectToLoginPageWhether we should always redirect to the login page, even if the user is a temporary account. If false (the default), the redirect will be to Special:CreateAccount when the user is logged in to a temporary account.

Definition at line 89 of file UserNotLoggedIn.php.

References $params.

Member Function Documentation

◆ report()

UserNotLoggedIn::report ( $action = self::SEND_OUTPUT)

Redirect to Special:Userlogin or Special:CreateAccount if the specified message is compatible.

Otherwise, show an error page as usual.

Parameters
int$action

Reimplemented from ErrorPageError.

Definition at line 114 of file UserNotLoggedIn.php.

References MWException\msg(), and wfArrayToCgi().


The documentation for this class was generated from the following file: