r94355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94354‎ | r94355 | r94356 >
Date:15:18, 12 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some fixes and cleanup
Modified paths:
  • /trunk/extensions/SemanticSignup/SemanticSignup.hooks.php (modified) (history)
  • /trunk/extensions/SemanticSignup/SemanticSignup.php (modified) (history)
  • /trunk/extensions/SemanticSignup/includes/SES_DataChecker.php (added) (history)
  • /trunk/extensions/SemanticSignup/includes/SES_Special.php (modified) (history)
  • /trunk/extensions/SemanticSignup/includes/SES_UserAccountDataChecker.php (added) (history)
  • /trunk/extensions/SemanticSignup/includes/SES_Utils.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/SemanticSignup/SemanticSignup.php
@@ -62,7 +62,8 @@
6363 $wgAutoloadClasses['SemanticSignupHooks'] = dirname( __FILE__ ) . '/SemanticSignup.hooks.php';
6464 $wgAutoloadClasses['SemanticSignup'] = dirname( __FILE__ ) . '/includes/SES_Special.php';
6565 $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';
6768 $wgAutoloadClasses['SES_SignupFields'] = dirname( __FILE__ ) . '/includes/SES_SignupFields.php';
6869 $wgAutoloadClasses['CreateUserFieldsTemplate'] = dirname( __FILE__ ) . '/includes/SES_SignupFields.php';
6970
Index: trunk/extensions/SemanticSignup/SemanticSignup.hooks.php
@@ -25,8 +25,7 @@
2626 return true;
2727 }
2828
29 - $semantic_signup_title = SemanticSignup::getTitleFor( 'SemanticSignup' );
30 - $url = $semantic_signup_title->escapeFullURL();
 29+ $url = SemanticSignup::getTitleFor( 'SemanticSignup' )->escapeFullURL();
3130 global $wgOut;
3231 $wgOut->redirect( $url );
3332
@@ -40,7 +39,7 @@
4140 */
4241 public static function onParserFirstCallInit() {
4342 global $wgParser;
44 -// $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' );
 43+ $wgParser->setHook( 'signupfields', 'SES_SignupFields::render' );
4544 return true;
4645 }
4746
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 @@
22 <?php
33
4 -/**
5 - * Created on 7 Jan 2008 by Serhii Kutnii
6 - */
7 -class SES_UserAccountDataChecker extends SES_DataChecker {
 4+class SemanticSignup extends SpecialPage {
85
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 - {
1186 private $mUserDataChecker = null;
1197 private $mUserPageUrl = '';
1208
121 - public function __construct()
122 - {
 9+ public function __construct() {
12310 parent::__construct('SemanticSignup');
12411 $this->mIncludable = false;
12512
12613 $this->mUserDataChecker = new SES_UserAccountDataChecker();
12714 }
12815
129 - private function userSignup()
130 - {
 16+ private function userSignup() {
13117 //Get user input and check the environment
13218 $this->mUserDataChecker->run();
13319
@@ -208,22 +94,22 @@
20995 $form = new Article($form_title);
21096 $form_definition = $form->getContent();
21197
212 - $page_title = Title::newFromText($this->mUserDataChecker->mUser->getName(), NS_USER);
 98+ $page_title = Title::newFromText( $this->mUserDataChecker->mUser->getName(), NS_USER );
21399 $this->mUserPageUrl = $page_title->escapeFullUrl();
214100
215101 global $sfgFormPrinter;
216102 list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) =
217103 $sfgFormPrinter->formHTML($form_definition, true, false);
218104
219 - $user_page = new Article($page_title);
 105+ $user_page = new Article( $page_title );
220106
221107 global $wgUser;
222108 $wgUser = $this->mUserDataChecker->mUser;
 109+ // TODO: doEdit removed; use internal API call
223110 $user_page->doEdit( $data_text, '', EDIT_FORCE_BOT );
224111 }
225112
226113 private function printForm() {
227 - global $sesSignupBotName;
228114 global $wgUser;
229115
230116 /*
@@ -232,10 +118,9 @@
233119 * the $old_user variable to be restored afterwards
234120 */
235121 $old_user = null;
236 - if ($wgUser->isAnon())
237 - {
 122+ if ( $wgUser->isAnon() ) {
238123 $old_user = $wgUser;
239 - $wgUser = User::newFromName($sesSignupBotName);
 124+ $wgUser = User::newFromName( SemanticSignupSettings::get( 'botName' ) );
240125 }
241126
242127 $form_title = Title::newFromText( SemanticSignupSettings::get( 'formName' ), SF_NS_FORM );
@@ -243,6 +128,7 @@
244129 $form_definition = $form->getContent();
245130
246131 global $sfgFormPrinter;
 132+ //var_dump($sfgFormPrinter);exit;
247133 list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) =
248134 $sfgFormPrinter->formHTML($form_definition, false, false);
249135
@@ -277,6 +163,8 @@
278164 'media' => "screen, projection",
279165 'href' => $sfgScriptPath . '/skins/floatbox.css'
280166 ));
 167+
 168+ // FIXME: wtf?
281169 $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'yahoo/yahoo-min.js"></script>' . "\n");
282170 $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'dom/dom-min.js"></script>' . "\n");
283171 $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
1115 + 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
174 + native