MediaWiki  master
LoginHelper.php
Go to the documentation of this file.
1 <?php
2 
3 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
4 
10 class LoginHelper extends ContextSource {
11  use ProtectedHookAccessorTrait;
12 
25  public static $validErrorMessages = [
26  'exception-nologin-text',
27  'watchlistanontext',
28  'changeemail-no-info',
29  'resetpass-no-info',
30  'confirmemail_needlogin',
31  'prefsnologintext2',
32  'specialmute-login-required',
33  ];
34 
41  public static function getValidErrorMessages() {
42  static $messages = null;
43  if ( !$messages ) {
44  $messages = self::$validErrorMessages;
45  Hooks::runner()->onLoginFormValidErrorMessages( $messages );
46  }
47 
48  return $messages;
49  }
50 
51  public function __construct( IContextSource $context ) {
52  $this->setContext( $context );
53  }
54 
69  public function showReturnToPage(
70  $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
71  ) {
72  $config = $this->getConfig();
73  if ( $type !== 'error' && $config->get( 'RedirectOnLogin' ) !== null ) {
74  $returnTo = $config->get( 'RedirectOnLogin' );
75  $returnToQuery = [];
76  } elseif ( is_string( $returnToQuery ) ) {
77  $returnToQuery = wfCgiToArray( $returnToQuery );
78  }
79 
80  // Allow modification of redirect behavior
81  $this->getHookRunner()->onPostLoginRedirect( $returnTo, $returnToQuery, $type );
82 
83  $returnToTitle = Title::newFromText( $returnTo ) ?: Title::newMainPage();
84 
85  if ( $config->get( 'ForceHTTPS' )
86  || ( $config->get( 'SecureLogin' ) && $stickHTTPS )
87  ) {
88  $options = [ 'https' ];
89  $proto = PROTO_HTTPS;
90  } elseif ( $config->get( 'SecureLogin' ) && !$stickHTTPS ) {
91  $options = [ 'http' ];
92  $proto = PROTO_HTTP;
93  } else {
94  $options = [];
95  $proto = PROTO_RELATIVE;
96  }
97 
98  if ( $type === 'successredirect' ) {
99  $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto );
100  $this->getOutput()->redirect( $redirectUrl );
101  } else {
102  $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
103  }
104  }
105 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:67
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:329
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:654
LoginHelper
Helper functions for the login form that need to be shared with other special pages (such as CentralA...
Definition: LoginHelper.php:10
LoginHelper\$validErrorMessages
static string[] $validErrorMessages
Valid error and warning messages.
Definition: LoginHelper.php:25
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:121
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:391
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:58
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:209
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
LoginHelper\__construct
__construct(IContextSource $context)
Definition: LoginHelper.php:51
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:208
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:210
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
LoginHelper\showReturnToPage
showReturnToPage( $type, $returnTo='', $returnToQuery='', $stickHTTPS=false)
Show a return link or redirect to it.
Definition: LoginHelper.php:69
LoginHelper\getValidErrorMessages
static getValidErrorMessages()
Returns an array of all valid error messages.
Definition: LoginHelper.php:41
$type
$type
Definition: testCompression.php:52