Index: trunk/extensions/SignupAPI/SignupAPI.i18n.php |
— | — | @@ -10,18 +10,18 @@ |
11 | 11 | |
12 | 12 | $messages['en'] = array( |
13 | 13 | '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', |
22 | 22 | |
23 | 23 | ); |
24 | 24 | |
25 | | -/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
| 25 | +/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
26 | 26 | * @author Wizardist |
27 | 27 | */ |
28 | 28 | $messages['be-tarask'] = array( |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | 'signupapi-passwordsmatch' => 'Die beiden Passwörter stimmen überein.', |
45 | 45 | ); |
46 | 46 | |
47 | | -/** German (formal address) (Deutsch (Sie-Form)) |
| 47 | +/** German (formal address) (Deutsch (Sie-Form)) |
48 | 48 | * @author Kghbln |
49 | 49 | */ |
50 | 50 | $messages['de-formal'] = array( |
Index: trunk/extensions/SignupAPI/SignupAPI.php |
— | — | @@ -17,147 +17,67 @@ |
18 | 18 | } |
19 | 19 | |
20 | 20 | $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', |
26 | 26 | 'descriptionmsg' => 'signupapi-desc', |
27 | 27 | ); |
28 | 28 | |
29 | | -global $wgSignupAPISourceTracking,$wgSignupAPIUseAjax; |
30 | 29 | $wgSignupAPIUseAjax = true; |
31 | 30 | $wgSignupAPISourceTracking = true; |
32 | 31 | |
| 32 | +# Includes |
| 33 | + |
33 | 34 | $dir = dirname(__FILE__); |
34 | 35 | $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'; |
40 | 37 | |
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'; |
44 | 42 | |
45 | | -$wgAutoloadClasses['ValidateSignup'] |
46 | | - = $wgMyExtensionIncludes . '/ValidateSignup.php'; |
47 | | - |
| 43 | +// Apis |
48 | 44 | $wgAPIModules['signup'] = 'ApiSignup'; |
| 45 | +$wgAutoloadClasses['ApiSignup'] = $dir . '/includes/ApiSignup.php'; |
49 | 46 | |
50 | | -$wgAPIModules['validatesignup'] = 'ValidateSignup'; |
| 47 | +$wgAPIModules['validatesignup'] = 'ApiValidateSignup'; |
| 48 | +$wgAutoloadClasses['ApiValidateSignup']= $dir . '/includes/ApiValidateSignup.php'; |
51 | 49 | |
52 | | -# Requires jquery.ui.progressbar for password strength validation |
53 | | -$wgResourceModules['ext.SignupAPI'] = array( |
| 50 | +# Modules |
54 | 51 | |
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' |
60 | 67 | ); |
61 | 68 | |
| 69 | +# Hooks |
62 | 70 | |
63 | | - |
64 | 71 | 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'; |
71 | 73 | } |
72 | 74 | |
73 | 75 | 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 | | - } |
83 | 76 | |
84 | | - # Add source tracking to personal URL's |
85 | | - $wgHooks['PersonalUrls'][] = 'addSourceTracking'; |
| 77 | + // Schema updates for update.php |
| 78 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'SignupAPIHooks::onSourceTracking'; |
86 | 79 | |
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'; |
162 | 82 | } |
163 | 83 | |
164 | 84 | |
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 |
1 | 134 | + 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 |
1 | 232 | + native |
Added: svn:keywords |
2 | 233 | + 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 @@ |
27 | 27 | * |
28 | 28 | * @ingroup SpecialPage |
29 | 29 | */ |
30 | | -class SignupForm extends SpecialPage { |
| 30 | +class SpecialUserSignup extends SpecialPage { |
31 | 31 | |
32 | 32 | const SUCCESS = 0; |
33 | 33 | const NO_NAME = 1; |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | const BLOCKED_BY_HOOK = 15; |
48 | 48 | const EXTR_DB_ERROR = 16; |
49 | 49 | const THROTLLED = 17; |
50 | | - const INIT_FAILED = 18; |
| 50 | + const INIT_FAILED = 18; |
51 | 51 | |
52 | 52 | //Initialise all variables to be used |
53 | 53 | var $tempUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | var $mType, $mReason, $mRealName; |
58 | 58 | var $abortError = ''; |
59 | 59 | var $tempUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation; |
60 | | - var $mSourceAction, $mSourceNS, $msourceArticle; |
| 60 | + var $mSourceAction, $mSourceNS, $msourceArticle; |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @var ExternalUser |
— | — | @@ -105,9 +105,9 @@ |
106 | 106 | $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' ); |
107 | 107 | $this->mToken = $request->getVal( 'wpCreateaccountToken' ); |
108 | 108 | |
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' ); |
112 | 112 | |
113 | 113 | if( $wgEnableEmail ) { |
114 | 114 | $this->mEmail = $request->getText( 'wpEmail' ); |
— | — | @@ -129,9 +129,6 @@ |
130 | 130 | |
131 | 131 | public function execute( $par ) { |
132 | 132 | |
133 | | - global $wgOut; |
134 | | - $wgOut->addModules( 'mediawiki.special.usersignup' ); |
135 | | - |
136 | 133 | if ( session_id() == '' ) { |
137 | 134 | wfSetupSession(); |
138 | 135 | } |
— | — | @@ -145,9 +142,9 @@ |
146 | 143 | return; |
147 | 144 | } elseif( $this->mPosted ) { |
148 | 145 | if( $this->mCreateaccount ) { |
149 | | - return $this->processSignup(); |
| 146 | + return $this->processSignup(); |
150 | 147 | } elseif ( $this->mCreateaccountMail ) { |
151 | | - return $this->addNewAccountMailPassword(); |
| 148 | + return $this->addNewAccountMailPassword(); |
152 | 149 | } |
153 | 150 | } |
154 | 151 | |
— | — | @@ -157,11 +154,11 @@ |
158 | 155 | /** |
159 | 156 | * @private |
160 | 157 | */ |
161 | | - //Used for mailing password reset request |
| 158 | + // Used for mailing password reset request |
162 | 159 | function addNewAccountMailPassword() { |
163 | 160 | global $wgOut; |
164 | 161 | |
165 | | - //check if no email id was provided |
| 162 | + // Check if no email id was provided |
166 | 163 | if ( $this->mEmail == '' ) { |
167 | 164 | $this->mainSignupForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mUsername ) ); |
168 | 165 | return; |
— | — | @@ -224,10 +221,10 @@ |
225 | 222 | return true; |
226 | 223 | } else { |
227 | 224 | $this->mRunCookieRedirect = true; |
228 | | - return true; |
| 225 | + return true; |
229 | 226 | } |
230 | 227 | } else { |
231 | | - $this->mRunCreationConfirmation = true; |
| 228 | + $this->mRunCreationConfirmation = true; |
232 | 229 | wfRunHooks( 'AddNewAccount', array( $tempUser, false ) ); |
233 | 230 | $tempUser->addNewUserLogEntry( false, $this->mReason ); |
234 | 231 | return true; |
— | — | @@ -270,7 +267,7 @@ |
271 | 268 | self::setCreateaccountToken(); |
272 | 269 | return self::NO_COOKIES; |
273 | 270 | } |
274 | | - |
| 271 | + |
275 | 272 | # The user didn't pass a createaccount token |
276 | 273 | if ( !$this->mToken ) { |
277 | 274 | return self::NEED_TOKEN; |
— | — | @@ -329,7 +326,7 @@ |
330 | 327 | # if email is provided then validate it |
331 | 328 | if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) { |
332 | 329 | return self::INVALID_EMAIL; |
333 | | - } |
| 330 | + } |
334 | 331 | |
335 | 332 | # Set some additional data so the AbortNewAccount hook can be used for |
336 | 333 | # more than just username validation |
— | — | @@ -361,12 +358,12 @@ |
362 | 359 | self::clearCreateaccountToken(); |
363 | 360 | |
364 | 361 | $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; |
371 | 368 | } |
372 | 369 | |
373 | 370 | /** |
— | — | @@ -408,7 +405,7 @@ |
409 | 406 | $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
410 | 407 | $ssUpdate->doUpdate(); |
411 | 408 | |
412 | | - $this->addToSourceTracking( $tempUser ); |
| 409 | + $this->addToSourceTracking( $tempUser ); |
413 | 410 | |
414 | 411 | return $tempUser; |
415 | 412 | } |
— | — | @@ -418,25 +415,25 @@ |
419 | 416 | |
420 | 417 | switch ( $this->addNewAccountInternal() ) { |
421 | 418 | 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 | + } |
429 | 426 | |
430 | | - if( $this->mRunCookieRedirect ) { |
431 | | - $this->cookieRedirectCheck( 'new' ); |
432 | | - } |
| 427 | + if( $this->mRunCookieRedirect ) { |
| 428 | + $this->cookieRedirectCheck( 'new' ); |
| 429 | + } |
433 | 430 | |
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 | + } |
441 | 438 | |
442 | 439 | $this->successfulCreation(); |
443 | 440 | break; |
— | — | @@ -519,8 +516,8 @@ |
520 | 517 | $this->mainSignupForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $wgAccountCreationThrottle ) ); |
521 | 518 | break; |
522 | 519 | |
523 | | - case self::INIT_FAILED: |
524 | | - $this->mainSignupForm( wfMsg( 'init_failed' ) ); |
| 520 | + case self::INIT_FAILED: |
| 521 | + $this->mainSignupForm( wfMsg( 'init_failed' ) ); |
525 | 522 | break; |
526 | 523 | |
527 | 524 | default: |
— | — | @@ -582,7 +579,7 @@ |
583 | 580 | |
584 | 581 | /** |
585 | 582 | * 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 |
587 | 584 | * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock' |
588 | 585 | * setting on blocks (bug 13611). |
589 | 586 | * @param $block Block the block causing this error |
— | — | @@ -710,9 +707,9 @@ |
711 | 708 | $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) ); |
712 | 709 | $template->set( 'stickHTTPS', $this->mStickHTTPS ); |
713 | 710 | |
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 ); |
717 | 714 | |
718 | 715 | if ( !self::getCreateaccountToken() ) { |
719 | 716 | self::setCreateaccountToken(); |
— | — | @@ -730,7 +727,7 @@ |
731 | 728 | $wgAuth->modifyUITemplate( $template, $this->mType ); |
732 | 729 | |
733 | 730 | wfRunHooks( 'UserCreateForm', array( &$template ) ); |
734 | | - wfRunHooks( 'SignupForm' ); |
| 731 | + wfRunHooks( 'SignupForm' ); |
735 | 732 | |
736 | 733 | // Changes the title depending on permissions for creating account |
737 | 734 | if ( $wgUser->isAllowed( 'createaccount' ) ) { |
— | — | @@ -741,7 +738,7 @@ |
742 | 739 | |
743 | 740 | $wgOut->disallowUserJs(); // just in case... |
744 | 741 | $wgOut->addTemplate( $template ); |
745 | | - |
| 742 | + |
746 | 743 | } |
747 | 744 | |
748 | 745 | /** |
— | — | @@ -753,11 +750,11 @@ |
754 | 751 | */ |
755 | 752 | function showCreateOrLoginLink( &$tempUserser ) { |
756 | 753 | if( $this->mType == 'signup' ) { |
757 | | - return true; |
| 754 | + return true; |
758 | 755 | } elseif( $tempUserser->isAllowed( 'createaccount' ) ) { |
759 | | - return true; |
| 756 | + return true; |
760 | 757 | } else { |
761 | | - return false; |
| 758 | + return false; |
762 | 759 | } |
763 | 760 | } |
764 | 761 | |
— | — | @@ -906,17 +903,17 @@ |
907 | 904 | } |
908 | 905 | } |
909 | 906 | |
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 | + ); |
917 | 914 | |
918 | | - $dbw = wfGetDB( DB_MASTER ); |
919 | | - $dbw->insert( 'sourcetracking', $sourcetracking_data ); |
| 915 | + $dbw = wfGetDB( DB_MASTER ); |
| 916 | + $dbw->insert( 'sourcetracking', $sourcetracking_data ); |
920 | 917 | |
921 | | - return true; |
922 | | - } |
| 918 | + return true; |
| 919 | + } |
923 | 920 | } |