r25627 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25626‎ | r25627 | r25628 >
Date:10:54, 7 September 2007
Author:jvelezv
Status:old
Tags:
Comment:
No change on functionality. Changes to make easier merge.
Modified paths:
  • /branches/ApiEdit_Vodafone/includes/SpecialUserlogin.php (modified) (history)
  • /branches/ApiEdit_Vodafone/includes/api/ApiRegUser.php (modified) (history)

Diff [purge]

Index: branches/ApiEdit_Vodafone/includes/SpecialUserlogin.php
@@ -8,7 +8,7 @@
99 * constructor
1010 */
1111 function wfSpecialUserlogin() {
12 -
 12+
1313 global $wgRequest;
1414 if( session_id() == '' ) {
1515 wfSetupSession();
@@ -24,40 +24,40 @@
2525 */
2626 class LoginForm {
2727
28 - const SUCCESS = 0;
29 - const NO_NAME = 1;
30 - const ILLEGAL = 2;
31 - const WRONG_PLUGIN_PASS = 3;
32 - const NOT_EXISTS = 4;
33 - const WRONG_PASS = 5;
34 - const EMPTY_PASS = 6;
35 - const RESET_PASS = 7;
36 - const ABORTED = 8;
37 - const COOKIE = 9;
38 - const NOCOOKIE = 10;
39 - const READ_ONLY = 11;
40 - const NOT_ALLOWED = 12;
41 - const SORBS = 13;
42 - const USER_EXISTS = 14;
43 - const BAD_RETYPE = 15;
44 - const TOO_SHORT = 16;
45 - const ABORT_ERROR = 17;
46 - const DB_ERROR = 18;
47 - const NO_EMAIL = 19;
48 - const MAIL_ERROR = 20;
49 - const ACCMAILTEXT = 21;
50 - const PASSWORD_SENT = 22;
51 - const PASSWORD_REMINDER_THROTTLED = 23;
52 - const NO_SUCH_USER = 24;
53 - const RATE_LIMITED = 25;
54 - const MAILPASSWORD_BLOCKED = 26;
55 - const RESETPASS_FORBIDDEN = 27;
56 - const NO_COOKIES_NEW = 28;
57 - const NO_COOKIES_LOGIN = 29;
58 - const ERROR = 30;
59 - const SUCCESFUL_LOGIN = 31;
60 -
61 -
 28+ const SUCCESS = 0;
 29+ const NO_NAME = 1;
 30+ const ILLEGAL = 2;
 31+ const WRONG_PLUGIN_PASS = 3;
 32+ const NOT_EXISTS = 4;
 33+ const WRONG_PASS = 5;
 34+ const EMPTY_PASS = 6;
 35+ const RESET_PASS = 7;
 36+ const ABORTED = 8;
 37+ const COOKIE = 9;
 38+ const NOCOOKIE = 10;
 39+ const READ_ONLY = 11;
 40+ const NOT_ALLOWED = 12;
 41+ const SORBS = 13;
 42+ const USER_EXISTS = 14;
 43+ const BAD_RETYPE = 15;
 44+ const TOO_SHORT = 16;
 45+ const ABORT_ERROR = 17;
 46+ const DB_ERROR = 18;
 47+ const NO_EMAIL = 19;
 48+ const MAIL_ERROR = 20;
 49+ const ACCMAILTEXT = 21;
 50+ const PASSWORD_SENT = 22;
 51+ const PASSWORD_REMINDER_THROTTLED = 23;
 52+ const NO_SUCH_USER = 24;
 53+ const RATE_LIMITED = 25;
 54+ const MAILPASSWORD_BLOCKED = 26;
 55+ const RESETPASS_FORBIDDEN = 27;
 56+ const NO_COOKIES_NEW = 28;
 57+ const NO_COOKIES_LOGIN = 29;
 58+ const ERROR = 30;
 59+ const SUCCESFUL_LOGIN = 31;
 60+
 61+
6262 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
6363 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
6464 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
@@ -76,8 +76,8 @@
7777 $this->mRetype = $request->getText( 'wpRetype' );
7878 $this->mDomain = $request->getText( 'wpDomain' );
7979 $this->mReturnTo = $request->getVal( 'returnto' );
80 -
81 - //
 80+
 81+
8282 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
8383 $this->mPosted = $request->wasPosted();
8484 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
@@ -113,21 +113,21 @@
114114 }
115115
116116 function execute() {
117 - $resultDetails = null;
118 - $value = null;
119 -
 117+ $resultDetails = null;
 118+ $value = null;
 119+
120120 if ( !is_null( $this->mCookieCheck ) ) {
121 - $value = $this->onCookieRedirectCheck( $this->mCookieCheck, $resultDetails );
122 - return $this->processRest($value, $resultDetails);
 121+ $value = $this->onCookieRedirectCheck( $this->mCookieCheck, $resultDetails );
 122+ return $this->processRest($value, $resultDetails);
123123 } else if( $this->mPosted ) {
124124 if( $this->mCreateaccount ) {
125 - $value = $this->addNewAccount($resultDetails);
 125+ $value = $this->addNewAccount($resultDetails);
126126 return $this->processRest($value,$resultDetails);
127127 } else if ( $this->mCreateaccountMail ) {
128 - $value = $this->addNewAccountMailPassword($resultDetails);
 128+ $value = $this->addNewAccountMailPassword($resultDetails);
129129 return $this->processRest($value,$resultDetails);
130130 } else if ( $this->mMailmypassword ) {
131 - $value = $this->mailPassword($resultDetails);
 131+ $value = $this->mailPassword($resultDetails);
132132 return $this->processRest($value,$resultDetails);
133133 } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
134134 return $this->processLogin();
@@ -143,7 +143,7 @@
144144 global $wgOut;
145145
146146 if ('' == $this->mEmail) {
147 - return self::NO_EMAIL;
 147+ return self::NO_EMAIL;
148148 }
149149
150150 $u = $this->addNewaccountInternal($results);
@@ -159,15 +159,13 @@
160160
161161 wfRunHooks( 'AddNewAccount', array( $u ) );
162162
163 -
164 - $results['user'] = $u;
 163+ $results['user'] = $u;
165164 if( WikiError::isError( $results['error'] ) ) {
166 - return self::MAIL_ERROR;
 165+ return self::MAIL_ERROR;
167166 } else {
168167 return self::ACCMAILTEXT;
169168 }
170169 }
171 -
172170
173171 /**
174172 * @private
@@ -191,11 +189,11 @@
192190 if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) {
193191 global $wgOut;
194192 $results['error'] = $u->sendConfirmationMail();
195 - $results['mailMsg'] = 0;
 193+ $results['mailMsg'] = 0;
196194 if( WikiError::isError( $results['error'] ) ) {
197 - $results['mailMsg'] = 2;
 195+ $results['mailMsg'] = 2;
198196 } else {
199 - $results['mailMsg'] = 1;
 197+ $results['mailMsg'] = 1;
200198 }
201199 }
202200
@@ -208,11 +206,13 @@
209207 if( $this->hasSessionCookie() ) {
210208 return self::COOKIE;
211209 } else {
212 - return self::NOCOOKIE;
 210+ return self::NOCOOKIE;
213211 }
214212 } else {
215213 # Confirm that the account was created
216 - $results['user'] = $u;
 214+ $results['user'] = $u;
 215+
 216+
217217 wfRunHooks( 'AddNewAccount', array( $u ) );
218218 return self::SUCCESS;
219219 }
@@ -226,11 +226,10 @@
227227 global $wgEnableSorbs, $wgProxyWhitelist;
228228 global $wgMemc, $wgAccountCreationThrottle;
229229 global $wgAuth, $wgMinimalPasswordLength;
230 -
 230+
231231 // If the user passes an invalid domain, something is fishy
232232 if( !$wgAuth->validDomain( $this->mDomain ) ) {
233233 return self::WRONG_PASS;
234 -
235234 }
236235
237236 // If we are not allowing users to login locally, we should
@@ -242,26 +241,23 @@
243242 if( 'local' != $this->mDomain && '' != $this->mDomain ) {
244243 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) {
245244 return self::WRONG_PASS;
246 -
247245 }
248246 }
249247
250248 if ( wfReadOnly() ) {
251249 return self::READ_ONLY;
252 -
253250 }
254251
255252 # Check anonymous user ($wgUser) limitations :
256253 if (!$wgUser->isAllowedToCreateAccount()) {
257254 return self::NOT_ALLOWED;
258 -
259255 }
260256
261257 $ip = wfGetIP();
262258 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
263259 $wgUser->inSorbsBlacklist( $ip ) )
264260 {
265 - $results['ip'] = $ip;
 261+ $results['ip'] = $ip;
266262 return self::SORBS;
267263
268264 }
@@ -447,108 +443,108 @@
448444 function processRest($value,$results = null) {
449445 global $wgUser, $wgAuth, $wgOut;
450446 if ($results['mailMsg'] == 1) {
451 - $wgOut->addWikiText( wfMsg( 'confirmemail_oncreate' ) );
452 - } else if ($results['mailMsg'] == 2) {
453 - $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $results['error']->getMessage() ) );
454 - }
 447+ $wgOut->addWikiText( wfMsg( 'confirmemail_oncreate' ) );
 448+ } else if ($results['mailMsg'] == 2) {
 449+ $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $results['error']->getMessage() ) );
 450+ }
455451 switch ($value)
456452 {
457453 case self::SUCCESS:
458 - $self = SpecialPage::getTitleFor( 'Userlogin' );
459 - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
460 - $wgOut->setArticleRelated( false );
461 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
462 - $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $this->mName ) );
463 - $wgOut->returnToMain( $self->getPrefixedText() );
464 - break;
 454+ $self = SpecialPage::getTitleFor( 'Userlogin' );
 455+ $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
 456+ $wgOut->setArticleRelated( false );
 457+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
 458+ $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $this->mName ) );
 459+ $wgOut->returnToMain( $self->getPrefixedText() );
 460+ break;
465461
466462 case self::COOKIE:
467463 $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false );
468464 break;
469465 case self::NOCOOKIE:
470466 $this->cookieRedirectCheck( 'new' );
471 - break;
472 - case self::WRONG_PASS :
473 - $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
474 - break;
475 - case self::READ_ONLY:
476 - $wgOut->readOnlyPage();
477 - break;
478 - case self::NOT_ALLOWED:
479 - $this->userNotPrivilegedMessage();
480 - break;
481 - case self::SORBS:
482 - $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $results['ip'] ) . ')' );
483 - break;
484 - case self::NO_NAME:
485 - $this->mainLoginForm( wfMsg( 'noname' ) );
486 - break;
487 - case self::USER_EXISTS:
488 - $this->mainLoginForm( wfMsg( 'userexists' ) );
489 - break;
490 - case self::BAD_RETYPE:
491 - $this->mainLoginForm( wfMsg( 'badretype' ) );
492 - break;
493 - case self::TOO_SHORT:
494 - $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
495 - break;
496 - case self::ABORT_ERROR:
497 - $this->mainLoginForm( $results['error'] );
498 - break;
499 - case self::DB_ERROR:
500 - $this->mainLoginForm( wfMsg( 'externaldberror' ) );
501 - break;
502 - case self::NO_EMAIL:
503 - $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) );
504 - break;
505 - case self::MAIL_ERROR:
506 - $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
507 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
508 - $wgOut->setArticleRelated( false );
509 - $this->mainLoginForm( wfMsg( 'mailerror', $results['error']->getMessage() ) );
510 - break;
511 - case self::ACCMAILTEXT:
512 - $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
513 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
514 - $wgOut->setArticleRelated( false );
515 - $wgOut->addWikiText( wfMsg( 'accmailtext', $results['user']->getName(), $results['user']->getEmail() ) );
516 - $wgOut->returnToMain( false );
517 - break;
518 - case self::ILLEGAL:
519 - $this->throttleHit( $wgAccountCreationThrottle );
520 - break;
521 - case self::PASSWORD_SENT:
522 - $this->mainLoginForm( wfMsg( 'passwordsent', $results['user']->getName() ), 'success' );
523 - break;
524 - case self::PASSWORD_REMINDER_THROTTLED:
525 - global $wgPasswordReminderResendTime;
526 - # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
527 - $this->mainLoginForm( wfMsg( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) ) );
528 - break;
529 - case self::NO_SUCH_USER:
530 - $this->mainLoginForm( wfMsg( 'nosuchuser', $results['user']->getName() ) );
531 - break;
532 - case self::RATE_LIMITED:
533 - $wgOut->rateLimited();
534 - break;
535 - case self::MAILPASSWORD_BLOCKED:
536 - $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
537 - break;
538 - case self::RESETPASS_FORBIDDEN:
539 - $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
540 - break;
541 - case self::NO_COOKIES_NEW:
542 - $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
543 - break;
544 - case self::NO_COOKIES_LOGIN:
545 - $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
546 - break;
547 - case self::ERROR:
548 - $this->mainLoginForm( wfMsg( 'error' ) );
549 - break;
550 - case self::LOGIN_SUCCESS:
551 - $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
552 - break;
 467+ break;
 468+ case self::WRONG_PASS :
 469+ $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
 470+ break;
 471+ case self::READ_ONLY:
 472+ $wgOut->readOnlyPage();
 473+ break;
 474+ case self::NOT_ALLOWED:
 475+ $this->userNotPrivilegedMessage();
 476+ break;
 477+ case self::SORBS:
 478+ $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $results['ip'] ) . ')' );
 479+ break;
 480+ case self::NO_NAME:
 481+ $this->mainLoginForm( wfMsg( 'noname' ) );
 482+ break;
 483+ case self::USER_EXISTS:
 484+ $this->mainLoginForm( wfMsg( 'userexists' ) );
 485+ break;
 486+ case self::BAD_RETYPE:
 487+ $this->mainLoginForm( wfMsg( 'badretype' ) );
 488+ break;
 489+ case self::TOO_SHORT:
 490+ $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
 491+ break;
 492+ case self::ABORT_ERROR:
 493+ $this->mainLoginForm( $results['error'] );
 494+ break;
 495+ case self::DB_ERROR:
 496+ $this->mainLoginForm( wfMsg( 'externaldberror' ) );
 497+ break;
 498+ case self::NO_EMAIL:
 499+ $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) );
 500+ break;
 501+ case self::MAIL_ERROR:
 502+ $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
 503+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
 504+ $wgOut->setArticleRelated( false );
 505+ $this->mainLoginForm( wfMsg( 'mailerror', $results['error']->getMessage() ) );
 506+ break;
 507+ case self::ACCMAILTEXT:
 508+ $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
 509+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
 510+ $wgOut->setArticleRelated( false );
 511+ $wgOut->addWikiText( wfMsg( 'accmailtext', $results['user']->getName(), $results['user']->getEmail() ) );
 512+ $wgOut->returnToMain( false );
 513+ break;
 514+ case self::ILLEGAL:
 515+ $this->throttleHit( $wgAccountCreationThrottle );
 516+ break;
 517+ case self::PASSWORD_SENT:
 518+ $this->mainLoginForm( wfMsg( 'passwordsent', $results['user']->getName() ), 'success' );
 519+ break;
 520+ case self::PASSWORD_REMINDER_THROTTLED:
 521+ global $wgPasswordReminderResendTime;
 522+ # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
 523+ $this->mainLoginForm( wfMsg( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) ) );
 524+ break;
 525+ case self::NO_SUCH_USER:
 526+ $this->mainLoginForm( wfMsg( 'nosuchuser', $results['user']->getName() ) );
 527+ break;
 528+ case self::RATE_LIMITED:
 529+ $wgOut->rateLimited();
 530+ break;
 531+ case self::MAILPASSWORD_BLOCKED:
 532+ $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
 533+ break;
 534+ case self::RESETPASS_FORBIDDEN:
 535+ $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
 536+ break;
 537+ case self::NO_COOKIES_NEW:
 538+ $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
 539+ break;
 540+ case self::NO_COOKIES_LOGIN:
 541+ $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
 542+ break;
 543+ case self::ERROR:
 544+ $this->mainLoginForm( wfMsg( 'error' ) );
 545+ break;
 546+ case self::LOGIN_SUCCESS:
 547+ $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
 548+ break;
553549 default:
554550 wfDebugDieBacktrace( "Unhandled case value" );
555551 }
@@ -641,7 +637,7 @@
642638
643639 }
644640 if ( 0 == $u->getID() ) {
645 - $results['user']=$u;
 641+ $results['user']=$u;
646642 return self::NO_SUCH_USER;
647643
648644 }
@@ -652,11 +648,11 @@
653649 }
654650
655651 $results['error'] = $this->mailPasswordInternal( $u, true );
656 - $results['user'] = $u;
 652+ $results['user'] = $u;
657653 if( WikiError::isError( $results['error'] ) ) {
658 - return self::MAIL_ERROR;
 654+ return self::MAIL_ERROR;
659655 } else {
660 - return self::PASSWORD_SENT;
 656+ return self::PASSWORD_SENT;
661657 }
662658 }
663659
@@ -894,15 +890,15 @@
895891
896892 if ( !$this->hasSessionCookie() ) {
897893 if ( $type == 'new' ) {
898 - return self::NO_COOKIES_NEW;
 894+ return self::NO_COOKIES_NEW;
899895 } else if ( $type == 'login' ) {
900 - return self::NO_COOKIES_LOGIN;
 896+ return self::NO_COOKIES_LOGIN;
901897 } else {
902 - # shouldn't happen
903 - return self::ERROR;
 898+ # shouldn't happen
 899+ return self::ERROR;
904900 }
905901 } else {
906 - return self::LOGIN_SUCCESS;
 902+ return self::LOGIN_SUCCESS;
907903 }
908904 }
909905
Index: branches/ApiEdit_Vodafone/includes/api/ApiRegUser.php
@@ -22,157 +22,154 @@
2323 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2424 * http://www.gnu.org/copyleft/gpl.html
2525 */
26 -
27 -if (!defined('MEDIAWIKI')) {
 26+
 27+if (!defined('MEDIAWIKI')) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ("ApiBase.php");
 29+ require_once ("ApiBase.php");
3030 }
31 -
3231
3332 /**
3433 * A module to register new user accounts.
3534 *
3635 * @addtogroup API
3736 */
38 -class ApiRegUser extends ApiBase {
 37+class ApiRegUser extends ApiBase {
3938
40 - const GET_CAPTCHA = -1;
41 - const MISSING_CAPTCHA = -2;
 39+ const GET_CAPTCHA = -1;
 40+ const MISSING_CAPTCHA = -2;
4241
4342 public function __construct($query, $moduleName) {
4443 parent :: __construct($query, $moduleName, 'ru');
4544 }
46 -
4745
48 -
49 - public function process($value,$results = null) {
50 - switch ($value) {
51 - case ApiRegUser::GET_CAPTCHA :
52 - $myCaptcha = new FancyCaptcha();
53 - $myCaptcha->storage->clearAll();
54 - $result['result'] = 'CaptchaIdGenerated';
55 - $myCaptcha->getXML($result);
56 - break;
57 - case ApiRegUser::MISSING_CAPTCHA :
58 - $myCaptcha = new FancyCaptcha();
59 - $myCaptcha->storage->clearAll();
60 - $result['result'] = 'MissingCaptcha';
61 - $myCaptcha->getXML($result);
62 - break;
63 - case LoginForm::SUCCESS :
64 - $result['result'] = 'Success';
65 - break;
66 - case LoginForm::COOKIE :
67 - $result['result'] = 'Logged';
68 - $result['userid'] = $_SESSION['wsUserID'];
69 - $result['username'] = $_SESSION['wsUserName'];
70 - $result['token'] = $_SESSION['wsToken'];
71 - break;
72 - case LoginForm::NOCOOKIE :
73 - $result['result'] = 'NoCookie';
74 - $result['userid'] = $_SESSION['wsUserID'];
75 - $result['username'] = $_SESSION['wsUserName'];
76 - $result['token'] = $_SESSION['wsToken'];
77 - break;
78 - case LoginForm::WRONG_PASS :
79 - $result['result'] = 'WrongPassword';
80 - break;
81 - case LoginForm::READ_ONLY :
82 - $result['result'] = 'ReadOnly';
83 - break;
84 - case LoginForm::NOT_ALLOWED :
85 - $result['result'] = 'NotAllowed';
86 - break;
87 - case LoginForm::SORBS :
88 - $result['result'] = 'Sorbs';
89 - $result['blockedIp'] = $results['ip'];
90 - break;
91 - case LoginForm::NO_NAME :
92 - $result['result'] = 'NoName';
93 - break;
94 - case LoginForm::USER_EXISTS :
95 - $result['result'] = 'UserExists';
96 - break;
97 - case LoginForm::BAD_RETYPE :
98 - $result['result'] = 'BadRetype';
99 - break;
100 - case LoginForm::TOO_SHORT :
101 - $result['result'] = 'TooShort';
102 - break;
103 - case LoginForm::ABORT_ERROR :
104 - $result['result'] = 'AbortError';
105 - break;
106 - case LoginForm::DB_ERROR :
107 - $result['result'] = 'DbError';
108 - break;
109 - case LoginForm::NO_EMAIL :
110 - $result['result'] = 'NoEmail';
111 - break;
112 - case LoginForm::MAIL_ERROR :
113 - $result['result'] = 'MailError';
114 - break;
115 - case LoginForm::ACCMAILTEXT :
116 - $result['result'] = 'AccMailText';
117 - $result['userid'] = $_SESSION['wsUserID'];
118 - $result['username'] = $_SESSION['wsUserName'];
119 - $result['token'] = $_SESSION['wsToken'];
120 - break;
121 - default :
122 - $result['result'] = 'Invalid';
123 -
124 - }
125 - if ($results['mailMsg'] == 1) {
126 - $result['confirmEmail'] = 'MailSent';
127 - } else if ($results['mailMsg'] == 2) {
128 - $result['confirmEmail'] = $results['error']->getMessage();
129 - }
130 - $this->getResult()->addValue(null, 'reguser', $result);
131 - }
132 -
133 - public function checkCaptcha() {
134 - global $wgHooks;
135 - $i = 0;
136 - $value = false;
137 - while ($i < sizeof($wgHooks['UserCreateForm'])) {
138 - if ($wgHooks['UserCreateForm'][$i][0] instanceof FancyCaptcha) $value = true;
139 - $i++;
140 - }
141 - return $value;
142 - }
 46+ public function process($value,$results = null) {
 47+ switch ($value) {
 48+ case ApiRegUser::GET_CAPTCHA :
 49+ $myCaptcha = new FancyCaptcha();
 50+ $myCaptcha->storage->clearAll();
 51+ $result['result'] = 'CaptchaIdGenerated';
 52+ $myCaptcha->getXML($result);
 53+ break;
 54+ case ApiRegUser::MISSING_CAPTCHA :
 55+ $myCaptcha = new FancyCaptcha();
 56+ $myCaptcha->storage->clearAll();
 57+ $result['result'] = 'MissingCaptcha';
 58+ $myCaptcha->getXML($result);
 59+ break;
 60+ case LoginForm::SUCCESS :
 61+ $result['result'] = 'Success';
 62+ break;
 63+ case LoginForm::COOKIE :
 64+ $result['result'] = 'Logged';
 65+ $result['userid'] = $_SESSION['wsUserID'];
 66+ $result['username'] = $_SESSION['wsUserName'];
 67+ $result['token'] = $_SESSION['wsToken'];
 68+ break;
 69+ case LoginForm::NOCOOKIE :
 70+ $result['result'] = 'NoCookie';
 71+ $result['userid'] = $_SESSION['wsUserID'];
 72+ $result['username'] = $_SESSION['wsUserName'];
 73+ $result['token'] = $_SESSION['wsToken'];
 74+ break;
 75+ case LoginForm::WRONG_PASS :
 76+ $result['result'] = 'WrongPassword';
 77+ break;
 78+ case LoginForm::READ_ONLY :
 79+ $result['result'] = 'ReadOnly';
 80+ break;
 81+ case LoginForm::NOT_ALLOWED :
 82+ $result['result'] = 'NotAllowed';
 83+ break;
 84+ case LoginForm::SORBS :
 85+ $result['result'] = 'Sorbs';
 86+ $result['blockedIp'] = $results['ip'];
 87+ break;
 88+ case LoginForm::NO_NAME :
 89+ $result['result'] = 'NoName';
 90+ break;
 91+ case LoginForm::USER_EXISTS :
 92+ $result['result'] = 'UserExists';
 93+ break;
 94+ case LoginForm::BAD_RETYPE :
 95+ $result['result'] = 'BadRetype';
 96+ break;
 97+ case LoginForm::TOO_SHORT :
 98+ $result['result'] = 'TooShort';
 99+ break;
 100+ case LoginForm::ABORT_ERROR :
 101+ $result['result'] = 'AbortError';
 102+ break;
 103+ case LoginForm::DB_ERROR :
 104+ $result['result'] = 'DbError';
 105+ break;
 106+ case LoginForm::NO_EMAIL :
 107+ $result['result'] = 'NoEmail';
 108+ break;
 109+ case LoginForm::MAIL_ERROR :
 110+ $result['result'] = 'MailError';
 111+ break;
 112+ case LoginForm::ACCMAILTEXT :
 113+ $result['result'] = 'AccMailText';
 114+ $result['userid'] = $_SESSION['wsUserID'];
 115+ $result['username'] = $_SESSION['wsUserName'];
 116+ $result['token'] = $_SESSION['wsToken'];
 117+ break;
 118+ default :
 119+ $result['result'] = 'Invalid';
143120
144 - public function execute() {
145 - global $wgRequest;
146 -
147 - $resultDetails = null;
148 - $value = null;
149 - if( session_id() == '' ) {
150 - wfSetupSession();
151 - }
152 -
153 - if ($_SERVER['REQUEST_METHOD'] == 'POST') {
154 - extract($this->extractRequestParams());
155 - if ( (strlen($user) == 0) && (strlen($password) == 0) && ($this->checkCaptcha()) ) {
156 - $value = ApiRegUser::GET_CAPTCHA;
157 - } elseif ($this->checkCaptcha() && ($captchaid == 0)) {
158 - $value = ApiRegUser::MISSING_CAPTCHA;
159 - } else {
160 - $data = array('wpName' => $user,
161 - 'wpPassword' => $password,
162 - 'wpRetype' => $password,
163 - 'wpEmail' => $email,
164 - 'wpRealName' => $name,
165 - 'wpCaptchaWord' => $captchaword,
166 - 'wpCaptchaId' => $captchaid,
167 - 'wpDomain' => $domain);
168 - $request = new FauxRequest($data);
169 - $wgRequest = $request;
170 - $form = new LoginForm( $request );
171 - $value = $form->addNewAccount($resultDetails);
172 - }
173 - }
174 - $this->process($value,$resultDetails);
 121+ }
 122+ if ($results['mailMsg'] == 1) {
 123+ $result['confirmEmail'] = 'MailSent';
 124+ } else if ($results['mailMsg'] == 2) {
 125+ $result['confirmEmail'] = $results['error']->getMessage();
 126+ }
 127+ $this->getResult()->addValue(null, 'reguser', $result);
175128 }
176129
 130+ public function checkCaptcha() {
 131+ global $wgHooks;
 132+ $i = 0;
 133+ $value = false;
 134+ while ($i < sizeof($wgHooks['UserCreateForm'])) {
 135+ if ($wgHooks['UserCreateForm'][$i][0] instanceof FancyCaptcha) $value = true;
 136+ $i++;
 137+ }
 138+ return $value;
 139+ }
 140+
 141+ public function execute() {
 142+ global $wgRequest;
 143+
 144+ $resultDetails = null;
 145+ $value = null;
 146+ if( session_id() == '' ) {
 147+ wfSetupSession();
 148+ }
 149+
 150+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 151+ extract($this->extractRequestParams());
 152+ if ( (strlen($user) == 0) && (strlen($password) == 0) && ($this->checkCaptcha()) ) {
 153+ $value = ApiRegUser::GET_CAPTCHA;
 154+ } elseif ($this->checkCaptcha() && ($captchaid == 0)) {
 155+ $value = ApiRegUser::MISSING_CAPTCHA;
 156+ } else {
 157+ $data = array('wpName' => $user,
 158+ 'wpPassword' => $password,
 159+ 'wpRetype' => $password,
 160+ 'wpEmail' => $email,
 161+ 'wpRealName' => $name,
 162+ 'wpCaptchaWord' => $captchaword,
 163+ 'wpCaptchaId' => $captchaid,
 164+ 'wpDomain' => $domain);
 165+ $request = new FauxRequest($data);
 166+ $wgRequest = $request;
 167+ $form = new LoginForm( $request );
 168+ $value = $form->addNewAccount($resultDetails);
 169+ }
 170+ }
 171+ $this->process($value,$resultDetails);
 172+ }
 173+
177174 protected function getDescription() {
178175 return 'Create new user account';
179176 }
@@ -180,49 +177,49 @@
181178 protected function getExamples() {
182179 return array (
183180 "Create new user account using MediaWiki API",
184 - " You must register using POST method."
 181+ " You must register using POST method."
185182 );
186183 }
187 -
188 - protected function getAllowedParams() {
189 - return array (
190 - 'user' => array(
191 - ApiBase :: PARAM_TYPE => 'string'
192 - ),
193 - 'password' => array(
194 - ApiBase :: PARAM_TYPE => 'string'
195 - ),
196 - 'email' => array(
197 - ApiBase :: PARAM_TYPE => 'string'
198 - ),
199 - 'name' => array(
200 - ApiBase :: PARAM_TYPE => 'string'
201 - ),
202 - 'captchaword' => array(
203 - ApiBase :: PARAM_TYPE => 'string'
204 - ),
205 - 'captchaid' => array(
206 - ApiBase :: PARAM_TYPE => 'string'
207 - ),
208 - 'domain' => array(
209 - ApiBase :: PARAM_TYPE => 'string'
210 - )
211 -
212 - );
213 - }
214 -
215 - protected function getParamDescription() {
216 - return array (
217 - 'user' => 'user login name',
218 - 'password' => 'user password',
219 - 'email' => 'user email',
220 - 'name' => 'user name',
221 - 'domain' => 'domain',
222 - 'captchaid' => 'question',
223 - 'captchaword' => 'answer'
224 - );
225 - }
226184
 185+ protected function getAllowedParams() {
 186+ return array (
 187+ 'user' => array(
 188+ ApiBase :: PARAM_TYPE => 'string'
 189+ ),
 190+ 'password' => array(
 191+ ApiBase :: PARAM_TYPE => 'string'
 192+ ),
 193+ 'email' => array(
 194+ ApiBase :: PARAM_TYPE => 'string'
 195+ ),
 196+ 'name' => array(
 197+ ApiBase :: PARAM_TYPE => 'string'
 198+ ),
 199+ 'captchaword' => array(
 200+ ApiBase :: PARAM_TYPE => 'string'
 201+ ),
 202+ 'captchaid' => array(
 203+ ApiBase :: PARAM_TYPE => 'string'
 204+ ),
 205+ 'domain' => array(
 206+ ApiBase :: PARAM_TYPE => 'string'
 207+ )
 208+
 209+ );
 210+ }
 211+
 212+ protected function getParamDescription() {
 213+ return array (
 214+ 'user' => 'user login name',
 215+ 'password' => 'user password',
 216+ 'email' => 'user email',
 217+ 'name' => 'user name',
 218+ 'domain' => 'domain',
 219+ 'captchaid' => 'question',
 220+ 'captchaword' => 'answer'
 221+ );
 222+ }
 223+
227224 public function getVersion() {
228225 return __CLASS__ . ': $Id: ApiRegUser.php 22289 2007-05-20 23:31:44Z jvelezv $';
229226 }

Status & tagging log