r95698 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95697‎ | r95698 | r95699 >
Date:21:06, 29 August 2011
Author:krinkle
Status:ok
Tags:
Comment:
Apply coding conventions:
* Spaces to tabs
* Spaces after a ',' in globals list.
* Api-classes starting with "Api"
* SpecialPage-classes with format Special{Name}. Renamed SignupForm class to SpecialUserSignup.
* Filenames matching classes they define
* No global functions, instead put hook functions inside a static hooks class

Best practices:
* Don't conditionally define a function
* No need for the 'global' keyword in the config as this is running in the global context already
* Move a file with 'svn move', not with delete and re-add. That way properties and commit history stays preserved. (I deleted ValidateSignup.php, and reverted r95213 to get the original validateSignup.php back and then renamed it to ApiValidateSignup.php)

Issues fixed:
* usersignup was listed on Special:SpecialPages under 'other'. Added it to 'login' group instead.
* Removed usage of inexistent module 'mediawiki.special.usersignup'
Modified paths:
  • /trunk/extensions/SignupAPI/SignupAPI.i18n.php (modified) (history)
  • /trunk/extensions/SignupAPI/SignupAPI.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/APISignup.php (deleted) (history)
  • /trunk/extensions/SignupAPI/includes/ApiSignup.php (added) (history)
  • /trunk/extensions/SignupAPI/includes/ApiValidateSignup.php (added) (history)
  • /trunk/extensions/SignupAPI/includes/SignupAPI.hooks.php (added) (history)
  • /trunk/extensions/SignupAPI/includes/SpecialUserSignup.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/ValidateSignup.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/SignupAPI.i18n.php
@@ -10,18 +10,18 @@
1111
1212 $messages['en'] = array(
1313 'signupapi-desc' => 'Cleans up the [[Special:UserLogin|login page]] from signup related stuff and adds an API for signup',
14 - 'signupapi-ok' => 'OK',
15 - 'signupapi-enterpassword' => 'You must enter a password',
16 - 'signupapi-passwordtooshort' => 'Password is too short',
17 - 'signupapi-weak' => 'Weak',
18 - 'signupapi-medium' => 'Medium',
19 - 'signupapi-strong' => 'Strong',
20 - 'signupapi-badretype' => 'The passwords you entered do not match',
21 - 'signupapi-passwordsmatch' => 'Passwords match',
 14+ 'signupapi-ok' => 'OK',
 15+ 'signupapi-enterpassword' => 'You must enter a password',
 16+ 'signupapi-passwordtooshort' => 'Password is too short',
 17+ 'signupapi-weak' => 'Weak',
 18+ 'signupapi-medium' => 'Medium',
 19+ 'signupapi-strong' => 'Strong',
 20+ 'signupapi-badretype' => 'The passwords you entered do not match',
 21+ 'signupapi-passwordsmatch' => 'Passwords match',
2222
2323 );
2424
25 -/** Belarusian (Taraškievica orthography) (‪Беларуская (тарашкевіца)‬)
 25+/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
2626 * @author Wizardist
2727 */
2828 $messages['be-tarask'] = array(
@@ -43,7 +43,7 @@
4444 'signupapi-passwordsmatch' => 'Die beiden Passwörter stimmen überein.',
4545 );
4646
47 -/** German (formal address) (‪Deutsch (Sie-Form)‬)
 47+/** German (formal address) (Deutsch (Sie-Form))
4848 * @author Kghbln
4949 */
5050 $messages['de-formal'] = array(
Index: trunk/extensions/SignupAPI/SignupAPI.php
@@ -17,147 +17,67 @@
1818 }
1919
2020 $wgExtensionCredits['specialpage'][] = array(
21 - 'path' => __FILE__,
22 - 'name' => 'SignupAPI',
23 - 'version' => 1.0,
24 - 'author' => 'Akshay Agarwal',
25 - 'url' => 'http://www.mediawiki.org/wiki/Extension:SignupAPI',
 21+ 'path' => __FILE__,
 22+ 'name' => 'SignupAPI',
 23+ 'version' => 1.0,
 24+ 'author' => 'Akshay Agarwal',
 25+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SignupAPI',
2626 'descriptionmsg' => 'signupapi-desc',
2727 );
2828
29 -global $wgSignupAPISourceTracking,$wgSignupAPIUseAjax;
3029 $wgSignupAPIUseAjax = true;
3130 $wgSignupAPISourceTracking = true;
3231
 32+# Includes
 33+
3334 $dir = dirname(__FILE__);
3435 $wgExtensionMessagesFiles['SignupAPI'] = $dir . '/SignupAPI.i18n.php';
35 -$wgMyExtensionIncludes = $dir . '/includes';
36 -
37 -## Special page class
38 -$wgAutoloadClasses['SignupForm']
39 - = $wgMyExtensionIncludes . '/SpecialUserSignup.php';
 36+$wgAutoloadClasses['SignupAPIHooks'] = $dir . '/includes/SignupAPI.hooks.php';
4037
41 -$wgAutoloadClasses['ApiSignup']
42 - = $wgMyExtensionIncludes . '/APISignup.php';
43 -$wgSpecialPages['UserSignup'] = 'SignupForm';
 38+// Special page class
 39+$wgSpecialPages['UserSignup'] = 'SpecialUserSignup';
 40+$wgSpecialPageGroups['UserSignup'] = 'login';
 41+$wgAutoloadClasses['SpecialUserSignup'] = $dir . '/includes/SpecialUserSignup.php';
4442
45 -$wgAutoloadClasses['ValidateSignup']
46 - = $wgMyExtensionIncludes . '/ValidateSignup.php';
47 -
 43+// Apis
4844 $wgAPIModules['signup'] = 'ApiSignup';
 45+$wgAutoloadClasses['ApiSignup'] = $dir . '/includes/ApiSignup.php';
4946
50 -$wgAPIModules['validatesignup'] = 'ValidateSignup';
 47+$wgAPIModules['validatesignup'] = 'ApiValidateSignup';
 48+$wgAutoloadClasses['ApiValidateSignup']= $dir . '/includes/ApiValidateSignup.php';
