3 * Implements Special:UserLogin
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
25 * Implements Special:UserLogin
27 * @ingroup SpecialPage
29 class LoginForm
extends SpecialPage
{
33 const WRONG_PLUGIN_PASS
= 3;
39 const CREATE_BLOCKED
= 9;
41 const USER_BLOCKED
= 11;
42 const NEED_TOKEN
= 12;
43 const WRONG_TOKEN
= 13;
44 const USER_MIGRATED
= 14;
47 * Valid error and warning messages
49 * Special:Userlogin can show an error or warning message on the form when
50 * coming from another page. This is done via the ?error= or ?warning= GET
53 * This array is the list of valid message keys. All other values will be
59 public static $validErrorMessages = array(
60 'exception-nologin-text',
62 'changeemail-no-info',
64 'confirmemail_needlogin',
68 public $mAbortLoginErrorMsg = null;
74 protected $mCookieCheck;
77 protected $mCreateaccount;
78 protected $mCreateaccountMail;
79 protected $mLoginattempt;
84 protected $mSkipCookieCheck;
85 protected $mReturnToQuery;
87 protected $mStickHTTPS;
91 protected $mEntryError = '';
92 protected $mEntryErrorType = 'error';
94 private $mTempPasswordUsed;
95 private $mLoaded = false;
96 private $mSecureLoginUrl;
98 /** @var WebRequest */
99 private $mOverrideRequest = null;
101 /** @var WebRequest Effective request; set at the beginning of load */
102 private $mRequest = null;
105 * @param WebRequest $request
107 public function __construct( $request = null ) {
108 parent
::__construct( 'Userlogin' );
110 $this->mOverrideRequest
= $request;
117 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
119 if ( $this->mLoaded
) {
122 $this->mLoaded
= true;
124 if ( $this->mOverrideRequest
=== null ) {
125 $request = $this->getRequest();
127 $request = $this->mOverrideRequest
;
129 $this->mRequest
= $request;
131 $this->mType
= $request->getText( 'type' );
132 $this->mUsername
= $request->getText( 'wpName' );
133 $this->mPassword
= $request->getText( 'wpPassword' );
134 $this->mRetype
= $request->getText( 'wpRetype' );
135 $this->mDomain
= $request->getText( 'wpDomain' );
136 $this->mReason
= $request->getText( 'wpReason' );
137 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
138 $this->mPosted
= $request->wasPosted();
139 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
141 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' ) && !$this->mCreateaccountMail
;
142 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
143 $this->mAction
= $request->getVal( 'action' );
144 $this->mRemember
= $request->getCheck( 'wpRemember' );
145 $this->mFromHTTP
= $request->getBool( 'fromhttp', false );
146 $this->mStickHTTPS
= ( !$this->mFromHTTP
&& $request->getProtocol() === 'https' )
147 ||
$request->getBool( 'wpForceHttps', false );
148 $this->mLanguage
= $request->getText( 'uselang' );
149 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
150 $this->mToken
= $this->mType
== 'signup'
151 ?
$request->getVal( 'wpCreateaccountToken' )
152 : $request->getVal( 'wpLoginToken' );
153 $this->mReturnTo
= $request->getVal( 'returnto', '' );
154 $this->mReturnToQuery
= $request->getVal( 'returntoquery', '' );
156 // Show an error or warning passed on from a previous page
157 $entryError = $this->msg( $request->getVal( 'error', '' ) );
158 $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
159 // bc: provide login link as a parameter for messages where the translation
161 $loginreqlink = Linker
::linkKnown(
162 $this->getPageTitle(),
163 $this->msg( 'loginreqlink' )->escaped(),
166 'returnto' => $this->mReturnTo
,
167 'returntoquery' => $this->mReturnToQuery
,
168 'uselang' => $this->mLanguage
,
169 'fromhttp' => $this->mFromHTTP ?
'1' : '0',
173 // Only show valid error or warning messages.
174 if ( $entryError->exists()
175 && in_array( $entryError->getKey(), self
::$validErrorMessages )
177 $this->mEntryErrorType
= 'error';
178 $this->mEntryError
= $entryError->rawParams( $loginreqlink )->escaped();
180 } elseif ( $entryWarning->exists()
181 && in_array( $entryWarning->getKey(), self
::$validErrorMessages )
183 $this->mEntryErrorType
= 'warning';
184 $this->mEntryError
= $entryWarning->rawParams( $loginreqlink )->escaped();
187 if ( $wgEnableEmail ) {
188 $this->mEmail
= $request->getText( 'wpEmail' );
192 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
193 $this->mRealName
= $request->getText( 'wpRealName' );
195 $this->mRealName
= '';
198 if ( !$wgAuth->validDomain( $this->mDomain
) ) {
199 $this->mDomain
= $wgAuth->getDomain();
201 $wgAuth->setDomain( $this->mDomain
);
203 # 1. When switching accounts, it sucks to get automatically logged out
204 # 2. Do not return to PasswordReset after a successful password change
205 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
206 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
207 if ( is_object( $returnToTitle )
208 && ( $returnToTitle->isSpecial( 'Userlogout' )
209 ||
$returnToTitle->isSpecial( 'PasswordReset' ) )
211 $this->mReturnTo
= '';
212 $this->mReturnToQuery
= '';
216 function getDescription() {
217 if ( $this->mType
=== 'signup' ) {
218 return $this->msg( 'createaccount' )->text();
220 return $this->msg( 'login' )->text();
225 * @param string|null $subPage
227 public function execute( $subPage ) {
228 if ( session_id() == '' ) {
234 // Check for [[Special:Userlogin/signup]]. This affects form display and
236 if ( $subPage == 'signup' ) {
237 $this->mType
= 'signup';
241 // In the case where the user is already logged in, and was redirected to the login form from a
242 // page that requires login, do not show the login page. The use case scenario for this is when
243 // a user opens a large number of tabs, is redirected to the login page on all of them, and then
244 // logs in on one, expecting all the others to work properly.
246 // However, do show the form if it was visited intentionally (no 'returnto' is present). People
247 // who often switch between several accounts have grown accustomed to this behavior.
249 $this->mType
!== 'signup' &&
251 $this->getUser()->isLoggedIn() &&
252 ( $this->mReturnTo
!== '' ||
$this->mReturnToQuery
!== '' )
254 $this->successfulLogin();
257 // If logging in and not on HTTPS, either redirect to it or offer a link.
258 global $wgSecureLogin;
259 if ( $this->mRequest
->getProtocol() !== 'https' ) {
260 $title = $this->getFullTitle();
262 'returnto' => $this->mReturnTo
!== '' ?
$this->mReturnTo
: null,
263 'returntoquery' => $this->mReturnToQuery
!== '' ?
264 $this->mReturnToQuery
: null,
266 ( $this->mEntryErrorType
=== 'error' ?
'error' : 'warning' ) => $this->mEntryError
,
267 ) +
$this->mRequest
->getQueryValues();
268 $url = $title->getFullURL( $query, false, PROTO_HTTPS
);
270 && wfCanIPUseHTTPS( $this->getRequest()->getIP() )
271 && !$this->mFromHTTP
) // Avoid infinite redirect
273 $url = wfAppendQuery( $url, 'fromhttp=1' );
274 $this->getOutput()->redirect( $url );
275 // Since we only do this redir to change proto, always vary
276 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
280 // A wiki without HTTPS login support should set $wgServer to
281 // http://somehost, in which case the secure URL generated
282 // above won't actually start with https://
283 if ( substr( $url, 0, 8 ) === 'https://' ) {
284 $this->mSecureLoginUrl
= $url;
289 if ( !is_null( $this->mCookieCheck
) ) {
290 $this->onCookieRedirectCheck( $this->mCookieCheck
);
293 } elseif ( $this->mPosted
) {
294 if ( $this->mCreateaccount
) {
295 $this->addNewAccount();
298 } elseif ( $this->mCreateaccountMail
) {
299 $this->addNewAccountMailPassword();
302 } elseif ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
303 $this->processLogin();
308 $this->mainLoginForm( $this->mEntryError
, $this->mEntryErrorType
);
314 function addNewAccountMailPassword() {
315 if ( $this->mEmail
== '' ) {
316 $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() );
321 $status = $this->addNewAccountInternal();
322 if ( !$status->isGood() ) {
323 $error = $status->getMessage();
324 $this->mainLoginForm( $error->toString() );
329 $u = $status->getValue();
331 // Wipe the initial password and mail a temporary one
332 $u->setPassword( null );
334 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
336 wfRunHooks( 'AddNewAccount', array( $u, true ) );
337 $u->addNewUserLogEntry( 'byemail', $this->mReason
);
339 $out = $this->getOutput();
340 $out->setPageTitle( $this->msg( 'accmailtitle' ) );
342 if ( !$result->isGood() ) {
343 $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
345 $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
346 $this->executeReturnTo( 'success' );
354 function addNewAccount() {
355 global $wgContLang, $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
357 # Create the account and abort if there's a problem doing so
358 $status = $this->addNewAccountInternal();
359 if ( !$status->isGood() ) {
360 $error = $status->getMessage();
361 $this->mainLoginForm( $error->toString() );
366 $u = $status->getValue();
368 # Only save preferences if the user is not creating an account for someone else.
369 if ( $this->getUser()->isAnon() ) {
370 # If we showed up language selection links, and one was in use, be
371 # smart (and sensible) and save that language as the user's preference
372 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
373 $u->setOption( 'language', $this->mLanguage
);
376 # Otherwise the user's language preference defaults to $wgContLang,
377 # but it may be better to set it to their preferred $wgContLang variant,
378 # based on browser preferences or URL parameters.
379 $u->setOption( 'language', $wgContLang->getPreferredVariant() );
381 if ( $wgContLang->hasVariants() ) {
382 $u->setOption( 'variant', $wgContLang->getPreferredVariant() );
386 $out = $this->getOutput();
388 # Send out an email authentication message if needed
389 if ( $wgEmailAuthentication && Sanitizer
::validateEmail( $u->getEmail() ) ) {
390 $status = $u->sendConfirmationMail();
391 if ( $status->isGood() ) {
392 $out->addWikiMsg( 'confirmemail_oncreate' );
394 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
398 # Save settings (including confirmation token)
401 # If not logged in, assume the new account as the current one and set
402 # session cookies then show a "welcome" message or a "need cookies"
404 if ( $this->getUser()->isAnon() ) {
407 // This should set it for OutputPage and the Skin
408 // which is needed or the personal links will be
410 $this->getContext()->setUser( $u );
411 wfRunHooks( 'AddNewAccount', array( $u, false ) );
412 $u->addNewUserLogEntry( 'create' );
413 if ( $this->hasSessionCookie() ) {
414 $this->successfulCreation();
416 $this->cookieRedirectCheck( 'new' );
419 # Confirm that the account was created
420 $out->setPageTitle( $this->msg( 'accountcreated' ) );
421 $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
422 $out->addReturnTo( $this->getPageTitle() );
423 wfRunHooks( 'AddNewAccount', array( $u, false ) );
424 $u->addNewUserLogEntry( 'create2', $this->mReason
);
431 * Make a new user account using the loaded data.
433 * @throws PermissionsError|ReadOnlyError
436 public function addNewAccountInternal() {
437 global $wgAuth, $wgMemc, $wgAccountCreationThrottle,
438 $wgMinimalPasswordLength, $wgEmailConfirmToEdit;
440 // If the user passes an invalid domain, something is fishy
441 if ( !$wgAuth->validDomain( $this->mDomain
) ) {
442 return Status
::newFatal( 'wrongpassword' );
445 // If we are not allowing users to login locally, we should be checking
446 // to see if the user is actually able to authenticate to the authenti-
447 // cation server before they create an account (otherwise, they can
448 // create a local account and login as any domain user). We only need
449 // to check this for domains that aren't local.
450 if ( 'local' != $this->mDomain
&& $this->mDomain
!= '' ) {
452 !$wgAuth->canCreateAccounts() &&
454 !$wgAuth->userExists( $this->mUsername
) ||
455 !$wgAuth->authenticate( $this->mUsername
, $this->mPassword
)
458 return Status
::newFatal( 'wrongpassword' );
462 if ( wfReadOnly() ) {
463 throw new ReadOnlyError
;
466 # Request forgery checks.
467 if ( !self
::getCreateaccountToken() ) {
468 self
::setCreateaccountToken();
470 return Status
::newFatal( 'nocookiesfornew' );
473 # The user didn't pass a createaccount token
474 if ( !$this->mToken
) {
475 return Status
::newFatal( 'sessionfailure' );
478 # Validate the createaccount token
479 if ( $this->mToken
!== self
::getCreateaccountToken() ) {
480 return Status
::newFatal( 'sessionfailure' );
484 $currentUser = $this->getUser();
485 $creationBlock = $currentUser->isBlockedFromCreateAccount();
486 if ( !$currentUser->isAllowed( 'createaccount' ) ) {
487 throw new PermissionsError( 'createaccount' );
488 } elseif ( $creationBlock instanceof Block
) {
489 // Throws an ErrorPageError.
490 $this->userBlockedMessage( $creationBlock );
492 // This should never be reached.
496 # Include checks that will include GlobalBlocking (Bug 38333)
497 $permErrors = $this->getPageTitle()->getUserPermissionsErrors(
503 if ( count( $permErrors ) ) {
504 throw new PermissionsError( 'createaccount', $permErrors );
507 $ip = $this->getRequest()->getIP();
508 if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
509 return Status
::newFatal( 'sorbs_create_account_reason' );
512 // Normalize the name so that silly things don't cause "invalid username"
513 // errors. User::newFromName does some rather strict checking, rejecting
514 // e.g. leading/trailing/multiple spaces. But first we need to reject
515 // usernames that would be treated as titles with a fragment part.
516 if ( strpos( $this->mUsername
, '#' ) !== false ) {
517 return Status
::newFatal( 'noname' );
519 $title = Title
::makeTitleSafe( NS_USER
, $this->mUsername
);
520 if ( !is_object( $title ) ) {
521 return Status
::newFatal( 'noname' );
524 # Now create a dummy user ($u) and check if it is valid
525 $u = User
::newFromName( $title->getText(), 'creatable' );
526 if ( !is_object( $u ) ) {
527 return Status
::newFatal( 'noname' );
528 } elseif ( 0 != $u->idForName() ) {
529 return Status
::newFatal( 'userexists' );
532 if ( $this->mCreateaccountMail
) {
533 # do not force a password for account creation by email
534 # set invalid password, it will be replaced later by a random generated password
535 $this->mPassword
= null;
537 if ( $this->mPassword
!== $this->mRetype
) {
538 return Status
::newFatal( 'badretype' );
541 # check for minimal password length
542 $valid = $u->getPasswordValidity( $this->mPassword
);
543 if ( $valid !== true ) {
544 if ( !is_array( $valid ) ) {
545 $valid = array( $valid, $wgMinimalPasswordLength );
548 return call_user_func_array( 'Status::newFatal', $valid );
552 # if you need a confirmed email address to edit, then obviously you
553 # need an email address.
554 if ( $wgEmailConfirmToEdit && strval( $this->mEmail
) === '' ) {
555 return Status
::newFatal( 'noemailtitle' );
558 if ( strval( $this->mEmail
) !== '' && !Sanitizer
::validateEmail( $this->mEmail
) ) {
559 return Status
::newFatal( 'invalidemailaddress' );
562 # Set some additional data so the AbortNewAccount hook can be used for
563 # more than just username validation
564 $u->setEmail( $this->mEmail
);
565 $u->setRealName( $this->mRealName
);
569 if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError, &$abortStatus ) ) ) {
570 // Hook point to add extra creation throttles and blocks
571 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
572 if ( $abortStatus === null ) {
573 // Report back the old string as a raw message status.
574 // This will report the error back as 'createaccount-hook-aborted'
575 // with the given string as the message.
576 // To return a different error code, return a Status object.
577 $abortError = new Message( 'createaccount-hook-aborted', array( $abortError ) );
580 return Status
::newFatal( $abortError );
582 // For MediaWiki 1.23+ and updated hooks, return the Status object
583 // returned from the hook.
588 // Hook point to check for exempt from account creation throttle
589 if ( !wfRunHooks( 'ExemptFromAccountCreationThrottle', array( $ip ) ) ) {
590 wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook " .
591 "allowed account creation w/o throttle\n" );
593 if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
594 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
595 $value = $wgMemc->get( $key );
597 $wgMemc->set( $key, 0, 86400 );
599 if ( $value >= $wgAccountCreationThrottle ) {
600 return Status
::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle );
602 $wgMemc->incr( $key );
606 if ( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
607 return Status
::newFatal( 'externaldberror' );
610 self
::clearCreateaccountToken();
612 return $this->initUser( $u, false );
616 * Actually add a user to the database.
617 * Give it a User object that has been initialised with a name.
620 * @param bool $autocreate True if this is an autocreation via auth plugin
621 * @return Status Status object, with the User object in the value member on success
624 function initUser( $u, $autocreate ) {
627 $status = $u->addToDatabase();
628 if ( !$status->isOK() ) {
632 if ( $wgAuth->allowPasswordChange() ) {
633 $u->setPassword( $this->mPassword
);
636 $u->setEmail( $this->mEmail
);
637 $u->setRealName( $this->mRealName
);
640 $wgAuth->initUser( $u, $autocreate );
645 DeferredUpdates
::addUpdate( new SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
647 // Watch user's userpage and talk page
648 $u->addWatch( $u->getUserPage(), WatchedItem
::IGNORE_USER_RIGHTS
);
650 return Status
::newGood( $u );
654 * Internally authenticate the login request.
656 * This may create a local account as a side effect if the
657 * authentication plugin allows transparent local account
661 public function authenticateUserData() {
662 global $wgUser, $wgAuth;
666 if ( $this->mUsername
== '' ) {
667 return self
::NO_NAME
;
670 // We require a login token to prevent login CSRF
671 // Handle part of this before incrementing the throttle so
672 // token-less login attempts don't count towards the throttle
673 // but wrong-token attempts do.
675 // If the user doesn't have a login token yet, set one.
676 if ( !self
::getLoginToken() ) {
677 self
::setLoginToken();
679 return self
::NEED_TOKEN
;
681 // If the user didn't pass a login token, tell them we need one
682 if ( !$this->mToken
) {
683 return self
::NEED_TOKEN
;
686 $throttleCount = self
::incLoginThrottle( $this->mUsername
);
687 if ( $throttleCount === true ) {
688 return self
::THROTTLED
;
691 // Validate the login token
692 if ( $this->mToken
!== self
::getLoginToken() ) {
693 return self
::WRONG_TOKEN
;
696 // Load the current user now, and check to see if we're logging in as
697 // the same name. This is necessary because loading the current user
698 // (say by calling getName()) calls the UserLoadFromSession hook, which
699 // potentially creates the user in the database. Until we load $wgUser,
700 // checking for user existence using User::newFromName($name)->getId() below
701 // will effectively be using stale data.
702 if ( $this->getUser()->getName() === $this->mUsername
) {
703 wfDebug( __METHOD__
. ": already logged in as {$this->mUsername}\n" );
705 return self
::SUCCESS
;
708 $u = User
::newFromName( $this->mUsername
);
710 // Give extensions a way to indicate the username has been updated,
711 // rather than telling the user the account doesn't exist.
712 if ( !wfRunHooks( 'LoginUserMigrated', array( $u, &$msg ) ) ) {
713 $this->mAbortLoginErrorMsg
= $msg;
714 return self
::USER_MIGRATED
;
717 if ( !( $u instanceof User
) ||
!User
::isUsableName( $u->getName() ) ) {
718 return self
::ILLEGAL
;
721 $isAutoCreated = false;
722 if ( $u->getID() == 0 ) {
723 $status = $this->attemptAutoCreate( $u );
724 if ( $status !== self
::SUCCESS
) {
727 $isAutoCreated = true;
733 // Give general extensions, such as a captcha, a chance to abort logins
734 $abort = self
::ABORTED
;
736 if ( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort, &$msg ) ) ) {
737 $this->mAbortLoginErrorMsg
= $msg;
742 global $wgBlockDisablesLogin;
743 if ( !$u->checkPassword( $this->mPassword
) ) {
744 if ( $u->checkTemporaryPassword( $this->mPassword
) ) {
745 // The e-mailed temporary password should not be used for actu-
746 // al logins; that's a very sloppy habit, and insecure if an
747 // attacker has a few seconds to click "search" on someone's o-
750 // Allow it to be used only to reset the password a single time
751 // to a new value, which won't be in the user's e-mail ar-
754 // For backwards compatibility, we'll still recognize it at the
755 // login form to minimize surprises for people who have been
756 // logging in with a temporary password for some time.
758 // As a side-effect, we can authenticate the user's e-mail ad-
759 // dress if it's not already done, since the temporary password
760 // was sent via e-mail.
761 if ( !$u->isEmailConfirmed() ) {
766 // At this point we just return an appropriate code/ indicating
767 // that the UI should show a password reset form; bot inter-
768 // faces etc will probably just fail cleanly here.
769 $this->mAbortLoginErrorMsg
= 'resetpass-temp-emailed';
770 $this->mTempPasswordUsed
= true;
771 $retval = self
::RESET_PASS
;
773 $retval = ( $this->mPassword
== '' ) ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
775 } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
776 // If we've enabled it, make it so that a blocked user cannot login
777 $retval = self
::USER_BLOCKED
;
778 } elseif ( $u->getPasswordExpired() == 'hard' ) {
779 // Force reset now, without logging in
780 $retval = self
::RESET_PASS
;
781 $this->mAbortLoginErrorMsg
= 'resetpass-expired';
783 $wgAuth->updateUser( $u );
785 // This should set it for OutputPage and the Skin
786 // which is needed or the personal links will be
788 $this->getContext()->setUser( $u );
790 // Please reset throttle for successful logins, thanks!
791 if ( $throttleCount ) {
792 self
::clearLoginThrottle( $this->mUsername
);
795 if ( $isAutoCreated ) {
796 // Must be run after $wgUser is set, for correct new user log
797 wfRunHooks( 'AuthPluginAutoCreate', array( $u ) );
800 $retval = self
::SUCCESS
;
802 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
808 * Increment the login attempt throttle hit count for the (username,current IP)
809 * tuple unless the throttle was already reached.
810 * @param string $username The user name
811 * @return bool|int The integer hit count or True if it is already at the limit
813 public static function incLoginThrottle( $username ) {
814 global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest;
815 $username = trim( $username ); // sanity
818 if ( is_array( $wgPasswordAttemptThrottle ) ) {
819 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
820 $count = $wgPasswordAttemptThrottle['count'];
821 $period = $wgPasswordAttemptThrottle['seconds'];
823 $throttleCount = $wgMemc->get( $throttleKey );
824 if ( !$throttleCount ) {
825 $wgMemc->add( $throttleKey, 1, $period ); // start counter
826 } elseif ( $throttleCount < $count ) {
827 $wgMemc->incr( $throttleKey );
828 } elseif ( $throttleCount >= $count ) {
833 return $throttleCount;
837 * Clear the login attempt throttle hit count for the (username,current IP) tuple.
838 * @param string $username The user name
841 public static function clearLoginThrottle( $username ) {
842 global $wgMemc, $wgRequest;
843 $username = trim( $username ); // sanity
845 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
846 $wgMemc->delete( $throttleKey );
850 * Attempt to automatically create a user on login. Only succeeds if there
851 * is an external authentication method which allows it.
855 * @return int Status code
857 function attemptAutoCreate( $user ) {
860 if ( $this->getUser()->isBlockedFromCreateAccount() ) {
861 wfDebug( __METHOD__
. ": user is blocked from account creation\n" );
863 return self
::CREATE_BLOCKED
;
866 if ( !$wgAuth->autoCreate() ) {
867 return self
::NOT_EXISTS
;
870 if ( !$wgAuth->userExists( $user->getName() ) ) {
871 wfDebug( __METHOD__
. ": user does not exist\n" );
873 return self
::NOT_EXISTS
;
876 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
877 wfDebug( __METHOD__
. ": \$wgAuth->authenticate() returned false, aborting\n" );
879 return self
::WRONG_PLUGIN_PASS
;
883 if ( !wfRunHooks( 'AbortAutoAccount', array( $user, &$abortError ) ) ) {
884 // Hook point to add extra creation throttles and blocks
885 wfDebug( "LoginForm::attemptAutoCreate: a hook blocked creation: $abortError\n" );
886 $this->mAbortLoginErrorMsg
= $abortError;
888 return self
::ABORTED
;
891 wfDebug( __METHOD__
. ": creating account\n" );
892 $status = $this->initUser( $user, true );
894 if ( !$status->isOK() ) {
895 $errors = $status->getErrorsByType( 'error' );
896 $this->mAbortLoginErrorMsg
= $errors[0]['message'];
898 return self
::ABORTED
;
901 return self
::SUCCESS
;
904 function processLogin() {
905 global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle,
906 $wgInvalidPasswordReset;
908 switch ( $this->authenticateUserData() ) {
910 # We've verified now, update the real record
911 $user = $this->getUser();
912 $user->invalidateCache();
914 if ( $user->requiresHTTPS() ) {
915 $this->mStickHTTPS
= true;
918 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
919 $user->setCookies( $this->mRequest
, false, $this->mRemember
);
921 $user->setCookies( $this->mRequest
, null, $this->mRemember
);
923 self
::clearLoginToken();
925 // Reset the throttle
926 $request = $this->getRequest();
927 $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername
) );
928 $wgMemc->delete( $key );
930 if ( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
931 /* Replace the language object to provide user interface in
932 * correct language immediately on this first page load.
934 $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
935 $userLang = Language
::factory( $code );
937 $this->getContext()->setLanguage( $userLang );
938 // Reset SessionID on Successful login (bug 40995)
939 $this->renewSessionId();
940 if ( $this->getUser()->getPasswordExpired() == 'soft' ) {
941 $this->resetLoginForm( $this->msg( 'resetpass-expired-soft' ) );
942 } elseif ( $wgInvalidPasswordReset
943 && !$user->isValidPassword( $this->mPassword
)
945 $status = $user->checkPasswordValidity( $this->mPassword
);
946 $this->resetLoginForm(
947 $status->getMessage( 'resetpass-validity-soft' )
950 $this->successfulLogin();
953 $this->cookieRedirectCheck( 'login' );
957 case self
::NEED_TOKEN
:
958 $error = $this->mAbortLoginErrorMsg ?
: 'nocookiesforlogin';
959 $this->mainLoginForm( $this->msg( $error )->parse() );
961 case self
::WRONG_TOKEN
:
962 $error = $this->mAbortLoginErrorMsg ?
: 'sessionfailure';
963 $this->mainLoginForm( $this->msg( $error )->text() );
967 $error = $this->mAbortLoginErrorMsg ?
: 'noname';
968 $this->mainLoginForm( $this->msg( $error )->text() );
970 case self
::WRONG_PLUGIN_PASS
:
971 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpassword';
972 $this->mainLoginForm( $this->msg( $error )->text() );
974 case self
::NOT_EXISTS
:
975 if ( $this->getUser()->isAllowed( 'createaccount' ) ) {
976 $error = $this->mAbortLoginErrorMsg ?
: 'nosuchuser';
977 $this->mainLoginForm( $this->msg( $error,
978 wfEscapeWikiText( $this->mUsername
) )->parse() );
980 $error = $this->mAbortLoginErrorMsg ?
: 'nosuchusershort';
981 $this->mainLoginForm( $this->msg( $error,
982 wfEscapeWikiText( $this->mUsername
) )->text() );
985 case self
::WRONG_PASS
:
986 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpassword';
987 $this->mainLoginForm( $this->msg( $error )->text() );
989 case self
::EMPTY_PASS
:
990 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpasswordempty';
991 $this->mainLoginForm( $this->msg( $error )->text() );
993 case self
::RESET_PASS
:
994 $error = $this->mAbortLoginErrorMsg ?
: 'resetpass_announce';
995 $this->resetLoginForm( $this->msg( $error ) );
997 case self
::CREATE_BLOCKED
:
998 $this->userBlockedMessage( $this->getUser()->isBlockedFromCreateAccount() );
1000 case self
::THROTTLED
:
1001 $error = $this->mAbortLoginErrorMsg ?
: 'login-throttled';
1002 $this->mainLoginForm( $this->msg( $error )
1003 ->params( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
1007 case self
::USER_BLOCKED
:
1008 $error = $this->mAbortLoginErrorMsg ?
: 'login-userblocked';
1009 $this->mainLoginForm( $this->msg( $error, $this->mUsername
)->escaped() );
1012 $error = $this->mAbortLoginErrorMsg ?
: 'login-abort-generic';
1013 $this->mainLoginForm( $this->msg( $error,
1014 wfEscapeWikiText( $this->mUsername
) )->text() );
1016 case self
::USER_MIGRATED
:
1017 $error = $this->mAbortLoginErrorMsg ?
: 'login-migrated-generic';
1019 if ( is_array( $error ) ) {
1020 $error = array_shift( $this->mAbortLoginErrorMsg
);
1021 $params = $this->mAbortLoginErrorMsg
;
1023 $this->mainLoginForm( $this->msg( $error, $params )->text() );
1026 throw new MWException( 'Unhandled case value' );
1031 * Show the Special:ChangePassword form, with custom message
1032 * @param Message $msg
1034 protected function resetLoginForm( Message
$msg ) {
1035 // Allow hooks to explain this password reset in more detail
1036 wfRunHooks( 'LoginPasswordResetMessage', array( &$msg, $this->mUsername
) );
1037 $reset = new SpecialChangePassword();
1038 $derivative = new DerivativeContext( $this->getContext() );
1039 $derivative->setTitle( $reset->getPageTitle() );
1040 $reset->setContext( $derivative );
1041 if ( !$this->mTempPasswordUsed
) {
1042 $reset->setOldPasswordMessage( 'oldpassword' );
1044 $reset->setChangeMessage( $msg );
1045 $reset->execute( null );
1050 * @param bool $throttle
1051 * @param string $emailTitle Message name of email title
1052 * @param string $emailText Message name of email text
1055 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle',
1056 $emailText = 'passwordremindertext'
1058 global $wgNewPasswordExpiry;
1060 if ( $u->getEmail() == '' ) {
1061 return Status
::newFatal( 'noemail', $u->getName() );
1063 $ip = $this->getRequest()->getIP();
1065 return Status
::newFatal( 'badipaddress' );
1068 $currentUser = $this->getUser();
1069 wfRunHooks( 'User::mailPasswordInternal', array( &$currentUser, &$ip, &$u ) );
1071 $np = $u->randomPassword();
1072 $u->setNewpassword( $np, $throttle );
1074 $userLanguage = $u->getOption( 'language' );
1076 $mainPage = Title
::newMainPage();
1077 $mainPageUrl = $mainPage->getCanonicalURL();
1079 $m = $this->msg( $emailText, $ip, $u->getName(), $np, '<' . $mainPageUrl . '>',
1080 round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text();
1081 $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m );
1087 * Run any hooks registered for logins, then HTTP redirect to
1088 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
1089 * nice message here, but that's really not as useful as just being sent to
1090 * wherever you logged in from. It should be clear that the action was
1091 * successful, given the lack of error messages plus the appearance of your
1092 * name in the upper right.
1096 function successfulLogin() {
1097 # Run any hooks; display injected HTML if any, else redirect
1098 $currentUser = $this->getUser();
1099 $injected_html = '';
1100 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
1102 if ( $injected_html !== '' ) {
1103 $this->displaySuccessfulAction( 'success', $this->msg( 'loginsuccesstitle' ),
1104 'loginsuccess', $injected_html );
1106 $this->executeReturnTo( 'successredirect' );
1111 * Run any hooks registered for logins, then display a message welcoming
1116 function successfulCreation() {
1117 # Run any hooks; display injected HTML
1118 $currentUser = $this->getUser();
1119 $injected_html = '';
1120 $welcome_creation_msg = 'welcomecreation-msg';
1122 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
1125 * Let any extensions change what message is shown.
1126 * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeWelcomeCreation
1129 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
1131 $this->displaySuccessfulAction(
1133 $this->msg( 'welcomeuser', $this->getUser()->getName() ),
1134 $welcome_creation_msg, $injected_html
1139 * Display a "successful action" page.
1141 * @param string $type Condition of return to; see `executeReturnTo`
1142 * @param string|Message $title Page's title
1143 * @param string $msgname
1144 * @param string $injected_html
1146 private function displaySuccessfulAction( $type, $title, $msgname, $injected_html ) {
1147 $out = $this->getOutput();
1148 $out->setPageTitle( $title );
1150 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
1153 $out->addHTML( $injected_html );
1155 $this->executeReturnTo( $type );
1159 * Output a message that informs the user that they cannot create an account because
1160 * there is a block on them or their IP which prevents account creation. Note that
1161 * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
1162 * setting on blocks (bug 13611).
1163 * @param Block $block The block causing this error
1164 * @throws ErrorPageError
1166 function userBlockedMessage( Block
$block ) {
1167 # Let's be nice about this, it's likely that this feature will be used
1168 # for blocking large numbers of innocent people, e.g. range blocks on
1169 # schools. Don't blame it on the user. There's a small chance that it
1170 # really is the user's fault, i.e. the username is blocked and they
1171 # haven't bothered to log out before trying to create an account to
1172 # evade it, but we'll leave that to their guilty conscience to figure
1174 $errorParams = array(
1175 $block->getTarget(),
1176 $block->mReason ?
$block->mReason
: $this->msg( 'blockednoreason' )->text(),
1180 if ( $block->getType() === Block
::TYPE_RANGE
) {
1181 $errorMessage = 'cantcreateaccount-range-text';
1182 $errorParams[] = $this->getRequest()->getIP();
1184 $errorMessage = 'cantcreateaccount-text';
1187 throw new ErrorPageError(
1188 'cantcreateaccounttitle',
1195 * Add a "return to" link or redirect to it.
1196 * Extensions can use this to reuse the "return to" logic after
1197 * inject steps (such as redirection) into the login process.
1199 * @param string $type One of the following:
1200 * - error: display a return to link ignoring $wgRedirectOnLogin
1201 * - signup: display a return to link using $wgRedirectOnLogin if needed
1202 * - success: display a return to link using $wgRedirectOnLogin if needed
1203 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
1204 * @param string $returnTo
1205 * @param array|string $returnToQuery
1206 * @param bool $stickHTTPs Keep redirect link on HTTPs
1209 public function showReturnToPage(
1210 $type, $returnTo = '', $returnToQuery = '', $stickHTTPs = false
1212 $this->mReturnTo
= $returnTo;
1213 $this->mReturnToQuery
= $returnToQuery;
1214 $this->mStickHTTPS
= $stickHTTPs;
1215 $this->executeReturnTo( $type );
1219 * Add a "return to" link or redirect to it.
1221 * @param string $type One of the following:
1222 * - error: display a return to link ignoring $wgRedirectOnLogin
1223 * - signup: display a return to link using $wgRedirectOnLogin if needed
1224 * - success: display a return to link using $wgRedirectOnLogin if needed
1225 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
1227 private function executeReturnTo( $type ) {
1228 global $wgRedirectOnLogin, $wgSecureLogin;
1230 if ( $type != 'error' && $wgRedirectOnLogin !== null ) {
1231 $returnTo = $wgRedirectOnLogin;
1232 $returnToQuery = array();
1234 $returnTo = $this->mReturnTo
;
1235 $returnToQuery = wfCgiToArray( $this->mReturnToQuery
);
1238 // Allow modification of redirect behavior
1239 wfRunHooks( 'PostLoginRedirect', array( &$returnTo, &$returnToQuery, &$type ) );
1241 $returnToTitle = Title
::newFromText( $returnTo );
1242 if ( !$returnToTitle ) {
1243 $returnToTitle = Title
::newMainPage();
1246 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
1247 $options = array( 'http' );
1248 $proto = PROTO_HTTP
;
1249 } elseif ( $wgSecureLogin ) {
1250 $options = array( 'https' );
1251 $proto = PROTO_HTTPS
;
1254 $proto = PROTO_RELATIVE
;
1257 if ( $type == 'successredirect' ) {
1258 $redirectUrl = $returnToTitle->getFullURL( $returnToQuery, false, $proto );
1259 $this->getOutput()->redirect( $redirectUrl );
1261 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
1266 * @param string $msg
1267 * @param string $msgtype
1270 function mainLoginForm( $msg, $msgtype = 'error' ) {
1271 global $wgEnableEmail, $wgEnableUserEmail;
1272 global $wgHiddenPrefs, $wgLoginLanguageSelector;
1273 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
1274 global $wgSecureLogin, $wgPasswordResetRoutes;
1276 $titleObj = $this->getPageTitle();
1277 $user = $this->getUser();
1278 $out = $this->getOutput();
1280 if ( $this->mType
== 'signup' ) {
1281 // Block signup here if in readonly. Keeps user from
1282 // going through the process (filling out data, etc)
1283 // and being informed later.
1284 $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true );
1285 if ( count( $permErrors ) ) {
1286 throw new PermissionsError( 'createaccount', $permErrors );
1287 } elseif ( $user->isBlockedFromCreateAccount() ) {
1288 $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
1291 } elseif ( wfReadOnly() ) {
1292 throw new ReadOnlyError
;
1296 // Pre-fill username (if not creating an account, bug 44775).
1297 if ( $this->mUsername
== '' && $this->mType
!= 'signup' ) {
1298 if ( $user->isLoggedIn() ) {
1299 $this->mUsername
= $user->getName();
1301 $this->mUsername
= $this->getRequest()->getCookie( 'UserName' );
1305 // Generic styles and scripts for both login and signup form
1306 $out->addModuleStyles( array(
1308 'mediawiki.ui.button',
1309 'mediawiki.ui.checkbox',
1310 'mediawiki.ui.input',
1311 'mediawiki.special.userlogin.common.styles'
1313 $out->addModules( array(
1314 'mediawiki.special.userlogin.common.js'
1317 if ( $this->mType
== 'signup' ) {
1318 // XXX hack pending RL or JS parse() support for complex content messages
1319 // https://bugzilla.wikimedia.org/show_bug.cgi?id=25349
1320 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
1321 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
1323 // Additional styles and scripts for signup form
1324 $out->addModules( array(
1325 'mediawiki.special.userlogin.signup.js'
1327 $out->addModuleStyles( array(
1328 'mediawiki.special.userlogin.signup.styles'
1331 $template = new UsercreateTemplate();
1333 // Must match number of benefits defined in messages
1334 $template->set( 'benefitCount', 3 );
1336 $q = 'action=submitlogin&type=signup';
1337 $linkq = 'type=login';
1339 // Additional styles for login form
1340 $out->addModuleStyles( array(
1341 'mediawiki.special.userlogin.login.styles'
1344 $template = new UserloginTemplate();
1346 $q = 'action=submitlogin&type=login';
1347 $linkq = 'type=signup';
1350 if ( $this->mReturnTo
!== '' ) {
1351 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
1352 if ( $this->mReturnToQuery
!== '' ) {
1353 $returnto .= '&returntoquery=' .
1354 wfUrlencode( $this->mReturnToQuery
);
1357 $linkq .= $returnto;
1360 # Don't show a "create account" link if the user can't.
1361 if ( $this->showCreateOrLoginLink( $user ) ) {
1362 # Pass any language selection on to the mode switch link
1363 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
1364 $linkq .= '&uselang=' . $this->mLanguage
;
1366 // Supply URL, login template creates the button.
1367 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
1369 $template->set( 'link', '' );
1372 $resetLink = $this->mType
== 'signup'
1374 : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );
1376 $template->set( 'header', '' );
1377 $template->set( 'skin', $this->getSkin() );
1378 $template->set( 'name', $this->mUsername
);
1379 $template->set( 'password', $this->mPassword
);
1380 $template->set( 'retype', $this->mRetype
);
1381 $template->set( 'createemailset', $this->mCreateaccountMail
);
1382 $template->set( 'email', $this->mEmail
);
1383 $template->set( 'realname', $this->mRealName
);
1384 $template->set( 'domain', $this->mDomain
);
1385 $template->set( 'reason', $this->mReason
);
1387 $template->set( 'action', $titleObj->getLocalURL( $q ) );
1388 $template->set( 'message', $msg );
1389 $template->set( 'messagetype', $msgtype );
1390 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
1391 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
1392 $template->set( 'useemail', $wgEnableEmail );
1393 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
1394 $template->set( 'emailothers', $wgEnableUserEmail );
1395 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
1396 $template->set( 'resetlink', $resetLink );
1397 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
1398 $template->set( 'usereason', $user->isLoggedIn() );
1399 $template->set( 'remember', $this->mRemember
);
1400 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
1401 $template->set( 'stickhttps', (int)$this->mStickHTTPS
);
1402 $template->set( 'loggedin', $user->isLoggedIn() );
1403 $template->set( 'loggedinuser', $user->getName() );
1405 if ( $this->mType
== 'signup' ) {
1406 if ( !self
::getCreateaccountToken() ) {
1407 self
::setCreateaccountToken();
1409 $template->set( 'token', self
::getCreateaccountToken() );
1411 if ( !self
::getLoginToken() ) {
1412 self
::setLoginToken();
1414 $template->set( 'token', self
::getLoginToken() );
1417 # Prepare language selection links as needed
1418 if ( $wgLoginLanguageSelector ) {
1419 $template->set( 'languages', $this->makeLanguageSelector() );
1420 if ( $this->mLanguage
) {
1421 $template->set( 'uselang', $this->mLanguage
);
1425 $template->set( 'secureLoginUrl', $this->mSecureLoginUrl
);
1426 // Use signupend-https for HTTPS requests if it's not blank, signupend otherwise
1427 $usingHTTPS = $this->mRequest
->getProtocol() == 'https';
1428 $signupendHTTPS = $this->msg( 'signupend-https' );
1429 if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) {
1430 $template->set( 'signupend', $signupendHTTPS->parse() );
1432 $template->set( 'signupend', $this->msg( 'signupend' )->parse() );
1435 // Give authentication and captcha plugins a chance to modify the form
1436 $wgAuth->modifyUITemplate( $template, $this->mType
);
1437 if ( $this->mType
== 'signup' ) {
1438 wfRunHooks( 'UserCreateForm', array( &$template ) );
1440 wfRunHooks( 'UserLoginForm', array( &$template ) );
1443 $out->disallowUserJs(); // just in case...
1444 $out->addTemplate( $template );
1448 * Whether the login/create account form should display a link to the
1449 * other form (in addition to whatever the skin provides).
1454 private function showCreateOrLoginLink( &$user ) {
1455 if ( $this->mType
== 'signup' ) {
1457 } elseif ( $user->isAllowed( 'createaccount' ) ) {
1465 * Check if a session cookie is present.
1467 * This will not pick up a cookie set during _this_ request, but is meant
1468 * to ensure that the client is returning the cookie which was set on a
1469 * previous pass through the system.
1474 function hasSessionCookie() {
1475 global $wgDisableCookieCheck;
1477 return $wgDisableCookieCheck ?
true : $this->getRequest()->checkSessionCookie();
1481 * Get the login token from the current session
1484 public static function getLoginToken() {
1487 return $wgRequest->getSessionData( 'wsLoginToken' );
1491 * Randomly generate a new login token and attach it to the current session
1493 public static function setLoginToken() {
1495 // Generate a token directly instead of using $user->getEditToken()
1496 // because the latter reuses $_SESSION['wsEditToken']
1497 $wgRequest->setSessionData( 'wsLoginToken', MWCryptRand
::generateHex( 32 ) );
1501 * Remove any login token attached to the current session
1503 public static function clearLoginToken() {
1505 $wgRequest->setSessionData( 'wsLoginToken', null );
1509 * Get the createaccount token from the current session
1512 public static function getCreateaccountToken() {
1515 return $wgRequest->getSessionData( 'wsCreateaccountToken' );
1519 * Randomly generate a new createaccount token and attach it to the current session
1521 public static function setCreateaccountToken() {
1523 $wgRequest->setSessionData( 'wsCreateaccountToken', MWCryptRand
::generateHex( 32 ) );
1527 * Remove any createaccount token attached to the current session
1529 public static function clearCreateaccountToken() {
1531 $wgRequest->setSessionData( 'wsCreateaccountToken', null );
1535 * Renew the user's session id, using strong entropy
1537 private function renewSessionId() {
1538 global $wgSecureLogin, $wgCookieSecure;
1539 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
1540 $wgCookieSecure = false;
1547 * @param string $type
1550 function cookieRedirectCheck( $type ) {
1551 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
1552 $query = array( 'wpCookieCheck' => $type );
1553 if ( $this->mReturnTo
!== '' ) {
1554 $query['returnto'] = $this->mReturnTo
;
1555 $query['returntoquery'] = $this->mReturnToQuery
;
1557 $check = $titleObj->getFullURL( $query );
1559 $this->getOutput()->redirect( $check );
1563 * @param string $type
1566 function onCookieRedirectCheck( $type ) {
1567 if ( !$this->hasSessionCookie() ) {
1568 if ( $type == 'new' ) {
1569 $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
1570 } elseif ( $type == 'login' ) {
1571 $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
1574 $this->mainLoginForm( $this->msg( 'error' )->text() );
1577 $this->successfulLogin();
1582 * Produce a bar of links which allow the user to select another language
1583 * during login/registration but retain "returnto"
1587 function makeLanguageSelector() {
1588 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1589 if ( !$msg->isBlank() ) {
1590 $langs = explode( "\n", $msg->text() );
1592 foreach ( $langs as $lang ) {
1593 $lang = trim( $lang, '* ' );
1594 $parts = explode( '|', $lang );
1595 if ( count( $parts ) >= 2 ) {
1596 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1600 return count( $links ) > 0 ?
$this->msg( 'loginlanguagelabel' )->rawParams(
1601 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1608 * Create a language selector link for a particular language
1609 * Links back to this page preserving type and returnto
1611 * @param string $text Link text
1612 * @param string $lang Language code
1615 function makeLanguageSelectorLink( $text, $lang ) {
1616 if ( $this->getLanguage()->getCode() == $lang ) {
1617 // no link for currently used language
1618 return htmlspecialchars( $text );
1620 $query = array( 'uselang' => $lang );
1621 if ( $this->mType
== 'signup' ) {
1622 $query['type'] = 'signup';
1624 if ( $this->mReturnTo
!== '' ) {
1625 $query['returnto'] = $this->mReturnTo
;
1626 $query['returntoquery'] = $this->mReturnToQuery
;
1630 $targetLanguage = Language
::factory( $lang );
1631 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1633 return Linker
::linkKnown(
1634 $this->getPageTitle(),
1635 htmlspecialchars( $text ),
1641 protected function getGroupName() {