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 $mSecureLoginUrl;
53 protected $securityLevel;
55 /** @var bool True if the user if creating an account for someone else. Flag used for internal
56 * communication, only set at the very end. */
57 protected $proxyAccountCreation;
58 /** @var User FIXME another flag for passing data. */
59 protected $targetUser;
64 /** @var FakeAuthTemplate */
65 protected $fakeTemplate;
67 abstract protected function isSignup();
70 * @param bool $direct True if the action was successful just now; false if that happened
71 * pre-redirection (so this handler was called already)
72 * @param StatusValue|null $extraMessages
75 abstract protected function successfulAction( $direct = false, $extraMessages = null );
78 * Logs to the authmanager-stats channel.
79 * @param bool $success
80 * @param string|null $status Error message key
82 abstract protected function logAuthResult( $success, $status = null );
84 public function __construct( $name ) {
85 global $wgUseMediaWikiUIEverywhere;
86 parent
::__construct( $name );
88 // Override UseMediaWikiEverywhere to true, to force login and create form to use mw ui
89 $wgUseMediaWikiUIEverywhere = true;
93 * Load data from request.
95 * @param string $subPage Subpage of Special:Userlogin
97 protected function load( $subPage ) {
98 global $wgSecureLogin;
100 if ( $this->mLoaded
) {
103 $this->mLoaded
= true;
105 $request = $this->getRequest();
107 $this->mPosted
= $request->wasPosted();
108 $this->mIsReturn
= $subPage === 'return';
109 $this->mAction
= $request->getVal( 'action' );
110 $this->mFromHTTP
= $request->getBool( 'fromhttp', false )
111 ||
$request->getBool( 'wpFromhttp', false );
112 $this->mStickHTTPS
= ( !$this->mFromHTTP
&& $request->getProtocol() === 'https' )
113 ||
$request->getBool( 'wpForceHttps', false );
114 $this->mLanguage
= $request->getText( 'uselang' );
115 $this->mReturnTo
= $request->getVal( 'returnto', '' );
116 $this->mReturnToQuery
= $request->getVal( 'returntoquery', '' );
118 $securityLevel = $this->getRequest()->getText( 'force' );
120 $securityLevel && AuthManager
::singleton()->securitySensitiveOperationStatus(
121 $securityLevel ) === AuthManager
::SEC_REAUTH
123 $this->securityLevel
= $securityLevel;
126 $this->loadAuth( $subPage );
128 $this->mToken
= $request->getVal( $this->getTokenName() );
130 // Show an error or warning passed on from a previous page
131 $entryError = $this->msg( $request->getVal( 'error', '' ) );
132 $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
133 // bc: provide login link as a parameter for messages where the translation
135 $loginreqlink = Linker
::linkKnown(
136 $this->getPageTitle(),
137 $this->msg( 'loginreqlink' )->escaped(),
140 'returnto' => $this->mReturnTo
,
141 'returntoquery' => $this->mReturnToQuery
,
142 'uselang' => $this->mLanguage
,
143 'fromhttp' => $wgSecureLogin && $this->mFromHTTP ?
'1' : null,
147 // Only show valid error or warning messages.
148 if ( $entryError->exists()
149 && in_array( $entryError->getKey(), LoginHelper
::getValidErrorMessages(), true )
151 $this->mEntryErrorType
= 'error';
152 $this->mEntryError
= $entryError->rawParams( $loginreqlink )->parse();
154 } elseif ( $entryWarning->exists()
155 && in_array( $entryWarning->getKey(), LoginHelper
::getValidErrorMessages(), true )
157 $this->mEntryErrorType
= 'warning';
158 $this->mEntryError
= $entryWarning->rawParams( $loginreqlink )->parse();
161 # 1. When switching accounts, it sucks to get automatically logged out
162 # 2. Do not return to PasswordReset after a successful password change
163 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
164 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
165 if ( is_object( $returnToTitle )
166 && ( $returnToTitle->isSpecial( 'Userlogout' )
167 ||
$returnToTitle->isSpecial( 'PasswordReset' ) )
169 $this->mReturnTo
= '';
170 $this->mReturnToQuery
= '';
174 protected function getPreservedParams( $withToken = false ) {
175 global $wgSecureLogin;
177 $params = parent
::getPreservedParams( $withToken );
179 'returnto' => $this->mReturnTo ?
: null,
180 'returntoquery' => $this->mReturnToQuery ?
: null,
182 if ( $wgSecureLogin && !$this->isSignup() ) {
183 $params['fromhttp'] = $this->mFromHTTP ?
'1' : null;
189 * @param string|null $subPage
191 public function execute( $subPage ) {
192 $authManager = AuthManager
::singleton();
193 $session = SessionManager
::getGlobalSession();
195 // Session data is used for various things in the authentication process, so we must make
196 // sure a session cookie or some equivalent mechanism is set.
199 $this->load( $subPage );
201 $this->checkPermissions();
203 // Make sure it's possible to log in
204 if ( !$this->isSignup() && !$session->canSetUser() ) {
205 throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
206 $session->getProvider()->describe( RequestContext
::getMain()->getLanguage() )
211 * In the case where the user is already logged in, and was redirected to
212 * the login form from a page that requires login, do not show the login
213 * page. The use case scenario for this is when a user opens a large number
214 * of tabs, is redirected to the login page on all of them, and then logs
215 * in on one, expecting all the others to work properly.
217 * However, do show the form if it was visited intentionally (no 'returnto'
218 * is present). People who often switch between several accounts have grown
219 * accustomed to this behavior.
221 * Also make an exception when force=<level> is set in the URL, which means the user must
222 * reauthenticate for security reasons.
224 if ( !$this->isSignup() && !$this->mPosted
&& !$this->securityLevel
&&
225 ( $this->mReturnTo
!== '' ||
$this->mReturnToQuery
!== '' ) &&
226 $this->getUser()->isLoggedIn()
228 $this->successfulAction();
231 // If logging in and not on HTTPS, either redirect to it or offer a link.
232 global $wgSecureLogin;
233 if ( $this->getRequest()->getProtocol() !== 'https' ) {
234 $title = $this->getFullTitle();
235 $query = $this->getPreservedParams( false ) +
[
237 ( $this->mEntryErrorType
=== 'error' ?
'error'
238 : 'warning' ) => $this->mEntryError
,
239 ] +
$this->getRequest()->getQueryValues();
240 $url = $title->getFullURL( $query, false, PROTO_HTTPS
);
241 if ( $wgSecureLogin && !$this->mFromHTTP
&&
242 wfCanIPUseHTTPS( $this->getRequest()->getIP() )
244 // Avoid infinite redirect
245 $url = wfAppendQuery( $url, 'fromhttp=1' );
246 $this->getOutput()->redirect( $url );
247 // Since we only do this redir to change proto, always vary
248 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
252 // A wiki without HTTPS login support should set $wgServer to
253 // http://somehost, in which case the secure URL generated
254 // above won't actually start with https://
255 if ( substr( $url, 0, 8 ) === 'https://' ) {
256 $this->mSecureLoginUrl
= $url;
261 if ( !$this->isActionAllowed( $this->authAction
) ) {
262 // FIXME how do we explain this to the user? can we handle session loss better?
263 // messages used: authpage-cannot-login, authpage-cannot-login-continue,
264 // authpage-cannot-create, authpage-cannot-create-continue
265 $this->mainLoginForm( [], 'authpage-cannot-' . $this->authAction
);
269 $status = $this->trySubmit();
271 if ( !$status ||
!$status->isGood() ) {
272 $this->mainLoginForm( $this->authRequests
, $status ?
$status->getMessage() : '', 'error' );
276 /** @var AuthenticationResponse $response */
277 $response = $status->getValue();
279 $returnToUrl = $this->getPageTitle( 'return' )
280 ->getFullURL( $this->getPreservedParams( true ), false, PROTO_HTTPS
);
281 switch ( $response->status
) {
282 case AuthenticationResponse
::PASS
:
283 $this->logAuthResult( true );
284 $this->proxyAccountCreation
= $this->isSignup() && !$this->getUser()->isAnon();
285 $this->targetUser
= User
::newFromName( $response->username
);
288 !$this->proxyAccountCreation
289 && $response->loginRequest
290 && $authManager->canAuthenticateNow()
292 // successful registration; log the user in instantly
293 $response2 = $authManager->beginAuthentication( [ $response->loginRequest
],
295 if ( $response2->status
!== AuthenticationResponse
::PASS
) {
296 LoggerFactory
::getInstance( 'login' )
297 ->error( 'Could not log in after account creation' );
298 $this->successfulAction( true, Status
::newFatal( 'createacct-loginerror' ) );
303 if ( !$this->proxyAccountCreation
) {
304 // Ensure that the context user is the same as the session user.
305 $this->setSessionUserForCurrentRequest();
308 $this->successfulAction( true );
310 case AuthenticationResponse
::FAIL
:
312 case AuthenticationResponse
::RESTART
:
313 unset( $this->authForm
);
314 if ( $response->status
=== AuthenticationResponse
::FAIL
) {
315 $action = $this->getDefaultAction( $subPage );
316 $messageType = 'error';
318 $action = $this->getContinueAction( $this->authAction
);
319 $messageType = 'warning';
321 $this->logAuthResult( false, $response->message ?
$response->message
->getKey() : '-' );
322 $this->loadAuth( $subPage, $action, true );
323 $this->mainLoginForm( $this->authRequests
, $response->message
, $messageType );
325 case AuthenticationResponse
::REDIRECT
:
326 unset( $this->authForm
);
327 $this->getOutput()->redirect( $response->redirectTarget
);
329 case AuthenticationResponse
::UI
:
330 unset( $this->authForm
);
331 $this->authAction
= $this->isSignup() ? AuthManager
::ACTION_CREATE_CONTINUE
332 : AuthManager
::ACTION_LOGIN_CONTINUE
;
333 $this->authRequests
= $response->neededRequests
;
334 $this->mainLoginForm( $response->neededRequests
, $response->message
, 'warning' );
337 throw new LogicException( 'invalid AuthenticationResponse' );
342 * Show the success page.
344 * @param string $type Condition of return to; see `executeReturnTo`
345 * @param string|Message $title Page's title
346 * @param string $msgname
347 * @param string $injected_html
348 * @param StatusValue|null $extraMessages
350 protected function showSuccessPage(
351 $type, $title, $msgname, $injected_html, $extraMessages
353 $out = $this->getOutput();
354 $out->setPageTitle( $title );
356 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
358 if ( $extraMessages ) {
359 $extraMessages = Status
::wrap( $extraMessages );
360 $out->addWikiText( $extraMessages->getWikiText() );
363 $out->addHTML( $injected_html );
365 $helper = new LoginHelper( $this->getContext() );
366 $helper->showReturnToPage( $type, $this->mReturnTo
, $this->mReturnToQuery
, $this->mStickHTTPS
);
370 * Add a "return to" link or redirect to it.
371 * Extensions can use this to reuse the "return to" logic after
372 * inject steps (such as redirection) into the login process.
374 * @param string $type One of the following:
375 * - error: display a return to link ignoring $wgRedirectOnLogin
376 * - signup: display a return to link using $wgRedirectOnLogin if needed
377 * - success: display a return to link using $wgRedirectOnLogin if needed
378 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
379 * @param string $returnTo
380 * @param array|string $returnToQuery
381 * @param bool $stickHTTPS Keep redirect link on HTTPS
384 public function showReturnToPage(
385 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
387 $helper = new LoginHelper( $this->getContext() );
388 $helper->showReturnToPage( $type, $returnTo, $returnToQuery, $stickHTTPS );
392 * Replace some globals to make sure the fact that the user has just been logged in is
393 * reflected in the current request.
396 protected function setSessionUserForCurrentRequest() {
397 global $wgUser, $wgLang;
399 $context = RequestContext
::getMain();
400 $localContext = $this->getContext();
401 if ( $context !== $localContext ) {
402 // remove AuthManagerSpecialPage context hack
403 $this->setContext( $context );
406 $user = $context->getRequest()->getSession()->getUser();
409 $context->setUser( $user );
411 $code = $this->getRequest()->getVal( 'uselang', $user->getOption( 'language' ) );
412 $userLang = Language
::factory( $code );
414 $context->setLanguage( $userLang );
418 * @param AuthenticationRequest[] $requests A list of AuthorizationRequest objects,
419 * used to generate the form fields. An empty array means a fatal error
420 * (authentication cannot continue).
421 * @param string|Message $msg
422 * @param string $msgtype
423 * @throws ErrorPageError
426 * @throws MWException
427 * @throws PermissionsError
428 * @throws ReadOnlyError
431 protected function mainLoginForm( array $requests, $msg = '', $msgtype = 'error' ) {
432 $titleObj = $this->getPageTitle();
433 $user = $this->getUser();
434 $out = $this->getOutput();
436 // FIXME how to handle empty $requests - restart, or no form, just an error message?
437 // no form would be better for no session type errors, restart is better when can* fails.
439 $this->authAction
= $this->getDefaultAction( $this->subPage
);
440 $this->authForm
= null;
441 $requests = AuthManager
::singleton()->getAuthenticationRequests( $this->authAction
, $user );
444 // Generic styles and scripts for both login and signup form
445 $out->addModuleStyles( [
447 'mediawiki.ui.button',
448 'mediawiki.ui.checkbox',
449 'mediawiki.ui.input',
450 'mediawiki.special.userlogin.common.styles'
452 if ( $this->isSignup() ) {
453 // XXX hack pending RL or JS parse() support for complex content messages T27349
454 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
455 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
457 // Additional styles and scripts for signup form
459 'mediawiki.special.userlogin.signup.js'
461 $out->addModuleStyles( [
462 'mediawiki.special.userlogin.signup.styles'
465 // Additional styles for login form
466 $out->addModuleStyles( [
467 'mediawiki.special.userlogin.login.styles'
470 $out->disallowUserJs(); // just in case...
472 $form = $this->getAuthForm( $requests, $this->authAction
, $msg, $msgtype );
473 $form->prepareForm();
474 $formHtml = $form->getHTML( $msg ? Status
::newFatal( $msg ) : false );
476 $out->addHTML( $this->getPageHtml( $formHtml ) );
480 * Add page elements which are outside the form.
481 * FIXME this should probably be a template, but use a sane language (handlebars?)
482 * @param string $formHtml
485 protected function getPageHtml( $formHtml ) {
486 global $wgLoginLanguageSelector;
488 $loginPrompt = $this->isSignup() ?
'' : Html
::rawElement( 'div',
489 [ 'id' => 'userloginprompt' ], $this->msg( 'loginprompt' )->parseAsBlock() );
490 $languageLinks = $wgLoginLanguageSelector ?
$this->makeLanguageSelector() : '';
491 $signupStartMsg = $this->msg( 'signupstart' );
492 $signupStart = ( $this->isSignup() && !$signupStartMsg->isDisabled() )
493 ? Html
::rawElement( 'div', [ 'id' => 'signupstart' ], $signupStartMsg->parseAsBlock() ) : '';
494 if ( $languageLinks ) {
495 $languageLinks = Html
::rawElement( 'div', [ 'id' => 'languagelinks' ],
496 Html
::rawElement( 'p', [], $languageLinks )
500 $benefitsContainer = '';
501 if ( $this->isSignup() && $this->showExtraInformation() ) {
503 // createacct-benefit-icon1 createacct-benefit-head1 createacct-benefit-body1
504 // createacct-benefit-icon2 createacct-benefit-head2 createacct-benefit-body2
505 // createacct-benefit-icon3 createacct-benefit-head3 createacct-benefit-body3
508 for ( $benefitIdx = 1; $benefitIdx <= $benefitCount; $benefitIdx++
) {
509 $headUnescaped = $this->msg( "createacct-benefit-head$benefitIdx" )->text();
510 $iconClass = $this->msg( "createacct-benefit-icon$benefitIdx" )->escaped();
511 $benefitList .= Html
::rawElement( 'div', [ 'class' => "mw-number-text $iconClass" ],
512 Html
::rawElement( 'h3', [],
513 $this->msg( "createacct-benefit-head$benefitIdx" )->escaped()
515 . Html
::rawElement( 'p', [],
516 $this->msg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped()
520 $benefitsContainer = Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-container' ],
521 Html
::rawElement( 'h2', [], $this->msg( 'createacct-benefit-heading' )->escaped() )
522 . Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-list' ],
528 $html = Html
::rawElement( 'div', [ 'class' => 'mw-ui-container' ],
532 . Html
::rawElement( 'div', [ 'id' => 'userloginForm' ],
542 * Generates a form from the given request.
543 * @param AuthenticationRequest[] $requests
544 * @param string $action AuthManager action name
545 * @param string|Message $msg
546 * @param string $msgType
549 protected function getAuthForm( array $requests, $action, $msg = '', $msgType = 'error' ) {
550 global $wgSecureLogin, $wgLoginLanguageSelector;
551 // FIXME merge this with parent
553 if ( isset( $this->authForm
) ) {
554 return $this->authForm
;
557 $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
559 // get basic form description from the auth logic
560 $fieldInfo = AuthenticationRequest
::mergeFieldInfo( $requests );
561 $fakeTemplate = $this->getFakeTemplate( $msg, $msgType );
562 $this->fakeTemplate
= $fakeTemplate; // FIXME there should be a saner way to pass this to the hook
563 // this will call onAuthChangeFormFields()
564 $formDescriptor = static::fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction
);
565 $this->postProcessFormDescriptor( $formDescriptor );
567 $context = $this->getContext();
568 if ( $context->getRequest() !== $this->getRequest() ) {
569 // We have overridden the request, need to make sure the form uses that too.
570 $context = new DerivativeContext( $this->getContext() );
571 $context->setRequest( $this->getRequest() );
573 $form = HTMLForm
::factory( 'vform', $formDescriptor, $context );
575 $form->addHiddenField( 'authAction', $this->authAction
);
576 if ( $wgLoginLanguageSelector ) {
577 $form->addHiddenField( 'uselang', $this->mLanguage
);
579 $form->addHiddenField( 'force', $this->securityLevel
);
580 $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() );
581 if ( $wgSecureLogin ) {
582 // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
583 if ( !$this->isSignup() ) {
584 $form->addHiddenField( 'wpForceHttps', (int)$this->mStickHTTPS
);
585 $form->addHiddenField( 'wpFromhttp', $usingHTTPS );
589 // set properties of the form itself
590 $form->setAction( $this->getPageTitle()->getLocalURL( $this->getReturnToQueryStringFragment() ) );
591 $form->setName( 'userlogin' . ( $this->isSignup() ?
'2' : '' ) );
592 if ( $this->isSignup() ) {
593 $form->setId( 'userlogin2' );
597 // header used by ConfirmEdit, CondfirmAccount, Persona, WikimediaIncubator, SemanticSignup
598 // should be above the error message but HTMLForm doesn't support that
599 $form->addHeaderText( $fakeTemplate->html( 'header' ) );
601 // FIXME the old form used this for error/warning messages which does not play well with
602 // HTMLForm (maybe it could with a subclass?); for now only display it for signups
603 // (where the JS username validation needs it) and alway empty
604 if ( $this->isSignup() ) {
605 // used by the mediawiki.special.userlogin.signup.js module
606 $statusAreaAttribs = [ 'id' => 'mw-createacct-status-area' ];
607 // $statusAreaAttribs += $msg ? [ 'class' => "{$msgType}box" ] : [ 'style' => 'display: none;' ];
608 $form->addHeaderText( Html
::element( 'div', $statusAreaAttribs ) );
611 // header used by MobileFrontend
612 $form->addHeaderText( $fakeTemplate->html( 'formheader' ) );
614 // blank signup footer for site customization
615 if ( $this->isSignup() && $this->showExtraInformation() ) {
616 // Use signupend-https for HTTPS requests if it's not blank, signupend otherwise
617 $signupendMsg = $this->msg( 'signupend' );
618 $signupendHttpsMsg = $this->msg( 'signupend-https' );
619 if ( !$signupendMsg->isDisabled() ) {
620 $signupendText = ( $usingHTTPS && !$signupendHttpsMsg->isBlank() )
621 ?
$signupendHttpsMsg ->parse() : $signupendMsg->parse();
622 $form->addPostText( Html
::rawElement( 'div', [ 'id' => 'signupend' ], $signupendText ) );
626 // warning header for non-standard workflows (e.g. security reauthentication)
627 if ( !$this->isSignup() && $this->getUser()->isLoggedIn() ) {
628 $reauthMessage = $this->securityLevel ?
'userlogin-reauth' : 'userlogin-loggedin';
629 $form->addHeaderText( Html
::rawElement( 'div', [ 'class' => 'warningbox' ],
630 $this->msg( $reauthMessage )->params( $this->getUser()->getName() )->parse() ) );
633 if ( !$this->isSignup() && $this->showExtraInformation() ) {
634 $passwordReset = new PasswordReset( $this->getConfig(), AuthManager
::singleton() );
635 if ( $passwordReset->isAllowed( $this->getUser() ) ) {
636 $form->addFooterText( Html
::rawElement(
638 [ 'class' => 'mw-ui-vform-field mw-form-related-link-container' ],
640 SpecialPage
::getTitleFor( 'PasswordReset' ),
641 $this->msg( 'userlogin-resetpassword-link' )->escaped()
646 // Don't show a "create account" link if the user can't.
647 if ( $this->showCreateAccountLink() ) {
648 // link to the other action
649 $linkTitle = $this->getTitleFor( $this->isSignup() ?
'Userlogin' :'CreateAccount' );
650 $linkq = $this->getReturnToQueryStringFragment();
651 // Pass any language selection on to the mode switch link
652 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
653 $linkq .= '&uselang=' . $this->mLanguage
;
656 $loggedIn = $this->getUser()->isLoggedIn();
657 $createOrLoginHtml = Html
::rawElement( 'div',
658 [ 'id' => 'mw-createaccount' . ( !$loggedIn ?
'-cta' : '' ),
659 'class' => ( $loggedIn ?
'mw-form-related-link-container' : 'mw-ui-vform-field' ) ],
660 ( $loggedIn ?
'' : $this->msg( 'userlogin-noaccount' )->escaped() )
661 . Html
::element( 'a',
663 'id' => 'mw-createaccount-join' . ( $loggedIn ?
'-loggedin' : '' ),
664 'href' => $linkTitle->getLocalURL( $linkq ),
665 'class' => ( $loggedIn ?
'' : 'mw-ui-button' ),
669 ( $this->getUser()->isLoggedIn() ?
670 'userlogin-createanother' :
671 'userlogin-joinproject'
675 $form->addFooterText( $createOrLoginHtml );
679 $form->suppressDefaultSubmit();
681 $this->authForm
= $form;
687 * Temporary B/C method to handle extensions using the UserLoginForm/UserCreateForm hooks.
688 * @param string|Message $msg
689 * @param string $msgType
690 * @return FakeAuthTemplate
692 protected function getFakeTemplate( $msg, $msgType ) {
693 global $wgAuth, $wgEnableEmail, $wgHiddenPrefs, $wgEmailConfirmToEdit, $wgEnableUserEmail,
694 $wgSecureLogin, $wgLoginLanguageSelector, $wgPasswordResetRoutes;
696 // make a best effort to get the value of fields which used to be fixed in the old login
697 // template but now might or might not exist depending on what providers are used
698 $request = $this->getRequest();
700 'mUsername' => $request->getText( 'wpName' ),
701 'mPassword' => $request->getText( 'wpPassword' ),
702 'mRetype' => $request->getText( 'wpRetype' ),
703 'mEmail' => $request->getText( 'wpEmail' ),
704 'mRealName' => $request->getText( 'wpRealName' ),
705 'mDomain' => $request->getText( 'wpDomain' ),
706 'mReason' => $request->getText( 'wpReason' ),
707 'mRemember' => $request->getCheck( 'wpRemember' ),
710 // Preserves a bunch of logic from the old code that was rewritten in getAuthForm().
711 // There is no code reuse to make this easier to remove .
712 // If an extension tries to change any of these values, they are out of luck - we only
713 // actually use the domain/usedomain/domainnames, extraInput and extrafields keys.
715 $titleObj = $this->getPageTitle();
716 $user = $this->getUser();
717 $template = new FakeAuthTemplate();
719 // Pre-fill username (if not creating an account, bug 44775).
720 if ( $data->mUsername
== '' && $this->isSignup() ) {
721 if ( $user->isLoggedIn() ) {
722 $data->mUsername
= $user->getName();
724 $data->mUsername
= $this->getRequest()->getSession()->suggestLoginUsername();
728 if ( $this->isSignup() ) {
729 // Must match number of benefits defined in messages
730 $template->set( 'benefitCount', 3 );
732 $q = 'action=submitlogin&type=signup';
733 $linkq = 'type=login';
735 $q = 'action=submitlogin&type=login';
736 $linkq = 'type=signup';
739 if ( $this->mReturnTo
!== '' ) {
740 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
741 if ( $this->mReturnToQuery
!== '' ) {
742 $returnto .= '&returntoquery=' .
743 wfUrlencode( $this->mReturnToQuery
);
749 # Don't show a "create account" link if the user can't.
750 if ( $this->showCreateAccountLink() ) {
751 # Pass any language selection on to the mode switch link
752 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
753 $linkq .= '&uselang=' . $this->mLanguage
;
755 // Supply URL, login template creates the button.
756 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
758 $template->set( 'link', '' );
761 $resetLink = $this->isSignup()
763 : is_array( $wgPasswordResetRoutes )
764 && in_array( true, array_values( $wgPasswordResetRoutes ), true );
766 $template->set( 'header', '' );
767 $template->set( 'formheader', '' );
768 $template->set( 'skin', $this->getSkin() );
770 $template->set( 'name', $data->mUsername
);
771 $template->set( 'password', $data->mPassword
);
772 $template->set( 'retype', $data->mRetype
);
773 $template->set( 'createemailset', false ); // no easy way to get that from AuthManager
774 $template->set( 'email', $data->mEmail
);
775 $template->set( 'realname', $data->mRealName
);
776 $template->set( 'domain', $data->mDomain
);
777 $template->set( 'reason', $data->mReason
);
778 $template->set( 'remember', $data->mRemember
);
780 $template->set( 'action', $titleObj->getLocalURL( $q ) );
781 $template->set( 'message', $msg );
782 $template->set( 'messagetype', $msgType );
783 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
784 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs, true ) );
785 $template->set( 'useemail', $wgEnableEmail );
786 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
787 $template->set( 'emailothers', $wgEnableUserEmail );
788 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
789 $template->set( 'resetlink', $resetLink );
790 $template->set( 'canremember', $request->getSession()->getProvider()
791 ->getRememberUserDuration() !== null );
792 $template->set( 'usereason', $user->isLoggedIn() );
793 $template->set( 'cansecurelogin', ( $wgSecureLogin ) );
794 $template->set( 'stickhttps', (int)$this->mStickHTTPS
);
795 $template->set( 'loggedin', $user->isLoggedIn() );
796 $template->set( 'loggedinuser', $user->getName() );
797 $template->set( 'token', $this->getToken()->toString() );
799 $action = $this->isSignup() ?
'signup' : 'login';
800 $wgAuth->modifyUITemplate( $template, $action );
802 $oldTemplate = $template;
803 $hookName = $this->isSignup() ?
'UserCreateForm' : 'UserLoginForm';
804 Hooks
::run( $hookName, [ &$template ] );
805 if ( $oldTemplate !== $template ) {
806 wfDeprecated( "reference in $hookName hook", '1.27' );
813 public function onAuthChangeFormFields(
814 array $requests, array $fieldInfo, array &$formDescriptor, $action
816 $coreFieldDescriptors = $this->getFieldDefinitions( $this->fakeTemplate
);
817 $specialFields = array_merge( [ 'extraInput', 'linkcontainer', 'entryError' ],
818 array_keys( $this->fakeTemplate
->getExtraInputDefinitions() ) );
820 // keep the ordering from getCoreFieldDescriptors() where there is no explicit weight
821 foreach ( $coreFieldDescriptors as $fieldName => $coreField ) {
822 $requestField = isset( $formDescriptor[$fieldName] ) ?
823 $formDescriptor[$fieldName] : [];
825 // remove everything that is not in the fieldinfo, is not marked as a supplemental field
826 // to something in the fieldinfo, and is not a generic or B/C field or a submit button
828 !isset( $fieldInfo[$fieldName] )
830 !isset( $coreField['baseField'] )
831 ||
!isset( $fieldInfo[$coreField['baseField']] )
832 ) && !in_array( $fieldName, $specialFields, true )
833 && $coreField['type'] !== 'submit'
835 $coreFieldDescriptors[$fieldName] = null;
839 // core message labels should always take priority
841 isset( $coreField['label'] )
842 ||
isset( $coreField['label-message'] )
843 ||
isset( $coreField['label-raw'] )
845 unset( $requestField['label'], $requestField['label-message'], $coreField['label-raw'] );
848 $coreFieldDescriptors[$fieldName] +
= $requestField;
851 $formDescriptor = array_filter( $coreFieldDescriptors +
$formDescriptor );
856 * Show extra information such as password recovery information, link from login to signup,
857 * CTA etc? Such information should only be shown on the "landing page", ie. when the user
858 * is at the first step of the authentication process.
861 protected function showExtraInformation() {
862 return $this->authAction
!== $this->getContinueAction( $this->authAction
)
863 && !$this->securityLevel
;
867 * Create a HTMLForm descriptor for the core login fields.
868 * @param FakeAuthTemplate $template B/C data (not used but needed by getBCFieldDefinitions)
871 protected function getFieldDefinitions( $template ) {
872 global $wgEmailConfirmToEdit;
874 $isLoggedIn = $this->getUser()->isLoggedIn();
875 $continuePart = $this->isContinued() ?
'continue-' : '';
876 $anotherPart = $isLoggedIn ?
'another-' : '';
877 $expiration = $this->getRequest()->getSession()->getProvider()
878 ->getRememberUserDuration();
879 $expirationDays = ceil( $expiration / ( 3600 * 24 ) );
880 $secureLoginLink = '';
881 if ( $this->mSecureLoginUrl
) {
882 $secureLoginLink = Html
::element( 'a', [
883 'href' => $this->mSecureLoginUrl
,
884 'class' => 'mw-ui-flush-right mw-secure',
885 ], $this->msg( 'userlogin-signwithsecure' )->text() );
888 if ( $this->isSignup() ) {
889 $fieldDefinitions = [
891 'label-message' => 'userlogin-yourname',
892 // FIXME help-message does not match old formatting
893 'help-message' => 'createacct-helpusername',
895 'placeholder-message' => $isLoggedIn ?
'createacct-another-username-ph'
896 : 'userlogin-yourname-ph',
899 // create account without providing password, a temporary one will be mailed
901 'label-message' => 'createaccountmail',
902 'name' => 'wpCreateaccountMail',
903 'id' => 'wpCreateaccountMail',
906 'id' => 'wpPassword2',
907 'placeholder-message' => 'createacct-yourpassword-ph',
908 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
912 'baseField' => 'password',
913 'type' => 'password',
914 'label-message' => 'createacct-yourpasswordagain',
916 'cssclass' => 'loginPassword',
918 'validation-callback' => function ( $value, $alldata ) {
919 if ( empty( $alldata['mailpassword'] ) && !empty( $alldata['password'] ) ) {
921 return $this->msg( 'htmlform-required' );
922 } elseif ( $value !== $alldata['password'] ) {
923 return $this->msg( 'badretype' );
928 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
929 'placeholder-message' => 'createacct-yourpasswordagain-ph',
933 'label-message' => $wgEmailConfirmToEdit ?
'createacct-emailrequired'
934 : 'createacct-emailoptional',
936 'cssclass' => 'loginText',
938 // FIXME will break non-standard providers
939 'required' => $wgEmailConfirmToEdit,
940 'validation-callback' => function ( $value, $alldata ) {
941 global $wgEmailConfirmToEdit;
943 // AuthManager will check most of these, but that will make the auth
944 // session fail and this won't, so nicer to do it this way
945 if ( !$value && $wgEmailConfirmToEdit ) {
946 // no point in allowing registration without email when email is
948 return $this->msg( 'noemailtitle' );
949 } elseif ( !$value && !empty( $alldata['mailpassword'] ) ) {
950 // cannot send password via email when there is no email address
951 return $this->msg( 'noemailcreate' );
952 } elseif ( $value && !Sanitizer
::validateEmail( $value ) ) {
953 return $this->msg( 'invalidemailaddress' );
957 'placeholder-message' => 'createacct-' . $anotherPart . 'email-ph',
961 'help-message' => $isLoggedIn ?
'createacct-another-realname-tip'
962 : 'prefs-help-realname',
963 'label-message' => 'createacct-realname',
964 'cssclass' => 'loginText',
966 'id' => 'wpRealName',
969 // comment for the user creation log
971 'label-message' => 'createacct-reason',
972 'cssclass' => 'loginText',
975 'placeholder-message' => 'createacct-reason-ph',
977 'extrainput' => [], // placeholder for fields coming from the template
981 'default' => $this->msg( 'createacct-' . $anotherPart . $continuePart .
983 'name' => 'wpCreateaccount',
984 'id' => 'wpCreateaccount',
989 $fieldDefinitions = [
991 'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $secureLoginLink,
993 'placeholder-message' => 'userlogin-yourname-ph',
996 'id' => 'wpPassword1',
997 'placeholder-message' => 'userlogin-yourpassword-ph',
1002 // option for saving the user token to a cookie
1004 'label-message' => $this->msg( 'userlogin-remembermypassword' )
1005 ->numParams( $expirationDays ),
1006 'id' => 'wpRemember',
1011 'name' => 'wpRemember',
1012 'default' => $this->msg( 'pt-login-' . $continuePart . 'button' )->text(),
1013 'id' => 'wpLoginAttempt',
1016 'linkcontainer' => [
1019 'cssclass' => 'mw-form-related-link-container mw-userlogin-help',
1020 // 'id' => 'mw-userlogin-help', // FIXME HTMLInfoField ignores this
1022 'default' => Html
::element( 'a', [
1023 'href' => Skin
::makeInternalOrExternalUrl( wfMessage( 'helplogin-url' )
1024 ->inContentLanguage()
1026 ], $this->msg( 'userlogin-helplink2' )->text() ),
1031 $fieldDefinitions['username'] +
= [
1034 'cssclass' => 'loginText',
1036 // 'required' => true,
1038 $fieldDefinitions['password'] +
= [
1039 'type' => 'password',
1040 // 'label-message' => 'userlogin-yourpassword', // would override the changepassword label
1041 'name' => 'wpPassword',
1042 'cssclass' => 'loginPassword',
1044 // 'required' => true,
1047 if ( $this->mEntryError
) {
1048 $fieldDefinitions['entryError'] = [
1050 'default' => Html
::rawElement( 'div', [ 'class' => $this->mEntryErrorType
. 'box', ],
1051 $this->mEntryError
),
1058 if ( !$this->showExtraInformation() ) {
1059 unset( $fieldDefinitions['linkcontainer'] );
1062 $fieldDefinitions = $this->getBCFieldDefinitions( $fieldDefinitions, $template );
1063 $fieldDefinitions = array_filter( $fieldDefinitions );
1065 return $fieldDefinitions;
1069 * Adds fields provided via the deprecated UserLoginForm / UserCreateForm hooks
1070 * @param $fieldDefinitions array
1071 * @param FakeAuthTemplate $template
1074 protected function getBCFieldDefinitions( $fieldDefinitions, $template ) {
1075 if ( $template->get( 'usedomain', false ) ) {
1076 // TODO probably should be translated to the new domain notation in AuthManager
1077 $fieldDefinitions['domain'] = [
1079 'label-message' => 'yourdomainname',
1080 'options' => array_combine( $template->get( 'domainnames', [] ),
1081 $template->get( 'domainnames', [] ) ),
1082 'default' => $template->get( 'domain', '' ),
1083 'name' => 'wpDomain',
1084 // FIXME id => 'mw-user-domain-section' on the parent div
1088 // poor man's associative array_splice
1089 $extraInputPos = array_search( 'extrainput', array_keys( $fieldDefinitions ), true );
1090 $fieldDefinitions = array_slice( $fieldDefinitions, 0, $extraInputPos, true )
1091 +
$template->getExtraInputDefinitions()
1092 +
array_slice( $fieldDefinitions, $extraInputPos +
1, null, true );
1094 return $fieldDefinitions;
1098 * Check if a session cookie is present.
1100 * This will not pick up a cookie set during _this_ request, but is meant
1101 * to ensure that the client is returning the cookie which was set on a
1102 * previous pass through the system.
1106 protected function hasSessionCookie() {
1107 global $wgDisableCookieCheck, $wgInitialSessionId;
1109 return $wgDisableCookieCheck ||
(
1110 $wgInitialSessionId &&
1111 $this->getRequest()->getSession()->getId() === (string)$wgInitialSessionId
1116 * Returns a string that can be appended to the URL (without encoding) to preserve the
1117 * return target. Does not include leading '?'/'&'.
1119 protected function getReturnToQueryStringFragment() {
1121 if ( $this->mReturnTo
!== '' ) {
1122 $returnto = 'returnto=' . wfUrlencode( $this->mReturnTo
);
1123 if ( $this->mReturnToQuery
!== '' ) {
1124 $returnto .= '&returntoquery=' . wfUrlencode( $this->mReturnToQuery
);
1131 * Whether the login/create account form should display a link to the
1132 * other form (in addition to whatever the skin provides).
1135 private function showCreateAccountLink() {
1136 if ( $this->isSignup() ) {
1138 } elseif ( $this->getUser()->isAllowed( 'createaccount' ) ) {
1145 protected function getTokenName() {
1146 return $this->isSignup() ?
'wpCreateaccountToken' : 'wpLoginToken';
1150 * Produce a bar of links which allow the user to select another language
1151 * during login/registration but retain "returnto"
1155 protected function makeLanguageSelector() {
1156 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1157 if ( $msg->isBlank() ) {
1160 $langs = explode( "\n", $msg->text() );
1162 foreach ( $langs as $lang ) {
1163 $lang = trim( $lang, '* ' );
1164 $parts = explode( '|', $lang );
1165 if ( count( $parts ) >= 2 ) {
1166 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1170 return count( $links ) > 0 ?
$this->msg( 'loginlanguagelabel' )->rawParams(
1171 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1175 * Create a language selector link for a particular language
1176 * Links back to this page preserving type and returnto
1178 * @param string $text Link text
1179 * @param string $lang Language code
1182 protected function makeLanguageSelectorLink( $text, $lang ) {
1183 if ( $this->getLanguage()->getCode() == $lang ) {
1184 // no link for currently used language
1185 return htmlspecialchars( $text );
1187 $query = [ 'uselang' => $lang ];
1188 if ( $this->mReturnTo
!== '' ) {
1189 $query['returnto'] = $this->mReturnTo
;
1190 $query['returntoquery'] = $this->mReturnToQuery
;
1194 $targetLanguage = Language
::factory( $lang );
1195 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1197 return Linker
::linkKnown(
1198 $this->getPageTitle(),
1199 htmlspecialchars( $text ),
1205 protected function getGroupName() {
1210 * @param array $formDescriptor
1212 protected function postProcessFormDescriptor( &$formDescriptor ) {
1213 // Pre-fill username (if not creating an account, T46775).
1215 isset( $formDescriptor['username'] ) &&
1216 !isset( $formDescriptor['username']['default'] ) &&
1219 $user = $this->getUser();
1220 if ( $user->isLoggedIn() ) {
1221 $formDescriptor['username']['default'] = $user->getName();
1223 $formDescriptor['username']['default'] =
1224 $this->getRequest()->getSession()->suggestLoginUsername();
1228 // don't show a submit button if there is nothing to submit (i.e. the only form content
1229 // is other submit buttons, for redirect flows)
1230 if ( !$this->needsSubmitButton( $formDescriptor ) ) {
1231 unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] );
1234 if ( !$this->isSignup() ) {
1235 // FIXME HACK don't focus on non-empty field
1236 // maybe there should be an autofocus-if similar to hide-if?
1238 isset( $formDescriptor['username'] )
1239 && empty( $formDescriptor['username']['default'] )
1240 && !$this->getRequest()->getCheck( 'wpName' )
1242 $formDescriptor['username']['autofocus'] = true;
1243 } elseif ( isset( $formDescriptor['password'] ) ) {
1244 $formDescriptor['password']['autofocus'] = true;
1248 $this->addTabIndex( $formDescriptor );
1253 * B/C class to try handling login/signup template modifications even though login/signup does not
1254 * actually happen through a template anymore. Just collects extra field definitions and allows
1255 * some other class to do decide what to do with threm..
1256 * TODO find the right place for adding extra fields and kill this
1258 class FakeAuthTemplate
extends BaseTemplate
{
1259 public function execute() {
1260 throw new LogicException( 'not used' );
1264 * Extensions (AntiSpoof and TitleBlacklist) call this in response to
1265 * UserCreateForm hook to add checkboxes to the create account form.
1267 public function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
1268 // use the same indexes as UserCreateForm just in case someone adds an item manually
1269 $this->data
['extrainput'][] = [
1274 'helptext' => $helptext,
1279 * Turns addInputItem-style field definitions into HTMLForm field definitions.
1282 public function getExtraInputDefinitions() {
1285 foreach ( $this->get( 'extrainput', [] ) as $field ) {
1287 'type' => $field['type'] === 'checkbox' ?
'check' : $field['type'],
1288 'name' => $field['name'],
1289 'value' => $field['value'],
1290 'id' => $field['name'],
1292 if ( $field['msg'] ) {
1293 $definition['label-message'] = $this->getMsg( $field['msg'] );
1295 if ( $field['helptext'] ) {
1296 $definition['help'] = $this->msgWiki( $field['helptext'] );
1299 // the array key doesn't matter much when name is defined explicitly but
1300 // let's try and follow HTMLForm conventions
1301 $name = preg_replace( '/^wp(?=[A-Z])/', '', $field['name'] );
1302 $definitions[$name] = $definition;
1305 if ( $this->haveData( 'extrafields' ) ) {
1306 $definitions['extrafields'] = [
1309 'default' => $this->get( 'extrafields' ),
1313 return $definitions;
1318 * A horrible hack to handle AuthManager's feature flag. For other special pages this is done in
1319 * SpecialPageFactory, but LoginForm is used directly by some extensions. Will be killed as soon
1320 * as AuthManager is stable.
1322 class LoginForm
extends SpecialPage
{
1323 private $realLoginForm;
1325 public function __construct( $request = null ) {
1326 global $wgDisableAuthManager;
1327 if ( $wgDisableAuthManager ) {
1328 $this->realLoginForm
= new LoginFormPreAuthManager( $request );
1330 $this->realLoginForm
= new LoginFormAuthManager( $request );
1336 public function __get( $name ) {
1337 return $this->realLoginForm
->$name;
1340 public function __set( $name, $value ) {
1341 $this->realLoginForm
->$name = $value;
1344 public function __call( $name, $args ) {
1345 return call_user_func_array( [ $this->realLoginForm
, $name ], $args );
1348 public static function __callStatic( $name, $args ) {
1349 global $wgDisableAuthManager;
1350 return call_user_func_array( [ $wgDisableAuthManager ? LoginFormPreAuthManager
::class
1351 : LoginFormAuthManager
::class, $name ], $args );
1354 // all public SpecialPage methods need to be proxied explicitly
1356 public function getName() {
1357 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1359 public function getRestriction() {
1360 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1362 public function isListed() {
1363 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1365 public function setListed( $listed ) {
1366 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1368 public function listed( $x = null ) {
1369 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1371 public function isIncludable() {
1372 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1374 public function including( $x = null ) {
1375 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1377 public function getLocalName() {
1378 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1380 public function isExpensive() {
1381 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1383 public function isCached() {
1384 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1386 public function isRestricted() {
1387 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1389 public function userCanExecute( User
$user ) {
1390 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1392 public function displayRestrictionError() {
1393 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1395 public function checkPermissions() {
1396 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1398 public function checkReadOnly() {
1399 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1401 public function requireLogin(
1402 $reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin'
1404 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1406 public function prefixSearchSubpages( $search, $limit, $offset ) {
1407 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1409 public function execute( $subPage ) {
1410 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1412 public function getDescription() {
1413 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1415 function getTitle( $subpage = false ) {
1416 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1418 function getPageTitle( $subpage = false ) {
1419 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1421 public function setContext( $context ) {
1422 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1424 public function getContext() {
1425 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1427 public function getRequest() {
1428 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1430 public function getOutput() {
1431 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1433 public function getUser() {
1434 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1436 public function getSkin() {
1437 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1439 public function getLanguage() {
1440 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1442 public function getConfig() {
1443 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1445 public function getFullTitle() {
1446 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1448 public function getFinalGroupName() {
1449 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1451 public function doesWrites() {
1452 return call_user_func_array( [ $this->realLoginForm
, __FUNCTION__
], func_get_args() );
1455 // no way to proxy constants and static properties
1460 const WRONG_PLUGIN_PASS
= 3;
1461 const NOT_EXISTS
= 4;
1462 const WRONG_PASS
= 5;
1463 const EMPTY_PASS
= 6;
1464 const RESET_PASS
= 7;
1466 const CREATE_BLOCKED
= 9;
1467 const THROTTLED
= 10;
1468 const USER_BLOCKED
= 11;
1469 const NEED_TOKEN
= 12;
1470 const WRONG_TOKEN
= 13;
1471 const USER_MIGRATED
= 14;
1473 public static $statusCodes = [
1474 self
::SUCCESS
=> 'success',
1475 self
::NO_NAME
=> 'no_name',
1476 self
::ILLEGAL
=> 'illegal',
1477 self
::WRONG_PLUGIN_PASS
=> 'wrong_plugin_pass',
1478 self
::NOT_EXISTS
=> 'not_exists',
1479 self
::WRONG_PASS
=> 'wrong_pass',
1480 self
::EMPTY_PASS
=> 'empty_pass',
1481 self
::RESET_PASS
=> 'reset_pass',
1482 self
::ABORTED
=> 'aborted',
1483 self
::CREATE_BLOCKED
=> 'create_blocked',
1484 self
::THROTTLED
=> 'throttled',
1485 self
::USER_BLOCKED
=> 'user_blocked',
1486 self
::NEED_TOKEN
=> 'need_token',
1487 self
::WRONG_TOKEN
=> 'wrong_token',
1488 self
::USER_MIGRATED
=> 'user_migrated',
1491 public static $validErrorMessages = [
1492 'exception-nologin-text',
1493 'watchlistanontext',
1494 'changeemail-no-info',
1495 'resetpass-no-info',
1496 'confirmemail_needlogin',
1497 'prefsnologintext2',
1502 * LoginForm as a special page has been replaced by SpecialUserLogin and SpecialCreateAccount,
1503 * but some extensions called its public methods directly, so the class is retained as a
1504 * B/C wrapper. Anything that used it before should use AuthManager instead.
1506 class LoginFormAuthManager
extends SpecialPage
{
1510 const WRONG_PLUGIN_PASS
= 3;
1511 const NOT_EXISTS
= 4;
1512 const WRONG_PASS
= 5;
1513 const EMPTY_PASS
= 6;
1514 const RESET_PASS
= 7;
1516 const CREATE_BLOCKED
= 9;
1517 const THROTTLED
= 10;
1518 const USER_BLOCKED
= 11;
1519 const NEED_TOKEN
= 12;
1520 const WRONG_TOKEN
= 13;
1521 const USER_MIGRATED
= 14;
1523 public static $statusCodes = [
1524 self
::SUCCESS
=> 'success',
1525 self
::NO_NAME
=> 'no_name',
1526 self
::ILLEGAL
=> 'illegal',
1527 self
::WRONG_PLUGIN_PASS
=> 'wrong_plugin_pass',
1528 self
::NOT_EXISTS
=> 'not_exists',
1529 self
::WRONG_PASS
=> 'wrong_pass',
1530 self
::EMPTY_PASS
=> 'empty_pass',
1531 self
::RESET_PASS
=> 'reset_pass',
1532 self
::ABORTED
=> 'aborted',
1533 self
::CREATE_BLOCKED
=> 'create_blocked',
1534 self
::THROTTLED
=> 'throttled',
1535 self
::USER_BLOCKED
=> 'user_blocked',
1536 self
::NEED_TOKEN
=> 'need_token',
1537 self
::WRONG_TOKEN
=> 'wrong_token',
1538 self
::USER_MIGRATED
=> 'user_migrated',
1542 * @param WebRequest $request
1544 public function __construct( $request = null ) {
1545 wfDeprecated( 'LoginForm', '1.27' );
1546 parent
::__construct();
1550 * @deprecated since 1.27 - call LoginHelper::getValidErrorMessages instead.
1552 public static function getValidErrorMessages() {
1553 return LoginHelper
::getValidErrorMessages();
1557 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1559 public static function incrementLoginThrottle( $username ) {
1560 wfDeprecated( __METHOD__
, "1.27" );
1562 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1563 $throttler = new Throttler();
1564 return $throttler->increase( $username, $wgRequest->getIP(), __METHOD__
);
1568 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1570 public static function incLoginThrottle( $username ) {
1571 wfDeprecated( __METHOD__
, "1.27" );
1572 $res = self
::incrementLoginThrottle( $username );
1573 return is_array( $res ) ?
true : 0;
1577 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1579 public static function clearLoginThrottle( $username ) {
1580 wfDeprecated( __METHOD__
, "1.27" );
1582 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1583 $throttler = new Throttler();
1584 return $throttler->clear( $username, $wgRequest->getIP() );
1588 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1590 public static function getLoginToken() {
1591 wfDeprecated( __METHOD__
, '1.27' );
1593 return $wgRequest->getSession()->getToken( '', 'login' )->toString();
1597 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1599 public static function setLoginToken() {
1600 wfDeprecated( __METHOD__
, '1.27' );
1604 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1606 public static function clearLoginToken() {
1607 wfDeprecated( __METHOD__
, '1.27' );
1609 $wgRequest->getSession()->resetToken( 'login' );
1613 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1615 public static function getCreateaccountToken() {
1616 wfDeprecated( __METHOD__
, '1.27' );
1618 return $wgRequest->getSession()->getToken( '', 'createaccount' )->toString();
1622 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1624 public static function setCreateaccountToken() {
1625 wfDeprecated( __METHOD__
, '1.27' );
1629 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1631 public static function clearCreateaccountToken() {
1632 wfDeprecated( __METHOD__
, '1.27' );
1634 $wgRequest->getSession()->resetToken( 'createaccount' );