5149
52 -# Requires jquery.ui.progressbar for password strength validation
53 -$wgResourceModules['ext.SignupAPI'] = array(
 50+# Modules
5451
55 - 'scripts' => array( 'includes/verification.js' ),
56 - 'messages' => array( 'signupapi-ok', 'signupapi-enterpassword', 'signupapi-passwordtooshort', 'signupapi-weak', 'signupapi-medium', 'signupapi-strong', 'signupapi-badretype', 'signupapi-passwordsmatch' ),
57 - 'dependencies' => array( 'jquery.ui.progressbar' ),
58 - 'localBasePath' => dirname( __FILE__ ),
59 - 'remoteExtPath' => 'SignupAPI'
 52+$wgResourceModules['ext.SignupAPI'] = array(
 53+ 'scripts' => 'includes/verification.js',
 54+ 'messages' => array(
 55+ 'signupapi-ok',
 56+ 'signupapi-enterpassword',
 57+ 'signupapi-passwordtooshort',
 58+ 'signupapi-weak',
 59+ 'signupapi-medium',
 60+ 'signupapi-strong',
 61+ 'signupapi-badretype',
 62+ 'signupapi-passwordsmatch'
 63+ ),
 64+ 'dependencies' => array( 'jquery.ui.progressbar' ),
 65+ 'localBasePath' => dirname( __FILE__ ),
 66+ 'remoteExtPath' => 'SignupAPI'
6067 );
6168
 69+# Hooks
6270
63 -
6471 if ( $wgSignupAPIUseAjax ) {
65 - $wgHooks['SignupForm'][] = 'onSignupAPIUseAjax';
66 - function onSignupAPIUseAjax() {
67 - global $wgOut;
68 - $wgOut->addModules( 'ext.SignupAPI' );
69 - return true;
70 - }
 72+ $wgHooks['SignupForm'][] = 'SignupAPIHooks::onSignupAPIUseAjax';
7173 }
7274
7375 if ( $wgSignupAPISourceTracking ) {
74 - # Schema updates for update.php
75 - $wgHooks['LoadExtensionSchemaUpdates'][] = 'onSourceTracking';
76 - function onSourceTracking() {
77 - global $wgExtNewTables;
78 - $wgExtNewTables[] = array(
79 - 'sourcetracking',
80 - dirname( __FILE__ ) . '/sourcetracking.sql' );
81 - return true;
82 - }
8376
84 - # Add source tracking to personal URL's
85 - $wgHooks['PersonalUrls'][] = 'addSourceTracking';
 77+ // Schema updates for update.php
 78+ $wgHooks['LoadExtensionSchemaUpdates'][] = 'SignupAPIHooks::onSourceTracking';
8679
87 - function addSourceTracking( &$personal_urls, &$title ) {
88 - global $wgRequest,$wgUser;
89 -
90 - #generate source tracking parameters
91 - $sourceAction = $wgRequest->getVal( 'action' );
92 - $sourceNS = $title->getNamespace();
93 - $sourceArticle = $title->getArticleID();
94 - $loggedin = $wgUser->isLoggedIn();
95 - $thispage = $title->getPrefixedDBkey();
96 - $thisurl = $title->getPrefixedURL();
97 - $query = array();
98 - if ( !$wgRequest->wasPosted() ) {
99 - $query = $wgRequest->getValues();
100 - unset( $query['title'] );
101 - unset( $query['returnto'] );
102 - unset( $query['returntoquery'] );
103 - }
104 - $thisquery = wfUrlencode( wfArrayToCGI( $query ) );
105 -
106 - // Get the returnto and returntoquery parameters from the query string
107 - // or fall back on $this->thisurl or $this->thisquery
108 - // We can't use getVal()'s default value feature here because
109 - // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
110 - // are already escaped.
111 - $page = $wgRequest->getVal( 'returnto' );
112 - if ( !is_null( $page ) ) {
113 - $page = wfUrlencode( $page );
114 - } else {
115 - $page = $thisurl;
116 - }
117 - $query = $wgRequest->getVal( 'returntoquery' );
118 - if ( !is_null( $query ) ) {
119 - $query = wfUrlencode( $query );
120 - } else {
121 - $query = $thisquery;
122 - }
123 - $returnto = "returnto=$page";
124 - if ( $query != '' ) {
125 - $returnto .= "&returntoquery=$query";
126 - }
127 -
128 - if (isset ( $personal_urls['login'] ) ) {
129 - $login_url = $personal_urls['login'];
130 - $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
131 - $personal_urls['login'] = $login_url;
132 - }
133 -
134 - if ( isset ( $personal_urls['anonlogin'] ) ) {
135 - $login_url = $personal_urls['anonlogin'];
136 - $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
137 - $personal_urls['anonlogin'] = $login_url;
138 - }
139 -
140 - if ( isset ( $personal_urls['createaccount'] ) ) {
141 - global $wgServer, $wgSecureLogin;
142 - $page = $wgRequest->getVal( 'returnto' );
143 - $is_signup = $wgRequest->getText( 'type' ) == "signup";
144 - $createaccount_url = array(
145 - 'text' => wfMsg( 'createaccount' ),
146 - 'href' => SkinTemplate::makeSpecialUrl( 'UserSignup', "$returnto&type=signup&wpSourceAction=$sourceAction&wpSourceNS=$sourceNS&wpSourceArticle=$sourceArticle" ),
147 - 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
148 - );
149 -
150 - if ( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
151 - $title = SpecialPage::getTitleFor( 'UserSignup' );
152 - $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL( "type=signup" ) );
153 - $createaccount_url['href'] = $https_url;
154 - $createaccount_url['class'] = 'link-https';
155 - }
156 - $personal_urls['createaccount'] = $createaccount_url;
157 - }
158 -
159 - return true;
160 - }
161 -
 80+ // Add source tracking to personal URL's
 81+ $wgHooks['PersonalUrls'][] = 'SignupAPIHooks::addSourceTracking';
16282 }
16383
16484
Index: trunk/extensions/SignupAPI/includes/APISignup.php
@@ -1,230 +0,0 @@
2 -<?php
3 -
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - // Eclipse helper - will be ignored in production
6 - require_once( 'ApiBase.php' );
7 -}
8 -
9 -/**
10 - * Unit to create accounts in the current wiki
11 - *
12 - * @ingroup API
13 - */
14 -class ApiSignup extends ApiBase {
15 -
16 - public function __construct( $main, $action ) {
17 - parent::__construct( $main, $action );
18 - }
19 -
20 - public function execute() {
21 - $params = $this->extractRequestParams();
22 -
23 - $result = array();
24 -
25 - $req = new FauxRequest( array(
26 - 'wpName' => $params['name'],
27 - 'wpPassword' => $params['password'],
28 - 'wpRetype' => $params['retype'],
29 - 'wpEmail' => $params['email'],
30 - 'wpDomain' => $params['domain'],
31 - 'wpReason' => $params['realname'],
32 - 'wpSourceAction' => $params['source_action'],
33 - 'wpSourceNS' => $params['source_ns'],
34 - 'wpSourceArticle' => $params['source_article'],
35 - 'wpRemember' => ''
36 - ) );
37 -
38 - // Init session if necessary
39 - if ( session_id() == '' ) {
40 - wfSetupSession();
41 - }
42 -
43 - $signupForm = new SignupForm( $req );
44 -
45 - global $wgCookiePrefix, $wgUser;
46 -
47 - $signupRes = $signupForm->addNewAccountInternal();
48 - switch( $signupRes ) {
49 - case SignupForm::SUCCESS:
50 - //$signupForm->initUser($signupForm->mUser);
51 -
52 - wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
53 - # Run any hooks; display injected HTML
54 - $injected_html = '';
55 - $welcome_creation_msg = 'welcomecreation';
56 -
57 - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
58 -
59 - //let any extensions change what message is shown
60 - wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
61 -
62 - $result['result'] = 'Success';
63 - $result['lguserid'] = intval( $wgUser->getId() );
64 - $result['lgusername'] = $wgUser->getName();
65 - $result['lgtoken'] = $wgUser->getToken();
66 - $result['cookieprefix'] = $wgCookiePrefix;
67 - $result['sessionid'] = session_id();
68 - break;
69 -
70 - case SignupForm::INVALID_DOMAIN:
71 - $result['result'] = 'WrongPassword';
72 - $result['domain']= $signupForm->mDomain;
73 - break;
74 -
75 - case SignupForm::READ_ONLY_PAGE:
76 - $result['result'] = 'ReadOnlyPage';
77 - break;
78 -
79 - case SignupForm::NO_COOKIES:
80 - $result['result'] = 'NoCookies';
81 - break;
82 -
83 - case SignupForm::NEED_TOKEN:
84 - $result['result'] = 'NeedToken';
85 - $result['token'] = $signupForm->getCreateaccountToken();
86 - $result['cookieprefix'] = $wgCookiePrefix;
87 - $result['sessionid'] = session_id();
88 - break;
89 -
90 - case SignupForm::WRONG_TOKEN:
91 - $result['result'] = 'WrongToken';
92 - break;
93 -
94 - case SignupForm::INSUFFICIENT_PERMISSION:
95 - $result['result'] = 'InsufficientPermission';
96 - break;
97 -
98 - case SignupForm::CREATE_BLOCKED:
99 - $result['result'] = 'CreateBlocked';
100 - break;
101 -
102 - case SignupForm::IP_BLOCKED:
103 - $result['result'] = 'IPBlocked';
104 - break;
105 -
106 - case SignupForm::NO_NAME:
107 - $result['result'] = 'NoName';
108 - break;
109 -
110 - case SignupForm::USER_EXISTS:
111 - $result['result'] = 'UserExists';
112 - break;
113 -
114 - case SignupForm::WRONG_RETYPE:
115 - $result['result'] = 'WrongRetype';
116 - break;
117 -
118 - case SignupForm::INVALID_PASS:
119 - $result['result'] = 'InvalidPass';
120 - break;
121 -
122 - case SignupForm::NO_EMAIL:
123 - $result['result'] = 'NoEmail';
124 - break;
125 -
126 - case SignupForm::INVALID_EMAIL:
127 - $result['result'] = 'InvalidEmail';
128 - break;
129 -
130 - case SignupForm::BLOCKED_BY_HOOK:
131 - $result['result'] = 'BlockedByHook';
132 - break;
133 -
134 - case SignupForm::EXTR_DB_ERROR:
135 - $result['result'] = 'ExternalDBError';
136 - break;
137 -
138 - case SignupForm::THROTLLED:
139 - $result['result'] = 'Throttled';
140 - break;
141 -
142 - default:
143 - ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$signupRes}" );
144 - }
145 -
146 - $this->getResult()->addValue( null, 'signup', $result );
147 - }
148 -
149 - public function mustBePosted() {
150 - return true;
151 - }
152 -
153 - public function isReadMode() {
154 - return false;
155 - }
156 -
157 - public function getAllowedParams() {
158 - return array(
159 - 'name' => null,
160 - 'password' => null,
161 - 'retype' => null,
162 - 'email' => null,
163 - 'domain' => null,
164 - 'realname' => null,
165 - 'source_action' => null,
166 - 'source_ns' => null,
167 - 'source_article' => null,
168 - );
169 - }
170 -
171 - public function getParamDescription() {
172 - return array(
173 - 'name' => 'Desired Username',
174 - 'password' => 'Password',
175 - 'retype' => 'Re-typed Password',
176 - 'email' => 'Email ID(optional)',
177 - 'domain' => 'Domain (optional)',
178 - 'realname' => 'Real Name(optional)',
179 - 'source_action' => 'Source Action',
180 - 'source_ns' => 'Source Namespace ID',
181 - 'source_article' => 'Source Article ID',
182 - );
183 - }
184 -
185 - public function getDescription() {
186 - return array(
187 - 'This module validates the parameters posted by the signup form.',
188 - 'If validated, a new account is created for the user.',
189 - 'If validation of any of the fields fails, the cause of',
190 - 'the error will be output. If the user chooses to provide',
191 - 'his email then a confirmation mail will be sent to him.',
192 - 'On successful account creation, this module will call APILogin',
193 - 'alongwith the newly created username & password'
194 - );
195 - }
196 -
197 - public function getPossibleErrors() {
198 - return array_merge( parent::getPossibleErrors(), array(
199 - array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ),
200 - array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ),
201 - array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source.
202 - Ensure you have cookies enabled, reload this page and try again.' ),
203 - array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ),
204 - array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ),
205 - array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ),
206 - array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ),
207 - array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ),
208 - array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ),
209 - array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ),
210 - array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ),
211 - array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ),
212 - array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ),
213 - array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ),
214 - array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ),
215 - array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ),
216 - array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ),
217 - ) );
218 - }
219 -
220 - protected function getExamples() {
221 - return array(
222 - 'api.php?action=signup&username=username&password=password&retype=passretype'
223 - );
224 - }
225 -
226 - public function getVersion() {
227 - return __CLASS__ . ': $Id$';
228 - }
229 -
230 -}
231 -
Index: trunk/extensions/SignupAPI/includes/ValidateSignup.php
@@ -1,129 +0,0 @@
2 -<?php
3 -
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - // Eclipse helper - will be ignored in production
6 - require_once( 'ApiBase.php' );
7 -}
8 -
9 -/**
10 - * Unit to create accounts in the current wiki
11 - *
12 - * @ingroup API
13 - */
14 -class ValidateSignup extends ApiBase {
15 -
16 - public function __construct( $main, $action ) {
17 - parent::__construct( $main, $action );
18 - }
19 -
20 - public function execute() {
21 - $params = $this->extractRequestParams();
22 -
23 - $result = array();
24 -
25 - switch ( $params['field'] ) {
26 - case "username":
27 - $mUser = User::newFromName( $params['inputVal'], 'creatable' );
28 - if ( !is_object( $mUser ) ) {
29 - $result['result'] = wfMsg( 'noname' );
30 - $result['icon'] = 'MW-Icon-AlertMark.png';
31 - }
32 -
33 - if ( 0 != $mUser->idForName() ) {
34 - $result['result'] = wfMsg( 'userexists' );
35 - $result['icon'] = "MW-Icon-NoMark.png";
36 - } else {
37 - $result['result'] = wfMsg( 'ok' );
38 - $result['icon'] = "MW-Icon-CheckMark.png";
39 - }
40 - break;
41 -
42 - case "email" :
43 - if ( $valid = User::isValidEmailAddr( $params['inputVal'] ) ) {
44 - $result['result']= wfMsg( 'ok' );
45 - $result['icon'] = "MW-Icon-CheckMark.png";
46 - } else {
47 - $result['result']= wfMsg( 'invalidemailaddress' );
48 - $result['icon'] = "MW-Icon-NoMark.png";
49 - }
50 - break;
51 -
52 - case "passwordlength" :
53 - global $wgMinimalPasswordLength;
54 - $result['result'] = $wgMinimalPasswordLength;
55 - break;
56 -
57 - default :
58 - ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$params['field']}" );
59 - }
60 -
61 - $this->getResult()->addValue( null, 'signup', $result );
62 - }
63 -
64 - public function mustBePosted() {
65 - return false;
66 - }
67 -
68 - public function isReadMode() {
69 - return false;
70 - }
71 -
72 - public function getAllowedParams() {
73 - return array(
74 - 'field' => null,
75 - 'inputVal' => null,
76 - 'password' => null,
77 - 'retype' => null,
78 - 'email' => null,
79 - );
80 - }
81 -
82 - public function getParamDescription() {
83 - return array(
84 - 'name' => 'Desired Username',
85 - 'password' => 'Password',
86 - 'retype' => 'Re-typed Password',
87 - 'email' => 'Email ID(optional)',
88 - );
89 - }
90 -
91 - public function getDescription() {
92 - return array(
93 - 'This module validates the parameters posted by the signup form.'
94 - );
95 - }
96 -
97 - public function getPossibleErrors() {
98 - return array_merge( parent::getPossibleErrors(), array(
99 - array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ),
100 - array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ),
101 - array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source.
102 - Ensure you have cookies enabled, reload this page and try again.' ),
103 - array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ),
104 - array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ),
105 - array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ),
106 - array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ),
107 - array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ),
108 - array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ),
109 - array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ),
110 - array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ),
111 - array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ),
112 - array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ),
113 - array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ),
114 - array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ),
115 - array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ),
116 - array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ),
117 - ) );
118 - }
119 -
120 - protected function getExamples() {
121 - return array(
122 - 'api.php?action=validatesignup&field=username&name=username'
123 - );
124 - }
125 -
126 - public function getVersion() {
127 - return __CLASS__ . ': $Id: validateSignup.php 91472 2011-07-05 18:43:51Z akshay $';
128 - }
129 -
130 -}
Index: trunk/extensions/SignupAPI/includes/ApiValidateSignup.php
@@ -0,0 +1,132 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) {
 5+ // Eclipse helper - will be ignored in production
 6+ require_once( 'ApiBase.php' );
 7+}
 8+
 9+/**
 10+ * Unit to create accounts in the current wiki
 11+ *
 12+ * @ingroup API
 13+ */
 14+class ApiValidateSignup extends ApiBase {
 15+
 16+ public function __construct( $main, $action ) {
 17+ parent::__construct( $main, $action );
 18+ }
 19+
 20+ public function execute() {
 21+ $params = $this->extractRequestParams();
 22+
 23+ $result = array();
 24+
 25+ switch ( $params['field'] ) {
 26+ case "username":
 27+ $mUser = User::newFromName( $params['inputVal'], 'creatable' );
 28+ if ( !is_object( $mUser ) ) {
 29+ $result['result'] = wfMsg( 'noname' );
 30+ $result['icon'] = 'MW-Icon-AlertMark.png';
 31+ }
 32+
 33+ if ( 0 != $mUser->idForName() ) {
 34+ $result['result'] = wfMsg( 'userexists' );
 35+ $result['icon'] = "MW-Icon-NoMark.png";
 36+ }
 37+
 38+ else {
 39+ $result['result'] = wfMsg( 'ok' );
 40+ $result['icon'] = "MW-Icon-CheckMark.png";
 41+ }
 42+ break;
 43+
 44+ case "email" :
 45+ if ( $valid = User::isValidEmailAddr( $params['inputVal'] ) ) {
 46+ $result['result']= wfMsg( 'ok' );
 47+ $result['icon'] = "MW-Icon-CheckMark.png";
 48+ }
 49+ else {
 50+ $result['result']= wfMsg( 'invalidemailaddress' );
 51+ $result['icon'] = "MW-Icon-NoMark.png";
 52+ }
 53+ break;
 54+
 55+ case "passwordlength" :
 56+ global $wgMinimalPasswordLength;
 57+ $result['result'] = $wgMinimalPasswordLength;
 58+ break;
 59+
 60+ default :
 61+ ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$params['field']}" );
 62+ }
 63+
 64+ $this->getResult()->addValue( null, 'signup', $result );
 65+ }
 66+
 67+ public function mustBePosted() {
 68+ return false;
 69+ }
 70+
 71+ public function isReadMode() {
 72+ return false;
 73+ }
 74+
 75+ public function getAllowedParams() {
 76+ return array(
 77+ 'field' => null,
 78+ 'inputVal' => null,
 79+ 'password' => null,
 80+ 'retype' => null,
 81+ 'email' => null,
 82+ );
 83+ }
 84+
 85+ public function getParamDescription() {
 86+ return array(
 87+ 'name' => 'Desired Username',
 88+ 'password' => 'Password',
 89+ 'retype' => 'Re-typed Password',
 90+ 'email' => 'Email ID(optional)',
 91+ );
 92+ }
 93+
 94+ public function getDescription() {
 95+ return array(
 96+ 'This module validates the parameters posted by the signup form.'
 97+ );
 98+ }
 99+
 100+ public function getPossibleErrors() {
 101+ return array_merge( parent::getPossibleErrors(), array(
 102+ array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ),
 103+ array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ),
 104+ array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source.
 105+ Ensure you have cookies enabled, reload this page and try again.' ),
 106+ array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ),
 107+ array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ),
 108+ array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ),
 109+ array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ),
 110+ array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ),
 111+ array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ),
 112+ array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ),
 113+ array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ),
 114+ array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ),
 115+ array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ),
 116+ array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ),
 117+ array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ),
 118+ array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ),
 119+ array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ),
 120+ ) );
 121+ }
 122+
 123+ protected function getExamples() {
 124+ return array(
 125+ 'api.php?action=validatesignup&field=username&name=username'
 126+ );
 127+ }
 128+
 129+ public function getVersion() {
 130+ return __CLASS__ . ': $Id: validateSignup.php 91472 2011-07-05 18:43:51Z akshay $';
 131+ }
 132+
 133+}
