Wikia code/includes/specials/SpecialUserlogin.php
From MediaWiki.org
< Wikia code | includes | specials
Removed one silly (probably accidental) change in Wikia code. Still many diffs below...
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\specials\SpecialUserlogin.php 2011-07-18 22:31:17.701171900 +0100 +++ D:\Programming\SVN\wikia\trunk\includes\specials\SpecialUserlogin.php 2011-08-17 15:28:16.346679700 +0100 @@ -42,6 +42,7 @@ var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage; var $mSkipCookieCheck, $mReturnToQuery, $mToken; + var $mMarketingOptIn, $wpBirthYear, $wpBirthMonth, $wpBirthDay; private $mExtUser = null; @@ -70,10 +72,15 @@ $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' ); $this->mAction = $request->getVal( 'action' ); $this->mRemember = $request->getCheck( 'wpRemember' ); + $this->mMarketingOptIn = $request->getCheck( 'wpMarketingOptIn' ); $this->mLanguage = $request->getText( 'uselang' ); $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' ); $this->mToken = ($this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' ); + $this->wpBirthYear = $request->getVal( 'wpBirthYear' ); + $this->wpBirthMonth = $request->getVal( 'wpBirthMonth' ); + $this->wpBirthDay = $request->getVal( 'wpBirthDay' ); + if ( $wgRedirectOnLogin ) { $this->mReturnTo = $wgRedirectOnLogin; $this->mReturnToQuery = ''; @@ -95,14 +102,21 @@ } $wgAuth->setDomain( $this->mDomain ); - # When switching accounts, it sucks to get automatically logged out - $returnToTitle = Title::newFromText( $this->mReturnTo ); - if( is_object( $returnToTitle ) && $returnToTitle->isSpecial( 'Userlogout' ) ) { + + $title = Title::newFromText($this->mReturnTo); + if (!empty($title)) + { + $this->mResolvedReturnTo = strtolower(SpecialPage::resolveAlias($title->getDBKey())); + if(in_array($this->mResolvedReturnTo,array('userlogout','signup','connect'))) + { $this->mReturnTo = ''; $this->mReturnToQuery = ''; } } + + } + function execute() { if ( !is_null( $this->mCookieCheck ) ) { $this->onCookieRedirectCheck( $this->mCookieCheck ); @@ -131,9 +145,7 @@ $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) ); return; } - - $u = $this->addNewaccountInternal(); - + $u = $this->addNewAccountInternal(); if ($u == null) { return; } @@ -200,7 +212,9 @@ wfRunHooks( 'AddNewAccount', array( $wgUser, false ) ); $wgUser->addNewUserLogEntry(); if( $this->hasSessionCookie() ) { - return $this->successfulCreation(); + $ret = $this->successfulCreation(); + wfRunHooks( 'AddNewAccount2', array( $wgUser ) ); + return $ret; } else { return $this->cookieRedirectCheck( 'new' ); } @@ -228,9 +242,34 @@ global $wgAuth, $wgMinimalPasswordLength; global $wgEmailConfirmToEdit; + /* wikia change start */ + //new registration - start [Marooned [at] wikia-inc.com] + //check if the date has been choosen + if ($this->wpBirthYear == -1 || $this->wpBirthMonth == -1 || $this->wpBirthDay == -1) { + $this->mainLoginForm( wfMsg( 'userlogin-bad-birthday' ) ); + return null; + } + + $userBirthDay = strtotime($this->wpBirthYear . '-' . $this->wpBirthMonth . '-' . $this->wpBirthDay); + if($userBirthDay > strtotime('-13 years')) { + $wgOut->setPageTitle( wfMsg('userlogin-unable-title') ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->setArticleRelated( false ); + $wgOut->addScript('<script type="text/javascript">WET.byStr(\'signupActions/signup/createaccount/failure\');</script>'); + $wgOut->addWikiText( wfMsg('userlogin-unable-info') ); + if ( !empty( $this->mReturnTo ) ) { + $wgOut->returnToMain( true, $this->mReturnTo ); + } else { + $wgOut->returnToMain( true ); + } + return null; + } + //new registration - end + /* wikia change end */ + // If the user passes an invalid domain, something is fishy if( !$wgAuth->validDomain( $this->mDomain ) ) { - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); // TODO: Misleading message. return false; } @@ -293,7 +332,12 @@ return false; } - if ( 0 != $u->idForName() ) { + $this->mExtUser = ExternalUser::newFromName( $this->mName ); + + if ( is_object( $this->mExtUser ) && ( 0 != $this->mExtUser->getId() ) ) { + $this->mainLoginForm( wfMsg( 'userexists' ) ); + return false; + } elseif ( 0 != $u->idForName() ) { $this->mainLoginForm( wfMsg( 'userexists' ) ); return false; } @@ -360,7 +404,19 @@ } self::clearCreateaccountToken(); - return $this->initUser( $u, false ); + $u->mBirthDate = date('Y-m-d', $userBirthDay); + $u = $this->initUser( $u, false ); + $user_id = $u->getID(); + if(!empty($user_id)) { + $dbw = wfGetDB(DB_MASTER); + $dbw->update( + 'user', + array( 'user_birthdate' => date('Y-m-d', $userBirthDay) ), + array( 'user_id' => $user_id ), + __METHOD__ + ); + } + return $u; } /** @@ -373,9 +429,16 @@ * @private */ function initUser( $u, $autocreate ) { - global $wgAuth; + global $wgAuth, $wgExternalAuthType; + if ( $wgExternalAuthType ) { + $u = ExternalUser::addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ); + if ( is_object( $u ) ) { + $this->mExtUser = ExternalUser::newFromName( $this->mName ); + } + } else{ $u->addToDatabase(); + } if ( $wgAuth->allowPasswordChange() ) { $u->setPassword( $this->mPassword ); @@ -387,7 +450,7 @@ $wgAuth->initUser( $u, $autocreate ); - if ( $this->mExtUser ) { + if ( is_object( $this->mExtUser ) ) { $this->mExtUser->linkToLocal( $u->getId() ); $email = $this->mExtUser->getPref( 'emailaddress' ); if ( $email && !$this->mEmail ) { @@ -396,6 +459,8 @@ } $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); + $u->setOption( 'marketingallowed', $this->mMarketingOptIn ? 1 : 0 ); + $u->setOption('skinoverwrite', 1); $u->saveSettings(); # Update user count @@ -423,7 +488,6 @@ // token-less login attempts don't count towards the throttle // but wrong-token attempts do. - // If the user doesn't have a login token yet, set one. if ( !self::getLoginToken() ) { self::setLoginToken(); return self::NEED_TOKEN; @@ -470,6 +534,15 @@ $this->mExtUser = ExternalUser::newFromName( $this->mName ); + global $wgExternalAuthType, $wgAutocreatePolicy; + if ( $wgExternalAuthType && $wgAutocreatePolicy != 'never' + && is_object( $this->mExtUser ) + && $this->mExtUser->authenticate( $this->mPassword ) ) { + # The external user and local user have the same name and + # password, so we assume they're the same. + $this->mExtUser->linkToLocal( $this->mExtUser->getId() ); + } + # TODO: Allow some magic here for invalid external names, e.g., let the # user choose a different wiki name. $u = User::newFromName( $this->mName ); @@ -485,17 +558,6 @@ } else { $isAutoCreated = true; } - } else { - global $wgExternalAuthType, $wgAutocreatePolicy; - if ( $wgExternalAuthType && $wgAutocreatePolicy != 'never' - && is_object( $this->mExtUser ) - && $this->mExtUser->authenticate( $this->mPassword ) ) { - # The external user and local user have the same name and - # password, so we assume they're the same. - $this->mExtUser->linkToLocal( $u->getID() ); - } - - $u->load(); } // Give general extensions, such as a captcha, a chance to abort logins @@ -785,7 +847,7 @@ * @private */ function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) { - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry; + global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgNoReplyAddress; if ( $u->getEmail() == '' ) { return new WikiError( wfMsg( 'noemail', $u->getName() ) ); @@ -800,10 +862,27 @@ $np = $u->randomPassword(); $u->setNewpassword( $np, $throttle ); $u->saveSettings(); + /* Wikia change begin - @author: Uberfuzzy */ + /* use noReply address (if available) */ + $nr = null; + if( !empty($wgNoReplyAddress) ) { + $nr = new MailAddress($wgNoReplyAddress, 'No Reply'); + } + /* Wikia change begin - @author: Marooned */ + /* HTML e-mails functionality */ + global $wgEnableRichEmails; + $priority = 1; // Password emails are higher than default priority of 0 + if (empty($wgEnableRichEmails)) { $userLanguage = $u->getOption( 'language' ); $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $userLanguage ), $ip, $u->getName(), $np, $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) ); - $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m ); + $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m, null, $nr, 'TemporaryPassword', $priority ); + } + else { + $wantHTML = $u->isAnon() || $u->getOption('htmlemails'); + list($m, $mHTML) = wfMsgHTMLwithLanguage($emailText, $u->getOption('language'), array( 'parsemag' ), array($ip, $u->getName(), $np, $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 )), $wantHTML); + $result = $u->sendMail( wfMsg( $emailTitle ), $m, null, $nr, 'TemporaryPassword', $mHTML, $priority ); + } return $result; } @@ -830,10 +909,12 @@ $this->displaySuccessfulLogin( 'loginsuccess', $injected_html ); } else { $titleObj = Title::newFromText( $this->mReturnTo ); - if ( !$titleObj instanceof Title ) { + if ( ( !$titleObj instanceof Title ) || ( $titleObj->isSpecial("Userlogout") ) || ( $titleObj->isSpecial("Signup") ) ) { $titleObj = Title::newMainPage(); + $wgOut->redirect( $titleObj->getFullURL( "cb=".rand(1,10000) ) ); + return true; } - $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery ) ); + $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery . "&cb=".rand(1,10000) ) ); } } @@ -925,6 +1006,10 @@ $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); + if ( ('' != $msg) && ('error' == $msgtype) && ('signup' == $this->mType) ) { + $wgOut->addScript('<script type="text/javascript">WET.byStr(\'signupActions/signup/createaccount/failure\');</script>'); + } + if ( $this->mType == 'signup' ) { // Block signup here if in readonly. Keeps user from // going through the process (filling out data, etc) @@ -954,11 +1039,16 @@ if ( $this->mType == 'signup' ) { $template = new UsercreateTemplate(); $q = 'action=submitlogin&type=signup'; + $q2 = 'action=submitlogin&type=login'; $linkq = 'type=login'; $linkmsg = 'gotaccount'; + + // ADi: marketing opt-in/out checkbox added + $template->addInputItem( 'wpMarketingOptIn', 1, 'checkbox', 'tog-marketingallowed'); } else { $template = new UserloginTemplate(); $q = 'action=submitlogin&type=login'; + $q2 = 'action=submitlogin&type=login'; $linkq = 'type=signup'; $linkmsg = 'nologin'; } @@ -970,6 +1060,8 @@ wfUrlencode( $this->mReturnToQuery ); $q .= $returnto; $linkq .= $returnto; + $q2 .= $returnto; + //$linkq2 .= $returnto; // not used anywhere else... FIXME: REMOVE } # Pass any language selection on to the mode switch link @@ -994,7 +1086,9 @@ $template->set( 'realname', $this->mRealName ); $template->set( 'domain', $this->mDomain ); - $template->set( 'action', $titleObj->getLocalUrl( $q ) ); + $template->set( 'actioncreate', $titleObj->getLocalUrl( $q ) ); + $template->set( 'actionlogin', $titleObj->getLocalUrl( $q2 ) ); + $template->set( 'message', $msg ); $template->set( 'messagetype', $msgtype ); $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() ); @@ -1005,6 +1099,10 @@ $template->set( 'canremember', ( $wgCookieExpiration > 0 ) ); $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember ); + $template->set( 'birthyear', $this->wpBirthYear ); + $template->set( 'birthmonth', $this->wpBirthMonth ); + $template->set( 'birthday', $this->wpBirthDay ); + if ( $this->mType == 'signup' ) { if ( !self::getCreateaccountToken() ) { self::setCreateaccountToken();