r95200 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95199‎ | r95200 | r95201 >
Date:13:22, 22 August 2011
Author:akshay
Status:deferred (Comments)
Tags:signupapi 
Comment:
Followup r95185, replaced with , added hook for 'SignupForm' event which can be used to run hooks specifically for SpecialUserSignup
Modified paths:
  • /trunk/extensions/SignupAPI/includes/SpecialUserSignup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php
@@ -49,13 +49,13 @@
5050 const INIT_FAILED = 18;
5151
5252 //Initialise all variables to be used
53 - var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
 53+ var $tempUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
5454 var $mAction, $mCreateaccount, $mCreateaccountMail;
5555 var $mRemember, $mEmail, $mDomain, $mLanguage;
5656 var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
5757 var $mType, $mReason, $mRealName;
5858 var $abortError = '';
59 - var $mUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation;
 59+ var $tempUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation;
6060 var $mSourceAction, $mSourceNS, $msourceArticle;
6161
6262 /**
@@ -167,26 +167,26 @@
168168 return;
169169 }
170170
171 - $mUser = $this->addNewaccountInternal();
 171+ $tempUser = $this->addNewaccountInternal();
172172
173 - if ( $mUser == null ) {
 173+ if ( $tempUser == null ) {
174174 return;
175175 }
176176
177177 // Wipe the initial password and mail a temporary one
178 - $mUser->setPassword( null );
179 - $mUser->saveSettings();
180 - $result = $this->mailPasswordInternal( $mUser, false, 'createaccount-title', 'createaccount-text' );
 178+ $tempUser->setPassword( null );
 179+ $tempUser->saveSettings();
 180+ $result = $this->mailPasswordInternal( $tempUser, false, 'createaccount-title', 'createaccount-text' );
181181
182 - wfRunHooks( 'AddNewAccount', array( $mUser, true ) );
183 - $mUser->addNewUserLogEntry( true, $this->mReason );
 182+ wfRunHooks( 'AddNewAccount', array( $tempUser, true ) );
 183+ $tempUser->addNewUserLogEntry( true, $this->mReason );
184184
185185 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
186186
187187 if( !$result->isGood() ) {
188188 $this->mainSignupForm( wfMsg( 'mailerror', $result->getWikiText() ) );
189189 } else {
190 - $wgOut->addWikiMsg( 'accmailtext', $mUser->getName(), $mUser->getEmail() );
 190+ $wgOut->addWikiMsg( 'accmailtext', $tempUser->getName(), $tempUser->getEmail() );
191191 $wgOut->returnToMain( false );
192192 }
193193 }
@@ -194,29 +194,29 @@
195195 /**
196196 * @private
197197 */
198 - function addNewAccount($mUser) {
 198+ function addNewAccount($tempUser) {
199199 global $wgUser, $wgEmailAuthentication, $wgOut;
200200
201201 # If we showed up language selection links, and one was in use, be
202202 # smart (and sensible) and save that language as the user's preference
203203 global $wgLoginLanguageSelector;
204204 if( $wgLoginLanguageSelector && $this->mLanguage ) {
205 - $mUser->setOption( 'language', $this->mLanguage );
 205+ $tempUser->setOption( 'language', $this->mLanguage );
206206 }
207207
208208 # Send out an email authentication message if needed
209209 if( $wgEmailAuthentication ) {
210 - $this->mConfirmationMailStatus = $mUser->sendConfirmationMail();
 210+ $this->mConfirmationMailStatus = $tempUser->sendConfirmationMail();
211211 }
212212
213213 # Save settings (including confirmation token)
214 - $mUser->saveSettings();
 214+ $tempUser->saveSettings();
215215
216216 # If not logged in, assume the new account as the current one and set
217217 # session cookies then show a "welcome" message or a "need cookies"
218218 # message as needed
219219 if( $wgUser->isAnon() ) {
220 - $wgUser = $mUser;
 220+ $wgUser = $tempUser;
221221 $wgUser->setCookies();
222222 wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
223223 $wgUser->addNewUserLogEntry();
@@ -228,8 +228,8 @@
229229 }
230230 } else {
231231 $this->mRunCreationConfirmation = true;
232 - wfRunHooks( 'AddNewAccount', array( $mUser, false ) );
233 - $mUser->addNewUserLogEntry( false, $this->mReason );
 232+ wfRunHooks( 'AddNewAccount', array( $tempUser, false ) );
 233+ $tempUser->addNewUserLogEntry( false, $this->mReason );
234234 return true;
235235 }
236236 }
@@ -293,14 +293,14 @@
294294 return self::IP_BLOCKED;
295295 }
296296
297 - # Now create a dummy user ($mUser) and check if it is valid
 297+ # Now create a dummy user ($tempUser) and check if it is valid
