Index: trunk/extensions/SignupAPI/includes/APISignup.php |
— | — | @@ -11,11 +11,11 @@ |
12 | 12 | * @ingroup API |
13 | 13 | */ |
14 | 14 | class ApiSignup extends ApiBase { |
15 | | - |
| 15 | + |
16 | 16 | public function __construct( $main, $action ) { |
17 | 17 | parent::__construct( $main, $action); |
18 | 18 | } |
19 | | - |
| 19 | + |
20 | 20 | public function execute() { |
21 | 21 | $params = $this->extractRequestParams(); |
22 | 22 | |
— | — | @@ -29,31 +29,31 @@ |
30 | 30 | 'wpDomain' => $params['domain'], |
31 | 31 | 'wpRemember' => '' |
32 | 32 | ) ); |
33 | | - |
| 33 | + |
34 | 34 | // Init session if necessary |
35 | 35 | if ( session_id() == '' ) { |
36 | 36 | wfSetupSession(); |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | $signupForm = new SignupForm( $req ); |
40 | | - |
41 | | - global $wgCookiePrefix, $wgUser, $wgAccountCreationThrottle; |
42 | | - |
| 40 | + |
| 41 | + global $wgCookiePrefix, $wgUser; |
| 42 | + |
43 | 43 | $signupRes = $signupForm->addNewAccountInternal(); |
44 | 44 | switch( $signupRes ) { |
45 | 45 | case SignupForm::SUCCESS: |
46 | 46 | $signupForm->initUser(); |
47 | | - |
| 47 | + |
48 | 48 | wfRunHooks( 'AddNewAccount', array( $wgUser, false ) ); |
49 | 49 | # Run any hooks; display injected HTML |
50 | 50 | $injected_html = ''; |
51 | 51 | $welcome_creation_msg = 'welcomecreation'; |
52 | | - |
| 52 | + |
53 | 53 | wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); |
54 | | - |
| 54 | + |
55 | 55 | //let any extensions change what message is shown |
56 | 56 | wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); |
57 | | - |
| 57 | + |
58 | 58 | $result['result'] = 'Success'; |
59 | 59 | $result['lguserid'] = intval( $wgUser->getId() ); |
60 | 60 | $result['lgusername'] = $wgUser->getName(); |
— | — | @@ -61,94 +61,94 @@ |
62 | 62 | $result['cookieprefix'] = $wgCookiePrefix; |
63 | 63 | $result['sessionid'] = session_id(); |
64 | 64 | break; |
65 | | - |
| 65 | + |
66 | 66 | case SignupForm::INVALID_DOMAIN: |
67 | 67 | $result['result'] = 'WrongPassword'; |
68 | 68 | $result['domain']= $signupForm->mDomain; |
69 | 69 | break; |
70 | | - |
| 70 | + |
71 | 71 | case SignupForm::READ_ONLY_PAGE: |
72 | 72 | $result['result'] = 'ReadOnlyPage'; |
73 | 73 | break; |
74 | | - |
| 74 | + |
75 | 75 | case SignupForm::NO_COOKIES: |
76 | 76 | $result['result'] = 'NoCookies'; |
77 | 77 | break; |
78 | | - |
| 78 | + |
79 | 79 | case SignupForm::NEED_TOKEN: |
80 | 80 | $result['result'] = 'NeedToken'; |
81 | 81 | $result['token'] = $signupForm->getCreateaccountToken(); |
82 | 82 | $result['cookieprefix'] = $wgCookiePrefix; |
83 | 83 | $result['sessionid'] = session_id(); |
84 | 84 | break; |
85 | | - |
| 85 | + |
86 | 86 | case SignupForm::WRONG_TOKEN: |
87 | 87 | $result['result'] = 'WrongToken'; |
88 | 88 | break; |
89 | | - |
| 89 | + |
90 | 90 | case SignupForm::INSUFFICIENT_PERMISSION: |
91 | 91 | $result['result'] = 'InsufficientPermission'; |
92 | 92 | break; |
93 | | - |
| 93 | + |
94 | 94 | case SignupForm::CREATE_BLOCKED: |
95 | 95 | $result['result'] = 'CreateBlocked'; |
96 | 96 | break; |
97 | | - |
| 97 | + |
98 | 98 | case SignupForm::IP_BLOCKED: |
99 | 99 | $result['result'] = 'IPBlocked'; |
100 | 100 | break; |
101 | | - |
| 101 | + |
102 | 102 | case SignupForm::NO_NAME: |
103 | 103 | $result['result'] = 'NoName'; |
104 | 104 | break; |
105 | | - |
| 105 | + |
106 | 106 | case SignupForm::USER_EXISTS: |
107 | 107 | $result['result'] = 'UserExists'; |
108 | 108 | break; |
109 | | - |
| 109 | + |
110 | 110 | case SignupForm::WRONG_RETYPE: |
111 | 111 | $result['result'] = 'WrongRetype'; |
112 | 112 | break; |
113 | | - |
| 113 | + |
114 | 114 | case SignupForm::INVALID_PASS: |
115 | 115 | $result['result'] = 'InvalidPass'; |
116 | 116 | break; |
117 | | - |
| 117 | + |
118 | 118 | case SignupForm::NO_EMAIL: |
119 | 119 | $result['result'] = 'NoEmail'; |
120 | 120 | break; |
121 | | - |
| 121 | + |
122 | 122 | case SignupForm::INVALID_EMAIL: |
123 | 123 | $result['result'] = 'InvalidEmail'; |
124 | 124 | break; |
125 | | - |
| 125 | + |
126 | 126 | case SignupForm::BLOCKED_BY_HOOK: |
127 | 127 | $result['result'] = 'BlockedByHook'; |
128 | 128 | break; |
129 | | - |
| 129 | + |
130 | 130 | case SignupForm::EXTR_DB_ERROR: |
131 | 131 | $result['result'] = 'ExternalDBError'; |
132 | 132 | break; |
133 | | - |
| 133 | + |
134 | 134 | case SignupForm::THROTLLED: |
135 | 135 | $result['result'] = 'Throttled'; |
136 | 136 | break; |
137 | | - |
| 137 | + |
138 | 138 | default: |
139 | 139 | ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$signupRes}" ); |
140 | 140 | } |
141 | | - |
142 | | - $this->getResult()->addValue( null, 'signup', $result ); |
| 141 | + |
| 142 | + $this->getResult()->addValue( null, 'signup', $result ); |
143 | 143 | } |
144 | | - |
| 144 | + |
145 | 145 | public function mustBePosted() { |
146 | 146 | return true; |
147 | 147 | } |
148 | | - |
| 148 | + |
149 | 149 | public function isReadMode() { |
150 | 150 | return false; |
151 | 151 | } |
152 | | - |
| 152 | + |
153 | 153 | public function getAllowedParams() { |
154 | 154 | return array( |
155 | 155 | 'name' => null, |
— | — | @@ -168,9 +168,9 @@ |
169 | 169 | 'domain' => 'Domain (optional)', |
170 | 170 | ); |
171 | 171 | } |
172 | | - |
173 | | - |
174 | 172 | |
| 173 | + |
| 174 | + |
175 | 175 | public function getDescription() { |
176 | 176 | return array( |
177 | 177 | 'This module validates the parameters posted by the signup form.', |
— | — | @@ -215,7 +215,6 @@ |
216 | 216 | public function getVersion() { |
217 | 217 | return __CLASS__ . ': $Id$'; |
218 | 218 | } |
219 | | - |
| 219 | + |
220 | 220 | } |
221 | | - |
222 | | - |
\ No newline at end of file |
| 221 | + |
Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | class SignupForm extends SpecialPage { |
31 | 31 | |
32 | 32 | const SUCCESS = 0; |
33 | | - const NO_NAME = 1; |
| 33 | + const NO_NAME = 1; |
34 | 34 | const CREATE_BLOCKED = 2; |
35 | 35 | const NEED_TOKEN = 3; |
36 | 36 | const WRONG_TOKEN = 4; |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | * @param $request WebRequest object |
84 | 84 | */ |
85 | 85 | function load( $request ) { |
86 | | - global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin; |
| 86 | + global $wgAuth, $wgHiddenPrefs, $wgEnableEmail; |
87 | 87 | |
88 | 88 | $this->mType = $request->getText( 'type' ); |
89 | 89 | $this->mUsername = $request->getText( 'wpName' ); |
— | — | @@ -102,9 +102,9 @@ |
103 | 103 | $this->mStickHTTPS = $request->getCheck( 'wpStickHTTPS' ); |
104 | 104 | $this->mLanguage = $request->getText( 'uselang' ); |
105 | 105 | $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' ); |
106 | | - |
| 106 | + |
107 | 107 | //Decide whether login or signup request |
108 | | - |
| 108 | + |
109 | 109 | $this->mToken = $request->getVal( 'wpCreateaccountToken' ); |
110 | 110 | |
111 | 111 | if( $wgEnableEmail ) { |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | } else { |
114 | 114 | $this->mEmail = ''; |
115 | 115 | } |
116 | | - |
| 116 | + |
117 | 117 | if( !in_array( 'realname', $wgHiddenPrefs ) ) { |
118 | 118 | $this->mRealName = $request->getText( 'wpRealName' ); |
119 | 119 | } else { |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | return $this->processSignup(); |
144 | 144 | } elseif ( $this->mCreateaccountMail ) { |
145 | 145 | return $this->addNewAccountMailPassword(); |
146 | | - } |
| 146 | + } |
147 | 147 | } |
148 | 148 | $this->mainSignupForm( '' ); |
149 | 149 | } |
— | — | @@ -262,13 +262,13 @@ |
263 | 263 | // to check this for domains that aren't local. |
264 | 264 | if( 'local' != $this->mDomain && $this->mDomain != '' ) { |
265 | 265 | if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername ) |
266 | | - || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) { |
| 266 | + || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) { |
267 | 267 | return self::INVALID_DOMAIN; |
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | 271 | if ( wfReadOnly() ) { |
272 | | - |
| 272 | + |
273 | 273 | return self::READ_ONLY_PAGE; |
274 | 274 | } |
275 | 275 | |
— | — | @@ -284,7 +284,7 @@ |
285 | 285 | } |
286 | 286 | |
287 | 287 | # Validate the createaccount token |
288 | | - if ( $this->mToken !== self::getCreateaccountToken() ) { |
| 288 | + if ( $this->mToken !== self::getCreateaccountToken() ) { |
289 | 289 | return self::WRONG_TOKEN; |
290 | 290 | } |
291 | 291 | |
— | — | @@ -332,9 +332,9 @@ |
333 | 333 | if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) { |
334 | 334 | return self::NO_EMAIL; |
335 | 335 | } |
336 | | - |
| 336 | + |
337 | 337 | # if email is provided then validate it |
338 | | - if( !empty( $this->mEmail ) && !User::isValidEmailAddr( $this->mEmail ) ) { |
| 338 | + if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) { |
339 | 339 | return self::INVALID_EMAIL; |
340 | 340 | } |
341 | 341 | |
— | — | @@ -413,15 +413,14 @@ |
414 | 414 | return $mUser; |
415 | 415 | } |
416 | 416 | |
417 | | - |
418 | 417 | function processSignup() { |
419 | 418 | global $wgUser, $wgOut; |
420 | | - |
| 419 | + |
421 | 420 | switch ( $this->addNewAccountInternal() ) { |
422 | 421 | case self::SUCCESS: |
423 | 422 | //$this->initUser( $mUser, false ); |
424 | 423 | //$this->addNewAccount($mUser); |
425 | | - break; |
| 424 | + break; |
426 | 425 | case self::INVALID_DOMAIN: |
427 | 426 | $this->mainSignupForm( wfMsg( 'wrongpassword' ) ); |
428 | 427 | break; |
— | — | @@ -488,8 +487,6 @@ |
489 | 488 | } |
490 | 489 | } |
491 | 490 | |
492 | | - |
493 | | - |
494 | 491 | /** |
495 | 492 | * @param $mUser User object |
496 | 493 | * @param $throttle Boolean |
— | — | @@ -522,8 +519,6 @@ |
523 | 520 | return $result; |
524 | 521 | } |
525 | 522 | |
526 | | - |
527 | | - |
528 | 523 | /** |
529 | 524 | * Run any hooks registered for logins, then display a message welcoming |
530 | 525 | * the user. |
— | — | @@ -535,12 +530,12 @@ |
536 | 531 | # Run any hooks; display injected HTML |
537 | 532 | $injected_html = ''; |
538 | 533 | $welcome_creation_msg = 'welcomecreation'; |
539 | | - |
| 534 | + |
540 | 535 | wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); |
541 | | - |
| 536 | + |
542 | 537 | //let any extensions change what message is shown |
543 | 538 | wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); |
544 | | - |
| 539 | + |
545 | 540 | $this->displaySuccessfulCreation( $welcome_creation_msg, $injected_html ); |
546 | 541 | } |
547 | 542 | |
— | — | @@ -575,7 +570,7 @@ |
576 | 571 | $block_reason, |
577 | 572 | $block->getBlocker()->getName() |
578 | 573 | ); |
579 | | - |
| 574 | + |
580 | 575 | $wgOut->returnToMain( false ); |
581 | 576 | } |
582 | 577 | |
— | — | @@ -585,28 +580,27 @@ |
586 | 581 | function mainSignupForm( $msg, $msgtype = 'error' ) { |
587 | 582 | global $wgUser, $wgOut, $wgHiddenPrefs; |
588 | 583 | global $wgEnableEmail, $wgEnableUserEmail; |
589 | | - global $wgRequest, $wgLoginLanguageSelector; |
| 584 | + global $wgLoginLanguageSelector; |
590 | 585 | global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration; |
591 | 586 | global $wgSecureLogin, $wgPasswordResetRoutes; |
592 | 587 | |
593 | 588 | $titleObj = SpecialPage::getTitleFor( 'Usersignup' ); |
594 | 589 | |
595 | | - |
596 | | - // Block signup here if in readonly. Keeps user from |
597 | | - // going through the process (filling out data, etc) |
598 | | - // and being informed later. |
599 | | - if ( wfReadOnly() ) { |
600 | | - $wgOut->readOnlyPage(); |
601 | | - return; |
602 | | - } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
603 | | - $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
604 | | - return; |
605 | | - } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { |
606 | | - $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); |
607 | | - return; |
608 | | - } |
609 | | - |
| 590 | + // Block signup here if in readonly. Keeps user from |
| 591 | + // going through the process (filling out data, etc) |
| 592 | + // and being informed later. |
| 593 | + if ( wfReadOnly() ) { |
| 594 | + $wgOut->readOnlyPage(); |
| 595 | + return; |
| 596 | + } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
| 597 | + $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
| 598 | + return; |
| 599 | + } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { |
| 600 | + $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); |
| 601 | + return; |
| 602 | + } |
610 | 603 | |
| 604 | + |
611 | 605 | if ( $this->mUsername == '' ) { |
612 | 606 | if ( $wgUser->isLoggedIn() ) { |
613 | 607 | $this->mUsername = $wgUser->getName(); |
— | — | @@ -615,13 +609,11 @@ |
616 | 610 | } |
617 | 611 | } |
618 | 612 | |
619 | | - |
620 | 613 | $template = new UsercreateTemplate(); |
621 | 614 | $q = 'action=submitlogin&type=signup'; |
622 | 615 | $linkq = 'type=login'; |
623 | 616 | $linkmsg = 'gotaccount'; |
624 | | - |
625 | | - |
| 617 | + |
626 | 618 | if ( !empty( $this->mReturnTo ) ) { |
627 | 619 | $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo ); |
628 | 620 | if ( !empty( $this->mReturnToQuery ) ) { |
— | — | @@ -677,13 +669,11 @@ |
678 | 670 | $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) ); |
679 | 671 | $template->set( 'stickHTTPS', $this->mStickHTTPS ); |
680 | 672 | |
681 | | - |
682 | 673 | if ( !self::getCreateaccountToken() ) { |
683 | 674 | self::setCreateaccountToken(); |
684 | 675 | } |
685 | 676 | $template->set( 'token', self::getCreateaccountToken() ); |
686 | | - |
687 | | - |
| 677 | + |
688 | 678 | # Prepare language selection links as needed |
689 | 679 | if( $wgLoginLanguageSelector ) { |
690 | 680 | $template->set( 'languages', $this->makeLanguageSelector() ); |
— | — | @@ -693,9 +683,8 @@ |
694 | 684 | |
695 | 685 | // Give authentication and captcha plugins a chance to modify the form |
696 | 686 | $wgAuth->modifyUITemplate( $template, $this->mType ); |
697 | | - |
| 687 | + |
698 | 688 | wfRunHooks( 'UserCreateForm', array( &$template ) ); |
699 | | - |
700 | 689 | |
701 | 690 | // Changes the title depending on permissions for creating account |
702 | 691 | if ( $wgUser->isAllowed( 'createaccount' ) ) { |
— | — | @@ -803,7 +792,7 @@ |
804 | 793 | * |
805 | 794 | * @return string |
806 | 795 | */ |
807 | | - |
| 796 | + |
808 | 797 | function makeLanguageSelector() { |
809 | 798 | global $wgLang; |
810 | 799 | |
— | — | @@ -849,7 +838,7 @@ |
850 | 839 | $attr |
851 | 840 | ); |
852 | 841 | } |
853 | | - |
| 842 | + |
854 | 843 | /** |
855 | 844 | * Display a "login successful" page. |
856 | 845 | */ |
— | — | @@ -860,7 +849,7 @@ |
861 | 850 | if( $msgname ){ |
862 | 851 | $wgOut->addWikiMsg( $msgname, $wgUser->getName() ); |
863 | 852 | } |
864 | | - |
| 853 | + |
865 | 854 | $wgOut->addHTML( $injected_html ); |
866 | 855 | |
867 | 856 | if ( !empty( $this->mReturnTo ) ) { |