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
;
32 * Holds shared logic for login and account creation pages.
34 * @ingroup SpecialPage
36 abstract class LoginSignupSpecialPage
extends AuthManagerSpecialPage
{
41 protected $mReturnToQuery;
43 protected $mStickHTTPS;
45 protected $mEntryError = '';
46 protected $mEntryErrorType = 'error';
48 protected $mLoaded = false;
49 protected $mLoadedRequest = 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;
92 protected function setRequest( array $data, $wasPosted = null ) {
93 parent
::setRequest( $data, $wasPosted );
94 $this->mLoadedRequest
= false;
98 * Load basic request parameters for this Special page.
101 private function loadRequestParameters( $subPage ) {
102 if ( $this->mLoadedRequest
) {
105 $this->mLoadedRequest
= true;
106 $request = $this->getRequest();
108 $this->mPosted
= $request->wasPosted();
109 $this->mIsReturn
= $subPage === 'return';
110 $this->mAction
= $request->getVal( 'action' );
111 $this->mFromHTTP
= $request->getBool( 'fromhttp', false )
112 ||
$request->getBool( 'wpFromhttp', false );
113 $this->mStickHTTPS
= ( !$this->mFromHTTP
&& $request->getProtocol() === 'https' )
114 ||
$request->getBool( 'wpForceHttps', false );
115 $this->mLanguage
= $request->getText( 'uselang' );
116 $this->mReturnTo
= $request->getVal( 'returnto', '' );
117 $this->mReturnToQuery
= $request->getVal( 'returntoquery', '' );
121 * Load data from request.
123 * @param string $subPage Subpage of Special:Userlogin
125 protected function load( $subPage ) {
126 global $wgSecureLogin;
128 $this->loadRequestParameters( $subPage );
129 if ( $this->mLoaded
) {
132 $this->mLoaded
= true;
133 $request = $this->getRequest();
135 $securityLevel = $this->getRequest()->getText( 'force' );
137 $securityLevel && AuthManager
::singleton()->securitySensitiveOperationStatus(
138 $securityLevel ) === AuthManager
::SEC_REAUTH
140 $this->securityLevel
= $securityLevel;
143 $this->loadAuth( $subPage );
145 $this->mToken
= $request->getVal( $this->getTokenName() );
147 // Show an error or warning passed on from a previous page
148 $entryError = $this->msg( $request->getVal( 'error', '' ) );
149 $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
150 // bc: provide login link as a parameter for messages where the translation
152 $loginreqlink = Linker
::linkKnown(
153 $this->getPageTitle(),
154 $this->msg( 'loginreqlink' )->escaped(),
157 'returnto' => $this->mReturnTo
,
158 'returntoquery' => $this->mReturnToQuery
,
159 'uselang' => $this->mLanguage
,
160 'fromhttp' => $wgSecureLogin && $this->mFromHTTP ?
'1' : null,
164 // Only show valid error or warning messages.
165 if ( $entryError->exists()
166 && in_array( $entryError->getKey(), LoginHelper
::getValidErrorMessages(), true )
168 $this->mEntryErrorType
= 'error';
169 $this->mEntryError
= $entryError->rawParams( $loginreqlink )->parse();
171 } elseif ( $entryWarning->exists()
172 && in_array( $entryWarning->getKey(), LoginHelper
::getValidErrorMessages(), true )
174 $this->mEntryErrorType
= 'warning';
175 $this->mEntryError
= $entryWarning->rawParams( $loginreqlink )->parse();
178 # 1. When switching accounts, it sucks to get automatically logged out
179 # 2. Do not return to PasswordReset after a successful password change
180 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
181 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
182 if ( is_object( $returnToTitle )
183 && ( $returnToTitle->isSpecial( 'Userlogout' )
184 ||
$returnToTitle->isSpecial( 'PasswordReset' ) )
186 $this->mReturnTo
= '';
187 $this->mReturnToQuery
= '';
191 protected function getPreservedParams( $withToken = false ) {
192 global $wgSecureLogin;
194 $params = parent
::getPreservedParams( $withToken );
196 'returnto' => $this->mReturnTo ?
: null,
197 'returntoquery' => $this->mReturnToQuery ?
: null,
199 if ( $wgSecureLogin && !$this->isSignup() ) {
200 $params['fromhttp'] = $this->mFromHTTP ?
'1' : null;
205 protected function beforeExecute( $subPage ) {
206 // finish initializing the class before processing the request - T135924
207 $this->loadRequestParameters( $subPage );
208 return parent
::beforeExecute( $subPage );
212 * @param string|null $subPage
214 public function execute( $subPage ) {
215 $authManager = AuthManager
::singleton();
216 $session = SessionManager
::getGlobalSession();
218 // Session data is used for various things in the authentication process, so we must make
219 // sure a session cookie or some equivalent mechanism is set.
222 $this->load( $subPage );
224 $this->checkPermissions();
226 // Make sure it's possible to log in
227 if ( !$this->isSignup() && !$session->canSetUser() ) {
228 throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
229 $session->getProvider()->describe( RequestContext
::getMain()->getLanguage() )
234 * In the case where the user is already logged in, and was redirected to
235 * the login form from a page that requires login, do not show the login
236 * page. The use case scenario for this is when a user opens a large number
237 * of tabs, is redirected to the login page on all of them, and then logs
238 * in on one, expecting all the others to work properly.
240 * However, do show the form if it was visited intentionally (no 'returnto'
241 * is present). People who often switch between several accounts have grown
242 * accustomed to this behavior.
244 * Also make an exception when force=<level> is set in the URL, which means the user must
245 * reauthenticate for security reasons.
247 if ( !$this->isSignup() && !$this->mPosted
&& !$this->securityLevel
&&
248 ( $this->mReturnTo
!== '' ||
$this->mReturnToQuery
!== '' ) &&
249 $this->getUser()->isLoggedIn()
251 $this->successfulAction();
254 // If logging in and not on HTTPS, either redirect to it or offer a link.
255 global $wgSecureLogin;
256 if ( $this->getRequest()->getProtocol() !== 'https' ) {
257 $title = $this->getFullTitle();
258 $query = $this->getPreservedParams( false ) +
[
260 ( $this->mEntryErrorType
=== 'error' ?
'error'
261 : 'warning' ) => $this->mEntryError
,
262 ] +
$this->getRequest()->getQueryValues();
263 $url = $title->getFullURL( $query, false, PROTO_HTTPS
);
264 if ( $wgSecureLogin && !$this->mFromHTTP
&&
265 wfCanIPUseHTTPS( $this->getRequest()->getIP() )
267 // Avoid infinite redirect
268 $url = wfAppendQuery( $url, 'fromhttp=1' );
269 $this->getOutput()->redirect( $url );
270 // Since we only do this redir to change proto, always vary
271 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
275 // A wiki without HTTPS login support should set $wgServer to
276 // http://somehost, in which case the secure URL generated
277 // above won't actually start with https://
278 if ( substr( $url, 0, 8 ) === 'https://' ) {
279 $this->mSecureLoginUrl
= $url;
284 if ( !$this->isActionAllowed( $this->authAction
) ) {
285 // FIXME how do we explain this to the user? can we handle session loss better?
286 // messages used: authpage-cannot-login, authpage-cannot-login-continue,
287 // authpage-cannot-create, authpage-cannot-create-continue
288 $this->mainLoginForm( [], 'authpage-cannot-' . $this->authAction
);
292 $status = $this->trySubmit();
294 if ( !$status ||
!$status->isGood() ) {
295 $this->mainLoginForm( $this->authRequests
, $status ?
$status->getMessage() : '', 'error' );
299 /** @var AuthenticationResponse $response */
300 $response = $status->getValue();
302 $returnToUrl = $this->getPageTitle( 'return' )
303 ->getFullURL( $this->getPreservedParams( true ), false, PROTO_HTTPS
);
304 switch ( $response->status
) {
305 case AuthenticationResponse
::PASS
:
306 $this->logAuthResult( true );
307 $this->proxyAccountCreation
= $this->isSignup() && !$this->getUser()->isAnon();
308 $this->targetUser
= User
::newFromName( $response->username
);
311 !$this->proxyAccountCreation
312 && $response->loginRequest
313 && $authManager->canAuthenticateNow()
315 // successful registration; log the user in instantly
316 $response2 = $authManager->beginAuthentication( [ $response->loginRequest
],
318 if ( $response2->status
!== AuthenticationResponse
::PASS
) {
319 LoggerFactory
::getInstance( 'login' )
320 ->error( 'Could not log in after account creation' );
321 $this->successfulAction( true, Status
::newFatal( 'createacct-loginerror' ) );
326 if ( !$this->proxyAccountCreation
) {
327 // Ensure that the context user is the same as the session user.
328 $this->setSessionUserForCurrentRequest();
331 $this->successfulAction( true );
333 case AuthenticationResponse
::FAIL
:
335 case AuthenticationResponse
::RESTART
:
336 unset( $this->authForm
);
337 if ( $response->status
=== AuthenticationResponse
::FAIL
) {
338 $action = $this->getDefaultAction( $subPage );
339 $messageType = 'error';
341 $action = $this->getContinueAction( $this->authAction
);
342 $messageType = 'warning';
344 $this->logAuthResult( false, $response->message ?
$response->message
->getKey() : '-' );
345 $this->loadAuth( $subPage, $action, true );
346 $this->mainLoginForm( $this->authRequests
, $response->message
, $messageType );
348 case AuthenticationResponse
::REDIRECT
:
349 unset( $this->authForm
);
350 $this->getOutput()->redirect( $response->redirectTarget
);
352 case AuthenticationResponse
::UI
:
353 unset( $this->authForm
);
354 $this->authAction
= $this->isSignup() ? AuthManager
::ACTION_CREATE_CONTINUE
355 : AuthManager
::ACTION_LOGIN_CONTINUE
;
356 $this->authRequests
= $response->neededRequests
;
357 $this->mainLoginForm( $response->neededRequests
, $response->message
, $response->messageType
);
360 throw new LogicException( 'invalid AuthenticationResponse' );
365 * Show the success page.
367 * @param string $type Condition of return to; see `executeReturnTo`
368 * @param string|Message $title Page's title
369 * @param string $msgname
370 * @param string $injected_html
371 * @param StatusValue|null $extraMessages
373 protected function showSuccessPage(
374 $type, $title, $msgname, $injected_html, $extraMessages
376 $out = $this->getOutput();
377 $out->setPageTitle( $title );
379 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
381 if ( $extraMessages ) {
382 $extraMessages = Status
::wrap( $extraMessages );
383 $out->addWikiText( $extraMessages->getWikiText() );
386 $out->addHTML( $injected_html );
388 $helper = new LoginHelper( $this->getContext() );
389 $helper->showReturnToPage( $type, $this->mReturnTo
, $this->mReturnToQuery
, $this->mStickHTTPS
);
393 * Add a "return to" link or redirect to it.
394 * Extensions can use this to reuse the "return to" logic after
395 * inject steps (such as redirection) into the login process.
397 * @param string $type One of the following:
398 * - error: display a return to link ignoring $wgRedirectOnLogin
399 * - signup: display a return to link using $wgRedirectOnLogin if needed
400 * - success: display a return to link using $wgRedirectOnLogin if needed
401 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
402 * @param string $returnTo
403 * @param array|string $returnToQuery
404 * @param bool $stickHTTPS Keep redirect link on HTTPS
407 public function showReturnToPage(
408 $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
410 $helper = new LoginHelper( $this->getContext() );
411 $helper->showReturnToPage( $type, $returnTo, $returnToQuery, $stickHTTPS );
415 * Replace some globals to make sure the fact that the user has just been logged in is
416 * reflected in the current request.
419 protected function setSessionUserForCurrentRequest() {
420 global $wgUser, $wgLang;
422 $context = RequestContext
::getMain();
423 $localContext = $this->getContext();
424 if ( $context !== $localContext ) {
425 // remove AuthManagerSpecialPage context hack
426 $this->setContext( $context );
429 $user = $context->getRequest()->getSession()->getUser();
432 $context->setUser( $user );
434 $code = $this->getRequest()->getVal( 'uselang', $user->getOption( 'language' ) );
435 $userLang = Language
::factory( $code );
437 $context->setLanguage( $userLang );
441 * @param AuthenticationRequest[] $requests A list of AuthorizationRequest objects,
442 * used to generate the form fields. An empty array means a fatal error
443 * (authentication cannot continue).
444 * @param string|Message $msg
445 * @param string $msgtype
446 * @throws ErrorPageError
449 * @throws MWException
450 * @throws PermissionsError
451 * @throws ReadOnlyError
454 protected function mainLoginForm( array $requests, $msg = '', $msgtype = 'error' ) {
455 $titleObj = $this->getPageTitle();
456 $user = $this->getUser();
457 $out = $this->getOutput();
459 // FIXME how to handle empty $requests - restart, or no form, just an error message?
460 // no form would be better for no session type errors, restart is better when can* fails.
462 $this->authAction
= $this->getDefaultAction( $this->subPage
);
463 $this->authForm
= null;
464 $requests = AuthManager
::singleton()->getAuthenticationRequests( $this->authAction
, $user );
467 // Generic styles and scripts for both login and signup form
468 $out->addModuleStyles( [
470 'mediawiki.ui.button',
471 'mediawiki.ui.checkbox',
472 'mediawiki.ui.input',
473 'mediawiki.special.userlogin.common.styles'
475 if ( $this->isSignup() ) {
476 // XXX hack pending RL or JS parse() support for complex content messages T27349
477 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
478 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
480 // Additional styles and scripts for signup form
482 'mediawiki.special.userlogin.signup.js'
484 $out->addModuleStyles( [
485 'mediawiki.special.userlogin.signup.styles'
488 // Additional styles for login form
489 $out->addModuleStyles( [
490 'mediawiki.special.userlogin.login.styles'
493 $out->disallowUserJs(); // just in case...
495 $form = $this->getAuthForm( $requests, $this->authAction
, $msg, $msgtype );
496 $form->prepareForm();
497 $submitStatus = Status
::newGood();
498 if ( $msg && $msgtype === 'warning' ) {
499 $submitStatus->warning( $msg );
500 } elseif ( $msg && $msgtype === 'error' ) {
501 $submitStatus->fatal( $msg );
503 $formHtml = $form->getHTML( $submitStatus );
505 $out->addHTML( $this->getPageHtml( $formHtml ) );
509 * Add page elements which are outside the form.
510 * FIXME this should probably be a template, but use a sane language (handlebars?)
511 * @param string $formHtml
514 protected function getPageHtml( $formHtml ) {
515 global $wgLoginLanguageSelector;
517 $loginPrompt = $this->isSignup() ?
'' : Html
::rawElement( 'div',
518 [ 'id' => 'userloginprompt' ], $this->msg( 'loginprompt' )->parseAsBlock() );
519 $languageLinks = $wgLoginLanguageSelector ?
$this->makeLanguageSelector() : '';
520 $signupStartMsg = $this->msg( 'signupstart' );
521 $signupStart = ( $this->isSignup() && !$signupStartMsg->isDisabled() )
522 ? Html
::rawElement( 'div', [ 'id' => 'signupstart' ], $signupStartMsg->parseAsBlock() ) : '';
523 if ( $languageLinks ) {
524 $languageLinks = Html
::rawElement( 'div', [ 'id' => 'languagelinks' ],
525 Html
::rawElement( 'p', [], $languageLinks )
529 $benefitsContainer = '';
530 if ( $this->isSignup() && $this->showExtraInformation() ) {
532 // createacct-benefit-icon1 createacct-benefit-head1 createacct-benefit-body1
533 // createacct-benefit-icon2 createacct-benefit-head2 createacct-benefit-body2
534 // createacct-benefit-icon3 createacct-benefit-head3 createacct-benefit-body3
537 for ( $benefitIdx = 1; $benefitIdx <= $benefitCount; $benefitIdx++
) {
538 $headUnescaped = $this->msg( "createacct-benefit-head$benefitIdx" )->text();
539 $iconClass = $this->msg( "createacct-benefit-icon$benefitIdx" )->escaped();
540 $benefitList .= Html
::rawElement( 'div', [ 'class' => "mw-number-text $iconClass" ],
541 Html
::rawElement( 'h3', [],
542 $this->msg( "createacct-benefit-head$benefitIdx" )->escaped()
544 . Html
::rawElement( 'p', [],
545 $this->msg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped()
549 $benefitsContainer = Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-container' ],
550 Html
::rawElement( 'h2', [], $this->msg( 'createacct-benefit-heading' )->escaped() )
551 . Html
::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-list' ],
557 $html = Html
::rawElement( 'div', [ 'class' => 'mw-ui-container' ],
561 . Html
::rawElement( 'div', [ 'id' => 'userloginForm' ],
571 * Generates a form from the given request.
572 * @param AuthenticationRequest[] $requests
573 * @param string $action AuthManager action name
574 * @param string|Message $msg
575 * @param string $msgType
578 protected function getAuthForm( array $requests, $action, $msg = '', $msgType = 'error' ) {
579 global $wgSecureLogin, $wgLoginLanguageSelector;
580 // FIXME merge this with parent
582 if ( isset( $this->authForm
) ) {
583 return $this->authForm
;
586 $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
588 // get basic form description from the auth logic
589 $fieldInfo = AuthenticationRequest
::mergeFieldInfo( $requests );
590 $fakeTemplate = $this->getFakeTemplate( $msg, $msgType );
591 $this->fakeTemplate
= $fakeTemplate; // FIXME there should be a saner way to pass this to the hook
592 // this will call onAuthChangeFormFields()
593 $formDescriptor = static::fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction
);
594 $this->postProcessFormDescriptor( $formDescriptor, $requests );
596 $context = $this->getContext();
597 if ( $context->getRequest() !== $this->getRequest() ) {
598 // We have overridden the request, need to make sure the form uses that too.
599 $context = new DerivativeContext( $this->getContext() );
600 $context->setRequest( $this->getRequest() );
602 $form = HTMLForm
::factory( 'vform', $formDescriptor, $context );
604 $form->addHiddenField( 'authAction', $this->authAction
);
605 if ( $wgLoginLanguageSelector ) {
606 $form->addHiddenField( 'uselang', $this->mLanguage
);
608 $form->addHiddenField( 'force', $this->securityLevel
);
609 $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() );
610 if ( $wgSecureLogin ) {
611 // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
612 if ( !$this->isSignup() ) {
613 $form->addHiddenField( 'wpForceHttps', (int)$this->mStickHTTPS
);
614 $form->addHiddenField( 'wpFromhttp', $usingHTTPS );
618 // set properties of the form itself
619 $form->setAction( $this->getPageTitle()->getLocalURL( $this->getReturnToQueryStringFragment() ) );
620 $form->setName( 'userlogin' . ( $this->isSignup() ?
'2' : '' ) );
621 if ( $this->isSignup() ) {
622 $form->setId( 'userlogin2' );
625 // warning header for non-standard workflows (e.g. security reauthentication)
626 if ( !$this->isSignup() && $this->getUser()->isLoggedIn() ) {
627 $reauthMessage = $this->securityLevel ?
'userlogin-reauth' : 'userlogin-loggedin';
628 $form->addHeaderText( Html
::rawElement( 'div', [ 'class' => 'warningbox' ],
629 $this->msg( $reauthMessage )->params( $this->getUser()->getName() )->parse() ) );
632 $form->suppressDefaultSubmit();
634 $this->authForm
= $form;
640 * Temporary B/C method to handle extensions using the UserLoginForm/UserCreateForm hooks.
641 * @param string|Message $msg
642 * @param string $msgType
643 * @return FakeAuthTemplate
645 protected function getFakeTemplate( $msg, $msgType ) {
646 global $wgAuth, $wgEnableEmail, $wgHiddenPrefs, $wgEmailConfirmToEdit, $wgEnableUserEmail,
647 $wgSecureLogin, $wgLoginLanguageSelector, $wgPasswordResetRoutes;
649 // make a best effort to get the value of fields which used to be fixed in the old login
650 // template but now might or might not exist depending on what providers are used
651 $request = $this->getRequest();
653 'mUsername' => $request->getText( 'wpName' ),
654 'mPassword' => $request->getText( 'wpPassword' ),
655 'mRetype' => $request->getText( 'wpRetype' ),
656 'mEmail' => $request->getText( 'wpEmail' ),
657 'mRealName' => $request->getText( 'wpRealName' ),
658 'mDomain' => $request->getText( 'wpDomain' ),
659 'mReason' => $request->getText( 'wpReason' ),
660 'mRemember' => $request->getCheck( 'wpRemember' ),
663 // Preserves a bunch of logic from the old code that was rewritten in getAuthForm().
664 // There is no code reuse to make this easier to remove .
665 // If an extension tries to change any of these values, they are out of luck - we only
666 // actually use the domain/usedomain/domainnames, extraInput and extrafields keys.
668 $titleObj = $this->getPageTitle();
669 $user = $this->getUser();
670 $template = new FakeAuthTemplate();
672 // Pre-fill username (if not creating an account, bug 44775).
673 if ( $data->mUsername
== '' && $this->isSignup() ) {
674 if ( $user->isLoggedIn() ) {
675 $data->mUsername
= $user->getName();
677 $data->mUsername
= $this->getRequest()->getSession()->suggestLoginUsername();
681 if ( $this->isSignup() ) {
682 // Must match number of benefits defined in messages
683 $template->set( 'benefitCount', 3 );
685 $q = 'action=submitlogin&type=signup';
686 $linkq = 'type=login';
688 $q = 'action=submitlogin&type=login';
689 $linkq = 'type=signup';
692 if ( $this->mReturnTo
!== '' ) {
693 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
694 if ( $this->mReturnToQuery
!== '' ) {
695 $returnto .= '&returntoquery=' .
696 wfUrlencode( $this->mReturnToQuery
);
702 # Don't show a "create account" link if the user can't.
703 if ( $this->showCreateAccountLink() ) {
704 # Pass any language selection on to the mode switch link
705 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
706 $linkq .= '&uselang=' . $this->mLanguage
;
708 // Supply URL, login template creates the button.
709 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
711 $template->set( 'link', '' );
714 $resetLink = $this->isSignup()
716 : is_array( $wgPasswordResetRoutes )
717 && in_array( true, array_values( $wgPasswordResetRoutes ), true );
719 $template->set( 'header', '' );
720 $template->set( 'formheader', '' );
721 $template->set( 'skin', $this->getSkin() );
723 $template->set( 'name', $data->mUsername
);
724 $template->set( 'password', $data->mPassword
);
725 $template->set( 'retype', $data->mRetype
);
726 $template->set( 'createemailset', false ); // no easy way to get that from AuthManager
727 $template->set( 'email', $data->mEmail
);
728 $template->set( 'realname', $data->mRealName
);
729 $template->set( 'domain', $data->mDomain
);
730 $template->set( 'reason', $data->mReason
);
731 $template->set( 'remember', $data->mRemember
);
733 $template->set( 'action', $titleObj->getLocalURL( $q ) );
734 $template->set( 'message', $msg );
735 $template->set( 'messagetype', $msgType );
736 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
737 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs, true ) );
738 $template->set( 'useemail', $wgEnableEmail );
739 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
740 $template->set( 'emailothers', $wgEnableUserEmail );
741 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
742 $template->set( 'resetlink', $resetLink );
743 $template->set( 'canremember', $request->getSession()->getProvider()
744 ->getRememberUserDuration() !== null );
745 $template->set( 'usereason', $user->isLoggedIn() );
746 $template->set( 'cansecurelogin', ( $wgSecureLogin ) );
747 $template->set( 'stickhttps', (int)$this->mStickHTTPS
);
748 $template->set( 'loggedin', $user->isLoggedIn() );
749 $template->set( 'loggedinuser', $user->getName() );
750 $template->set( 'token', $this->getToken()->toString() );
752 $action = $this->isSignup() ?
'signup' : 'login';
753 $wgAuth->modifyUITemplate( $template, $action );
755 $oldTemplate = $template;
756 $hookName = $this->isSignup() ?
'UserCreateForm' : 'UserLoginForm';
757 Hooks
::run( $hookName, [ &$template ] );
758 if ( $oldTemplate !== $template ) {
759 wfDeprecated( "reference in $hookName hook", '1.27' );
766 public function onAuthChangeFormFields(
767 array $requests, array $fieldInfo, array &$formDescriptor, $action
769 $coreFieldDescriptors = $this->getFieldDefinitions( $this->fakeTemplate
);
770 $specialFields = array_merge( [ 'extraInput' ],
771 array_keys( $this->fakeTemplate
->getExtraInputDefinitions() ) );
773 // keep the ordering from getCoreFieldDescriptors() where there is no explicit weight
774 foreach ( $coreFieldDescriptors as $fieldName => $coreField ) {
775 $requestField = isset( $formDescriptor[$fieldName] ) ?
776 $formDescriptor[$fieldName] : [];
778 // remove everything that is not in the fieldinfo, is not marked as a supplemental field
779 // to something in the fieldinfo, is not B/C for the pre-AuthManager templates,
780 // and is not an info field or a submit button
782 !isset( $fieldInfo[$fieldName] )
784 !isset( $coreField['baseField'] )
785 ||
!isset( $fieldInfo[$coreField['baseField']] )
787 && !in_array( $fieldName, $specialFields, true )
789 !isset( $coreField['type'] )
790 ||
!in_array( $coreField['type'], [ 'submit', 'info' ], true )
793 $coreFieldDescriptors[$fieldName] = null;
797 // core message labels should always take priority
799 isset( $coreField['label'] )
800 ||
isset( $coreField['label-message'] )
801 ||
isset( $coreField['label-raw'] )
803 unset( $requestField['label'], $requestField['label-message'], $coreField['label-raw'] );
806 $coreFieldDescriptors[$fieldName] +
= $requestField;
809 $formDescriptor = array_filter( $coreFieldDescriptors +
$formDescriptor );
814 * Show extra information such as password recovery information, link from login to signup,
815 * CTA etc? Such information should only be shown on the "landing page", ie. when the user
816 * is at the first step of the authentication process.
819 protected function showExtraInformation() {
820 return $this->authAction
!== $this->getContinueAction( $this->authAction
)
821 && !$this->securityLevel
;
825 * Create a HTMLForm descriptor for the core login fields.
826 * @param FakeAuthTemplate $template B/C data (not used but needed by getBCFieldDefinitions)
829 protected function getFieldDefinitions( $template ) {
830 global $wgEmailConfirmToEdit, $wgLoginLanguageSelector;
832 $isLoggedIn = $this->getUser()->isLoggedIn();
833 $continuePart = $this->isContinued() ?
'continue-' : '';
834 $anotherPart = $isLoggedIn ?
'another-' : '';
835 $expiration = $this->getRequest()->getSession()->getProvider()->getRememberUserDuration();
836 $expirationDays = ceil( $expiration / ( 3600 * 24 ) );
837 $secureLoginLink = '';
838 if ( $this->mSecureLoginUrl
) {
839 $secureLoginLink = Html
::element( 'a', [
840 'href' => $this->mSecureLoginUrl
,
841 'class' => 'mw-ui-flush-right mw-secure',
842 ], $this->msg( 'userlogin-signwithsecure' )->text() );
844 $usernameHelpLink = '';
845 if ( !$this->msg( 'createacct-helpusername' )->isDisabled() ) {
846 $usernameHelpLink = Html
::rawElement( 'span', [
847 'class' => 'mw-ui-flush-right',
848 ], $this->msg( 'createacct-helpusername' )->parse() );
851 if ( $this->isSignup() ) {
852 $fieldDefinitions = [
854 // used by the mediawiki.special.userlogin.signup.js module for error display
855 // FIXME merge this with HTMLForm's normal status (error) area
858 'default' => Html
::element( 'div', [ 'id' => 'mw-createacct-status-area' ] ),
862 'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $usernameHelpLink,
864 'placeholder-message' => $isLoggedIn ?
'createacct-another-username-ph'
865 : 'userlogin-yourname-ph',
868 // create account without providing password, a temporary one will be mailed
870 'label-message' => 'createaccountmail',
871 'name' => 'wpCreateaccountMail',
872 'id' => 'wpCreateaccountMail',
875 'id' => 'wpPassword2',
876 'placeholder-message' => 'createacct-yourpassword-ph',
877 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
881 'baseField' => 'password',
882 'type' => 'password',
883 'label-message' => 'createacct-yourpasswordagain',
885 'cssclass' => 'loginPassword',
887 'validation-callback' => function ( $value, $alldata ) {
888 if ( empty( $alldata['mailpassword'] ) && !empty( $alldata['password'] ) ) {
890 return $this->msg( 'htmlform-required' );
891 } elseif ( $value !== $alldata['password'] ) {
892 return $this->msg( 'badretype' );
897 'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
898 'placeholder-message' => 'createacct-yourpasswordagain-ph',
902 'label-message' => $wgEmailConfirmToEdit ?
'createacct-emailrequired'
903 : 'createacct-emailoptional',
905 'cssclass' => 'loginText',
907 // FIXME will break non-standard providers
908 'required' => $wgEmailConfirmToEdit,
909 'validation-callback' => function ( $value, $alldata ) {
910 global $wgEmailConfirmToEdit;
912 // AuthManager will check most of these, but that will make the auth
913 // session fail and this won't, so nicer to do it this way
914 if ( !$value && $wgEmailConfirmToEdit ) {
915 // no point in allowing registration without email when email is
917 return $this->msg( 'noemailtitle' );
918 } elseif ( !$value && !empty( $alldata['mailpassword'] ) ) {
919 // cannot send password via email when there is no email address
920 return $this->msg( 'noemailcreate' );
921 } elseif ( $value && !Sanitizer
::validateEmail( $value ) ) {
922 return $this->msg( 'invalidemailaddress' );
926 'placeholder-message' => 'createacct-' . $anotherPart . 'email-ph',
930 'help-message' => $isLoggedIn ?
'createacct-another-realname-tip'
931 : 'prefs-help-realname',
932 'label-message' => 'createacct-realname',
933 'cssclass' => 'loginText',
935 'id' => 'wpRealName',
938 // comment for the user creation log
940 'label-message' => 'createacct-reason',
941 'cssclass' => 'loginText',
944 'placeholder-message' => 'createacct-reason-ph',
946 'extrainput' => [], // placeholder for fields coming from the template
950 'default' => $this->msg( 'createacct-' . $anotherPart . $continuePart .
952 'name' => 'wpCreateaccount',
953 'id' => 'wpCreateaccount',
958 $fieldDefinitions = [
960 'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $secureLoginLink,
962 'placeholder-message' => 'userlogin-yourname-ph',
965 'id' => 'wpPassword1',
966 'placeholder-message' => 'userlogin-yourpassword-ph',
971 // option for saving the user token to a cookie
973 'name' => 'wpRemember',
974 'label-message' => $this->msg( 'userlogin-remembermypassword' )
975 ->numParams( $expirationDays ),
976 'id' => 'wpRemember',
981 'default' => $this->msg( 'pt-login-' . $continuePart . 'button' )->text(),
982 'id' => 'wpLoginAttempt',
988 'cssclass' => 'mw-form-related-link-container mw-userlogin-help',
989 // 'id' => 'mw-userlogin-help', // FIXME HTMLInfoField ignores this
991 'default' => Html
::element( 'a', [
992 'href' => Skin
::makeInternalOrExternalUrl( wfMessage( 'helplogin-url' )
993 ->inContentLanguage()
995 ], $this->msg( 'userlogin-helplink2' )->text() ),
998 // button for ResetPasswordSecondaryAuthenticationProvider
1006 $fieldDefinitions['username'] +
= [
1009 'cssclass' => 'loginText',
1011 // 'required' => true,
1013 $fieldDefinitions['password'] +
= [
1014 'type' => 'password',
1015 // 'label-message' => 'userlogin-yourpassword', // would override the changepassword label
1016 'name' => 'wpPassword',
1017 'cssclass' => 'loginPassword',
1019 // 'required' => true,
1022 if ( $template->get( 'header' ) ||
$template->get( 'formheader' ) ) {
1023 // B/C for old extensions that haven't been converted to AuthManager (or have been
1024 // but somebody is using the old version) and still use templates via the
1025 // UserCreateForm/UserLoginForm hook.
1026 // 'header' used by ConfirmEdit, CondfirmAccount, Persona, WikimediaIncubator, SemanticSignup
1027 // 'formheader' used by MobileFrontend
1028 $fieldDefinitions['header'] = [
1031 'default' => $template->get( 'header' ) ?
: $template->get( 'formheader' ),
1035 if ( $this->mEntryError
) {
1036 $fieldDefinitions['entryError'] = [
1038 'default' => Html
::rawElement( 'div', [ 'class' => $this->mEntryErrorType
. 'box', ],
1039 $this->mEntryError
),
1045 if ( !$this->showExtraInformation() ) {
1046 unset( $fieldDefinitions['linkcontainer'], $fieldDefinitions['signupend'] );
1048 if ( $this->isSignup() && $this->showExtraInformation() ) {
1049 // blank signup footer for site customization
1050 // uses signupend-https for HTTPS requests if it's not blank, signupend otherwise
1051 $signupendMsg = $this->msg( 'signupend' );
1052 $signupendHttpsMsg = $this->msg( 'signupend-https' );
1053 if ( !$signupendMsg->isDisabled() ) {
1054 $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
1055 $signupendText = ( $usingHTTPS && !$signupendHttpsMsg->isBlank() )
1056 ?
$signupendHttpsMsg ->parse() : $signupendMsg->parse();
1057 $fieldDefinitions['signupend'] = [
1060 'default' => Html
::rawElement( 'div', [ 'id' => 'signupend' ], $signupendText ),
1065 if ( !$this->isSignup() && $this->showExtraInformation() ) {
1066 $passwordReset = new PasswordReset( $this->getConfig(), AuthManager
::singleton() );
1067 if ( $passwordReset->isAllowed( $this->getUser() ) ) {
1068 $fieldDefinitions['passwordReset'] = [
1071 'cssclass' => 'mw-form-related-link-container',
1072 'default' => Linker
::link(
1073 SpecialPage
::getTitleFor( 'PasswordReset' ),
1074 $this->msg( 'userlogin-resetpassword-link' )->escaped()
1080 // Don't show a "create account" link if the user can't.
1081 if ( $this->showCreateAccountLink() ) {
1082 // link to the other action
1083 $linkTitle = $this->getTitleFor( $this->isSignup() ?
'Userlogin' :'CreateAccount' );
1084 $linkq = $this->getReturnToQueryStringFragment();
1085 // Pass any language selection on to the mode switch link
1086 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
1087 $linkq .= '&uselang=' . $this->mLanguage
;
1089 $loggedIn = $this->getUser()->isLoggedIn();
1091 $fieldDefinitions['createOrLogin'] = [
1094 'linkQuery' => $linkq,
1095 'default' => function ( $params ) use ( $loggedIn, $linkTitle ) {
1096 return Html
::rawElement( 'div',
1097 [ 'id' => 'mw-createaccount' . ( !$loggedIn ?
'-cta' : '' ),
1098 'class' => ( $loggedIn ?
'mw-form-related-link-container' : 'mw-ui-vform-field' ) ],
1099 ( $loggedIn ?
'' : $this->msg( 'userlogin-noaccount' )->escaped() )
1100 . Html
::element( 'a',
1102 'id' => 'mw-createaccount-join' . ( $loggedIn ?
'-loggedin' : '' ),
1103 'href' => $linkTitle->getLocalURL( $params['linkQuery'] ),
1104 'class' => ( $loggedIn ?
'' : 'mw-ui-button' ),
1108 $loggedIn ?
'userlogin-createanother' : 'userlogin-joinproject'
1118 $fieldDefinitions = $this->getBCFieldDefinitions( $fieldDefinitions, $template );
1119 $fieldDefinitions = array_filter( $fieldDefinitions );
1121 return $fieldDefinitions;
1125 * Adds fields provided via the deprecated UserLoginForm / UserCreateForm hooks
1126 * @param $fieldDefinitions array
1127 * @param FakeAuthTemplate $template
1130 protected function getBCFieldDefinitions( $fieldDefinitions, $template ) {
1131 if ( $template->get( 'usedomain', false ) ) {
1132 // TODO probably should be translated to the new domain notation in AuthManager
1133 $fieldDefinitions['domain'] = [
1135 'label-message' => 'yourdomainname',
1136 'options' => array_combine( $template->get( 'domainnames', [] ),
1137 $template->get( 'domainnames', [] ) ),
1138 'default' => $template->get( 'domain', '' ),
1139 'name' => 'wpDomain',
1140 // FIXME id => 'mw-user-domain-section' on the parent div
1144 // poor man's associative array_splice
1145 $extraInputPos = array_search( 'extrainput', array_keys( $fieldDefinitions ), true );
1146 $fieldDefinitions = array_slice( $fieldDefinitions, 0, $extraInputPos, true )
1147 +
$template->getExtraInputDefinitions()
1148 +
array_slice( $fieldDefinitions, $extraInputPos +
1, null, true );
1150 return $fieldDefinitions;
1154 * Check if a session cookie is present.
1156 * This will not pick up a cookie set during _this_ request, but is meant
1157 * to ensure that the client is returning the cookie which was set on a
1158 * previous pass through the system.
1162 protected function hasSessionCookie() {
1163 global $wgDisableCookieCheck, $wgInitialSessionId;
1165 return $wgDisableCookieCheck ||
(
1166 $wgInitialSessionId &&
1167 $this->getRequest()->getSession()->getId() === (string)$wgInitialSessionId
1172 * Returns a string that can be appended to the URL (without encoding) to preserve the
1173 * return target. Does not include leading '?'/'&'.
1175 protected function getReturnToQueryStringFragment() {
1177 if ( $this->mReturnTo
!== '' ) {
1178 $returnto = 'returnto=' . wfUrlencode( $this->mReturnTo
);
1179 if ( $this->mReturnToQuery
!== '' ) {
1180 $returnto .= '&returntoquery=' . wfUrlencode( $this->mReturnToQuery
);
1187 * Whether the login/create account form should display a link to the
1188 * other form (in addition to whatever the skin provides).
1191 private function showCreateAccountLink() {
1192 if ( $this->isSignup() ) {
1194 } elseif ( $this->getUser()->isAllowed( 'createaccount' ) ) {
1201 protected function getTokenName() {
1202 return $this->isSignup() ?
'wpCreateaccountToken' : 'wpLoginToken';
1206 * Produce a bar of links which allow the user to select another language
1207 * during login/registration but retain "returnto"
1211 protected function makeLanguageSelector() {
1212 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1213 if ( $msg->isBlank() ) {
1216 $langs = explode( "\n", $msg->text() );
1218 foreach ( $langs as $lang ) {
1219 $lang = trim( $lang, '* ' );
1220 $parts = explode( '|', $lang );
1221 if ( count( $parts ) >= 2 ) {
1222 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1226 return count( $links ) > 0 ?
$this->msg( 'loginlanguagelabel' )->rawParams(
1227 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1231 * Create a language selector link for a particular language
1232 * Links back to this page preserving type and returnto
1234 * @param string $text Link text
1235 * @param string $lang Language code
1238 protected function makeLanguageSelectorLink( $text, $lang ) {
1239 if ( $this->getLanguage()->getCode() == $lang ) {
1240 // no link for currently used language
1241 return htmlspecialchars( $text );
1243 $query = [ 'uselang' => $lang ];
1244 if ( $this->mReturnTo
!== '' ) {
1245 $query['returnto'] = $this->mReturnTo
;
1246 $query['returntoquery'] = $this->mReturnToQuery
;
1250 $targetLanguage = Language
::factory( $lang );
1251 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1253 return Linker
::linkKnown(
1254 $this->getPageTitle(),
1255 htmlspecialchars( $text ),
1261 protected function getGroupName() {
1266 * @param array $formDescriptor
1268 protected function postProcessFormDescriptor( &$formDescriptor, $requests ) {
1269 // Pre-fill username (if not creating an account, T46775).
1271 isset( $formDescriptor['username'] ) &&
1272 !isset( $formDescriptor['username']['default'] ) &&
1275 $user = $this->getUser();
1276 if ( $user->isLoggedIn() ) {
1277 $formDescriptor['username']['default'] = $user->getName();
1279 $formDescriptor['username']['default'] =
1280 $this->getRequest()->getSession()->suggestLoginUsername();
1284 // don't show a submit button if there is nothing to submit (i.e. the only form content
1285 // is other submit buttons, for redirect flows)
1286 if ( !$this->needsSubmitButton( $requests ) ) {
1287 unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] );
1290 if ( !$this->isSignup() ) {
1291 // FIXME HACK don't focus on non-empty field
1292 // maybe there should be an autofocus-if similar to hide-if?
1294 isset( $formDescriptor['username'] )
1295 && empty( $formDescriptor['username']['default'] )
1296 && !$this->getRequest()->getCheck( 'wpName' )
1298 $formDescriptor['username']['autofocus'] = true;
1299 } elseif ( isset( $formDescriptor['password'] ) ) {
1300 $formDescriptor['password']['autofocus'] = true;
1304 $this->addTabIndex( $formDescriptor );
1309 * B/C class to try handling login/signup template modifications even though login/signup does not
1310 * actually happen through a template anymore. Just collects extra field definitions and allows
1311 * some other class to do decide what to do with threm..
1312 * TODO find the right place for adding extra fields and kill this
1314 class FakeAuthTemplate
extends BaseTemplate
{
1315 public function execute() {
1316 throw new LogicException( 'not used' );
1320 * Extensions (AntiSpoof and TitleBlacklist) call this in response to
1321 * UserCreateForm hook to add checkboxes to the create account form.
1323 public function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
1324 // use the same indexes as UserCreateForm just in case someone adds an item manually
1325 $this->data
['extrainput'][] = [
1330 'helptext' => $helptext,
1335 * Turns addInputItem-style field definitions into HTMLForm field definitions.
1338 public function getExtraInputDefinitions() {
1341 foreach ( $this->get( 'extrainput', [] ) as $field ) {
1343 'type' => $field['type'] === 'checkbox' ?
'check' : $field['type'],
1344 'name' => $field['name'],
1345 'value' => $field['value'],
1346 'id' => $field['name'],
1348 if ( $field['msg'] ) {
1349 $definition['label-message'] = $this->getMsg( $field['msg'] );
1351 if ( $field['helptext'] ) {
1352 $definition['help'] = $this->msgWiki( $field['helptext'] );
1355 // the array key doesn't matter much when name is defined explicitly but
1356 // let's try and follow HTMLForm conventions
1357 $name = preg_replace( '/^wp(?=[A-Z])/', '', $field['name'] );
1358 $definitions[$name] = $definition;
1361 if ( $this->haveData( 'extrafields' ) ) {
1362 $definitions['extrafields'] = [
1365 'default' => $this->get( 'extrafields' ),
1369 return $definitions;
1374 * LoginForm as a special page has been replaced by SpecialUserLogin and SpecialCreateAccount,
1375 * but some extensions called its public methods directly, so the class is retained as a
1376 * B/C wrapper. Anything that used it before should use AuthManager instead.
1378 class LoginForm
extends SpecialPage
{
1382 const WRONG_PLUGIN_PASS
= 3;
1383 const NOT_EXISTS
= 4;
1384 const WRONG_PASS
= 5;
1385 const EMPTY_PASS
= 6;
1386 const RESET_PASS
= 7;
1388 const CREATE_BLOCKED
= 9;
1389 const THROTTLED
= 10;
1390 const USER_BLOCKED
= 11;
1391 const NEED_TOKEN
= 12;
1392 const WRONG_TOKEN
= 13;
1393 const USER_MIGRATED
= 14;
1395 public static $statusCodes = [
1396 self
::SUCCESS
=> 'success',
1397 self
::NO_NAME
=> 'no_name',
1398 self
::ILLEGAL
=> 'illegal',
1399 self
::WRONG_PLUGIN_PASS
=> 'wrong_plugin_pass',
1400 self
::NOT_EXISTS
=> 'not_exists',
1401 self
::WRONG_PASS
=> 'wrong_pass',
1402 self
::EMPTY_PASS
=> 'empty_pass',
1403 self
::RESET_PASS
=> 'reset_pass',
1404 self
::ABORTED
=> 'aborted',
1405 self
::CREATE_BLOCKED
=> 'create_blocked',
1406 self
::THROTTLED
=> 'throttled',
1407 self
::USER_BLOCKED
=> 'user_blocked',
1408 self
::NEED_TOKEN
=> 'need_token',
1409 self
::WRONG_TOKEN
=> 'wrong_token',
1410 self
::USER_MIGRATED
=> 'user_migrated',
1414 * @param WebRequest $request
1416 public function __construct( $request = null ) {
1417 wfDeprecated( 'LoginForm', '1.27' );
1418 parent
::__construct();
1422 * @deprecated since 1.27 - call LoginHelper::getValidErrorMessages instead.
1424 public static function getValidErrorMessages() {
1425 return LoginHelper
::getValidErrorMessages();
1429 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1431 public static function incrementLoginThrottle( $username ) {
1432 wfDeprecated( __METHOD__
, "1.27" );
1434 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1435 $throttler = new Throttler();
1436 return $throttler->increase( $username, $wgRequest->getIP(), __METHOD__
);
1440 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1442 public static function incLoginThrottle( $username ) {
1443 wfDeprecated( __METHOD__
, "1.27" );
1444 $res = self
::incrementLoginThrottle( $username );
1445 return is_array( $res ) ?
true : 0;
1449 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1451 public static function clearLoginThrottle( $username ) {
1452 wfDeprecated( __METHOD__
, "1.27" );
1454 $username = User
::getCanonicalName( $username, 'usable' ) ?
: $username;
1455 $throttler = new Throttler();
1456 return $throttler->clear( $username, $wgRequest->getIP() );
1460 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1462 public static function getLoginToken() {
1463 wfDeprecated( __METHOD__
, '1.27' );
1465 return $wgRequest->getSession()->getToken( '', 'login' )->toString();
1469 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1471 public static function setLoginToken() {
1472 wfDeprecated( __METHOD__
, '1.27' );
1476 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1478 public static function clearLoginToken() {
1479 wfDeprecated( __METHOD__
, '1.27' );
1481 $wgRequest->getSession()->resetToken( 'login' );
1485 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1487 public static function getCreateaccountToken() {
1488 wfDeprecated( __METHOD__
, '1.27' );
1490 return $wgRequest->getSession()->getToken( '', 'createaccount' )->toString();
1494 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1496 public static function setCreateaccountToken() {
1497 wfDeprecated( __METHOD__
, '1.27' );
1501 * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
1503 public static function clearCreateaccountToken() {
1504 wfDeprecated( __METHOD__
, '1.27' );
1506 $wgRequest->getSession()->resetToken( 'createaccount' );