Index: trunk/extensions/SemanticSignup/SemanticSignup.php |
— | — | @@ -62,7 +62,8 @@ |
63 | 63 | $wgAutoloadClasses['SemanticSignupHooks'] = dirname( __FILE__ ) . '/SemanticSignup.hooks.php'; |
64 | 64 | $wgAutoloadClasses['SemanticSignup'] = dirname( __FILE__ ) . '/includes/SES_Special.php'; |
65 | 65 | $wgAutoloadClasses['SES_UserAccountDataChecker'] = dirname( __FILE__ ) . '/includes/SES_Special.php'; |
66 | | -$wgAutoloadClasses['SES_DataChecker'] = dirname( __FILE__ ) . '/includes/SES_Utils.php'; |
| 66 | +$wgAutoloadClasses['SES_DataChecker'] = dirname( __FILE__ ) . '/includes/SES_DataChecker.php'; |
| 67 | +$wgAutoloadClasses['SES_UserAccountDataChecker'] = dirname( __FILE__ ) . '/includes/SES_UserAccountDataChecker.php'; |
67 | 68 | $wgAutoloadClasses['SES_SignupFields'] = dirname( __FILE__ ) . '/includes/SES_SignupFields.php'; |
68 | 69 | $wgAutoloadClasses['CreateUserFieldsTemplate'] = dirname( __FILE__ ) . '/includes/SES_SignupFields.php'; |
69 | 70 | |
Index: trunk/extensions/SemanticSignup/SemanticSignup.hooks.php |
— | — | @@ -25,8 +25,7 @@ |
26 | 26 | return true; |
27 | 27 | } |
28 | 28 | |
29 | | - $semantic_signup_title = SemanticSignup::getTitleFor( 'SemanticSignup' ); |
30 | | - $url = $semantic_signup_title->escapeFullURL(); |
| 29 | + $url = SemanticSignup::getTitleFor( 'SemanticSignup' )->escapeFullURL(); |
31 | 30 | global $wgOut; |
32 | 31 | $wgOut->redirect( $url ); |
33 | 32 | |
— | — | @@ -40,7 +39,7 @@ |
41 | 40 | */ |
42 | 41 | public static function onParserFirstCallInit() { |
43 | 42 | global $wgParser; |
44 | | -// $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' ); |
| 43 | + $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' ); |
45 | 44 | return true; |
46 | 45 | } |
47 | 46 | |
Index: trunk/extensions/SemanticSignup/includes/SES_Utils.php |
— | — | @@ -1,72 +0,0 @@ |
2 | | -<?php |
3 | | -/* |
4 | | - * Created on 13 Jan 2009 by Serhii Kutnii |
5 | | - */ |
6 | | - |
7 | | -/* |
8 | | - * An abstract data getter and checker class. |
9 | | - * Its concrete subclasses should incapsulate all the necessary data getting |
10 | | - * and environment checks. |
11 | | - */ |
12 | | -abstract class SES_DataChecker |
13 | | -{ |
14 | | - private $mError = null; |
15 | | - |
16 | | - public function getError() |
17 | | - { |
18 | | - return $this->mError; |
19 | | - } |
20 | | - |
21 | | - /* |
22 | | - * Get a value from the request. |
23 | | - * $err_message_id specifies an error that should be thrown |
24 | | - * if the value is empty |
25 | | - */ |
26 | | - protected function getUserDataValue($id, $err_message_id = null) |
27 | | - { |
28 | | - global $wgRequest; |
29 | | - $value = $wgRequest->getText($id); |
30 | | - |
31 | | - if ($err_message_id && !$value) |
32 | | - $this->error(wfMsg($err_message_id)); |
33 | | - |
34 | | - return $value; |
35 | | - } |
36 | | - |
37 | | - //Checks |
38 | | - private $mEnvCheckCalls = array(); |
39 | | - |
40 | | - protected function addCheck($method_callback, array $args) |
41 | | - { |
42 | | - $this->mEnvCheckCalls[] = array($method_callback, $args); |
43 | | - } |
44 | | - |
45 | | - protected function runChecks() |
46 | | - { |
47 | | - foreach ($this->mEnvCheckCalls as $call_array) |
48 | | - { |
49 | | - call_user_func_array($call_array[0], $call_array[1]); |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - //Abstracting error calls in order to make this functionality changeable in subclasses |
54 | | - protected function error($message) |
55 | | - { |
56 | | - throw new Exception($message); |
57 | | - } |
58 | | - |
59 | | - abstract protected function populateData(); |
60 | | - |
61 | | - public function run() |
62 | | - { |
63 | | - try |
64 | | - { |
65 | | - $this->populateData(); |
66 | | - $this->runChecks(); |
67 | | - } |
68 | | - catch (Exception $e) |
69 | | - { |
70 | | - $this->mError = $e->getMessage(); |
71 | | - } |
72 | | - } |
73 | | -} |
Index: trunk/extensions/SemanticSignup/includes/SES_Special.php |
— | — | @@ -1,132 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/** |
5 | | - * Created on 7 Jan 2008 by Serhii Kutnii |
6 | | - */ |
7 | | -class SES_UserAccountDataChecker extends SES_DataChecker { |
| 4 | +class SemanticSignup extends SpecialPage { |
8 | 5 | |
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 | | - } |
25 | | - |
26 | | - global $sesRealNameRequired; |
27 | | - $this->mRealname = $this->getUserDataValue('wpRealName', $sesRealNameRequired ? 'norealname' : null); |
28 | | - |
29 | | - $this->mPassword = $this->getUserDataValue('wpPassword'); |
30 | | - $retype = $this->getUserDataValue('wpRetype'); |
31 | | - if (strcmp($this->mPassword, $retype)) |
32 | | - $this->error(wfMsg('nopwdmatch')); |
33 | | - |
34 | | - $this->mDomain = $this->getUserDataValue('wpDomain'); |
35 | | - |
36 | | - global $wgEmailConfirmToEdit; |
37 | | - $this->mEmail = $this->getUserDataValue('wpEmail', $wgEmailConfirmToEdit ? 'noemailtitle' : null ); |
38 | | - |
39 | | - $this->mLanguage = $this->getUserDataValue('uselang'); |
40 | | - |
41 | | - global $wgRequest; |
42 | | - $this->mRemember = $wgRequest->getCheck('wpRemember'); |
43 | | - } |
44 | | - |
45 | | - //Checks |
46 | | - |
47 | | - public function checkDomainValidity() |
48 | | - { |
49 | | - global $wgAuth; |
50 | | - |
51 | | - if( !$wgAuth->validDomain( $this->mDomain ) ) |
52 | | - $this->error(wfMsg('wrongpassword')); |
53 | | - } |
54 | | - |
55 | | - public function checkDomainUser() |
56 | | - { |
57 | | - global $wgAuth; |
58 | | - |
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(); |
77 | | - if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && |
78 | | - $wgUser->inSorbsBlacklist( $ip ) ) |
79 | | - $this->error(wfMsg('sorbs_create_account_reason')); |
80 | | - } |
81 | | - |
82 | | - public function checkUserExists() |
83 | | - { |
84 | | - if ($this->mUser->idForName()) |
85 | | - $this->error(wfMsg('userexists')); |
86 | | - } |
87 | | - |
88 | | - public function checkPasswordLength() |
89 | | - { |
90 | | - if (!$this->mUser->isValidPassword($this->mPassword)) |
91 | | - { |
92 | | - global $wgMinimalPasswordLength; |
93 | | - $this->error(wfMsgExt('passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength)); |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - public function checkEmailValidity() |
98 | | - { |
99 | | - global $wgEnableEmail; |
100 | | - if ($wgEnableEmail && !User::isValidEmailAddr($this->mEmail)) |
101 | | - $this->error(wfMsg('invalidemailaddress')); |
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 | | - } |
114 | | - } |
115 | | - |
116 | | - class SemanticSignup extends SpecialPage |
117 | | - { |
118 | 6 | private $mUserDataChecker = null; |
119 | 7 | private $mUserPageUrl = ''; |
120 | 8 | |
121 | | - public function __construct() |
122 | | - { |
| 9 | + public function __construct() { |
123 | 10 | parent::__construct('SemanticSignup'); |
124 | 11 | $this->mIncludable = false; |
125 | 12 | |
126 | 13 | $this->mUserDataChecker = new SES_UserAccountDataChecker(); |
127 | 14 | } |
128 | 15 | |
129 | | - private function userSignup() |
130 | | - { |
| 16 | + private function userSignup() { |
131 | 17 | //Get user input and check the environment |
132 | 18 | $this->mUserDataChecker->run(); |
133 | 19 | |
— | — | @@ -208,22 +94,22 @@ |
209 | 95 | $form = new Article($form_title); |
210 | 96 | $form_definition = $form->getContent(); |
211 | 97 | |
212 | | - $page_title = Title::newFromText($this->mUserDataChecker->mUser->getName(), NS_USER); |
| 98 | + $page_title = Title::newFromText( $this->mUserDataChecker->mUser->getName(), NS_USER ); |
213 | 99 | $this->mUserPageUrl = $page_title->escapeFullUrl(); |
214 | 100 | |
215 | 101 | global $sfgFormPrinter; |
216 | 102 | list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
217 | 103 | $sfgFormPrinter->formHTML($form_definition, true, false); |
218 | 104 | |
219 | | - $user_page = new Article($page_title); |
| 105 | + $user_page = new Article( $page_title ); |
220 | 106 | |
221 | 107 | global $wgUser; |
222 | 108 | $wgUser = $this->mUserDataChecker->mUser; |
| 109 | + // TODO: doEdit removed; use internal API call |
223 | 110 | $user_page->doEdit( $data_text, '', EDIT_FORCE_BOT ); |
224 | 111 | } |
225 | 112 | |
226 | 113 | private function printForm() { |
227 | | - global $sesSignupBotName; |
228 | 114 | global $wgUser; |
229 | 115 | |
230 | 116 | /* |
— | — | @@ -232,10 +118,9 @@ |
233 | 119 | * the $old_user variable to be restored afterwards |
234 | 120 | */ |
235 | 121 | $old_user = null; |
236 | | - if ($wgUser->isAnon()) |
237 | | - { |
| 122 | + if ( $wgUser->isAnon() ) { |
238 | 123 | $old_user = $wgUser; |
239 | | - $wgUser = User::newFromName($sesSignupBotName); |
| 124 | + $wgUser = User::newFromName( SemanticSignupSettings::get( 'botName' ) ); |
240 | 125 | } |
241 | 126 | |
242 | 127 | $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ); |
— | — | @@ -243,6 +128,7 @@ |
244 | 129 | $form_definition = $form->getContent(); |
245 | 130 | |
246 | 131 | global $sfgFormPrinter; |
| 132 | + //var_dump($sfgFormPrinter);exit; |
247 | 133 | list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
248 | 134 | $sfgFormPrinter->formHTML($form_definition, false, false); |
249 | 135 | |
— | — | @@ -277,6 +163,8 @@ |
278 | 164 | 'media' => "screen, projection", |
279 | 165 | 'href' => $sfgScriptPath . '/skins/floatbox.css' |
280 | 166 | )); |
| 167 | + |
| 168 | + // FIXME: wtf? |
281 | 169 | $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'yahoo/yahoo-min.js"></script>' . "\n"); |
282 | 170 | $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'dom/dom-min.js"></script>' . "\n"); |
283 | 171 | $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'event/event-min.js"></script>' . "\n"); |
Index: trunk/extensions/SemanticSignup/includes/SES_UserAccountDataChecker.php |
— | — | @@ -0,0 +1,113 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Created on 7 Jan 2008 by Serhii Kutnii |
| 6 | + */ |
| 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 | + } |
| 25 | + |
| 26 | + global $sesRealNameRequired; |
| 27 | + $this->mRealname = $this->getUserDataValue('wpRealName', $sesRealNameRequired ? 'norealname' : null); |
| 28 | + |
| 29 | + $this->mPassword = $this->getUserDataValue('wpPassword'); |
| 30 | + $retype = $this->getUserDataValue('wpRetype'); |
| 31 | + if (strcmp($this->mPassword, $retype)) |
| 32 | + $this->error(wfMsg('nopwdmatch')); |
| 33 | + |
| 34 | + $this->mDomain = $this->getUserDataValue('wpDomain'); |
| 35 | + |
| 36 | + global $wgEmailConfirmToEdit; |
| 37 | + $this->mEmail = $this->getUserDataValue('wpEmail', $wgEmailConfirmToEdit ? 'noemailtitle' : null ); |
| 38 | + |
| 39 | + $this->mLanguage = $this->getUserDataValue('uselang'); |
| 40 | + |
| 41 | + global $wgRequest; |
| 42 | + $this->mRemember = $wgRequest->getCheck('wpRemember'); |
| 43 | + } |
| 44 | + |
| 45 | + //Checks |
| 46 | + |
| 47 | + public function checkDomainValidity() |
| 48 | + { |
| 49 | + global $wgAuth; |
| 50 | + |
| 51 | + if( !$wgAuth->validDomain( $this->mDomain ) ) |
| 52 | + $this->error(wfMsg('wrongpassword')); |
| 53 | + } |
| 54 | + |
| 55 | + public function checkDomainUser() |
| 56 | + { |
| 57 | + global $wgAuth; |
| 58 | + |
| 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(); |
| 77 | + if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && |
| 78 | + $wgUser->inSorbsBlacklist( $ip ) ) |
| 79 | + $this->error(wfMsg('sorbs_create_account_reason')); |
| 80 | + } |
| 81 | + |
| 82 | + public function checkUserExists() |
| 83 | + { |
| 84 | + if ($this->mUser->idForName()) |
| 85 | + $this->error(wfMsg('userexists')); |
| 86 | + } |
| 87 | + |
| 88 | + public function checkPasswordLength() |
| 89 | + { |
| 90 | + if (!$this->mUser->isValidPassword($this->mPassword)) |
| 91 | + { |
| 92 | + global $wgMinimalPasswordLength; |
| 93 | + $this->error(wfMsgExt('passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength)); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public function checkEmailValidity() |
| 98 | + { |
| 99 | + global $wgEnableEmail; |
| 100 | + if ($wgEnableEmail && !User::isValidEmailAddr($this->mEmail)) |
| 101 | + $this->error(wfMsg('invalidemailaddress')); |
| 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 | + } |
| 114 | + } |
Property changes on: trunk/extensions/SemanticSignup/includes/SES_UserAccountDataChecker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 115 | + native |
Index: trunk/extensions/SemanticSignup/includes/SES_DataChecker.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Created on 13 Jan 2009 by Serhii Kutnii |
| 5 | + */ |
| 6 | + |
| 7 | +/* |
| 8 | + * An abstract data getter and checker class. |
| 9 | + * Its concrete subclasses should incapsulate all the necessary data getting |
| 10 | + * and environment checks. |
| 11 | + */ |
| 12 | +abstract class SES_DataChecker |
| 13 | +{ |
| 14 | + private $mError = null; |
| 15 | + |
| 16 | + public function getError() |
| 17 | + { |
| 18 | + return $this->mError; |
| 19 | + } |
| 20 | + |
| 21 | + /* |
| 22 | + * Get a value from the request. |
| 23 | + * $err_message_id specifies an error that should be thrown |
| 24 | + * if the value is empty |
| 25 | + */ |
| 26 | + protected function getUserDataValue($id, $err_message_id = null) |
| 27 | + { |
| 28 | + global $wgRequest; |
| 29 | + $value = $wgRequest->getText($id); |
| 30 | + |
| 31 | + if ($err_message_id && !$value) |
| 32 | + $this->error(wfMsg($err_message_id)); |
| 33 | + |
| 34 | + return $value; |
| 35 | + } |
| 36 | + |
| 37 | + //Checks |
| 38 | + private $mEnvCheckCalls = array(); |
| 39 | + |
| 40 | + protected function addCheck($method_callback, array $args) |
| 41 | + { |
| 42 | + $this->mEnvCheckCalls[] = array($method_callback, $args); |
| 43 | + } |
| 44 | + |
| 45 | + protected function runChecks() |
| 46 | + { |
| 47 | + foreach ($this->mEnvCheckCalls as $call_array) |
| 48 | + { |
| 49 | + call_user_func_array($call_array[0], $call_array[1]); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + //Abstracting error calls in order to make this functionality changeable in subclasses |
| 54 | + protected function error($message) |
| 55 | + { |
| 56 | + throw new Exception($message); |
| 57 | + } |
| 58 | + |
| 59 | + abstract protected function populateData(); |
| 60 | + |
| 61 | + public function run() |
| 62 | + { |
| 63 | + try |
| 64 | + { |
| 65 | + $this->populateData(); |
| 66 | + $this->runChecks(); |
| 67 | + } |
| 68 | + catch (Exception $e) |
| 69 | + { |
| 70 | + $this->mError = $e->getMessage(); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
Property changes on: trunk/extensions/SemanticSignup/includes/SES_DataChecker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 74 | + native |