Property changes on: trunk/extensions/SignupAPI/includes/ApiValidateSignup.php
___________________________________________________________________
Added: svn:eol-style
1134 + native
Index: trunk/extensions/SignupAPI/includes/ApiSignup.php
@@ -0,0 +1,230 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) {
 5+ // Eclipse helper - will be ignored in production
 6+ require_once( 'ApiBase.php' );
 7+}
 8+
 9+/**
 10+ * Unit to create accounts in the current wiki
 11+ *
 12+ * @ingroup API
 13+ */
 14+class ApiSignup extends ApiBase {
 15+
 16+ public function __construct( $main, $action ) {
 17+ parent::__construct( $main, $action );
 18+ }
 19+
 20+ public function execute() {
 21+ $params = $this->extractRequestParams();
 22+
 23+ $result = array();
 24+
 25+ $req = new FauxRequest( array(
 26+ 'wpName' => $params['name'],
 27+ 'wpPassword' => $params['password'],
 28+ 'wpRetype' => $params['retype'],
 29+ 'wpEmail' => $params['email'],
 30+ 'wpDomain' => $params['domain'],
 31+ 'wpReason' => $params['realname'],
 32+ 'wpSourceAction' => $params['source_action'],
 33+ 'wpSourceNS' => $params['source_ns'],
 34+ 'wpSourceArticle' => $params['source_article'],
 35+ 'wpRemember' => ''
 36+ ) );
 37+
 38+ // Init session if necessary
 39+ if ( session_id() == '' ) {
 40+ wfSetupSession();
 41+ }
 42+
 43+ $signupForm = new SignupForm( $req );
 44+
 45+ global $wgCookiePrefix, $wgUser;
 46+
 47+ $signupRes = $signupForm->addNewAccountInternal();
 48+ switch( $signupRes ) {
 49+ case SignupForm::SUCCESS:
 50+ //$signupForm->initUser($signupForm->mUser);
 51+
 52+ wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
 53+ # Run any hooks; display injected HTML
 54+ $injected_html = '';
 55+ $welcome_creation_msg = 'welcomecreation';
 56+
 57+ wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
 58+
 59+ //let any extensions change what message is shown
 60+ wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
 61+
 62+ $result['result'] = 'Success';
 63+ $result['lguserid'] = intval( $wgUser->getId() );
 64+ $result['lgusername'] = $wgUser->getName();
 65+ $result['lgtoken'] = $wgUser->getToken();
 66+ $result['cookieprefix'] = $wgCookiePrefix;
 67+ $result['sessionid'] = session_id();
 68+ break;
 69+
 70+ case SignupForm::INVALID_DOMAIN:
 71+ $result['result'] = 'WrongPassword';
 72+ $result['domain']= $signupForm->mDomain;
 73+ break;
 74+
 75+ case SignupForm::READ_ONLY_PAGE:
 76+ $result['result'] = 'ReadOnlyPage';
 77+ break;
 78+
 79+ case SignupForm::NO_COOKIES:
 80+ $result['result'] = 'NoCookies';
 81+ break;
 82+
 83+ case SignupForm::NEED_TOKEN:
 84+ $result['result'] = 'NeedToken';
 85+ $result['token'] = $signupForm->getCreateaccountToken();
 86+ $result['cookieprefix'] = $wgCookiePrefix;
 87+ $result['sessionid'] = session_id();
 88+ break;
 89+
 90+ case SignupForm::WRONG_TOKEN:
 91+ $result['result'] = 'WrongToken';
 92+ break;
 93+
 94+ case SignupForm::INSUFFICIENT_PERMISSION:
 95+ $result['result'] = 'InsufficientPermission';
 96+ break;
 97+
 98+ case SignupForm::CREATE_BLOCKED:
 99+ $result['result'] = 'CreateBlocked';
 100+ break;
 101+
 102+ case SignupForm::IP_BLOCKED:
 103+ $result['result'] = 'IPBlocked';
 104+ break;
 105+
 106+ case SignupForm::NO_NAME:
 107+ $result['result'] = 'NoName';
 108+ break;
 109+
 110+ case SignupForm::USER_EXISTS:
 111+ $result['result'] = 'UserExists';
 112+ break;
 113+
 114+ case SignupForm::WRONG_RETYPE:
 115+ $result['result'] = 'WrongRetype';
 116+ break;
 117+
 118+ case SignupForm::INVALID_PASS:
 119+ $result['result'] = 'InvalidPass';
 120+ break;
 121+
 122+ case SignupForm::NO_EMAIL:
 123+ $result['result'] = 'NoEmail';
 124+ break;
 125+
 126+ case SignupForm::INVALID_EMAIL:
 127+ $result['result'] = 'InvalidEmail';
 128+ break;
 129+
 130+ case SignupForm::BLOCKED_BY_HOOK:
 131+ $result['result'] = 'BlockedByHook';
 132+ break;
 133+
 134+ case SignupForm::EXTR_DB_ERROR:
 135+ $result['result'] = 'ExternalDBError';
 136+ break;
 137+
 138+ case SignupForm::THROTLLED:
 139+ $result['result'] = 'Throttled';
 140+ break;
 141+
 142+ default:
 143+ ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$signupRes}" );
 144+ }
 145+
 146+ $this->getResult()->addValue( null, 'signup', $result );
 147+ }
 148+
 149+ public function mustBePosted() {
 150+ return true;
 151+ }
 152+
 153+ public function isReadMode() {
 154+ return false;
 155+ }
 156+
 157+ public function getAllowedParams() {
 158+ return array(
 159+ 'name' => null,
 160+ 'password' => null,
 161+ 'retype' => null,
 162+ 'email' => null,
 163+ 'domain' => null,
 164+ 'realname' => null,
 165+ 'source_action' => null,
 166+ 'source_ns' => null,
 167+ 'source_article' => null,
 168+ );
 169+ }
 170+
 171+ public function getParamDescription() {
 172+ return array(
 173+ 'name' => 'Desired Username',
 174+ 'password' => 'Password',
 175+ 'retype' => 'Re-typed Password',
 176+ 'email' => 'Email ID(optional)',
 177+ 'domain' => 'Domain (optional)',
 178+ 'realname' => 'Real Name(optional)',
 179+ 'source_action' => 'Source Action',
 180+ 'source_ns' => 'Source Namespace ID',
 181+ 'source_article' => 'Source Article ID',
 182+ );
 183+ }
 184+
 185+ public function getDescription() {
 186+ return array(
 187+ 'This module validates the parameters posted by the signup form.',
 188+ 'If validated, a new account is created for the user.',
 189+ 'If validation of any of the fields fails, the cause of',
 190+ 'the error will be output. If the user chooses to provide',
 191+ 'his email then a confirmation mail will be sent to him.',
 192+ 'On successful account creation, this module will call APILogin',
 193+ 'alongwith the newly created username & password'
 194+ );
 195+ }
 196+
 197+ public function getPossibleErrors() {
 198+ return array_merge( parent::getPossibleErrors(), array(
 199+ array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ),
 200+ array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ),
 201+ array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source.
 202+ Ensure you have cookies enabled, reload this page and try again.' ),
 203+ array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ),
 204+ array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ),
 205+ array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ),
 206+ array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ),
 207+ array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ),
 208+ array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ),
 209+ array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ),
 210+ array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ),
 211+ array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ),
 212+ array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ),
 213+ array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ),
 214+ array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ),
 215+ array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ),
 216+ array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ),
 217+ ) );
 218+ }
 219+
 220+ protected function getExamples() {
 221+ return array(
 222+ 'api.php?action=signup&username=username&password=password&retype=passretype'
 223+ );
 224+ }
 225+
 226+ public function getVersion() {
 227+ return __CLASS__ . ': $Id$';
 228+ }
 229+
 230+}
 231+
