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;
45 public $mAbortLoginErrorMsg = null;
51 protected $mCookieCheck;
54 protected $mCreateaccount;
55 protected $mCreateaccountMail;
56 protected $mLoginattempt;
61 protected $mSkipCookieCheck;
62 protected $mReturnToQuery;
64 protected $mStickHTTPS;
69 private $mTempPasswordUsed;
70 private $mLoaded = false;
71 private $mSecureLoginUrl;
73 /** @var WebRequest */
74 private $mOverrideRequest = null;
76 /** @var WebRequest Effective request; set at the beginning of load */
77 private $mRequest = null;
80 * @param WebRequest $request
82 public function __construct( $request = null ) {
83 parent
::__construct( 'Userlogin' );
85 $this->mOverrideRequest
= $request;
92 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
94 if ( $this->mLoaded
) {
97 $this->mLoaded
= true;
99 if ( $this->mOverrideRequest
=== null ) {
100 $request = $this->getRequest();
102 $request = $this->mOverrideRequest
;
104 $this->mRequest
= $request;
106 $this->mType
= $request->getText( 'type' );
107 $this->mUsername
= $request->getText( 'wpName' );
108 $this->mPassword
= $request->getText( 'wpPassword' );
109 $this->mRetype
= $request->getText( 'wpRetype' );
110 $this->mDomain
= $request->getText( 'wpDomain' );
111 $this->mReason
= $request->getText( 'wpReason' );
112 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
113 $this->mPosted
= $request->wasPosted();
114 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
116 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' ) && !$this->mCreateaccountMail
;
117 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
118 $this->mAction
= $request->getVal( 'action' );
119 $this->mRemember
= $request->getCheck( 'wpRemember' );
120 $this->mFromHTTP
= $request->getBool( 'fromhttp', false );
121 $this->mStickHTTPS
= ( !$this->mFromHTTP
&& $request->getProtocol() === 'https' )
122 ||
$request->getBool( 'wpForceHttps', false );
123 $this->mLanguage
= $request->getText( 'uselang' );
124 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
125 $this->mToken
= $this->mType
== 'signup'
126 ?
$request->getVal( 'wpCreateaccountToken' )
127 : $request->getVal( 'wpLoginToken' );
128 $this->mReturnTo
= $request->getVal( 'returnto', '' );
129 $this->mReturnToQuery
= $request->getVal( 'returntoquery', '' );
131 if ( $wgEnableEmail ) {
132 $this->mEmail
= $request->getText( 'wpEmail' );
136 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
137 $this->mRealName
= $request->getText( 'wpRealName' );
139 $this->mRealName
= '';
142 if ( !$wgAuth->validDomain( $this->mDomain
) ) {
143 $this->mDomain
= $wgAuth->getDomain();
145 $wgAuth->setDomain( $this->mDomain
);
147 # 1. When switching accounts, it sucks to get automatically logged out
148 # 2. Do not return to PasswordReset after a successful password change
149 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
150 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
151 if ( is_object( $returnToTitle )
152 && ( $returnToTitle->isSpecial( 'Userlogout' )
153 ||
$returnToTitle->isSpecial( 'PasswordReset' ) )
155 $this->mReturnTo
= '';
156 $this->mReturnToQuery
= '';
160 function getDescription() {
161 if ( $this->mType
=== 'signup' ) {
162 return $this->msg( 'createaccount' )->text();
164 return $this->msg( 'login' )->text();
169 * @param string|null $subPage
171 public function execute( $subPage ) {
172 if ( session_id() == '' ) {
178 // Check for [[Special:Userlogin/signup]]. This affects form display and
180 if ( $subPage == 'signup' ) {
181 $this->mType
= 'signup';
185 // If logging in and not on HTTPS, either redirect to it or offer a link.
186 global $wgSecureLogin;
187 if ( $this->mRequest
->getProtocol() !== 'https' ) {
188 $title = $this->getFullTitle();
190 'returnto' => $this->mReturnTo
!== '' ?
$this->mReturnTo
: null,
191 'returntoquery' => $this->mReturnToQuery
!== '' ?
192 $this->mReturnToQuery
: null,
194 ) +
$this->mRequest
->getQueryValues();
195 $url = $title->getFullURL( $query, false, PROTO_HTTPS
);
197 && wfCanIPUseHTTPS( $this->getRequest()->getIP() )
198 && !$this->mFromHTTP
) // Avoid infinite redirect
200 $url = wfAppendQuery( $url, 'fromhttp=1' );
201 $this->getOutput()->redirect( $url );
202 // Since we only do this redir to change proto, always vary
203 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
207 // A wiki without HTTPS login support should set $wgServer to
208 // http://somehost, in which case the secure URL generated
209 // above won't actually start with https://
210 if ( substr( $url, 0, 8 ) === 'https://' ) {
211 $this->mSecureLoginUrl
= $url;
216 if ( !is_null( $this->mCookieCheck
) ) {
217 $this->onCookieRedirectCheck( $this->mCookieCheck
);
220 } elseif ( $this->mPosted
) {
221 if ( $this->mCreateaccount
) {
222 $this->addNewAccount();
225 } elseif ( $this->mCreateaccountMail
) {
226 $this->addNewAccountMailPassword();
229 } elseif ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
230 $this->processLogin();
235 $this->mainLoginForm( '' );
241 function addNewAccountMailPassword() {
242 if ( $this->mEmail
== '' ) {
243 $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() );
248 $status = $this->addNewAccountInternal();
249 if ( !$status->isGood() ) {
250 $error = $status->getMessage();
251 $this->mainLoginForm( $error->toString() );
256 $u = $status->getValue();
258 // Wipe the initial password and mail a temporary one
259 $u->setPassword( null );
261 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
263 wfRunHooks( 'AddNewAccount', array( $u, true ) );
264 $u->addNewUserLogEntry( 'byemail', $this->mReason
);
266 $out = $this->getOutput();
267 $out->setPageTitle( $this->msg( 'accmailtitle' ) );
269 if ( !$result->isGood() ) {
270 $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
272 $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
273 $this->executeReturnTo( 'success' );
281 function addNewAccount() {
282 global $wgContLang, $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
284 # Create the account and abort if there's a problem doing so
285 $status = $this->addNewAccountInternal();
286 if ( !$status->isGood() ) {
287 $error = $status->getMessage();
288 $this->mainLoginForm( $error->toString() );
293 $u = $status->getValue();
295 # Only save preferences if the user is not creating an account for someone else.
296 if ( $this->getUser()->isAnon() ) {
297 # If we showed up language selection links, and one was in use, be
298 # smart (and sensible) and save that language as the user's preference
299 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
300 $u->setOption( 'language', $this->mLanguage
);
303 # Otherwise the user's language preference defaults to $wgContLang,
304 # but it may be better to set it to their preferred $wgContLang variant,
305 # based on browser preferences or URL parameters.
306 $u->setOption( 'language', $wgContLang->getPreferredVariant() );
308 if ( $wgContLang->hasVariants() ) {
309 $u->setOption( 'variant', $wgContLang->getPreferredVariant() );
313 $out = $this->getOutput();
315 # Send out an email authentication message if needed
316 if ( $wgEmailAuthentication && Sanitizer
::validateEmail( $u->getEmail() ) ) {
317 $status = $u->sendConfirmationMail();
318 if ( $status->isGood() ) {
319 $out->addWikiMsg( 'confirmemail_oncreate' );
321 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
325 # Save settings (including confirmation token)
328 # If not logged in, assume the new account as the current one and set
329 # session cookies then show a "welcome" message or a "need cookies"
331 if ( $this->getUser()->isAnon() ) {
334 // This should set it for OutputPage and the Skin
335 // which is needed or the personal links will be
337 $this->getContext()->setUser( $u );
338 wfRunHooks( 'AddNewAccount', array( $u, false ) );
339 $u->addNewUserLogEntry( 'create' );
340 if ( $this->hasSessionCookie() ) {
341 $this->successfulCreation();
343 $this->cookieRedirectCheck( 'new' );
346 # Confirm that the account was created
347 $out->setPageTitle( $this->msg( 'accountcreated' ) );
348 $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
349 $out->addReturnTo( $this->getPageTitle() );
350 wfRunHooks( 'AddNewAccount', array( $u, false ) );
351 $u->addNewUserLogEntry( 'create2', $this->mReason
);
358 * Make a new user account using the loaded data.
360 * @throws PermissionsError|ReadOnlyError
363 public function addNewAccountInternal() {
364 global $wgAuth, $wgMemc, $wgAccountCreationThrottle,
365 $wgMinimalPasswordLength, $wgEmailConfirmToEdit;
367 // If the user passes an invalid domain, something is fishy
368 if ( !$wgAuth->validDomain( $this->mDomain
) ) {
369 return Status
::newFatal( 'wrongpassword' );
372 // If we are not allowing users to login locally, we should be checking
373 // to see if the user is actually able to authenticate to the authenti-
374 // cation server before they create an account (otherwise, they can
375 // create a local account and login as any domain user). We only need
376 // to check this for domains that aren't local.
377 if ( 'local' != $this->mDomain
&& $this->mDomain
!= '' ) {
379 !$wgAuth->canCreateAccounts() &&
381 !$wgAuth->userExists( $this->mUsername
) ||
382 !$wgAuth->authenticate( $this->mUsername
, $this->mPassword
)
385 return Status
::newFatal( 'wrongpassword' );
389 if ( wfReadOnly() ) {
390 throw new ReadOnlyError
;
393 # Request forgery checks.
394 if ( !self
::getCreateaccountToken() ) {
395 self
::setCreateaccountToken();
397 return Status
::newFatal( 'nocookiesfornew' );
400 # The user didn't pass a createaccount token
401 if ( !$this->mToken
) {
402 return Status
::newFatal( 'sessionfailure' );
405 # Validate the createaccount token
406 if ( $this->mToken
!== self
::getCreateaccountToken() ) {
407 return Status
::newFatal( 'sessionfailure' );
411 $currentUser = $this->getUser();
412 $creationBlock = $currentUser->isBlockedFromCreateAccount();
413 if ( !$currentUser->isAllowed( 'createaccount' ) ) {
414 throw new PermissionsError( 'createaccount' );
415 } elseif ( $creationBlock instanceof Block
) {
416 // Throws an ErrorPageError.
417 $this->userBlockedMessage( $creationBlock );
419 // This should never be reached.
423 # Include checks that will include GlobalBlocking (Bug 38333)
424 $permErrors = $this->getPageTitle()->getUserPermissionsErrors(
430 if ( count( $permErrors ) ) {
431 throw new PermissionsError( 'createaccount', $permErrors );
434 $ip = $this->getRequest()->getIP();
435 if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
436 return Status
::newFatal( 'sorbs_create_account_reason' );
439 // Normalize the name so that silly things don't cause "invalid username"
440 // errors. User::newFromName does some rather strict checking, rejecting
441 // e.g. leading/trailing/multiple spaces. But first we need to reject
442 // usernames that would be treated as titles with a fragment part.
443 if ( strpos( $this->mUsername
, '#' ) !== false ) {
444 return Status
::newFatal( 'noname' );
446 $title = Title
::makeTitleSafe( NS_USER
, $this->mUsername
);
447 if ( !is_object( $title ) ) {
448 return Status
::newFatal( 'noname' );
451 # Now create a dummy user ($u) and check if it is valid
452 $u = User
::newFromName( $title->getText(), 'creatable' );
453 if ( !is_object( $u ) ) {
454 return Status
::newFatal( 'noname' );
455 } elseif ( 0 != $u->idForName() ) {
456 return Status
::newFatal( 'userexists' );
459 if ( $this->mCreateaccountMail
) {
460 # do not force a password for account creation by email
461 # set invalid password, it will be replaced later by a random generated password
462 $this->mPassword
= null;
464 if ( $this->mPassword
!== $this->mRetype
) {
465 return Status
::newFatal( 'badretype' );
468 # check for minimal password length
469 $valid = $u->getPasswordValidity( $this->mPassword
);
470 if ( $valid !== true ) {
471 if ( !is_array( $valid ) ) {
472 $valid = array( $valid, $wgMinimalPasswordLength );
475 return call_user_func_array( 'Status::newFatal', $valid );
479 # if you need a confirmed email address to edit, then obviously you
480 # need an email address.
481 if ( $wgEmailConfirmToEdit && strval( $this->mEmail
) === '' ) {
482 return Status
::newFatal( 'noemailtitle' );
485 if ( strval( $this->mEmail
) !== '' && !Sanitizer
::validateEmail( $this->mEmail
) ) {
486 return Status
::newFatal( 'invalidemailaddress' );
489 # Set some additional data so the AbortNewAccount hook can be used for
490 # more than just username validation
491 $u->setEmail( $this->mEmail
);
492 $u->setRealName( $this->mRealName
);
496 if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError, &$abortStatus ) ) ) {
497 // Hook point to add extra creation throttles and blocks
498 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
499 if ( $abortStatus === null ) {
500 // Report back the old string as a raw message status.
501 // This will report the error back as 'createaccount-hook-aborted'
502 // with the given string as the message.
503 // To return a different error code, return a Status object.
504 $abortError = new Message( 'createaccount-hook-aborted', array( $abortError ) );
507 return Status
::newFatal( $abortError );
509 // For MediaWiki 1.23+ and updated hooks, return the Status object
510 // returned from the hook.
515 // Hook point to check for exempt from account creation throttle
516 if ( !wfRunHooks( 'ExemptFromAccountCreationThrottle', array( $ip ) ) ) {
517 wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook " .
518 "allowed account creation w/o throttle\n" );
520 if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
521 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
522 $value = $wgMemc->get( $key );
524 $wgMemc->set( $key, 0, 86400 );
526 if ( $value >= $wgAccountCreationThrottle ) {
527 return Status
::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle );
529 $wgMemc->incr( $key );
533 if ( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
534 return Status
::newFatal( 'externaldberror' );
537 self
::clearCreateaccountToken();
539 return $this->initUser( $u, false );
543 * Actually add a user to the database.
544 * Give it a User object that has been initialised with a name.
547 * @param bool $autocreate True if this is an autocreation via auth plugin
548 * @return Status Status object, with the User object in the value member on success
551 function initUser( $u, $autocreate ) {
554 $status = $u->addToDatabase();
555 if ( !$status->isOK() ) {
559 if ( $wgAuth->allowPasswordChange() ) {
560 $u->setPassword( $this->mPassword
);
563 $u->setEmail( $this->mEmail
);
564 $u->setRealName( $this->mRealName
);
567 $wgAuth->initUser( $u, $autocreate );
572 DeferredUpdates
::addUpdate( new SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
574 // Watch user's userpage and talk page
575 $u->addWatch( $u->getUserPage(), WatchedItem
::IGNORE_USER_RIGHTS
);
577 return Status
::newGood( $u );
581 * Internally authenticate the login request.
583 * This may create a local account as a side effect if the
584 * authentication plugin allows transparent local account
588 public function authenticateUserData() {
589 global $wgUser, $wgAuth;
593 if ( $this->mUsername
== '' ) {
594 return self
::NO_NAME
;
597 // We require a login token to prevent login CSRF
598 // Handle part of this before incrementing the throttle so
599 // token-less login attempts don't count towards the throttle
600 // but wrong-token attempts do.
602 // If the user doesn't have a login token yet, set one.
603 if ( !self
::getLoginToken() ) {
604 self
::setLoginToken();
606 return self
::NEED_TOKEN
;
608 // If the user didn't pass a login token, tell them we need one
609 if ( !$this->mToken
) {
610 return self
::NEED_TOKEN
;
613 $throttleCount = self
::incLoginThrottle( $this->mUsername
);
614 if ( $throttleCount === true ) {
615 return self
::THROTTLED
;
618 // Validate the login token
619 if ( $this->mToken
!== self
::getLoginToken() ) {
620 return self
::WRONG_TOKEN
;
623 // Load the current user now, and check to see if we're logging in as
624 // the same name. This is necessary because loading the current user
625 // (say by calling getName()) calls the UserLoadFromSession hook, which
626 // potentially creates the user in the database. Until we load $wgUser,
627 // checking for user existence using User::newFromName($name)->getId() below
628 // will effectively be using stale data.
629 if ( $this->getUser()->getName() === $this->mUsername
) {
630 wfDebug( __METHOD__
. ": already logged in as {$this->mUsername}\n" );
632 return self
::SUCCESS
;
635 $u = User
::newFromName( $this->mUsername
);
636 if ( !( $u instanceof User
) ||
!User
::isUsableName( $u->getName() ) ) {
637 return self
::ILLEGAL
;
640 $isAutoCreated = false;
641 if ( $u->getID() == 0 ) {
642 $status = $this->attemptAutoCreate( $u );
643 if ( $status !== self
::SUCCESS
) {
646 $isAutoCreated = true;
652 // Give general extensions, such as a captcha, a chance to abort logins
653 $abort = self
::ABORTED
;
655 if ( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort, &$msg ) ) ) {
656 $this->mAbortLoginErrorMsg
= $msg;
661 global $wgBlockDisablesLogin;
662 if ( !$u->checkPassword( $this->mPassword
) ) {
663 if ( $u->checkTemporaryPassword( $this->mPassword
) ) {
664 // The e-mailed temporary password should not be used for actu-
665 // al logins; that's a very sloppy habit, and insecure if an
666 // attacker has a few seconds to click "search" on someone's o-
669 // Allow it to be used only to reset the password a single time
670 // to a new value, which won't be in the user's e-mail ar-
673 // For backwards compatibility, we'll still recognize it at the
674 // login form to minimize surprises for people who have been
675 // logging in with a temporary password for some time.
677 // As a side-effect, we can authenticate the user's e-mail ad-
678 // dress if it's not already done, since the temporary password
679 // was sent via e-mail.
680 if ( !$u->isEmailConfirmed() ) {
685 // At this point we just return an appropriate code/ indicating
686 // that the UI should show a password reset form; bot inter-
687 // faces etc will probably just fail cleanly here.
688 $this->mAbortLoginErrorMsg
= 'resetpass-temp-emailed';
689 $this->mTempPasswordUsed
= true;
690 $retval = self
::RESET_PASS
;
692 $retval = ( $this->mPassword
== '' ) ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
694 } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
695 // If we've enabled it, make it so that a blocked user cannot login
696 $retval = self
::USER_BLOCKED
;
697 } elseif ( $u->getPasswordExpired() == 'hard' ) {
698 // Force reset now, without logging in
699 $retval = self
::RESET_PASS
;
700 $this->mAbortLoginErrorMsg
= 'resetpass-expired';
702 $wgAuth->updateUser( $u );
704 // This should set it for OutputPage and the Skin
705 // which is needed or the personal links will be
707 $this->getContext()->setUser( $u );
709 // Please reset throttle for successful logins, thanks!
710 if ( $throttleCount ) {
711 self
::clearLoginThrottle( $this->mUsername
);
714 if ( $isAutoCreated ) {
715 // Must be run after $wgUser is set, for correct new user log
716 wfRunHooks( 'AuthPluginAutoCreate', array( $u ) );
719 $retval = self
::SUCCESS
;
721 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
727 * Increment the login attempt throttle hit count for the (username,current IP)
728 * tuple unless the throttle was already reached.
729 * @param string $username The user name
730 * @return bool|int The integer hit count or True if it is already at the limit
732 public static function incLoginThrottle( $username ) {
733 global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest;
734 $username = trim( $username ); // sanity
737 if ( is_array( $wgPasswordAttemptThrottle ) ) {
738 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
739 $count = $wgPasswordAttemptThrottle['count'];
740 $period = $wgPasswordAttemptThrottle['seconds'];
742 $throttleCount = $wgMemc->get( $throttleKey );
743 if ( !$throttleCount ) {
744 $wgMemc->add( $throttleKey, 1, $period ); // start counter
745 } elseif ( $throttleCount < $count ) {
746 $wgMemc->incr( $throttleKey );
747 } elseif ( $throttleCount >= $count ) {
752 return $throttleCount;
756 * Clear the login attempt throttle hit count for the (username,current IP) tuple.
757 * @param string $username The user name
760 public static function clearLoginThrottle( $username ) {
761 global $wgMemc, $wgRequest;
762 $username = trim( $username ); // sanity
764 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
765 $wgMemc->delete( $throttleKey );
769 * Attempt to automatically create a user on login. Only succeeds if there
770 * is an external authentication method which allows it.
774 * @return int Status code
776 function attemptAutoCreate( $user ) {
779 if ( $this->getUser()->isBlockedFromCreateAccount() ) {
780 wfDebug( __METHOD__
. ": user is blocked from account creation\n" );
782 return self
::CREATE_BLOCKED
;
785 if ( !$wgAuth->autoCreate() ) {
786 return self
::NOT_EXISTS
;
789 if ( !$wgAuth->userExists( $user->getName() ) ) {
790 wfDebug( __METHOD__
. ": user does not exist\n" );
792 return self
::NOT_EXISTS
;
795 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
796 wfDebug( __METHOD__
. ": \$wgAuth->authenticate() returned false, aborting\n" );
798 return self
::WRONG_PLUGIN_PASS
;
802 if ( !wfRunHooks( 'AbortAutoAccount', array( $user, &$abortError ) ) ) {
803 // Hook point to add extra creation throttles and blocks
804 wfDebug( "LoginForm::attemptAutoCreate: a hook blocked creation: $abortError\n" );
805 $this->mAbortLoginErrorMsg
= $abortError;
807 return self
::ABORTED
;
810 wfDebug( __METHOD__
. ": creating account\n" );
811 $status = $this->initUser( $user, true );
813 if ( !$status->isOK() ) {
814 $errors = $status->getErrorsByType( 'error' );
815 $this->mAbortLoginErrorMsg
= $errors[0]['message'];
817 return self
::ABORTED
;
820 return self
::SUCCESS
;
823 function processLogin() {
824 global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle,
825 $wgInvalidPasswordReset;
827 switch ( $this->authenticateUserData() ) {
829 # We've verified now, update the real record
830 $user = $this->getUser();
831 $user->invalidateCache();
833 if ( $user->requiresHTTPS() ) {
834 $this->mStickHTTPS
= true;
837 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
838 $user->setCookies( $this->mRequest
, false, $this->mRemember
);
840 $user->setCookies( $this->mRequest
, null, $this->mRemember
);
842 self
::clearLoginToken();
844 // Reset the throttle
845 $request = $this->getRequest();
846 $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername
) );
847 $wgMemc->delete( $key );
849 if ( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
850 /* Replace the language object to provide user interface in
851 * correct language immediately on this first page load.
853 $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
854 $userLang = Language
::factory( $code );
856 $this->getContext()->setLanguage( $userLang );
857 // Reset SessionID on Successful login (bug 40995)
858 $this->renewSessionId();
859 if ( $this->getUser()->getPasswordExpired() == 'soft' ) {
860 $this->resetLoginForm( $this->msg( 'resetpass-expired-soft' ) );
861 } elseif ( $wgInvalidPasswordReset
862 && !$user->isValidPassword( $this->mPassword
)
864 $status = $user->checkPasswordValidity( $this->mPassword
);
865 $this->resetLoginForm(
866 $status->getMessage( 'resetpass-validity-soft' )
869 $this->successfulLogin();
872 $this->cookieRedirectCheck( 'login' );
876 case self
::NEED_TOKEN
:
877 $error = $this->mAbortLoginErrorMsg ?
: 'nocookiesforlogin';
878 $this->mainLoginForm( $this->msg( $error )->parse() );
880 case self
::WRONG_TOKEN
:
881 $error = $this->mAbortLoginErrorMsg ?
: 'sessionfailure';
882 $this->mainLoginForm( $this->msg( $error )->text() );
886 $error = $this->mAbortLoginErrorMsg ?
: 'noname';
887 $this->mainLoginForm( $this->msg( $error )->text() );
889 case self
::WRONG_PLUGIN_PASS
:
890 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpassword';
891 $this->mainLoginForm( $this->msg( $error )->text() );
893 case self
::NOT_EXISTS
:
894 if ( $this->getUser()->isAllowed( 'createaccount' ) ) {
895 $error = $this->mAbortLoginErrorMsg ?
: 'nosuchuser';
896 $this->mainLoginForm( $this->msg( $error,
897 wfEscapeWikiText( $this->mUsername
) )->parse() );
899 $error = $this->mAbortLoginErrorMsg ?
: 'nosuchusershort';
900 $this->mainLoginForm( $this->msg( $error,
901 wfEscapeWikiText( $this->mUsername
) )->text() );
904 case self
::WRONG_PASS
:
905 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpassword';
906 $this->mainLoginForm( $this->msg( $error )->text() );
908 case self
::EMPTY_PASS
:
909 $error = $this->mAbortLoginErrorMsg ?
: 'wrongpasswordempty';
910 $this->mainLoginForm( $this->msg( $error )->text() );
912 case self
::RESET_PASS
:
913 $error = $this->mAbortLoginErrorMsg ?
: 'resetpass_announce';
914 $this->resetLoginForm( $this->msg( $error ) );
916 case self
::CREATE_BLOCKED
:
917 $this->userBlockedMessage( $this->getUser()->isBlockedFromCreateAccount() );
919 case self
::THROTTLED
:
920 $error = $this->mAbortLoginErrorMsg ?
: 'login-throttled';
921 $this->mainLoginForm( $this->msg( $error )
922 ->params( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
926 case self
::USER_BLOCKED
:
927 $error = $this->mAbortLoginErrorMsg ?
: 'login-userblocked';
928 $this->mainLoginForm( $this->msg( $error, $this->mUsername
)->escaped() );
931 $error = $this->mAbortLoginErrorMsg ?
: 'login-abort-generic';
932 $this->mainLoginForm( $this->msg( $error,
933 wfEscapeWikiText( $this->mUsername
) )->text() );
936 throw new MWException( 'Unhandled case value' );
941 * Show the Special:ChangePassword form, with custom message
942 * @param Message $msg
944 protected function resetLoginForm( Message
$msg ) {
945 // Allow hooks to explain this password reset in more detail
946 wfRunHooks( 'LoginPasswordResetMessage', array( &$msg, $this->mUsername
) );
947 $reset = new SpecialChangePassword();
948 $derivative = new DerivativeContext( $this->getContext() );
949 $derivative->setTitle( $reset->getPageTitle() );
950 $reset->setContext( $derivative );
951 if ( !$this->mTempPasswordUsed
) {
952 $reset->setOldPasswordMessage( 'oldpassword' );
954 $reset->setChangeMessage( $msg );
955 $reset->execute( null );
960 * @param bool $throttle
961 * @param string $emailTitle Message name of email title
962 * @param string $emailText Message name of email text
965 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle',
966 $emailText = 'passwordremindertext'
968 global $wgNewPasswordExpiry;
970 if ( $u->getEmail() == '' ) {
971 return Status
::newFatal( 'noemail', $u->getName() );
973 $ip = $this->getRequest()->getIP();
975 return Status
::newFatal( 'badipaddress' );
978 $currentUser = $this->getUser();
979 wfRunHooks( 'User::mailPasswordInternal', array( &$currentUser, &$ip, &$u ) );
981 $np = $u->randomPassword();
982 $u->setNewpassword( $np, $throttle );
984 $userLanguage = $u->getOption( 'language' );
986 $mainPage = Title
::newMainPage();
987 $mainPageUrl = $mainPage->getCanonicalURL();
989 $m = $this->msg( $emailText, $ip, $u->getName(), $np, '<' . $mainPageUrl . '>',
990 round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text();
991 $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m );
997 * Run any hooks registered for logins, then HTTP redirect to
998 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
999 * nice message here, but that's really not as useful as just being sent to
1000 * wherever you logged in from. It should be clear that the action was
1001 * successful, given the lack of error messages plus the appearance of your
1002 * name in the upper right.
1006 function successfulLogin() {
1007 # Run any hooks; display injected HTML if any, else redirect
1008 $currentUser = $this->getUser();
1009 $injected_html = '';
1010 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
1012 if ( $injected_html !== '' ) {
1013 $this->displaySuccessfulAction( 'success', $this->msg( 'loginsuccesstitle' ),
1014 'loginsuccess', $injected_html );
1016 $this->executeReturnTo( 'successredirect' );
1021 * Run any hooks registered for logins, then display a message welcoming
1026 function successfulCreation() {
1027 # Run any hooks; display injected HTML
1028 $currentUser = $this->getUser();
1029 $injected_html = '';
1030 $welcome_creation_msg = 'welcomecreation-msg';
1032 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
1035 * Let any extensions change what message is shown.
1036 * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeWelcomeCreation
1039 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
1041 $this->displaySuccessfulAction(
1043 $this->msg( 'welcomeuser', $this->getUser()->getName() ),
1044 $welcome_creation_msg, $injected_html
1049 * Display a "successful action" page.
1051 * @param string $type condition of return to; see `executeReturnTo`
1052 * @param string|Message $title Page's title
1053 * @param string $msgname
1054 * @param string $injected_html
1056 private function displaySuccessfulAction( $type, $title, $msgname, $injected_html ) {
1057 $out = $this->getOutput();
1058 $out->setPageTitle( $title );
1060 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
1063 $out->addHTML( $injected_html );
1065 $this->executeReturnTo( $type );
1069 * Output a message that informs the user that they cannot create an account because
1070 * there is a block on them or their IP which prevents account creation. Note that
1071 * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
1072 * setting on blocks (bug 13611).
1073 * @param Block $block The block causing this error
1074 * @throws ErrorPageError
1076 function userBlockedMessage( Block
$block ) {
1077 # Let's be nice about this, it's likely that this feature will be used
1078 # for blocking large numbers of innocent people, e.g. range blocks on
1079 # schools. Don't blame it on the user. There's a small chance that it
1080 # really is the user's fault, i.e. the username is blocked and they
1081 # haven't bothered to log out before trying to create an account to
1082 # evade it, but we'll leave that to their guilty conscience to figure
1084 $errorParams = array(
1085 $block->getTarget(),
1086 $block->mReason ?
$block->mReason
: $this->msg( 'blockednoreason' )->text(),
1090 if ( $block->getType() === Block
::TYPE_RANGE
) {
1091 $errorMessage = 'cantcreateaccount-range-text';
1092 $errorParams[] = $this->getRequest()->getIP();
1094 $errorMessage = 'cantcreateaccount-text';
1097 throw new ErrorPageError(
1098 'cantcreateaccounttitle',
1105 * Add a "return to" link or redirect to it.
1106 * Extensions can use this to reuse the "return to" logic after
1107 * inject steps (such as redirection) into the login process.
1109 * @param string $type One of the following:
1110 * - error: display a return to link ignoring $wgRedirectOnLogin
1111 * - signup: display a return to link using $wgRedirectOnLogin if needed
1112 * - success: display a return to link using $wgRedirectOnLogin if needed
1113 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
1114 * @param string $returnTo
1115 * @param array|string $returnToQuery
1116 * @param bool $stickHTTPs Keep redirect link on HTTPs
1119 public function showReturnToPage(
1120 $type, $returnTo = '', $returnToQuery = '', $stickHTTPs = false
1122 $this->mReturnTo
= $returnTo;
1123 $this->mReturnToQuery
= $returnToQuery;
1124 $this->mStickHTTPS
= $stickHTTPs;
1125 $this->executeReturnTo( $type );
1129 * Add a "return to" link or redirect to it.
1131 * @param string $type One of the following:
1132 * - error: display a return to link ignoring $wgRedirectOnLogin
1133 * - signup: display a return to link using $wgRedirectOnLogin if needed
1134 * - success: display a return to link using $wgRedirectOnLogin if needed
1135 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
1137 private function executeReturnTo( $type ) {
1138 global $wgRedirectOnLogin, $wgSecureLogin;
1140 if ( $type != 'error' && $wgRedirectOnLogin !== null ) {
1141 $returnTo = $wgRedirectOnLogin;
1142 $returnToQuery = array();
1144 $returnTo = $this->mReturnTo
;
1145 $returnToQuery = wfCgiToArray( $this->mReturnToQuery
);
1148 // Allow modification of redirect behavior
1149 wfRunHooks( 'PostLoginRedirect', array( &$returnTo, &$returnToQuery, &$type ) );
1151 $returnToTitle = Title
::newFromText( $returnTo );
1152 if ( !$returnToTitle ) {
1153 $returnToTitle = Title
::newMainPage();
1156 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
1157 $options = array( 'http' );
1158 $proto = PROTO_HTTP
;
1159 } elseif ( $wgSecureLogin ) {
1160 $options = array( 'https' );
1161 $proto = PROTO_HTTPS
;
1164 $proto = PROTO_RELATIVE
;
1167 if ( $type == 'successredirect' ) {
1168 $redirectUrl = $returnToTitle->getFullURL( $returnToQuery, false, $proto );
1169 $this->getOutput()->redirect( $redirectUrl );
1171 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
1178 function mainLoginForm( $msg, $msgtype = 'error' ) {
1179 global $wgEnableEmail, $wgEnableUserEmail;
1180 global $wgHiddenPrefs, $wgLoginLanguageSelector;
1181 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
1182 global $wgSecureLogin, $wgPasswordResetRoutes;
1184 $titleObj = $this->getPageTitle();
1185 $user = $this->getUser();
1186 $out = $this->getOutput();
1188 if ( $this->mType
== 'signup' ) {
1189 // Block signup here if in readonly. Keeps user from
1190 // going through the process (filling out data, etc)
1191 // and being informed later.
1192 $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true );
1193 if ( count( $permErrors ) ) {
1194 throw new PermissionsError( 'createaccount', $permErrors );
1195 } elseif ( $user->isBlockedFromCreateAccount() ) {
1196 $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
1199 } elseif ( wfReadOnly() ) {
1200 throw new ReadOnlyError
;
1204 // Pre-fill username (if not creating an account, bug 44775).
1205 if ( $this->mUsername
== '' && $this->mType
!= 'signup' ) {
1206 if ( $user->isLoggedIn() ) {
1207 $this->mUsername
= $user->getName();
1209 $this->mUsername
= $this->getRequest()->getCookie( 'UserName' );
1213 // Generic styles and scripts for both login and signup form
1214 $out->addModuleStyles( array(
1216 'mediawiki.ui.button',
1217 'mediawiki.special.userlogin.common.styles'
1219 $out->addModules( array(
1220 'mediawiki.special.userlogin.common.js'
1223 if ( $this->mType
== 'signup' ) {
1224 // XXX hack pending RL or JS parse() support for complex content messages
1225 // https://bugzilla.wikimedia.org/show_bug.cgi?id=25349
1226 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
1227 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
1229 // Additional styles and scripts for signup form
1230 $out->addModules( array(
1231 'mediawiki.special.userlogin.signup.js'
1233 $out->addModuleStyles( array(
1234 'mediawiki.special.userlogin.signup.styles'
1237 $template = new UsercreateTemplate();
1239 // Must match number of benefits defined in messages
1240 $template->set( 'benefitCount', 3 );
1242 $q = 'action=submitlogin&type=signup';
1243 $linkq = 'type=login';
1245 // Additional styles for login form
1246 $out->addModuleStyles( array(
1247 'mediawiki.special.userlogin.login.styles'
1250 $template = new UserloginTemplate();
1252 $q = 'action=submitlogin&type=login';
1253 $linkq = 'type=signup';
1256 if ( $this->mReturnTo
!== '' ) {
1257 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
1258 if ( $this->mReturnToQuery
!== '' ) {
1259 $returnto .= '&returntoquery=' .
1260 wfUrlencode( $this->mReturnToQuery
);
1263 $linkq .= $returnto;
1266 # Don't show a "create account" link if the user can't.
1267 if ( $this->showCreateOrLoginLink( $user ) ) {
1268 # Pass any language selection on to the mode switch link
1269 if ( $wgLoginLanguageSelector && $this->mLanguage
) {
1270 $linkq .= '&uselang=' . $this->mLanguage
;
1272 // Supply URL, login template creates the button.
1273 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
1275 $template->set( 'link', '' );
1278 $resetLink = $this->mType
== 'signup'
1280 : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );
1282 $template->set( 'header', '' );
1283 $template->set( 'skin', $this->getSkin() );
1284 $template->set( 'name', $this->mUsername
);
1285 $template->set( 'password', $this->mPassword
);
1286 $template->set( 'retype', $this->mRetype
);
1287 $template->set( 'createemailset', $this->mCreateaccountMail
);
1288 $template->set( 'email', $this->mEmail
);
1289 $template->set( 'realname', $this->mRealName
);
1290 $template->set( 'domain', $this->mDomain
);
1291 $template->set( 'reason', $this->mReason
);
1293 $template->set( 'action', $titleObj->getLocalURL( $q ) );
1294 $template->set( 'message', $msg );
1295 $template->set( 'messagetype', $msgtype );
1296 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
1297 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
1298 $template->set( 'useemail', $wgEnableEmail );
1299 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
1300 $template->set( 'emailothers', $wgEnableUserEmail );
1301 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
1302 $template->set( 'resetlink', $resetLink );
1303 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
1304 $template->set( 'usereason', $user->isLoggedIn() );
1305 $template->set( 'remember', $this->mRemember
);
1306 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
1307 $template->set( 'stickhttps', (int)$this->mStickHTTPS
);
1308 $template->set( 'loggedin', $user->isLoggedIn() );
1309 $template->set( 'loggedinuser', $user->getName() );
1311 if ( $this->mType
== 'signup' ) {
1312 if ( !self
::getCreateaccountToken() ) {
1313 self
::setCreateaccountToken();
1315 $template->set( 'token', self
::getCreateaccountToken() );
1317 if ( !self
::getLoginToken() ) {
1318 self
::setLoginToken();
1320 $template->set( 'token', self
::getLoginToken() );
1323 # Prepare language selection links as needed
1324 if ( $wgLoginLanguageSelector ) {
1325 $template->set( 'languages', $this->makeLanguageSelector() );
1326 if ( $this->mLanguage
) {
1327 $template->set( 'uselang', $this->mLanguage
);
1331 $template->set( 'secureLoginUrl', $this->mSecureLoginUrl
);
1332 // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
1333 // Ditto for signupend. New forms use neither.
1334 $usingHTTPS = $this->mRequest
->getProtocol() == 'https';
1335 $loginendHTTPS = $this->msg( 'loginend-https' );
1336 $signupendHTTPS = $this->msg( 'signupend-https' );
1337 if ( $usingHTTPS && !$loginendHTTPS->isBlank() ) {
1338 $template->set( 'loginend', $loginendHTTPS->parse() );
1340 $template->set( 'loginend', $this->msg( 'loginend' )->parse() );
1342 if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) {
1343 $template->set( 'signupend', $signupendHTTPS->parse() );
1345 $template->set( 'signupend', $this->msg( 'signupend' )->parse() );
1348 // Give authentication and captcha plugins a chance to modify the form
1349 $wgAuth->modifyUITemplate( $template, $this->mType
);
1350 if ( $this->mType
== 'signup' ) {
1351 wfRunHooks( 'UserCreateForm', array( &$template ) );
1353 wfRunHooks( 'UserLoginForm', array( &$template ) );
1356 $out->disallowUserJs(); // just in case...
1357 $out->addTemplate( $template );
1361 * Whether the login/create account form should display a link to the
1362 * other form (in addition to whatever the skin provides).
1367 private function showCreateOrLoginLink( &$user ) {
1368 if ( $this->mType
== 'signup' ) {
1370 } elseif ( $user->isAllowed( 'createaccount' ) ) {
1378 * Check if a session cookie is present.
1380 * This will not pick up a cookie set during _this_ request, but is meant
1381 * to ensure that the client is returning the cookie which was set on a
1382 * previous pass through the system.
1387 function hasSessionCookie() {
1388 global $wgDisableCookieCheck;
1390 return $wgDisableCookieCheck ?
true : $this->getRequest()->checkSessionCookie();
1394 * Get the login token from the current session
1397 public static function getLoginToken() {
1400 return $wgRequest->getSessionData( 'wsLoginToken' );
1404 * Randomly generate a new login token and attach it to the current session
1406 public static function setLoginToken() {
1408 // Generate a token directly instead of using $user->getEditToken()
1409 // because the latter reuses $_SESSION['wsEditToken']
1410 $wgRequest->setSessionData( 'wsLoginToken', MWCryptRand
::generateHex( 32 ) );
1414 * Remove any login token attached to the current session
1416 public static function clearLoginToken() {
1418 $wgRequest->setSessionData( 'wsLoginToken', null );
1422 * Get the createaccount token from the current session
1425 public static function getCreateaccountToken() {
1428 return $wgRequest->getSessionData( 'wsCreateaccountToken' );
1432 * Randomly generate a new createaccount token and attach it to the current session
1434 public static function setCreateaccountToken() {
1436 $wgRequest->setSessionData( 'wsCreateaccountToken', MWCryptRand
::generateHex( 32 ) );
1440 * Remove any createaccount token attached to the current session
1442 public static function clearCreateaccountToken() {
1444 $wgRequest->setSessionData( 'wsCreateaccountToken', null );
1448 * Renew the user's session id, using strong entropy
1450 private function renewSessionId() {
1451 global $wgSecureLogin, $wgCookieSecure;
1452 if ( $wgSecureLogin && !$this->mStickHTTPS
) {
1453 $wgCookieSecure = false;
1462 function cookieRedirectCheck( $type ) {
1463 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
1464 $query = array( 'wpCookieCheck' => $type );
1465 if ( $this->mReturnTo
!== '' ) {
1466 $query['returnto'] = $this->mReturnTo
;
1467 $query['returntoquery'] = $this->mReturnToQuery
;
1469 $check = $titleObj->getFullURL( $query );
1471 $this->getOutput()->redirect( $check );
1477 function onCookieRedirectCheck( $type ) {
1478 if ( !$this->hasSessionCookie() ) {
1479 if ( $type == 'new' ) {
1480 $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
1481 } elseif ( $type == 'login' ) {
1482 $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
1485 $this->mainLoginForm( $this->msg( 'error' )->text() );
1488 $this->successfulLogin();
1493 * Produce a bar of links which allow the user to select another language
1494 * during login/registration but retain "returnto"
1498 function makeLanguageSelector() {
1499 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1500 if ( !$msg->isBlank() ) {
1501 $langs = explode( "\n", $msg->text() );
1503 foreach ( $langs as $lang ) {
1504 $lang = trim( $lang, '* ' );
1505 $parts = explode( '|', $lang );
1506 if ( count( $parts ) >= 2 ) {
1507 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1511 return count( $links ) > 0 ?
$this->msg( 'loginlanguagelabel' )->rawParams(
1512 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1519 * Create a language selector link for a particular language
1520 * Links back to this page preserving type and returnto
1522 * @param string $text Link text
1523 * @param string $lang Language code
1526 function makeLanguageSelectorLink( $text, $lang ) {
1527 if ( $this->getLanguage()->getCode() == $lang ) {
1528 // no link for currently used language
1529 return htmlspecialchars( $text );
1531 $query = array( 'uselang' => $lang );
1532 if ( $this->mType
== 'signup' ) {
1533 $query['type'] = 'signup';
1535 if ( $this->mReturnTo
!== '' ) {
1536 $query['returnto'] = $this->mReturnTo
;
1537 $query['returntoquery'] = $this->mReturnToQuery
;
1541 $targetLanguage = Language
::factory( $lang );
1542 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1544 return Linker
::linkKnown(
1545 $this->getPageTitle(),
1546 htmlspecialchars( $text ),
1552 protected function getGroupName() {