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