@@ -12,17 +12,17 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageRequestSubmitted extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - // clear any requests for client hints. Should have been done already prior to |
|
| 22 | - // email confirmation, but this catches the case where email confirmation is |
|
| 23 | - // disabled. |
|
| 24 | - $this->headerQueue[] = "Accept-CH:"; |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + // clear any requests for client hints. Should have been done already prior to |
|
| 22 | + // email confirmation, but this catches the case where email confirmation is |
|
| 23 | + // disabled. |
|
| 24 | + $this->headerQueue[] = "Accept-CH:"; |
|
| 25 | 25 | |
| 26 | - $this->setTemplate('request/email-confirmed.tpl'); |
|
| 27 | - } |
|
| 26 | + $this->setTemplate('request/email-confirmed.tpl'); |
|
| 27 | + } |
|
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -27,316 +27,316 @@ |
||
| 27 | 27 | |
| 28 | 28 | class PageRequestAccount extends PublicInterfacePageBase |
| 29 | 29 | { |
| 30 | - /** @var RequestValidationHelper do not use directly. */ |
|
| 31 | - private $validationHelper; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Main function for this page, when no specific actions are called. |
|
| 35 | - * @return void |
|
| 36 | - * @throws OptimisticLockFailedException |
|
| 37 | - * @throws Exception |
|
| 38 | - */ |
|
| 39 | - protected function main() |
|
| 40 | - { |
|
| 41 | - // dual mode page |
|
| 42 | - if (WebRequest::wasPosted()) { |
|
| 43 | - $request = $this->createNewRequest(null); |
|
| 44 | - $this->handleFormPost($request); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - $this->requestClientHints(); |
|
| 48 | - $this->handleFormRefilling(); |
|
| 49 | - |
|
| 50 | - $this->setTemplate('request/request-form.tpl'); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Handles dynamic request forms. |
|
| 56 | - * @return void |
|
| 57 | - * @throws OptimisticLockFailedException |
|
| 58 | - * @throws Exception |
|
| 59 | - */ |
|
| 60 | - protected function dynamic() |
|
| 61 | - { |
|
| 62 | - $database = $this->getDatabase(); |
|
| 63 | - |
|
| 64 | - $pathInfo = WebRequest::pathInfo(); |
|
| 65 | - $domain = Domain::getByShortName($pathInfo[1], $database); |
|
| 66 | - if ($domain === false || !$domain->isEnabled()) { |
|
| 67 | - throw new ApplicationLogicException("This form is not available at this time."); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $form = RequestForm::getByPublicEndpoint($database, $pathInfo[2], $domain->getId()); |
|
| 71 | - |
|
| 72 | - if ($form === false || !$form->isEnabled()) { |
|
| 73 | - throw new ApplicationLogicException("This form is not available at this time."); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // dual mode page |
|
| 77 | - if (WebRequest::wasPosted()) { |
|
| 78 | - $request = $this->createNewRequest($form); |
|
| 79 | - $this->handleFormPost($request); |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $this->requestClientHints(); |
|
| 83 | - $this->handleFormRefilling(); |
|
| 84 | - |
|
| 85 | - $renderer = new MarkdownRenderingHelper(); |
|
| 86 | - $this->assign('formPreamble', $renderer->doRender($form->getFormContent())); |
|
| 87 | - $this->assign('formUsernameHelp', $renderer->doRenderInline($form->getUsernameHelp())); |
|
| 88 | - $this->assign('formEmailHelp', $renderer->doRenderInline($form->getEmailHelp())); |
|
| 89 | - $this->assign('formCommentsHelp', $renderer->doRenderInline($form->getCommentHelp())); |
|
| 90 | - |
|
| 91 | - $this->setTemplate('request/request-form-dynamic.tpl'); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param RequestForm|null $form |
|
| 97 | - * |
|
| 98 | - * @return Request |
|
| 99 | - * @throws ApplicationLogicException |
|
| 100 | - */ |
|
| 101 | - protected function createNewRequest(?RequestForm $form): Request |
|
| 102 | - { |
|
| 103 | - $database = $this->getDatabase(); |
|
| 104 | - |
|
| 105 | - $request = new Request(); |
|
| 106 | - |
|
| 107 | - if ($form === null) { |
|
| 108 | - $domain = 1; |
|
| 109 | - } |
|
| 110 | - else { |
|
| 111 | - $domain = $form->getDomain(); |
|
| 112 | - $request->setOriginForm($form->getId()); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $request->setQueue(RequestQueue::getDefaultQueue($database, $domain)->getId()); |
|
| 116 | - $request->setDatabase($database); |
|
| 117 | - $request->setDomain($domain); |
|
| 118 | - |
|
| 119 | - $request->setName(trim(WebRequest::postString('name'))); |
|
| 120 | - $request->setEmail(WebRequest::postEmail('email')); |
|
| 121 | - |
|
| 122 | - $request->setIp(WebRequest::remoteAddress()); |
|
| 123 | - $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 124 | - |
|
| 125 | - $request->setUserAgent(WebRequest::userAgent()); |
|
| 126 | - |
|
| 127 | - return $request; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return Comment|null |
|
| 132 | - */ |
|
| 133 | - private function createComment() |
|
| 134 | - { |
|
| 135 | - $commentText = WebRequest::postString('comments'); |
|
| 136 | - if ($commentText === null || trim($commentText) === '') { |
|
| 137 | - return null; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $comment = new Comment(); |
|
| 141 | - $comment->setDatabase($this->getDatabase()); |
|
| 142 | - |
|
| 143 | - $comment->setVisibility('requester'); |
|
| 144 | - $comment->setUser(null); |
|
| 145 | - $comment->setComment($commentText); |
|
| 146 | - |
|
| 147 | - return $comment; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param Request $request |
|
| 152 | - * |
|
| 153 | - * @return ValidationError[] |
|
| 154 | - */ |
|
| 155 | - protected function validateRequest($request) |
|
| 156 | - { |
|
| 157 | - $validationHelper = $this->getRequestValidationHelper(); |
|
| 158 | - |
|
| 159 | - // These are arrays of ValidationError. |
|
| 160 | - $nameValidation = $validationHelper->validateName($request); |
|
| 161 | - $emailValidation = $validationHelper->validateEmail($request, WebRequest::postEmail('emailconfirm')); |
|
| 162 | - $otherValidation = $validationHelper->validateOther($request); |
|
| 163 | - |
|
| 164 | - $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 165 | - |
|
| 166 | - return $validationErrors; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param Request $request |
|
| 171 | - * |
|
| 172 | - * @param Comment|null $comment |
|
| 173 | - * |
|
| 174 | - * @throws OptimisticLockFailedException |
|
| 175 | - * @throws Exception |
|
| 176 | - */ |
|
| 177 | - protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 178 | - { |
|
| 179 | - $request->generateEmailConfirmationHash(); |
|
| 180 | - $request->save(); |
|
| 181 | - |
|
| 182 | - if ($comment !== null) { |
|
| 183 | - $comment->setRequest($request->getId()); |
|
| 184 | - $comment->save(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 188 | - $request->getIp(), |
|
| 189 | - $request->getForwardedIp()); |
|
| 190 | - |
|
| 191 | - $this->assign("ip", $trustedIp); |
|
| 192 | - $this->assign("id", $request->getId()); |
|
| 193 | - $this->assign("hash", $request->getEmailConfirm()); |
|
| 194 | - |
|
| 195 | - // Sends the confirmation email to the user. |
|
| 196 | - // FIXME: domains |
|
| 197 | - /** @var Domain $domain */ |
|
| 198 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 199 | - $this->getEmailHelper()->sendMail( |
|
| 200 | - $domain->getEmailReplyAddress(), |
|
| 201 | - $request->getEmail(), |
|
| 202 | - "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 203 | - $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 204 | - |
|
| 205 | - $this->redirect('emailConfirmationRequired'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param Request $request |
|
| 210 | - * |
|
| 211 | - * @param Comment|null $comment |
|
| 212 | - * |
|
| 213 | - * @throws OptimisticLockFailedException |
|
| 214 | - * @throws Exception |
|
| 215 | - */ |
|
| 216 | - protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 217 | - { |
|
| 218 | - $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 219 | - $request->save(); |
|
| 220 | - |
|
| 221 | - if ($comment !== null) { |
|
| 222 | - $comment->setRequest($request->getId()); |
|
| 223 | - $comment->save(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 227 | - |
|
| 228 | - $this->redirect('requestSubmitted'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @return RequestValidationHelper |
|
| 233 | - */ |
|
| 234 | - protected function getRequestValidationHelper(): RequestValidationHelper |
|
| 235 | - { |
|
| 236 | - $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), null); |
|
| 237 | - |
|
| 238 | - if ($this->validationHelper === null) { |
|
| 239 | - $this->validationHelper = new RequestValidationHelper( |
|
| 240 | - $banHelper, |
|
| 241 | - $this->getDatabase(), |
|
| 242 | - $this->getAntiSpoofProvider(), |
|
| 243 | - $this->getXffTrustProvider(), |
|
| 244 | - $this->getHttpHelper(), |
|
| 245 | - $this->getTorExitProvider(), |
|
| 246 | - $this->getSiteConfiguration()); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $this->validationHelper; |
|
| 30 | + /** @var RequestValidationHelper do not use directly. */ |
|
| 31 | + private $validationHelper; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Main function for this page, when no specific actions are called. |
|
| 35 | + * @return void |
|
| 36 | + * @throws OptimisticLockFailedException |
|
| 37 | + * @throws Exception |
|
| 38 | + */ |
|
| 39 | + protected function main() |
|
| 40 | + { |
|
| 41 | + // dual mode page |
|
| 42 | + if (WebRequest::wasPosted()) { |
|
| 43 | + $request = $this->createNewRequest(null); |
|
| 44 | + $this->handleFormPost($request); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + $this->requestClientHints(); |
|
| 48 | + $this->handleFormRefilling(); |
|
| 49 | + |
|
| 50 | + $this->setTemplate('request/request-form.tpl'); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Handles dynamic request forms. |
|
| 56 | + * @return void |
|
| 57 | + * @throws OptimisticLockFailedException |
|
| 58 | + * @throws Exception |
|
| 59 | + */ |
|
| 60 | + protected function dynamic() |
|
| 61 | + { |
|
| 62 | + $database = $this->getDatabase(); |
|
| 63 | + |
|
| 64 | + $pathInfo = WebRequest::pathInfo(); |
|
| 65 | + $domain = Domain::getByShortName($pathInfo[1], $database); |
|
| 66 | + if ($domain === false || !$domain->isEnabled()) { |
|
| 67 | + throw new ApplicationLogicException("This form is not available at this time."); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $form = RequestForm::getByPublicEndpoint($database, $pathInfo[2], $domain->getId()); |
|
| 71 | + |
|
| 72 | + if ($form === false || !$form->isEnabled()) { |
|
| 73 | + throw new ApplicationLogicException("This form is not available at this time."); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // dual mode page |
|
| 77 | + if (WebRequest::wasPosted()) { |
|
| 78 | + $request = $this->createNewRequest($form); |
|
| 79 | + $this->handleFormPost($request); |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $this->requestClientHints(); |
|
| 83 | + $this->handleFormRefilling(); |
|
| 84 | + |
|
| 85 | + $renderer = new MarkdownRenderingHelper(); |
|
| 86 | + $this->assign('formPreamble', $renderer->doRender($form->getFormContent())); |
|
| 87 | + $this->assign('formUsernameHelp', $renderer->doRenderInline($form->getUsernameHelp())); |
|
| 88 | + $this->assign('formEmailHelp', $renderer->doRenderInline($form->getEmailHelp())); |
|
| 89 | + $this->assign('formCommentsHelp', $renderer->doRenderInline($form->getCommentHelp())); |
|
| 90 | + |
|
| 91 | + $this->setTemplate('request/request-form-dynamic.tpl'); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param RequestForm|null $form |
|
| 97 | + * |
|
| 98 | + * @return Request |
|
| 99 | + * @throws ApplicationLogicException |
|
| 100 | + */ |
|
| 101 | + protected function createNewRequest(?RequestForm $form): Request |
|
| 102 | + { |
|
| 103 | + $database = $this->getDatabase(); |
|
| 104 | + |
|
| 105 | + $request = new Request(); |
|
| 106 | + |
|
| 107 | + if ($form === null) { |
|
| 108 | + $domain = 1; |
|
| 109 | + } |
|
| 110 | + else { |
|
| 111 | + $domain = $form->getDomain(); |
|
| 112 | + $request->setOriginForm($form->getId()); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $request->setQueue(RequestQueue::getDefaultQueue($database, $domain)->getId()); |
|
| 116 | + $request->setDatabase($database); |
|
| 117 | + $request->setDomain($domain); |
|
| 118 | + |
|
| 119 | + $request->setName(trim(WebRequest::postString('name'))); |
|
| 120 | + $request->setEmail(WebRequest::postEmail('email')); |
|
| 121 | + |
|
| 122 | + $request->setIp(WebRequest::remoteAddress()); |
|
| 123 | + $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 124 | + |
|
| 125 | + $request->setUserAgent(WebRequest::userAgent()); |
|
| 126 | + |
|
| 127 | + return $request; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return Comment|null |
|
| 132 | + */ |
|
| 133 | + private function createComment() |
|
| 134 | + { |
|
| 135 | + $commentText = WebRequest::postString('comments'); |
|
| 136 | + if ($commentText === null || trim($commentText) === '') { |
|
| 137 | + return null; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $comment = new Comment(); |
|
| 141 | + $comment->setDatabase($this->getDatabase()); |
|
| 142 | + |
|
| 143 | + $comment->setVisibility('requester'); |
|
| 144 | + $comment->setUser(null); |
|
| 145 | + $comment->setComment($commentText); |
|
| 146 | + |
|
| 147 | + return $comment; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param Request $request |
|
| 152 | + * |
|
| 153 | + * @return ValidationError[] |
|
| 154 | + */ |
|
| 155 | + protected function validateRequest($request) |
|
| 156 | + { |
|
| 157 | + $validationHelper = $this->getRequestValidationHelper(); |
|
| 158 | + |
|
| 159 | + // These are arrays of ValidationError. |
|
| 160 | + $nameValidation = $validationHelper->validateName($request); |
|
| 161 | + $emailValidation = $validationHelper->validateEmail($request, WebRequest::postEmail('emailconfirm')); |
|
| 162 | + $otherValidation = $validationHelper->validateOther($request); |
|
| 163 | + |
|
| 164 | + $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 165 | + |
|
| 166 | + return $validationErrors; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param Request $request |
|
| 171 | + * |
|
| 172 | + * @param Comment|null $comment |
|
| 173 | + * |
|
| 174 | + * @throws OptimisticLockFailedException |
|
| 175 | + * @throws Exception |
|
| 176 | + */ |
|
| 177 | + protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 178 | + { |
|
| 179 | + $request->generateEmailConfirmationHash(); |
|
| 180 | + $request->save(); |
|
| 181 | + |
|
| 182 | + if ($comment !== null) { |
|
| 183 | + $comment->setRequest($request->getId()); |
|
| 184 | + $comment->save(); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 188 | + $request->getIp(), |
|
| 189 | + $request->getForwardedIp()); |
|
| 190 | + |
|
| 191 | + $this->assign("ip", $trustedIp); |
|
| 192 | + $this->assign("id", $request->getId()); |
|
| 193 | + $this->assign("hash", $request->getEmailConfirm()); |
|
| 194 | + |
|
| 195 | + // Sends the confirmation email to the user. |
|
| 196 | + // FIXME: domains |
|
| 197 | + /** @var Domain $domain */ |
|
| 198 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 199 | + $this->getEmailHelper()->sendMail( |
|
| 200 | + $domain->getEmailReplyAddress(), |
|
| 201 | + $request->getEmail(), |
|
| 202 | + "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 203 | + $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 204 | + |
|
| 205 | + $this->redirect('emailConfirmationRequired'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param Request $request |
|
| 210 | + * |
|
| 211 | + * @param Comment|null $comment |
|
| 212 | + * |
|
| 213 | + * @throws OptimisticLockFailedException |
|
| 214 | + * @throws Exception |
|
| 215 | + */ |
|
| 216 | + protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 217 | + { |
|
| 218 | + $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 219 | + $request->save(); |
|
| 220 | + |
|
| 221 | + if ($comment !== null) { |
|
| 222 | + $comment->setRequest($request->getId()); |
|
| 223 | + $comment->save(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 227 | + |
|
| 228 | + $this->redirect('requestSubmitted'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @return RequestValidationHelper |
|
| 233 | + */ |
|
| 234 | + protected function getRequestValidationHelper(): RequestValidationHelper |
|
| 235 | + { |
|
| 236 | + $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), null); |
|
| 237 | + |
|
| 238 | + if ($this->validationHelper === null) { |
|
| 239 | + $this->validationHelper = new RequestValidationHelper( |
|
| 240 | + $banHelper, |
|
| 241 | + $this->getDatabase(), |
|
| 242 | + $this->getAntiSpoofProvider(), |
|
| 243 | + $this->getXffTrustProvider(), |
|
| 244 | + $this->getHttpHelper(), |
|
| 245 | + $this->getTorExitProvider(), |
|
| 246 | + $this->getSiteConfiguration()); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $this->validationHelper; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @param Request $request |
|
| 254 | - * |
|
| 255 | - * @return void |
|
| 256 | - * @throws OptimisticLockFailedException |
|
| 257 | - */ |
|
| 258 | - protected function handleFormPost(Request $request): void |
|
| 259 | - { |
|
| 260 | - $comment = $this->createComment(); |
|
| 261 | - |
|
| 262 | - $validationErrors = $this->validateRequest($request); |
|
| 263 | - |
|
| 264 | - if (count($validationErrors) > 0) { |
|
| 265 | - foreach ($validationErrors as $validationError) { |
|
| 266 | - SessionAlert::error($validationError->getErrorMessage()); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Preserve the data after an error |
|
| 270 | - WebRequest::setSessionContext('accountReq', |
|
| 271 | - array( |
|
| 272 | - 'username' => WebRequest::postString('name'), |
|
| 273 | - 'email' => WebRequest::postEmail('email'), |
|
| 274 | - 'comments' => WebRequest::postString('comments'), |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - |
|
| 278 | - // Validation error, bomb out early. |
|
| 279 | - $this->redirect(); |
|
| 280 | - |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // actually save the request to the database |
|
| 285 | - if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 286 | - $this->saveAsEmailConfirmation($request, $comment); |
|
| 287 | - $this->savePrivateData($request); |
|
| 288 | - } |
|
| 289 | - else { |
|
| 290 | - $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 291 | - $this->savePrivateData($request); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $this->getRequestValidationHelper()->postSaveValidations($request); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return void |
|
| 299 | - */ |
|
| 300 | - protected function handleFormRefilling(): void |
|
| 301 | - { |
|
| 302 | - // set the form values from the session context |
|
| 303 | - $context = WebRequest::getSessionContext('accountReq'); |
|
| 304 | - if ($context !== null && is_array($context)) { |
|
| 305 | - $this->assign('username', $context['username']); |
|
| 306 | - $this->assign('email', $context['email']); |
|
| 307 | - $this->assign('comments', $context['comments']); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Clear it for a refresh |
|
| 311 | - WebRequest::setSessionContext('accountReq', null); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - private function requestClientHints() |
|
| 315 | - { |
|
| 316 | - $hints = $this->getSiteConfiguration()->getAcceptClientHints(); |
|
| 317 | - |
|
| 318 | - $this->headerQueue[] = "Accept-CH: " . implode(', ', $hints); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - private function savePrivateData(Request $request) |
|
| 322 | - { |
|
| 323 | - foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) |
|
| 324 | - { |
|
| 325 | - $value = WebRequest::httpHeader($header); |
|
| 326 | - |
|
| 327 | - if($value === null){ |
|
| 328 | - continue; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $d = new RequestData(); |
|
| 332 | - $d->setDatabase($request->getDatabase()); |
|
| 333 | - $d->setRequest($request->getId()); |
|
| 334 | - |
|
| 335 | - $d->setType(RequestData::TYPE_CLIENTHINT); |
|
| 336 | - $d->setName($header); |
|
| 337 | - $d->setValue(WebRequest::httpHeader($header)); |
|
| 338 | - |
|
| 339 | - $d->save(); |
|
| 340 | - } |
|
| 341 | - } |
|
| 252 | + /** |
|
| 253 | + * @param Request $request |
|
| 254 | + * |
|
| 255 | + * @return void |
|
| 256 | + * @throws OptimisticLockFailedException |
|
| 257 | + */ |
|
| 258 | + protected function handleFormPost(Request $request): void |
|
| 259 | + { |
|
| 260 | + $comment = $this->createComment(); |
|
| 261 | + |
|
| 262 | + $validationErrors = $this->validateRequest($request); |
|
| 263 | + |
|
| 264 | + if (count($validationErrors) > 0) { |
|
| 265 | + foreach ($validationErrors as $validationError) { |
|
| 266 | + SessionAlert::error($validationError->getErrorMessage()); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Preserve the data after an error |
|
| 270 | + WebRequest::setSessionContext('accountReq', |
|
| 271 | + array( |
|
| 272 | + 'username' => WebRequest::postString('name'), |
|
| 273 | + 'email' => WebRequest::postEmail('email'), |
|
| 274 | + 'comments' => WebRequest::postString('comments'), |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + |
|
| 278 | + // Validation error, bomb out early. |
|
| 279 | + $this->redirect(); |
|
| 280 | + |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // actually save the request to the database |
|
| 285 | + if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 286 | + $this->saveAsEmailConfirmation($request, $comment); |
|
| 287 | + $this->savePrivateData($request); |
|
| 288 | + } |
|
| 289 | + else { |
|
| 290 | + $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 291 | + $this->savePrivateData($request); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $this->getRequestValidationHelper()->postSaveValidations($request); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return void |
|
| 299 | + */ |
|
| 300 | + protected function handleFormRefilling(): void |
|
| 301 | + { |
|
| 302 | + // set the form values from the session context |
|
| 303 | + $context = WebRequest::getSessionContext('accountReq'); |
|
| 304 | + if ($context !== null && is_array($context)) { |
|
| 305 | + $this->assign('username', $context['username']); |
|
| 306 | + $this->assign('email', $context['email']); |
|
| 307 | + $this->assign('comments', $context['comments']); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Clear it for a refresh |
|
| 311 | + WebRequest::setSessionContext('accountReq', null); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + private function requestClientHints() |
|
| 315 | + { |
|
| 316 | + $hints = $this->getSiteConfiguration()->getAcceptClientHints(); |
|
| 317 | + |
|
| 318 | + $this->headerQueue[] = "Accept-CH: " . implode(', ', $hints); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + private function savePrivateData(Request $request) |
|
| 322 | + { |
|
| 323 | + foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) |
|
| 324 | + { |
|
| 325 | + $value = WebRequest::httpHeader($header); |
|
| 326 | + |
|
| 327 | + if($value === null){ |
|
| 328 | + continue; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $d = new RequestData(); |
|
| 332 | + $d->setDatabase($request->getDatabase()); |
|
| 333 | + $d->setRequest($request->getId()); |
|
| 334 | + |
|
| 335 | + $d->setType(RequestData::TYPE_CLIENTHINT); |
|
| 336 | + $d->setName($header); |
|
| 337 | + $d->setValue(WebRequest::httpHeader($header)); |
|
| 338 | + |
|
| 339 | + $d->save(); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | \ No newline at end of file |
@@ -19,70 +19,70 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageConfirmEmail extends PublicInterfacePageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Main function for this page, when no specific actions are called. |
|
| 24 | - * @throws ApplicationLogicException |
|
| 25 | - * @throws Exception |
|
| 26 | - */ |
|
| 27 | - protected function main() |
|
| 28 | - { |
|
| 29 | - $id = WebRequest::getInt('id'); |
|
| 30 | - $si = WebRequest::getString('si'); |
|
| 31 | - |
|
| 32 | - if ($id === null || $si === null) { |
|
| 33 | - throw new ApplicationLogicException('Link incomplete - please double check the link you received.'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** @var Request|false $request */ |
|
| 37 | - $request = Request::getById($id, $this->getDatabase()); |
|
| 38 | - |
|
| 39 | - if ($request === false) { |
|
| 40 | - throw new ApplicationLogicException('Request not found'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 44 | - // request has already been confirmed. Bomb out silently. |
|
| 45 | - $this->redirect('requestSubmitted'); |
|
| 46 | - |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if ($request->getEmailConfirm() === $si) { |
|
| 51 | - $request->setEmailConfirm('Confirmed'); |
|
| 52 | - } |
|
| 53 | - else { |
|
| 54 | - throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - try { |
|
| 58 | - $request->save(); |
|
| 59 | - } |
|
| 60 | - catch (OptimisticLockFailedException $ex) { |
|
| 61 | - // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting |
|
| 62 | - // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they |
|
| 63 | - // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the |
|
| 64 | - // case. |
|
| 65 | - |
|
| 66 | - $request = Request::getById($id, $this->getDatabase()); |
|
| 67 | - if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 68 | - // we've already done the sanity checks above |
|
| 69 | - |
|
| 70 | - $this->redirect('requestSubmitted'); |
|
| 71 | - |
|
| 72 | - // skip the log and notification |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // something really weird happened. Another race condition? |
|
| 77 | - throw $ex; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - Logger::emailConfirmed($this->getDatabase(), $request); |
|
| 81 | - |
|
| 82 | - if ($request->getStatus() != RequestStatus::CLOSED) { |
|
| 83 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->redirect('requestSubmitted'); |
|
| 87 | - } |
|
| 22 | + /** |
|
| 23 | + * Main function for this page, when no specific actions are called. |
|
| 24 | + * @throws ApplicationLogicException |
|
| 25 | + * @throws Exception |
|
| 26 | + */ |
|
| 27 | + protected function main() |
|
| 28 | + { |
|
| 29 | + $id = WebRequest::getInt('id'); |
|
| 30 | + $si = WebRequest::getString('si'); |
|
| 31 | + |
|
| 32 | + if ($id === null || $si === null) { |
|
| 33 | + throw new ApplicationLogicException('Link incomplete - please double check the link you received.'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** @var Request|false $request */ |
|
| 37 | + $request = Request::getById($id, $this->getDatabase()); |
|
| 38 | + |
|
| 39 | + if ($request === false) { |
|
| 40 | + throw new ApplicationLogicException('Request not found'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 44 | + // request has already been confirmed. Bomb out silently. |
|
| 45 | + $this->redirect('requestSubmitted'); |
|
| 46 | + |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if ($request->getEmailConfirm() === $si) { |
|
| 51 | + $request->setEmailConfirm('Confirmed'); |
|
| 52 | + } |
|
| 53 | + else { |
|
| 54 | + throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + try { |
|
| 58 | + $request->save(); |
|
| 59 | + } |
|
| 60 | + catch (OptimisticLockFailedException $ex) { |
|
| 61 | + // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting |
|
| 62 | + // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they |
|
| 63 | + // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the |
|
| 64 | + // case. |
|
| 65 | + |
|
| 66 | + $request = Request::getById($id, $this->getDatabase()); |
|
| 67 | + if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 68 | + // we've already done the sanity checks above |
|
| 69 | + |
|
| 70 | + $this->redirect('requestSubmitted'); |
|
| 71 | + |
|
| 72 | + // skip the log and notification |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // something really weird happened. Another race condition? |
|
| 77 | + throw $ex; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + Logger::emailConfirmed($this->getDatabase(), $request); |
|
| 81 | + |
|
| 82 | + if ($request->getStatus() != RequestStatus::CLOSED) { |
|
| 83 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->redirect('requestSubmitted'); |
|
| 87 | + } |
|
| 88 | 88 | } |
| 89 | 89 | \ No newline at end of file |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageEmailConfirmationRequired extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - // clear any requests for client hints |
|
| 22 | - $this->headerQueue[] = "Accept-CH:"; |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + // clear any requests for client hints |
|
| 22 | + $this->headerQueue[] = "Accept-CH:"; |
|
| 23 | 23 | |
| 24 | - $this->setTemplate('request/email-confirmation.tpl'); |
|
| 25 | - } |
|
| 24 | + $this->setTemplate('request/email-confirmation.tpl'); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -21,159 +21,159 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageEditComment extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - * @throws ApplicationLogicException |
|
| 27 | - * @throws Exception |
|
| 28 | - */ |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $commentId = WebRequest::getInt('id'); |
|
| 32 | - if ($commentId === null) { |
|
| 33 | - throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $database = $this->getDatabase(); |
|
| 37 | - |
|
| 38 | - /** @var Comment|false $comment */ |
|
| 39 | - $comment = Comment::getById($commentId, $database); |
|
| 40 | - if ($comment === false) { |
|
| 41 | - throw new ApplicationLogicException('Comment not found'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $currentUser = User::getCurrent($database); |
|
| 45 | - |
|
| 46 | - $this->checkCommentAccess($comment, $currentUser); |
|
| 47 | - |
|
| 48 | - /** @var Request|false $request */ |
|
| 49 | - $request = Request::getById($comment->getRequest(), $database); |
|
| 50 | - |
|
| 51 | - if ($request === false) { |
|
| 52 | - throw new ApplicationLogicException('Request was not found.'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 56 | - |
|
| 57 | - if (WebRequest::wasPosted()) { |
|
| 58 | - $this->validateCSRFToken(); |
|
| 59 | - $newComment = WebRequest::postString('newcomment'); |
|
| 60 | - $visibility = WebRequest::postString('visibility'); |
|
| 61 | - $doUnflag = WebRequest::postBoolean('unflag'); |
|
| 62 | - |
|
| 63 | - if ($newComment === null || $newComment === '') { |
|
| 64 | - throw new ApplicationLogicException('Comment cannot be empty!'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $commentDataUnchanged = $newComment === $comment->getComment() |
|
| 68 | - && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
| 69 | - $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
| 70 | - |
|
| 71 | - if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
| 72 | - // No change was made; redirect back. |
|
| 73 | - $this->redirectBack($comment->getRequest()); |
|
| 74 | - |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // optimistically lock from the load of the edit comment form |
|
| 79 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 80 | - |
|
| 81 | - // comment data has changed, update the object |
|
| 82 | - if (!$commentDataUnchanged) { |
|
| 83 | - $this->updateCommentData($comment, $visibility, $newComment); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($doUnflag && $canUnflag) { |
|
| 87 | - $comment->setFlagged(false); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $comment->setUpdateVersion($updateVersion); |
|
| 91 | - $comment->save(); |
|
| 92 | - |
|
| 93 | - if (!$commentDataUnchanged) { |
|
| 94 | - Logger::editComment($database, $comment, $request); |
|
| 95 | - $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if ($doUnflag && $canUnflag) { |
|
| 99 | - Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - SessionAlert::success('Comment has been saved successfully'); |
|
| 103 | - $this->redirectBack($comment->getRequest()); |
|
| 104 | - } |
|
| 105 | - else { |
|
| 106 | - $this->assignCSRFToken(); |
|
| 107 | - $this->assign('comment', $comment); |
|
| 108 | - $this->assign('request', $request); |
|
| 109 | - $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 110 | - $this->assign('canUnflag', $canUnflag); |
|
| 111 | - $this->setTemplate('edit-comment.tpl'); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @throws AccessDeniedException |
|
| 117 | - */ |
|
| 118 | - private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
| 119 | - { |
|
| 120 | - if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 121 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $restrictedVisibility = $comment->getFlagged() |
|
| 125 | - || $comment->getVisibility() === 'admin' |
|
| 126 | - || $comment->getVisibility() === 'checkuser'; |
|
| 127 | - |
|
| 128 | - if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 129 | - // Restricted visibility comments can only be seen if the user has a request reserved. |
|
| 130 | - /** @var Request $request */ |
|
| 131 | - $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
| 132 | - |
|
| 133 | - if ($request->getReserved() !== $currentUser->getId()) { |
|
| 134 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($comment->getVisibility() === 'admin' |
|
| 139 | - && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
| 140 | - && $comment->getUser() !== $currentUser->getId()) { |
|
| 141 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($comment->getVisibility() === 'checkuser' |
|
| 145 | - && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
| 146 | - && $comment->getUser() !== $currentUser->getId()) { |
|
| 147 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @throws ApplicationLogicException |
|
| 153 | - */ |
|
| 154 | - private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
| 155 | - { |
|
| 156 | - if ($comment->getVisibility() !== 'requester') { |
|
| 157 | - if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
| 158 | - throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $comment->setVisibility($visibility); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $comment->setComment($newComment); |
|
| 165 | - $comment->touchEdited(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - private function redirectBack(int $requestId): void |
|
| 169 | - { |
|
| 170 | - $source = WebRequest::getString('from'); |
|
| 171 | - |
|
| 172 | - if ($source == 'flagged') { |
|
| 173 | - $this->redirect('flaggedComments'); |
|
| 174 | - } |
|
| 175 | - else { |
|
| 176 | - $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
| 177 | - } |
|
| 178 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + * @throws ApplicationLogicException |
|
| 27 | + * @throws Exception |
|
| 28 | + */ |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $commentId = WebRequest::getInt('id'); |
|
| 32 | + if ($commentId === null) { |
|
| 33 | + throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $database = $this->getDatabase(); |
|
| 37 | + |
|
| 38 | + /** @var Comment|false $comment */ |
|
| 39 | + $comment = Comment::getById($commentId, $database); |
|
| 40 | + if ($comment === false) { |
|
| 41 | + throw new ApplicationLogicException('Comment not found'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $currentUser = User::getCurrent($database); |
|
| 45 | + |
|
| 46 | + $this->checkCommentAccess($comment, $currentUser); |
|
| 47 | + |
|
| 48 | + /** @var Request|false $request */ |
|
| 49 | + $request = Request::getById($comment->getRequest(), $database); |
|
| 50 | + |
|
| 51 | + if ($request === false) { |
|
| 52 | + throw new ApplicationLogicException('Request was not found.'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 56 | + |
|
| 57 | + if (WebRequest::wasPosted()) { |
|
| 58 | + $this->validateCSRFToken(); |
|
| 59 | + $newComment = WebRequest::postString('newcomment'); |
|
| 60 | + $visibility = WebRequest::postString('visibility'); |
|
| 61 | + $doUnflag = WebRequest::postBoolean('unflag'); |
|
| 62 | + |
|
| 63 | + if ($newComment === null || $newComment === '') { |
|
| 64 | + throw new ApplicationLogicException('Comment cannot be empty!'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $commentDataUnchanged = $newComment === $comment->getComment() |
|
| 68 | + && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
| 69 | + $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
| 70 | + |
|
| 71 | + if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
| 72 | + // No change was made; redirect back. |
|
| 73 | + $this->redirectBack($comment->getRequest()); |
|
| 74 | + |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // optimistically lock from the load of the edit comment form |
|
| 79 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 80 | + |
|
| 81 | + // comment data has changed, update the object |
|
| 82 | + if (!$commentDataUnchanged) { |
|
| 83 | + $this->updateCommentData($comment, $visibility, $newComment); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($doUnflag && $canUnflag) { |
|
| 87 | + $comment->setFlagged(false); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $comment->setUpdateVersion($updateVersion); |
|
| 91 | + $comment->save(); |
|
| 92 | + |
|
| 93 | + if (!$commentDataUnchanged) { |
|
| 94 | + Logger::editComment($database, $comment, $request); |
|
| 95 | + $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if ($doUnflag && $canUnflag) { |
|
| 99 | + Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + SessionAlert::success('Comment has been saved successfully'); |
|
| 103 | + $this->redirectBack($comment->getRequest()); |
|
| 104 | + } |
|
| 105 | + else { |
|
| 106 | + $this->assignCSRFToken(); |
|
| 107 | + $this->assign('comment', $comment); |
|
| 108 | + $this->assign('request', $request); |
|
| 109 | + $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 110 | + $this->assign('canUnflag', $canUnflag); |
|
| 111 | + $this->setTemplate('edit-comment.tpl'); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @throws AccessDeniedException |
|
| 117 | + */ |
|
| 118 | + private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
| 119 | + { |
|
| 120 | + if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 121 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $restrictedVisibility = $comment->getFlagged() |
|
| 125 | + || $comment->getVisibility() === 'admin' |
|
| 126 | + || $comment->getVisibility() === 'checkuser'; |
|
| 127 | + |
|
| 128 | + if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 129 | + // Restricted visibility comments can only be seen if the user has a request reserved. |
|
| 130 | + /** @var Request $request */ |
|
| 131 | + $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
| 132 | + |
|
| 133 | + if ($request->getReserved() !== $currentUser->getId()) { |
|
| 134 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($comment->getVisibility() === 'admin' |
|
| 139 | + && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
| 140 | + && $comment->getUser() !== $currentUser->getId()) { |
|
| 141 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($comment->getVisibility() === 'checkuser' |
|
| 145 | + && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
| 146 | + && $comment->getUser() !== $currentUser->getId()) { |
|
| 147 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @throws ApplicationLogicException |
|
| 153 | + */ |
|
| 154 | + private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
| 155 | + { |
|
| 156 | + if ($comment->getVisibility() !== 'requester') { |
|
| 157 | + if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
| 158 | + throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $comment->setVisibility($visibility); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $comment->setComment($newComment); |
|
| 165 | + $comment->touchEdited(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + private function redirectBack(int $requestId): void |
|
| 169 | + { |
|
| 170 | + $source = WebRequest::getString('from'); |
|
| 171 | + |
|
| 172 | + if ($source == 'flagged') { |
|
| 173 | + $this->redirect('flaggedComments'); |
|
| 174 | + } |
|
| 175 | + else { |
|
| 176 | + $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class StatsFastCloses extends InternalPageBase |
| 15 | 15 | { |
| 16 | - public function main() |
|
| 17 | - { |
|
| 18 | - $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
| 16 | + public function main() |
|
| 17 | + { |
|
| 18 | + $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
| 19 | 19 | |
| 20 | - $query = <<<SQL |
|
| 20 | + $query = <<<SQL |
|
| 21 | 21 | WITH closedescs AS ( |
| 22 | 22 | SELECT closes, mail_desc FROM closes |
| 23 | 23 | UNION ALL |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | ORDER BY TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) ASC |
| 48 | 48 | ; |
| 49 | 49 | SQL; |
| 50 | - $database = $this->getDatabase(); |
|
| 51 | - $statement = $database->query($query); |
|
| 52 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 53 | - $this->assign('dataTable', $data); |
|
| 54 | - $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
| 55 | - $this->setTemplate('statistics/fast-closes.tpl'); |
|
| 56 | - } |
|
| 50 | + $database = $this->getDatabase(); |
|
| 51 | + $statement = $database->query($query); |
|
| 52 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 53 | + $this->assign('dataTable', $data); |
|
| 54 | + $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
| 55 | + $this->setTemplate('statistics/fast-closes.tpl'); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class StatsTemplateStats extends InternalPageBase |
| 17 | 17 | { |
| 18 | - public function main() |
|
| 19 | - { |
|
| 20 | - $this->setHtmlTitle('Template Stats :: Statistics'); |
|
| 18 | + public function main() |
|
| 19 | + { |
|
| 20 | + $this->setHtmlTitle('Template Stats :: Statistics'); |
|
| 21 | 21 | |
| 22 | - $query = <<<SQL |
|
| 22 | + $query = <<<SQL |
|
| 23 | 23 | SELECT |
| 24 | 24 | t.id AS templateid, |
| 25 | 25 | t.usercode AS usercode, |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | ) allUsers ON allUsers.welcome_template = t.id |
| 50 | 50 | ORDER BY t.id |
| 51 | 51 | SQL; |
| 52 | - $database = $this->getDatabase(); |
|
| 53 | - $statement = $database->prepare($query); |
|
| 54 | - $statement->execute([ |
|
| 55 | - ':domain1' => WebRequest::getSessionDomain(), |
|
| 56 | - ':domain2' => WebRequest::getSessionDomain(), |
|
| 57 | - ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 58 | - ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 59 | - ]); |
|
| 60 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 61 | - $this->assign('dataTable', $data); |
|
| 62 | - $this->assign('statsPageTitle', 'Template Stats'); |
|
| 63 | - $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
| 64 | - } |
|
| 52 | + $database = $this->getDatabase(); |
|
| 53 | + $statement = $database->prepare($query); |
|
| 54 | + $statement->execute([ |
|
| 55 | + ':domain1' => WebRequest::getSessionDomain(), |
|
| 56 | + ':domain2' => WebRequest::getSessionDomain(), |
|
| 57 | + ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 58 | + ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 59 | + ]); |
|
| 60 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 61 | + $this->assign('dataTable', $data); |
|
| 62 | + $this->assign('statsPageTitle', 'Template Stats'); |
|
| 63 | + $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class StatsTopCreators extends InternalPageBase |
| 16 | 16 | { |
| 17 | - public function main() |
|
| 18 | - { |
|
| 19 | - $this->setHtmlTitle('Top Creators :: Statistics'); |
|
| 17 | + public function main() |
|
| 18 | + { |
|
| 19 | + $this->setHtmlTitle('Top Creators :: Statistics'); |
|
| 20 | 20 | |
| 21 | - // Retrieve all-time stats |
|
| 22 | - $queryAllTime = <<<SQL |
|
| 21 | + // Retrieve all-time stats |
|
| 22 | + $queryAllTime = <<<SQL |
|
| 23 | 23 | SELECT |
| 24 | 24 | /* StatsTopCreators::execute()/queryAllTime */ |
| 25 | 25 | COUNT(*) count, |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | ORDER BY COUNT(*) DESC; |
| 37 | 37 | SQL; |
| 38 | 38 | |
| 39 | - // Retrieve all-time stats for active users only |
|
| 40 | - $queryAllTimeActive = <<<SQL |
|
| 39 | + // Retrieve all-time stats for active users only |
|
| 40 | + $queryAllTimeActive = <<<SQL |
|
| 41 | 41 | SELECT |
| 42 | 42 | /* StatsTopCreators::execute()/queryAllTimeActive */ |
| 43 | 43 | COUNT(*) count, |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | ORDER BY COUNT(*) DESC; |
| 55 | 55 | SQL; |
| 56 | 56 | |
| 57 | - // Retrieve today's stats (so far) |
|
| 58 | - $queryToday = <<<SQL |
|
| 57 | + // Retrieve today's stats (so far) |
|
| 58 | + $queryToday = <<<SQL |
|
| 59 | 59 | SELECT |
| 60 | 60 | /* StatsTopCreators::execute()/top5out */ |
| 61 | 61 | COUNT(*) count, |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | ORDER BY COUNT(*) DESC; |
| 72 | 72 | SQL; |
| 73 | 73 | |
| 74 | - // Retrieve Yesterday's stats |
|
| 75 | - $queryYesterday = <<<SQL |
|
| 74 | + // Retrieve Yesterday's stats |
|
| 75 | + $queryYesterday = <<<SQL |
|
| 76 | 76 | SELECT |
| 77 | 77 | /* StatsTopCreators::execute()/top5yout */ |
| 78 | 78 | COUNT(*) count, |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | ORDER BY COUNT(*) DESC; |
| 89 | 89 | SQL; |
| 90 | 90 | |
| 91 | - // Retrieve last 7 days |
|
| 92 | - $queryLast7Days = <<<SQL |
|
| 91 | + // Retrieve last 7 days |
|
| 92 | + $queryLast7Days = <<<SQL |
|
| 93 | 93 | SELECT |
| 94 | 94 | /* StatsTopCreators::execute()/top5wout */ |
| 95 | 95 | COUNT(*) count, |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | ORDER BY COUNT(*) DESC; |
| 106 | 106 | SQL; |
| 107 | 107 | |
| 108 | - // Retrieve last month's stats |
|
| 109 | - $queryLast28Days = <<<SQL |
|
| 108 | + // Retrieve last month's stats |
|
| 109 | + $queryLast28Days = <<<SQL |
|
| 110 | 110 | SELECT |
| 111 | 111 | /* StatsTopCreators::execute()/top5mout */ |
| 112 | 112 | COUNT(*) count, |
@@ -122,25 +122,25 @@ discard block |
||
| 122 | 122 | ORDER BY COUNT(*) DESC; |
| 123 | 123 | SQL; |
| 124 | 124 | |
| 125 | - // Put it all together |
|
| 126 | - $queries = array( |
|
| 127 | - 'queryAllTime' => $queryAllTime, |
|
| 128 | - 'queryAllTimeActive' => $queryAllTimeActive, |
|
| 129 | - 'queryToday' => $queryToday, |
|
| 130 | - 'queryYesterday' => $queryYesterday, |
|
| 131 | - 'queryLast7Days' => $queryLast7Days, |
|
| 132 | - 'queryLast28Days' => $queryLast28Days, |
|
| 133 | - ); |
|
| 125 | + // Put it all together |
|
| 126 | + $queries = array( |
|
| 127 | + 'queryAllTime' => $queryAllTime, |
|
| 128 | + 'queryAllTimeActive' => $queryAllTimeActive, |
|
| 129 | + 'queryToday' => $queryToday, |
|
| 130 | + 'queryYesterday' => $queryYesterday, |
|
| 131 | + 'queryLast7Days' => $queryLast7Days, |
|
| 132 | + 'queryLast28Days' => $queryLast28Days, |
|
| 133 | + ); |
|
| 134 | 134 | |
| 135 | - $database = $this->getDatabase(); |
|
| 136 | - foreach ($queries as $name => $sql) { |
|
| 137 | - $statement = $database->prepare($sql); |
|
| 138 | - $statement->execute([":created" => EmailTemplate::ACTION_CREATED]); |
|
| 139 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 140 | - $this->assign($name, $data); |
|
| 141 | - } |
|
| 135 | + $database = $this->getDatabase(); |
|
| 136 | + foreach ($queries as $name => $sql) { |
|
| 137 | + $statement = $database->prepare($sql); |
|
| 138 | + $statement->execute([":created" => EmailTemplate::ACTION_CREATED]); |
|
| 139 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 140 | + $this->assign($name, $data); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $this->assign('statsPageTitle', 'Top Account Creators'); |
|
| 144 | - $this->setTemplate('statistics/top-creators.tpl'); |
|
| 145 | - } |
|
| 143 | + $this->assign('statsPageTitle', 'Top Account Creators'); |
|
| 144 | + $this->setTemplate('statistics/top-creators.tpl'); |
|
| 145 | + } |
|
| 146 | 146 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class StatsMonthlyStats extends InternalPageBase |
| 15 | 15 | { |
| 16 | - public function main() |
|
| 17 | - { |
|
| 18 | - $this->setHtmlTitle('Monthly Stats :: Statistics'); |
|
| 16 | + public function main() |
|
| 17 | + { |
|
| 18 | + $this->setHtmlTitle('Monthly Stats :: Statistics'); |
|
| 19 | 19 | |
| 20 | - $query = <<<SQL |
|
| 20 | + $query = <<<SQL |
|
| 21 | 21 | WITH activemonths AS ( |
| 22 | 22 | -- Pull all values from two generated sequences (values 2008 to 2050, and values 1 to 12) to generate dates. |
| 23 | 23 | -- Filter the resulting set down to months between the earliest and latest log entries. |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | ORDER BY sortkey ASC; |
| 156 | 156 | SQL; |
| 157 | 157 | |
| 158 | - $database = $this->getDatabase(); |
|
| 159 | - $statement = $database->query($query); |
|
| 160 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 158 | + $database = $this->getDatabase(); |
|
| 159 | + $statement = $database->query($query); |
|
| 160 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 161 | 161 | |
| 162 | - $this->assign('dataTable', $data); |
|
| 163 | - $this->assign('statsPageTitle', 'Monthly Statistics'); |
|
| 164 | - $this->setTemplate('statistics/monthly-stats.tpl'); |
|
| 165 | - } |
|
| 162 | + $this->assign('dataTable', $data); |
|
| 163 | + $this->assign('statsPageTitle', 'Monthly Statistics'); |
|
| 164 | + $this->setTemplate('statistics/monthly-stats.tpl'); |
|
| 165 | + } |
|
| 166 | 166 | } |