3 * Holds shared logic for login and account creation pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 use MediaWiki\Auth\AuthenticationRequest
;
25 use MediaWiki\Auth\AuthenticationResponse
;
26 use MediaWiki\Auth\AuthManager
;
27 use MediaWiki\Auth\Throttler
;
28 use MediaWiki\Logger\LoggerFactory
;
29 use MediaWiki\Session\SessionManager
;
33 * Holds shared logic for login and account creation pages.
35 * @ingroup SpecialPage
37 abstract class LoginSignupSpecialPage
extends AuthManagerSpecialPage
{
42 protected $mReturnToQuery;
44 protected $mStickHTTPS;
46 protected $mEntryError = '';
47 protected $mEntryErrorType = 'error';
49 protected $mLoaded = false;
50 protected $mLoadedRequest = false;
51 protected $mSecureLoginUrl;
54 protected $securityLevel;
56 /** @var bool True if the user if creating an account for someone else. Flag used for internal
57 * communication, only set at the very end. */
58 protected $proxyAccountCreation;
59 /** @var User FIXME another flag for passing data. */
60 protected $targetUser;
65 /** @var FakeAuthTemplate */
66 protected $fakeTemplate;
68 abstract protected function isSignup();
71 * @param bool $direct True if the action was successful just now; false if that happened
72 * pre-redirection (so this handler was called already)
73 * @param StatusValue|null $extraMessages
76 abstract protected function successfulAction( $direct = false, $extraMessages = null );
79 * Logs to the authmanager-stats channel.
80 * @param bool $success
81 * @param string|null $status Error message key
83 abstract protected function logAuthResult( $success, $status = null );
85 public function __construct( $name ) {
86 global $wgUseMediaWikiUIEverywhere;
87 parent
::__construct( $name );
89 // Override UseMediaWikiEverywhere to true, to force login and create form to use mw ui
90 $wgUseMediaWikiUIEverywhere = true;
93 protected function setRequest( array $data, $wasPosted = null ) {
94 parent
::setRequest( $data, $wasPosted );
95 $this->mLoadedRequest
= false;
99 * Load basic request parameters for this Special page.
102 private function loadRequestParameters( $subPage ) {
103 if ( $this->mLoadedRequest
) {
106 $this->mLoadedRequest
= true;
107 $request = $this->getRequest();
109 $this->mPosted
= $request->wasPosted();
110 $this->mIsReturn
= $subPage === 'return';
111 $this->mAction
= $request->getVal( 'action' );
112 $this->mFromHTTP
= $request->getBool( 'fromhttp', false )
113 ||
$request->getBool( 'wpFromhttp', false );
114 $this->mStickHTTPS
= ( !$this->mFromHTTP
&& $request->getProtocol() === 'https' )
115 ||
$request->getBool( 'wpForceHttps', false );
116 $this->mLanguage
= $request->getText( 'uselang' );
117 $this->mReturnTo
= $request->getVal( 'returnto', '' );
118 $this->mReturnToQuery
= $request->getVal( 'returntoquery', '' );
122 * Load data from request.
124 * @param string $subPage Subpage of Special:Userlogin
126 protected function load( $subPage ) {
127 global $wgSecureLogin;
129 $this->loadRequestParameters( $subPage );
130 if ( $this->mLoaded
) {
133 $this->mLoaded
= true;
134 $request = $this->getRequest();
136 $securityLevel = $this->getRequest()->getText( 'force' );
138 $securityLevel && AuthManager
::singleton()->securitySensitiveOperationStatus(
139 $securityLevel ) === AuthManager
::SEC_REAUTH
141 $this->securityLevel
= $securityLevel;
144 $this->loadAuth( $subPage );
146 $this->mToken
= $request->getVal( $this->getTokenName() );
148 // Show an error or warning passed on from a previous page
149 $entryError = $this->msg( $request->getVal( 'error', '' ) );
150 $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
151 // bc: provide login link as a parameter for messages where the translation
153 $loginreqlink = Linker
::linkKnown(
154 $this->getPageTitle(),
155 $this->msg( 'loginreqlink' )->escaped(),
158 'returnto' => $this->mReturnTo
,
159 'returntoquery' => $this->mReturnToQuery
,
160 'uselang' => $this->mLanguage
,
161 'fromhttp' => $wgSecureLogin && $this->mFromHTTP ?
'1' : null,
165 // Only show valid error or warning messages.
166 if ( $entryError->exists()
167 && in_array( $entryError->getKey(), LoginHelper
::getValidErrorMessages(), true )
169 $this->mEntryErrorType
= 'error';
170 $this->mEntryError
= $entryError->rawParams( $loginreqlink )->parse();
172 } elseif ( $entryWarning->exists()
173 && in_array( $entryWarning->getKey(), LoginHelper
::getValidErrorMessages(), true )
175 $this->mEntryErrorType
= 'warning';
176 $this->mEntryError
= $entryWarning->rawParams( $loginreqlink )->parse();
179 # 1. When switching accounts, it sucks to get automatically logged out
180 # 2. Do not return to PasswordReset after a successful password change
181 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
182 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
183 if ( is_object( $returnToTitle )
184 && ( $returnToTitle->isSpecial( 'Userlogout' )
185 ||
$returnToTitle->isSpecial( 'PasswordReset' ) )
187 $this->mReturnTo
= '';
188 $this->mReturnToQuery
= '';
192 protected function getPreservedParams( $withToken = false ) {
193 global $wgSecureLogin;
195 $params = parent
::getPreservedParams( $withToken );
197 'returnto' => $this->mReturnTo ?
: null,
198 'returntoquery' => $this->mReturnToQuery ?
: null,
200 if ( $wgSecureLogin && !$this->isSignup() ) {
201 $params['fromhttp'] = $this->mFromHTTP ?
'1' : null;
206 protected function beforeExecute( $subPage ) {
207 // finish initializing the class before processing the request - T135924
208 $this->loadRequestParameters( $subPage );
209 return parent
::beforeExecute( $subPage );
213 * @param string|null $subPage
215 public function execute( $subPage ) {
216 $authManager = AuthManager
::singleton();
217 $session = SessionManager
::getGlobalSession();
219 // Session data is used for various things in the authentication process, so we must make
220 // sure a session cookie or some equivalent mechanism is set.
223 $this->load( $subPage );
225 $this->checkPermissions();
227 // Make sure it's possible to log in
228 if ( !$this->isSignup() && !$session->canSetUser() ) {
229 throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
230 $session->getProvider()->describe( RequestContext
::getMain()->getLanguage() )
235 * In the case where the user is already logged in, and was redirected to
236 * the login form from a page that requires login, do not show the login
237 * page. The use case scenario for this is when a user opens a large number
238 * of tabs, is redirected to the login page on all of them, and then logs
239 * in on one, expecting all the others to work properly.
241 * However, do show the form if it was visited intentionally (no 'returnto'
242 * is present). People who often switch between several accounts have grown
243 * accustomed to this behavior.
245 * Also make an exception when force=<level> is set in the URL, which means the user must
246 * reauthenticate for security reasons.
248 if ( !$this->isSignup() && !$this->mPosted
&& !$this->securityLevel
&&
249 ( $this->mReturnTo
!== '' ||
$this->mReturnToQuery
!== '' ) &&
250 $this->getUser()->isLoggedIn()
252 $this->successfulAction();
255 // If logging in and not on HTTPS, either redirect to it or offer a link.
256 global $wgSecureLogin;
257 if ( $this->getRequest()->getProtocol() !== 'https' ) {
258 $title = $this->getFullTitle();
259 $query = $this->getPreservedParams( false ) +
[
261 ( $this->mEntryErrorType
=== 'error' ?
'error'
262 : 'warning' ) => $this->mEntryError
,
263 ] +
$this->getRequest()->getQueryValues();
264 $url = $title->getFullURL( $query, false, PROTO_HTTPS
);
265 if ( $wgSecureLogin && !$this->mFromHTTP
&&
266 wfCanIPUseHTTPS( $this->getRequest()->getIP() )
268 // Avoid infinite redirect
269 $url = wfAppendQuery( $url, 'fromhttp=1' );
270 $this->getOutput()->redirect( $url );
271 // Since we only do this redir to change proto, always vary
272 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
276 // A wiki without HTTPS login support should set $wgServer to
277 // http://somehost, in which case the secure URL generated
278 // above won't actually start with https://
279 if ( substr( $url, 0, 8 ) === 'https://' ) {
280 $this->mSecureLoginUrl
= $url;
285 if ( !$this->isActionAllowed( $this->authAction
) ) {
286 // FIXME how do we explain this to the user? can we handle session loss better?
287 // messages used: authpage-cannot-login, authpage-cannot-login-continue,
288 // authpage-cannot-create, authpage-cannot-create-continue
289 $this->mainLoginForm( [], 'authpage-cannot-' . $this->authAction
);
293 $status = $this->trySubmit();
295 if ( !$status ||
!$status->isGood() ) {
296 $this->mainLoginForm( $this->authRequests
, $status ?
$status->getMessage() : '', 'error' );
300 /** @var AuthenticationResponse $response */
301 $response = $status->getValue();
303 $returnToUrl = $this->getPageTitle( 'return' )
304 ->getFullURL( $this->getPreservedParams( true ), false, PROTO_HTTPS
);
305 switch ( $response->status
) {
306 case AuthenticationResponse
::PASS
:
307 $this->logAuthResult( true );
308 $this->proxyAccountCreation
= $this->isSignup() && !$this->getUser()->isAnon();
309 $this->targetUser
= User
::newFromName( $response->username
);
312 !$this->proxyAccountCreation
313 && $response->loginRequest
314 && $authManager->canAuthenticateNow()
316 // successful registration; log the user in instantly
317 $response2 = $authManager->beginAuthentication( [ $response->loginRequest
],
319 if ( $response2->status
!== AuthenticationResponse
::PASS
) {
320 LoggerFactory
::getInstance( 'login' )
321 ->error( 'Could not log in after account creation' );
322 $this->successfulAction( true, Status
::newFatal( 'createacct-loginerror' ) );
327 if ( !$this->proxyAccountCreation
) {
328 // Ensure that the context user is the same as the session user.
329 $this->setSessionUserForCurrentRequest();
332 $this->successfulAction( true );
334 case AuthenticationResponse
::FAIL
:
336 case AuthenticationResponse
::RESTART
:
337 unset( $this->authForm
);
338 if ( $response->status
=== AuthenticationResponse
::FAIL
) {
339 $action = $this->getDefaultAction( $subPage );
340 $messageType = 'error';
342 $action = $this->getContinueAction( $this->authAction
);
343 $messageType = 'warning';
345 $this->logAuthResult( false, $response->message ?
$response->message
->getKey() : '-' );
346 $this->loadAuth( $subPage, $action, true );
347 $this->mainLoginForm( $this->authRequests
, $response->message
, $messageType );
349 case AuthenticationResponse
::REDIRECT
:
350 unset( $this->authForm
);
351 $this->getOutput()->redirect( $response->redirectTarget
);
353 case AuthenticationResponse
::UI
:
354 unset( $this->authForm
);
355 $this->authAction
= $this->isSignup() ? AuthManager
::ACTION_CREATE_CONTINUE
356 : AuthManager
::ACTION_LOGIN_CONTINUE
;
357 $this->authRequests
= $response->neededRequests
;
358 $this->mainLoginForm( $response->neededRequests
, $response->message
, 'warning' );
361 throw new LogicException( 'invalid AuthenticationResponse' );
366 * Show the success page.
368 * @param string $type Condition of return to; see `executeReturnTo`
369 * @param string|Message $title Page's title
370 * @param string $msgname
371 * @param string $injected_html
372 * @param StatusValue|null $extraMessages
374 protected function showSuccessPage(
375 $type, $title, $msgname, $injected_html, $extraMessages
377 $out = $this->getOutput();
378 $out->setPageTitle( $title );
380 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
382 if ( $extraMessages ) {
383 $extraMessages = Status
::wrap( $extraMessages );
384 $out->addWikiText( $extraMessages->getWikiText() );
387 $out->addHTML( $injected_html );
389 $helper = new LoginHelper( $this->getContext() );
390 $helper->showReturnToPage( $type, $this->mReturnTo
, $this->mReturnToQuery
, $this->mStickHTTPS
);
394 * Add a "return to" link or redirect to it.
395 * Extensions can use this to reuse the "return to" logic after
396 * inject steps (such as redirection) into the login process.
398 * @param string $type One of the following:
399 * - error: display a return to link ignoring $wgRedirectOnLogin
400 * - signup: display a return to link using $wgRedirectOnLogin if needed
401 * - success: display a return to link using $wgRedirectOnLogin if needed
402 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
403 * @param string $returnTo
404 * @param array|string $returnToQuery
405 * @param bool $stickHTTPS Keep redirect link on HTTPS
408 public function showReturnToPage(
409 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
411 $helper = new LoginHelper( $this->getContext() );
412 $helper->showReturnToPage( $type, $returnTo, $returnToQuery, $stickHTTPS );
416 * Replace some globals to make sure the fact that the user has just been logged in is
417 * reflected in the current request.
420 protected function setSessionUserForCurrentRequest() {
421 global $wgUser, $wgLang;
423 $context = RequestContext
::getMain();
424 $localContext = $this->getContext();
425 if ( $context !== $localContext ) {
426 // remove AuthManagerSpecialPage context hack
427 $this->setContext( $context );
430 $user = $context->getRequest()->getSession()->getUser();
433 $context->setUser( $user );
435 $code = $this->getRequest()->getVal( 'uselang', $user->getOption( 'language' ) );
436 $userLang = Language
::factory( $code );
438 $context->setLanguage( $userLang );
442 * @param AuthenticationRequest[] $requests A list of AuthorizationRequest objects,
443 * used to generate the form fields. An empty array means a fatal error
444 * (authentication cannot continue).
445 * @param string|Message $msg
446 * @param string $msgtype
447 * @throws ErrorPageError
450 * @throws MWException
451 * @throws PermissionsError
452 * @throws ReadOnlyError
455 protected function mainLoginForm( array $requests, $msg = '', $msgtype = 'error' ) {
456 $titleObj = $this->getPageTitle();
457 $user = $this->getUser();
458 $out = $this->getOutput();
460 // FIXME how to handle empty $requests - restart, or no form, just an error message?
461 // no form would be better for no session type errors, restart is better when can* fails.
463 $this->authAction
= $this->getDefaultAction( $this->subPage
);
464 $this->authForm
= null;
465 $requests = AuthManager
::singleton()->getAuthenticationRequests( $this->authAction
, $user );
468 // Generic styles and scripts for both login and signup form
469 $out->addModuleStyles( [
471 'mediawiki.ui.button',
472 'mediawiki.ui.checkbox',
473 'mediawiki.ui.input',
474 'mediawiki.special.userlogin.common.styles'
476 if ( $this->isSignup() ) {
477 // XXX hack pending RL or JS parse() support for complex content messages T27349
478 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
479 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
481 // Additional styles and scripts for signup form
483 'mediawiki.special.userlogin.signup.js'
485 $out->addModuleStyles( [
486 'mediawiki.special.userlogin.signup.styles'
489 // Additional styles for login form
490 $out->addModuleStyles( [
491 'mediawiki.special.userlogin.login.styles'
494 $out->disallowUserJs(); // just in case...
496 $form = $this->getAuthForm( $requests, $this->authAction
, $msg, $msgtype );
497 $form->prepareForm();
498 $formHtml = $form->getHTML( $msg ? Status
::newFatal( $msg ) : false );
500 $out->addHTML( $this->getPageHtml( $formHtml ) );
504 * Add page elements which are outside the form.
505 * FIXME this should probably be a template, but use a sane language (handlebars?)
506 * @param string $formHtml
509 protected function getPageHtml( $formHtml ) {
510 global $wgLoginLanguageSelector;
512 $loginPrompt = $this->isSignup() ?
'' : Html
::rawElement( 'div',
513 [ 'id' => 'userloginprompt' ], $this->msg( 'loginprompt' )->parseAsBlock() );
514 $languageLinks = $wgLoginLanguageSelector ?
$this->makeLanguageSelector() : '';
515 $signupStartMsg = $this->msg( 'signupstart' );
516 $signupStart = ( $this->isSignup() && !$signupStartMsg->isDisabled() )
517 ? Html
::rawElement( 'div', [ 'id' => 'signupstart' ], $signupStartMsg->parseAsBlock() ) : '';
518 if ( $languageLinks ) {
519 $languageLinks = Html
::rawElement( 'div', [ 'id' => 'languagelinks' ],
520 Html
::rawElement( 'p', [], $languageLinks )
524 $benefitsContainer = '';
525 if ( $this->isSignup() && $this->showExtraInformation() ) {
527 // createacct-benefit-icon1 createacct-benefit-head1 createacct-benefit-body1
528 // createacct-benefit-icon2 createacct-benefit-head2 createacct-benefit-body2
529 // createacct-benefit-icon3 createacct-benefit-head3 createacct-benefit-body3
532 for ( $benefitIdx = 1; $benefitIdx <= $benefitCount; $benefitIdx++
) {
533 $headUnescaped = $this->msg( "createacct-benefit-head$benefitIdx" )->text();
534 $iconClass = $this->msg( "createacct-benefit-icon$benefitIdx" )->escaped();
535 $benefitList .= Html
::rawElement( 'div', [ 'class' => "mw-number-text $iconClass" ],
536 Html
::rawElement( 'h3', [],
537 $this->msg( "createacct-benefit-head$benefitIdx" )->escaped()
539 . Html
::rawElement( 'p', [],
540 $this->msg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped()
544 $benefitsContainer = Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-container' ],
545 Html
::rawElement( 'h2', [], $this->msg( 'createacct-benefit-heading' )->escaped() )
546 . Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-list' ],
552 $html = Html
::rawElement( 'div', [ 'class' => 'mw-ui-container' ],
556 . Html
::rawElement( 'div', [ 'id' => 'userloginForm' ],
566 * Generates a form from the given request.
567 * @param AuthenticationRequest[] $requests
568 * @param string $action AuthManager action name
569 * @param string|Message $msg
570 * @param string $msgType
573 protected function getAuthForm( array $requests, $action, $msg = '', $msgType = 'error' ) {
574 global $wgSecureLogin, $wgLoginLanguageSelector;
575 // FIXME merge this with parent
577 if ( isset( $this->authForm
) ) {
578 return $this->authForm
;
581 $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
583 // get basic form description from the auth logic
584 $fieldInfo = AuthenticationRequest
::mergeFieldInfo( $requests );
585 $fakeTemplate = $this->getFakeTemplate( $msg, $msgType );
586 $this->fakeTemplate
= $fakeTemplate; // FIXME there should be a saner way to pass this to the hook
587 // this will call onAuthChangeFormFields()
588 $formDescriptor = static::fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction
);
589 $this->postProcessFormDescriptor( $formDescriptor );
591 $context = $this->getContext();
592 if ( $context->getRequest() !== $this->getRequest() ) {
593 // We have overridden the request, need to make sure the form uses that too.
594 $context = new DerivativeContext( $this->getContext() );
595 $context->setRequest( $this->getRequest() );
597 $form = HTMLForm
::factory( 'vform', $formDescriptor, $context );
599 $form->addHiddenField( 'authAction', $this->authAction
);
600 if ( $wgLoginLanguageSelector ) {
601 $form->addHiddenField( 'uselang', $this->mLanguage
);
603 $form->addHiddenField( 'force', $this->securityLevel
);
604 $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() );
605 if ( $wgSecureLogin ) {
606 // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
607 if ( !$this->isSignup() ) {
608 $form->addHiddenField( 'wpForceHttps', (int)$this->mStickHTTPS
);
609 $form->addHiddenField( 'wpFromhttp', $usingHTTPS );
613 // set properties of the form itself
614 $form->setAction( $this->getPageTitle()->getLocalURL( $this->getReturnToQueryStringFragment() ) );
615 $form->setName( 'userlogin' . ( $this->isSignup() ?
'2' : '' ) );
616 if ( $this->isSignup() ) {
617 $form->setId( 'userlogin2' );
621 // header used by ConfirmEdit, CondfirmAccount, Persona, WikimediaIncubator, SemanticSignup
622 // should be above the error message but HTMLForm doesn't support that
623 $form->addHeaderText( $fakeTemplate->get( 'header' ) );
625 // FIXME the old form used this for error/warning messages which does not play well with
626 // HTMLForm (maybe it could with a subclass?); for now only display it for signups
627 // (where the JS username validation needs it) and alway empty
628 if ( $this->isSignup() ) {
629 // used by the mediawiki.special.userlogin.signup.js module
630 $statusAreaAttribs = [ 'id' => 'mw-createacct-status-area' ];
631 // $statusAreaAttribs += $msg ? [ 'class' => "{$msgType}box" ] : [ 'style' => 'display: none;' ];
632 $form->addHeaderText( Html
::element( 'div', $statusAreaAttribs ) );
635 // header used by MobileFrontend
636 $form->addHeaderText( $fakeTemplate->get( 'formheader' ) );
638 // blank signup footer for site customization
639 if ( $this->isSignup() && $this->showExtraInformation() ) {
640 // Use signupend-https for HTTPS requests if it's not blank, signupend otherwise
641 $signupendMsg = $this->msg( 'signupend' );
642 $signupendHttpsMsg = $this->msg( 'signupend-https' );
643 if ( !$signupendMsg->isDisabled() ) {
644 $signupendText = ( $usingHTTPS && !$signupendHttpsMsg->isBlank() )
645 ?
$signupendHttpsMsg ->parse() : $signupendMsg->parse();
646 $form->addPostText( Html
::rawElement( 'div', [ 'id' => 'signupend' ], $signupendText ) );
650 // warning header for non-standard workflows (e.g. security reauthentication)
651 if ( !$this->isSignup() && $this->getUser()->isLoggedIn() ) {
652 $reauthMessage = $this->securityLevel ?
'userlogin-reauth' : 'userlogin-loggedin';
653 $form->addHeaderText( Html
::rawElement( 'div', [ 'class' => 'warningbox' ],
654 $this->msg( $reauthMessage )->params( $this->getUser()->getName() )->parse() ) );
657 if ( !$this->isSignup() && $this->showExtraInformation() ) {
658 $passwordReset = new PasswordReset( $this->getConfig(), AuthManager
::singleton() );
659 if ( $passwordReset->isAllowed( $this->getUser() ) ) {
660 $form->addFooterText( Html
::rawElement(
662 [ 'class' => 'mw-ui-vform-field mw-form-related-link-container' ],
664 SpecialPage
::getTitleFor( 'PasswordReset' ),
665 $this->msg( 'userlogin-resetpassword-link' )->escaped()
670 // Don't show a "create account" link if the user can't.
671 if ( $this->showCreateAccountLink() ) {
672 // link to the other action
673 $linkTitle = $this->getTitleFor( $this->isSignup() ?
'Userlogin' :'CreateAccount' );
674 $linkq = $this->getReturnToQueryStringFragment();
675 // Pass any language selection on to the mode switch link
676 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
677 $linkq .= '&uselang=' . $this->mLanguage
;
680 $loggedIn = $this->getUser()->isLoggedIn();
681 $createOrLoginHtml = Html
::rawElement( 'div',
682 [ 'id' => 'mw-createaccount' . ( !$loggedIn ?
'-cta' : '' ),
683 'class' => ( $loggedIn ?
'mw-form-related-link-container' : 'mw-ui-vform-field' ) ],
684 ( $loggedIn ?
'' : $this->msg( 'userlogin-noaccount' )->escaped() )
685 . Html
::element( 'a',
687 'id' => 'mw-createaccount-join' . ( $loggedIn ?
'-loggedin' : '' ),
688 'href' => $linkTitle->getLocalURL( $linkq ),
689 'class' => ( $loggedIn ?
'' : 'mw-ui-button' ),
693 ( $this->getUser()->isLoggedIn() ?
694 'userlogin-createanother' :
695 'userlogin-joinproject'
699 $form->addFooterText( $createOrLoginHtml );
703 $form->suppressDefaultSubmit();
705 $this->authForm
= $form;
711 * Temporary B/C method to handle extensions using the UserLoginForm/UserCreateForm hooks.
712 * @param string|Message $msg
713 * @param string $msgType
714 * @return FakeAuthTemplate
716 protected function getFakeTemplate( $msg, $msgType ) {
717 global $wgAuth, $wgEnableEmail, $wgHiddenPrefs, $wgEmailConfirmToEdit, $wgEnableUserEmail,
718 $wgSecureLogin, $wgLoginLanguageSelector, $wgPasswordResetRoutes;
720 // make a best effort to get the value of fields which used to be fixed in the old login
721 // template but now might or might not exist depending on what providers are used
722 $request = $this->getRequest();
724 'mUsername' => $request->getText( 'wpName' ),
725 'mPassword' => $request->getText( 'wpPassword' ),
726 'mRetype' => $request->getText( 'wpRetype' ),
727 'mEmail' => $request->getText( 'wpEmail' ),
728 'mRealName' => $request->getText( 'wpRealName' ),
729 'mDomain' => $request->getText( 'wpDomain' ),
730 'mReason' => $request->getText( 'wpReason' ),
731 'mRemember' => $request->getCheck( 'wpRemember' ),
734 // Preserves a bunch of logic from the old code that was rewritten in getAuthForm().
735 // There is no code reuse to make this easier to remove .
736 // If an extension tries to change any of these values, they are out of luck - we only
737 // actually use the domain/usedomain/domainnames, extraInput and extrafields keys.
739 $titleObj = $this->getPageTitle();
740 $user = $this->getUser();
741 $template = new FakeAuthTemplate();
743 // Pre-fill username (if not creating an account, bug 44775).
744 if ( $data->mUsername
== '' && $this->isSignup() ) {
745 if ( $user->isLoggedIn() ) {
746 $data->mUsername
= $user->getName();
748 $data->mUsername
= $this->getRequest()->getSession()->suggestLoginUsername();
752 if ( $this->isSignup() ) {
753 // Must match number of benefits defined in messages
754 $template->set( 'benefitCount', 3 );
756 $q = 'action=submitlogin&type=signup';
757 $linkq = 'type=login';
759 $q = 'action=submitlogin&type=login';
760 $linkq = 'type=signup';
763 if ( $this->mReturnTo
!== '' ) {
764 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
765 if ( $this->mReturnToQuery
!== '' ) {
766 $returnto .= '&returntoquery=' .
767 wfUrlencode( $this->mReturnToQuery
);
773 # Don't show a "create account" link if the user can't.
774 if ( $this->showCreateAccountLink() ) {
775 # Pass any language selection on to the mode switch link
776 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
777 $linkq .= '&uselang=' . $this->mLanguage
;
779 // Supply URL, login template creates the button.
780 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
782 $template->set( 'link', '' );
785 $resetLink = $this->isSignup()
787 : is_array( $wgPasswordResetRoutes )
788 && in_array( true, array_values( $wgPasswordResetRoutes ), true );
790 $template->set( 'header', '' );
791 $template->set( 'formheader', '' );
792 $template->set( 'skin', $this->getSkin() );
794 $template->set( 'name', $data->mUsername
);
795 $template->set( 'password', $data->mPassword
);
796 $template->set( 'retype', $data->mRetype
);
797 $template->set( 'createemailset', false ); // no easy way to get that from AuthManager
798 $template->set( 'email', $data->mEmail
);
799 $template->set( 'realname', $data->mRealName
);
800 $template->set( 'domain', $data->mDomain
);
801 $template->set( 'reason', $data->mReason
);
802 $template->set( 'remember', $data->mRemember
);
804 $template->set( 'action', $titleObj->getLocalURL( $q ) );
805 $template->set( 'message', $msg );
806 $template->set( 'messagetype', $msgType );
807 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
808 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs, true ) );
809 $template->set( 'useemail', $wgEnableEmail );
810 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
811 $template->set( 'emailothers', $wgEnableUserEmail );
812 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
813 $template->set( 'resetlink', $resetLink );
814 $template->set( 'canremember', $request->getSession()->getProvider()
815 ->getRememberUserDuration() !== null );
816 $template->set( 'usereason', $user->isLoggedIn() );
817 $template->set( 'cansecurelogin', ( $wgSecureLogin ) );
818 $template->set( 'stickhttps', (int)$this->mStickHTTPS
);
819 $template->set( 'loggedin', $user->isLoggedIn() );
820 $template->set( 'loggedinuser', $user->getName() );
821 $template->set( 'token', $this->getToken()->toString() );
823 $action = $this->isSignup() ?
'signup' : 'login';
824 $wgAuth->modifyUITemplate( $template, $action );
826 $oldTemplate = $template;
827 $hookName = $this->isSignup() ?
'UserCreateForm' : 'UserLoginForm';
828 Hooks
::run( $hookName, [ &$template ] );
829 if ( $oldTemplate !== $template ) {
830 wfDeprecated( "reference in $hookName hook", '1.27' );
837 public function onAuthChangeFormFields(
838 array $requests, array $fieldInfo, array &$formDescriptor, $action
840 $coreFieldDescriptors = $this->getFieldDefinitions( $this->fakeTemplate
);
841 $specialFields = array_merge( [ 'extraInput', 'linkcontainer', 'entryError' ],
842 array_keys( $this->fakeTemplate
->getExtraInputDefinitions() ) );
844 // keep the ordering from getCoreFieldDescriptors() where there is no explicit weight
845 foreach ( $coreFieldDescriptors as $fieldName => $coreField ) {
846 $requestField = isset( $formDescriptor[$fieldName] ) ?
847 $formDescriptor[$fieldName] : [];
849 // remove everything that is not in the fieldinfo, is not marked as a supplemental field
850 // to something in the fieldinfo, and is not a generic or B/C field or a submit button
852 !isset( $fieldInfo[$fieldName] )
854 !isset( $coreField['baseField'] )
855 ||
!isset( $fieldInfo[$coreField['baseField']] )
856 ) && !in_array( $fieldName, $specialFields, true )
857 && ( !isset( $coreField['type'] ) ||
$coreField['type'] !== 'submit' )
859 $coreFieldDescriptors[$fieldName] = null;
863 // core message labels should always take priority
865 isset( $coreField['label'] )
866 ||
isset( $coreField['label-message'] )
867 ||
isset( $coreField['label-raw'] )
869 unset( $requestField['label'], $requestField['label-message'], $coreField['label-raw'] );
872 $coreFieldDescriptors[$fieldName] +
= $requestField;
875 $formDescriptor = array_filter( $coreFieldDescriptors +
$formDescriptor );
880 * Show extra information such as password recovery information, link from login to signup,
881 * CTA etc? Such information should only be shown on the "landing page", ie. when the user
882 * is at the first step of the authentication process.
885 protected function showExtraInformation() {
886 return $this->authAction
!== $this->getContinueAction( $this->authAction
)
887 && !$this->securityLevel
;
891 * Create a HTMLForm descriptor for the core login fields.
892 * @param FakeAuthTemplate $template B/C data (not used but needed by getBCFieldDefinitions)
895 protected function getFieldDefinitions( $template ) {
896 global $wgEmailConfirmToEdit;
898 $isLoggedIn = $this->getUser()->isLoggedIn();
899 $continuePart = $this->isContinued() ?
'continue-' : '';
900 $anotherPart = $isLoggedIn ?
'another-' : '';
901 $expiration = $this->getRequest()->getSession()->getProvider()
902 ->getRememberUserDuration();
903 $expirationDays = ceil( $expiration / ( 3600 * 24 ) );
904 $secureLoginLink = '';
905 if ( $this->mSecureLoginUrl
) {
906 $secureLoginLink = Html
::element( 'a', [
907 'href' => $this->mSecureLoginUrl
,
908 'class' => 'mw-ui-flush-right mw-secure',
909 ], $this->msg( 'userlogin-signwithsecure' )->text() );
912 if ( $this->isSignup() ) {
913 $fieldDefinitions = [
915 'label-message' => 'userlogin-yourname',
916 // FIXME help-message does not match old formatting
917 'help-message' => 'createacct-helpusername',
919 'placeholder-message' => $isLoggedIn ?
'createacct-another-username-ph'
920 : 'userlogin-yourname-ph',
923 // create account without providing password, a temporary one will be mailed
925 'label-message' => 'createaccountmail',
926 'name' => 'wpCreateaccountMail',
927 'id' => 'wpCreateaccountMail',
930 'id' => 'wpPassword2',
931 'placeholder-message' => 'createacct-yourpassword-ph',
932 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
936 'baseField' => 'password',
937 'type' => 'password',
938 'label-message' => 'createacct-yourpasswordagain',
940 'cssclass' => 'loginPassword',
942 'validation-callback' => function ( $value, $alldata ) {
943 if ( empty( $alldata['mailpassword'] ) && !empty( $alldata['password'] ) ) {
945 return $this->msg( 'htmlform-required' );
946 } elseif ( $value !== $alldata['password'] ) {
947 return $this->msg( 'badretype' );
952 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
953 'placeholder-message' => 'createacct-yourpasswordagain-ph',
957 'label-message' => $wgEmailConfirmToEdit ?
'createacct-emailrequired'
958 : 'createacct-emailoptional',
960 'cssclass' => 'loginText',
962 // FIXME will break non-standard providers
963 'required' => $wgEmailConfirmToEdit,
964 'validation-callback' => function ( $value, $alldata ) {
965 global $wgEmailConfirmToEdit;
967 // AuthManager will check most of these, but that will make the auth
968 // session fail and this won't, so nicer to do it this way
969 if ( !$value && $wgEmailConfirmToEdit ) {
970 // no point in allowing registration without email when email is
972 return $this->msg( 'noemailtitle' );
973 } elseif ( !$value && !empty( $alldata['mailpassword'] ) ) {
974 // cannot send password via email when there is no email address
975 return $this->msg( 'noemailcreate' );
976 } elseif ( $value && !Sanitizer
::validateEmail( $value ) ) {
977 return $this->msg( 'invalidemailaddress' );
981 'placeholder-message' => 'createacct-' . $anotherPart . 'email-ph',
985 'help-message' => $isLoggedIn ?
'createacct-another-realname-tip'
986 : 'prefs-help-realname',
987 'label-message' => 'createacct-realname',
988 'cssclass' => 'loginText',
990 'id' => 'wpRealName',
993 // comment for the user creation log
995 'label-message' => 'createacct-reason',
996 'cssclass' => 'loginText',
999 'placeholder-message' => 'createacct-reason-ph',
1001 'extrainput' => [], // placeholder for fields coming from the template
1002 'createaccount' => [
1005 'default' => $this->msg( 'createacct-' . $anotherPart . $continuePart .
1007 'name' => 'wpCreateaccount',
1008 'id' => 'wpCreateaccount',
1013 $fieldDefinitions = [
1015 'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $secureLoginLink,
1017 'placeholder-message' => 'userlogin-yourname-ph',
1020 'id' => 'wpPassword1',
1021 'placeholder-message' => 'userlogin-yourpassword-ph',
1026 // option for saving the user token to a cookie
1028 'name' => 'wpRemember',
1029 'label-message' => $this->msg( 'userlogin-remembermypassword' )
1030 ->numParams( $expirationDays ),
1031 'id' => 'wpRemember',
1036 'default' => $this->msg( 'pt-login-' . $continuePart . 'button' )->text(),
1037 'id' => 'wpLoginAttempt',
1040 'linkcontainer' => [
1043 'cssclass' => 'mw-form-related-link-container mw-userlogin-help',
1044 // 'id' => 'mw-userlogin-help', // FIXME HTMLInfoField ignores this
1046 'default' => Html
::element( 'a', [
1047 'href' => Skin
::makeInternalOrExternalUrl( wfMessage( 'helplogin-url' )
1048 ->inContentLanguage()
1050 ], $this->msg( 'userlogin-helplink2' )->text() ),
1053 // button for ResetPasswordSecondaryAuthenticationProvider
1060 $fieldDefinitions['username'] +
= [
1063 'cssclass' => 'loginText',
1065 // 'required' => true,
1067 $fieldDefinitions['password'] +
= [
1068 'type' => 'password',
1069 // 'label-message' => 'userlogin-yourpassword', // would override the changepassword label
1070 'name' => 'wpPassword',
1071 'cssclass' => 'loginPassword',
1073 // 'required' => true,
1076 if ( $this->mEntryError
) {
1077 $fieldDefinitions['entryError'] = [
1079 'default' => Html
::rawElement( 'div', [ 'class' => $this->mEntryErrorType
. 'box', ],
1080 $this->mEntryError
),
1087 if ( !$this->showExtraInformation() ) {
1088 unset( $fieldDefinitions['linkcontainer'] );
1091 $fieldDefinitions = $this->getBCFieldDefinitions( $fieldDefinitions, $template );
1092 $fieldDefinitions = array_filter( $fieldDefinitions );
1094 return $fieldDefinitions;
1098 * Adds fields provided via the deprecated UserLoginForm / UserCreateForm hooks
1099 * @param $fieldDefinitions array
1100 * @param FakeAuthTemplate $template
1103 protected function getBCFieldDefinitions( $fieldDefinitions, $template ) {
1104 if ( $template->get( 'usedomain', false ) ) {
1105 // TODO probably should be translated to the new domain notation in AuthManager
1106 $fieldDefinitions['domain'] = [
1108 'label-message' => 'yourdomainname',
1109 'options' => array_combine( $template->get( 'domainnames', [] ),
1110 $template->get( 'domainnames', [] ) ),
1111 'default' => $template->get( 'domain', '' ),
1112 'name' => 'wpDomain',
1113 // FIXME id => 'mw-user-domain-section' on the parent div
1117 // poor man's associative array_splice
1118 $extraInputPos = array_search( 'extrainput', array_keys( $fieldDefinitions ), true );
1119 $fieldDefinitions = array_slice( $fieldDefinitions, 0, $extraInputPos, true )
1120 +
$template->getExtraInputDefinitions()
1121 +
array_slice( $fieldDefinitions, $extraInputPos +
1, null, true );
1123 return $fieldDefinitions;
1127 * Check if a session cookie is present.
1129 * This will not pick up a cookie set during _this_ request, but is meant
1130 * to ensure that the client is returning the cookie which was set on a
1131 * previous pass through the system.
1135 protected function hasSessionCookie() {
1136 global $wgDisableCookieCheck, $wgInitialSessionId;
1138 return $wgDisableCookieCheck ||
(
1139 $wgInitialSessionId &&
1140 $this->getRequest()->getSession()->getId() === (string)$wgInitialSessionId
1145 * Returns a string that can be appended to the URL (without encoding) to preserve the
1146 * return target. Does not include leading '?'/'&'.
1148 protected function getReturnToQueryStringFragment() {
1150 if ( $this->mReturnTo
!== '' ) {
1151 $returnto = 'returnto=' . wfUrlencode( $this->mReturnTo
);
1152 if ( $this->mReturnToQuery
!== '' ) {
1153 $returnto .= '&returntoquery=' . wfUrlencode( $this->mReturnToQuery
);
1160 * Whether the login/create account form should display a link to the
1161 * other form (in addition to whatever the skin provides).
1164 private function showCreateAccountLink() {
1165 if ( $this->isSignup() ) {
1167 } elseif ( $this->getUser()->isAllowed( 'createaccount' ) ) {
1174 protected function getTokenName() {
1175 return $this->isSignup() ?
'wpCreateaccountToken' : 'wpLoginToken';
1179 * Produce a bar of links which allow the user to select another language
1180 * during login/registration but retain "returnto"
1184 protected function makeLanguageSelector() {
1185 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1186 if ( $msg->isBlank() ) {
1189 $langs = explode( "\n", $msg->text() );
1191 foreach ( $langs as $lang ) {
1192 $lang = trim( $lang, '* ' );
1193 $parts = explode( '|', $lang );
1194 if ( count( $parts ) >= 2 ) {
1195 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1199 return count( $links ) > 0 ?
$this->msg( 'loginlanguagelabel' )->rawParams(
1200 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1204 * Create a language selector link for a particular language
1205 * Links back to this page preserving type and returnto
1207 * @param string $text Link text
1208 * @param string $lang Language code
1211 protected function makeLanguageSelectorLink( $text, $lang ) {
1212 if ( $this->getLanguage()->getCode() == $lang ) {
1213 // no link for currently used language
1214 return htmlspecialchars( $text );
1216 $query = [ 'uselang' => $lang ];
1217 if ( $this->mReturnTo
!== '' ) {
1218 $query['returnto'] = $this->mReturnTo
;
1219 $query['returntoquery'] = $this->mReturnToQuery
;
1223 $targetLanguage = Language
::factory( $lang );
1224 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1226 return Linker
::linkKnown(
1227 $this->getPageTitle(),
1228 htmlspecialchars( $text ),
1234 protected function getGroupName() {
1239 * @param array $formDescriptor
1241 protected function postProcessFormDescriptor( &$formDescriptor ) {
1242 // Pre-fill username (if not creating an account, T46775).
1244 isset( $formDescriptor['username'] ) &&
1245 !isset( $formDescriptor['username']['default'] ) &&
1248 $user = $this->getUser();
1249 if ( $user->isLoggedIn() ) {
1250 $formDescriptor['username']['default'] = $user->getName();
1252 $formDescriptor['username']['default'] =
1253 $this->getRequest()->getSession()->suggestLoginUsername();
1257 // don't show a submit button if there is nothing to submit (i.e. the only form content
1258 // is other submit buttons, for redirect flows)
1259 if ( !$this->needsSubmitButton( $formDescriptor ) ) {
1260 unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] );
1263 if ( !$this->isSignup() ) {
1264 // FIXME HACK don't focus on non-empty field
1265 // maybe there should be an autofocus-if similar to hide-if?
1267 isset( $formDescriptor['username'] )
1268 && empty( $formDescriptor['username']['default'] )
1269 && !$this->getRequest()->getCheck( 'wpName' )
1271 $formDescriptor['username']['autofocus'] = true;
1272 } elseif ( isset( $formDescriptor['password'] ) ) {
1273 $formDescriptor['password']['autofocus'] = true;
1277 $this->addTabIndex( $formDescriptor );
1282 * B/C class to try handling login/signup template modifications even though login/signup does not
1283 * actually happen through a template anymore. Just collects extra field definitions and allows
1284 * some other class to do decide what to do with threm..
1285 * TODO find the right place for adding extra fields and kill this
1287 class FakeAuthTemplate
extends BaseTemplate
{
1288 public function execute() {
1289 throw new LogicException( 'not used' );
1293 * Extensions (AntiSpoof and TitleBlacklist) call this in response to
1294 * UserCreateForm hook to add checkboxes to the create account form.
1296 public function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
1297 // use the same indexes as UserCreateForm just in case someone adds an item manually
1298 $this->data
['extrainput'][] = [
1303 'helptext' => $helptext,
1308 * Turns addInputItem-style field definitions into HTMLForm field definitions.
1311 public function getExtraInputDefinitions() {
1314 foreach ( $this->get( 'extrainput', [] ) as $field ) {
1316 'type' => $field['type'] === 'checkbox' ?
'check' : $field['type'],
1317 'name' => $field['name'],
1318 'value' => $field['value'],
1319 'id' => $field['name'],
1321 if ( $field['msg'] ) {
1322 $definition['label-message'] = $this->getMsg( $field['msg'] );
1324 if ( $field['helptext'] ) {
1325 $definition['help'] = $this->msgWiki( $field['helptext'] );
1328 // the array key doesn't matter much when name is defined explicitly but
1329 // let's try and follow HTMLForm conventions
1330 $name = preg_replace( '/^wp(?=[A-Z])/', '', $field['name'] );
1331 $definitions[$name] = $definition;
1334 if ( $this->haveData( 'extrafields' ) ) {
1335 $definitions['extrafields'] = [
1338 'default' => $this->get( 'extrafields' ),
1342 return $definitions;
1347 * A horrible hack to handle AuthManager's feature flag. For other special pages this is done in
1348 * SpecialPageFactory, but LoginForm is used directly by some extensions. Will be killed as soon
1349 * as AuthManager is stable.
1351 class LoginForm
extends SpecialPage
{
1352 private $realLoginForm;
1354 public function __construct( $request = null ) {
1355 global $wgDisableAuthManager;
1356 if ( $wgDisableAuthManager ) {
1357 $this->realLoginForm
= new LoginFormPreAuthManager( $request );
1359 $this->realLoginForm
= new LoginFormAuthManager( $request );
1365 public function __get( $name ) {
1366 return $this->realLoginForm
->$name;
1369 public function __set( $name, $value ) {
1370 $this->realLoginForm
->$name = $value;
1373 public function __call( $name, $args ) {
1374 return call_user_func_array( [ $this->realLoginForm
, $name ], $args );
1377 public static function __callStatic( $name, $args ) {
1378 global $wgDisableAuthManager;
1379 return call_user_func_array( [ $wgDisableAuthManager ? LoginFormPreAuthManager
::class
1380 : LoginFormAuthManager
::class, $name ], $args );
1383 // all public SpecialPage methods need to be proxied explicitly
1385 public function getName() {
1386 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1388 public function getRestriction() {
1389 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1391 public function isListed() {
1392 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1394 public function setListed( $listed ) {
1395 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1397 public function listed( $x = null ) {
1398 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1400 public function isIncludable() {
1401 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1403 public function including( $x = null ) {
1404 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1406 public function getLocalName() {
1407 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1409 public function isExpensive() {
1410 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1412 public function isCached() {
1413 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1415 public function isRestricted() {
1416 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1418 public function userCanExecute( User
$user ) {
1419 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1421 public function displayRestrictionError() {
1422 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1424 public function checkPermissions() {
1425 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1427 public function checkReadOnly() {
1428 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1430 public function requireLogin(
1431 $reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin'
1433 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1435 public function prefixSearchSubpages( $search, $limit, $offset ) {
1436 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1438 public function execute( $subPage ) {
1439 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1441 public function getDescription() {
1442 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1444 function getTitle( $subpage = false ) {
1445 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1447 function getPageTitle( $subpage = false ) {
1448 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1450 public function setContext( $context ) {
1451 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1453 public function getContext() {
1454 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1456 public function getRequest() {
1457 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1459 public function getOutput() {
1460 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1462 public function getUser() {
1463 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1465 public function getSkin() {
1466 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1468 public function getLanguage() {
1469 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1471 public function getConfig() {
1472 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1474 public function getFullTitle() {
1475 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1477 public function getFinalGroupName() {
1478 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1480 public function doesWrites() {
1481 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1484 // no way to proxy constants and static properties
1489 const WRONG_PLUGIN_PASS
= 3;
1490 const NOT_EXISTS
= 4;
1491 const WRONG_PASS
= 5;
1492 const EMPTY_PASS
= 6;
1493 const RESET_PASS
= 7;
1495 const CREATE_BLOCKED
= 9;
1496 const THROTTLED
= 10;
1497 const USER_BLOCKED
= 11;
1498 const NEED_TOKEN
= 12;
1499 const WRONG_TOKEN
= 13;
1500 const USER_MIGRATED
= 14;
1502 public static $statusCodes = [
1503 self
::SUCCESS
=> 'success',
1504 self
::NO_NAME
=> 'no_name',
1505 self
::ILLEGAL
=> 'illegal',
1506 self
::WRONG_PLUGIN_PASS
=> 'wrong_plugin_pass',
1507 self
::NOT_EXISTS
=> 'not_exists',
1508 self
::WRONG_PASS
=> 'wrong_pass',
1509 self
::EMPTY_PASS
=> 'empty_pass',
1510 self
::RESET_PASS
=> 'reset_pass',
1511 self
::ABORTED
=> 'aborted',
1512 self
::CREATE_BLOCKED
=> 'create_blocked',
1513 self
::THROTTLED
=> 'throttled',
1514 self
::USER_BLOCKED
=> 'user_blocked',
1515 self
::NEED_TOKEN
=> 'need_token',
1516 self
::WRONG_TOKEN
=> 'wrong_token',
1517 self
::USER_MIGRATED
=> 'user_migrated',
1520 public static $validErrorMessages = [
1521 'exception-nologin-text',
1522 'watchlistanontext',
1523 'changeemail-no-info',
1524 'resetpass-no-info',
1525 'confirmemail_needlogin',
1526 'prefsnologintext2',
1531 * LoginForm as a special page has been replaced by SpecialUserLogin and SpecialCreateAccount,
1532 * but some extensions called its public methods directly, so the class is retained as a
1533 * B/C wrapper. Anything that used it before should use AuthManager instead.
1535 class LoginFormAuthManager
extends SpecialPage
{
1539 const WRONG_PLUGIN_PASS
= 3;
1540 const NOT_EXISTS
= 4;
1541 const WRONG_PASS
= 5;
1542 const EMPTY_PASS
= 6;
1543 const RESET_PASS
= 7;
1545 const CREATE_BLOCKED
= 9;
1546 const THROTTLED
= 10;
1547 const USER_BLOCKED
= 11;
1548 const NEED_TOKEN
= 12;
1549 const WRONG_TOKEN
= 13;
1550 const USER_MIGRATED
= 14;
1552 public static $statusCodes = [
1553 self
::SUCCESS
=> 'success',
1554 self
::NO_NAME
=> 'no_name',
1555 self
::ILLEGAL
=> 'illegal',
1556 self
::WRONG_PLUGIN_PASS
=> 'wrong_plugin_pass',
1557 self
::NOT_EXISTS
=> 'not_exists',
1558 self
::WRONG_PASS
=> 'wrong_pass',
1559 self
::EMPTY_PASS
=> 'empty_pass',
1560 self
::RESET_PASS
=> 'reset_pass',
1561 self
::ABORTED
=> 'aborted',
1562 self
::CREATE_BLOCKED
=> 'create_blocked',
1563 self
::THROTTLED
=> 'throttled',
1564 self
::USER_BLOCKED
=> 'user_blocked',
1565 self
::NEED_TOKEN
=> 'need_token',
1566 self
::WRONG_TOKEN
=> 'wrong_token',
1567 self
::USER_MIGRATED
=> 'user_migrated',
1571 * @param WebRequest $request
1573 public function __construct( $request = null ) {
1574 wfDeprecated( 'LoginForm', '1.27' );
1575 parent
::__construct();
1579 * @deprecated since 1.27 - call LoginHelper::getValidErrorMessages instead.
1581 public static function getValidErrorMessages() {
1582 return LoginHelper
::getValidErrorMessages();
1586 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1588 public static function incrementLoginThrottle( $username ) {
1589 wfDeprecated( __METHOD__
, "1.27" );
1591 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1592 $throttler = new Throttler();
1593 return $throttler->increase( $username, $wgRequest->getIP(), __METHOD__
);
1597 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1599 public static function incLoginThrottle( $username ) {
1600 wfDeprecated( __METHOD__
, "1.27" );
1601 $res = self
::incrementLoginThrottle( $username );
1602 return is_array( $res ) ?
true : 0;
1606 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1608 public static function clearLoginThrottle( $username ) {
1609 wfDeprecated( __METHOD__
, "1.27" );
1611 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1612 $throttler = new Throttler();
1613 return $throttler->clear( $username, $wgRequest->getIP() );
1617 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1619 public static function getLoginToken() {
1620 wfDeprecated( __METHOD__
, '1.27' );
1622 return $wgRequest->getSession()->getToken( '', 'login' )->toString();
1626 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1628 public static function setLoginToken() {
1629 wfDeprecated( __METHOD__
, '1.27' );
1633 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1635 public static function clearLoginToken() {
1636 wfDeprecated( __METHOD__
, '1.27' );
1638 $wgRequest->getSession()->resetToken( 'login' );
1642 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1644 public static function getCreateaccountToken() {
1645 wfDeprecated( __METHOD__
, '1.27' );
1647 return $wgRequest->getSession()->getToken( '', 'createaccount' )->toString();
1651 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1653 public static function setCreateaccountToken() {
1654 wfDeprecated( __METHOD__
, '1.27' );
1658 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1660 public static function clearCreateaccountToken() {
1661 wfDeprecated( __METHOD__
, '1.27' );
1663 $wgRequest->getSession()->resetToken( 'createaccount' );