10 function wfSpecialUserlogin( $par = '' ) {
12 if( session_id() == '' ) {
16 $form = new LoginForm( $wgRequest, $par );
21 * implements Special:Login
22 * @ingroup SpecialPage
29 const WRONG_PLUGIN_PASS
= 3;
35 const CREATE_BLOCKED
= 9;
37 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
38 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
39 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
43 * @param WebRequest $request A WebRequest object passed by reference
45 function LoginForm( &$request, $par = '' ) {
46 global $wgLang, $wgAllowRealName, $wgEnableEmail;
49 $this->mType
= ( $par == 'signup' ) ?
$par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
50 $this->mName
= $request->getText( 'wpName' );
51 $this->mPassword
= $request->getText( 'wpPassword' );
52 $this->mRetype
= $request->getText( 'wpRetype' );
53 $this->mDomain
= $request->getText( 'wpDomain' );
54 $this->mReturnTo
= $request->getVal( 'returnto' );
55 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
56 $this->mPosted
= $request->wasPosted();
57 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' );
58 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
60 $this->mMailmypassword
= $request->getCheck( 'wpMailmypassword' )
62 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
63 $this->mAction
= $request->getVal( 'action' );
64 $this->mRemember
= $request->getCheck( 'wpRemember' );
65 $this->mLanguage
= $request->getText( 'uselang' );
67 if( $wgEnableEmail ) {
68 $this->mEmail
= $request->getText( 'wpEmail' );
72 if( $wgAllowRealName ) {
73 $this->mRealName
= $request->getText( 'wpRealName' );
75 $this->mRealName
= '';
78 if( !$wgAuth->validDomain( $this->mDomain
) ) {
79 $this->mDomain
= 'invaliddomain';
81 $wgAuth->setDomain( $this->mDomain
);
83 # When switching accounts, it sucks to get automatically logged out
84 if( $this->mReturnTo
== $wgLang->specialPage( 'Userlogout' ) ) {
85 $this->mReturnTo
= '';
90 if ( !is_null( $this->mCookieCheck
) ) {
91 $this->onCookieRedirectCheck( $this->mCookieCheck
);
93 } else if( $this->mPosted
) {
94 if( $this->mCreateaccount
) {
95 return $this->addNewAccount();
96 } else if ( $this->mCreateaccountMail
) {
97 return $this->addNewAccountMailPassword();
98 } else if ( $this->mMailmypassword
) {
99 return $this->mailPassword();
100 } else if ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
101 return $this->processLogin();
104 $this->mainLoginForm( '' );
110 function addNewAccountMailPassword() {
113 if ('' == $this->mEmail
) {
114 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName
) ) );
118 $u = $this->addNewaccountInternal();
124 // Wipe the initial password and mail a temporary one
125 $u->setPassword( null );
127 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
129 wfRunHooks( 'AddNewAccount', array( $u, true ) );
131 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
132 $wgOut->setRobotpolicy( 'noindex,nofollow' );
133 $wgOut->setArticleRelated( false );
135 if( WikiError
::isError( $result ) ) {
136 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
138 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
139 $wgOut->returnToMain( false );
148 function addNewAccount() {
149 global $wgUser, $wgEmailAuthentication;
151 # Create the account and abort if there's a problem doing so
152 $u = $this->addNewAccountInternal();
156 # If we showed up language selection links, and one was in use, be
157 # smart (and sensible) and save that language as the user's preference
158 global $wgLoginLanguageSelector;
159 if( $wgLoginLanguageSelector && $this->mLanguage
)
160 $u->setOption( 'language', $this->mLanguage
);
162 # Send out an email authentication message if needed
163 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
165 $error = $u->sendConfirmationMail();
166 if( WikiError
::isError( $error ) ) {
167 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
169 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
173 # Save settings (including confirmation token)
176 # If not logged in, assume the new account as the current one and set session cookies
177 # then show a "welcome" message or a "need cookies" message as needed
178 if( $wgUser->isAnon() ) {
180 $wgUser->setCookies();
181 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
182 if( $this->hasSessionCookie() ) {
183 return $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false );
185 return $this->cookieRedirectCheck( 'new' );
188 # Confirm that the account was created
190 $self = SpecialPage
::getTitleFor( 'Userlogin' );
191 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
192 $wgOut->setArticleRelated( false );
193 $wgOut->setRobotPolicy( 'noindex,nofollow' );
194 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
195 $wgOut->returnToMain( false, $self );
196 wfRunHooks( 'AddNewAccount', array( $u ) );
204 function addNewAccountInternal() {
205 global $wgUser, $wgOut;
206 global $wgEnableSorbs, $wgProxyWhitelist;
207 global $wgMemc, $wgAccountCreationThrottle;
208 global $wgAuth, $wgMinimalPasswordLength;
209 global $wgEmailConfirmToEdit;
211 // If the user passes an invalid domain, something is fishy
212 if( !$wgAuth->validDomain( $this->mDomain
) ) {
213 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
217 // If we are not allowing users to login locally, we should
218 // be checking to see if the user is actually able to
219 // authenticate to the authentication server before they
220 // create an account (otherwise, they can create a local account
221 // and login as any domain user). We only need to check this for
222 // domains that aren't local.
223 if( 'local' != $this->mDomain
&& '' != $this->mDomain
) {
224 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
225 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
230 if ( wfReadOnly() ) {
231 $wgOut->readOnlyPage();
236 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
237 $this->userNotPrivilegedMessage();
239 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
240 $this->userBlockedMessage();
245 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
246 $wgUser->inSorbsBlacklist( $ip ) )
248 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
252 # Now create a dummy user ($u) and check if it is valid
253 $name = trim( $this->mName
);
254 $u = User
::newFromName( $name, 'creatable' );
255 if ( is_null( $u ) ) {
256 $this->mainLoginForm( wfMsg( 'noname' ) );
260 if ( 0 != $u->idForName() ) {
261 $this->mainLoginForm( wfMsg( 'userexists' ) );
265 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
266 $this->mainLoginForm( wfMsg( 'badretype' ) );
270 # check for minimal password length
271 if ( !$u->isValidPassword( $this->mPassword
) ) {
272 if ( !$this->mCreateaccountMail
) {
273 $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
276 # do not force a password for account creation by email
277 # set invalid password, it will be replaced later by a random generated password
278 $this->mPassword
= null;
282 # if you need a confirmed email address to edit, then obviously you need an email address.
283 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
284 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
288 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
289 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
293 # Set some additional data so the AbortNewAccount hook can be
294 # used for more than just username validation
295 $u->setEmail( $this->mEmail
);
296 $u->setRealName( $this->mRealName
);
299 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
300 // Hook point to add extra creation throttles and blocks
301 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
302 $this->mainLoginForm( $abortError );
306 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
307 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
308 $value = $wgMemc->incr( $key );
310 $wgMemc->set( $key, 1, 86400 );
312 if ( $value > $wgAccountCreationThrottle ) {
313 $this->throttleHit( $wgAccountCreationThrottle );
318 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
319 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
323 return $this->initUser( $u, false );
327 * Actually add a user to the database.
328 * Give it a User object that has been initialised with a name.
330 * @param $u User object.
331 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
332 * @return User object.
335 function initUser( $u, $autocreate ) {
340 if ( $wgAuth->allowPasswordChange() ) {
341 $u->setPassword( $this->mPassword
);
344 $u->setEmail( $this->mEmail
);
345 $u->setRealName( $this->mRealName
);
348 $wgAuth->initUser( $u, $autocreate );
350 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
354 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
355 $ssUpdate->doUpdate();
361 * Internally authenticate the login request.
363 * This may create a local account as a side effect if the
364 * authentication plugin allows transparent local account
369 function authenticateUserData() {
370 global $wgUser, $wgAuth;
371 if ( '' == $this->mName
) {
372 return self
::NO_NAME
;
375 // Load $wgUser now, and check to see if we're logging in as the same name.
376 // This is necessary because loading $wgUser (say by calling getName()) calls
377 // the UserLoadFromSession hook, which potentially creates the user in the
378 // database. Until we load $wgUser, checking for user existence using
379 // User::newFromName($name)->getId() below will effectively be using stale data.
380 if ( $wgUser->getName() === $this->mName
) {
381 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
382 return self
::SUCCESS
;
384 $u = User
::newFromName( $this->mName
);
385 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
386 return self
::ILLEGAL
;
389 $isAutoCreated = false;
390 if ( 0 == $u->getID() ) {
391 $status = $this->attemptAutoCreate( $u );
392 if ( $status !== self
::SUCCESS
) {
395 $isAutoCreated = true;
401 // Give general extensions, such as a captcha, a chance to abort logins
402 $abort = self
::ABORTED
;
403 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
407 if (!$u->checkPassword( $this->mPassword
)) {
408 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
409 // The e-mailed temporary password should not be used
410 // for actual logins; that's a very sloppy habit,
411 // and insecure if an attacker has a few seconds to
412 // click "search" on someone's open mail reader.
414 // Allow it to be used only to reset the password
415 // a single time to a new value, which won't be in
416 // the user's e-mail archives.
418 // For backwards compatibility, we'll still recognize
419 // it at the login form to minimize surprises for
420 // people who have been logging in with a temporary
421 // password for some time.
423 // As a side-effect, we can authenticate the user's
424 // e-mail address if it's not already done, since
425 // the temporary password was sent via e-mail.
427 if( !$u->isEmailConfirmed() ) {
432 // At this point we just return an appropriate code
433 // indicating that the UI should show a password
434 // reset form; bot interfaces etc will probably just
435 // fail cleanly here.
437 $retval = self
::RESET_PASS
;
439 $retval = '' == $this->mPassword ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
442 $wgAuth->updateUser( $u );
445 if ( $isAutoCreated ) {
446 // Must be run after $wgUser is set, for correct new user log
447 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
450 $retval = self
::SUCCESS
;
452 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
457 * Attempt to automatically create a user on login.
458 * Only succeeds if there is an external authentication method which allows it.
459 * @return integer Status code
461 function attemptAutoCreate( $user ) {
462 global $wgAuth, $wgUser;
464 * If the external authentication plugin allows it,
465 * automatically create a new account for users that
466 * are externally defined but have not yet logged in.
468 if ( !$wgAuth->autoCreate() ) {
469 return self
::NOT_EXISTS
;
471 if ( !$wgAuth->userExists( $user->getName() ) ) {
472 wfDebug( __METHOD__
.": user does not exist\n" );
473 return self
::NOT_EXISTS
;
475 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
476 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
477 return self
::WRONG_PLUGIN_PASS
;
479 if ( $wgUser->isBlockedFromCreateAccount() ) {
480 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
481 return self
::CREATE_BLOCKED
;
484 wfDebug( __METHOD__
.": creating account\n" );
485 $user = $this->initUser( $user, true );
486 return self
::SUCCESS
;
489 function processLogin() {
490 global $wgUser, $wgAuth;
492 switch ($this->authenticateUserData())
495 # We've verified now, update the real record
496 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
497 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
498 $wgUser->saveSettings();
500 $wgUser->invalidateCache();
502 $wgUser->setCookies();
504 if( $this->hasSessionCookie() ) {
505 /* Replace the language object to provide user interface in correct
506 * language immediately on this first page load.
508 global $wgLang, $wgRequest;
509 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
510 $wgLang = Language
::factory( $code );
511 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
513 return $this->cookieRedirectCheck( 'login' );
519 $this->mainLoginForm( wfMsg( 'noname' ) );
521 case self
::WRONG_PLUGIN_PASS
:
522 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
524 case self
::NOT_EXISTS
:
525 if( $wgUser->isAllowed( 'createaccount' ) ){
526 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
528 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
531 case self
::WRONG_PASS
:
532 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
534 case self
::EMPTY_PASS
:
535 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
537 case self
::RESET_PASS
:
538 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
540 case self
::CREATE_BLOCKED
:
541 $this->userBlockedMessage();
544 throw new MWException( "Unhandled case value" );
548 function resetLoginForm( $error ) {
550 $wgOut->addWikiText( "<div class=\"errorbox\">$error</div>" );
551 $reset = new PasswordResetForm( $this->mName
, $this->mPassword
);
552 $reset->execute( null );
558 function mailPassword() {
559 global $wgUser, $wgOut, $wgAuth;
561 if( !$wgAuth->allowPasswordChange() ) {
562 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
566 # Check against blocked IPs
567 # fixme -- should we not?
568 if( $wgUser->isBlocked() ) {
569 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
573 # Check against the rate limiter
574 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
575 $wgOut->rateLimited();
579 if ( '' == $this->mName
) {
580 $this->mainLoginForm( wfMsg( 'noname' ) );
583 $u = User
::newFromName( $this->mName
);
584 if( is_null( $u ) ) {
585 $this->mainLoginForm( wfMsg( 'noname' ) );
588 if ( 0 == $u->getID() ) {
589 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
593 # Check against password throttle
594 if ( $u->isPasswordReminderThrottled() ) {
595 global $wgPasswordReminderResendTime;
596 # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
597 $this->mainLoginForm( wfMsg( 'throttled-mailpassword',
598 round( $wgPasswordReminderResendTime, 3 ) ) );
602 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
603 if( WikiError
::isError( $result ) ) {
604 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
606 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
613 * @param bool throttle
614 * @param string message name of email title
615 * @param string message name of email text
616 * @return mixed true on success, WikiError on failure
619 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
620 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
621 global $wgServer, $wgScript;
623 if ( '' == $u->getEmail() ) {
624 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
627 $np = $u->randomPassword();
628 $u->setNewpassword( $np, $throttle );
632 if ( '' == $ip ) { $ip = '(Unknown)'; }
634 $m = wfMsg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript );
635 $result = $u->sendMail( wfMsg( $emailTitle ), $m );
642 * @param string $msg Message that will be shown on success
643 * @param bool $auto Toggle auto-redirect to main page; default true
646 function successfulLogin( $msg, $auto = true ) {
650 # Run any hooks; ignore results
653 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
655 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
656 $wgOut->setRobotpolicy( 'noindex,nofollow' );
657 $wgOut->setArticleRelated( false );
658 $wgOut->addWikiText( $msg );
659 $wgOut->addHtml( $injected_html );
660 if ( !empty( $this->mReturnTo
) ) {
661 $wgOut->returnToMain( $auto, $this->mReturnTo
);
663 $wgOut->returnToMain( $auto );
668 function userNotPrivilegedMessage($errors) {
671 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
672 $wgOut->setRobotpolicy( 'noindex,nofollow' );
673 $wgOut->setArticleRelated( false );
675 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
676 // Stuff that might want to be added at the end. For example, instructions if blocked.
677 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
679 $wgOut->returnToMain( false );
683 function userBlockedMessage() {
684 global $wgOut, $wgUser;
686 # Let's be nice about this, it's likely that this feature will be used
687 # for blocking large numbers of innocent people, e.g. range blocks on
688 # schools. Don't blame it on the user. There's a small chance that it
689 # really is the user's fault, i.e. the username is blocked and they
690 # haven't bothered to log out before trying to create an account to
691 # evade it, but we'll leave that to their guilty conscience to figure
694 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
695 $wgOut->setRobotpolicy( 'noindex,nofollow' );
696 $wgOut->setArticleRelated( false );
699 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
700 $block_reason = $wgUser->mBlock
->mReason
;
702 if ( strval( $block_reason ) === '' ) {
703 $block_reason = wfMsg( 'blockednoreason' );
705 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
706 $wgOut->returnToMain( false );
712 function mainLoginForm( $msg, $msgtype = 'error' ) {
713 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
714 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
715 global $wgAuth, $wgEmailConfirmToEdit;
717 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
719 if ( $this->mType
== 'signup' ) {
720 if ( $wgUser->isBlockedFromCreateAccount() ) {
721 $this->userBlockedMessage();
723 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
724 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
729 if ( '' == $this->mName
) {
730 if ( $wgUser->isLoggedIn() ) {
731 $this->mName
= $wgUser->getName();
733 $this->mName
= isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ?
$_COOKIE[$wgCookiePrefix.'UserName'] : null;
737 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
739 if ( $this->mType
== 'signup' ) {
740 $template = new UsercreateTemplate();
741 $q = 'action=submitlogin&type=signup';
742 $linkq = 'type=login';
743 $linkmsg = 'gotaccount';
745 $template = new UserloginTemplate();
746 $q = 'action=submitlogin&type=login';
747 $linkq = 'type=signup';
748 $linkmsg = 'nologin';
751 if ( !empty( $this->mReturnTo
) ) {
752 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
757 # Pass any language selection on to the mode switch link
758 if( $wgLoginLanguageSelector && $this->mLanguage
)
759 $linkq .= '&uselang=' . $this->mLanguage
;
761 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
762 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
765 # Don't show a "create account" link if the user can't
766 if( $this->showCreateOrLoginLink( $wgUser ) )
767 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
769 $template->set( 'link', '' );
771 $template->set( 'header', '' );
772 $template->set( 'name', $this->mName
);
773 $template->set( 'password', $this->mPassword
);
774 $template->set( 'retype', $this->mRetype
);
775 $template->set( 'email', $this->mEmail
);
776 $template->set( 'realname', $this->mRealName
);
777 $template->set( 'domain', $this->mDomain
);
779 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
780 $template->set( 'message', $msg );
781 $template->set( 'messagetype', $msgtype );
782 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
783 $template->set( 'userealname', $wgAllowRealName );
784 $template->set( 'useemail', $wgEnableEmail );
785 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
786 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
787 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
789 # Prepare language selection links as needed
790 if( $wgLoginLanguageSelector ) {
791 $template->set( 'languages', $this->makeLanguageSelector() );
792 if( $this->mLanguage
)
793 $template->set( 'uselang', $this->mLanguage
);
796 // Give authentication and captcha plugins a chance to modify the form
797 $wgAuth->modifyUITemplate( $template );
798 if ( $this->mType
== 'signup' ) {
799 wfRunHooks( 'UserCreateForm', array( &$template ) );
801 wfRunHooks( 'UserLoginForm', array( &$template ) );
804 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
805 $wgOut->setRobotpolicy( 'noindex,nofollow' );
806 $wgOut->setArticleRelated( false );
807 $wgOut->disallowUserJs(); // just in case...
808 $wgOut->addTemplate( $template );
814 function showCreateOrLoginLink( &$user ) {
815 if( $this->mType
== 'signup' ) {
817 } elseif( $user->isAllowed( 'createaccount' ) ) {
825 * Check if a session cookie is present.
827 * This will not pick up a cookie set during _this_ request, but is
828 * meant to ensure that the client is returning the cookie which was
829 * set on a previous pass through the system.
833 function hasSessionCookie() {
834 global $wgDisableCookieCheck, $wgRequest;
835 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
841 function cookieRedirectCheck( $type ) {
844 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
845 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
847 return $wgOut->redirect( $check );
853 function onCookieRedirectCheck( $type ) {
856 if ( !$this->hasSessionCookie() ) {
857 if ( $type == 'new' ) {
858 return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
859 } else if ( $type == 'login' ) {
860 return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
863 return $this->mainLoginForm( wfMsg( 'error' ) );
866 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
873 function throttleHit( $limit ) {
876 $wgOut->addWikiMsg( 'acct_creation_throttle_hit', $limit );
880 * Produce a bar of links which allow the user to select another language
881 * during login/registration but retain "returnto"
885 function makeLanguageSelector() {
886 $msg = wfMsgForContent( 'loginlanguagelinks' );
887 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
888 $langs = explode( "\n", $msg );
890 foreach( $langs as $lang ) {
891 $lang = trim( $lang, '* ' );
892 $parts = explode( '|', $lang );
893 if (count($parts) >= 2) {
894 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
897 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
904 * Create a language selector link for a particular language
905 * Links back to this page preserving type and returnto
907 * @param $text Link text
908 * @param $lang Language code
910 function makeLanguageSelectorLink( $text, $lang ) {
912 $self = SpecialPage
::getTitleFor( 'Userlogin' );
913 $attr[] = 'uselang=' . $lang;
914 if( $this->mType
== 'signup' )
915 $attr[] = 'type=signup';
916 if( $this->mReturnTo
)
917 $attr[] = 'returnto=' . $this->mReturnTo
;
918 $skin = $wgUser->getSkin();
919 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );