00001 <?php
00010 function wfSpecialUserlogin( $par = '' ) {
00011 global $wgRequest;
00012 if( session_id() == '' ) {
00013 wfSetupSession();
00014 }
00015
00016 $form = new LoginForm( $wgRequest, $par );
00017 $form->execute();
00018 }
00019
00024 class LoginForm {
00025
00026 const SUCCESS = 0;
00027 const NO_NAME = 1;
00028 const ILLEGAL = 2;
00029 const WRONG_PLUGIN_PASS = 3;
00030 const NOT_EXISTS = 4;
00031 const WRONG_PASS = 5;
00032 const EMPTY_PASS = 6;
00033 const RESET_PASS = 7;
00034 const ABORTED = 8;
00035 const CREATE_BLOCKED = 9;
00036 const THROTTLED = 10;
00037
00038 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
00039 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
00040 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage, $mSkipCookieCheck;
00041
00046 function LoginForm( &$request, $par = '' ) {
00047 global $wgLang, $wgAllowRealName, $wgEnableEmail;
00048 global $wgAuth, $wgRedirectOnLogin;
00049
00050 $this->mType = ( $par == 'signup' ) ? $par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
00051 $this->mName = $request->getText( 'wpName' );
00052 $this->mPassword = $request->getText( 'wpPassword' );
00053 $this->mRetype = $request->getText( 'wpRetype' );
00054 $this->mDomain = $request->getText( 'wpDomain' );
00055 $this->mReturnTo = $request->getVal( 'returnto' );
00056 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
00057 $this->mPosted = $request->wasPosted();
00058 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
00059 $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
00060 && $wgEnableEmail;
00061 $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' )
00062 && $wgEnableEmail;
00063 $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
00064 $this->mAction = $request->getVal( 'action' );
00065 $this->mRemember = $request->getCheck( 'wpRemember' );
00066 $this->mLanguage = $request->getText( 'uselang' );
00067 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
00068
00069 if ( $wgRedirectOnLogin ) {
00070 $this->mReturnTo = $wgRedirectOnLogin;
00071 }
00072
00073 if( $wgEnableEmail ) {
00074 $this->mEmail = $request->getText( 'wpEmail' );
00075 } else {
00076 $this->mEmail = '';
00077 }
00078 if( $wgAllowRealName ) {
00079 $this->mRealName = $request->getText( 'wpRealName' );
00080 } else {
00081 $this->mRealName = '';
00082 }
00083
00084 if( !$wgAuth->validDomain( $this->mDomain ) ) {
00085 $this->mDomain = 'invaliddomain';
00086 }
00087 $wgAuth->setDomain( $this->mDomain );
00088
00089 # When switching accounts, it sucks to get automatically logged out
00090 if( $this->mReturnTo == $wgLang->specialPage( 'Userlogout' ) ) {
00091 $this->mReturnTo = '';
00092 }
00093 }
00094
00095 function execute() {
00096 if ( !is_null( $this->mCookieCheck ) ) {
00097 $this->onCookieRedirectCheck( $this->mCookieCheck );
00098 return;
00099 } else if( $this->mPosted ) {
00100 if( $this->mCreateaccount ) {
00101 return $this->addNewAccount();
00102 } else if ( $this->mCreateaccountMail ) {
00103 return $this->addNewAccountMailPassword();
00104 } else if ( $this->mMailmypassword ) {
00105 return $this->mailPassword();
00106 } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
00107 return $this->processLogin();
00108 }
00109 }
00110 $this->mainLoginForm( '' );
00111 }
00112
00116 function addNewAccountMailPassword() {
00117 global $wgOut;
00118
00119 if ('' == $this->mEmail) {
00120 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) );
00121 return;
00122 }
00123
00124 $u = $this->addNewaccountInternal();
00125
00126 if ($u == NULL) {
00127 return;
00128 }
00129
00130
00131 $u->setPassword( null );
00132 $u->saveSettings();
00133 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
00134
00135 wfRunHooks( 'AddNewAccount', array( $u, true ) );
00136 $u->addNewUserLogEntry();
00137
00138 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
00139 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00140 $wgOut->setArticleRelated( false );
00141
00142 if( WikiError::isError( $result ) ) {
00143 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
00144 } else {
00145 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
00146 $wgOut->returnToMain( false );
00147 }
00148 $u = 0;
00149 }
00150
00151
00155 function addNewAccount() {
00156 global $wgUser, $wgEmailAuthentication;
00157
00158 # Create the account and abort if there's a problem doing so
00159 $u = $this->addNewAccountInternal();
00160 if( $u == NULL )
00161 return;
00162
00163 # If we showed up language selection links, and one was in use, be
00164 # smart (and sensible) and save that language as the user's preference
00165 global $wgLoginLanguageSelector;
00166 if( $wgLoginLanguageSelector && $this->mLanguage )
00167 $u->setOption( 'language', $this->mLanguage );
00168
00169 # Send out an email authentication message if needed
00170 if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) {
00171 global $wgOut;
00172 $error = $u->sendConfirmationMail();
00173 if( WikiError::isError( $error ) ) {
00174 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
00175 } else {
00176 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
00177 }
00178 }
00179
00180 # Save settings (including confirmation token)
00181 $u->saveSettings();
00182
00183 # If not logged in, assume the new account as the current one and set
00184 # session cookies then show a "welcome" message or a "need cookies"
00185 # message as needed
00186 if( $wgUser->isAnon() ) {
00187 $wgUser = $u;
00188 $wgUser->setCookies();
00189 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
00190 $wgUser->addNewUserLogEntry();
00191 if( $this->hasSessionCookie() ) {
00192 return $this->successfulCreation();
00193 } else {
00194 return $this->cookieRedirectCheck( 'new' );
00195 }
00196 } else {
00197 # Confirm that the account was created
00198 global $wgOut;
00199 $self = SpecialPage::getTitleFor( 'Userlogin' );
00200 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
00201 $wgOut->setArticleRelated( false );
00202 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00203 $wgOut->addHTML( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
00204 $wgOut->returnToMain( false, $self );
00205 wfRunHooks( 'AddNewAccount', array( $u ) );
00206 $u->addNewUserLogEntry();
00207 return true;
00208 }
00209 }
00210
00214 function addNewAccountInternal() {
00215 global $wgUser, $wgOut;
00216 global $wgEnableSorbs, $wgProxyWhitelist;
00217 global $wgMemc, $wgAccountCreationThrottle;
00218 global $wgAuth, $wgMinimalPasswordLength;
00219 global $wgEmailConfirmToEdit;
00220
00221
00222 if( !$wgAuth->validDomain( $this->mDomain ) ) {
00223 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
00224 return false;
00225 }
00226
00227
00228
00229
00230
00231
00232 if( 'local' != $this->mDomain && '' != $this->mDomain ) {
00233 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) {
00234 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
00235 return false;
00236 }
00237 }
00238
00239 if ( wfReadOnly() ) {
00240 $wgOut->readOnlyPage();
00241 return false;
00242 }
00243
00244 # Check permissions
00245 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
00246 $this->userNotPrivilegedMessage();
00247 return false;
00248 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
00249 $this->userBlockedMessage();
00250 return false;
00251 }
00252
00253 $ip = wfGetIP();
00254 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
00255 $wgUser->inSorbsBlacklist( $ip ) )
00256 {
00257 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
00258 return;
00259 }
00260
00261 # Now create a dummy user ($u) and check if it is valid
00262 $name = trim( $this->mName );
00263 $u = User::newFromName( $name, 'creatable' );
00264 if ( is_null( $u ) ) {
00265 $this->mainLoginForm( wfMsg( 'noname' ) );
00266 return false;
00267 }
00268
00269 if ( 0 != $u->idForName() ) {
00270 $this->mainLoginForm( wfMsg( 'userexists' ) );
00271 return false;
00272 }
00273
00274 if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
00275 $this->mainLoginForm( wfMsg( 'badretype' ) );
00276 return false;
00277 }
00278
00279 # check for minimal password length
00280 if ( !$u->isValidPassword( $this->mPassword ) ) {
00281 if ( !$this->mCreateaccountMail ) {
00282 $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) );
00283 return false;
00284 } else {
00285 # do not force a password for account creation by email
00286 # set invalid password, it will be replaced later by a random generated password
00287 $this->mPassword = null;
00288 }
00289 }
00290
00291 # if you need a confirmed email address to edit, then obviously you
00292 # need an email address.
00293 if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
00294 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
00295 return false;
00296 }
00297
00298 if( !empty( $this->mEmail ) && !User::isValidEmailAddr( $this->mEmail ) ) {
00299 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
00300 return false;
00301 }
00302
00303 # Set some additional data so the AbortNewAccount hook can be used for
00304 # more than just username validation
00305 $u->setEmail( $this->mEmail );
00306 $u->setRealName( $this->mRealName );
00307
00308 $abortError = '';
00309 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
00310
00311 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
00312 $this->mainLoginForm( $abortError );
00313 return false;
00314 }
00315
00316 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
00317 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
00318 $value = $wgMemc->get( $key );
00319 if ( !$value ) {
00320 $wgMemc->set( $key, 0, 86400 );
00321 }
00322 if ( $value >= $wgAccountCreationThrottle ) {
00323 $this->throttleHit( $wgAccountCreationThrottle );
00324 return false;
00325 }
00326 $wgMemc->incr( $key );
00327 }
00328
00329 if( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) {
00330 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
00331 return false;
00332 }
00333
00334 return $this->initUser( $u, false );
00335 }
00336
00346 function initUser( $u, $autocreate ) {
00347 global $wgAuth;
00348
00349 $u->addToDatabase();
00350
00351 if ( $wgAuth->allowPasswordChange() ) {
00352 $u->setPassword( $this->mPassword );
00353 }
00354
00355 $u->setEmail( $this->mEmail );
00356 $u->setRealName( $this->mRealName );
00357 $u->setToken();
00358
00359 $wgAuth->initUser( $u, $autocreate );
00360
00361 $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
00362 $u->saveSettings();
00363
00364 # Update user count
00365 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
00366 $ssUpdate->doUpdate();
00367
00368 return $u;
00369 }
00370
00380 function authenticateUserData() {
00381 global $wgUser, $wgAuth;
00382 if ( '' == $this->mName ) {
00383 return self::NO_NAME;
00384 }
00385
00386 global $wgPasswordAttemptThrottle;
00387
00388 $throttleCount=0;
00389 if ( is_array($wgPasswordAttemptThrottle) ) {
00390 $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
00391 $count = $wgPasswordAttemptThrottle['count'];
00392 $period = $wgPasswordAttemptThrottle['seconds'];
00393
00394 global $wgMemc;
00395 $throttleCount = $wgMemc->get($throttleKey);
00396 if ( !$throttleCount ) {
00397 $wgMemc->add( $throttleKey, 1, $period );
00398 } else if ( $throttleCount < $count ) {
00399 $wgMemc->incr($throttleKey);
00400 } else if ( $throttleCount >= $count ) {
00401 return self::THROTTLED;
00402 }
00403 }
00404
00405
00406
00407
00408
00409
00410
00411 if ( $wgUser->getName() === $this->mName ) {
00412 wfDebug( __METHOD__.": already logged in as {$this->mName}\n" );
00413 return self::SUCCESS;
00414 }
00415 $u = User::newFromName( $this->mName );
00416 if( is_null( $u ) || !User::isUsableName( $u->getName() ) ) {
00417 return self::ILLEGAL;
00418 }
00419
00420 $isAutoCreated = false;
00421 if ( 0 == $u->getID() ) {
00422 $status = $this->attemptAutoCreate( $u );
00423 if ( $status !== self::SUCCESS ) {
00424 return $status;
00425 } else {
00426 $isAutoCreated = true;
00427 }
00428 } else {
00429 $u->load();
00430 }
00431
00432
00433 $abort = self::ABORTED;
00434 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort ) ) ) {
00435 return $abort;
00436 }
00437
00438 if (!$u->checkPassword( $this->mPassword )) {
00439 if( $u->checkTemporaryPassword( $this->mPassword ) ) {
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 if( !$u->isEmailConfirmed() ) {
00457 $u->confirmEmail();
00458 $u->saveSettings();
00459 }
00460
00461
00462
00463
00464 $retval = self::RESET_PASS;
00465 } else {
00466 $retval = '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
00467 }
00468 } else {
00469 $wgAuth->updateUser( $u );
00470 $wgUser = $u;
00471
00472
00473 if($throttleCount) {
00474 $wgMemc->delete($throttleKey);
00475 }
00476
00477 if ( $isAutoCreated ) {
00478
00479 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
00480 }
00481
00482 $retval = self::SUCCESS;
00483 }
00484 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
00485 return $retval;
00486 }
00487
00493 function attemptAutoCreate( $user ) {
00494 global $wgAuth, $wgUser;
00500 if ( !$wgAuth->autoCreate() ) {
00501 return self::NOT_EXISTS;
00502 }
00503 if ( !$wgAuth->userExists( $user->getName() ) ) {
00504 wfDebug( __METHOD__.": user does not exist\n" );
00505 return self::NOT_EXISTS;
00506 }
00507 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) {
00508 wfDebug( __METHOD__.": \$wgAuth->authenticate() returned false, aborting\n" );
00509 return self::WRONG_PLUGIN_PASS;
00510 }
00511 if ( $wgUser->isBlockedFromCreateAccount() ) {
00512 wfDebug( __METHOD__.": user is blocked from account creation\n" );
00513 return self::CREATE_BLOCKED;
00514 }
00515
00516 wfDebug( __METHOD__.": creating account\n" );
00517 $user = $this->initUser( $user, true );
00518 return self::SUCCESS;
00519 }
00520
00521 function processLogin() {
00522 global $wgUser, $wgAuth;
00523
00524 switch ($this->authenticateUserData())
00525 {
00526 case self::SUCCESS:
00527 # We've verified now, update the real record
00528 if( (bool)$this->mRemember != (bool)$wgUser->getOption( 'rememberpassword' ) ) {
00529 $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
00530 $wgUser->saveSettings();
00531 } else {
00532 $wgUser->invalidateCache();
00533 }
00534 $wgUser->setCookies();
00535
00536
00537 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
00538 global $wgMemc;
00539 $wgMemc->delete( $key );
00540
00541 if( $this->hasSessionCookie() || $this->mSkipCookieCheck ) {
00542
00543
00544
00545 global $wgLang, $wgRequest;
00546 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
00547 $wgLang = Language::factory( $code );
00548 return $this->successfulLogin();
00549 } else {
00550 return $this->cookieRedirectCheck( 'login' );
00551 }
00552 break;
00553
00554 case self::NO_NAME:
00555 case self::ILLEGAL:
00556 $this->mainLoginForm( wfMsg( 'noname' ) );
00557 break;
00558 case self::WRONG_PLUGIN_PASS:
00559 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
00560 break;
00561 case self::NOT_EXISTS:
00562 if( $wgUser->isAllowed( 'createaccount' ) ){
00563 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
00564 } else {
00565 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName ) ) );
00566 }
00567 break;
00568 case self::WRONG_PASS:
00569 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
00570 break;
00571 case self::EMPTY_PASS:
00572 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
00573 break;
00574 case self::RESET_PASS:
00575 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
00576 break;
00577 case self::CREATE_BLOCKED:
00578 $this->userBlockedMessage();
00579 break;
00580 case self::THROTTLED:
00581 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
00582 break;
00583 default:
00584 throw new MWException( "Unhandled case value" );
00585 }
00586 }
00587
00588 function resetLoginForm( $error ) {
00589 global $wgOut;
00590 $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
00591 $reset = new SpecialResetpass();
00592 $reset->execute( null );
00593 }
00594
00598 function mailPassword() {
00599 global $wgUser, $wgOut, $wgAuth;
00600
00601 if ( wfReadOnly() ) {
00602 $wgOut->readOnlyPage();
00603 return false;
00604 }
00605
00606 if( !$wgAuth->allowPasswordChange() ) {
00607 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
00608 return;
00609 }
00610
00611 # Check against blocked IPs
00612 # fixme -- should we not?
00613 if( $wgUser->isBlocked() ) {
00614 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
00615 return;
00616 }
00617
00618 # Check against the rate limiter
00619 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
00620 $wgOut->rateLimited();
00621 return;
00622 }
00623
00624 if ( '' == $this->mName ) {
00625 $this->mainLoginForm( wfMsg( 'noname' ) );
00626 return;
00627 }
00628 $u = User::newFromName( $this->mName );
00629 if( is_null( $u ) ) {
00630 $this->mainLoginForm( wfMsg( 'noname' ) );
00631 return;
00632 }
00633 if ( 0 == $u->getID() ) {
00634 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) );
00635 return;
00636 }
00637
00638 # Check against password throttle
00639 if ( $u->isPasswordReminderThrottled() ) {
00640 global $wgPasswordReminderResendTime;
00641 # Round the time in hours to 3 d.p., in case someone is specifying
00642 # minutes or seconds.
00643 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
00644 round( $wgPasswordReminderResendTime, 3 ) ) );
00645 return;
00646 }
00647
00648 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
00649 if( WikiError::isError( $result ) ) {
00650 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
00651 } else {
00652 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
00653 }
00654 }
00655
00656
00665 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
00666 global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
00667
00668 if ( '' == $u->getEmail() ) {
00669 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
00670 }
00671 $ip = wfGetIP();
00672 if( !$ip ) {
00673 return new WikiError( wfMsg( 'badipaddress' ) );
00674 }
00675
00676 wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
00677
00678 $np = $u->randomPassword();
00679 $u->setNewpassword( $np, $throttle );
00680 $u->saveSettings();
00681
00682 $m = wfMsgExt( $emailText, array( 'parsemag' ), $ip, $u->getName(), $np,
00683 $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) );
00684 $result = $u->sendMail( wfMsg( $emailTitle ), $m );
00685
00686 return $result;
00687 }
00688
00689
00700 function successfulLogin() {
00701 global $wgUser, $wgOut;
00702
00703 # Run any hooks; display injected HTML if any, else redirect
00704 $injected_html = '';
00705 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
00706
00707 if( $injected_html !== '' ) {
00708 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
00709 } else {
00710 $titleObj = Title::newFromText( $this->mReturnTo );
00711 if ( !$titleObj instanceof Title ) {
00712 $titleObj = Title::newMainPage();
00713 }
00714
00715 $wgOut->redirect( $titleObj->getFullURL() );
00716 }
00717 }
00718
00725 function successfulCreation() {
00726 global $wgUser, $wgOut;
00727
00728 # Run any hooks; display injected HTML
00729 $injected_html = '';
00730 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
00731
00732 $this->displaySuccessfulLogin( 'welcomecreation', $injected_html );
00733 }
00734
00738 private function displaySuccessfulLogin( $msgname, $injected_html ) {
00739 global $wgOut, $wgUser;
00740
00741 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
00742 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00743 $wgOut->setArticleRelated( false );
00744 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
00745 $wgOut->addHTML( $injected_html );
00746
00747 if ( !empty( $this->mReturnTo ) ) {
00748 $wgOut->returnToMain( null, $this->mReturnTo );
00749 } else {
00750 $wgOut->returnToMain( null );
00751 }
00752 }
00753
00755 function userNotPrivilegedMessage($errors) {
00756 global $wgOut;
00757
00758 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
00759 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00760 $wgOut->setArticleRelated( false );
00761
00762 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
00763
00764
00765 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
00766
00767 $wgOut->returnToMain( false );
00768 }
00769
00771 function userBlockedMessage() {
00772 global $wgOut, $wgUser;
00773
00774 # Let's be nice about this, it's likely that this feature will be used
00775 # for blocking large numbers of innocent people, e.g. range blocks on
00776 # schools. Don't blame it on the user. There's a small chance that it
00777 # really is the user's fault, i.e. the username is blocked and they
00778 # haven't bothered to log out before trying to create an account to
00779 # evade it, but we'll leave that to their guilty conscience to figure
00780 # out.
00781
00782 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
00783 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00784 $wgOut->setArticleRelated( false );
00785
00786 $ip = wfGetIP();
00787 $blocker = User::whoIs( $wgUser->mBlock->mBy );
00788 $block_reason = $wgUser->mBlock->mReason;
00789
00790 if ( strval( $block_reason ) === '' ) {
00791 $block_reason = wfMsg( 'blockednoreason' );
00792 }
00793 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
00794 $wgOut->returnToMain( false );
00795 }
00796
00800 function mainLoginForm( $msg, $msgtype = 'error' ) {
00801 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
00802 global $wgCookiePrefix, $wgLoginLanguageSelector;
00803 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
00804
00805 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
00806
00807 if ( $this->mType == 'signup' ) {
00808
00809
00810
00811 if ( wfReadOnly() ) {
00812 $wgOut->readOnlyPage();
00813 return;
00814 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
00815 $this->userBlockedMessage();
00816 return;
00817 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
00818 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
00819 return;
00820 }
00821 }
00822
00823 if ( '' == $this->mName ) {
00824 if ( $wgUser->isLoggedIn() ) {
00825 $this->mName = $wgUser->getName();
00826 } else {
00827 $this->mName = isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : null;
00828 }
00829 }
00830
00831 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
00832
00833 if ( $this->mType == 'signup' ) {
00834 $template = new UsercreateTemplate();
00835 $q = 'action=submitlogin&type=signup';
00836 $linkq = 'type=login';
00837 $linkmsg = 'gotaccount';
00838 } else {
00839 $template = new UserloginTemplate();
00840 $q = 'action=submitlogin&type=login';
00841 $linkq = 'type=signup';
00842 $linkmsg = 'nologin';
00843 }
00844
00845 if ( !empty( $this->mReturnTo ) ) {
00846 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
00847 $q .= $returnto;
00848 $linkq .= $returnto;
00849 }
00850
00851 # Pass any language selection on to the mode switch link
00852 if( $wgLoginLanguageSelector && $this->mLanguage )
00853 $linkq .= '&uselang=' . $this->mLanguage;
00854
00855 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
00856 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
00857 $link .= '</a>';
00858
00859 # Don't show a "create account" link if the user can't
00860 if( $this->showCreateOrLoginLink( $wgUser ) )
00861 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
00862 else
00863 $template->set( 'link', '' );
00864
00865 $template->set( 'header', '' );
00866 $template->set( 'name', $this->mName );
00867 $template->set( 'password', $this->mPassword );
00868 $template->set( 'retype', $this->mRetype );
00869 $template->set( 'email', $this->mEmail );
00870 $template->set( 'realname', $this->mRealName );
00871 $template->set( 'domain', $this->mDomain );
00872
00873 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
00874 $template->set( 'message', $msg );
00875 $template->set( 'messagetype', $msgtype );
00876 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
00877 $template->set( 'userealname', $wgAllowRealName );
00878 $template->set( 'useemail', $wgEnableEmail );
00879 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
00880 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
00881 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
00882 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
00883
00884 # Prepare language selection links as needed
00885 if( $wgLoginLanguageSelector ) {
00886 $template->set( 'languages', $this->makeLanguageSelector() );
00887 if( $this->mLanguage )
00888 $template->set( 'uselang', $this->mLanguage );
00889 }
00890
00891
00892 $wgAuth->modifyUITemplate( $template );
00893 if ( $this->mType == 'signup' ) {
00894 wfRunHooks( 'UserCreateForm', array( &$template ) );
00895 } else {
00896 wfRunHooks( 'UserLoginForm', array( &$template ) );
00897 }
00898
00899 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
00900 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00901 $wgOut->setArticleRelated( false );
00902 $wgOut->disallowUserJs();
00903 $wgOut->addTemplate( $template );
00904 }
00905
00909 function showCreateOrLoginLink( &$user ) {
00910 if( $this->mType == 'signup' ) {
00911 return( true );
00912 } elseif( $user->isAllowed( 'createaccount' ) ) {
00913 return( true );
00914 } else {
00915 return( false );
00916 }
00917 }
00918
00928 function hasSessionCookie() {
00929 global $wgDisableCookieCheck, $wgRequest;
00930 return $wgDisableCookieCheck ? true : $wgRequest->checkSessionCookie();
00931 }
00932
00936 function cookieRedirectCheck( $type ) {
00937 global $wgOut;
00938
00939 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
00940 $query = array( 'wpCookieCheck' => $type );
00941 if ( $this->mReturnTo ) $query['returnto'] = $this->mReturnTo;
00942 $check = $titleObj->getFullURL( $query );
00943
00944 return $wgOut->redirect( $check );
00945 }
00946
00950 function onCookieRedirectCheck( $type ) {
00951 global $wgUser;
00952
00953 if ( !$this->hasSessionCookie() ) {
00954 if ( $type == 'new' ) {
00955 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
00956 } else if ( $type == 'login' ) {
00957 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
00958 } else {
00959 # shouldn't happen
00960 return $this->mainLoginForm( wfMsg( 'error' ) );
00961 }
00962 } else {
00963 return $this->successfulLogin();
00964 }
00965 }
00966
00970 function throttleHit( $limit ) {
00971 $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) );
00972 }
00973
00980 function makeLanguageSelector() {
00981 global $wgLang;
00982
00983 $msg = wfMsgForContent( 'loginlanguagelinks' );
00984 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
00985 $langs = explode( "\n", $msg );
00986 $links = array();
00987 foreach( $langs as $lang ) {
00988 $lang = trim( $lang, '* ' );
00989 $parts = explode( '|', $lang );
00990 if (count($parts) >= 2) {
00991 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
00992 }
00993 }
00994 return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', $wgLang->pipeList( $links ) ) : '';
00995 } else {
00996 return '';
00997 }
00998 }
00999
01007 function makeLanguageSelectorLink( $text, $lang ) {
01008 global $wgUser;
01009 $self = SpecialPage::getTitleFor( 'Userlogin' );
01010 $attr[] = 'uselang=' . $lang;
01011 if( $this->mType == 'signup' )
01012 $attr[] = 'type=signup';
01013 if( $this->mReturnTo )
01014 $attr[] = 'returnto=' . $this->mReturnTo;
01015 $skin = $wgUser->getSkin();
01016 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
01017 }
01018 }