MediaWiki
master
UserNotLoggedIn.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\Context\RequestContext
;
22
use
MediaWiki\SpecialPage\SpecialPage
;
23
66
class
UserNotLoggedIn
extends
ErrorPageError
{
67
68
private
bool
$alwaysRedirectToLoginPage;
69
89
public
function
__construct
(
90
$reasonMsg =
'exception-nologin-text'
,
91
$titleMsg =
'exception-nologin'
,
92
$params
= [],
93
bool
$alwaysRedirectToLoginPage =
false
94
) {
95
$context = RequestContext::getMain();
96
// Replace the reason message for one that describes creating account when the user is a temporary account
97
// when such a custom message exists (T358586).
98
if
( $context->getUser()->isTemp() && !$alwaysRedirectToLoginPage ) {
99
// For grep to find usages: exception-nologin-text-for-temp-user
100
$tempUserReasonMsg = $reasonMsg .
'-for-temp-user'
;
101
if
( $context->msg( $tempUserReasonMsg )->exists() ) {
102
$reasonMsg = $tempUserReasonMsg;
103
}
104
}
105
parent::__construct( $titleMsg, $reasonMsg,
$params
);
106
$this->alwaysRedirectToLoginPage = $alwaysRedirectToLoginPage;
107
}
108
114
public
function
report
( $action = self::SEND_OUTPUT ) {
115
// If an unsupported message is used, don't try redirecting to Special:Userlogin,
116
// since the message may not be compatible.
117
if
( !in_array( $this->
msg
, LoginHelper::getValidErrorMessages() ) ) {
118
parent::report( $action );
119
return
;
120
}
121
122
$context = RequestContext::getMain();
123
124
// Message is valid. Redirect to Special:Userlogin, unless the user is a temporary account in which case
125
// redirect to Special:CreateAccount (T358586).
126
$specialPageName =
'Userlogin'
;
127
if
( $context->getUser()->isTemp() && !$this->alwaysRedirectToLoginPage ) {
128
$specialPageName =
'CreateAccount'
;
129
}
130
131
$output = $context->getOutput();
132
$query = $context->getRequest()->getValues();
133
// Title will be overridden by returnto
134
unset( $query[
'title'
] );
135
// Redirect to Special:Userlogin
136
$output->redirect( SpecialPage::getTitleFor( $specialPageName )->getFullURL( [
137
// Return to this page when the user logs in
138
'returnto'
=> $context->getTitle()->getFullText(),
139
'returntoquery'
=>
wfArrayToCgi
( $query ),
140
'warning'
=> $this->
msg
,
141
// Forward the 'display' parameter if provided
142
'display'
=> $query[
'display'
] ??
null
,
143
] ) );
144
145
if
( $action === self::SEND_OUTPUT ) {
146
$output->output();
147
}
148
}
149
}
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:344
$params
array $params
The job parameters.
Definition
UploadJobTrait.php:45
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:33
MWException\msg
msg( $key, $fallback,... $params)
Get a message from i18n.
Definition
MWException.php:71
MediaWiki\Context\RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition
RequestContext.php:67
MediaWiki\SpecialPage\SpecialPage
Parent class for all special pages.
Definition
SpecialPage.php:66
UserNotLoggedIn
Redirect a user to the login page or account creation page.
Definition
UserNotLoggedIn.php:66
UserNotLoggedIn\__construct
__construct( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', $params=[], bool $alwaysRedirectToLoginPage=false)
Definition
UserNotLoggedIn.php:89
UserNotLoggedIn\report
report( $action=self::SEND_OUTPUT)
Redirect to Special:Userlogin or Special:CreateAccount if the specified message is compatible.
Definition
UserNotLoggedIn.php:114
includes
exception
UserNotLoggedIn.php
Generated on Sun Oct 6 2024 23:23:43 for MediaWiki by
1.10.0