r90788 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90787‎ | r90788 | r90789 >
Date:19:29, 25 June 2011
Author:reedy
Status:deferred
Tags:
Comment:
Fixup whitespace, remove unused globals
Modified paths:
  • /trunk/extensions/SignupAPI/includes/APISignup.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/SpecialUserSignup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/includes/APISignup.php
@@ -11,11 +11,11 @@
1212 * @ingroup API
1313 */
1414 class ApiSignup extends ApiBase {
15 -
 15+
1616 public function __construct( $main, $action ) {
1717 parent::__construct( $main, $action);
1818 }
19 -
 19+
2020 public function execute() {
2121 $params = $this->extractRequestParams();
2222
@@ -29,31 +29,31 @@
3030 'wpDomain' => $params['domain'],
3131 'wpRemember' => ''
3232 ) );
33 -
 33+
3434 // Init session if necessary
3535 if ( session_id() == '' ) {
3636 wfSetupSession();
3737 }
38 -
 38+
3939 $signupForm = new SignupForm( $req );
40 -
41 - global $wgCookiePrefix, $wgUser, $wgAccountCreationThrottle;
42 -
 40+
 41+ global $wgCookiePrefix, $wgUser;
 42+
4343 $signupRes = $signupForm->addNewAccountInternal();
4444 switch( $signupRes ) {
4545 case SignupForm::SUCCESS:
4646 $signupForm->initUser();
47 -
 47+
4848 wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
4949 # Run any hooks; display injected HTML
5050 $injected_html = '';
5151 $welcome_creation_msg = 'welcomecreation';
52 -
 52+
5353 wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
54 -
 54+
5555 //let any extensions change what message is shown
5656 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
57 -
 57+
5858 $result['result'] = 'Success';
5959 $result['lguserid'] = intval( $wgUser->getId() );
6060 $result['lgusername'] = $wgUser->getName();
@@ -61,94 +61,94 @@
6262 $result['cookieprefix'] = $wgCookiePrefix;
6363 $result['sessionid'] = session_id();
6464 break;
65 -
 65+
6666 case SignupForm::INVALID_DOMAIN:
6767 $result['result'] = 'WrongPassword';
6868 $result['domain']= $signupForm->mDomain;
6969 break;
70 -
 70+
7171 case SignupForm::READ_ONLY_PAGE:
7272 $result['result'] = 'ReadOnlyPage';
7373 break;
74 -
 74+
7575 case SignupForm::NO_COOKIES:
7676 $result['result'] = 'NoCookies';
7777 break;
78 -
 78+
7979 case SignupForm::NEED_TOKEN:
8080 $result['result'] = 'NeedToken';
8181 $result['token'] = $signupForm->getCreateaccountToken();
8282 $result['cookieprefix'] = $wgCookiePrefix;
8383 $result['sessionid'] = session_id();
8484 break;
85 -
 85+
8686 case SignupForm::WRONG_TOKEN:
8787 $result['result'] = 'WrongToken';
8888 break;
89 -
 89+
9090 case SignupForm::INSUFFICIENT_PERMISSION:
9191 $result['result'] = 'InsufficientPermission';
9292 break;
93 -
 93+
9494 case SignupForm::CREATE_BLOCKED:
9595 $result['result'] = 'CreateBlocked';
9696 break;
97 -
 97+
9898 case SignupForm::IP_BLOCKED:
9999 $result['result'] = 'IPBlocked';
100100 break;
101 -
 101+
102102 case SignupForm::NO_NAME:
103103 $result['result'] = 'NoName';
104104 break;
105 -
 105+
106106 case SignupForm::USER_EXISTS:
107107 $result['result'] = 'UserExists';
108108 break;
109 -
 109+
110110 case SignupForm::WRONG_RETYPE:
111111 $result['result'] = 'WrongRetype';
112112 break;
113 -
 113+
114114 case SignupForm::INVALID_PASS:
115115 $result['result'] = 'InvalidPass';
116116 break;
117 -
 117+
118118 case SignupForm::NO_EMAIL:
119119 $result['result'] = 'NoEmail';
120120 break;
121 -
 121+
122122 case SignupForm::INVALID_EMAIL:
123123 $result['result'] = 'InvalidEmail';
124124 break;
125 -
 125+
126126 case SignupForm::BLOCKED_BY_HOOK:
127127 $result['result'] = 'BlockedByHook';
128128 break;
129 -
 129+
130130 case SignupForm::EXTR_DB_ERROR:
131131 $result['result'] = 'ExternalDBError';
132132 break;
133 -
 133+
134134 case SignupForm::THROTLLED:
135135 $result['result'] = 'Throttled';
136136 break;
137 -
 137+
138138 default:
139139 ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$signupRes}" );
140140 }
141 -
142 - $this->getResult()->addValue( null, 'signup', $result );
 141+
 142+ $this->getResult()->addValue( null, 'signup', $result );
143143 }
144 -
 144+
145145 public function mustBePosted() {
146146 return true;
147147 }
148 -
 148+
149149 public function isReadMode() {
150150 return false;
151151 }
152 -
 152+
153153 public function getAllowedParams() {
154154 return array(
155155 'name' => null,
@@ -168,9 +168,9 @@
169169 'domain' => 'Domain (optional)',
170170 );
171171 }
172 -
173 -
174172
 173+
 174+
175175 public function getDescription() {
176176 return array(
177177 'This module validates the parameters posted by the signup form.',
@@ -215,7 +215,6 @@
216216 public function getVersion() {
217217 return __CLASS__ . ': $Id$';
218218 }
219 -
 219+
220220 }
221 -
222 -
\ No newline at end of file
 221+
Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php
@@ -29,7 +29,7 @@
3030 class SignupForm extends SpecialPage {
3131
3232 const SUCCESS = 0;
33 - const NO_NAME = 1;
 33+ const NO_NAME = 1;
3434 const CREATE_BLOCKED = 2;
3535 const NEED_TOKEN = 3;
3636 const WRONG_TOKEN = 4;
@@ -82,7 +82,7 @@
8383 * @param $request WebRequest object
8484 */
8585 function load( $request ) {
86 - global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
 86+ global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
8787
8888 $this->mType = $request->getText( 'type' );
8989 $this->mUsername = $request->getText( 'wpName' );
@@ -102,9 +102,9 @@
103103 $this->mStickHTTPS = $request->getCheck( 'wpStickHTTPS' );
104104 $this->mLanguage = $request->getText( 'uselang' );
105105 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
106 -
 106+
107107 //Decide whether login or signup request
108 -
 108+
109109 $this->mToken = $request->getVal( 'wpCreateaccountToken' );
110110
111111 if( $wgEnableEmail ) {
@@ -112,7 +112,7 @@
113113 } else {
114114 $this->mEmail = '';
115115 }
116 -
 116+
117117 if( !in_array( 'realname', $wgHiddenPrefs ) ) {
118118 $this->mRealName = $request->getText( 'wpRealName' );
119119 } else {
@@ -142,7 +142,7 @@
143143 return $this->processSignup();
144144 } elseif ( $this->mCreateaccountMail ) {
145145 return $this->addNewAccountMailPassword();
146 - }
 146+ }
147147 }
148148 $this->mainSignupForm( '' );
149149 }
@@ -262,13 +262,13 @@
263263 // to check this for domains that aren't local.
264264 if( 'local' != $this->mDomain && $this->mDomain != '' ) {
265265 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername )
266 - || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) {
 266+ || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) {
267267 return self::INVALID_DOMAIN;
268268 }
269269 }
270270
271271 if ( wfReadOnly() ) {
272 -
 272+
273273 return self::READ_ONLY_PAGE;
274274 }
275275
@@ -284,7 +284,7 @@
285285 }
286286
287287 # Validate the createaccount token
288 - if ( $this->mToken !== self::getCreateaccountToken() ) {
 288+ if ( $this->mToken !== self::getCreateaccountToken() ) {
289289 return self::WRONG_TOKEN;
290290 }
291291
@@ -332,9 +332,9 @@
333333 if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
334334 return self::NO_EMAIL;
335335 }
336 -
 336+
