MediaWiki  master
UserNotLoggedIn.php
Go to the documentation of this file.
1 <?php
55 
69  public function __construct(
70  $reasonMsg = 'exception-nologin-text',
71  $titleMsg = 'exception-nologin',
72  $params = []
73  ) {
74  parent::__construct( $titleMsg, $reasonMsg, $params );
75  }
76 
82  public function report( $action = self::SEND_OUTPUT ) {
83  // If an unsupported message is used, don't try redirecting to Special:Userlogin,
84  // since the message may not be compatible.
85  if ( !in_array( $this->msg, LoginHelper::getValidErrorMessages() ) ) {
86  parent::report( $action );
87  return;
88  }
89 
90  // Message is valid. Redirect to Special:Userlogin
91 
92  $context = RequestContext::getMain();
93 
94  $output = $context->getOutput();
95  $query = $context->getRequest()->getValues();
96  // Title will be overridden by returnto
97  unset( $query['title'] );
98  // Redirect to Special:Userlogin
99  $output->redirect( SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( [
100  // Return to this page when the user logs in
101  'returnto' => $context->getTitle()->getFullText(),
102  'returntoquery' => wfArrayToCgi( $query ),
103  'warning' => $this->msg,
104  ] ) );
105 
106  if ( $action === self::SEND_OUTPUT ) {
107  $output->output();
108  }
109  }
110 }
UserNotLoggedIn
Redirect a user to the login page.
Definition: UserNotLoggedIn.php:54
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:92
MWException\msg
msg( $key, $fallback,... $params)
Get a message from i18n.
Definition: MWException.php:81
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:451
ErrorPageError\$params
$params
Definition: ErrorPageError.php:33
UserNotLoggedIn\__construct
__construct( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', $params=[])
Stable to call.
Definition: UserNotLoggedIn.php:69
UserNotLoggedIn\report
report( $action=self::SEND_OUTPUT)
Redirect to Special:Userlogin if the specified message is compatible.
Definition: UserNotLoggedIn.php:82
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
LoginHelper\getValidErrorMessages
static getValidErrorMessages()
Returns an array of all valid error messages.
Definition: LoginHelper.php:41
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:346