Property changes on: trunk/extensions/SignupAPI/includes/ApiSignup.php
___________________________________________________________________
Added: svn:eol-style
1232 + native
Added: svn:keywords
2233 + Id
Index: trunk/extensions/SignupAPI/includes/SignupAPI.hooks.php
@@ -0,0 +1,104 @@
 2+<?php
 3+/**
 4+ * Hooks for SignupAPI
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class SignupAPIHooks {
 11+
 12+ function onSignupAPIUseAjax() {
 13+ global $wgOut;
 14+ $wgOut->addModules( 'ext.SignupAPI' );
 15+ return true;
 16+ }
 17+
 18+ function onSourceTracking() {
 19+ global $wgExtNewTables;
 20+
 21+ $wgExtNewTables[] = array(
 22+ 'sourcetracking',
 23+ dirname( __FILE__ ) . '/sourcetracking.sql'
 24+ );
 25+ return true;
 26+ }
 27+
 28+ function addSourceTracking( &$personal_urls, &$title ) {
 29+ global $wgRequest, $wgUser, $wgServer, $wgSecureLogin;
 30+
 31+ // Generate source tracking parameters
 32+ $sourceAction = $wgRequest->getVal( 'action' );
 33+ $sourceNS = $title->getNamespace();
 34+ $sourceArticle = $title->getArticleID();
 35+ $loggedin = $wgUser->isLoggedIn();
 36+ $thispage = $title->getPrefixedDBkey();
 37+ $thisurl = $title->getPrefixedURL();
 38+ $query = array();
 39+ if ( !$wgRequest->wasPosted() ) {
 40+ $query = $wgRequest->getValues();
 41+ unset( $query['title'] );
 42+ unset( $query['returnto'] );
 43+ unset( $query['returntoquery'] );
 44+ }
 45+ $thisquery = wfUrlencode( wfArrayToCGI( $query ) );
 46+
 47+ // Get the returnto and returntoquery parameters from the query string
 48+ // or fall back on $this->thisurl or $this->thisquery
 49+ // We can't use getVal()'s default value feature here because
 50+ // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
 51+ // are already escaped.
 52+ $page = $wgRequest->getVal( 'returnto' );
 53+ if ( !is_null( $page ) ) {
 54+ $page = wfUrlencode( $page );
 55+ } else {
 56+ $page = $thisurl;
 57+ }
 58+ $query = $wgRequest->getVal( 'returntoquery' );
 59+ if ( !is_null( $query ) ) {
 60+ $query = wfUrlencode( $query );
 61+ } else {
 62+ $query = $thisquery;
 63+ }
 64+ $returnto = "returnto=$page";
 65+ if ( $query != '' ) {
 66+ $returnto .= "&returntoquery=$query";
 67+ }
 68+
 69+ if (isset ( $personal_urls['login'] ) ) {
 70+ $login_url = $personal_urls['login'];
 71+ $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
 72+ $personal_urls['login'] = $login_url;
 73+ }
 74+
 75+ if ( isset ( $personal_urls['anonlogin'] ) ) {
 76+ $login_url = $personal_urls['anonlogin'];
 77+ $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
 78+ $personal_urls['anonlogin'] = $login_url;
 79+ }
 80+
 81+ if ( isset ( $personal_urls['createaccount'] ) ) {
 82+ $page = $wgRequest->getVal( 'returnto' );
 83+ $is_signup = $wgRequest->getText( 'type' ) == "signup";
 84+ $createaccount_url = array(
 85+ 'text' => wfMsg( 'createaccount' ),
 86+ 'href' => SkinTemplate::makeSpecialUrl( 'UserSignup', "$returnto&type=signup&wpSourceAction=$sourceAction&wpSourceNS=$sourceNS&wpSourceArticle=$sourceArticle" ),
 87+ 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
 88+ );
 89+
 90+ if ( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
 91+ $title = SpecialPage::getTitleFor( 'UserSignup' );
 92+ $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL( "type=signup" ) );
 93+ $createaccount_url['href'] = $https_url;
 94+ $createaccount_url['class'] = 'link-https';
 95+ }
 96+
 97+ $personal_urls['createaccount'] = $createaccount_url;
 98+
 99+ }
 100+
 101+ return true;
 102+
 103+ }
 104+
 105+}
Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php
@@ -26,7 +26,7 @@
2727 *
2828 * @ingroup SpecialPage
2929 */
30 -class SignupForm extends SpecialPage {
 30+class SpecialUserSignup extends SpecialPage {
3131
3232 const SUCCESS = 0;
3333 const NO_NAME = 1;
@@ -46,7 +46,7 @@
4747 const BLOCKED_BY_HOOK = 15;
4848 const EXTR_DB_ERROR = 16;
4949 const THROTLLED = 17;
50 - const INIT_FAILED = 18;
 50+ const INIT_FAILED = 18;
5151
5252 //Initialise all variables to be used
5353 var $tempUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
@@ -56,7 +56,7 @@
5757 var $mType, $mReason, $mRealName;
5858 var $abortError = '';
5959 var $tempUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation;
60 - var $mSourceAction, $mSourceNS, $msourceArticle;
 60+ var $mSourceAction, $mSourceNS, $msourceArticle;
6161
6262 /**
6363 * @var ExternalUser
@@ -105,9 +105,9 @@
106106 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
107107 $this->mToken = $request->getVal( 'wpCreateaccountToken' );
108108
109 - $this->mSourceAction = $request->getVal( 'wpSourceAction' );
110 - $this->mSourceNS = $request->getVal( 'wpSourceNS' );
111 - $this->msourceArticle = $request->getVal( 'wpSourceArticle' );
 109+ $this->mSourceAction = $request->getVal( 'wpSourceAction' );
 110+ $this->mSourceNS = $request->getVal( 'wpSourceNS' );
 111+ $this->msourceArticle = $request->getVal( 'wpSourceArticle' );
112112
113113 if( $wgEnableEmail ) {
114114 $this->mEmail = $request->getText( 'wpEmail' );
@@ -129,9 +129,6 @@
130130
131131 public function execute( $par ) {
132132
133 - global $wgOut;
134 - $wgOut->addModules( 'mediawiki.special.usersignup' );
135 -
136133 if ( session_id() == '' ) {
137134 wfSetupSession();
138135 }
@@ -145,9 +142,9 @@
146143 return;
147144 } elseif( $this->mPosted ) {
148145 if( $this->mCreateaccount ) {
149 - return $this->processSignup();
 146+ return $this->processSignup();
150147 } elseif ( $this->mCreateaccountMail ) {
151 - return $this->addNewAccountMailPassword();
 148+ return $this->addNewAccountMailPassword();
152149 }
153150 }
154151
@@ -157,11 +154,11 @@
158155 /**
159156 * @private
160157 */
161 - //Used for mailing password reset request
 158+ // Used for mailing password reset request
162159 function addNewAccountMailPassword() {
163160 global $wgOut;
164161
165 - //check if no email id was provided
 162+ // Check if no email id was provided
166163 if ( $this->mEmail == '' ) {
167164 $this->mainSignupForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mUsername ) );
168165 return;
@@ -224,10 +221,10 @@
225222 return true;
226223 } else {
227224 $this->mRunCookieRedirect = true;
228 - return true;
 225+ return true;
229226 }
230227 } else {
231 - $this->mRunCreationConfirmation = true;
 228+ $this->mRunCreationConfirmation = true;
232229 wfRunHooks( 'AddNewAccount', array( $tempUser, false ) );
233230 $tempUser->addNewUserLogEntry( false, $this->mReason );
234231 return true;
@@ -270,7 +267,7 @@
271268 self::setCreateaccountToken();
272269 return self::NO_COOKIES;
273270 }
274 -
 271+
