MediaWiki REL1_39
LoginHelper.php
Go to the documentation of this file.
1<?php
2
3use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
5
12 use ProtectedHookAccessorTrait;
13
26 public static $validErrorMessages = [
27 'exception-nologin-text',
28 'watchlistanontext',
29 'changeemail-no-info',
30 'resetpass-no-info',
31 'confirmemail_needlogin',
32 'prefsnologintext2',
33 'specialmute-login-required',
34 ];
35
42 public static function getValidErrorMessages() {
43 static $messages = null;
44 if ( !$messages ) {
45 $messages = self::$validErrorMessages;
46 Hooks::runner()->onLoginFormValidErrorMessages( $messages );
47 }
48
49 return $messages;
50 }
51
52 public function __construct( IContextSource $context ) {
53 $this->setContext( $context );
54 }
55
74 public function showReturnToPage(
75 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false, $returnToAnchor = ''
76 ) {
77 $config = $this->getConfig();
78 if ( $type !== 'error' && $config->get( MainConfigNames::RedirectOnLogin ) !== null ) {
79 $returnTo = $config->get( MainConfigNames::RedirectOnLogin );
80 $returnToQuery = [];
81 } elseif ( is_string( $returnToQuery ) ) {
82 $returnToQuery = wfCgiToArray( $returnToQuery );
83 }
84
85 // Allow modification of redirect behavior
86 $this->getHookRunner()->onPostLoginRedirect( $returnTo, $returnToQuery, $type );
87
88 $returnToTitle = Title::newFromText( $returnTo ) ?: Title::newMainPage();
89
90 if ( $config->get( MainConfigNames::ForceHTTPS )
91 || ( $config->get( MainConfigNames::SecureLogin ) && $stickHTTPS )
92 ) {
93 $options = [ 'https' ];
94 $proto = PROTO_HTTPS;
95 } elseif ( $config->get( MainConfigNames::SecureLogin ) && !$stickHTTPS ) {
96 $options = [ 'http' ];
97 $proto = PROTO_HTTP;
98 } else {
99 $options = [];
100 $proto = PROTO_RELATIVE;
101 }
102
103 if ( $type === 'successredirect' ) {
104 $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto )
105 . $returnToAnchor;
106 $this->getOutput()->redirect( $redirectUrl );
107 } else {
108 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
109 }
110 }
111}
const PROTO_HTTPS
Definition Defines.php:194
const PROTO_HTTP
Definition Defines.php:193
const PROTO_RELATIVE
Definition Defines.php:195
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 ...
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)
showReturnToPage( $type, $returnTo='', $returnToQuery='', $stickHTTPS=false, $returnToAnchor='')
Show a return link or redirect to it.
static string[] $validErrorMessages
Valid error and warning messages.
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.