298298 $name = trim( $this->mUsername );
299 - $mUser = User::newFromName( $name, 'creatable' );
300 - if ( !is_object( $mUser ) ) {
 299+ $tempUser = User::newFromName( $name, 'creatable' );
 300+ if ( !is_object( $tempUser ) ) {
301301 return self::NO_NAME;
302302 }
303303
304 - if ( 0 != $mUser->idForName() ) {
 304+ if ( 0 != $tempUser->idForName() ) {
305305 return self::USER_EXISTS;
306306 }
307307
@@ -309,7 +309,7 @@
310310 }
311311
312312 # check for minimal password length
313 - $valid = $mUser->getPasswordValidity( $this->mPassword );
 313+ $valid = $tempUser->getPasswordValidity( $this->mPassword );
314314 if ( $valid !== true ) {
315315 if ( !$this->mCreateaccountMail ) {
316316 return self::INVALID_PASS;
@@ -333,11 +333,11 @@
334334
335335 # Set some additional data so the AbortNewAccount hook can be used for
336336 # more than just username validation
337 - $mUser->setEmail( $this->mEmail );
338 - $mUser->setRealName( $this->mRealName );
 337+ $tempUser->setEmail( $this->mEmail );
 338+ $tempUser->setRealName( $this->mRealName );
339339
340340 $abortError = '';
341 - if( !wfRunHooks( 'AbortNewAccount', array( $mUser, &$abortError ) ) ) {
 341+ if( !wfRunHooks( 'AbortNewAccount', array( $tempUser, &$abortError ) ) ) {
342342 // Hook point to add extra creation throttles and blocks
343343 return self::BLOCKED_BY_HOOK;
344344 }
@@ -354,18 +354,18 @@
355355 $wgMemc->incr( $key );
356356 }
357357
358 - if( !$wgAuth->addUser( $mUser, $this->mPassword, $this->mEmail, $this->mRealName ) ) {
 358+ if( !$wgAuth->addUser( $tempUser, $this->mPassword, $this->mEmail, $this->mRealName ) ) {
359359 return self::EXTR_DB_ERROR;
360360 }
361361
362362 self::clearCreateaccountToken();
363363
364 - $mUser = $this->initUser( $mUser, false );
365 - if( $mUser == null ) {
 364+ $tempUser = $this->initUser( $tempUser, false );
 365+ if( $tempUser == null ) {
366366 return self::INIT_FAILED;
367367 }
368368
369 - $this->addNewAccount( $mUser );
 369+ $this->addNewAccount( $tempUser );
370370 return self::SUCCESS;
371371 }
372372
@@ -373,44 +373,44 @@
374374 * Actually add a user to the database.
375375 * Give it a User object that has been initialised with a name.
376376 *
377 - * @param $mUser User object.
 377+ * @param $tempUser User object.
378378 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
379379 * @return User object.
380380 * @private
381381 */
382 - function initUser( $mUser, $autocreate = false ) {
 382+ function initUser( $tempUser, $autocreate = false ) {
383383 global $wgAuth;
384384
385 - $mUser->addToDatabase();
 385+ $tempUser->addToDatabase();
386386
387387 if ( $wgAuth->allowPasswordChange() ) {
388 - $mUser->setPassword( $this->mPassword );
 388+ $tempUser->setPassword( $this->mPassword );
389389 }
390390
391 - $mUser->setEmail( $this->mEmail );
392 - $mUser->setRealName( $this->mRealName );
393 - $mUser->setToken();
 391+ $tempUser->setEmail( $this->mEmail );
 392+ $tempUser->setRealName( $this->mRealName );
 393+ $tempUser->setToken();
394394
395 - $wgAuth->initUser( $mUser, $autocreate );
 395+ $wgAuth->initUser( $tempUser, $autocreate );
396396
397397 if ( $this->mExtUser ) {
398 - $this->mExtUser->linkToLocal( $mUser->getId() );
 398+ $this->mExtUser->linkToLocal( $tempUser->getId() );
399399 $email = $this->mExtUser->getPref( 'emailaddress' );
400400 if ( $email && !$this->mEmail ) {
401 - $mUser->setEmail( $email );
 401+ $tempUser->setEmail( $email );
402402 }
403403 }
404404
405 - $mUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
406 - $mUser->saveSettings();
 405+ $tempUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
 406+ $tempUser->saveSettings();
407407
408408 # Update user count
409409 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
410410 $ssUpdate->doUpdate();
411411
412 - $this->addToSourceTracking( $mUser );
 412+ $this->addToSourceTracking( $tempUser );
413413
414 - return $mUser;
 414+ return $tempUser;
415415 }
416416
417417 function processSignup() {
@@ -434,7 +434,7 @@
435435 if( $this->mRunCreationConfirmation ) {
436436 $self = SpecialPage::getTitleFor( 'Userlogin' );
437437 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
438 - $wgOut->addWikiMsg( 'accountcreatedtext', $mUser->getName() );
 438+ $wgOut->addWikiMsg( 'accountcreatedtext', $tempUser->getName() );
439439 $wgOut->returnToMain( false, $self );
440440 }
441441
@@ -529,33 +529,33 @@
530530 }
531531
532532 /**
533 - * @param $mUser User object
 533+ * @param $tempUser User object
534534 * @param $throttle Boolean
535535 * @param $emailTitle String: message name of email title
536536 * @param $emailText String: message name of email text
537537 * @return Status object
538538 * @private
539539 */
540 - function mailPasswordInternal( $mUser, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
 540+ function mailPasswordInternal( $tempUser, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
541541 global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
542542
543 - if ( $mUser->getEmail() == '' ) {
544 - return Status::newFatal( 'noemail', $mUser->getName() );
 543+ if ( $tempUser->getEmail() == '' ) {
 544+ return Status::newFatal( 'noemail', $tempUser->getName() );
545545 }
546546 $ip = wfGetIP();
547547 if( !$ip ) {
548548 return Status::newFatal( 'badipaddress' );
549549 }
550550
551 - wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$mUser ) );
 551+ wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$tempUser ) );
552552
553 - $np = $mUser->randomPassword();
554 - $mUser->setNewpassword( $np, $throttle );
555 - $mUser->saveSettings();
556 - $mUserserLanguage = $mUser->getOption( 'language' );
557 - $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $mUserserLanguage ), $ip, $mUser->getName(), $np,
 553+ $np = $tempUser->randomPassword();
 554+ $tempUser->setNewpassword( $np, $throttle );
 555+ $tempUser->saveSettings();
 556+ $tempUserserLanguage = $tempUser->getOption( 'language' );
 557+ $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $tempUserserLanguage ), $ip, $tempUser->getName(), $np,
558558 $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) );
559 - $result = $mUser->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $mUserserLanguage ) ), $m );
 559+ $result = $tempUser->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $tempUserserLanguage ) ), $m );
