r94265 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94264‎ | r94265 | r94266 >
Date:18:03, 11 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some cleanup
Modified paths:
  • /trunk/extensions/SemanticSignup/SemanticSignup.hooks.php (modified) (history)
  • /trunk/extensions/SemanticSignup/SemanticSignup.php (modified) (history)
  • /trunk/extensions/SemanticSignup/includes/SES_Special.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticSignup/SemanticSignup.php
@@ -70,11 +70,5 @@
7171
7272 $egSemanticSignupSettings = array();
7373
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 @@
2222 * @return false
2323 */
2424 public static function onUserCreateForm( $template ) {
 25+ if ( is_null( Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM ) ) ) {
 26+ return true;
 27+ }
 28+
2529 $semantic_signup_title = SemanticSignup::getTitleFor( 'SemanticSignup' );
2630 $url = $semantic_signup_title->escapeFullURL();
27 -
2831 global $wgOut;
2932 $wgOut->redirect( $url );
3033
@@ -37,7 +40,7 @@
3841 */
3942 public static function onParserFirstCallInit() {
4043 global $wgParser;
41 - $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' );
 44+// $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' );
4245 return true;
4346 }
4447
Index: trunk/extensions/SemanticSignup/includes/SES_Special.php
@@ -1,27 +1,26 @@
22 <?php
3 -/*
 3+
 4+/**
45 * Created on 7 Jan 2008 by Serhii Kutnii
5 - *
66 */
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+ }
2625
2726 global $sesRealNameRequired;
2827 $this->mRealname = $this->getUserDataValue('wpRealName', $sesRealNameRequired ? 'norealname' : null);
@@ -40,95 +39,95 @@
4140
4241 global $wgRequest;
4342 $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 ) )
5352 $this->error(wfMsg('wrongpassword'));
54 - }
55 -
56 - public function checkDomainUser()
57 - {
58 - global $wgAuth;
 53+ }
 54+
 55+ public function checkDomainUser()
 56+ {
 57+ global $wgAuth;
5958
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();
7877 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
7978 $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+ {
8584 if ($this->mUser->idForName())
8685 $this->error(wfMsg('userexists'));
87 - }
88 -
89 - public function checkPasswordLength()
90 - {
 86+ }
 87+
 88+ public function checkPasswordLength()
 89+ {
9190 if (!$this->mUser->isValidPassword($this->mPassword))
9291 {
9392 global $wgMinimalPasswordLength;
9493 $this->error(wfMsgExt('passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength));
9594 }
96 - }
97 -
98 - public function checkEmailValidity()
99 - {
100 - global $wgEnableEmail;
 95+ }
 96+
 97+ public function checkEmailValidity()
 98+ {
 99+ global $wgEnableEmail;
101100 if ($wgEnableEmail && !User::isValidEmailAddr($this->mEmail))
102101 $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+ }
115114 }
116115
117116 class SemanticSignup extends SpecialPage
118117 {
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;
126125
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
133132 $this->mUserDataChecker->run();
134133
135134 //Throw if data getting or environment checks have failed which indicates that account creation is impossible
@@ -150,7 +149,7 @@
151150 }
152151
153152 global $wgAccountCreationThrottle;
154 - global $wgUser;
 153+ global $wgUser;
155154 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() )
156155 {
157156 $key = wfMemcKey( 'acctcreate', 'ip', wfGetIP() );
@@ -192,40 +191,40 @@
193192 $language = $this->mUserDataChecker->mLanguage;
194193 if( $wgLoginLanguageSelector && $language )
195194 $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();
215214
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);
219218
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+ }
226225
227 - private function printForm() {
228 - global $sesSignupBotName;
229 - global $wgUser;
 226+ private function printForm() {
 227+ global $sesSignupBotName;
 228+ global $wgUser;
230229
231230 /*
232231 * SemanticForms disable the form automatically if current user hasn't got edit rights
@@ -233,27 +232,27 @@
234233 * the $old_user variable to be restored afterwards
235234 */
236235 $old_user = null;
237 - if ($wgUser->isAnon())
 236+ if ($wgUser->isAnon())
238237 {
239 - $old_user = $wgUser;
240 - $wgUser = User::newFromName($sesSignupBotName);
 238+ $old_user = $wgUser;
 239+ $wgUser = User::newFromName($sesSignupBotName);
241240 }
242241
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+
251250 $text =<<<END
252251 <form name="createbox" onsubmit="return validate_all()" action="" method="post" class="createbox">
253252 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';
258257 $wgOut->addLink( array(
259258 'rel' => 'stylesheet',
260259 'type' => 'text/css',
@@ -300,46 +299,36 @@
301300 //Restoring the current user
302301 if ($old_user)
303302 $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+
336325 $this->setHeaders();
337326
338 - $form_submitted = $wgRequest->getCheck('wpSave');
339 - if ($form_submitted)
340 - {
 327+ if ( $wgRequest->getCheck( 'wpSave' ) ) {
341328 return $this->executeOnSubmit();
342329 } else {
343 - return $this->executeOnGetPage();
 330+ $this->printForm();
 331+ return true;
344332 }
345 - }
346 - }
\ No newline at end of file
 333+ }
 334+}
 335+
\ No newline at end of file