r91100 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91099‎ | r91100 | r91101 >
Date:20:04, 29 June 2011
Author:akshay
Status:deferred (Comments)
Tags:signupapi 
Comment:
refactored to act more like an MVC model & some other minor fixes
Modified paths:
  • /trunk/extensions/SignupAPI/includes/SpecialUserSignup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php
@@ -46,6 +46,7 @@
4747 const BLOCKED_BY_HOOK = 15;
4848 const EXTR_DB_ERROR = 16;
4949 const THROTLLED = 17;
 50+ const INIT_FAILED = 18;
5051
5152
5253 //Initialise all variables to be used
@@ -55,7 +56,7 @@
5657 var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
5758 var $mType, $mReason, $mRealName;
5859 var $abortError = '';
59 - var $mUser;
 60+ var $mUser,$mConfirmationMailStatus,$mRunCookieRedirect,$mRunCreationConfirmation;
6061
6162 /**
6263 * @var ExternalUser
@@ -187,12 +188,6 @@
188189 function addNewAccount($mUser) {
189190 global $wgUser, $wgEmailAuthentication, $wgOut;
190191
191 - # Create the account and abort if there's a problem doing so
192 - //$mUser = $this->addNewAccountInternal();
193 - if( $mUser == null ) {
194 - return;
195 - }
196 -
197192 # If we showed up language selection links, and one was in use, be
198193 # smart (and sensible) and save that language as the user's preference
199194 global $wgLoginLanguageSelector;
@@ -201,13 +196,8 @@
202197 }
203198
204199 # Send out an email authentication message if needed
205 - if( $wgEmailAuthentication && User::isValidEmailAddr( $mUser->getEmail() ) ) {
206 - $status = $mUser->sendConfirmationMail();
207 - if( $status->isGood() ) {
208 - $wgOut->addWikiMsg( 'confirmemail_oncreate' );
209 - } else {
210 - $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
211 - }
 200+ if( $wgEmailAuthentication ) {
 201+ $this->mConfirmationMailStatus = $mUser->sendConfirmationMail();
212202 }
213203
214204 # Save settings (including confirmation token)
@@ -222,16 +212,13 @@
223213 wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
224214 $wgUser->addNewUserLogEntry();
225215 if( $this->hasSessionCookie() ) {
226 - return $this->successfulCreation();
 216+ return true;
227217 } else {
228 - return $this->cookieRedirectCheck( 'new' );
 218+ $this->mRunCookieRedirect = true;
 219+ return true;
229220 }
230221 } else {
231 - # Confirm that the account was created
232 - $self = SpecialPage::getTitleFor( 'Userlogin' );
233 - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
234 - $wgOut->addWikiMsg( 'accountcreatedtext', $mUser->getName() );
235 - $wgOut->returnToMain( false, $self );
 222+ $this->mRunCreationConfirmation = true;
236223 wfRunHooks( 'AddNewAccount', array( $mUser, false ) );
237224 $mUser->addNewUserLogEntry( false, $this->mReason );
238225 return true;
@@ -274,17 +261,18 @@
275262 self::setCreateaccountToken();
276263 return self::NO_COOKIES;
277264 }
278 -
 265+
279266 # The user didn't pass a createaccount token
280267 if ( !$this->mToken ) {
281268 return self::NEED_TOKEN;
282269 }
283270
 271+
284272 # Validate the createaccount token
285273 if ( $this->mToken !== self::getCreateaccountToken() ) {
286274 return self::WRONG_TOKEN;
287275 }
288 -
 276+
289277 # Check permissions
290278 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
291279 return self::INSUFFICIENT_PERMISSION;
@@ -364,8 +352,12 @@
365353
366354 self::clearCreateaccountToken();
367355 $mUser = $this->initUser( $mUser, false );
368 - $this->addNewAccount($mUser);
369 - return self::SUCCESS;
 356+ if( $mUser == null ) {
 357+ return self::INIT_FAILED;
 358+ }
 359+
 360+ $this->addNewAccount($mUser);
 361+ return self::SUCCESS;
370362 }
371363
372364 /**
@@ -411,12 +403,28 @@
412404 }
413405
414406 function processSignup() {
415 - global $wgUser, $wgOut;
 407+ global $wgUser, $wgOut, $wgEmailAuthentication;
416408
417409 switch ( $this->addNewAccountInternal() ) {
418410 case self::SUCCESS:
419 - //$this->initUser( $mUser, false );
420 - //$this->addNewAccount($mUser);
 411+ if( $wgEmailAuthentication ) {
 412+ if( $this->mConfirmationMailStatus->isGood() ) {
 413+ $wgOut->addWikiMsg( 'confirmemail_oncreate' );
 414+ } else {
 415+ $wgOut->addWikiText( $this->mConfirmationMailStatus->getWikiText( 'confirmemail_sendfailed' ) );
 416+ }
 417+ }
 418+ if( $this->mRunCookieRedirect ) {
 419+ $this->cookieRedirectCheck( 'new' );
 420+ }
 421+ # Confirm that the account was created
 422+ if($this->mRunCreationConfirmation) {
 423+ $self = SpecialPage::getTitleFor( 'Userlogin' );
 424+ $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
 425+ $wgOut->addWikiMsg( 'accountcreatedtext', $mUser->getName() );
 426+ $wgOut->returnToMain( false, $self );
 427+ }
 428+ $this->successfulCreation();
421429 break;
422430 case self::INVALID_DOMAIN:
423431 $this->mainSignupForm( wfMsg( 'wrongpassword' ) );
@@ -475,10 +483,13 @@
476484 case self::EXTR_DB_ERROR:
477485 $this->mainSignupForm( wfMsg( 'externaldberror' ) );
478486 break;
479 - case self::THROTLLED;
 487+ case self::THROTLLED:
480488 global $wgAccountCreationThrottle;
481489 $this->mainSignupForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $wgAccountCreationThrottle ) );
482490 break;
 491+ case self::INIT_FAILED:
 492+ $this->mainSignupForm( wfMsg( 'init_failed' ) );
 493+ break;
483494 default:
484495 throw new MWException( 'Unhandled case value' );
485496 }
@@ -602,7 +613,7 @@
603614 if ( $wgUser->isLoggedIn() ) {
604615 $this->mUsername = $wgUser->getName();
605616 } else {
606 - //$this->mUsername = $wgRequest->getCookie( 'UserName' );
 617+ $this->mUsername = $wgRequest->getCookie( 'UserName' );
607618 }
608619 }
609620

Comments

#Comment by Reedy (talk | contribs)   01:16, 30 June 2011

You've got mixed spaces and tabs for whitespace,in both this and other commits

See Manual:Coding_conventions#Tab_size

Status & tagging log