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;
38 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
39 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
40 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage, $mSkipCookieCheck;
44 * @param WebRequest $request A WebRequest object passed by reference
46 function LoginForm( &$request, $par = '' ) {
47 global $wgLang, $wgAllowRealName, $wgEnableEmail;
50 $this->mType
= ( $par == 'signup' ) ?
$par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
51 $this->mName
= $request->getText( 'wpName' );
52 $this->mPassword
= $request->getText( 'wpPassword' );
53 $this->mRetype
= $request->getText( 'wpRetype' );
54 $this->mDomain
= $request->getText( 'wpDomain' );
55 $this->mReturnTo
= $request->getVal( 'returnto' );
56 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
57 $this->mPosted
= $request->wasPosted();
58 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' );
59 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
61 $this->mMailmypassword
= $request->getCheck( 'wpMailmypassword' )
63 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
64 $this->mAction
= $request->getVal( 'action' );
65 $this->mRemember
= $request->getCheck( 'wpRemember' );
66 $this->mLanguage
= $request->getText( 'uselang' );
67 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
69 if( $wgEnableEmail ) {
70 $this->mEmail
= $request->getText( 'wpEmail' );
74 if( $wgAllowRealName ) {
75 $this->mRealName
= $request->getText( 'wpRealName' );
77 $this->mRealName
= '';
80 if( !$wgAuth->validDomain( $this->mDomain
) ) {
81 $this->mDomain
= 'invaliddomain';
83 $wgAuth->setDomain( $this->mDomain
);
85 # When switching accounts, it sucks to get automatically logged out
86 if( $this->mReturnTo
== $wgLang->specialPage( 'Userlogout' ) ) {
87 $this->mReturnTo
= '';
92 if ( !is_null( $this->mCookieCheck
) ) {
93 $this->onCookieRedirectCheck( $this->mCookieCheck
);
95 } else if( $this->mPosted
) {
96 if( $this->mCreateaccount
) {
97 return $this->addNewAccount();
98 } else if ( $this->mCreateaccountMail
) {
99 return $this->addNewAccountMailPassword();
100 } else if ( $this->mMailmypassword
) {
101 return $this->mailPassword();
102 } else if ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
103 return $this->processLogin();
106 $this->mainLoginForm( '' );
112 function addNewAccountMailPassword() {
115 if ('' == $this->mEmail
) {
116 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName
) ) );
120 $u = $this->addNewaccountInternal();
126 // Wipe the initial password and mail a temporary one
127 $u->setPassword( null );
129 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
131 wfRunHooks( 'AddNewAccount', array( $u, true ) );
132 $u->addNewUserLogEntry();
134 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
135 $wgOut->setRobotPolicy( 'noindex,nofollow' );
136 $wgOut->setArticleRelated( false );
138 if( WikiError
::isError( $result ) ) {
139 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
141 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
142 $wgOut->returnToMain( false );
151 function addNewAccount() {
152 global $wgUser, $wgEmailAuthentication;
154 # Create the account and abort if there's a problem doing so
155 $u = $this->addNewAccountInternal();
159 # If we showed up language selection links, and one was in use, be
160 # smart (and sensible) and save that language as the user's preference
161 global $wgLoginLanguageSelector;
162 if( $wgLoginLanguageSelector && $this->mLanguage
)
163 $u->setOption( 'language', $this->mLanguage
);
165 # Send out an email authentication message if needed
166 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
168 $error = $u->sendConfirmationMail();
169 if( WikiError
::isError( $error ) ) {
170 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
172 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
176 # Save settings (including confirmation token)
179 # If not logged in, assume the new account as the current one and set
180 # session cookies then show a "welcome" message or a "need cookies"
182 if( $wgUser->isAnon() ) {
184 $wgUser->setCookies();
185 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
186 $wgUser->addNewUserLogEntry();
187 if( $this->hasSessionCookie() ) {
188 return $this->successfulCreation();
190 return $this->cookieRedirectCheck( 'new' );
193 # Confirm that the account was created
195 $self = SpecialPage
::getTitleFor( 'Userlogin' );
196 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
197 $wgOut->setArticleRelated( false );
198 $wgOut->setRobotPolicy( 'noindex,nofollow' );
199 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
200 $wgOut->returnToMain( false, $self );
201 wfRunHooks( 'AddNewAccount', array( $u ) );
202 $u->addNewUserLogEntry();
210 function addNewAccountInternal() {
211 global $wgUser, $wgOut;
212 global $wgEnableSorbs, $wgProxyWhitelist;
213 global $wgMemc, $wgAccountCreationThrottle;
214 global $wgAuth, $wgMinimalPasswordLength;
215 global $wgEmailConfirmToEdit;
217 // If the user passes an invalid domain, something is fishy
218 if( !$wgAuth->validDomain( $this->mDomain
) ) {
219 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
223 // If we are not allowing users to login locally, we should be checking
224 // to see if the user is actually able to authenticate to the authenti-
225 // cation server before they create an account (otherwise, they can
226 // create a local account and login as any domain user). We only need
227 // to check this for domains that aren't local.
228 if( 'local' != $this->mDomain
&& '' != $this->mDomain
) {
229 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
230 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
235 if ( wfReadOnly() ) {
236 $wgOut->readOnlyPage();
241 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
242 $this->userNotPrivilegedMessage();
244 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
245 $this->userBlockedMessage();
250 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
251 $wgUser->inSorbsBlacklist( $ip ) )
253 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
257 # Now create a dummy user ($u) and check if it is valid
258 $name = trim( $this->mName
);
259 $u = User
::newFromName( $name, 'creatable' );
260 if ( is_null( $u ) ) {
261 $this->mainLoginForm( wfMsg( 'noname' ) );
265 if ( 0 != $u->idForName() ) {
266 $this->mainLoginForm( wfMsg( 'userexists' ) );
270 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
271 $this->mainLoginForm( wfMsg( 'badretype' ) );
275 # check for minimal password length
276 if ( !$u->isValidPassword( $this->mPassword
) ) {
277 if ( !$this->mCreateaccountMail
) {
278 $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) );
281 # do not force a password for account creation by email
282 # set invalid password, it will be replaced later by a random generated password
283 $this->mPassword
= null;
287 # if you need a confirmed email address to edit, then obviously you
288 # need an email address.
289 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
290 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
294 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
295 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
299 # Set some additional data so the AbortNewAccount hook can be used for
300 # more than just username validation
301 $u->setEmail( $this->mEmail
);
302 $u->setRealName( $this->mRealName
);
305 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
306 // Hook point to add extra creation throttles and blocks
307 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
308 $this->mainLoginForm( $abortError );
312 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
313 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
314 $value = $wgMemc->incr( $key );
316 $wgMemc->set( $key, 1, 86400 );
318 if ( $value > $wgAccountCreationThrottle ) {
319 $this->throttleHit( $wgAccountCreationThrottle );
324 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
325 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
329 return $this->initUser( $u, false );
333 * Actually add a user to the database.
334 * Give it a User object that has been initialised with a name.
336 * @param $u User object.
337 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
338 * @return User object.
341 function initUser( $u, $autocreate ) {
346 if ( $wgAuth->allowPasswordChange() ) {
347 $u->setPassword( $this->mPassword
);
350 $u->setEmail( $this->mEmail
);
351 $u->setRealName( $this->mRealName
);
354 $wgAuth->initUser( $u, $autocreate );
356 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
360 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
361 $ssUpdate->doUpdate();
367 * Internally authenticate the login request.
369 * This may create a local account as a side effect if the
370 * authentication plugin allows transparent local account
375 function authenticateUserData() {
376 global $wgUser, $wgAuth;
377 if ( '' == $this->mName
) {
378 return self
::NO_NAME
;
381 global $wgPasswordAttemptThrottle;
382 if ( is_array($wgPasswordAttemptThrottle) ) {
383 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
384 $count = $wgPasswordAttemptThrottle['count'];
385 $period = $wgPasswordAttemptThrottle['seconds'];
388 $cur = $wgMemc->get($key);
390 $wgMemc->add( $key, 1, $period ); // start counter
391 } else if ( $cur < $count ) {
393 } else if ( $cur >= $count ) {
394 return self
::THROTTLED
;
398 // Load $wgUser now, and check to see if we're logging in as the same
399 // name. This is necessary because loading $wgUser (say by calling
400 // getName()) calls the UserLoadFromSession hook, which potentially
401 // creates the user in the database. Until we load $wgUser, checking
402 // for user existence using User::newFromName($name)->getId() below
403 // will effectively be using stale data.
404 if ( $wgUser->getName() === $this->mName
) {
405 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
406 return self
::SUCCESS
;
408 $u = User
::newFromName( $this->mName
);
409 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
410 return self
::ILLEGAL
;
413 $isAutoCreated = false;
414 if ( 0 == $u->getID() ) {
415 $status = $this->attemptAutoCreate( $u );
416 if ( $status !== self
::SUCCESS
) {
419 $isAutoCreated = true;
425 // Give general extensions, such as a captcha, a chance to abort logins
426 $abort = self
::ABORTED
;
427 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
431 if (!$u->checkPassword( $this->mPassword
)) {
432 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
433 // The e-mailed temporary password should not be used for actu-
434 // al logins; that's a very sloppy habit, and insecure if an
435 // attacker has a few seconds to click "search" on someone's o-
438 // Allow it to be used only to reset the password a single time
439 // to a new value, which won't be in the user's e-mail ar-
442 // For backwards compatibility, we'll still recognize it at the
443 // login form to minimize surprises for people who have been
444 // logging in with a temporary password for some time.
446 // As a side-effect, we can authenticate the user's e-mail ad-
447 // dress if it's not already done, since the temporary password
448 // was sent via e-mail.
449 if( !$u->isEmailConfirmed() ) {
454 // At this point we just return an appropriate code/ indicating
455 // that the UI should show a password reset form; bot inter-
456 // faces etc will probably just fail cleanly here.
457 $retval = self
::RESET_PASS
;
459 $retval = '' == $this->mPassword ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
462 $wgAuth->updateUser( $u );
465 if ( $isAutoCreated ) {
466 // Must be run after $wgUser is set, for correct new user log
467 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
470 $retval = self
::SUCCESS
;
472 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
477 * Attempt to automatically create a user on login. Only succeeds if there
478 * is an external authentication method which allows it.
479 * @return integer Status code
481 function attemptAutoCreate( $user ) {
482 global $wgAuth, $wgUser;
484 * If the external authentication plugin allows it, automatically cre-
485 * ate a new account for users that are externally defined but have not
488 if ( !$wgAuth->autoCreate() ) {
489 return self
::NOT_EXISTS
;
491 if ( !$wgAuth->userExists( $user->getName() ) ) {
492 wfDebug( __METHOD__
.": user does not exist\n" );
493 return self
::NOT_EXISTS
;
495 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
496 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
497 return self
::WRONG_PLUGIN_PASS
;
499 if ( $wgUser->isBlockedFromCreateAccount() ) {
500 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
501 return self
::CREATE_BLOCKED
;
504 wfDebug( __METHOD__
.": creating account\n" );
505 $user = $this->initUser( $user, true );
506 return self
::SUCCESS
;
509 function processLogin() {
510 global $wgUser, $wgAuth;
512 switch ($this->authenticateUserData())
515 # We've verified now, update the real record
516 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
517 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
518 $wgUser->saveSettings();
520 $wgUser->invalidateCache();
522 $wgUser->setCookies();
524 // Reset the throttle
525 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
527 $wgMemc->delete( $key );
529 if( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
530 /* Replace the language object to provide user interface in
531 * correct language immediately on this first page load.
533 global $wgLang, $wgRequest;
534 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
535 $wgLang = Language
::factory( $code );
536 return $this->successfulLogin();
538 return $this->cookieRedirectCheck( 'login' );
544 $this->mainLoginForm( wfMsg( 'noname' ) );
546 case self
::WRONG_PLUGIN_PASS
:
547 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
549 case self
::NOT_EXISTS
:
550 if( $wgUser->isAllowed( 'createaccount' ) ){
551 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
553 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
556 case self
::WRONG_PASS
:
557 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
559 case self
::EMPTY_PASS
:
560 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
562 case self
::RESET_PASS
:
563 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
565 case self
::CREATE_BLOCKED
:
566 $this->userBlockedMessage();
568 case self
::THROTTLED
:
569 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
572 throw new MWException( "Unhandled case value" );
576 function resetLoginForm( $error ) {
578 $wgOut->addWikiText( "<div class=\"errorbox\">$error</div>" );
579 $reset = new PasswordResetForm( $this->mName
, $this->mPassword
);
580 $reset->execute( null );
586 function mailPassword() {
587 global $wgUser, $wgOut, $wgAuth;
589 if( !$wgAuth->allowPasswordChange() ) {
590 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
594 # Check against blocked IPs
595 # fixme -- should we not?
596 if( $wgUser->isBlocked() ) {
597 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
601 # Check against the rate limiter
602 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
603 $wgOut->rateLimited();
607 if ( '' == $this->mName
) {
608 $this->mainLoginForm( wfMsg( 'noname' ) );
611 $u = User
::newFromName( $this->mName
);
612 if( is_null( $u ) ) {
613 $this->mainLoginForm( wfMsg( 'noname' ) );
616 if ( 0 == $u->getID() ) {
617 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
621 # Check against password throttle
622 if ( $u->isPasswordReminderThrottled() ) {
623 global $wgPasswordReminderResendTime;
624 # Round the time in hours to 3 d.p., in case someone is specifying
625 # minutes or seconds.
626 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
627 round( $wgPasswordReminderResendTime, 3 ) ) );
631 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
632 if( WikiError
::isError( $result ) ) {
633 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
635 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
642 * @param bool throttle
643 * @param string message name of email title
644 * @param string message name of email text
645 * @return mixed true on success, WikiError on failure
648 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
649 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
650 global $wgServer, $wgScript, $wgUser;
652 if ( '' == $u->getEmail() ) {
653 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
657 return new WikiError( wfMsg( 'badipaddress' ) );
660 wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
662 $np = $u->randomPassword();
663 $u->setNewpassword( $np, $throttle );
666 $m = wfMsg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript );
667 $result = $u->sendMail( wfMsg( $emailTitle ), $m );
674 * Run any hooks registered for logins, then HTTP redirect to
675 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
676 * nice message here, but that's really not as useful as just being sent to
677 * wherever you logged in from. It should be clear that the action was
678 * successful, given the lack of error messages plus the appearance of your
679 * name in the upper right.
683 function successfulLogin() {
684 global $wgUser, $wgOut;
686 # Run any hooks; display injected HTML if any, else redirect
688 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
690 if( $injected_html !== '' ) {
691 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
693 $titleObj = Title
::newFromText( $this->mReturnTo
);
694 if ( !$titleObj instanceof Title
) {
695 $titleObj = Title
::newMainPage();
698 $wgOut->redirect( $titleObj->getFullURL() );
703 * Run any hooks registered for logins, then display a message welcoming
708 function successfulCreation() {
709 global $wgUser, $wgOut;
711 # Run any hooks; display injected HTML
713 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
715 $this->displaySuccessfulLogin( 'welcomecreation', $injected_html );
719 * Display a "login successful" page.
721 private function displaySuccessfulLogin( $msgname, $injected_html ) {
722 global $wgOut, $wgUser;
724 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
725 $wgOut->setRobotPolicy( 'noindex,nofollow' );
726 $wgOut->setArticleRelated( false );
727 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
728 $wgOut->addHtml( $injected_html );
730 if ( !empty( $this->mReturnTo
) ) {
731 $wgOut->returnToMain( null, $this->mReturnTo
);
733 $wgOut->returnToMain( null );
738 function userNotPrivilegedMessage($errors) {
741 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
742 $wgOut->setRobotPolicy( 'noindex,nofollow' );
743 $wgOut->setArticleRelated( false );
745 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
746 // Stuff that might want to be added at the end. For example, instruc-
748 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
750 $wgOut->returnToMain( false );
754 function userBlockedMessage() {
755 global $wgOut, $wgUser;
757 # Let's be nice about this, it's likely that this feature will be used
758 # for blocking large numbers of innocent people, e.g. range blocks on
759 # schools. Don't blame it on the user. There's a small chance that it
760 # really is the user's fault, i.e. the username is blocked and they
761 # haven't bothered to log out before trying to create an account to
762 # evade it, but we'll leave that to their guilty conscience to figure
765 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
766 $wgOut->setRobotPolicy( 'noindex,nofollow' );
767 $wgOut->setArticleRelated( false );
770 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
771 $block_reason = $wgUser->mBlock
->mReason
;
773 if ( strval( $block_reason ) === '' ) {
774 $block_reason = wfMsg( 'blockednoreason' );
776 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
777 $wgOut->returnToMain( false );
783 function mainLoginForm( $msg, $msgtype = 'error' ) {
784 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
785 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
786 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
788 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
790 if ( $this->mType
== 'signup' ) {
791 // Block signup here if in readonly. Keeps user from
792 // going through the process (filling out data, etc)
793 // and being informed later.
794 if ( wfReadOnly() ) {
795 $wgOut->readOnlyPage();
797 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
798 $this->userBlockedMessage();
800 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
801 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
806 if ( '' == $this->mName
) {
807 if ( $wgUser->isLoggedIn() ) {
808 $this->mName
= $wgUser->getName();
810 $this->mName
= isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ?
$_COOKIE[$wgCookiePrefix.'UserName'] : null;
814 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
816 if ( $this->mType
== 'signup' ) {
817 $template = new UsercreateTemplate();
818 $q = 'action=submitlogin&type=signup';
819 $linkq = 'type=login';
820 $linkmsg = 'gotaccount';
822 $template = new UserloginTemplate();
823 $q = 'action=submitlogin&type=login';
824 $linkq = 'type=signup';
825 $linkmsg = 'nologin';
828 if ( !empty( $this->mReturnTo
) ) {
829 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
834 # Pass any language selection on to the mode switch link
835 if( $wgLoginLanguageSelector && $this->mLanguage
)
836 $linkq .= '&uselang=' . $this->mLanguage
;
838 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
839 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
842 # Don't show a "create account" link if the user can't
843 if( $this->showCreateOrLoginLink( $wgUser ) )
844 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
846 $template->set( 'link', '' );
848 $template->set( 'header', '' );
849 $template->set( 'name', $this->mName
);
850 $template->set( 'password', $this->mPassword
);
851 $template->set( 'retype', $this->mRetype
);
852 $template->set( 'email', $this->mEmail
);
853 $template->set( 'realname', $this->mRealName
);
854 $template->set( 'domain', $this->mDomain
);
856 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
857 $template->set( 'message', $msg );
858 $template->set( 'messagetype', $msgtype );
859 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
860 $template->set( 'userealname', $wgAllowRealName );
861 $template->set( 'useemail', $wgEnableEmail );
862 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
863 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
864 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
865 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
867 # Prepare language selection links as needed
868 if( $wgLoginLanguageSelector ) {
869 $template->set( 'languages', $this->makeLanguageSelector() );
870 if( $this->mLanguage
)
871 $template->set( 'uselang', $this->mLanguage
);
874 // Give authentication and captcha plugins a chance to modify the form
875 $wgAuth->modifyUITemplate( $template );
876 if ( $this->mType
== 'signup' ) {
877 wfRunHooks( 'UserCreateForm', array( &$template ) );
879 wfRunHooks( 'UserLoginForm', array( &$template ) );
882 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
883 $wgOut->setRobotPolicy( 'noindex,nofollow' );
884 $wgOut->setArticleRelated( false );
885 $wgOut->disallowUserJs(); // just in case...
886 $wgOut->addTemplate( $template );
892 function showCreateOrLoginLink( &$user ) {
893 if( $this->mType
== 'signup' ) {
895 } elseif( $user->isAllowed( 'createaccount' ) ) {
903 * Check if a session cookie is present.
905 * This will not pick up a cookie set during _this_ request, but is meant
906 * to ensure that the client is returning the cookie which was set on a
907 * previous pass through the system.
911 function hasSessionCookie() {
912 global $wgDisableCookieCheck, $wgRequest;
913 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
919 function cookieRedirectCheck( $type ) {
922 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
923 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
925 return $wgOut->redirect( $check );
931 function onCookieRedirectCheck( $type ) {
934 if ( !$this->hasSessionCookie() ) {
935 if ( $type == 'new' ) {
936 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
937 } else if ( $type == 'login' ) {
938 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
941 return $this->mainLoginForm( wfMsg( 'error' ) );
944 return $this->successfulLogin();
951 function throttleHit( $limit ) {
952 $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) );
956 * Produce a bar of links which allow the user to select another language
957 * during login/registration but retain "returnto"
961 function makeLanguageSelector() {
962 $msg = wfMsgForContent( 'loginlanguagelinks' );
963 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
964 $langs = explode( "\n", $msg );
966 foreach( $langs as $lang ) {
967 $lang = trim( $lang, '* ' );
968 $parts = explode( '|', $lang );
969 if (count($parts) >= 2) {
970 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
973 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
980 * Create a language selector link for a particular language
981 * Links back to this page preserving type and returnto
983 * @param $text Link text
984 * @param $lang Language code
986 function makeLanguageSelectorLink( $text, $lang ) {
988 $self = SpecialPage
::getTitleFor( 'Userlogin' );
989 $attr[] = 'uselang=' . $lang;
990 if( $this->mType
== 'signup' )
991 $attr[] = 'type=signup';
992 if( $this->mReturnTo
)
993 $attr[] = 'returnto=' . $this->mReturnTo
;
994 $skin = $wgUser->getSkin();
995 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );