4 * Helper functions for the login form that need to be shared with other special pages
5 * (such as CentralAuth's SpecialCentralLogin).
8 class LoginHelper
extends ContextSource
{
10 * Valid error and warning messages
12 * Special:Userlogin can show an error or warning message on the form when
13 * coming from another page. This is done via the ?error= or ?warning= GET
16 * This array is the list of valid message keys. Further keys can be added by the
17 * LoginFormValidErrorMessages hook. All other values will be ignored.
21 public static $validErrorMessages = [
22 'exception-nologin-text',
24 'changeemail-no-info',
26 'confirmemail_needlogin',
28 'specialmute-login-required',
32 * Returns an array of all valid error messages.
35 * @see LoginHelper::$validErrorMessages
37 public static function getValidErrorMessages() {
38 static $messages = null;
40 $messages = self
::$validErrorMessages;
41 Hooks
::run( 'LoginFormValidErrorMessages', [ &$messages ] );
47 public function __construct( IContextSource
$context ) {
48 $this->setContext( $context );
52 * Show a return link or redirect to it.
53 * Extensions can change where the link should point or inject content into the page
54 * (which will change it from redirect to link mode).
56 * @param string $type One of the following:
57 * - error: display a return to link ignoring $wgRedirectOnLogin
58 * - success: display a return to link using $wgRedirectOnLogin if needed
59 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
60 * @param string $returnTo
61 * @param array|string $returnToQuery
62 * @param bool $stickHTTPS Keep redirect link on HTTPS
64 public function showReturnToPage(
65 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
67 $config = $this->getConfig();
68 if ( $type !== 'error' && $config->get( 'RedirectOnLogin' ) !== null ) {
69 $returnTo = $config->get( 'RedirectOnLogin' );
71 } elseif ( is_string( $returnToQuery ) ) {
72 $returnToQuery = wfCgiToArray( $returnToQuery );
75 // Allow modification of redirect behavior
76 Hooks
::run( 'PostLoginRedirect', [ &$returnTo, &$returnToQuery, &$type ] );
78 $returnToTitle = Title
::newFromText( $returnTo ) ?
: Title
::newMainPage();
80 if ( $config->get( 'SecureLogin' ) && !$stickHTTPS ) {
81 $options = [ 'http' ];
83 } elseif ( $config->get( 'SecureLogin' ) ) {
84 $options = [ 'https' ];
88 $proto = PROTO_RELATIVE
;
91 if ( $type === 'successredirect' ) {
92 $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto );
93 $this->getOutput()->redirect( $redirectUrl );
95 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );