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