337337 # 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 ) ) {
339339 return self::INVALID_EMAIL;
340340 }
341341
@@ -413,15 +413,14 @@
414414 return $mUser;
415415 }
416416
417 -
418417 function processSignup() {
419418 global $wgUser, $wgOut;
420 -
 419+
421420 switch ( $this->addNewAccountInternal() ) {
422421 case self::SUCCESS:
423422 //$this->initUser( $mUser, false );
424423 //$this->addNewAccount($mUser);
425 - break;
 424+ break;
426425 case self::INVALID_DOMAIN:
427426 $this->mainSignupForm( wfMsg( 'wrongpassword' ) );
428427 break;
@@ -488,8 +487,6 @@
489488 }
490489 }
491490
492 -
493 -
494491 /**
495492 * @param $mUser User object
496493 * @param $throttle Boolean
@@ -522,8 +519,6 @@
523520 return $result;
524521 }
525522
526 -
527 -
528523 /**
529524 * Run any hooks registered for logins, then display a message welcoming
530525 * the user.
@@ -535,12 +530,12 @@
536531 # Run any hooks; display injected HTML
537532 $injected_html = '';
538533 $welcome_creation_msg = 'welcomecreation';
539 -
 534+
540535 wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
541 -
 536+
542537 //let any extensions change what message is shown
543538 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
544 -
 539+
545540 $this->displaySuccessfulCreation( $welcome_creation_msg, $injected_html );
546541 }
547542
@@ -575,7 +570,7 @@
576571 $block_reason,
577572 $block->getBlocker()->getName()
578573 );
579 -
 574+
580575 $wgOut->returnToMain( false );
581576 }
582577
@@ -585,28 +580,27 @@
586581 function mainSignupForm( $msg, $msgtype = 'error' ) {
587582 global $wgUser, $wgOut, $wgHiddenPrefs;
588583 global $wgEnableEmail, $wgEnableUserEmail;
589 - global $wgRequest, $wgLoginLanguageSelector;
 584+ global $wgLoginLanguageSelector;
590585 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
591586 global $wgSecureLogin, $wgPasswordResetRoutes;
592587
593588 $titleObj = SpecialPage::getTitleFor( 'Usersignup' );
594589
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+ }
610603
 604+
611605 if ( $this->mUsername == '' ) {
612606 if ( $wgUser->isLoggedIn() ) {
613607 $this->mUsername = $wgUser->getName();
@@ -615,13 +609,11 @@
616610 }
617611 }
618612
619 -
620613 $template = new UsercreateTemplate();
621614 $q = 'action=submitlogin&type=signup';
622615 $linkq = 'type=login';
623616 $linkmsg = 'gotaccount';
624 -
625 -
 617+
626618 if ( !empty( $this->mReturnTo ) ) {
627619 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
628620 if ( !empty( $this->mReturnToQuery ) ) {
@@ -677,13 +669,11 @@
678670 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
679671 $template->set( 'stickHTTPS', $this->mStickHTTPS );
680672
681 -
682673 if ( !self::getCreateaccountToken() ) {
683674 self::setCreateaccountToken();
684675 }
685676 $template->set( 'token', self::getCreateaccountToken() );
686 -
687 -
 677+
688678 # Prepare language selection links as needed
689679 if( $wgLoginLanguageSelector ) {
690680 $template->set( 'languages', $this->makeLanguageSelector() );
@@ -693,9 +683,8 @@
694684
695685 // Give authentication and captcha plugins a chance to modify the form
696686 $wgAuth->modifyUITemplate( $template, $this->mType );
697 -
 687+
698688 wfRunHooks( 'UserCreateForm', array( &$template ) );
699 -
700689
701690 // Changes the title depending on permissions for creating account
702691 if ( $wgUser->isAllowed( 'createaccount' ) ) {
@@ -803,7 +792,7 @@
804793 *
805794 * @return string
806795 */
807 -
 796+
808797 function makeLanguageSelector() {
809798 global $wgLang;
810799
@@ -849,7 +838,7 @@
850839 $attr
851840 );
852841 }
853 -
 842+
854843 /**
855844 * Display a "login successful" page.
856845 */
@@ -860,7 +849,7 @@
861850 if( $msgname ){
862851 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
863852 }
864 -
 853+
865854 $wgOut->addHTML( $injected_html );
866855
867856 if ( !empty( $this->mReturnTo ) ) {

Status & tagging log