Index: trunk/extensions/SemanticSignup/SemanticSignup.php |
— | — | @@ -70,11 +70,5 @@ |
71 | 71 | |
72 | 72 | $egSemanticSignupSettings = array(); |
73 | 73 | |
74 | | -$wgExtensionFunctions[] = 'efSemanticSignupSetup'; |
75 | | - |
76 | | -function efSemanticSignupSetup() { |
77 | | - if ( !is_null( Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ) ) ) { |
78 | | - $wgHooks['UserCreateForm'][] = 'SemanticSignupHooks::onUserCreateForm'; |
79 | | - $wgHooks['ParserFirstCallInit'][] = 'SemanticSignupHooks::onParserFirstCallInit'; |
80 | | - } |
81 | | -} |
| 74 | +$wgHooks['UserCreateForm'][] = 'SemanticSignupHooks::onUserCreateForm'; |
| 75 | +$wgHooks['ParserFirstCallInit'][] = 'SemanticSignupHooks::onParserFirstCallInit'; |
Index: trunk/extensions/SemanticSignup/SemanticSignup.hooks.php |
— | — | @@ -21,9 +21,12 @@ |
22 | 22 | * @return false |
23 | 23 | */ |
24 | 24 | public static function onUserCreateForm( $template ) { |
| 25 | + if ( is_null( Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ) ) ) { |
| 26 | + return true; |
| 27 | + } |
| 28 | + |
25 | 29 | $semantic_signup_title = SemanticSignup::getTitleFor( 'SemanticSignup' ); |
26 | 30 | $url = $semantic_signup_title->escapeFullURL(); |
27 | | - |
28 | 31 | global $wgOut; |
29 | 32 | $wgOut->redirect( $url ); |
30 | 33 | |
— | — | @@ -37,7 +40,7 @@ |
38 | 41 | */ |
39 | 42 | public static function onParserFirstCallInit() { |
40 | 43 | global $wgParser; |
41 | | - $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' ); |
| 44 | +// $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' ); |
42 | 45 | return true; |
43 | 46 | } |
44 | 47 | |
Index: trunk/extensions/SemanticSignup/includes/SES_Special.php |
— | — | @@ -1,27 +1,26 @@ |
2 | 2 | <?php |
3 | | -/* |
| 3 | + |
| 4 | +/** |
4 | 5 | * Created on 7 Jan 2008 by Serhii Kutnii |
5 | | - * |
6 | 6 | */ |
7 | | - |
8 | | - class SES_UserAccountDataChecker extends SES_DataChecker |
9 | | - { |
10 | | - public $mUsername = ''; |
11 | | - public $mPassword = ''; |
12 | | - public $mEmail = ''; |
13 | | - public $mRealname = ''; |
14 | | - public $mDomain = ''; |
15 | | - public $mLanguage = ''; |
16 | | - public $mRemember = false; |
17 | | - public $mUser = null; |
18 | | - |
19 | | - protected function populateData() |
20 | | - { |
21 | | - $this->mUsername = $this->getUserDataValue('wpName', 'nousername'); |
22 | | - $name = trim($this->mUsername); |
23 | | - $this->mUser = User::newFromName($name, 'creatable'); |
24 | | - if (!$this->mUser) |
25 | | - $this->error(wfMsg('noname')); |
| 7 | +class SES_UserAccountDataChecker extends SES_DataChecker { |
| 8 | + |
| 9 | + public $mUsername = ''; |
| 10 | + public $mPassword = ''; |
| 11 | + public $mEmail = ''; |
| 12 | + public $mRealname = ''; |
| 13 | + public $mDomain = ''; |
| 14 | + public $mLanguage = ''; |
| 15 | + public $mRemember = false; |
| 16 | + public $mUser = null; |
| 17 | + |
| 18 | + protected function populateData() { |
| 19 | + $this->mUsername = $this->getUserDataValue( 'wpName', 'nousername' ); |
| 20 | + $name = trim( $this->mUsername ); |
| 21 | + $this->mUser = User::newFromName( $name, 'creatable' ); |
| 22 | + if ( !$this->mUser ) { |
| 23 | + $this->error( wfMsg( 'noname' ) ); |
| 24 | + } |
26 | 25 | |
27 | 26 | global $sesRealNameRequired; |
28 | 27 | $this->mRealname = $this->getUserDataValue('wpRealName', $sesRealNameRequired ? 'norealname' : null); |
— | — | @@ -40,95 +39,95 @@ |
41 | 40 | |
42 | 41 | global $wgRequest; |
43 | 42 | $this->mRemember = $wgRequest->getCheck('wpRemember'); |
44 | | - } |
45 | | - |
46 | | - //Checks |
47 | | - |
48 | | - public function checkDomainValidity() |
49 | | - { |
50 | | - global $wgAuth; |
51 | | - |
52 | | - if( !$wgAuth->validDomain( $this->mDomain ) ) |
| 43 | + } |
| 44 | + |
| 45 | + //Checks |
| 46 | + |
| 47 | + public function checkDomainValidity() |
| 48 | + { |
| 49 | + global $wgAuth; |
| 50 | + |
| 51 | + if( !$wgAuth->validDomain( $this->mDomain ) ) |
53 | 52 | $this->error(wfMsg('wrongpassword')); |
54 | | - } |
55 | | - |
56 | | - public function checkDomainUser() |
57 | | - { |
58 | | - global $wgAuth; |
| 53 | + } |
| 54 | + |
| 55 | + public function checkDomainUser() |
| 56 | + { |
| 57 | + global $wgAuth; |
59 | 58 | |
60 | | - if( ('local' != $this->mDomain) && ('' != $this->mDomain) |
61 | | - && !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists($this->mName) || !$wgAuth->authenticate($this->mName, $this->mPassword) ) ) |
62 | | - $this->error(wfMsg('wrongpassword')); |
63 | | - } |
64 | | - |
65 | | - public function checkCreatePermissions() |
66 | | - { |
67 | | - global $wgUser; |
68 | | - |
69 | | - if (!$wgUser->isAllowed( 'createaccount' ) || $wgUser->isBlockedFromCreateAccount() ) |
70 | | - $this->error(wfMsg('createforbidden')); |
71 | | - } |
72 | | - |
73 | | - public function checkSorbs() |
74 | | - { |
75 | | - global $wgProxyWhitelist; |
76 | | - global $wgEnableSorbs; |
77 | | - $ip = wfGetIP(); |
| 59 | + if( ('local' != $this->mDomain) && ('' != $this->mDomain) |
| 60 | + && !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists($this->mName) || !$wgAuth->authenticate($this->mName, $this->mPassword) ) ) |
| 61 | + $this->error(wfMsg('wrongpassword')); |
| 62 | + } |
| 63 | + |
| 64 | + public function checkCreatePermissions() |
| 65 | + { |
| 66 | + global $wgUser; |
| 67 | + |
| 68 | + if (!$wgUser->isAllowed( 'createaccount' ) || $wgUser->isBlockedFromCreateAccount() ) |
| 69 | + $this->error(wfMsg('createforbidden')); |
| 70 | + } |
| 71 | + |
| 72 | + public function checkSorbs() |
| 73 | + { |
| 74 | + global $wgProxyWhitelist; |
| 75 | + global $wgEnableSorbs; |
| 76 | + $ip = wfGetIP(); |
78 | 77 | if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && |
79 | 78 | $wgUser->inSorbsBlacklist( $ip ) ) |
80 | | - $this->error(wfMsg('sorbs_create_account_reason')); |
81 | | - } |
82 | | - |
83 | | - public function checkUserExists() |
84 | | - { |
| 79 | + $this->error(wfMsg('sorbs_create_account_reason')); |
| 80 | + } |
| 81 | + |
| 82 | + public function checkUserExists() |
| 83 | + { |
85 | 84 | if ($this->mUser->idForName()) |
86 | 85 | $this->error(wfMsg('userexists')); |
87 | | - } |
88 | | - |
89 | | - public function checkPasswordLength() |
90 | | - { |
| 86 | + } |
| 87 | + |
| 88 | + public function checkPasswordLength() |
| 89 | + { |
91 | 90 | if (!$this->mUser->isValidPassword($this->mPassword)) |
92 | 91 | { |
93 | 92 | global $wgMinimalPasswordLength; |
94 | 93 | $this->error(wfMsgExt('passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength)); |
95 | 94 | } |
96 | | - } |
97 | | - |
98 | | - public function checkEmailValidity() |
99 | | - { |
100 | | - global $wgEnableEmail; |
| 95 | + } |
| 96 | + |
| 97 | + public function checkEmailValidity() |
| 98 | + { |
| 99 | + global $wgEnableEmail; |
101 | 100 | if ($wgEnableEmail && !User::isValidEmailAddr($this->mEmail)) |
102 | 101 | $this->error(wfMsg('invalidemailaddress')); |
103 | | - } |
104 | | - |
105 | | - public function __construct() |
106 | | - { |
107 | | - $this->addCheck(array(&$this, 'checkDomainValidity'), array()); |
108 | | - $this->addCheck(array(&$this, 'checkDomainUser'), array()); |
109 | | - $this->addCheck(array(&$this, 'checkCreatePermissions'), array()); |
110 | | - $this->addCheck(array(&$this, 'checkSorbs'), array()); |
111 | | - $this->addCheck(array(&$this, 'checkUserExists'), array()); |
112 | | - $this->addCheck(array(&$this, 'checkPasswordLength'), array()); |
113 | | - $this->addCheck(array(&$this, 'checkEmailValidity'), array()); |
114 | | - } |
| 102 | + } |
| 103 | + |
| 104 | + public function __construct() |
| 105 | + { |
| 106 | + $this->addCheck(array(&$this, 'checkDomainValidity'), array()); |
| 107 | + $this->addCheck(array(&$this, 'checkDomainUser'), array()); |
| 108 | + $this->addCheck(array(&$this, 'checkCreatePermissions'), array()); |
| 109 | + $this->addCheck(array(&$this, 'checkSorbs'), array()); |
| 110 | + $this->addCheck(array(&$this, 'checkUserExists'), array()); |
| 111 | + $this->addCheck(array(&$this, 'checkPasswordLength'), array()); |
| 112 | + $this->addCheck(array(&$this, 'checkEmailValidity'), array()); |
| 113 | + } |
115 | 114 | } |
116 | 115 | |
117 | 116 | class SemanticSignup extends SpecialPage |
118 | 117 | { |
119 | | - private $mUserDataChecker = null; |
120 | | - private $mUserPageUrl = ''; |
121 | | - |
122 | | - public function __construct() |
123 | | - { |
124 | | - parent::__construct('SemanticSignup'); |
125 | | - $this->mIncludable = false; |
| 118 | + private $mUserDataChecker = null; |
| 119 | + private $mUserPageUrl = ''; |
| 120 | + |
| 121 | + public function __construct() |
| 122 | + { |
| 123 | + parent::__construct('SemanticSignup'); |
| 124 | + $this->mIncludable = false; |
126 | 125 | |
127 | | - $this->mUserDataChecker = new SES_UserAccountDataChecker(); |
128 | | - } |
129 | | - |
130 | | - private function userSignup() |
131 | | - { |
132 | | - //Get user input and check the environment |
| 126 | + $this->mUserDataChecker = new SES_UserAccountDataChecker(); |
| 127 | + } |
| 128 | + |
| 129 | + private function userSignup() |
| 130 | + { |
| 131 | + //Get user input and check the environment |
133 | 132 | $this->mUserDataChecker->run(); |
134 | 133 | |
135 | 134 | //Throw if data getting or environment checks have failed which indicates that account creation is impossible |
— | — | @@ -150,7 +149,7 @@ |
151 | 150 | } |
152 | 151 | |
153 | 152 | global $wgAccountCreationThrottle; |
154 | | - global $wgUser; |
| 153 | + global $wgUser; |
155 | 154 | if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) |
156 | 155 | { |
157 | 156 | $key = wfMemcKey( 'acctcreate', 'ip', wfGetIP() ); |
— | — | @@ -192,40 +191,40 @@ |
193 | 192 | $language = $this->mUserDataChecker->mLanguage; |
194 | 193 | if( $wgLoginLanguageSelector && $language ) |
195 | 194 | $user->setOption( 'language', $language ); |
196 | | - |
197 | | - global $wgEmailAuthentication; |
198 | | - if( $wgEmailAuthentication && User::isValidEmailAddr( $user->getEmail() ) ){ |
199 | | - $err = $user->sendConfirmationMail(); |
200 | | - if (WikiError::isError($err)) |
201 | | - throw new Exception(wfMsg('emailfailed')); |
202 | | - } |
203 | | - |
204 | | - $user->saveSettings(); |
205 | | - wfRunHooks('AddNewAccount', array($user)); |
206 | | - } |
207 | | - |
208 | | - private function createUserPage() { |
209 | | - $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ); |
210 | | - $form = new Article($form_title); |
211 | | - $form_definition = $form->getContent(); |
212 | | - |
213 | | - $page_title = Title::newFromText($this->mUserDataChecker->mUser->getName(), NS_USER); |
214 | | - $this->mUserPageUrl = $page_title->escapeFullUrl(); |
| 195 | + |
| 196 | + global $wgEmailAuthentication; |
| 197 | + if( $wgEmailAuthentication && User::isValidEmailAddr( $user->getEmail() ) ){ |
| 198 | + $err = $user->sendConfirmationMail(); |
| 199 | + if (WikiError::isError($err)) |
| 200 | + throw new Exception(wfMsg('emailfailed')); |
| 201 | + } |
| 202 | + |
| 203 | + $user->saveSettings(); |
| 204 | + wfRunHooks('AddNewAccount', array($user)); |
| 205 | + } |
| 206 | + |
| 207 | + private function createUserPage() { |
| 208 | + $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ); |
| 209 | + $form = new Article($form_title); |
| 210 | + $form_definition = $form->getContent(); |
| 211 | + |
| 212 | + $page_title = Title::newFromText($this->mUserDataChecker->mUser->getName(), NS_USER); |
| 213 | + $this->mUserPageUrl = $page_title->escapeFullUrl(); |
215 | 214 | |
216 | | - global $sfgFormPrinter; |
217 | | - list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
218 | | - $sfgFormPrinter->formHTML($form_definition, true, false); |
| 215 | + global $sfgFormPrinter; |
| 216 | + list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
| 217 | + $sfgFormPrinter->formHTML($form_definition, true, false); |
219 | 218 | |
220 | | - $user_page = new Article($page_title); |
221 | | - |
222 | | - global $wgUser; |
223 | | - $wgUser = $this->mUserDataChecker->mUser; |
224 | | - $user_page->doEdit( $data_text, '', EDIT_FORCE_BOT ); |
225 | | - } |
| 219 | + $user_page = new Article($page_title); |
| 220 | + |
| 221 | + global $wgUser; |
| 222 | + $wgUser = $this->mUserDataChecker->mUser; |
| 223 | + $user_page->doEdit( $data_text, '', EDIT_FORCE_BOT ); |
| 224 | + } |
226 | 225 | |
227 | | - private function printForm() { |
228 | | - global $sesSignupBotName; |
229 | | - global $wgUser; |
| 226 | + private function printForm() { |
| 227 | + global $sesSignupBotName; |
| 228 | + global $wgUser; |
230 | 229 | |
231 | 230 | /* |
232 | 231 | * SemanticForms disable the form automatically if current user hasn't got edit rights |
— | — | @@ -233,27 +232,27 @@ |
234 | 233 | * the $old_user variable to be restored afterwards |
235 | 234 | */ |
236 | 235 | $old_user = null; |
237 | | - if ($wgUser->isAnon()) |
| 236 | + if ($wgUser->isAnon()) |
238 | 237 | { |
239 | | - $old_user = $wgUser; |
240 | | - $wgUser = User::newFromName($sesSignupBotName); |
| 238 | + $old_user = $wgUser; |
| 239 | + $wgUser = User::newFromName($sesSignupBotName); |
241 | 240 | } |
242 | 241 | |
243 | | - $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ); |
244 | | - $form = new Article($form_title); |
245 | | - $form_definition = $form->getContent(); |
246 | | - |
247 | | - global $sfgFormPrinter; |
248 | | - list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
249 | | - $sfgFormPrinter->formHTML($form_definition, false, false); |
250 | | - |
| 242 | + $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ); |
| 243 | + $form = new Article($form_title); |
| 244 | + $form_definition = $form->getContent(); |
| 245 | + |
| 246 | + global $sfgFormPrinter; |
| 247 | + list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
| 248 | + $sfgFormPrinter->formHTML($form_definition, false, false); |
| 249 | + |
251 | 250 | $text =<<<END |
252 | 251 | <form name="createbox" onsubmit="return validate_all()" action="" method="post" class="createbox"> |
253 | 252 | END; |
254 | | - $text .= $form_text.'</form>'; |
255 | | - |
256 | | - global $sfgScriptPath, $sfgYUIBase, $wgOut; |
257 | | - $mainCssUrl = $sfgScriptPath . '/skins/SF_main.css'; |
| 253 | + $text .= $form_text.'</form>'; |
| 254 | + |
| 255 | + global $sfgScriptPath, $sfgYUIBase, $wgOut; |
| 256 | + $mainCssUrl = $sfgScriptPath . '/skins/SF_main.css'; |
258 | 257 | $wgOut->addLink( array( |
259 | 258 | 'rel' => 'stylesheet', |
260 | 259 | 'type' => 'text/css', |
— | — | @@ -300,46 +299,36 @@ |
301 | 300 | //Restoring the current user |
302 | 301 | if ($old_user) |
303 | 302 | $wgUser = $old_user; |
304 | | - } |
305 | | - |
306 | | - private function executeOnSubmit() |
307 | | - { |
308 | | - global $wgOut; |
309 | | - |
310 | | - try |
311 | | - { |
312 | | - $this->userSignup(); |
313 | | - $this->createUserPage(); |
314 | | - |
315 | | - $wgOut->redirect($this->mUserPageUrl); |
316 | | - } |
317 | | - catch (Exception $e) |
318 | | - { |
319 | | - $wgOut->addHTML('<div class="error">'.$e->getMessage().'</div>'); |
320 | | - $this->printForm(); |
321 | | - } |
322 | | - |
323 | | - return true; |
324 | | - } |
325 | | - |
326 | | - private function executeOnGetPage() |
327 | | - { |
328 | | - $this->printForm(); |
329 | | - return true; |
330 | | - } |
331 | | - |
332 | | - public function execute($par) |
333 | | - { |
334 | | - global $wgRequest, $wgOut; |
335 | | - |
| 303 | + } |
| 304 | + |
| 305 | + private function executeOnSubmit() { |
| 306 | + global $wgOut; |
| 307 | + |
| 308 | + try { |
| 309 | + $this->userSignup(); |
| 310 | + $this->createUserPage(); |
| 311 | + |
| 312 | + $wgOut->redirect( $this->mUserPageUrl ); |
| 313 | + } |
| 314 | + catch ( Exception $e ) { |
| 315 | + $wgOut->addHTML( '<div class="error">' . $e->getMessage() . '</div>' ); |
| 316 | + $this->printForm(); |
| 317 | + } |
| 318 | + |
| 319 | + return true; |
| 320 | + } |
| 321 | + |
| 322 | + public function execute( $par ) { |
| 323 | + global $wgRequest, $wgOut; |
| 324 | + |
336 | 325 | $this->setHeaders(); |
337 | 326 | |
338 | | - $form_submitted = $wgRequest->getCheck('wpSave'); |
339 | | - if ($form_submitted) |
340 | | - { |
| 327 | + if ( $wgRequest->getCheck( 'wpSave' ) ) { |
341 | 328 | return $this->executeOnSubmit(); |
342 | 329 | } else { |
343 | | - return $this->executeOnGetPage(); |
| 330 | + $this->printForm(); |
| 331 | + return true; |
344 | 332 | } |
345 | | - } |
346 | | - } |
\ No newline at end of file |
| 333 | + } |
| 334 | +} |
| 335 | + |
\ No newline at end of file |