@@ -21,204 +21,204 @@ |
||
21 | 21 | |
22 | 22 | abstract class PageRegisterBase extends InternalPageBase |
23 | 23 | { |
24 | - /** |
|
25 | - * Main function for this page, when no specific actions are called. |
|
26 | - * @throws AccessDeniedException |
|
27 | - */ |
|
28 | - protected function main() |
|
29 | - { |
|
30 | - $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
31 | - if (! $this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
32 | - throw new AccessDeniedException(); |
|
33 | - } |
|
34 | - |
|
35 | - // Dual-mode page |
|
36 | - if (WebRequest::wasPosted()) { |
|
37 | - $this->validateCSRFToken(); |
|
38 | - |
|
39 | - try { |
|
40 | - $this->handlePost($useOAuthSignup); |
|
41 | - } |
|
42 | - catch (ApplicationLogicException $ex) { |
|
43 | - SessionAlert::error($ex->getMessage()); |
|
44 | - $this->redirect('register'); |
|
45 | - } |
|
46 | - } |
|
47 | - else { |
|
48 | - $this->assignCSRFToken(); |
|
49 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
50 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - protected abstract function getRegistrationTemplate(); |
|
55 | - |
|
56 | - protected function isProtectedPage() |
|
57 | - { |
|
58 | - return false; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $emailAddress |
|
63 | - * |
|
64 | - * @throws ApplicationLogicException |
|
65 | - */ |
|
66 | - protected function validateUniqueEmail($emailAddress) |
|
67 | - { |
|
68 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
69 | - $statement = $this->getDatabase()->prepare($query); |
|
70 | - $statement->execute(array(':email' => $emailAddress)); |
|
71 | - |
|
72 | - if ($statement->fetchColumn() > 0) { |
|
73 | - throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
74 | - } |
|
75 | - |
|
76 | - $statement->closeCursor(); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param $emailAddress |
|
81 | - * @param $password |
|
82 | - * @param $username |
|
83 | - * @param $useOAuthSignup |
|
84 | - * @param $confirmationId |
|
85 | - * @param $onwikiUsername |
|
86 | - * |
|
87 | - * @throws ApplicationLogicException |
|
88 | - */ |
|
89 | - protected function validateRequest( |
|
90 | - $emailAddress, |
|
91 | - $password, |
|
92 | - $username, |
|
93 | - $useOAuthSignup, |
|
94 | - $confirmationId, |
|
95 | - $onwikiUsername |
|
96 | - ) { |
|
97 | - if (!WebRequest::postBoolean('guidelines')) { |
|
98 | - throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
99 | - } |
|
100 | - |
|
101 | - $this->validateGeneralInformation($emailAddress, $password, $username); |
|
102 | - $this->validateUniqueEmail($emailAddress); |
|
103 | - $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param $useOAuthSignup |
|
108 | - * @param $confirmationId |
|
109 | - * @param $onwikiUsername |
|
110 | - * |
|
111 | - * @throws ApplicationLogicException |
|
112 | - */ |
|
113 | - protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
114 | - { |
|
115 | - if (!$useOAuthSignup) { |
|
116 | - if ($confirmationId === null || $confirmationId <= 0) { |
|
117 | - throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
118 | - } |
|
119 | - |
|
120 | - if ($onwikiUsername === null) { |
|
121 | - throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param $emailAddress |
|
128 | - * @param $password |
|
129 | - * @param $username |
|
130 | - * |
|
131 | - * @throws ApplicationLogicException |
|
132 | - */ |
|
133 | - protected function validateGeneralInformation($emailAddress, $password, $username) |
|
134 | - { |
|
135 | - if ($emailAddress === null) { |
|
136 | - throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
137 | - } |
|
138 | - |
|
139 | - if ($password !== WebRequest::postString('pass2')) { |
|
140 | - throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
141 | - } |
|
142 | - |
|
143 | - if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
144 | - throw new ApplicationLogicException('That username is already in use on this system.'); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @param $useOAuthSignup |
|
150 | - * |
|
151 | - * @throws ApplicationLogicException |
|
152 | - * @throws \Exception |
|
153 | - */ |
|
154 | - protected function handlePost($useOAuthSignup) |
|
155 | - { |
|
156 | - // Get the data |
|
157 | - $emailAddress = WebRequest::postEmail('email'); |
|
158 | - $password = WebRequest::postString('pass'); |
|
159 | - $username = WebRequest::postString('name'); |
|
160 | - |
|
161 | - // Only set if OAuth is disabled |
|
162 | - $confirmationId = WebRequest::postInt('conf_revid'); |
|
163 | - $onwikiUsername = WebRequest::postString('wname'); |
|
164 | - |
|
165 | - // Do some validation |
|
166 | - $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
167 | - $onwikiUsername); |
|
168 | - |
|
169 | - $database = $this->getDatabase(); |
|
170 | - |
|
171 | - $user = new User(); |
|
172 | - $user->setDatabase($database); |
|
173 | - |
|
174 | - $user->setUsername($username); |
|
175 | - $user->setEmail($emailAddress); |
|
176 | - |
|
177 | - if (!$useOAuthSignup) { |
|
178 | - $user->setOnWikiName($onwikiUsername); |
|
179 | - $user->setConfirmationDiff($confirmationId); |
|
180 | - } |
|
181 | - |
|
182 | - $user->save(); |
|
183 | - |
|
184 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
185 | - $passwordCredentialProvider->setCredential($user, 1, $password); |
|
186 | - |
|
187 | - $defaultRole = $this->getDefaultRole(); |
|
188 | - |
|
189 | - $role = new UserRole(); |
|
190 | - $role->setDatabase($database); |
|
191 | - $role->setUser($user->getId()); |
|
192 | - $role->setRole($defaultRole); |
|
193 | - $role->save(); |
|
194 | - |
|
195 | - // Log now to get the signup date. |
|
196 | - Logger::newUser($database, $user); |
|
197 | - Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
198 | - |
|
199 | - if ($useOAuthSignup) { |
|
200 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
201 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
202 | - |
|
203 | - $authoriseUrl = $oauth->getRequestToken(); |
|
204 | - WebRequest::setOAuthPartialLogin($user); |
|
205 | - $this->redirectUrl($authoriseUrl); |
|
206 | - } |
|
207 | - else { |
|
208 | - // only notify if we're not using the oauth signup. |
|
209 | - $this->getNotificationHelper()->userNew($user); |
|
210 | - WebRequest::setLoggedInUser($user); |
|
211 | - $this->redirect('preferences'); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - protected abstract function getDefaultRole(); |
|
216 | - |
|
217 | - /** |
|
218 | - * Entry point for registration complete |
|
219 | - */ |
|
220 | - protected function done() |
|
221 | - { |
|
222 | - $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
223 | - } |
|
24 | + /** |
|
25 | + * Main function for this page, when no specific actions are called. |
|
26 | + * @throws AccessDeniedException |
|
27 | + */ |
|
28 | + protected function main() |
|
29 | + { |
|
30 | + $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
31 | + if (! $this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
32 | + throw new AccessDeniedException(); |
|
33 | + } |
|
34 | + |
|
35 | + // Dual-mode page |
|
36 | + if (WebRequest::wasPosted()) { |
|
37 | + $this->validateCSRFToken(); |
|
38 | + |
|
39 | + try { |
|
40 | + $this->handlePost($useOAuthSignup); |
|
41 | + } |
|
42 | + catch (ApplicationLogicException $ex) { |
|
43 | + SessionAlert::error($ex->getMessage()); |
|
44 | + $this->redirect('register'); |
|
45 | + } |
|
46 | + } |
|
47 | + else { |
|
48 | + $this->assignCSRFToken(); |
|
49 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
50 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + protected abstract function getRegistrationTemplate(); |
|
55 | + |
|
56 | + protected function isProtectedPage() |
|
57 | + { |
|
58 | + return false; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $emailAddress |
|
63 | + * |
|
64 | + * @throws ApplicationLogicException |
|
65 | + */ |
|
66 | + protected function validateUniqueEmail($emailAddress) |
|
67 | + { |
|
68 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
69 | + $statement = $this->getDatabase()->prepare($query); |
|
70 | + $statement->execute(array(':email' => $emailAddress)); |
|
71 | + |
|
72 | + if ($statement->fetchColumn() > 0) { |
|
73 | + throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
74 | + } |
|
75 | + |
|
76 | + $statement->closeCursor(); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param $emailAddress |
|
81 | + * @param $password |
|
82 | + * @param $username |
|
83 | + * @param $useOAuthSignup |
|
84 | + * @param $confirmationId |
|
85 | + * @param $onwikiUsername |
|
86 | + * |
|
87 | + * @throws ApplicationLogicException |
|
88 | + */ |
|
89 | + protected function validateRequest( |
|
90 | + $emailAddress, |
|
91 | + $password, |
|
92 | + $username, |
|
93 | + $useOAuthSignup, |
|
94 | + $confirmationId, |
|
95 | + $onwikiUsername |
|
96 | + ) { |
|
97 | + if (!WebRequest::postBoolean('guidelines')) { |
|
98 | + throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
99 | + } |
|
100 | + |
|
101 | + $this->validateGeneralInformation($emailAddress, $password, $username); |
|
102 | + $this->validateUniqueEmail($emailAddress); |
|
103 | + $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param $useOAuthSignup |
|
108 | + * @param $confirmationId |
|
109 | + * @param $onwikiUsername |
|
110 | + * |
|
111 | + * @throws ApplicationLogicException |
|
112 | + */ |
|
113 | + protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
114 | + { |
|
115 | + if (!$useOAuthSignup) { |
|
116 | + if ($confirmationId === null || $confirmationId <= 0) { |
|
117 | + throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
118 | + } |
|
119 | + |
|
120 | + if ($onwikiUsername === null) { |
|
121 | + throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param $emailAddress |
|
128 | + * @param $password |
|
129 | + * @param $username |
|
130 | + * |
|
131 | + * @throws ApplicationLogicException |
|
132 | + */ |
|
133 | + protected function validateGeneralInformation($emailAddress, $password, $username) |
|
134 | + { |
|
135 | + if ($emailAddress === null) { |
|
136 | + throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
137 | + } |
|
138 | + |
|
139 | + if ($password !== WebRequest::postString('pass2')) { |
|
140 | + throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
141 | + } |
|
142 | + |
|
143 | + if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
144 | + throw new ApplicationLogicException('That username is already in use on this system.'); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @param $useOAuthSignup |
|
150 | + * |
|
151 | + * @throws ApplicationLogicException |
|
152 | + * @throws \Exception |
|
153 | + */ |
|
154 | + protected function handlePost($useOAuthSignup) |
|
155 | + { |
|
156 | + // Get the data |
|
157 | + $emailAddress = WebRequest::postEmail('email'); |
|
158 | + $password = WebRequest::postString('pass'); |
|
159 | + $username = WebRequest::postString('name'); |
|
160 | + |
|
161 | + // Only set if OAuth is disabled |
|
162 | + $confirmationId = WebRequest::postInt('conf_revid'); |
|
163 | + $onwikiUsername = WebRequest::postString('wname'); |
|
164 | + |
|
165 | + // Do some validation |
|
166 | + $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
167 | + $onwikiUsername); |
|
168 | + |
|
169 | + $database = $this->getDatabase(); |
|
170 | + |
|
171 | + $user = new User(); |
|
172 | + $user->setDatabase($database); |
|
173 | + |
|
174 | + $user->setUsername($username); |
|
175 | + $user->setEmail($emailAddress); |
|
176 | + |
|
177 | + if (!$useOAuthSignup) { |
|
178 | + $user->setOnWikiName($onwikiUsername); |
|
179 | + $user->setConfirmationDiff($confirmationId); |
|
180 | + } |
|
181 | + |
|
182 | + $user->save(); |
|
183 | + |
|
184 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
185 | + $passwordCredentialProvider->setCredential($user, 1, $password); |
|
186 | + |
|
187 | + $defaultRole = $this->getDefaultRole(); |
|
188 | + |
|
189 | + $role = new UserRole(); |
|
190 | + $role->setDatabase($database); |
|
191 | + $role->setUser($user->getId()); |
|
192 | + $role->setRole($defaultRole); |
|
193 | + $role->save(); |
|
194 | + |
|
195 | + // Log now to get the signup date. |
|
196 | + Logger::newUser($database, $user); |
|
197 | + Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
198 | + |
|
199 | + if ($useOAuthSignup) { |
|
200 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
201 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
202 | + |
|
203 | + $authoriseUrl = $oauth->getRequestToken(); |
|
204 | + WebRequest::setOAuthPartialLogin($user); |
|
205 | + $this->redirectUrl($authoriseUrl); |
|
206 | + } |
|
207 | + else { |
|
208 | + // only notify if we're not using the oauth signup. |
|
209 | + $this->getNotificationHelper()->userNew($user); |
|
210 | + WebRequest::setLoggedInUser($user); |
|
211 | + $this->redirect('preferences'); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + protected abstract function getDefaultRole(); |
|
216 | + |
|
217 | + /** |
|
218 | + * Entry point for registration complete |
|
219 | + */ |
|
220 | + protected function done() |
|
221 | + { |
|
222 | + $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
223 | + } |
|
224 | 224 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | protected function main() |
29 | 29 | { |
30 | 30 | $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
31 | - if (! $this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
31 | + if (!$this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
32 | 32 | throw new AccessDeniedException(); |
33 | 33 | } |
34 | 34 |
@@ -15,73 +15,73 @@ discard block |
||
15 | 15 | |
16 | 16 | class UserSearchHelper extends SearchHelperBase |
17 | 17 | { |
18 | - /** |
|
19 | - * UserSearchHelper constructor. |
|
20 | - * |
|
21 | - * @param PdoDatabase $database |
|
22 | - */ |
|
23 | - public function __construct(PdoDatabase $database) |
|
24 | - { |
|
25 | - parent::__construct($database, 'user', User::class); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Initiates a search for requests |
|
30 | - * |
|
31 | - * @param PdoDatabase $database |
|
32 | - * |
|
33 | - * @return UserSearchHelper |
|
34 | - */ |
|
35 | - public static function get(PdoDatabase $database) |
|
36 | - { |
|
37 | - $helper = new UserSearchHelper($database); |
|
38 | - |
|
39 | - return $helper; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $status |
|
44 | - * |
|
45 | - * @return $this |
|
46 | - */ |
|
47 | - public function byStatus($status) |
|
48 | - { |
|
49 | - $this->whereClause .= ' AND status = ?'; |
|
50 | - $this->parameterList[] = $status; |
|
51 | - |
|
52 | - return $this; |
|
53 | - } |
|
54 | - |
|
55 | - public function statusIn($statuses) |
|
56 | - { |
|
57 | - $this->inClause('status', $statuses); |
|
58 | - |
|
59 | - return $this; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $role |
|
64 | - * |
|
65 | - * @return $this |
|
66 | - */ |
|
67 | - public function byRole($role) |
|
68 | - { |
|
69 | - $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
70 | - $this->whereClause .= ' AND r.role = ?'; |
|
71 | - $this->parameterList[] = $role; |
|
72 | - |
|
73 | - return $this; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param DateTime $instant |
|
78 | - * |
|
79 | - * @return $this |
|
80 | - */ |
|
81 | - public function lastActiveBefore(DateTime $instant) |
|
82 | - { |
|
83 | - $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
84 | - $this->joinClause .= <<<'SQLFRAG' |
|
18 | + /** |
|
19 | + * UserSearchHelper constructor. |
|
20 | + * |
|
21 | + * @param PdoDatabase $database |
|
22 | + */ |
|
23 | + public function __construct(PdoDatabase $database) |
|
24 | + { |
|
25 | + parent::__construct($database, 'user', User::class); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Initiates a search for requests |
|
30 | + * |
|
31 | + * @param PdoDatabase $database |
|
32 | + * |
|
33 | + * @return UserSearchHelper |
|
34 | + */ |
|
35 | + public static function get(PdoDatabase $database) |
|
36 | + { |
|
37 | + $helper = new UserSearchHelper($database); |
|
38 | + |
|
39 | + return $helper; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $status |
|
44 | + * |
|
45 | + * @return $this |
|
46 | + */ |
|
47 | + public function byStatus($status) |
|
48 | + { |
|
49 | + $this->whereClause .= ' AND status = ?'; |
|
50 | + $this->parameterList[] = $status; |
|
51 | + |
|
52 | + return $this; |
|
53 | + } |
|
54 | + |
|
55 | + public function statusIn($statuses) |
|
56 | + { |
|
57 | + $this->inClause('status', $statuses); |
|
58 | + |
|
59 | + return $this; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $role |
|
64 | + * |
|
65 | + * @return $this |
|
66 | + */ |
|
67 | + public function byRole($role) |
|
68 | + { |
|
69 | + $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
70 | + $this->whereClause .= ' AND r.role = ?'; |
|
71 | + $this->parameterList[] = $role; |
|
72 | + |
|
73 | + return $this; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param DateTime $instant |
|
78 | + * |
|
79 | + * @return $this |
|
80 | + */ |
|
81 | + public function lastActiveBefore(DateTime $instant) |
|
82 | + { |
|
83 | + $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
84 | + $this->joinClause .= <<<'SQLFRAG' |
|
85 | 85 | LEFT JOIN ( |
86 | 86 | SELECT objectid, MAX(timestamp) timestamp |
87 | 87 | FROM log |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | GROUP BY objectid |
90 | 90 | ) approvaldate ON approvaldate.objectid = origin.id |
91 | 91 | SQLFRAG; |
92 | - $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
93 | - $this->parameterList[] = $formattedDate; |
|
94 | - $this->parameterList[] = $formattedDate; |
|
92 | + $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
93 | + $this->parameterList[] = $formattedDate; |
|
94 | + $this->parameterList[] = $formattedDate; |
|
95 | 95 | |
96 | - return $this; |
|
97 | - } |
|
96 | + return $this; |
|
97 | + } |
|
98 | 98 | |
99 | - public function getRoleMap(&$roleMap) |
|
100 | - { |
|
101 | - $query = <<<SQL |
|
99 | + public function getRoleMap(&$roleMap) |
|
100 | + { |
|
101 | + $query = <<<SQL |
|
102 | 102 | SELECT /* UserSearchHelper/roleMap */ |
103 | 103 | r.user user |
104 | 104 | , group_concat(r.role SEPARATOR ', ') roles |
@@ -107,22 +107,22 @@ discard block |
||
107 | 107 | GROUP BY r.user |
108 | 108 | SQL; |
109 | 109 | |
110 | - $statement = $this->database->prepare($query); |
|
111 | - $statement->execute($this->parameterList); |
|
110 | + $statement = $this->database->prepare($query); |
|
111 | + $statement->execute($this->parameterList); |
|
112 | 112 | |
113 | - $roleMap = array(); |
|
114 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
115 | - $roleMap[$row['user']] = $row['roles']; |
|
116 | - } |
|
113 | + $roleMap = array(); |
|
114 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
115 | + $roleMap[$row['user']] = $row['roles']; |
|
116 | + } |
|
117 | 117 | |
118 | - return $this; |
|
119 | - } |
|
118 | + return $this; |
|
119 | + } |
|
120 | 120 | |
121 | - public function withReservedRequest() |
|
122 | - { |
|
123 | - $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
124 | - $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
121 | + public function withReservedRequest() |
|
122 | + { |
|
123 | + $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
124 | + $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
125 | 125 | |
126 | - return $this->fetchMap('username'); |
|
127 | - } |
|
126 | + return $this->fetchMap('username'); |
|
127 | + } |
|
128 | 128 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | |
15 | 15 | class PrecacheGeolocationTask extends ConsoleTaskBase |
16 | 16 | { |
17 | - public function execute() |
|
18 | - { |
|
19 | - $database = $this->getDatabase(); |
|
20 | - $locationProvider = $this->getLocationProvider(); |
|
17 | + public function execute() |
|
18 | + { |
|
19 | + $database = $this->getDatabase(); |
|
20 | + $locationProvider = $this->getLocationProvider(); |
|
21 | 21 | |
22 | - while (true) { |
|
23 | - echo "Beginning txn\n"; |
|
24 | - $database->beginTransaction(); |
|
22 | + while (true) { |
|
23 | + echo "Beginning txn\n"; |
|
24 | + $database->beginTransaction(); |
|
25 | 25 | |
26 | - try { |
|
27 | - echo ". Fetching data...\n"; |
|
26 | + try { |
|
27 | + echo ". Fetching data...\n"; |
|
28 | 28 | |
29 | - // fetch a bunch of un-geolocated IPs from the database. |
|
30 | - // Note we have to parse the forwardedip field in the database so we can test against the geolocation |
|
31 | - // table. |
|
32 | - // |
|
33 | - // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
34 | - // |
|
35 | - // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an |
|
36 | - // IN() clause dynamically, sending that back to the database to check if there are geolocation entries, |
|
37 | - // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all |
|
38 | - // IPs from the database before we find any at all. This way keeps all of that legwork in the database, |
|
39 | - // at the cost of a more complex query. |
|
40 | - $statement = $database->query(<<<SQL |
|
29 | + // fetch a bunch of un-geolocated IPs from the database. |
|
30 | + // Note we have to parse the forwardedip field in the database so we can test against the geolocation |
|
31 | + // table. |
|
32 | + // |
|
33 | + // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
34 | + // |
|
35 | + // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an |
|
36 | + // IN() clause dynamically, sending that back to the database to check if there are geolocation entries, |
|
37 | + // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all |
|
38 | + // IPs from the database before we find any at all. This way keeps all of that legwork in the database, |
|
39 | + // at the cost of a more complex query. |
|
40 | + $statement = $database->query(<<<SQL |
|
41 | 41 | SELECT /* PrecacheGeolocationTask */ p.prox |
42 | 42 | FROM ( |
43 | 43 | SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox |
@@ -54,42 +54,42 @@ discard block |
||
54 | 54 | WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox FOR UPDATE) |
55 | 55 | LIMIT 10; |
56 | 56 | SQL |
57 | - ); |
|
57 | + ); |
|
58 | 58 | |
59 | - $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
59 | + $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
60 | 60 | |
61 | - $count = count($missingIps); |
|
62 | - if ($count === 0) { |
|
63 | - echo ". Found nothing to do.\n"; |
|
64 | - break; |
|
65 | - } |
|
61 | + $count = count($missingIps); |
|
62 | + if ($count === 0) { |
|
63 | + echo ". Found nothing to do.\n"; |
|
64 | + break; |
|
65 | + } |
|
66 | 66 | |
67 | - echo ". Picked {$count} IP addresses\n"; |
|
67 | + echo ". Picked {$count} IP addresses\n"; |
|
68 | 68 | |
69 | - foreach ($missingIps as $ip) { |
|
70 | - echo ". . Getting location for {$ip}...\n"; |
|
71 | - $data = json_encode($locationProvider->getIpLocation($ip)); |
|
72 | - echo ". . . {$data}\n"; |
|
73 | - } |
|
69 | + foreach ($missingIps as $ip) { |
|
70 | + echo ". . Getting location for {$ip}...\n"; |
|
71 | + $data = json_encode($locationProvider->getIpLocation($ip)); |
|
72 | + echo ". . . {$data}\n"; |
|
73 | + } |
|
74 | 74 | |
75 | - echo ". IP location fetch complete.\n"; |
|
76 | - $database->commit(); |
|
77 | - echo ". Committed txn.\n"; |
|
78 | - } |
|
79 | - catch (Exception $ex) { |
|
80 | - echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
81 | - $database->rollBack(); |
|
82 | - echo ". Rolled back txn\n"; |
|
83 | - throw $ex; |
|
84 | - } |
|
85 | - finally { |
|
86 | - if ($database->hasActiveTransaction()) { |
|
87 | - $database->rollBack(); |
|
88 | - echo ". Rolled back txn\n"; |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
75 | + echo ". IP location fetch complete.\n"; |
|
76 | + $database->commit(); |
|
77 | + echo ". Committed txn.\n"; |
|
78 | + } |
|
79 | + catch (Exception $ex) { |
|
80 | + echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
81 | + $database->rollBack(); |
|
82 | + echo ". Rolled back txn\n"; |
|
83 | + throw $ex; |
|
84 | + } |
|
85 | + finally { |
|
86 | + if ($database->hasActiveTransaction()) { |
|
87 | + $database->rollBack(); |
|
88 | + echo ". Rolled back txn\n"; |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - echo "Done.\n"; |
|
94 | - } |
|
93 | + echo "Done.\n"; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | \ No newline at end of file |
@@ -77,7 +77,7 @@ |
||
77 | 77 | echo ". Committed txn.\n"; |
78 | 78 | } |
79 | 79 | catch (Exception $ex) { |
80 | - echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
80 | + echo ". Encountered exception: ".$ex->getMessage()."\n"; |
|
81 | 81 | $database->rollBack(); |
82 | 82 | echo ". Rolled back txn\n"; |
83 | 83 | throw $ex; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $BUbasefile = "backup"; // The basefile's name. |
134 | 134 | $BUdir = "/home/project/a/c/c/acc/backups"; // The directory where backups should be stored. |
135 | -$BUmonthdir = $BUdir . "/monthly"; // The directory where monthly backups should be stored. |
|
135 | +$BUmonthdir = $BUdir."/monthly"; // The directory where monthly backups should be stored. |
|
136 | 136 | $BUdumper = "/opt/ts/mysql/5.1/bin/mysqldump --defaults-file=~/.my.cnf p_acc_live"; // Add parameters here if they are needed. |
137 | 137 | $BUgzip = "/usr/bin/gzip"; // Add the gzip parameters here if needed. |
138 | 138 | $BUtar = "/bin/tar -cvf"; // Add the tar parameters here if needed. |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $curlDisableSSLVerifyPeer = false; |
249 | 249 | |
250 | 250 | // Change this to be outside the web directory. |
251 | -$curlCookieJar = __DIR__ . '/../cookies.txt'; |
|
251 | +$curlCookieJar = __DIR__.'/../cookies.txt'; |
|
252 | 252 | |
253 | 253 | $yubicoApiId = 0; |
254 | 254 | $yubicoApiKey = ""; |
@@ -267,19 +267,19 @@ discard block |
||
267 | 267 | |
268 | 268 | $cDatabaseConfig = array( |
269 | 269 | "acc" => array( |
270 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
270 | + "dsrcname" => "mysql:host=".$toolserver_host.";dbname=".$toolserver_database, |
|
271 | 271 | "username" => $toolserver_username, |
272 | 272 | "password" => $toolserver_password, |
273 | 273 | "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'), |
274 | 274 | ), |
275 | 275 | "wikipedia" => array( |
276 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
276 | + "dsrcname" => "mysql:host=".$antispoof_host.";dbname=".$antispoof_db, |
|
277 | 277 | "username" => $toolserver_username, |
278 | 278 | "password" => $toolserver_password, |
279 | 279 | "options" => array(), |
280 | 280 | ), |
281 | 281 | "notifications" => array( |
282 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
282 | + "dsrcname" => "mysql:host=".$toolserver_notification_dbhost.";dbname=".$toolserver_notification_database, |
|
283 | 283 | "username" => $notifications_username, |
284 | 284 | "password" => $notifications_password, |
285 | 285 | "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'), |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | } |
311 | 311 | |
312 | 312 | // Set up the AutoLoader |
313 | -require_once(__DIR__ . "/includes/AutoLoader.php"); |
|
313 | +require_once(__DIR__."/includes/AutoLoader.php"); |
|
314 | 314 | spl_autoload_register('Waca\\AutoLoader::load'); |
315 | -require_once(__DIR__ . '/vendor/autoload.php'); |
|
315 | +require_once(__DIR__.'/vendor/autoload.php'); |
|
316 | 316 | |
317 | 317 | // Extra includes which are just plain awkward wherever they are. |
318 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
319 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
318 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
319 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
320 | 320 | |
321 | 321 | // Crap that's needed for libraries. >:( |
322 | 322 | /** |
@@ -202,27 +202,27 @@ discard block |
||
202 | 202 | |
203 | 203 | // request states |
204 | 204 | $availableRequestStates = array( |
205 | - 'Open' => array( |
|
206 | - 'defertolog' => 'users', // don't change or you'll break old logs |
|
207 | - 'deferto' => 'users', |
|
208 | - 'header' => 'Open requests', |
|
209 | - 'api' => "open", |
|
210 | - 'queuehelp' => null |
|
211 | - ), |
|
212 | - 'Flagged users' => array( |
|
213 | - 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
214 | - 'deferto' => 'flagged users', |
|
215 | - 'header' => 'Flagged user needed', |
|
216 | - 'api' => "admin", |
|
217 | - 'queuehelp' => 'This queue lists the requests which require a user with the <code>accountcreator</code> flag to create.<br />If creation is determined to be the correct course of action, requests here will require the overriding the AntiSpoof checks or the title blacklist in order to create. It is recommended to try to create the account <em>without</em> checking the flags to validate the results of the AntiSpoof and/or title blacklist hits.' |
|
218 | - ), |
|
219 | - 'Checkuser' => array( |
|
220 | - 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
221 | - 'deferto' => 'checkusers', |
|
222 | - 'header' => 'Checkuser needed', |
|
223 | - 'api' => "checkuser", |
|
224 | - 'queuehelp' => null |
|
225 | - ), |
|
205 | + 'Open' => array( |
|
206 | + 'defertolog' => 'users', // don't change or you'll break old logs |
|
207 | + 'deferto' => 'users', |
|
208 | + 'header' => 'Open requests', |
|
209 | + 'api' => "open", |
|
210 | + 'queuehelp' => null |
|
211 | + ), |
|
212 | + 'Flagged users' => array( |
|
213 | + 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
214 | + 'deferto' => 'flagged users', |
|
215 | + 'header' => 'Flagged user needed', |
|
216 | + 'api' => "admin", |
|
217 | + 'queuehelp' => 'This queue lists the requests which require a user with the <code>accountcreator</code> flag to create.<br />If creation is determined to be the correct course of action, requests here will require the overriding the AntiSpoof checks or the title blacklist in order to create. It is recommended to try to create the account <em>without</em> checking the flags to validate the results of the AntiSpoof and/or title blacklist hits.' |
|
218 | + ), |
|
219 | + 'Checkuser' => array( |
|
220 | + 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
221 | + 'deferto' => 'checkusers', |
|
222 | + 'header' => 'Checkuser needed', |
|
223 | + 'api' => "checkuser", |
|
224 | + 'queuehelp' => null |
|
225 | + ), |
|
226 | 226 | ); |
227 | 227 | |
228 | 228 | $defaultRequestStateKey = 'Open'; |
@@ -272,24 +272,24 @@ discard block |
||
272 | 272 | require_once('config.local.inc.php'); |
273 | 273 | |
274 | 274 | $cDatabaseConfig = array( |
275 | - "acc" => array( |
|
276 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
277 | - "username" => $toolserver_username, |
|
278 | - "password" => $toolserver_password, |
|
275 | + "acc" => array( |
|
276 | + "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
277 | + "username" => $toolserver_username, |
|
278 | + "password" => $toolserver_password, |
|
279 | 279 | "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'), |
280 | - ), |
|
281 | - "wikipedia" => array( |
|
282 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
283 | - "username" => $toolserver_username, |
|
284 | - "password" => $toolserver_password, |
|
285 | - "options" => array(), |
|
286 | - ), |
|
287 | - "notifications" => array( |
|
288 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
289 | - "username" => $notifications_username, |
|
290 | - "password" => $notifications_password, |
|
291 | - "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'), |
|
292 | - ), |
|
280 | + ), |
|
281 | + "wikipedia" => array( |
|
282 | + "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
283 | + "username" => $toolserver_username, |
|
284 | + "password" => $toolserver_password, |
|
285 | + "options" => array(), |
|
286 | + ), |
|
287 | + "notifications" => array( |
|
288 | + "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
289 | + "username" => $notifications_username, |
|
290 | + "password" => $notifications_password, |
|
291 | + "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'), |
|
292 | + ), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | // //Keep the included files from being executed. |
@@ -301,18 +301,18 @@ discard block |
||
301 | 301 | ini_set('user_agent', $toolUserAgent); |
302 | 302 | |
303 | 303 | foreach (array( |
304 | - "mbstring", // unicode and stuff |
|
305 | - "pdo", |
|
306 | - "pdo_mysql", // new database module |
|
307 | - "session", |
|
308 | - "date", |
|
309 | - "pcre", // core stuff |
|
310 | - "curl", // mediawiki api access etc |
|
311 | - "openssl", // token generation |
|
304 | + "mbstring", // unicode and stuff |
|
305 | + "pdo", |
|
306 | + "pdo_mysql", // new database module |
|
307 | + "session", |
|
308 | + "date", |
|
309 | + "pcre", // core stuff |
|
310 | + "curl", // mediawiki api access etc |
|
311 | + "openssl", // token generation |
|
312 | 312 | ) as $x) { |
313 | - if (!extension_loaded($x)) { |
|
314 | - die("extension $x is required."); |
|
315 | - } |
|
313 | + if (!extension_loaded($x)) { |
|
314 | + die("extension $x is required."); |
|
315 | + } |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | // Set up the AutoLoader |
@@ -339,41 +339,41 @@ discard block |
||
339 | 339 | $siteConfiguration = new \Waca\SiteConfiguration(); |
340 | 340 | |
341 | 341 | $siteConfiguration->setBaseUrl($baseurl) |
342 | - ->setFilePath(__DIR__) |
|
343 | - ->setDebuggingTraceEnabled($enableErrorTrace) |
|
344 | - ->setForceIdentification($forceIdentification) |
|
345 | - ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
346 | - ->setMediawikiScriptPath($mediawikiScriptPath) |
|
347 | - ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
348 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
349 | - ->setEnforceOAuth($enforceOAuth) |
|
350 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
351 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
352 | - ->setMiserModeLimit($requestLimitShowOnly) |
|
353 | - ->setRequestStates($availableRequestStates) |
|
354 | - ->setSquidList($squidIpList) |
|
355 | - ->setDefaultCreatedTemplateId($createdid) |
|
356 | - ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
357 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
358 | - ->setUserAgent($toolUserAgent) |
|
359 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
360 | - ->setUseOAuthSignup($useOauthSignup) |
|
361 | - ->setOAuthBaseUrl($oauthBaseUrl) |
|
362 | - ->setOAuthConsumerToken($oauthConsumerToken) |
|
363 | - ->setOAuthConsumerSecret($oauthSecretToken) |
|
364 | - ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
365 | - ->setDataClearInterval($dataclear_interval) |
|
366 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
367 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
368 | - ->setIrcNotificationType($ircBotNotificationType) |
|
369 | - ->setIrcNotificationsInstance($whichami) |
|
370 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
371 | - ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
372 | - ->setCreationBotUsername($creationBotUsername) |
|
373 | - ->setCreationBotPassword($creationBotPassword) |
|
374 | - ->setCurlCookieJar($curlCookieJar) |
|
375 | - ->setYubicoApiId($yubicoApiId) |
|
376 | - ->setYubicoApiKey($yubicoApiKey) |
|
377 | - ->setTotpEncryptionKey($totpEncryptionKey) |
|
378 | - ->setRegistrationAllowed($allowRegistration) |
|
379 | - ->setCspReportUri($cspReportUri); |
|
342 | + ->setFilePath(__DIR__) |
|
343 | + ->setDebuggingTraceEnabled($enableErrorTrace) |
|
344 | + ->setForceIdentification($forceIdentification) |
|
345 | + ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
346 | + ->setMediawikiScriptPath($mediawikiScriptPath) |
|
347 | + ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
348 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
349 | + ->setEnforceOAuth($enforceOAuth) |
|
350 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
351 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
352 | + ->setMiserModeLimit($requestLimitShowOnly) |
|
353 | + ->setRequestStates($availableRequestStates) |
|
354 | + ->setSquidList($squidIpList) |
|
355 | + ->setDefaultCreatedTemplateId($createdid) |
|
356 | + ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
357 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
358 | + ->setUserAgent($toolUserAgent) |
|
359 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
360 | + ->setUseOAuthSignup($useOauthSignup) |
|
361 | + ->setOAuthBaseUrl($oauthBaseUrl) |
|
362 | + ->setOAuthConsumerToken($oauthConsumerToken) |
|
363 | + ->setOAuthConsumerSecret($oauthSecretToken) |
|
364 | + ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
365 | + ->setDataClearInterval($dataclear_interval) |
|
366 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
367 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
368 | + ->setIrcNotificationType($ircBotNotificationType) |
|
369 | + ->setIrcNotificationsInstance($whichami) |
|
370 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
371 | + ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
372 | + ->setCreationBotUsername($creationBotUsername) |
|
373 | + ->setCreationBotPassword($creationBotPassword) |
|
374 | + ->setCurlCookieJar($curlCookieJar) |
|
375 | + ->setYubicoApiId($yubicoApiId) |
|
376 | + ->setYubicoApiKey($yubicoApiKey) |
|
377 | + ->setTotpEncryptionKey($totpEncryptionKey) |
|
378 | + ->setRegistrationAllowed($allowRegistration) |
|
379 | + ->setCspReportUri($cspReportUri); |
@@ -19,179 +19,179 @@ |
||
19 | 19 | |
20 | 20 | class PageEmailManagement extends InternalPageBase |
21 | 21 | { |
22 | - /** |
|
23 | - * Main function for this page, when no specific actions are called. |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $this->setHtmlTitle('Close Emails'); |
|
29 | - |
|
30 | - // Get all active email templates |
|
31 | - $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
32 | - $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
33 | - |
|
34 | - $this->assign('activeTemplates', $activeTemplates); |
|
35 | - $this->assign('inactiveTemplates', $inactiveTemplates); |
|
36 | - |
|
37 | - $user = User::getCurrent($this->getDatabase()); |
|
38 | - $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
39 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
40 | - |
|
41 | - $this->setTemplate('email-management/main.tpl'); |
|
42 | - } |
|
43 | - |
|
44 | - protected function view() |
|
45 | - { |
|
46 | - $this->setHtmlTitle('Close Emails'); |
|
47 | - |
|
48 | - $database = $this->getDatabase(); |
|
49 | - $template = $this->getTemplate($database); |
|
50 | - |
|
51 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
52 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
53 | - |
|
54 | - $this->assign('id', $template->getId()); |
|
55 | - $this->assign('emailTemplate', $template); |
|
56 | - $this->assign('createdid', $createdId); |
|
57 | - $this->assign('requeststates', $requestStates); |
|
58 | - |
|
59 | - $this->setTemplate('email-management/view.tpl'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param PdoDatabase $database |
|
64 | - * |
|
65 | - * @return EmailTemplate |
|
66 | - * @throws ApplicationLogicException |
|
67 | - */ |
|
68 | - protected function getTemplate(PdoDatabase $database) |
|
69 | - { |
|
70 | - $templateId = WebRequest::getInt('id'); |
|
71 | - if ($templateId === null) { |
|
72 | - throw new ApplicationLogicException('Template not specified'); |
|
73 | - } |
|
74 | - $template = EmailTemplate::getById($templateId, $database); |
|
75 | - if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
76 | - throw new ApplicationLogicException('Template not found'); |
|
77 | - } |
|
78 | - |
|
79 | - return $template; |
|
80 | - } |
|
81 | - |
|
82 | - protected function edit() |
|
83 | - { |
|
84 | - $this->setHtmlTitle('Close Emails'); |
|
85 | - |
|
86 | - $database = $this->getDatabase(); |
|
87 | - $template = $this->getTemplate($database); |
|
88 | - |
|
89 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
90 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
91 | - |
|
92 | - if (WebRequest::wasPosted()) { |
|
93 | - $this->validateCSRFToken(); |
|
94 | - |
|
95 | - $this->modifyTemplateData($template); |
|
96 | - |
|
97 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
98 | - if ($other !== false && $other->getId() !== $template->getId()) { |
|
99 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
100 | - } |
|
101 | - |
|
102 | - if ($template->getId() === $createdId) { |
|
103 | - $template->setDefaultAction(EmailTemplate::CREATED); |
|
104 | - $template->setActive(true); |
|
105 | - $template->setPreloadOnly(false); |
|
106 | - } |
|
107 | - |
|
108 | - // optimistically lock on load of edit form |
|
109 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
110 | - $template->setUpdateVersion($updateVersion); |
|
111 | - |
|
112 | - $template->save(); |
|
113 | - Logger::editedEmail($database, $template); |
|
114 | - $this->getNotificationHelper()->emailEdited($template); |
|
115 | - SessionAlert::success("Email template has been saved successfully."); |
|
116 | - |
|
117 | - $this->redirect('emailManagement'); |
|
118 | - } |
|
119 | - else { |
|
120 | - $this->assignCSRFToken(); |
|
121 | - $this->assign('id', $template->getId()); |
|
122 | - $this->assign('emailTemplate', $template); |
|
123 | - $this->assign('createdid', $createdId); |
|
124 | - $this->assign('requeststates', $requestStates); |
|
125 | - |
|
126 | - $this->setTemplate('email-management/edit.tpl'); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param EmailTemplate $template |
|
132 | - * |
|
133 | - * @throws ApplicationLogicException |
|
134 | - */ |
|
135 | - private function modifyTemplateData(EmailTemplate $template) |
|
136 | - { |
|
137 | - $name = WebRequest::postString('name'); |
|
138 | - if ($name === null || $name === '') { |
|
139 | - throw new ApplicationLogicException('Name not specified'); |
|
140 | - } |
|
141 | - |
|
142 | - $template->setName($name); |
|
143 | - |
|
144 | - $text = WebRequest::postString('text'); |
|
145 | - if ($text === null || $text === '') { |
|
146 | - throw new ApplicationLogicException('Text not specified'); |
|
147 | - } |
|
148 | - |
|
149 | - $template->setText($text); |
|
150 | - |
|
151 | - $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
152 | - |
|
153 | - $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
154 | - $template->setActive(WebRequest::postBoolean('active')); |
|
155 | - $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
156 | - } |
|
157 | - |
|
158 | - protected function create() |
|
159 | - { |
|
160 | - $this->setHtmlTitle('Close Emails'); |
|
161 | - |
|
162 | - $database = $this->getDatabase(); |
|
163 | - |
|
164 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
165 | - |
|
166 | - if (WebRequest::wasPosted()) { |
|
167 | - $this->validateCSRFToken(); |
|
168 | - $template = new EmailTemplate(); |
|
169 | - $template->setDatabase($database); |
|
170 | - |
|
171 | - $this->modifyTemplateData($template); |
|
172 | - |
|
173 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
174 | - if ($other !== false) { |
|
175 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
176 | - } |
|
177 | - |
|
178 | - $template->save(); |
|
179 | - |
|
180 | - Logger::createEmail($database, $template); |
|
181 | - $this->getNotificationHelper()->emailCreated($template); |
|
182 | - |
|
183 | - SessionAlert::success("Email template has been saved successfully."); |
|
184 | - |
|
185 | - $this->redirect('emailManagement'); |
|
186 | - } |
|
187 | - else { |
|
188 | - $this->assignCSRFToken(); |
|
189 | - $this->assign('id', -1); |
|
190 | - $this->assign('emailTemplate', new EmailTemplate()); |
|
191 | - $this->assign('createdid', -2); |
|
192 | - |
|
193 | - $this->assign('requeststates', $requestStates); |
|
194 | - $this->setTemplate('email-management/edit.tpl'); |
|
195 | - } |
|
196 | - } |
|
22 | + /** |
|
23 | + * Main function for this page, when no specific actions are called. |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $this->setHtmlTitle('Close Emails'); |
|
29 | + |
|
30 | + // Get all active email templates |
|
31 | + $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
32 | + $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
33 | + |
|
34 | + $this->assign('activeTemplates', $activeTemplates); |
|
35 | + $this->assign('inactiveTemplates', $inactiveTemplates); |
|
36 | + |
|
37 | + $user = User::getCurrent($this->getDatabase()); |
|
38 | + $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
39 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
40 | + |
|
41 | + $this->setTemplate('email-management/main.tpl'); |
|
42 | + } |
|
43 | + |
|
44 | + protected function view() |
|
45 | + { |
|
46 | + $this->setHtmlTitle('Close Emails'); |
|
47 | + |
|
48 | + $database = $this->getDatabase(); |
|
49 | + $template = $this->getTemplate($database); |
|
50 | + |
|
51 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
52 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
53 | + |
|
54 | + $this->assign('id', $template->getId()); |
|
55 | + $this->assign('emailTemplate', $template); |
|
56 | + $this->assign('createdid', $createdId); |
|
57 | + $this->assign('requeststates', $requestStates); |
|
58 | + |
|
59 | + $this->setTemplate('email-management/view.tpl'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param PdoDatabase $database |
|
64 | + * |
|
65 | + * @return EmailTemplate |
|
66 | + * @throws ApplicationLogicException |
|
67 | + */ |
|
68 | + protected function getTemplate(PdoDatabase $database) |
|
69 | + { |
|
70 | + $templateId = WebRequest::getInt('id'); |
|
71 | + if ($templateId === null) { |
|
72 | + throw new ApplicationLogicException('Template not specified'); |
|
73 | + } |
|
74 | + $template = EmailTemplate::getById($templateId, $database); |
|
75 | + if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
76 | + throw new ApplicationLogicException('Template not found'); |
|
77 | + } |
|
78 | + |
|
79 | + return $template; |
|
80 | + } |
|
81 | + |
|
82 | + protected function edit() |
|
83 | + { |
|
84 | + $this->setHtmlTitle('Close Emails'); |
|
85 | + |
|
86 | + $database = $this->getDatabase(); |
|
87 | + $template = $this->getTemplate($database); |
|
88 | + |
|
89 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
90 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
91 | + |
|
92 | + if (WebRequest::wasPosted()) { |
|
93 | + $this->validateCSRFToken(); |
|
94 | + |
|
95 | + $this->modifyTemplateData($template); |
|
96 | + |
|
97 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
98 | + if ($other !== false && $other->getId() !== $template->getId()) { |
|
99 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
100 | + } |
|
101 | + |
|
102 | + if ($template->getId() === $createdId) { |
|
103 | + $template->setDefaultAction(EmailTemplate::CREATED); |
|
104 | + $template->setActive(true); |
|
105 | + $template->setPreloadOnly(false); |
|
106 | + } |
|
107 | + |
|
108 | + // optimistically lock on load of edit form |
|
109 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
110 | + $template->setUpdateVersion($updateVersion); |
|
111 | + |
|
112 | + $template->save(); |
|
113 | + Logger::editedEmail($database, $template); |
|
114 | + $this->getNotificationHelper()->emailEdited($template); |
|
115 | + SessionAlert::success("Email template has been saved successfully."); |
|
116 | + |
|
117 | + $this->redirect('emailManagement'); |
|
118 | + } |
|
119 | + else { |
|
120 | + $this->assignCSRFToken(); |
|
121 | + $this->assign('id', $template->getId()); |
|
122 | + $this->assign('emailTemplate', $template); |
|
123 | + $this->assign('createdid', $createdId); |
|
124 | + $this->assign('requeststates', $requestStates); |
|
125 | + |
|
126 | + $this->setTemplate('email-management/edit.tpl'); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param EmailTemplate $template |
|
132 | + * |
|
133 | + * @throws ApplicationLogicException |
|
134 | + */ |
|
135 | + private function modifyTemplateData(EmailTemplate $template) |
|
136 | + { |
|
137 | + $name = WebRequest::postString('name'); |
|
138 | + if ($name === null || $name === '') { |
|
139 | + throw new ApplicationLogicException('Name not specified'); |
|
140 | + } |
|
141 | + |
|
142 | + $template->setName($name); |
|
143 | + |
|
144 | + $text = WebRequest::postString('text'); |
|
145 | + if ($text === null || $text === '') { |
|
146 | + throw new ApplicationLogicException('Text not specified'); |
|
147 | + } |
|
148 | + |
|
149 | + $template->setText($text); |
|
150 | + |
|
151 | + $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
152 | + |
|
153 | + $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
154 | + $template->setActive(WebRequest::postBoolean('active')); |
|
155 | + $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
156 | + } |
|
157 | + |
|
158 | + protected function create() |
|
159 | + { |
|
160 | + $this->setHtmlTitle('Close Emails'); |
|
161 | + |
|
162 | + $database = $this->getDatabase(); |
|
163 | + |
|
164 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
165 | + |
|
166 | + if (WebRequest::wasPosted()) { |
|
167 | + $this->validateCSRFToken(); |
|
168 | + $template = new EmailTemplate(); |
|
169 | + $template->setDatabase($database); |
|
170 | + |
|
171 | + $this->modifyTemplateData($template); |
|
172 | + |
|
173 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
174 | + if ($other !== false) { |
|
175 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
176 | + } |
|
177 | + |
|
178 | + $template->save(); |
|
179 | + |
|
180 | + Logger::createEmail($database, $template); |
|
181 | + $this->getNotificationHelper()->emailCreated($template); |
|
182 | + |
|
183 | + SessionAlert::success("Email template has been saved successfully."); |
|
184 | + |
|
185 | + $this->redirect('emailManagement'); |
|
186 | + } |
|
187 | + else { |
|
188 | + $this->assignCSRFToken(); |
|
189 | + $this->assign('id', -1); |
|
190 | + $this->assign('emailTemplate', new EmailTemplate()); |
|
191 | + $this->assign('createdid', -2); |
|
192 | + |
|
193 | + $this->assign('requeststates', $requestStates); |
|
194 | + $this->setTemplate('email-management/edit.tpl'); |
|
195 | + } |
|
196 | + } |
|
197 | 197 | } |
@@ -16,12 +16,12 @@ |
||
16 | 16 | */ |
17 | 17 | interface IXmlApiAction extends IRoutedTask, IApiAction |
18 | 18 | { |
19 | - /** |
|
20 | - * Method that runs API action |
|
21 | - * |
|
22 | - * @param DOMElement $apiDocument |
|
23 | - * |
|
24 | - * @return DOMElement The modified API document |
|
25 | - */ |
|
26 | - public function executeApiAction(DOMElement $apiDocument); |
|
19 | + /** |
|
20 | + * Method that runs API action |
|
21 | + * |
|
22 | + * @param DOMElement $apiDocument |
|
23 | + * |
|
24 | + * @return DOMElement The modified API document |
|
25 | + */ |
|
26 | + public function executeApiAction(DOMElement $apiDocument); |
|
27 | 27 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | */ |
16 | 16 | interface IJsonApiAction extends IRoutedTask, IApiAction |
17 | 17 | { |
18 | - /** |
|
19 | - * Method that runs API action |
|
20 | - * |
|
21 | - * @return object|array The modified API document |
|
22 | - */ |
|
23 | - public function executeApiAction(); |
|
18 | + /** |
|
19 | + * Method that runs API action |
|
20 | + * |
|
21 | + * @return object|array The modified API document |
|
22 | + */ |
|
23 | + public function executeApiAction(); |
|
24 | 24 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | */ |
17 | 17 | class UnknownAction extends HelpAction implements IXmlApiAction |
18 | 18 | { |
19 | - public function executeApiAction(DOMElement $apiDocument) |
|
20 | - { |
|
21 | - $errorText = "Unknown API action specified."; |
|
22 | - $errorNode = $this->document->createElement("error", $errorText); |
|
23 | - $apiDocument->appendChild($errorNode); |
|
19 | + public function executeApiAction(DOMElement $apiDocument) |
|
20 | + { |
|
21 | + $errorText = "Unknown API action specified."; |
|
22 | + $errorNode = $this->document->createElement("error", $errorText); |
|
23 | + $apiDocument->appendChild($errorNode); |
|
24 | 24 | |
25 | - $helpElement = $this->getHelpElement(); |
|
26 | - $apiDocument->appendChild($helpElement); |
|
25 | + $helpElement = $this->getHelpElement(); |
|
26 | + $apiDocument->appendChild($helpElement); |
|
27 | 27 | |
28 | - return $apiDocument; |
|
29 | - } |
|
28 | + return $apiDocument; |
|
29 | + } |
|
30 | 30 | } |
@@ -16,18 +16,18 @@ |
||
16 | 16 | |
17 | 17 | class JsUsersAction extends JsonApiPageBase implements IJsonApiAction |
18 | 18 | { |
19 | - public function executeApiAction() |
|
20 | - { |
|
21 | - $this->getDatabase(); |
|
19 | + public function executeApiAction() |
|
20 | + { |
|
21 | + $this->getDatabase(); |
|
22 | 22 | |
23 | - $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
23 | + $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
24 | 24 | |
25 | - if (WebRequest::getString('all') === null) { |
|
26 | - $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
25 | + if (WebRequest::getString('all') === null) { |
|
26 | + $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | - return $dataset; |
|
32 | - } |
|
30 | + $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | + return $dataset; |
|
32 | + } |
|
33 | 33 | } |