275272 # The user didn't pass a createaccount token
276273 if ( !$this->mToken ) {
277274 return self::NEED_TOKEN;
@@ -329,7 +326,7 @@
330327 # if email is provided then validate it
331328 if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) {
332329 return self::INVALID_EMAIL;
333 - }
 330+ }
334331
335332 # Set some additional data so the AbortNewAccount hook can be used for
336333 # more than just username validation
@@ -361,12 +358,12 @@
362359 self::clearCreateaccountToken();
363360
364361 $tempUser = $this->initUser( $tempUser, false );
365 - if( $tempUser == null ) {
366 - return self::INIT_FAILED;
367 - }
368 -
369 - $this->addNewAccount( $tempUser );
370 - return self::SUCCESS;
 362+ if( $tempUser == null ) {
 363+ return self::INIT_FAILED;
 364+ }
 365+
 366+ $this->addNewAccount( $tempUser );
 367+ return self::SUCCESS;
371368 }
372369
373370 /**
@@ -408,7 +405,7 @@
409406 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
410407 $ssUpdate->doUpdate();
411408
412 - $this->addToSourceTracking( $tempUser );
 409+ $this->addToSourceTracking( $tempUser );
413410
414411 return $tempUser;
415412 }
@@ -418,25 +415,25 @@
419416
420417 switch ( $this->addNewAccountInternal() ) {
421418 case self::SUCCESS:
422 - if( $wgEmailAuthentication ) {
423 - if( $this->mConfirmationMailStatus->isGood() ) {
424 - $wgOut->addWikiMsg( 'confirmemail_oncreate' );
425 - } else {
426 - $wgOut->addWikiText( $this->mConfirmationMailStatus->getWikiText( 'confirmemail_sendfailed' ) );
427 - }
428 - }
 419+ if( $wgEmailAuthentication ) {
 420+ if( $this->mConfirmationMailStatus->isGood() ) {
 421+ $wgOut->addWikiMsg( 'confirmemail_oncreate' );
 422+ } else {
 423+ $wgOut->addWikiText( $this->mConfirmationMailStatus->getWikiText( 'confirmemail_sendfailed' ) );
 424+ }
 425+ }
429426
430 - if( $this->mRunCookieRedirect ) {
431 - $this->cookieRedirectCheck( 'new' );
432 - }
 427+ if( $this->mRunCookieRedirect ) {
 428+ $this->cookieRedirectCheck( 'new' );
 429+ }
433430
434 - # Confirm that the account was created
435 - if( $this->mRunCreationConfirmation ) {
436 - $self = SpecialPage::getTitleFor( 'Userlogin' );
437 - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
438 - $wgOut->addWikiMsg( 'accountcreatedtext', $tempUser->getName() );
439 - $wgOut->returnToMain( false, $self );
440 - }
 431+ # Confirm that the account was created
 432+ if( $this->mRunCreationConfirmation ) {
 433+ $self = SpecialPage::getTitleFor( 'Userlogin' );
 434+ $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
 435+ $wgOut->addWikiMsg( 'accountcreatedtext', $tempUser->getName() );
 436+ $wgOut->returnToMain( false, $self );
 437+ }
441438
442439 $this->successfulCreation();
443440 break;
@@ -519,8 +516,8 @@
520517 $this->mainSignupForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $wgAccountCreationThrottle ) );
521518 break;
522519
523 - case self::INIT_FAILED:
524 - $this->mainSignupForm( wfMsg( 'init_failed' ) );
 520+ case self::INIT_FAILED:
 521+ $this->mainSignupForm( wfMsg( 'init_failed' ) );
525522 break;
526523
527524 default:
@@ -582,7 +579,7 @@
583580
584581 /**
585582 * Output a message that informs the user that they cannot create an account because
586 - * there is a block on them or their IP which prevents account creation. Note that
 583+ * there is a block on them or their IP which prevents account creation. Note that
587584 * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
588585 * setting on blocks (bug 13611).
589586 * @param $block Block the block causing this error
@@ -710,9 +707,9 @@
711708 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
712709 $template->set( 'stickHTTPS', $this->mStickHTTPS );
713710
714 - $template->set( 'wpSourceAction', $this->mSourceAction );
715 - $template->set( 'wpSourceNS', $this->mSourceNS );
716 - $template->set( 'wpSourceArticle', $this->msourceArticle );
 711+ $template->set( 'wpSourceAction', $this->mSourceAction );
 712+ $template->set( 'wpSourceNS', $this->mSourceNS );
 713+ $template->set( 'wpSourceArticle', $this->msourceArticle );
717714
718715 if ( !self::getCreateaccountToken() ) {
719716 self::setCreateaccountToken();
@@ -730,7 +727,7 @@
731728 $wgAuth->modifyUITemplate( $template, $this->mType );
732729
733730 wfRunHooks( 'UserCreateForm', array( &$template ) );
734 - wfRunHooks( 'SignupForm' );
 731+ wfRunHooks( 'SignupForm' );
735732
736733 // Changes the title depending on permissions for creating account
737734 if ( $wgUser->isAllowed( 'createaccount' ) ) {
@@ -741,7 +738,7 @@
742739
743740 $wgOut->disallowUserJs(); // just in case...
744741 $wgOut->addTemplate( $template );
745 -
 742+
746743 }
747744
748745 /**
@@ -753,11 +750,11 @@
754751 */
755752 function showCreateOrLoginLink( &$tempUserser ) {
756753 if( $this->mType == 'signup' ) {
757 - return true;
 754+ return true;
758755 } elseif( $tempUserser->isAllowed( 'createaccount' ) ) {
759 - return true;
 756+ return true;
760757 } else {
761 - return false;
 758+ return false;
762759 }
763760 }
764761
@@ -906,17 +903,17 @@
907904 }
908905 }
909906
910 - private function addToSourceTracking( $tempUser ) {
911 - $sourcetracking_data = array(
912 - 'userid' => $tempUser->getId(),
913 - 'source_action' => $this->mSourceAction,
914 - 'source_ns' => $this->mSourceNS,
915 - 'source_article' => $this->msourceArticle
916 - );
 907+ private function addToSourceTracking( $tempUser ) {
 908+ $sourcetracking_data = array(
 909+ 'userid' => $tempUser->getId(),
 910+ 'source_action' => $this->mSourceAction,
 911+ 'source_ns' => $this->mSourceNS,
 912+ 'source_article' => $this->msourceArticle
 913+ );
917914
918 - $dbw = wfGetDB( DB_MASTER );
919 - $dbw->insert( 'sourcetracking', $sourcetracking_data );
 915+ $dbw = wfGetDB( DB_MASTER );
 916+ $dbw->insert( 'sourcetracking', $sourcetracking_data );
920917
921 - return true;
922 - }
 918+ return true;
 919+ }
923920 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95213removing old validateSignup fileakshay17:40, 22 August 2011

Status & tagging log