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, $mSkipCookieCheck;
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' );
66 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
68 if( $wgEnableEmail ) {
69 $this->mEmail
= $request->getText( 'wpEmail' );
73 if( $wgAllowRealName ) {
74 $this->mRealName
= $request->getText( 'wpRealName' );
76 $this->mRealName
= '';
79 if( !$wgAuth->validDomain( $this->mDomain
) ) {
80 $this->mDomain
= 'invaliddomain';
82 $wgAuth->setDomain( $this->mDomain
);
84 # When switching accounts, it sucks to get automatically logged out
85 if( $this->mReturnTo
== $wgLang->specialPage( 'Userlogout' ) ) {
86 $this->mReturnTo
= '';
91 if ( !is_null( $this->mCookieCheck
) ) {
92 $this->onCookieRedirectCheck( $this->mCookieCheck
);
94 } else if( $this->mPosted
) {
95 if( $this->mCreateaccount
) {
96 return $this->addNewAccount();
97 } else if ( $this->mCreateaccountMail
) {
98 return $this->addNewAccountMailPassword();
99 } else if ( $this->mMailmypassword
) {
100 return $this->mailPassword();
101 } else if ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
102 return $this->processLogin();
105 $this->mainLoginForm( '' );
111 function addNewAccountMailPassword() {
114 if ('' == $this->mEmail
) {
115 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName
) ) );
119 $u = $this->addNewaccountInternal();
125 // Wipe the initial password and mail a temporary one
126 $u->setPassword( null );
128 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
130 wfRunHooks( 'AddNewAccount', array( $u, true ) );
132 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
133 $wgOut->setRobotpolicy( 'noindex,nofollow' );
134 $wgOut->setArticleRelated( false );
136 if( WikiError
::isError( $result ) ) {
137 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
139 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
140 $wgOut->returnToMain( false );
149 function addNewAccount() {
150 global $wgUser, $wgEmailAuthentication;
152 # Create the account and abort if there's a problem doing so
153 $u = $this->addNewAccountInternal();
157 # If we showed up language selection links, and one was in use, be
158 # smart (and sensible) and save that language as the user's preference
159 global $wgLoginLanguageSelector;
160 if( $wgLoginLanguageSelector && $this->mLanguage
)
161 $u->setOption( 'language', $this->mLanguage
);
163 # Send out an email authentication message if needed
164 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
166 $error = $u->sendConfirmationMail();
167 if( WikiError
::isError( $error ) ) {
168 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
170 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
174 # Save settings (including confirmation token)
177 # If not logged in, assume the new account as the current one and set session cookies
178 # then show a "welcome" message or a "need cookies" message as needed
179 if( $wgUser->isAnon() ) {
181 $wgUser->setCookies();
182 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
183 if( $this->hasSessionCookie() ) {
184 return $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false );
186 return $this->cookieRedirectCheck( 'new' );
189 # Confirm that the account was created
191 $self = SpecialPage
::getTitleFor( 'Userlogin' );
192 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
193 $wgOut->setArticleRelated( false );
194 $wgOut->setRobotPolicy( 'noindex,nofollow' );
195 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
196 $wgOut->returnToMain( false, $self );
197 wfRunHooks( 'AddNewAccount', array( $u ) );
205 function addNewAccountInternal() {
206 global $wgUser, $wgOut;
207 global $wgEnableSorbs, $wgProxyWhitelist;
208 global $wgMemc, $wgAccountCreationThrottle;
209 global $wgAuth, $wgMinimalPasswordLength;
210 global $wgEmailConfirmToEdit;
212 // If the user passes an invalid domain, something is fishy
213 if( !$wgAuth->validDomain( $this->mDomain
) ) {
214 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
218 // If we are not allowing users to login locally, we should
219 // be checking to see if the user is actually able to
220 // authenticate to the authentication server before they
221 // create an account (otherwise, they can create a local account
222 // and login as any domain user). We only need to check this for
223 // domains that aren't local.
224 if( 'local' != $this->mDomain
&& '' != $this->mDomain
) {
225 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
226 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
231 if ( wfReadOnly() ) {
232 $wgOut->readOnlyPage();
237 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
238 $this->userNotPrivilegedMessage();
240 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
241 $this->userBlockedMessage();
246 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
247 $wgUser->inSorbsBlacklist( $ip ) )
249 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
253 # Now create a dummy user ($u) and check if it is valid
254 $name = trim( $this->mName
);
255 $u = User
::newFromName( $name, 'creatable' );
256 if ( is_null( $u ) ) {
257 $this->mainLoginForm( wfMsg( 'noname' ) );
261 if ( 0 != $u->idForName() ) {
262 $this->mainLoginForm( wfMsg( 'userexists' ) );
266 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
267 $this->mainLoginForm( wfMsg( 'badretype' ) );
271 # check for minimal password length
272 if ( !$u->isValidPassword( $this->mPassword
) ) {
273 if ( !$this->mCreateaccountMail
) {
274 $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) );
277 # do not force a password for account creation by email
278 # set invalid password, it will be replaced later by a random generated password
279 $this->mPassword
= null;
283 # if you need a confirmed email address to edit, then obviously you need an email address.
284 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
285 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
289 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
290 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
294 # Set some additional data so the AbortNewAccount hook can be
295 # used for more than just username validation
296 $u->setEmail( $this->mEmail
);
297 $u->setRealName( $this->mRealName
);
300 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
301 // Hook point to add extra creation throttles and blocks
302 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
303 $this->mainLoginForm( $abortError );
307 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
308 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
309 $value = $wgMemc->incr( $key );
311 $wgMemc->set( $key, 1, 86400 );
313 if ( $value > $wgAccountCreationThrottle ) {
314 $this->throttleHit( $wgAccountCreationThrottle );
319 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
320 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
324 return $this->initUser( $u, false );
328 * Actually add a user to the database.
329 * Give it a User object that has been initialised with a name.
331 * @param $u User object.
332 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
333 * @return User object.
336 function initUser( $u, $autocreate ) {
341 if ( $wgAuth->allowPasswordChange() ) {
342 $u->setPassword( $this->mPassword
);
345 $u->setEmail( $this->mEmail
);
346 $u->setRealName( $this->mRealName
);
349 $wgAuth->initUser( $u, $autocreate );
351 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
355 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
356 $ssUpdate->doUpdate();
362 * Internally authenticate the login request.
364 * This may create a local account as a side effect if the
365 * authentication plugin allows transparent local account
370 function authenticateUserData() {
371 global $wgUser, $wgAuth;
372 if ( '' == $this->mName
) {
373 return self
::NO_NAME
;
376 // Load $wgUser now, and check to see if we're logging in as the same name.
377 // This is necessary because loading $wgUser (say by calling getName()) calls
378 // the UserLoadFromSession hook, which potentially creates the user in the
379 // database. Until we load $wgUser, checking for user existence using
380 // User::newFromName($name)->getId() below will effectively be using stale data.
381 if ( $wgUser->getName() === $this->mName
) {
382 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
383 return self
::SUCCESS
;
385 $u = User
::newFromName( $this->mName
);
386 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
387 return self
::ILLEGAL
;
390 $isAutoCreated = false;
391 if ( 0 == $u->getID() ) {
392 $status = $this->attemptAutoCreate( $u );
393 if ( $status !== self
::SUCCESS
) {
396 $isAutoCreated = true;
402 // Give general extensions, such as a captcha, a chance to abort logins
403 $abort = self
::ABORTED
;
404 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
408 if (!$u->checkPassword( $this->mPassword
)) {
409 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
410 // The e-mailed temporary password should not be used
411 // for actual logins; that's a very sloppy habit,
412 // and insecure if an attacker has a few seconds to
413 // click "search" on someone's open mail reader.
415 // Allow it to be used only to reset the password
416 // a single time to a new value, which won't be in
417 // the user's e-mail archives.
419 // For backwards compatibility, we'll still recognize
420 // it at the login form to minimize surprises for
421 // people who have been logging in with a temporary
422 // password for some time.
424 // As a side-effect, we can authenticate the user's
425 // e-mail address if it's not already done, since
426 // the temporary password was sent via e-mail.
428 if( !$u->isEmailConfirmed() ) {
433 // At this point we just return an appropriate code
434 // indicating that the UI should show a password
435 // reset form; bot interfaces etc will probably just
436 // fail cleanly here.
438 $retval = self
::RESET_PASS
;
440 $retval = '' == $this->mPassword ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
443 $wgAuth->updateUser( $u );
446 if ( $isAutoCreated ) {
447 // Must be run after $wgUser is set, for correct new user log
448 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
451 $retval = self
::SUCCESS
;
453 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
458 * Attempt to automatically create a user on login.
459 * Only succeeds if there is an external authentication method which allows it.
460 * @return integer Status code
462 function attemptAutoCreate( $user ) {
463 global $wgAuth, $wgUser;
465 * If the external authentication plugin allows it,
466 * automatically create a new account for users that
467 * are externally defined but have not yet logged in.
469 if ( !$wgAuth->autoCreate() ) {
470 return self
::NOT_EXISTS
;
472 if ( !$wgAuth->userExists( $user->getName() ) ) {
473 wfDebug( __METHOD__
.": user does not exist\n" );
474 return self
::NOT_EXISTS
;
476 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
477 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
478 return self
::WRONG_PLUGIN_PASS
;
480 if ( $wgUser->isBlockedFromCreateAccount() ) {
481 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
482 return self
::CREATE_BLOCKED
;
485 wfDebug( __METHOD__
.": creating account\n" );
486 $user = $this->initUser( $user, true );
487 return self
::SUCCESS
;
490 function processLogin() {
491 global $wgUser, $wgAuth;
493 switch ($this->authenticateUserData())
496 # We've verified now, update the real record
497 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
498 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
499 $wgUser->saveSettings();
501 $wgUser->invalidateCache();
503 $wgUser->setCookies();
505 if( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
506 /* Replace the language object to provide user interface in correct
507 * language immediately on this first page load.
509 global $wgLang, $wgRequest;
510 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
511 $wgLang = Language
::factory( $code );
512 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
514 return $this->cookieRedirectCheck( 'login' );
520 $this->mainLoginForm( wfMsg( 'noname' ) );
522 case self
::WRONG_PLUGIN_PASS
:
523 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
525 case self
::NOT_EXISTS
:
526 if( $wgUser->isAllowed( 'createaccount' ) ){
527 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
529 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
532 case self
::WRONG_PASS
:
533 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
535 case self
::EMPTY_PASS
:
536 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
538 case self
::RESET_PASS
:
539 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
541 case self
::CREATE_BLOCKED
:
542 $this->userBlockedMessage();
545 throw new MWException( "Unhandled case value" );
549 function resetLoginForm( $error ) {
551 $wgOut->addWikiText( "<div class=\"errorbox\">$error</div>" );
552 $reset = new PasswordResetForm( $this->mName
, $this->mPassword
);
553 $reset->execute( null );
559 function mailPassword() {
560 global $wgUser, $wgOut, $wgAuth;
562 if( !$wgAuth->allowPasswordChange() ) {
563 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
567 # Check against blocked IPs
568 # fixme -- should we not?
569 if( $wgUser->isBlocked() ) {
570 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
574 # Check against the rate limiter
575 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
576 $wgOut->rateLimited();
580 if ( '' == $this->mName
) {
581 $this->mainLoginForm( wfMsg( 'noname' ) );
584 $u = User
::newFromName( $this->mName
);
585 if( is_null( $u ) ) {
586 $this->mainLoginForm( wfMsg( 'noname' ) );
589 if ( 0 == $u->getID() ) {
590 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
594 # Check against password throttle
595 if ( $u->isPasswordReminderThrottled() ) {
596 global $wgPasswordReminderResendTime;
597 # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
598 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
599 round( $wgPasswordReminderResendTime, 3 ) ) );
603 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
604 if( WikiError
::isError( $result ) ) {
605 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
607 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
614 * @param bool throttle
615 * @param string message name of email title
616 * @param string message name of email text
617 * @return mixed true on success, WikiError on failure
620 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
621 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
622 global $wgServer, $wgScript;
624 if ( '' == $u->getEmail() ) {
625 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
628 $np = $u->randomPassword();
629 $u->setNewpassword( $np, $throttle );
633 if ( '' == $ip ) { $ip = '(Unknown)'; }
635 $m = wfMsg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript );
636 $result = $u->sendMail( wfMsg( $emailTitle ), $m );
643 * @param string $msg Message that will be shown on success
644 * @param bool $auto Toggle auto-redirect to main page; default true
647 function successfulLogin( $msg, $auto = true ) {
651 # Run any hooks; ignore results
654 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
656 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
657 $wgOut->setRobotpolicy( 'noindex,nofollow' );
658 $wgOut->setArticleRelated( false );
659 $wgOut->addWikiText( $msg );
660 $wgOut->addHtml( $injected_html );
661 if ( !empty( $this->mReturnTo
) ) {
662 $wgOut->returnToMain( $auto, $this->mReturnTo
);
664 $wgOut->returnToMain( $auto );
669 function userNotPrivilegedMessage($errors) {
672 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
673 $wgOut->setRobotpolicy( 'noindex,nofollow' );
674 $wgOut->setArticleRelated( false );
676 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
677 // Stuff that might want to be added at the end. For example, instructions if blocked.
678 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
680 $wgOut->returnToMain( false );
684 function userBlockedMessage() {
685 global $wgOut, $wgUser;
687 # Let's be nice about this, it's likely that this feature will be used
688 # for blocking large numbers of innocent people, e.g. range blocks on
689 # schools. Don't blame it on the user. There's a small chance that it
690 # really is the user's fault, i.e. the username is blocked and they
691 # haven't bothered to log out before trying to create an account to
692 # evade it, but we'll leave that to their guilty conscience to figure
695 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
696 $wgOut->setRobotpolicy( 'noindex,nofollow' );
697 $wgOut->setArticleRelated( false );
700 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
701 $block_reason = $wgUser->mBlock
->mReason
;
703 if ( strval( $block_reason ) === '' ) {
704 $block_reason = wfMsg( 'blockednoreason' );
706 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
707 $wgOut->returnToMain( false );
713 function mainLoginForm( $msg, $msgtype = 'error' ) {
714 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
715 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
716 global $wgAuth, $wgEmailConfirmToEdit;
718 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
720 if ( $this->mType
== 'signup' ) {
721 // Block signup here if in readonly. Keeps user from
722 // going through the process (filling out data, etc)
723 // and being informed later.
724 if ( wfReadOnly() ) {
725 $wgOut->readOnlyPage();
727 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
728 $this->userBlockedMessage();
731 // Supress 'blockedtext' error here, we already checked above.
732 elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true, array('blockedtext') ) )>0 ) {
733 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
738 if ( '' == $this->mName
) {
739 if ( $wgUser->isLoggedIn() ) {
740 $this->mName
= $wgUser->getName();
742 $this->mName
= isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ?
$_COOKIE[$wgCookiePrefix.'UserName'] : null;
746 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
748 if ( $this->mType
== 'signup' ) {
749 $template = new UsercreateTemplate();
750 $q = 'action=submitlogin&type=signup';
751 $linkq = 'type=login';
752 $linkmsg = 'gotaccount';
754 $template = new UserloginTemplate();
755 $q = 'action=submitlogin&type=login';
756 $linkq = 'type=signup';
757 $linkmsg = 'nologin';
760 if ( !empty( $this->mReturnTo
) ) {
761 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
766 # Pass any language selection on to the mode switch link
767 if( $wgLoginLanguageSelector && $this->mLanguage
)
768 $linkq .= '&uselang=' . $this->mLanguage
;
770 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
771 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
774 # Don't show a "create account" link if the user can't
775 if( $this->showCreateOrLoginLink( $wgUser ) )
776 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
778 $template->set( 'link', '' );
780 $template->set( 'header', '' );
781 $template->set( 'name', $this->mName
);
782 $template->set( 'password', $this->mPassword
);
783 $template->set( 'retype', $this->mRetype
);
784 $template->set( 'email', $this->mEmail
);
785 $template->set( 'realname', $this->mRealName
);
786 $template->set( 'domain', $this->mDomain
);
788 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
789 $template->set( 'message', $msg );
790 $template->set( 'messagetype', $msgtype );
791 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
792 $template->set( 'userealname', $wgAllowRealName );
793 $template->set( 'useemail', $wgEnableEmail );
794 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
795 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
796 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
798 # Prepare language selection links as needed
799 if( $wgLoginLanguageSelector ) {
800 $template->set( 'languages', $this->makeLanguageSelector() );
801 if( $this->mLanguage
)
802 $template->set( 'uselang', $this->mLanguage
);
805 // Give authentication and captcha plugins a chance to modify the form
806 $wgAuth->modifyUITemplate( $template );
807 if ( $this->mType
== 'signup' ) {
808 wfRunHooks( 'UserCreateForm', array( &$template ) );
810 wfRunHooks( 'UserLoginForm', array( &$template ) );
813 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
814 $wgOut->setRobotpolicy( 'noindex,nofollow' );
815 $wgOut->setArticleRelated( false );
816 $wgOut->disallowUserJs(); // just in case...
817 $wgOut->addTemplate( $template );
823 function showCreateOrLoginLink( &$user ) {
824 if( $this->mType
== 'signup' ) {
826 } elseif( $user->isAllowed( 'createaccount' ) ) {
834 * Check if a session cookie is present.
836 * This will not pick up a cookie set during _this_ request, but is
837 * meant to ensure that the client is returning the cookie which was
838 * set on a previous pass through the system.
842 function hasSessionCookie() {
843 global $wgDisableCookieCheck, $wgRequest;
844 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
850 function cookieRedirectCheck( $type ) {
853 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
854 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
856 return $wgOut->redirect( $check );
862 function onCookieRedirectCheck( $type ) {
865 if ( !$this->hasSessionCookie() ) {
866 if ( $type == 'new' ) {
867 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
868 } else if ( $type == 'login' ) {
869 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
872 return $this->mainLoginForm( wfMsg( 'error' ) );
875 return $this->successfulLogin( wfMsgExt( 'loginsuccess', array( 'parseinline' ), $wgUser->getName() ) );
882 function throttleHit( $limit ) {
885 $wgOut->addWikiMsg( 'acct_creation_throttle_hit', $limit );
889 * Produce a bar of links which allow the user to select another language
890 * during login/registration but retain "returnto"
894 function makeLanguageSelector() {
895 $msg = wfMsgForContent( 'loginlanguagelinks' );
896 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
897 $langs = explode( "\n", $msg );
899 foreach( $langs as $lang ) {
900 $lang = trim( $lang, '* ' );
901 $parts = explode( '|', $lang );
902 if (count($parts) >= 2) {
903 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
906 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
913 * Create a language selector link for a particular language
914 * Links back to this page preserving type and returnto
916 * @param $text Link text
917 * @param $lang Language code
919 function makeLanguageSelectorLink( $text, $lang ) {
921 $self = SpecialPage
::getTitleFor( 'Userlogin' );
922 $attr[] = 'uselang=' . $lang;
923 if( $this->mType
== 'signup' )
924 $attr[] = 'type=signup';
925 if( $this->mReturnTo
)
926 $attr[] = 'returnto=' . $this->mReturnTo
;
927 $skin = $wgUser->getSkin();
928 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );