MediaWiki
master
Toggle main menu visibility
UserNotLoggedIn.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\Exception;
8
9
use MediaWiki\Context\RequestContext;
10
use MediaWiki\SpecialPage\SpecialPage;
11
54
class
UserNotLoggedIn
extends
ErrorPageError
{
55
56
private
bool
$alwaysRedirectToLoginPage;
57
77
public
function
__construct
(
78
$reasonMsg =
'exception-nologin-text'
,
79
$titleMsg =
'exception-nologin'
,
80
$params
= [],
81
bool
$alwaysRedirectToLoginPage =
false
82
) {
83
$context = RequestContext::getMain();
84
// Replace the reason message for one that describes creating account when the user is a temporary account
85
// when such a custom message exists (T358586).
86
if
( $context->getUser()->isTemp() && !$alwaysRedirectToLoginPage ) {
87
// For grep to find usages: exception-nologin-text-for-temp-user
88
$tempUserReasonMsg = $reasonMsg .
'-for-temp-user'
;
89
if
( $context->msg( $tempUserReasonMsg )->exists() ) {
90
$reasonMsg = $tempUserReasonMsg;
91
}
92
}
93
parent::__construct( $titleMsg, $reasonMsg,
$params
);
94
$this->alwaysRedirectToLoginPage = $alwaysRedirectToLoginPage;
95
}
96
102
public
function
report
( $action = self::SEND_OUTPUT ) {
103
// If an unsupported message is used, don't try redirecting to Special:Userlogin,
104
// since the message may not be compatible.
105
if
( !in_array( $this->
msg
,
LoginErrorHelper::getValidErrorMessages
() ) ) {
106
parent::report( $action );
107
return
;
108
}
109
110
$context = RequestContext::getMain();
111
112
// Message is valid. Redirect to Special:Userlogin, unless the user is a temporary account in which case
113
// redirect to Special:CreateAccount (T358586).
114
$specialPageName =
'Userlogin'
;
115
if
( $context->getUser()->isTemp() && !$this->alwaysRedirectToLoginPage ) {
116
$specialPageName =
'CreateAccount'
;
117
}
118
119
$output = $context->getOutput();
120
$query = $context->getRequest()->getQueryValues();
121
// Title will be overridden by returnto
122
unset( $query[
'title'
] );
123
// Redirect to Special:Userlogin
124
$output->redirect(
SpecialPage::getTitleFor
( $specialPageName )->getFullURL( [
125
'warning'
=> $this->
msg
,
126
// Return to this page when the user logs in
127
'returnto'
=> $context->getTitle()->getFullText(),
128
'returntoquery'
=>
wfArrayToCgi
( $query ),
129
// keep the current language
130
'uselang'
=> $query[
'uselang'
] ??
null
,
131
'variant'
=> $query[
'variant'
] ??
null
,
132
// Forward the 'display' parameter if provided
133
'display'
=> $query[
'display'
] ??
null
,
134
] ) );
135
136
if
( $action === self::SEND_OUTPUT ) {
137
$output->output();
138
}
139
}
140
}
141
143
class_alias( UserNotLoggedIn::class,
'UserNotLoggedIn'
);
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition
GlobalFunctions.php:219
MediaWiki\Exception\ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:21
MediaWiki\Exception\ErrorPageError\$params
array $params
Definition
ErrorPageError.php:29
MediaWiki\Exception\LoginErrorHelper\getValidErrorMessages
static getValidErrorMessages()
Returns an array of all error and warning messages that can be displayed on Special:UserLogin or Spec...
Definition
LoginErrorHelper.php:49
MediaWiki\Exception\MWException\msg
msg( $key, $fallback,... $params)
Get a message from i18n.
Definition
MWException.php:65
MediaWiki\Exception\UserNotLoggedIn
Redirect a user to the login page or account creation page.
Definition
UserNotLoggedIn.php:54
MediaWiki\Exception\UserNotLoggedIn\__construct
__construct( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', $params=[], bool $alwaysRedirectToLoginPage=false)
Definition
UserNotLoggedIn.php:77
MediaWiki\Exception\UserNotLoggedIn\report
report( $action=self::SEND_OUTPUT)
Redirect to Special:Userlogin or Special:CreateAccount if the specified message is compatible.
Definition
UserNotLoggedIn.php:102
MediaWiki\SpecialPage\SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition
SpecialPage.php:129
includes
Exception
UserNotLoggedIn.php
Generated on
for MediaWiki by
1.18.0