MediaWiki REL1_34
LoginHelper.php
Go to the documentation of this file.
1<?php
2
21 public static $validErrorMessages = [
22 'exception-nologin-text',
23 'watchlistanontext',
24 'changeemail-no-info',
25 'resetpass-no-info',
26 'confirmemail_needlogin',
27 'prefsnologintext2',
28 'specialmute-login-required',
29 ];
30
37 public static function getValidErrorMessages() {
38 static $messages = null;
39 if ( !$messages ) {
40 $messages = self::$validErrorMessages;
41 Hooks::run( 'LoginFormValidErrorMessages', [ &$messages ] );
42 }
43
44 return $messages;
45 }
46
47 public function __construct( IContextSource $context ) {
48 $this->setContext( $context );
49 }
50
65 public function showReturnToPage(
66 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
67 ) {
68 $config = $this->getConfig();
69 if ( $type !== 'error' && $config->get( 'RedirectOnLogin' ) !== null ) {
70 $returnTo = $config->get( 'RedirectOnLogin' );
71 $returnToQuery = [];
72 } elseif ( is_string( $returnToQuery ) ) {
73 $returnToQuery = wfCgiToArray( $returnToQuery );
74 }
75
76 // Allow modification of redirect behavior
77 Hooks::run( 'PostLoginRedirect', [ &$returnTo, &$returnToQuery, &$type ] );
78
79 $returnToTitle = Title::newFromText( $returnTo ) ?: Title::newMainPage();
80
81 if ( $config->get( 'ForceHTTPS' )
82 || ( $config->get( 'SecureLogin' ) && $stickHTTPS )
83 ) {
84 $options = [ 'https' ];
85 $proto = PROTO_HTTPS;
86 } elseif ( $config->get( 'SecureLogin' ) && !$stickHTTPS ) {
87 $options = [ 'http' ];
88 $proto = PROTO_HTTP;
89 } else {
90 $options = [];
91 $proto = PROTO_RELATIVE;
92 }
93
94 if ( $type === 'successredirect' ) {
95 $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto );
96 $this->getOutput()->redirect( $redirectUrl );
97 } else {
98 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
99 }
100 }
101}
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:209
const PROTO_HTTP
Definition Defines.php:208
const PROTO_RELATIVE
Definition Defines.php:210
Interface for objects which can provide a MediaWiki context on request.