MediaWiki REL1_35
LoginHelper.php
Go to the documentation of this file.
1<?php
2
3use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
4
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}
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
IContextSource $context
setContext(IContextSource $context)
Helper functions for the login form that need to be shared with other special pages (such as CentralA...
static getValidErrorMessages()
Returns an array of all valid error messages.
__construct(IContextSource $context)
static string[] $validErrorMessages
Valid error and warning messages.
showReturnToPage( $type, $returnTo='', $returnToQuery='', $stickHTTPS=false)
Show a return link or redirect to it.
const PROTO_HTTPS
Definition Defines.php:210
const PROTO_HTTP
Definition Defines.php:209
const PROTO_RELATIVE
Definition Defines.php:211
Interface for objects which can provide a MediaWiki context on request.