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 ) );
133 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
134 $wgOut->setRobotPolicy( 'noindex,nofollow' );
135 $wgOut->setArticleRelated( false );
137 if( WikiError
::isError( $result ) ) {
138 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
140 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
141 $wgOut->returnToMain( false );
150 function addNewAccount() {
151 global $wgUser, $wgEmailAuthentication;
153 # Create the account and abort if there's a problem doing so
154 $u = $this->addNewAccountInternal();
158 # If we showed up language selection links, and one was in use, be
159 # smart (and sensible) and save that language as the user's preference
160 global $wgLoginLanguageSelector;
161 if( $wgLoginLanguageSelector && $this->mLanguage
)
162 $u->setOption( 'language', $this->mLanguage
);
164 # Send out an email authentication message if needed
165 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
167 $error = $u->sendConfirmationMail();
168 if( WikiError
::isError( $error ) ) {
169 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
171 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
175 # Save settings (including confirmation token)
178 # If not logged in, assume the new account as the current one and set session cookies
179 # then show a "welcome" message or a "need cookies" message as needed
180 if( $wgUser->isAnon() ) {
182 $wgUser->setCookies();
183 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
184 if( $this->hasSessionCookie() ) {
185 return $this->successfulLogin( 'welcomecreation', $wgUser->getName(), false );
187 return $this->cookieRedirectCheck( 'new' );
190 # Confirm that the account was created
192 $self = SpecialPage
::getTitleFor( 'Userlogin' );
193 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
194 $wgOut->setArticleRelated( false );
195 $wgOut->setRobotPolicy( 'noindex,nofollow' );
196 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
197 $wgOut->returnToMain( false, $self );
198 wfRunHooks( 'AddNewAccount', array( $u ) );
206 function addNewAccountInternal() {
207 global $wgUser, $wgOut;
208 global $wgEnableSorbs, $wgProxyWhitelist;
209 global $wgMemc, $wgAccountCreationThrottle;
210 global $wgAuth, $wgMinimalPasswordLength;
211 global $wgEmailConfirmToEdit;
213 // If the user passes an invalid domain, something is fishy
214 if( !$wgAuth->validDomain( $this->mDomain
) ) {
215 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
219 // If we are not allowing users to login locally, we should
220 // be checking to see if the user is actually able to
221 // authenticate to the authentication server before they
222 // create an account (otherwise, they can create a local account
223 // and login as any domain user). We only need to check this for
224 // domains that aren't local.
225 if( 'local' != $this->mDomain
&& '' != $this->mDomain
) {
226 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
227 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
232 if ( wfReadOnly() ) {
233 $wgOut->readOnlyPage();
238 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
239 $this->userNotPrivilegedMessage();
241 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
242 $this->userBlockedMessage();
247 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
248 $wgUser->inSorbsBlacklist( $ip ) )
250 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
254 # Now create a dummy user ($u) and check if it is valid
255 $name = trim( $this->mName
);
256 $u = User
::newFromName( $name, 'creatable' );
257 if ( is_null( $u ) ) {
258 $this->mainLoginForm( wfMsg( 'noname' ) );
262 if ( 0 != $u->idForName() ) {
263 $this->mainLoginForm( wfMsg( 'userexists' ) );
267 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
268 $this->mainLoginForm( wfMsg( 'badretype' ) );
272 # check for minimal password length
273 if ( !$u->isValidPassword( $this->mPassword
) ) {
274 if ( !$this->mCreateaccountMail
) {
275 $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) );
278 # do not force a password for account creation by email
279 # set invalid password, it will be replaced later by a random generated password
280 $this->mPassword
= null;
284 # if you need a confirmed email address to edit, then obviously you need an email address.
285 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
286 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
290 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
291 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
295 # Set some additional data so the AbortNewAccount hook can be
296 # used for more than just username validation
297 $u->setEmail( $this->mEmail
);
298 $u->setRealName( $this->mRealName
);
301 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
302 // Hook point to add extra creation throttles and blocks
303 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
304 $this->mainLoginForm( $abortError );
308 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
309 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
310 $value = $wgMemc->incr( $key );
312 $wgMemc->set( $key, 1, 86400 );
314 if ( $value > $wgAccountCreationThrottle ) {
315 $this->throttleHit( $wgAccountCreationThrottle );
320 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
321 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
325 return $this->initUser( $u, false );
329 * Actually add a user to the database.
330 * Give it a User object that has been initialised with a name.
332 * @param $u User object.
333 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
334 * @return User object.
337 function initUser( $u, $autocreate ) {
342 if ( $wgAuth->allowPasswordChange() ) {
343 $u->setPassword( $this->mPassword
);
346 $u->setEmail( $this->mEmail
);
347 $u->setRealName( $this->mRealName
);
350 $wgAuth->initUser( $u, $autocreate );
352 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
356 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
357 $ssUpdate->doUpdate();
363 * Internally authenticate the login request.
365 * This may create a local account as a side effect if the
366 * authentication plugin allows transparent local account
371 function authenticateUserData() {
372 global $wgUser, $wgAuth;
373 if ( '' == $this->mName
) {
374 return self
::NO_NAME
;
377 global $wgPasswordAttemptThrottle;
378 if ( is_array($wgPasswordAttemptThrottle) ) {
379 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
380 $count = $wgPasswordAttemptThrottle['count'];
381 $period = $wgPasswordAttemptThrottle['seconds'];
384 $cur = $wgMemc->get($key);
386 $wgMemc->add( $key, 1, $period ); // start counter
387 } else if ( $cur < $count ) {
389 } else if ( $cur >= $count ) {
390 return self
::THROTTLED
;
394 // Load $wgUser now, and check to see if we're logging in as the same name.
395 // This is necessary because loading $wgUser (say by calling getName()) calls
396 // the UserLoadFromSession hook, which potentially creates the user in the
397 // database. Until we load $wgUser, checking for user existence using
398 // User::newFromName($name)->getId() below will effectively be using stale data.
399 if ( $wgUser->getName() === $this->mName
) {
400 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
401 return self
::SUCCESS
;
403 $u = User
::newFromName( $this->mName
);
404 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
405 return self
::ILLEGAL
;
408 $isAutoCreated = false;
409 if ( 0 == $u->getID() ) {
410 $status = $this->attemptAutoCreate( $u );
411 if ( $status !== self
::SUCCESS
) {
414 $isAutoCreated = true;
420 // Give general extensions, such as a captcha, a chance to abort logins
421 $abort = self
::ABORTED
;
422 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
426 if (!$u->checkPassword( $this->mPassword
)) {
427 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
428 // The e-mailed temporary password should not be used
429 // for actual logins; that's a very sloppy habit,
430 // and insecure if an attacker has a few seconds to
431 // click "search" on someone's open mail reader.
433 // Allow it to be used only to reset the password
434 // a single time to a new value, which won't be in
435 // the user's e-mail archives.
437 // For backwards compatibility, we'll still recognize
438 // it at the login form to minimize surprises for
439 // people who have been logging in with a temporary
440 // password for some time.
442 // As a side-effect, we can authenticate the user's
443 // e-mail address if it's not already done, since
444 // the temporary password was sent via e-mail.
446 if( !$u->isEmailConfirmed() ) {
451 // At this point we just return an appropriate code
452 // indicating that the UI should show a password
453 // reset form; bot interfaces etc will probably just
454 // fail cleanly here.
456 $retval = self
::RESET_PASS
;
458 $retval = '' == $this->mPassword ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
461 $wgAuth->updateUser( $u );
464 if ( $isAutoCreated ) {
465 // Must be run after $wgUser is set, for correct new user log
466 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
469 $retval = self
::SUCCESS
;
471 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
476 * Attempt to automatically create a user on login.
477 * Only succeeds if there is an external authentication method which allows it.
478 * @return integer Status code
480 function attemptAutoCreate( $user ) {
481 global $wgAuth, $wgUser;
483 * If the external authentication plugin allows it,
484 * automatically create a new account for users that
485 * are externally defined but have not yet logged in.
487 if ( !$wgAuth->autoCreate() ) {
488 return self
::NOT_EXISTS
;
490 if ( !$wgAuth->userExists( $user->getName() ) ) {
491 wfDebug( __METHOD__
.": user does not exist\n" );
492 return self
::NOT_EXISTS
;
494 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
495 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
496 return self
::WRONG_PLUGIN_PASS
;
498 if ( $wgUser->isBlockedFromCreateAccount() ) {
499 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
500 return self
::CREATE_BLOCKED
;
503 wfDebug( __METHOD__
.": creating account\n" );
504 $user = $this->initUser( $user, true );
505 return self
::SUCCESS
;
508 function processLogin() {
509 global $wgUser, $wgAuth;
511 switch ($this->authenticateUserData())
514 # We've verified now, update the real record
515 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
516 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
517 $wgUser->saveSettings();
519 $wgUser->invalidateCache();
521 $wgUser->setCookies();
523 // Reset the throttle
524 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
526 $wgMemc->delete( $key );
528 if( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
529 /* Replace the language object to provide user interface in correct
530 * language immediately on this first page load.
532 global $wgLang, $wgRequest;
533 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
534 $wgLang = Language
::factory( $code );
535 return $this->successfulLogin( 'loginsuccess', $wgUser->getName() );
537 return $this->cookieRedirectCheck( 'login' );
543 $this->mainLoginForm( wfMsg( 'noname' ) );
545 case self
::WRONG_PLUGIN_PASS
:
546 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
548 case self
::NOT_EXISTS
:
549 if( $wgUser->isAllowed( 'createaccount' ) ){
550 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
552 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
555 case self
::WRONG_PASS
:
556 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
558 case self
::EMPTY_PASS
:
559 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
561 case self
::RESET_PASS
:
562 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
564 case self
::CREATE_BLOCKED
:
565 $this->userBlockedMessage();
567 case self
::THROTTLED
:
568 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
571 throw new MWException( "Unhandled case value" );
575 function resetLoginForm( $error ) {
577 $wgOut->addWikiText( "<div class=\"errorbox\">$error</div>" );
578 $reset = new PasswordResetForm( $this->mName
, $this->mPassword
);
579 $reset->execute( null );
585 function mailPassword() {
586 global $wgUser, $wgOut, $wgAuth;
588 if( !$wgAuth->allowPasswordChange() ) {
589 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
593 # Check against blocked IPs
594 # fixme -- should we not?
595 if( $wgUser->isBlocked() ) {
596 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
600 # Check against the rate limiter
601 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
602 $wgOut->rateLimited();
606 if ( '' == $this->mName
) {
607 $this->mainLoginForm( wfMsg( 'noname' ) );
610 $u = User
::newFromName( $this->mName
);
611 if( is_null( $u ) ) {
612 $this->mainLoginForm( wfMsg( 'noname' ) );
615 if ( 0 == $u->getID() ) {
616 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
620 # Check against password throttle
621 if ( $u->isPasswordReminderThrottled() ) {
622 global $wgPasswordReminderResendTime;
623 # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
624 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
625 round( $wgPasswordReminderResendTime, 3 ) ) );
629 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
630 if( WikiError
::isError( $result ) ) {
631 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
633 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
640 * @param bool throttle
641 * @param string message name of email title
642 * @param string message name of email text
643 * @return mixed true on success, WikiError on failure
646 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
647 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
648 global $wgServer, $wgScript, $wgUser;
650 if ( '' == $u->getEmail() ) {
651 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
655 return new WikiError( wfMsg( 'badipaddress' ) );
658 wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
660 $np = $u->randomPassword();
661 $u->setNewpassword( $np, $throttle );
664 $m = wfMsg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript );
665 $result = $u->sendMail( wfMsg( $emailTitle ), $m );
672 * @param string $msg Message key that will be shown on success
673 * @param $params String: parameters for the above message
674 * @param bool $auto Toggle auto-redirect to main page; default true
677 function successfulLogin( $msg, $params, $auto = true ) {
681 # Run any hooks; ignore results
684 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
686 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
687 $wgOut->setRobotPolicy( 'noindex,nofollow' );
688 $wgOut->setArticleRelated( false );
689 $wgOut->addWikiMsgArray( $msg, $params );
690 $wgOut->addHtml( $injected_html );
691 if ( !empty( $this->mReturnTo
) ) {
692 $wgOut->returnToMain( $auto, $this->mReturnTo
);
694 $wgOut->returnToMain( $auto );
699 function userNotPrivilegedMessage($errors) {
702 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
703 $wgOut->setRobotPolicy( 'noindex,nofollow' );
704 $wgOut->setArticleRelated( false );
706 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
707 // Stuff that might want to be added at the end. For example, instructions if blocked.
708 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
710 $wgOut->returnToMain( false );
714 function userBlockedMessage() {
715 global $wgOut, $wgUser;
717 # Let's be nice about this, it's likely that this feature will be used
718 # for blocking large numbers of innocent people, e.g. range blocks on
719 # schools. Don't blame it on the user. There's a small chance that it
720 # really is the user's fault, i.e. the username is blocked and they
721 # haven't bothered to log out before trying to create an account to
722 # evade it, but we'll leave that to their guilty conscience to figure
725 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
726 $wgOut->setRobotPolicy( 'noindex,nofollow' );
727 $wgOut->setArticleRelated( false );
730 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
731 $block_reason = $wgUser->mBlock
->mReason
;
733 if ( strval( $block_reason ) === '' ) {
734 $block_reason = wfMsg( 'blockednoreason' );
736 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
737 $wgOut->returnToMain( false );
743 function mainLoginForm( $msg, $msgtype = 'error' ) {
744 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
745 global $wgRequest, $wgAuth, $wgLoginLanguageSelector;
746 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
748 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
750 if ( $this->mType
== 'signup' ) {
751 // Block signup here if in readonly. Keeps user from
752 // going through the process (filling out data, etc)
753 // and being informed later.
754 if ( wfReadOnly() ) {
755 $wgOut->readOnlyPage();
757 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
758 $this->userBlockedMessage();
760 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
761 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
766 if ( '' == $this->mName
) {
767 if ( $wgUser->isLoggedIn() ) {
768 $this->mName
= $wgUser->getName();
770 $this->mName
= $wgRequest->getCookie('UserName');
774 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
776 if ( $this->mType
== 'signup' ) {
777 $template = new UsercreateTemplate();
778 $q = 'action=submitlogin&type=signup';
779 $linkq = 'type=login';
780 $linkmsg = 'gotaccount';
782 $template = new UserloginTemplate();
783 $q = 'action=submitlogin&type=login';
784 $linkq = 'type=signup';
785 $linkmsg = 'nologin';
788 if ( !empty( $this->mReturnTo
) ) {
789 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
794 # Pass any language selection on to the mode switch link
795 if( $wgLoginLanguageSelector && $this->mLanguage
)
796 $linkq .= '&uselang=' . $this->mLanguage
;
798 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
799 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
802 # Don't show a "create account" link if the user can't
803 if( $this->showCreateOrLoginLink( $wgUser ) )
804 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
806 $template->set( 'link', '' );
808 $template->set( 'header', '' );
809 $template->set( 'name', $this->mName
);
810 $template->set( 'password', $this->mPassword
);
811 $template->set( 'retype', $this->mRetype
);
812 $template->set( 'email', $this->mEmail
);
813 $template->set( 'realname', $this->mRealName
);
814 $template->set( 'domain', $this->mDomain
);
816 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
817 $template->set( 'message', $msg );
818 $template->set( 'messagetype', $msgtype );
819 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
820 $template->set( 'userealname', $wgAllowRealName );
821 $template->set( 'useemail', $wgEnableEmail );
822 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
823 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
824 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
825 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
827 # Prepare language selection links as needed
828 if( $wgLoginLanguageSelector ) {
829 $template->set( 'languages', $this->makeLanguageSelector() );
830 if( $this->mLanguage
)
831 $template->set( 'uselang', $this->mLanguage
);
834 // Give authentication and captcha plugins a chance to modify the form
835 $wgAuth->modifyUITemplate( $template );
836 if ( $this->mType
== 'signup' ) {
837 wfRunHooks( 'UserCreateForm', array( &$template ) );
839 wfRunHooks( 'UserLoginForm', array( &$template ) );
842 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
843 $wgOut->setRobotPolicy( 'noindex,nofollow' );
844 $wgOut->setArticleRelated( false );
845 $wgOut->disallowUserJs(); // just in case...
846 $wgOut->addTemplate( $template );
852 function showCreateOrLoginLink( &$user ) {
853 if( $this->mType
== 'signup' ) {
855 } elseif( $user->isAllowed( 'createaccount' ) ) {
863 * Check if a session cookie is present.
865 * This will not pick up a cookie set during _this_ request, but is
866 * meant to ensure that the client is returning the cookie which was
867 * set on a previous pass through the system.
871 function hasSessionCookie() {
872 global $wgDisableCookieCheck, $wgRequest;
873 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
879 function cookieRedirectCheck( $type ) {
882 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
883 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
885 return $wgOut->redirect( $check );
891 function onCookieRedirectCheck( $type ) {
894 if ( !$this->hasSessionCookie() ) {
895 if ( $type == 'new' ) {
896 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
897 } else if ( $type == 'login' ) {
898 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
901 return $this->mainLoginForm( wfMsg( 'error' ) );
904 return $this->successfulLogin( 'loginsuccess', $wgUser->getName() );
911 function throttleHit( $limit ) {
914 $wgOut->addWikiMsg( 'acct_creation_throttle_hit', $limit );
918 * Produce a bar of links which allow the user to select another language
919 * during login/registration but retain "returnto"
923 function makeLanguageSelector() {
924 $msg = wfMsgForContent( 'loginlanguagelinks' );
925 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
926 $langs = explode( "\n", $msg );
928 foreach( $langs as $lang ) {
929 $lang = trim( $lang, '* ' );
930 $parts = explode( '|', $lang );
931 if (count($parts) >= 2) {
932 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
935 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
942 * Create a language selector link for a particular language
943 * Links back to this page preserving type and returnto
945 * @param $text Link text
946 * @param $lang Language code
948 function makeLanguageSelectorLink( $text, $lang ) {
950 $self = SpecialPage
::getTitleFor( 'Userlogin' );
951 $attr[] = 'uselang=' . $lang;
952 if( $this->mType
== 'signup' )
953 $attr[] = 'type=signup';
954 if( $this->mReturnTo
)
955 $attr[] = 'returnto=' . $this->mReturnTo
;
956 $skin = $wgUser->getSkin();
957 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );