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 
78  public function report( $action = self::SEND_OUTPUT ) {
79  // If an unsupported message is used, don't try redirecting to Special:Userlogin,
80  // since the message may not be compatible.
81  if ( !in_array( $this->msg, LoginHelper::getValidErrorMessages() ) ) {
82  parent::report( $action );
83  return;
84  }
85 
86  // Message is valid. Redirect to Special:Userlogin
87 
89 
90  $output = $context->getOutput();
91  $query = $context->getRequest()->getValues();
92  // Title will be overridden by returnto
93  unset( $query['title'] );
94  // Redirect to Special:Userlogin
95  $output->redirect( SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( [
96  // Return to this page when the user logs in
97  'returnto' => $context->getTitle()->getFullText(),
98  'returntoquery' => wfArrayToCgi( $query ),
99  'warning' => $this->msg,
100  ] ) );
101 
102  if ( $action === self::SEND_OUTPUT ) {
103  $output->output();
104  }
105  }
106 }
$context
Definition: load.php:45
Redirect a user to the login page.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
msg( $key, $fallback,... $params)
Get a message from i18n.
Definition: MWException.php:75
static getMain()
Get the RequestContext object associated with the main request.
An error page which can definitely be safely rendered using the OutputPage.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
__construct( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', $params=[])
static getValidErrorMessages()
Returns an array of all valid error messages.
Definition: LoginHelper.php:37
report( $action=self::SEND_OUTPUT)
Redirect to Special:Userlogin if the specified message is compatible.