MediaWiki master
LoginHelper.php
Go to the documentation of this file.
1<?php
2
6use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
10
17 use ProtectedHookAccessorTrait;
18
31 public static $validErrorMessages = [
32 'exception-nologin-text',
33 'watchlistanontext',
34 'changeemail-no-info',
35 'resetpass-no-info',
36 'confirmemail_needlogin',
37 'prefsnologintext2',
38 'specialmute-login-required',
39 ];
40
47 public static function getValidErrorMessages() {
48 static $messages = null;
49 if ( !$messages ) {
50 $messages = self::$validErrorMessages;
51 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
52 ->onLoginFormValidErrorMessages( $messages );
53 }
54
55 return $messages;
56 }
57
58 public function __construct( IContextSource $context ) {
59 $this->setContext( $context );
60 }
61
80 public function showReturnToPage(
81 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false, $returnToAnchor = ''
82 ) {
83 $config = $this->getConfig();
84 if ( $type !== 'error' && $config->get( MainConfigNames::RedirectOnLogin ) !== null ) {
85 $returnTo = $config->get( MainConfigNames::RedirectOnLogin );
86 $returnToQuery = [];
87 } elseif ( is_string( $returnToQuery ) ) {
88 $returnToQuery = wfCgiToArray( $returnToQuery );
89 }
90
91 // Allow modification of redirect behavior
92 $this->getHookRunner()->onPostLoginRedirect( $returnTo, $returnToQuery, $type );
93
94 $returnToTitle = Title::newFromText( $returnTo ) ?: Title::newMainPage();
95
96 if ( $config->get( MainConfigNames::ForceHTTPS )
97 || ( $config->get( MainConfigNames::SecureLogin ) && $stickHTTPS )
98 ) {
99 $options = [ 'https' ];
100 $proto = PROTO_HTTPS;
101 } elseif ( $config->get( MainConfigNames::SecureLogin ) && !$stickHTTPS ) {
102 $options = [ 'http' ];
103 $proto = PROTO_HTTP;
104 } else {
105 $options = [];
106 $proto = PROTO_RELATIVE;
107 }
108
109 if ( $type === 'successredirect' ) {
110 $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto )
111 . $returnToAnchor;
112 $this->getOutput()->redirect( $redirectUrl );
113 } else {
114 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
115 }
116 }
117}
const PROTO_HTTPS
Definition Defines.php:204
const PROTO_HTTP
Definition Defines.php:203
const PROTO_RELATIVE
Definition Defines.php:205
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
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.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:78
Interface for objects which can provide a MediaWiki context on request.