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