r78227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78226‎ | r78227 | r78228 >
Date:20:07, 11 December 2010
Author:ialex
Status:ok
Tags:
Comment:
* Per Ilmari Karonen, fix for r78224: make it work correctly with API
* Renamed $mName to $mUsername since it was conflicting with a member variable of SpecialPage
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -43,54 +43,54 @@
4444 const NEED_TOKEN = 12;
4545 const WRONG_TOKEN = 13;
4646
47 - var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
 47+ var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
4848 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
4949 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
50 - var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS, $mRequest;
 50+ var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
5151
5252 private $mExtUser = null;
5353
5454 public function __construct( $request = null ) {
 55+ parent::__construct( 'Userlogin' );
 56+
5557 if ( $request === null ) {
5658 global $wgRequest;
57 - $this->mRequest = $wgRequest;
 59+ $this->load( $wgRequest );
5860 } else {
59 - $this->mRequest = $request;
 61+ $this->load( $request );
6062 }
61 -
62 - parent::__construct( 'Userlogin' );
6363 }
6464
6565 /**
6666 * Loader
6767 *
68 - * @param $par String: subpage parameter
 68+ * @param $request WebRequest object
6969 */
70 - function load( $par ) {
 70+ function load( $request ) {
7171 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
7272
73 - $this->mType = ( $par == 'signup' ) ? $par : $this->mRequest->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
74 - $this->mName = $this->mRequest->getText( 'wpName' );
75 - $this->mPassword = $this->mRequest->getText( 'wpPassword' );
76 - $this->mRetype = $this->mRequest->getText( 'wpRetype' );
77 - $this->mDomain = $this->mRequest->getText( 'wpDomain' );
78 - $this->mReason = $this->mRequest->getText( 'wpReason' );
79 - $this->mReturnTo = $this->mRequest->getVal( 'returnto' );
80 - $this->mReturnToQuery = $this->mRequest->getVal( 'returntoquery' );
81 - $this->mCookieCheck = $this->mRequest->getVal( 'wpCookieCheck' );
82 - $this->mPosted = $this->mRequest->wasPosted();
83 - $this->mCreateaccount = $this->mRequest->getCheck( 'wpCreateaccount' );
84 - $this->mCreateaccountMail = $this->mRequest->getCheck( 'wpCreateaccountMail' )
 73+ $this->mType = $request->getText( 'type' );
 74+ $this->mUsername = $request->getText( 'wpName' );
 75+ $this->mPassword = $request->getText( 'wpPassword' );
 76+ $this->mRetype = $request->getText( 'wpRetype' );
 77+ $this->mDomain = $request->getText( 'wpDomain' );
 78+ $this->mReason = $request->getText( 'wpReason' );
 79+ $this->mReturnTo = $request->getVal( 'returnto' );
 80+ $this->mReturnToQuery = $request->getVal( 'returntoquery' );
 81+ $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
 82+ $this->mPosted = $request->wasPosted();
 83+ $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
 84+ $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
8585 && $wgEnableEmail;
86 - $this->mMailmypassword = $this->mRequest->getCheck( 'wpMailmypassword' )
 86+ $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' )
8787 && $wgEnableEmail;
88 - $this->mLoginattempt = $this->mRequest->getCheck( 'wpLoginattempt' );
89 - $this->mAction = $this->mRequest->getVal( 'action' );
90 - $this->mRemember = $this->mRequest->getCheck( 'wpRemember' );
91 - $this->mStickHTTPS = $this->mRequest->getCheck( 'wpStickHTTPS' );
92 - $this->mLanguage = $this->mRequest->getText( 'uselang' );
93 - $this->mSkipCookieCheck = $this->mRequest->getCheck( 'wpSkipCookieCheck' );
94 - $this->mToken = ( $this->mType == 'signup' ) ? $this->mRequest->getVal( 'wpCreateaccountToken' ) : $this->mRequest->getVal( 'wpLoginToken' );
 88+ $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
 89+ $this->mAction = $request->getVal( 'action' );
 90+ $this->mRemember = $request->getCheck( 'wpRemember' );
 91+ $this->mStickHTTPS = $request->getCheck( 'wpStickHTTPS' );
 92+ $this->mLanguage = $request->getText( 'uselang' );
 93+ $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
 94+ $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
9595
9696 if ( $wgRedirectOnLogin ) {
9797 $this->mReturnTo = $wgRedirectOnLogin;
@@ -98,12 +98,12 @@
9999 }
100100
101101 if( $wgEnableEmail ) {
102 - $this->mEmail = $this->mRequest->getText( 'wpEmail' );
 102+ $this->mEmail = $request->getText( 'wpEmail' );
103103 } else {
104104 $this->mEmail = '';
105105 }
106106 if( !in_array( 'realname', $wgHiddenPrefs ) ) {
107 - $this->mRealName = $this->mRequest->getText( 'wpRealName' );
 107+ $this->mRealName = $request->getText( 'wpRealName' );
108108 } else {
109109 $this->mRealName = '';
110110 }
@@ -126,7 +126,9 @@
127127 wfSetupSession();
128128 }
129129
130 - $this->load( $par );
 130+ if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]]
 131+ $this->mType = 'signup';
 132+ }
131133
132134 if ( !is_null( $this->mCookieCheck ) ) {
133135 $this->onCookieRedirectCheck( $this->mCookieCheck );
@@ -152,7 +154,7 @@
153155 global $wgOut;
154156
155157 if ( $this->mEmail == '' ) {
156 - $this->mainLoginForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mName ) );
 158+ $this->mainLoginForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mUsername ) );
