DifferenceEngine cleanup
[mediawiki.git] / includes / specials / SpecialUserlogin.php
blobf40966c2cc52d0b0f8244772a8e679da560b723d
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Implements Special:UserLogin
27 * @ingroup SpecialPage
29 class LoginForm extends SpecialPage {
31 const SUCCESS = 0;
32 const NO_NAME = 1;
33 const ILLEGAL = 2;
34 const WRONG_PLUGIN_PASS = 3;
35 const NOT_EXISTS = 4;
36 const WRONG_PASS = 5;
37 const EMPTY_PASS = 6;
38 const RESET_PASS = 7;
39 const ABORTED = 8;
40 const CREATE_BLOCKED = 9;
41 const THROTTLED = 10;
42 const USER_BLOCKED = 11;
43 const NEED_TOKEN = 12;
44 const WRONG_TOKEN = 13;
46 var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
47 var $mAction, $mCreateaccount, $mCreateaccountMail;
48 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
49 var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
50 var $mType, $mReason, $mRealName;
51 var $mAbortLoginErrorMsg = null;
52 private $mLoaded = false;
53 private $mSecureLoginUrl;
55 /**
56 * @ var WebRequest
58 private $mOverrideRequest = null;
60 /**
61 * Effective request; set at the beginning of load
63 * @var WebRequest $mRequest
65 private $mRequest = null;
67 /**
68 * @param WebRequest $request
70 public function __construct( $request = null ) {
71 parent::__construct( 'Userlogin' );
73 $this->mOverrideRequest = $request;
76 /**
77 * Loader
79 function load() {
80 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
82 if ( $this->mLoaded ) {
83 return;
85 $this->mLoaded = true;
87 if ( $this->mOverrideRequest === null ) {
88 $request = $this->getRequest();
89 } else {
90 $request = $this->mOverrideRequest;
92 $this->mRequest = $request;
94 $this->mType = $request->getText( 'type' );
95 $this->mUsername = $request->getText( 'wpName' );
96 $this->mPassword = $request->getText( 'wpPassword' );
97 $this->mRetype = $request->getText( 'wpRetype' );
98 $this->mDomain = $request->getText( 'wpDomain' );
99 $this->mReason = $request->getText( 'wpReason' );
100 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
101 $this->mPosted = $request->wasPosted();
102 $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
103 && $wgEnableEmail;
104 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ) && !$this->mCreateaccountMail;
105 $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
106 $this->mAction = $request->getVal( 'action' );
107 $this->mRemember = $request->getCheck( 'wpRemember' );
108 $this->mFromHTTP = $request->getBool( 'fromhttp', false );
109 $this->mStickHTTPS = ( !$this->mFromHTTP && $request->getProtocol() === 'https' ) || $request->getBool( 'wpForceHttps', false );
110 $this->mLanguage = $request->getText( 'uselang' );
111 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
112 $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
113 $this->mReturnTo = $request->getVal( 'returnto', '' );
114 $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
116 if ( $wgEnableEmail ) {
117 $this->mEmail = $request->getText( 'wpEmail' );
118 } else {
119 $this->mEmail = '';
121 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
122 $this->mRealName = $request->getText( 'wpRealName' );
123 } else {
124 $this->mRealName = '';
127 if ( !$wgAuth->validDomain( $this->mDomain ) ) {
128 $this->mDomain = $wgAuth->getDomain();
130 $wgAuth->setDomain( $this->mDomain );
132 # 1. When switching accounts, it sucks to get automatically logged out
133 # 2. Do not return to PasswordReset after a successful password change
134 # but goto Wiki start page (Main_Page) instead ( bug 33997 )
135 $returnToTitle = Title::newFromText( $this->mReturnTo );
136 if ( is_object( $returnToTitle ) && (
137 $returnToTitle->isSpecial( 'Userlogout' )
138 || $returnToTitle->isSpecial( 'PasswordReset' ) ) ) {
139 $this->mReturnTo = '';
140 $this->mReturnToQuery = '';
144 function getDescription() {
145 if ( $this->mType === 'signup' ) {
146 return $this->msg( 'createaccount' )->text();
147 } else {
148 return $this->msg( 'login' )->text();
153 * @param $subPage string|null
155 public function execute( $subPage ) {
156 if ( session_id() == '' ) {
157 wfSetupSession();
160 $this->load();
162 // Check for [[Special:Userlogin/signup]]. This affects form display and
163 // page title.
164 if ( $subPage == 'signup' ) {
165 $this->mType = 'signup';
167 $this->setHeaders();
169 // If logging in and not on HTTPS, either redirect to it or offer a link.
170 global $wgSecureLogin;
171 if ( $this->mRequest->getProtocol() !== 'https' ) {
172 $title = $this->getFullTitle();
173 $query = array(
174 'returnto' => $this->mReturnTo,
175 'returntoquery' => $this->mReturnToQuery,
176 'title' => null,
177 ) + $this->mRequest->getQueryValues();
178 $url = $title->getFullURL( $query, false, PROTO_HTTPS );
179 if ( $wgSecureLogin && wfCanIPUseHTTPS( $this->getRequest()->getIP() ) ) {
180 $url = wfAppendQuery( $url, 'fromhttp=1' );
181 $this->getOutput()->redirect( $url );
182 // Since we only do this redir to change proto, always vary
183 $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
184 return;
185 } else {
186 // A wiki without HTTPS login support should set $wgServer to
187 // http://somehost, in which case the secure URL generated
188 // above won't actually start with https://
189 if ( substr( $url, 0, 8 ) === 'https://' ) {
190 $this->mSecureLoginUrl = $url;
195 if ( !is_null( $this->mCookieCheck ) ) {
196 $this->onCookieRedirectCheck( $this->mCookieCheck );
197 return;
198 } elseif ( $this->mPosted ) {
199 if ( $this->mCreateaccount ) {
200 $this->addNewAccount();
201 return;
202 } elseif ( $this->mCreateaccountMail ) {
203 $this->addNewAccountMailPassword();
204 return;
205 } elseif ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
206 $this->processLogin();
207 return;
210 $this->mainLoginForm( '' );
214 * @private
216 function addNewAccountMailPassword() {
217 if ( $this->mEmail == '' ) {
218 $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() );
219 return;
222 $status = $this->addNewaccountInternal();
223 if ( !$status->isGood() ) {
224 $error = $status->getMessage();
225 $this->mainLoginForm( $error->toString() );
226 return;
229 $u = $status->getValue();
231 // Wipe the initial password and mail a temporary one
232 $u->setPassword( null );
233 $u->saveSettings();
234 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
236 wfRunHooks( 'AddNewAccount', array( $u, true ) );
237 $u->addNewUserLogEntry( 'byemail', $this->mReason );
239 $out = $this->getOutput();
240 $out->setPageTitle( $this->msg( 'accmailtitle' ) );
242 if ( !$result->isGood() ) {
243 $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
244 } else {
245 $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
246 $this->executeReturnTo( 'success' );
251 * @private
252 * @return bool
254 function addNewAccount() {
255 global $wgContLang, $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
257 # Create the account and abort if there's a problem doing so
258 $status = $this->addNewAccountInternal();
259 if ( !$status->isGood() ) {
260 $error = $status->getMessage();
261 $this->mainLoginForm( $error->toString() );
262 return false;
265 $u = $status->getValue();
267 # Only save preferences if the user is not creating an account for someone else.
268 if ( $this->getUser()->isAnon() ) {
269 # If we showed up language selection links, and one was in use, be
270 # smart (and sensible) and save that language as the user's preference
271 if ( $wgLoginLanguageSelector && $this->mLanguage ) {
272 $u->setOption( 'language', $this->mLanguage );
273 } else {
275 # Otherwise the user's language preference defaults to $wgContLang,
276 # but it may be better to set it to their preferred $wgContLang variant,
277 # based on browser preferences or URL parameters.
278 $u->setOption( 'language', $wgContLang->getPreferredVariant() );
280 if ( $wgContLang->hasVariants() ) {
281 $u->setOption( 'variant', $wgContLang->getPreferredVariant() );
285 $out = $this->getOutput();
287 # Send out an email authentication message if needed
288 if ( $wgEmailAuthentication && Sanitizer::validateEmail( $u->getEmail() ) ) {
289 $status = $u->sendConfirmationMail();
290 if ( $status->isGood() ) {
291 $out->addWikiMsg( 'confirmemail_oncreate' );
292 } else {
293 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
297 # Save settings (including confirmation token)
298 $u->saveSettings();
300 # If not logged in, assume the new account as the current one and set
301 # session cookies then show a "welcome" message or a "need cookies"
302 # message as needed
303 if ( $this->getUser()->isAnon() ) {
304 $u->setCookies();
305 $wgUser = $u;
306 // This should set it for OutputPage and the Skin
307 // which is needed or the personal links will be
308 // wrong.
309 $this->getContext()->setUser( $u );
310 wfRunHooks( 'AddNewAccount', array( $u, false ) );
311 $u->addNewUserLogEntry( 'create' );
312 if ( $this->hasSessionCookie() ) {
313 $this->successfulCreation();
314 } else {
315 $this->cookieRedirectCheck( 'new' );
317 } else {
318 # Confirm that the account was created
319 $out->setPageTitle( $this->msg( 'accountcreated' ) );
320 $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
321 $out->addReturnTo( $this->getTitle() );
322 wfRunHooks( 'AddNewAccount', array( $u, false ) );
323 $u->addNewUserLogEntry( 'create2', $this->mReason );
325 return true;
329 * Make a new user account using the loaded data.
330 * @private
331 * @throws PermissionsError|ReadOnlyError
332 * @return Status
334 public function addNewAccountInternal() {
335 global $wgAuth, $wgMemc, $wgAccountCreationThrottle,
336 $wgMinimalPasswordLength, $wgEmailConfirmToEdit;
338 // If the user passes an invalid domain, something is fishy
339 if ( !$wgAuth->validDomain( $this->mDomain ) ) {
340 return Status::newFatal( 'wrongpassword' );
343 // If we are not allowing users to login locally, we should be checking
344 // to see if the user is actually able to authenticate to the authenti-
345 // cation server before they create an account (otherwise, they can
346 // create a local account and login as any domain user). We only need
347 // to check this for domains that aren't local.
348 if ( 'local' != $this->mDomain && $this->mDomain != '' ) {
349 if (
350 !$wgAuth->canCreateAccounts() &&
352 !$wgAuth->userExists( $this->mUsername ) ||
353 !$wgAuth->authenticate( $this->mUsername, $this->mPassword )
356 return Status::newFatal( 'wrongpassword' );
360 if ( wfReadOnly() ) {
361 throw new ReadOnlyError;
364 # Request forgery checks.
365 if ( !self::getCreateaccountToken() ) {
366 self::setCreateaccountToken();
367 return Status::newFatal( 'nocookiesfornew' );
370 # The user didn't pass a createaccount token
371 if ( !$this->mToken ) {
372 return Status::newFatal( 'sessionfailure' );
375 # Validate the createaccount token
376 if ( $this->mToken !== self::getCreateaccountToken() ) {
377 return Status::newFatal( 'sessionfailure' );
380 # Check permissions
381 $currentUser = $this->getUser();
382 $creationBlock = $currentUser->isBlockedFromCreateAccount();
383 if ( !$currentUser->isAllowed( 'createaccount' ) ) {
384 throw new PermissionsError( 'createaccount' );
385 } elseif ( $creationBlock instanceof Block ) {
386 // Throws an ErrorPageError.
387 $this->userBlockedMessage( $creationBlock );
388 // This should never be reached.
389 return false;
392 # Include checks that will include GlobalBlocking (Bug 38333)
393 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'createaccount', $currentUser, true );
394 if ( count( $permErrors ) ) {
395 throw new PermissionsError( 'createaccount', $permErrors );
398 $ip = $this->getRequest()->getIP();
399 if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
400 return Status::newFatal( 'sorbs_create_account_reason' );
403 # Now create a dummy user ($u) and check if it is valid
404 $name = trim( $this->mUsername );
405 $u = User::newFromName( $name, 'creatable' );
406 if ( !is_object( $u ) ) {
407 return Status::newFatal( 'noname' );
408 } elseif ( 0 != $u->idForName() ) {
409 return Status::newFatal( 'userexists' );
412 if ( $this->mCreateaccountMail ) {
413 # do not force a password for account creation by email
414 # set invalid password, it will be replaced later by a random generated password
415 $this->mPassword = null;
416 } else {
417 if ( $this->mPassword !== $this->mRetype ) {
418 return Status::newFatal( 'badretype' );
421 # check for minimal password length
422 $valid = $u->getPasswordValidity( $this->mPassword );
423 if ( $valid !== true ) {
424 if ( !is_array( $valid ) ) {
425 $valid = array( $valid, $wgMinimalPasswordLength );
427 return call_user_func_array( 'Status::newFatal', $valid );
431 # if you need a confirmed email address to edit, then obviously you
432 # need an email address.
433 if ( $wgEmailConfirmToEdit && strval( $this->mEmail ) === '' ) {
434 return Status::newFatal( 'noemailtitle' );
437 if ( strval( $this->mEmail ) !== '' && !Sanitizer::validateEmail( $this->mEmail ) ) {
438 return Status::newFatal( 'invalidemailaddress' );
441 # Set some additional data so the AbortNewAccount hook can be used for
442 # more than just username validation
443 $u->setEmail( $this->mEmail );
444 $u->setRealName( $this->mRealName );
446 $abortError = '';
447 if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
448 // Hook point to add extra creation throttles and blocks
449 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
450 $abortError = new RawMessage( $abortError );
451 $abortError->text();
452 return Status::newFatal( $abortError );
455 // Hook point to check for exempt from account creation throttle
456 if ( !wfRunHooks( 'ExemptFromAccountCreationThrottle', array( $ip ) ) ) {
457 wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook allowed account creation w/o throttle\n" );
458 } else {
459 if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
460 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
461 $value = $wgMemc->get( $key );
462 if ( !$value ) {
463 $wgMemc->set( $key, 0, 86400 );
465 if ( $value >= $wgAccountCreationThrottle ) {
466 return Status::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle );
468 $wgMemc->incr( $key );
472 if ( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) {
473 return Status::newFatal( 'externaldberror' );
476 self::clearCreateaccountToken();
477 return $this->initUser( $u, false );
481 * Actually add a user to the database.
482 * Give it a User object that has been initialised with a name.
484 * @param $u User object.
485 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
486 * @return Status object, with the User object in the value member on success
487 * @private
489 function initUser( $u, $autocreate ) {
490 global $wgAuth;
492 $status = $u->addToDatabase();
493 if ( !$status->isOK() ) {
494 return $status;
497 if ( $wgAuth->allowPasswordChange() ) {
498 $u->setPassword( $this->mPassword );
501 $u->setEmail( $this->mEmail );
502 $u->setRealName( $this->mRealName );
503 $u->setToken();
505 $wgAuth->initUser( $u, $autocreate );
507 $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
508 $u->saveSettings();
510 # Update user count
511 DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
513 return Status::newGood( $u );
517 * Internally authenticate the login request.
519 * This may create a local account as a side effect if the
520 * authentication plugin allows transparent local account
521 * creation.
522 * @return int
524 public function authenticateUserData() {
525 global $wgUser, $wgAuth;
527 $this->load();
529 if ( $this->mUsername == '' ) {
530 return self::NO_NAME;
533 // We require a login token to prevent login CSRF
534 // Handle part of this before incrementing the throttle so
535 // token-less login attempts don't count towards the throttle
536 // but wrong-token attempts do.
538 // If the user doesn't have a login token yet, set one.
539 if ( !self::getLoginToken() ) {
540 self::setLoginToken();
541 return self::NEED_TOKEN;
543 // If the user didn't pass a login token, tell them we need one
544 if ( !$this->mToken ) {
545 return self::NEED_TOKEN;
548 $throttleCount = self::incLoginThrottle( $this->mUsername );
549 if ( $throttleCount === true ) {
550 return self::THROTTLED;
553 // Validate the login token
554 if ( $this->mToken !== self::getLoginToken() ) {
555 return self::WRONG_TOKEN;
558 // Load the current user now, and check to see if we're logging in as
559 // the same name. This is necessary because loading the current user
560 // (say by calling getName()) calls the UserLoadFromSession hook, which
561 // potentially creates the user in the database. Until we load $wgUser,
562 // checking for user existence using User::newFromName($name)->getId() below
563 // will effectively be using stale data.
564 if ( $this->getUser()->getName() === $this->mUsername ) {
565 wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" );
566 return self::SUCCESS;
569 $u = User::newFromName( $this->mUsername );
570 if ( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) {
571 return self::ILLEGAL;
574 $isAutoCreated = false;
575 if ( $u->getID() == 0 ) {
576 $status = $this->attemptAutoCreate( $u );
577 if ( $status !== self::SUCCESS ) {
578 return $status;
579 } else {
580 $isAutoCreated = true;
582 } else {
583 $u->load();
586 // Give general extensions, such as a captcha, a chance to abort logins
587 $abort = self::ABORTED;
588 $msg = null;
589 if ( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort, &$msg ) ) ) {
590 $this->mAbortLoginErrorMsg = $msg;
591 return $abort;
594 global $wgBlockDisablesLogin;
595 if ( !$u->checkPassword( $this->mPassword ) ) {
596 if ( $u->checkTemporaryPassword( $this->mPassword ) ) {
597 // The e-mailed temporary password should not be used for actu-
598 // al logins; that's a very sloppy habit, and insecure if an
599 // attacker has a few seconds to click "search" on someone's o-
600 // pen mail reader.
602 // Allow it to be used only to reset the password a single time
603 // to a new value, which won't be in the user's e-mail ar-
604 // chives.
606 // For backwards compatibility, we'll still recognize it at the
607 // login form to minimize surprises for people who have been
608 // logging in with a temporary password for some time.
610 // As a side-effect, we can authenticate the user's e-mail ad-
611 // dress if it's not already done, since the temporary password
612 // was sent via e-mail.
613 if ( !$u->isEmailConfirmed() ) {
614 $u->confirmEmail();
615 $u->saveSettings();
618 // At this point we just return an appropriate code/ indicating
619 // that the UI should show a password reset form; bot inter-
620 // faces etc will probably just fail cleanly here.
621 $retval = self::RESET_PASS;
622 } else {
623 $retval = ( $this->mPassword == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
625 } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
626 // If we've enabled it, make it so that a blocked user cannot login
627 $retval = self::USER_BLOCKED;
628 } else {
629 $wgAuth->updateUser( $u );
630 $wgUser = $u;
631 // This should set it for OutputPage and the Skin
632 // which is needed or the personal links will be
633 // wrong.
634 $this->getContext()->setUser( $u );
636 // Please reset throttle for successful logins, thanks!
637 if ( $throttleCount ) {
638 self::clearLoginThrottle( $this->mUsername );
641 if ( $isAutoCreated ) {
642 // Must be run after $wgUser is set, for correct new user log
643 wfRunHooks( 'AuthPluginAutoCreate', array( $u ) );
646 $retval = self::SUCCESS;
648 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
649 return $retval;
653 * Increment the login attempt throttle hit count for the (username,current IP)
654 * tuple unless the throttle was already reached.
655 * @param string $username The user name
656 * @return Bool|Integer The integer hit count or True if it is already at the limit
658 public static function incLoginThrottle( $username ) {
659 global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest;
660 $username = trim( $username ); // sanity
662 $throttleCount = 0;
663 if ( is_array( $wgPasswordAttemptThrottle ) ) {
664 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
665 $count = $wgPasswordAttemptThrottle['count'];
666 $period = $wgPasswordAttemptThrottle['seconds'];
668 $throttleCount = $wgMemc->get( $throttleKey );
669 if ( !$throttleCount ) {
670 $wgMemc->add( $throttleKey, 1, $period ); // start counter
671 } elseif ( $throttleCount < $count ) {
672 $wgMemc->incr( $throttleKey );
673 } elseif ( $throttleCount >= $count ) {
674 return true;
678 return $throttleCount;
682 * Clear the login attempt throttle hit count for the (username,current IP) tuple.
683 * @param string $username The user name
684 * @return void
686 public static function clearLoginThrottle( $username ) {
687 global $wgMemc, $wgRequest;
688 $username = trim( $username ); // sanity
690 $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
691 $wgMemc->delete( $throttleKey );
695 * Attempt to automatically create a user on login. Only succeeds if there
696 * is an external authentication method which allows it.
698 * @param $user User
700 * @return integer Status code
702 function attemptAutoCreate( $user ) {
703 global $wgAuth;
705 if ( $this->getUser()->isBlockedFromCreateAccount() ) {
706 wfDebug( __METHOD__ . ": user is blocked from account creation\n" );
707 return self::CREATE_BLOCKED;
709 if ( !$wgAuth->autoCreate() ) {
710 return self::NOT_EXISTS;
712 if ( !$wgAuth->userExists( $user->getName() ) ) {
713 wfDebug( __METHOD__ . ": user does not exist\n" );
714 return self::NOT_EXISTS;
716 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) {
717 wfDebug( __METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n" );
718 return self::WRONG_PLUGIN_PASS;
721 $abortError = '';
722 if ( !wfRunHooks( 'AbortAutoAccount', array( $user, &$abortError ) ) ) {
723 // Hook point to add extra creation throttles and blocks
724 wfDebug( "LoginForm::attemptAutoCreate: a hook blocked creation: $abortError\n" );
725 $this->mAbortLoginErrorMsg = $abortError;
726 return self::ABORTED;
729 wfDebug( __METHOD__ . ": creating account\n" );
730 $status = $this->initUser( $user, true );
732 if ( !$status->isOK() ) {
733 $errors = $status->getErrorsByType( 'error' );
734 $this->mAbortLoginErrorMsg = $errors[0]['message'];
735 return self::ABORTED;
738 return self::SUCCESS;
741 function processLogin() {
742 global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle;
744 switch ( $this->authenticateUserData() ) {
745 case self::SUCCESS:
746 # We've verified now, update the real record
747 $user = $this->getUser();
748 if ( (bool)$this->mRemember != $user->getBoolOption( 'rememberpassword' ) ) {
749 $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
750 $user->saveSettings();
751 } else {
752 $user->invalidateCache();
755 if ( $user->requiresHTTPS() ) {
756 $this->mStickHTTPS = true;
759 if ( $wgSecureLogin && !$this->mStickHTTPS ) {
760 $user->setCookies( null, false );
761 } else {
762 $user->setCookies();
764 self::clearLoginToken();
766 // Reset the throttle
767 $request = $this->getRequest();
768 $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername ) );
769 $wgMemc->delete( $key );
771 if ( $this->hasSessionCookie() || $this->mSkipCookieCheck ) {
772 /* Replace the language object to provide user interface in
773 * correct language immediately on this first page load.
775 $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
776 $userLang = Language::factory( $code );
777 $wgLang = $userLang;
778 $this->getContext()->setLanguage( $userLang );
779 // Reset SessionID on Successful login (bug 40995)
780 $this->renewSessionId();
781 $this->successfulLogin();
782 } else {
783 $this->cookieRedirectCheck( 'login' );
785 break;
787 case self::NEED_TOKEN:
788 $error = $this->mAbortLoginErrorMsg ?: 'nocookiesforlogin';
789 $this->mainLoginForm( $this->msg( $error )->parse() );
790 break;
791 case self::WRONG_TOKEN:
792 $error = $this->mAbortLoginErrorMsg ?: 'sessionfailure';
793 $this->mainLoginForm( $this->msg( $error )->text() );
794 break;
795 case self::NO_NAME:
796 case self::ILLEGAL:
797 $error = $this->mAbortLoginErrorMsg ?: 'noname';
798 $this->mainLoginForm( $this->msg( $error )->text() );
799 break;
800 case self::WRONG_PLUGIN_PASS:
801 $error = $this->mAbortLoginErrorMsg ?: 'wrongpassword';
802 $this->mainLoginForm( $this->msg( $error )->text() );
803 break;
804 case self::NOT_EXISTS:
805 if ( $this->getUser()->isAllowed( 'createaccount' ) ) {
806 $error = $this->mAbortLoginErrorMsg ?: 'nosuchuser';
807 $this->mainLoginForm( $this->msg( $error,
808 wfEscapeWikiText( $this->mUsername ) )->parse() );
809 } else {
810 $error = $this->mAbortLoginErrorMsg ?: 'nosuchusershort';
811 $this->mainLoginForm( $this->msg( $error,
812 wfEscapeWikiText( $this->mUsername ) )->text() );
814 break;
815 case self::WRONG_PASS:
816 $error = $this->mAbortLoginErrorMsg ?: 'wrongpassword';
817 $this->mainLoginForm( $this->msg( $error )->text() );
818 break;
819 case self::EMPTY_PASS:
820 $error = $this->mAbortLoginErrorMsg ?: 'wrongpasswordempty';
821 $this->mainLoginForm( $this->msg( $error )->text() );
822 break;
823 case self::RESET_PASS:
824 $error = $this->mAbortLoginErrorMsg ?: 'resetpass_announce';
825 $this->resetLoginForm( $this->msg( $error )->text() );
826 break;
827 case self::CREATE_BLOCKED:
828 $this->userBlockedMessage( $this->getUser()->isBlockedFromCreateAccount() );
829 break;
830 case self::THROTTLED:
831 $error = $this->mAbortLoginErrorMsg ?: 'login-throttled';
832 $this->mainLoginForm( $this->msg( $error )
833 ->params ( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
834 ->text()
836 break;
837 case self::USER_BLOCKED:
838 $error = $this->mAbortLoginErrorMsg ?: 'login-userblocked';
839 $this->mainLoginForm( $this->msg( $error, $this->mUsername )->escaped() );
840 break;
841 case self::ABORTED:
842 $error = $this->mAbortLoginErrorMsg ?: 'login-abort-generic';
843 $this->mainLoginForm( $this->msg( $error )->text() );
844 break;
845 default:
846 throw new MWException( 'Unhandled case value' );
851 * @param $error string
853 function resetLoginForm( $error ) {
854 $this->getOutput()->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $error ) );
855 $reset = new SpecialChangePassword();
856 $reset->setContext( $this->getContext() );
857 $reset->execute( null );
861 * @param $u User object
862 * @param $throttle Boolean
863 * @param string $emailTitle message name of email title
864 * @param string $emailText message name of email text
865 * @return Status object
867 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
868 global $wgCanonicalServer, $wgScript, $wgNewPasswordExpiry;
870 if ( $u->getEmail() == '' ) {
871 return Status::newFatal( 'noemail', $u->getName() );
873 $ip = $this->getRequest()->getIP();
874 if ( !$ip ) {
875 return Status::newFatal( 'badipaddress' );
878 $currentUser = $this->getUser();
879 wfRunHooks( 'User::mailPasswordInternal', array( &$currentUser, &$ip, &$u ) );
881 $np = $u->randomPassword();
882 $u->setNewpassword( $np, $throttle );
883 $u->saveSettings();
884 $userLanguage = $u->getOption( 'language' );
885 $m = $this->msg( $emailText, $ip, $u->getName(), $np, '<' . $wgCanonicalServer . $wgScript . '>',
886 round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text();
887 $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m );
889 return $result;
893 * Run any hooks registered for logins, then HTTP redirect to
894 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
895 * nice message here, but that's really not as useful as just being sent to
896 * wherever you logged in from. It should be clear that the action was
897 * successful, given the lack of error messages plus the appearance of your
898 * name in the upper right.
900 * @private
902 function successfulLogin() {
903 # Run any hooks; display injected HTML if any, else redirect
904 $currentUser = $this->getUser();
905 $injected_html = '';
906 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
908 if ( $injected_html !== '' ) {
909 $this->displaySuccessfulAction( $this->msg( 'loginsuccesstitle' ),
910 'loginsuccess', $injected_html );
911 } else {
912 $this->executeReturnTo( 'successredirect' );
917 * Run any hooks registered for logins, then display a message welcoming
918 * the user.
920 * @private
922 function successfulCreation() {
923 # Run any hooks; display injected HTML
924 $currentUser = $this->getUser();
925 $injected_html = '';
926 $welcome_creation_msg = 'welcomecreation-msg';
928 wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
931 * Let any extensions change what message is shown.
932 * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeWelcomeCreation
933 * @since 1.18
935 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
937 $this->displaySuccessfulAction( $this->msg( 'welcomeuser', $this->getUser()->getName() ),
938 $welcome_creation_msg, $injected_html );
942 * Display an "successful action" page.
944 * @param string|Message $title page's title
945 * @param $msgname string
946 * @param $injected_html string
948 private function displaySuccessfulAction( $title, $msgname, $injected_html ) {
949 $out = $this->getOutput();
950 $out->setPageTitle( $title );
951 if ( $msgname ) {
952 $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
955 $out->addHTML( $injected_html );
957 $this->executeReturnTo( 'success' );
961 * Output a message that informs the user that they cannot create an account because
962 * there is a block on them or their IP which prevents account creation. Note that
963 * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
964 * setting on blocks (bug 13611).
965 * @param $block Block the block causing this error
966 * @throws ErrorPageError
968 function userBlockedMessage( Block $block ) {
969 # Let's be nice about this, it's likely that this feature will be used
970 # for blocking large numbers of innocent people, e.g. range blocks on
971 # schools. Don't blame it on the user. There's a small chance that it
972 # really is the user's fault, i.e. the username is blocked and they
973 # haven't bothered to log out before trying to create an account to
974 # evade it, but we'll leave that to their guilty conscience to figure
975 # out.
976 throw new ErrorPageError(
977 'cantcreateaccounttitle',
978 'cantcreateaccount-text',
979 array(
980 $block->getTarget(),
981 $block->mReason ? $block->mReason : $this->msg( 'blockednoreason' )->text(),
982 $block->getByName()
988 * Add a "return to" link or redirect to it.
989 * Extensions can use this to reuse the "return to" logic after
990 * inject steps (such as redirection) into the login process.
992 * @param $type string, one of the following:
993 * - error: display a return to link ignoring $wgRedirectOnLogin
994 * - success: display a return to link using $wgRedirectOnLogin if needed
995 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
996 * @param string $returnTo
997 * @param array|string $returnToQuery
998 * @param bool $stickHTTPs Keep redirect link on HTTPs
999 * @since 1.22
1001 public function showReturnToPage(
1002 $type, $returnTo = '', $returnToQuery = '', $stickHTTPs = false
1004 $this->mReturnTo = $returnTo;
1005 $this->mReturnToQuery = $returnToQuery;
1006 $this->mStickHTTPS = $stickHTTPs;
1007 $this->executeReturnTo( $type );
1011 * Add a "return to" link or redirect to it.
1013 * @param $type string, one of the following:
1014 * - error: display a return to link ignoring $wgRedirectOnLogin
1015 * - success: display a return to link using $wgRedirectOnLogin if needed
1016 * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
1018 private function executeReturnTo( $type ) {
1019 global $wgRedirectOnLogin, $wgSecureLogin;
1021 if ( $type != 'error' && $wgRedirectOnLogin !== null ) {
1022 $returnTo = $wgRedirectOnLogin;
1023 $returnToQuery = array();
1024 } else {
1025 $returnTo = $this->mReturnTo;
1026 $returnToQuery = wfCgiToArray( $this->mReturnToQuery );
1029 $returnToTitle = Title::newFromText( $returnTo );
1030 if ( !$returnToTitle ) {
1031 $returnToTitle = Title::newMainPage();
1034 if ( $wgSecureLogin && !$this->mStickHTTPS ) {
1035 $options = array( 'http' );
1036 $proto = PROTO_HTTP;
1037 } elseif ( $wgSecureLogin ) {
1038 $options = array( 'https' );
1039 $proto = PROTO_HTTPS;
1040 } else {
1041 $options = array();
1042 $proto = PROTO_RELATIVE;
1045 if ( $type == 'successredirect' ) {
1046 $redirectUrl = $returnToTitle->getFullURL( $returnToQuery, false, $proto );
1047 $this->getOutput()->redirect( $redirectUrl );
1048 } else {
1049 $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
1054 * @private
1056 function mainLoginForm( $msg, $msgtype = 'error' ) {
1057 global $wgEnableEmail, $wgEnableUserEmail;
1058 global $wgHiddenPrefs, $wgLoginLanguageSelector;
1059 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
1060 global $wgSecureLogin, $wgPasswordResetRoutes;
1062 $titleObj = $this->getTitle();
1063 $user = $this->getUser();
1064 $out = $this->getOutput();
1066 if ( $this->mType == 'signup' ) {
1067 // Block signup here if in readonly. Keeps user from
1068 // going through the process (filling out data, etc)
1069 // and being informed later.
1070 $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true );
1071 if ( count( $permErrors ) ) {
1072 throw new PermissionsError( 'createaccount', $permErrors );
1073 } elseif ( $user->isBlockedFromCreateAccount() ) {
1074 $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
1075 return;
1076 } elseif ( wfReadOnly() ) {
1077 throw new ReadOnlyError;
1081 // Pre-fill username (if not creating an account, bug 44775).
1082 if ( $this->mUsername == '' && $this->mType != 'signup' ) {
1083 if ( $user->isLoggedIn() ) {
1084 $this->mUsername = $user->getName();
1085 } else {
1086 $this->mUsername = $this->getRequest()->getCookie( 'UserName' );
1090 if ( $this->mType == 'signup' ) {
1091 $template = new UsercreateTemplate();
1093 $out->addModuleStyles( array(
1094 'mediawiki.ui',
1095 'mediawiki.special.createaccount'
1096 ) );
1097 // XXX hack pending RL or JS parse() support for complex content messages
1098 // https://bugzilla.wikimedia.org/show_bug.cgi?id=25349
1099 $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
1100 $this->msg( 'createacct-imgcaptcha-help' )->parse() );
1101 $out->addModules( array(
1102 'mediawiki.special.createaccount.js'
1103 ) );
1104 // Must match number of benefits defined in messages
1105 $template->set( 'benefitCount', 3 );
1107 $q = 'action=submitlogin&type=signup';
1108 $linkq = 'type=login';
1109 } else {
1110 $template = new UserloginTemplate();
1112 $out->addModuleStyles( array(
1113 'mediawiki.ui',
1114 'mediawiki.special.userlogin'
1115 ) );
1117 $q = 'action=submitlogin&type=login';
1118 $linkq = 'type=signup';
1121 if ( $this->mReturnTo !== '' ) {
1122 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
1123 if ( $this->mReturnToQuery !== '' ) {
1124 $returnto .= '&returntoquery=' .
1125 wfUrlencode( $this->mReturnToQuery );
1127 $q .= $returnto;
1128 $linkq .= $returnto;
1131 # Don't show a "create account" link if the user can't.
1132 if ( $this->showCreateOrLoginLink( $user ) ) {
1133 # Pass any language selection on to the mode switch link
1134 if ( $wgLoginLanguageSelector && $this->mLanguage ) {
1135 $linkq .= '&uselang=' . $this->mLanguage;
1137 // Supply URL, login template creates the button.
1138 $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
1139 } else {
1140 $template->set( 'link', '' );
1143 $resetLink = $this->mType == 'signup'
1144 ? null
1145 : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );
1147 $template->set( 'header', '' );
1148 $template->set( 'skin', $this->getSkin() );
1149 $template->set( 'name', $this->mUsername );
1150 $template->set( 'password', $this->mPassword );
1151 $template->set( 'retype', $this->mRetype );
1152 $template->set( 'createemailset', $this->mCreateaccountMail );
1153 $template->set( 'email', $this->mEmail );
1154 $template->set( 'realname', $this->mRealName );
1155 $template->set( 'domain', $this->mDomain );
1156 $template->set( 'reason', $this->mReason );
1158 $template->set( 'action', $titleObj->getLocalURL( $q ) );
1159 $template->set( 'message', $msg );
1160 $template->set( 'messagetype', $msgtype );
1161 $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
1162 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
1163 $template->set( 'useemail', $wgEnableEmail );
1164 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
1165 $template->set( 'emailothers', $wgEnableUserEmail );
1166 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
1167 $template->set( 'resetlink', $resetLink );
1168 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
1169 $template->set( 'usereason', $user->isLoggedIn() );
1170 $template->set( 'remember', $user->getOption( 'rememberpassword' ) || $this->mRemember );
1171 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
1172 $template->set( 'stickhttps', (int)$this->mStickHTTPS );
1173 $template->set( 'loggedin', $user->isLoggedIn() );
1174 $template->set( 'loggedinuser', $user->getName() );
1176 if ( $this->mType == 'signup' ) {
1177 if ( !self::getCreateaccountToken() ) {
1178 self::setCreateaccountToken();
1180 $template->set( 'token', self::getCreateaccountToken() );
1181 } else {
1182 if ( !self::getLoginToken() ) {
1183 self::setLoginToken();
1185 $template->set( 'token', self::getLoginToken() );
1188 # Prepare language selection links as needed
1189 if ( $wgLoginLanguageSelector ) {
1190 $template->set( 'languages', $this->makeLanguageSelector() );
1191 if ( $this->mLanguage ) {
1192 $template->set( 'uselang', $this->mLanguage );
1196 $template->set( 'secureLoginUrl', $this->mSecureLoginUrl );
1197 // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
1198 // Ditto for signupend. New forms use neither.
1199 $usingHTTPS = $this->mRequest->getProtocol() == 'https';
1200 $loginendHTTPS = $this->msg( 'loginend-https' );
1201 $signupendHTTPS = $this->msg( 'signupend-https' );
1202 if ( $usingHTTPS && !$loginendHTTPS->isBlank() ) {
1203 $template->set( 'loginend', $loginendHTTPS->parse() );
1204 } else {
1205 $template->set( 'loginend', $this->msg( 'loginend' )->parse() );
1207 if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) {
1208 $template->set( 'signupend', $signupendHTTPS->parse() );
1209 } else {
1210 $template->set( 'signupend', $this->msg( 'signupend' )->parse() );
1213 // Give authentication and captcha plugins a chance to modify the form
1214 $wgAuth->modifyUITemplate( $template, $this->mType );
1215 if ( $this->mType == 'signup' ) {
1216 wfRunHooks( 'UserCreateForm', array( &$template ) );
1217 } else {
1218 wfRunHooks( 'UserLoginForm', array( &$template ) );
1221 $out->disallowUserJs(); // just in case...
1222 $out->addTemplate( $template );
1226 * Whether the login/create account form should display a link to the
1227 * other form (in addition to whatever the skin provides).
1229 * @param $user User
1230 * @return bool
1232 private function showCreateOrLoginLink( &$user ) {
1233 if ( $this->mType == 'signup' ) {
1234 return true;
1235 } elseif ( $user->isAllowed( 'createaccount' ) ) {
1236 return true;
1237 } else {
1238 return false;
1243 * Check if a session cookie is present.
1245 * This will not pick up a cookie set during _this_ request, but is meant
1246 * to ensure that the client is returning the cookie which was set on a
1247 * previous pass through the system.
1249 * @private
1250 * @return bool
1252 function hasSessionCookie() {
1253 global $wgDisableCookieCheck;
1254 return $wgDisableCookieCheck ? true : $this->getRequest()->checkSessionCookie();
1258 * Get the login token from the current session
1259 * @return Mixed
1261 public static function getLoginToken() {
1262 global $wgRequest;
1263 return $wgRequest->getSessionData( 'wsLoginToken' );
1267 * Randomly generate a new login token and attach it to the current session
1269 public static function setLoginToken() {
1270 global $wgRequest;
1271 // Generate a token directly instead of using $user->editToken()
1272 // because the latter reuses $_SESSION['wsEditToken']
1273 $wgRequest->setSessionData( 'wsLoginToken', MWCryptRand::generateHex( 32 ) );
1277 * Remove any login token attached to the current session
1279 public static function clearLoginToken() {
1280 global $wgRequest;
1281 $wgRequest->setSessionData( 'wsLoginToken', null );
1285 * Get the createaccount token from the current session
1286 * @return Mixed
1288 public static function getCreateaccountToken() {
1289 global $wgRequest;
1290 return $wgRequest->getSessionData( 'wsCreateaccountToken' );
1294 * Randomly generate a new createaccount token and attach it to the current session
1296 public static function setCreateaccountToken() {
1297 global $wgRequest;
1298 $wgRequest->setSessionData( 'wsCreateaccountToken', MWCryptRand::generateHex( 32 ) );
1302 * Remove any createaccount token attached to the current session
1304 public static function clearCreateaccountToken() {
1305 global $wgRequest;
1306 $wgRequest->setSessionData( 'wsCreateaccountToken', null );
1310 * Renew the user's session id, using strong entropy
1312 private function renewSessionId() {
1313 global $wgSecureLogin, $wgCookieSecure;
1314 if ( $wgSecureLogin && !$this->mStickHTTPS ) {
1315 $wgCookieSecure = false;
1318 wfResetSessionID();
1322 * @private
1324 function cookieRedirectCheck( $type ) {
1325 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
1326 $query = array( 'wpCookieCheck' => $type );
1327 if ( $this->mReturnTo !== '' ) {
1328 $query['returnto'] = $this->mReturnTo;
1329 $query['returntoquery'] = $this->mReturnToQuery;
1331 $check = $titleObj->getFullURL( $query );
1333 $this->getOutput()->redirect( $check );
1337 * @private
1339 function onCookieRedirectCheck( $type ) {
1340 if ( !$this->hasSessionCookie() ) {
1341 if ( $type == 'new' ) {
1342 $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
1343 } elseif ( $type == 'login' ) {
1344 $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
1345 } else {
1346 # shouldn't happen
1347 $this->mainLoginForm( $this->msg( 'error' )->text() );
1349 } else {
1350 $this->successfulLogin();
1355 * Produce a bar of links which allow the user to select another language
1356 * during login/registration but retain "returnto"
1358 * @return string
1360 function makeLanguageSelector() {
1361 $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1362 if ( !$msg->isBlank() ) {
1363 $langs = explode( "\n", $msg->text() );
1364 $links = array();
1365 foreach ( $langs as $lang ) {
1366 $lang = trim( $lang, '* ' );
1367 $parts = explode( '|', $lang );
1368 if ( count( $parts ) >= 2 ) {
1369 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1372 return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams(
1373 $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1374 } else {
1375 return '';
1380 * Create a language selector link for a particular language
1381 * Links back to this page preserving type and returnto
1383 * @param string $text Link text
1384 * @param string $lang Language code
1385 * @return string
1387 function makeLanguageSelectorLink( $text, $lang ) {
1388 if ( $this->getLanguage()->getCode() == $lang ) {
1389 // no link for currently used language
1390 return htmlspecialchars( $text );
1392 $query = array( 'uselang' => $lang );
1393 if ( $this->mType == 'signup' ) {
1394 $query['type'] = 'signup';
1396 if ( $this->mReturnTo !== '' ) {
1397 $query['returnto'] = $this->mReturnTo;
1398 $query['returntoquery'] = $this->mReturnToQuery;
1401 $attr = array();
1402 $targetLanguage = Language::factory( $lang );
1403 $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1405 return Linker::linkKnown(
1406 $this->getTitle(),
1407 htmlspecialchars( $text ),
1408 $attr,
1409 $query
1413 protected function getGroupName() {
1414 return 'login';