560560
561561 return $result;
562562 }
@@ -730,6 +730,7 @@
731731 $wgAuth->modifyUITemplate( $template, $this->mType );
732732
733733 wfRunHooks( 'UserCreateForm', array( &$template ) );
 734+ wfRunHooks( 'SignupForm' );
734735
735736 // Changes the title depending on permissions for creating account
736737 if ( $wgUser->isAllowed( 'createaccount' ) ) {
@@ -740,20 +741,20 @@
741742
742743 $wgOut->disallowUserJs(); // just in case...
743744 $wgOut->addTemplate( $template );
744 - $wgOut->addModules( 'ext.SignupAPI' );
 745+
745746 }
746747
747748 /**
748749 * @private
749750 *
750 - * @param $mUserser User
 751+ * @param $tempUserser User
751752 *
752753 * @return Boolean
753754 */
754 - function showCreateOrLoginLink( &$mUserser ) {
 755+ function showCreateOrLoginLink( &$tempUserser ) {
755756 if( $this->mType == 'signup' ) {
756757 return true;
757 - } elseif( $mUserser->isAllowed( 'createaccount' ) ) {
 758+ } elseif( $tempUserser->isAllowed( 'createaccount' ) ) {
758759 return true;
759760 } else {
760761 return false;
@@ -905,9 +906,9 @@
906907 }
907908 }
908909
909 - private function addToSourceTracking( $mUser ) {
 910+ private function addToSourceTracking( $tempUser ) {
910911 $sourcetracking_data = array(
911 - 'userid' => $mUser->getId(),
 912+ 'userid' => $tempUser->getId(),
912913 'source_action' => $this->mSourceAction,
913914 'source_ns' => $this->mSourceNS,
914915 'source_article' => $this->msourceArticle

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95185Added resources for AJAX-ifying the signup form...akshay00:34, 22 August 2011

Comments

#Comment by NeilK (talk | contribs)   03:12, 26 August 2011

I have no idea how this can happen, but I'm seeing this when I update:


U extensions/SignupAPI/SignupAPI.i18n.php U extensions/SignupAPI/SignupAPI.php U extensions/SignupAPI/includes/SpecialUserSignup.php svn: Failed to add file 'extensions/SignupAPI/includes/ValidateSignup.php': an unversioned file of the same name already exists neilk@ivy:~/Sites/trunk$ svn up svn: Checksum mismatch while updating 'extensions/SignupAPI/includes/SpecialUserSignup.php'; expected: '7e81ae765db0321240f30bce4f27f228', actual: 'a2fc873195b88e10c1b22376f3e2d9ab' neilk@ivy:~/Sites/trunk$ rm extensions/SignupAPI/includes/ValidateSignup.php neilk@ivy:~/Sites/trunk$ svn up extensions/SignupAPI svn: Checksum mismatch while updating 'extensions/SignupAPI/includes/SpecialUserSignup.php'; expected: '7e81ae765db0321240f30bce4f27f228', actual: 'a2fc873195b88e10c1b22376f3e2d9ab'

Obviously I did not have this file before I svn up'ed. The error message must somehow be confusing a checksum failure with a pre-existing file.

#Comment by NeilK (talk | contribs)   03:13, 26 August 2011

Er, for easier reading:


   U    extensions/SignupAPI/SignupAPI.i18n.php
   U    extensions/SignupAPI/SignupAPI.php
   U    extensions/SignupAPI/includes/SpecialUserSignup.php
   svn: Failed to add file 'extensions/SignupAPI/includes/ValidateSignup.php': an unversioned file of the same name already exists
   neilk@ivy:~/Sites/trunk$ svn up
   svn: Checksum mismatch while updating 'extensions/SignupAPI/includes/SpecialUserSignup.php'; expected: '7e81ae765db0321240f30bce4f27f228', actual: 'a2fc873195b88e10c1b22376f3e2d9ab'
   neilk@ivy:~/Sites/trunk$ rm extensions/SignupAPI/includes/ValidateSignup.php 
   neilk@ivy:~/Sites/trunk$ svn up extensions/SignupAPI
   svn: Checksum mismatch while updating 'extensions/SignupAPI/includes/SpecialUserSignup.php'; expected: '7e81ae765db0321240f30bce4f27f228', actual: 'a2fc873195b88e10c1b22376f3e2d9ab'
#Comment by 😂 (talk | contribs)   03:13, 26 August 2011

Did you try deleting it and doing a fresh checkout?

#Comment by NeilK (talk | contribs)   03:19, 26 August 2011

That worked... thanks

   $ rm -rf extensions/SignupAPI
   $ svn checkout svn+ssh://neilk@svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SignupAPI extensions/SignupAPI
#Comment by Nikerabbit (talk | contribs)   10:51, 21 September 2011
+                wfRunHooks( 'SignupForm' );

No parameters? What can they do?

Status & tagging log