157159 return;
158160 }
159161
@@ -258,7 +260,7 @@
259261 // create a local account and login as any domain user). We only need
260262 // to check this for domains that aren't local.
261263 if( 'local' != $this->mDomain && $this->mDomain != '' ) {
262 - if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) {
 264+ if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername ) || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) {
263265 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
264266 return false;
265267 }
@@ -304,7 +306,7 @@
305307 }
306308
307309 # Now create a dummy user ($u) and check if it is valid
308 - $name = trim( $this->mName );
 310+ $name = trim( $this->mUsername );
309311 $u = User::newFromName( $name, 'creatable' );
310312 if ( !is_object( $u ) ) {
311313 $this->mainLoginForm( wfMsg( 'noname' ) );
@@ -433,7 +435,7 @@
434436 public function authenticateUserData() {
435437 global $wgUser, $wgAuth, $wgMemc;
436438
437 - if ( $this->mName == '' ) {
 439+ if ( $this->mUsername == '' ) {
438440 return self::NO_NAME;
439441 }
440442
@@ -456,7 +458,7 @@
457459
458460 $throttleCount = 0;
459461 if ( is_array( $wgPasswordAttemptThrottle ) ) {
460 - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
 462+ $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) );
461463 $count = $wgPasswordAttemptThrottle['count'];
462464 $period = $wgPasswordAttemptThrottle['seconds'];
463465
@@ -481,16 +483,16 @@
482484 // creates the user in the database. Until we load $wgUser, checking
483485 // for user existence using User::newFromName($name)->getId() below
484486 // will effectively be using stale data.
485 - if ( $wgUser->getName() === $this->mName ) {
486 - wfDebug( __METHOD__ . ": already logged in as {$this->mName}\n" );
 487+ if ( $wgUser->getName() === $this->mUsername ) {
 488+ wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" );
487489 return self::SUCCESS;
488490 }
489491
490 - $this->mExtUser = ExternalUser::newFromName( $this->mName );
 492+ $this->mExtUser = ExternalUser::newFromName( $this->mUsername );
491493
492494 # TODO: Allow some magic here for invalid external names, e.g., let the
493495 # user choose a different wiki name.
494 - $u = User::newFromName( $this->mName );
 496+ $u = User::newFromName( $this->mUsername );
495497 if( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) {
496498 return self::ILLEGAL;
497499 }
@@ -639,7 +641,7 @@
640642 self::clearLoginToken();
641643
642644 // Reset the throttle
643 - $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
 645+ $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) );
644646 global $wgMemc;
645647 $wgMemc->delete( $key );
646648
@@ -671,9 +673,9 @@
672674 break;
673675 case self::NOT_EXISTS:
674676 if( $wgUser->isAllowed( 'createaccount' ) ) {
675 - $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
 677+ $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mUsername ) ) );
676678 } else {
677 - $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName ) ) );
 679+ $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mUsername ) ) );
678680 }
679681 break;
680682 case self::WRONG_PASS:
@@ -693,7 +695,7 @@
694696 break;
695697 case self::USER_BLOCKED:
696698 $this->mainLoginForm( wfMsgExt( 'login-userblocked',
697 - array( 'parsemag', 'escape' ), $this->mName ) );
 699+ array( 'parsemag', 'escape' ), $this->mUsername ) );
698700 break;
699701 default:
700702 throw new MWException( 'Unhandled case value' );
@@ -732,7 +734,7 @@
733735
734736 # Check for hooks
735737 $error = null;
736 - if ( !wfRunHooks( 'UserLoginMailPassword', array( $this->mName, &$error ) ) ) {
 738+ if ( !wfRunHooks( 'UserLoginMailPassword', array( $this->mUsername, &$error ) ) ) {
737739 $this->mainLoginForm( $error );
738740 return;
739741 }
@@ -756,11 +758,11 @@
757759 return;
758760 }
759761
760 - if ( $this->mName == '' ) {
 762+ if ( $this->mUsername == '' ) {
761763 $this->mainLoginForm( wfMsg( 'noname' ) );
762764 return;
763765 }
764 - $u = User::newFromName( $this->mName );
 766+ $u = User::newFromName( $this->mUsername );
765767 if( !$u instanceof User ) {
766768 $this->mainLoginForm( wfMsg( 'noname' ) );
767769 return;
@@ -946,11 +948,11 @@
947949 }
948950 }
949951
950 - if ( $this->mName == '' ) {
 952+ if ( $this->mUsername == '' ) {
951953 if ( $wgUser->isLoggedIn() ) {
952 - $this->mName = $wgUser->getName();
 954+ $this->mUsername = $wgUser->getName();
953955 } else {
954 - $this->mName = $wgRequest->getCookie( 'UserName' );
 956+ $this->mUsername = $wgRequest->getCookie( 'UserName' );
955957 }
956958 }
957959
@@ -997,7 +999,7 @@
9981000 }
9991001
10001002 $template->set( 'header', '' );
1001 - $template->set( 'name', $this->mName );
 1003+ $template->set( 'name', $this->mUsername );
10021004 $template->set( 'password', $this->mPassword );
10031005 $template->set( 'retype', $this->mRetype );
10041006 $template->set( 'email', $this->mEmail );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78224* Converted Special:Userlogin to subclass SpecialPage...ialex17:44, 11 December 2010

Status & tagging log