@@ -15,22 +15,22 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageDropRequest extends PageCloseRequest |
| 17 | 17 | { |
| 18 | - protected function getTemplate(PdoDatabase $database) |
|
| 19 | - { |
|
| 20 | - return EmailTemplate::getDroppedTemplate(); |
|
| 21 | - } |
|
| 18 | + protected function getTemplate(PdoDatabase $database) |
|
| 19 | + { |
|
| 20 | + return EmailTemplate::getDroppedTemplate(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | - { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | + { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList) |
|
| 34 | - { |
|
| 35 | - } |
|
| 33 | + protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList) |
|
| 34 | + { |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |
@@ -239,11 +239,11 @@ |
||
| 239 | 239 | |
| 240 | 240 | $emailSig = $currentUser->getEmailSig(); |
| 241 | 241 | if ($emailSig !== '' || $emailSig !== null) { |
| 242 | - $emailSig = "\n\n" . $emailSig; |
|
| 242 | + $emailSig = "\n\n".$emailSig; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
| 246 | - $content = $mailText . $emailSig; |
|
| 246 | + $content = $mailText.$emailSig; |
|
| 247 | 247 | |
| 248 | 248 | $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
| 249 | 249 | |
@@ -20,240 +20,240 @@ |
||
| 20 | 20 | |
| 21 | 21 | class PageCloseRequest extends RequestActionBase |
| 22 | 22 | { |
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->processClose(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Main function for this page, when no specific actions are called. |
|
| 30 | - * @throws ApplicationLogicException |
|
| 31 | - */ |
|
| 32 | - final protected function processClose() |
|
| 33 | - { |
|
| 34 | - $this->checkPosted(); |
|
| 35 | - $database = $this->getDatabase(); |
|
| 36 | - |
|
| 37 | - $currentUser = User::getCurrent($database); |
|
| 38 | - $template = $this->getTemplate($database); |
|
| 39 | - $request = $this->getRequest($database); |
|
| 40 | - |
|
| 41 | - if ($request->getStatus() === 'Closed') { |
|
| 42 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($this->confirmAccountCreated($request, $template)) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // I think we're good here... |
|
| 58 | - $request->setStatus('Closed'); |
|
| 59 | - $request->setReserved(null); |
|
| 60 | - |
|
| 61 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 62 | - |
|
| 63 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 64 | - $request->save(); |
|
| 65 | - |
|
| 66 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | - // be rolled back. |
|
| 68 | - |
|
| 69 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | - SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | - |
|
| 72 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | - |
|
| 74 | - $this->redirect(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param PdoDatabase $database |
|
| 79 | - * |
|
| 80 | - * @return EmailTemplate |
|
| 81 | - * @throws ApplicationLogicException |
|
| 82 | - */ |
|
| 83 | - protected function getTemplate(PdoDatabase $database) |
|
| 84 | - { |
|
| 85 | - $templateId = WebRequest::postInt('template'); |
|
| 86 | - if ($templateId === null) { |
|
| 87 | - throw new ApplicationLogicException('No template specified'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** @var EmailTemplate $template */ |
|
| 91 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | - if ($template === false || !$template->getActive()) { |
|
| 93 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $template; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param Request $request |
|
| 101 | - * @param EmailTemplate $template |
|
| 102 | - * |
|
| 103 | - * @return bool |
|
| 104 | - */ |
|
| 105 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | - { |
|
| 107 | - if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | - |
|
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - protected function checkEmailAlreadySent(Request $request) |
|
| 117 | - { |
|
| 118 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | - { |
|
| 127 | - $reservationId = $request->getReserved(); |
|
| 128 | - |
|
| 129 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | - if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | - if ($currentUser->getId() !== $reservationId) { |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param Request $request |
|
| 142 | - * @param EmailTemplate $template |
|
| 143 | - * @param User $currentUser |
|
| 144 | - * @param PdoDatabase $database |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function confirmReserveOverride( |
|
| 149 | - Request $request, |
|
| 150 | - EmailTemplate $template, |
|
| 151 | - User $currentUser, |
|
| 152 | - PdoDatabase $database |
|
| 153 | - ) { |
|
| 154 | - if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | - $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | - $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | - |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param Request $request |
|
| 166 | - * @param EmailTemplate $template |
|
| 167 | - * |
|
| 168 | - * @return bool |
|
| 169 | - * @throws \Waca\Exceptions\CurlException |
|
| 170 | - */ |
|
| 171 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | - { |
|
| 173 | - if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | - |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | - { |
|
| 184 | - if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | - $parameters = array( |
|
| 186 | - 'action' => 'query', |
|
| 187 | - 'list' => 'users', |
|
| 188 | - 'format' => 'php', |
|
| 189 | - 'ususers' => $request->getName(), |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | - $parameters); |
|
| 194 | - |
|
| 195 | - $apiResult = unserialize($content); |
|
| 196 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | - |
|
| 198 | - if (!$exists) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @param Request $request |
|
| 208 | - * @param string $mailText |
|
| 209 | - * @param User $currentUser |
|
| 210 | - * @param boolean $ccMailingList |
|
| 211 | - */ |
|
| 212 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | - { |
|
| 214 | - $headers = array( |
|
| 215 | - 'X-ACC-Request' => $request->getId(), |
|
| 216 | - 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - if ($ccMailingList) { |
|
| 220 | - $headers['Cc'] = '[email protected]'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $helper = $this->getEmailHelper(); |
|
| 224 | - |
|
| 225 | - $emailSig = $currentUser->getEmailSig(); |
|
| 226 | - if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | - $emailSig = "\n\n" . $emailSig; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | - $content = $mailText . $emailSig; |
|
| 232 | - |
|
| 233 | - $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | - |
|
| 235 | - $request->setEmailSent(true); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param Request $request |
|
| 240 | - * @param EmailTemplate $template |
|
| 241 | - * @param string $templateName |
|
| 242 | - * |
|
| 243 | - * @throws Exception |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | - { |
|
| 248 | - $this->assignCSRFToken(); |
|
| 249 | - |
|
| 250 | - $this->assign('request', $request->getId()); |
|
| 251 | - $this->assign('template', $template->getId()); |
|
| 252 | - |
|
| 253 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 254 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 255 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 256 | - |
|
| 257 | - $this->setTemplate($templateName); |
|
| 258 | - } |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->processClose(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Main function for this page, when no specific actions are called. |
|
| 30 | + * @throws ApplicationLogicException |
|
| 31 | + */ |
|
| 32 | + final protected function processClose() |
|
| 33 | + { |
|
| 34 | + $this->checkPosted(); |
|
| 35 | + $database = $this->getDatabase(); |
|
| 36 | + |
|
| 37 | + $currentUser = User::getCurrent($database); |
|
| 38 | + $template = $this->getTemplate($database); |
|
| 39 | + $request = $this->getRequest($database); |
|
| 40 | + |
|
| 41 | + if ($request->getStatus() === 'Closed') { |
|
| 42 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($this->confirmAccountCreated($request, $template)) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // I think we're good here... |
|
| 58 | + $request->setStatus('Closed'); |
|
| 59 | + $request->setReserved(null); |
|
| 60 | + |
|
| 61 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 62 | + |
|
| 63 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 64 | + $request->save(); |
|
| 65 | + |
|
| 66 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | + // be rolled back. |
|
| 68 | + |
|
| 69 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | + SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | + |
|
| 72 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | + |
|
| 74 | + $this->redirect(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param PdoDatabase $database |
|
| 79 | + * |
|
| 80 | + * @return EmailTemplate |
|
| 81 | + * @throws ApplicationLogicException |
|
| 82 | + */ |
|
| 83 | + protected function getTemplate(PdoDatabase $database) |
|
| 84 | + { |
|
| 85 | + $templateId = WebRequest::postInt('template'); |
|
| 86 | + if ($templateId === null) { |
|
| 87 | + throw new ApplicationLogicException('No template specified'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** @var EmailTemplate $template */ |
|
| 91 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | + if ($template === false || !$template->getActive()) { |
|
| 93 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $template; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param Request $request |
|
| 101 | + * @param EmailTemplate $template |
|
| 102 | + * |
|
| 103 | + * @return bool |
|
| 104 | + */ |
|
| 105 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | + { |
|
| 107 | + if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | + |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + protected function checkEmailAlreadySent(Request $request) |
|
| 117 | + { |
|
| 118 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | + { |
|
| 127 | + $reservationId = $request->getReserved(); |
|
| 128 | + |
|
| 129 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | + if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | + if ($currentUser->getId() !== $reservationId) { |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param Request $request |
|
| 142 | + * @param EmailTemplate $template |
|
| 143 | + * @param User $currentUser |
|
| 144 | + * @param PdoDatabase $database |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function confirmReserveOverride( |
|
| 149 | + Request $request, |
|
| 150 | + EmailTemplate $template, |
|
| 151 | + User $currentUser, |
|
| 152 | + PdoDatabase $database |
|
| 153 | + ) { |
|
| 154 | + if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | + $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | + $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | + |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param Request $request |
|
| 166 | + * @param EmailTemplate $template |
|
| 167 | + * |
|
| 168 | + * @return bool |
|
| 169 | + * @throws \Waca\Exceptions\CurlException |
|
| 170 | + */ |
|
| 171 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | + { |
|
| 173 | + if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | + |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | + { |
|
| 184 | + if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | + $parameters = array( |
|
| 186 | + 'action' => 'query', |
|
| 187 | + 'list' => 'users', |
|
| 188 | + 'format' => 'php', |
|
| 189 | + 'ususers' => $request->getName(), |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | + $parameters); |
|
| 194 | + |
|
| 195 | + $apiResult = unserialize($content); |
|
| 196 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | + |
|
| 198 | + if (!$exists) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @param Request $request |
|
| 208 | + * @param string $mailText |
|
| 209 | + * @param User $currentUser |
|
| 210 | + * @param boolean $ccMailingList |
|
| 211 | + */ |
|
| 212 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | + { |
|
| 214 | + $headers = array( |
|
| 215 | + 'X-ACC-Request' => $request->getId(), |
|
| 216 | + 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + if ($ccMailingList) { |
|
| 220 | + $headers['Cc'] = '[email protected]'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $helper = $this->getEmailHelper(); |
|
| 224 | + |
|
| 225 | + $emailSig = $currentUser->getEmailSig(); |
|
| 226 | + if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | + $emailSig = "\n\n" . $emailSig; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | + $content = $mailText . $emailSig; |
|
| 232 | + |
|
| 233 | + $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | + |
|
| 235 | + $request->setEmailSent(true); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param Request $request |
|
| 240 | + * @param EmailTemplate $template |
|
| 241 | + * @param string $templateName |
|
| 242 | + * |
|
| 243 | + * @throws Exception |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | + { |
|
| 248 | + $this->assignCSRFToken(); |
|
| 249 | + |
|
| 250 | + $this->assign('request', $request->getId()); |
|
| 251 | + $this->assign('template', $template->getId()); |
|
| 252 | + |
|
| 253 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 254 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 255 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 256 | + |
|
| 257 | + $this->setTemplate($templateName); |
|
| 258 | + } |
|
| 259 | 259 | } |
@@ -48,8 +48,8 @@ |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
| 51 | - $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 52 | - $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 51 | + $ipv4Regex = '/\b'.RegexConstants::IPV4.'\b/'; |
|
| 52 | + $ipv6Regex = '/\b'.RegexConstants::IPV6.'\b/'; |
|
| 53 | 53 | |
| 54 | 54 | $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
| 55 | 55 | |
@@ -15,51 +15,51 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageComment extends RequestActionBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Main function for this page, when no specific actions are called. |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->checkPosted(); |
|
| 25 | - $database = $this->getDatabase(); |
|
| 26 | - $request = $this->getRequest($database); |
|
| 18 | + /** |
|
| 19 | + * Main function for this page, when no specific actions are called. |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->checkPosted(); |
|
| 25 | + $database = $this->getDatabase(); |
|
| 26 | + $request = $this->getRequest($database); |
|
| 27 | 27 | |
| 28 | - $commentText = WebRequest::postString('comment'); |
|
| 29 | - if ($commentText === false || $commentText == '') { |
|
| 30 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 28 | + $commentText = WebRequest::postString('comment'); |
|
| 29 | + if ($commentText === false || $commentText == '') { |
|
| 30 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 31 | 31 | |
| 32 | - return; |
|
| 33 | - } |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | - $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | - $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 35 | + //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | + $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | + $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 38 | 38 | |
| 39 | - $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 39 | + $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 40 | 40 | |
| 41 | - if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | - $this->assignCSRFToken(); |
|
| 43 | - $this->assign("request", $request); |
|
| 44 | - $this->assign("comment", $commentText); |
|
| 45 | - $this->setTemplate("privpol-warning.tpl"); |
|
| 41 | + if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | + $this->assignCSRFToken(); |
|
| 43 | + $this->assign("request", $request); |
|
| 44 | + $this->assign("comment", $commentText); |
|
| 45 | + $this->setTemplate("privpol-warning.tpl"); |
|
| 46 | 46 | |
| 47 | - return; |
|
| 48 | - } |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 50 | + $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 51 | 51 | |
| 52 | - $comment = new Comment(); |
|
| 53 | - $comment->setDatabase($database); |
|
| 52 | + $comment = new Comment(); |
|
| 53 | + $comment->setDatabase($database); |
|
| 54 | 54 | |
| 55 | - $comment->setRequest($request->getId()); |
|
| 56 | - $comment->setVisibility($visibility); |
|
| 57 | - $comment->setUser(User::getCurrent($database)->getId()); |
|
| 58 | - $comment->setComment($commentText); |
|
| 55 | + $comment->setRequest($request->getId()); |
|
| 56 | + $comment->setVisibility($visibility); |
|
| 57 | + $comment->setUser(User::getCurrent($database)->getId()); |
|
| 58 | + $comment->setComment($commentText); |
|
| 59 | 59 | |
| 60 | - $comment->save(); |
|
| 60 | + $comment->save(); |
|
| 61 | 61 | |
| 62 | - $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 63 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 64 | - } |
|
| 62 | + $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 63 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -100,7 +100,7 @@ |
||
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 103 | + $this->setHtmlTitle($statusSymbol.' #'.$request->getId()); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -24,212 +24,212 @@ |
||
| 24 | 24 | |
| 25 | 25 | class PageViewRequest extends InternalPageBase |
| 26 | 26 | { |
| 27 | - use RequestData; |
|
| 28 | - const STATUS_SYMBOL_OPEN = '☐'; |
|
| 29 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 30 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Main function for this page, when no specific actions are called. |
|
| 34 | - * @throws ApplicationLogicException |
|
| 35 | - */ |
|
| 36 | - protected function main() |
|
| 37 | - { |
|
| 38 | - // set up csrf protection |
|
| 39 | - $this->assignCSRFToken(); |
|
| 40 | - |
|
| 41 | - // get some useful objects |
|
| 42 | - $database = $this->getDatabase(); |
|
| 43 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 44 | - $config = $this->getSiteConfiguration(); |
|
| 45 | - $currentUser = User::getCurrent($database); |
|
| 46 | - |
|
| 47 | - // Test we should be able to look at this request |
|
| 48 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 49 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 50 | - // Not allowed to look at this yet. |
|
| 51 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $this->setupBasicData($request, $config); |
|
| 56 | - |
|
| 57 | - $this->setupUsernameData($request); |
|
| 58 | - |
|
| 59 | - $this->setupTitle($request); |
|
| 60 | - |
|
| 61 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 62 | - $this->setupGeneralData($database); |
|
| 63 | - |
|
| 64 | - $this->assign('requestDataCleared', false); |
|
| 65 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 66 | - $this->assign('requestDataCleared', true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 70 | - |
|
| 71 | - $this->setupLogData($request, $database); |
|
| 72 | - |
|
| 73 | - if ($allowedPrivateData) { |
|
| 74 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 75 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 76 | - |
|
| 77 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 78 | - |
|
| 79 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 80 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 81 | - $this->setupCheckUserData($request); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - else { |
|
| 85 | - $this->setTemplate('view-request/main.tpl'); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param Request $request |
|
| 91 | - */ |
|
| 92 | - protected function setupTitle(Request $request) |
|
| 93 | - { |
|
| 94 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 95 | - if ($request->getStatus() === 'Closed') { |
|
| 96 | - if ($request->getWasCreated()) { |
|
| 97 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 98 | - } |
|
| 99 | - else { |
|
| 100 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Sets up data unrelated to the request, such as the email template information |
|
| 109 | - * |
|
| 110 | - * @param PdoDatabase $database |
|
| 111 | - */ |
|
| 112 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 113 | - { |
|
| 114 | - $config = $this->getSiteConfiguration(); |
|
| 115 | - |
|
| 116 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 117 | - |
|
| 118 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 119 | - |
|
| 120 | - $this->assign('requestStates', $config->getRequestStates()); |
|
| 121 | - |
|
| 122 | - /** @var EmailTemplate $createdTemplate */ |
|
| 123 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 124 | - |
|
| 125 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 126 | - $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
| 127 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 128 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 129 | - |
|
| 130 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 131 | - $this->assign("createReasons", $createReasons); |
|
| 132 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 133 | - $this->assign("declineReasons", $declineReasons); |
|
| 134 | - |
|
| 135 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 136 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 137 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 138 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 139 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 140 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 141 | - |
|
| 142 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 143 | - return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username'); |
|
| 144 | - }); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
| 148 | - { |
|
| 149 | - $currentUser = User::getCurrent($database); |
|
| 150 | - |
|
| 151 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 152 | - $requestLogs = array(); |
|
| 153 | - |
|
| 154 | - if (trim($request->getComment()) !== "") { |
|
| 155 | - $requestLogs[] = array( |
|
| 156 | - 'type' => 'comment', |
|
| 157 | - 'security' => 'user', |
|
| 158 | - 'userid' => null, |
|
| 159 | - 'user' => $request->getName(), |
|
| 160 | - 'entry' => null, |
|
| 161 | - 'time' => $request->getDate(), |
|
| 162 | - 'canedit' => false, |
|
| 163 | - 'id' => $request->getId(), |
|
| 164 | - 'comment' => $request->getComment(), |
|
| 165 | - ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** @var User[] $nameCache */ |
|
| 169 | - $nameCache = array(); |
|
| 170 | - |
|
| 171 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 172 | - |
|
| 173 | - /** @var Log|Comment $entry */ |
|
| 174 | - foreach ($logs as $entry) { |
|
| 175 | - // both log and comment have a 'user' field |
|
| 176 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 177 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 178 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if ($entry instanceof Comment) { |
|
| 182 | - $requestLogs[] = array( |
|
| 183 | - 'type' => 'comment', |
|
| 184 | - 'security' => $entry->getVisibility(), |
|
| 185 | - 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 186 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 187 | - 'entry' => null, |
|
| 188 | - 'time' => $entry->getTime(), |
|
| 189 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 190 | - 'id' => $entry->getId(), |
|
| 191 | - 'comment' => $entry->getComment(), |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($entry instanceof Log) { |
|
| 196 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 197 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 198 | - |
|
| 199 | - $requestLogs[] = array( |
|
| 200 | - 'type' => 'log', |
|
| 201 | - 'security' => 'user', |
|
| 202 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 203 | - 'user' => $entryUser->getUsername(), |
|
| 204 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 205 | - 'time' => $entry->getTimestamp(), |
|
| 206 | - 'canedit' => false, |
|
| 207 | - 'id' => $entry->getId(), |
|
| 208 | - 'comment' => $entry->getComment(), |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $this->assign("requestLogs", $requestLogs); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @param Request $request |
|
| 218 | - */ |
|
| 219 | - protected function setupUsernameData(Request $request) |
|
| 220 | - { |
|
| 221 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 222 | - |
|
| 223 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 224 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 225 | - |
|
| 226 | - try { |
|
| 227 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 228 | - } |
|
| 229 | - catch (Exception $ex) { |
|
| 230 | - $spoofs = $ex->getMessage(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - $this->assign("spoofs", $spoofs); |
|
| 234 | - } |
|
| 27 | + use RequestData; |
|
| 28 | + const STATUS_SYMBOL_OPEN = '☐'; |
|
| 29 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 30 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Main function for this page, when no specific actions are called. |
|
| 34 | + * @throws ApplicationLogicException |
|
| 35 | + */ |
|
| 36 | + protected function main() |
|
| 37 | + { |
|
| 38 | + // set up csrf protection |
|
| 39 | + $this->assignCSRFToken(); |
|
| 40 | + |
|
| 41 | + // get some useful objects |
|
| 42 | + $database = $this->getDatabase(); |
|
| 43 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 44 | + $config = $this->getSiteConfiguration(); |
|
| 45 | + $currentUser = User::getCurrent($database); |
|
| 46 | + |
|
| 47 | + // Test we should be able to look at this request |
|
| 48 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 49 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 50 | + // Not allowed to look at this yet. |
|
| 51 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $this->setupBasicData($request, $config); |
|
| 56 | + |
|
| 57 | + $this->setupUsernameData($request); |
|
| 58 | + |
|
| 59 | + $this->setupTitle($request); |
|
| 60 | + |
|
| 61 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 62 | + $this->setupGeneralData($database); |
|
| 63 | + |
|
| 64 | + $this->assign('requestDataCleared', false); |
|
| 65 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 66 | + $this->assign('requestDataCleared', true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 70 | + |
|
| 71 | + $this->setupLogData($request, $database); |
|
| 72 | + |
|
| 73 | + if ($allowedPrivateData) { |
|
| 74 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 75 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 76 | + |
|
| 77 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 78 | + |
|
| 79 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 80 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 81 | + $this->setupCheckUserData($request); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + else { |
|
| 85 | + $this->setTemplate('view-request/main.tpl'); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param Request $request |
|
| 91 | + */ |
|
| 92 | + protected function setupTitle(Request $request) |
|
| 93 | + { |
|
| 94 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 95 | + if ($request->getStatus() === 'Closed') { |
|
| 96 | + if ($request->getWasCreated()) { |
|
| 97 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 98 | + } |
|
| 99 | + else { |
|
| 100 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Sets up data unrelated to the request, such as the email template information |
|
| 109 | + * |
|
| 110 | + * @param PdoDatabase $database |
|
| 111 | + */ |
|
| 112 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 113 | + { |
|
| 114 | + $config = $this->getSiteConfiguration(); |
|
| 115 | + |
|
| 116 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 117 | + |
|
| 118 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 119 | + |
|
| 120 | + $this->assign('requestStates', $config->getRequestStates()); |
|
| 121 | + |
|
| 122 | + /** @var EmailTemplate $createdTemplate */ |
|
| 123 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 124 | + |
|
| 125 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 126 | + $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
| 127 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 128 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 129 | + |
|
| 130 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 131 | + $this->assign("createReasons", $createReasons); |
|
| 132 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 133 | + $this->assign("declineReasons", $declineReasons); |
|
| 134 | + |
|
| 135 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 136 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 137 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 138 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 139 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 140 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 141 | + |
|
| 142 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 143 | + return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username'); |
|
| 144 | + }); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
| 148 | + { |
|
| 149 | + $currentUser = User::getCurrent($database); |
|
| 150 | + |
|
| 151 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 152 | + $requestLogs = array(); |
|
| 153 | + |
|
| 154 | + if (trim($request->getComment()) !== "") { |
|
| 155 | + $requestLogs[] = array( |
|
| 156 | + 'type' => 'comment', |
|
| 157 | + 'security' => 'user', |
|
| 158 | + 'userid' => null, |
|
| 159 | + 'user' => $request->getName(), |
|
| 160 | + 'entry' => null, |
|
| 161 | + 'time' => $request->getDate(), |
|
| 162 | + 'canedit' => false, |
|
| 163 | + 'id' => $request->getId(), |
|
| 164 | + 'comment' => $request->getComment(), |
|
| 165 | + ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** @var User[] $nameCache */ |
|
| 169 | + $nameCache = array(); |
|
| 170 | + |
|
| 171 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 172 | + |
|
| 173 | + /** @var Log|Comment $entry */ |
|
| 174 | + foreach ($logs as $entry) { |
|
| 175 | + // both log and comment have a 'user' field |
|
| 176 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 177 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 178 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if ($entry instanceof Comment) { |
|
| 182 | + $requestLogs[] = array( |
|
| 183 | + 'type' => 'comment', |
|
| 184 | + 'security' => $entry->getVisibility(), |
|
| 185 | + 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 186 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 187 | + 'entry' => null, |
|
| 188 | + 'time' => $entry->getTime(), |
|
| 189 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 190 | + 'id' => $entry->getId(), |
|
| 191 | + 'comment' => $entry->getComment(), |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($entry instanceof Log) { |
|
| 196 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 197 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 198 | + |
|
| 199 | + $requestLogs[] = array( |
|
| 200 | + 'type' => 'log', |
|
| 201 | + 'security' => 'user', |
|
| 202 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 203 | + 'user' => $entryUser->getUsername(), |
|
| 204 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 205 | + 'time' => $entry->getTimestamp(), |
|
| 206 | + 'canedit' => false, |
|
| 207 | + 'id' => $entry->getId(), |
|
| 208 | + 'comment' => $entry->getComment(), |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $this->assign("requestLogs", $requestLogs); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param Request $request |
|
| 218 | + */ |
|
| 219 | + protected function setupUsernameData(Request $request) |
|
| 220 | + { |
|
| 221 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 222 | + |
|
| 223 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 224 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 225 | + |
|
| 226 | + try { |
|
| 227 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 228 | + } |
|
| 229 | + catch (Exception $ex) { |
|
| 230 | + $spoofs = $ex->getMessage(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + $this->assign("spoofs", $spoofs); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -178,12 +178,12 @@ |
||
| 178 | 178 | $onWikiName = $strings->ucfirst($onWikiName); |
| 179 | 179 | |
| 180 | 180 | $parameters = self::$apiQueryParameters; |
| 181 | - $parameters['pltitles'] = "User:" . $onWikiName; |
|
| 181 | + $parameters['pltitles'] = "User:".$onWikiName; |
|
| 182 | 182 | $response = $this->httpHelper->get($this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(), $parameters); |
| 183 | 183 | $response = json_decode($response, true); |
| 184 | 184 | |
| 185 | 185 | $page = @array_pop($response['query']['pages']); |
| 186 | 186 | |
| 187 | - return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
| 187 | + return @$page['links'][0]['title'] === "User:".$onWikiName; |
|
| 188 | 188 | } |
| 189 | 189 | } |
@@ -26,131 +26,131 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class IdentificationVerifier |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
| 31 | - * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
| 32 | - * of these values is *not* necessary; this is done automatically. |
|
| 33 | - * |
|
| 34 | - * @var string[] |
|
| 35 | - * @category Security-Critical |
|
| 36 | - */ |
|
| 37 | - private static $apiQueryParameters = array( |
|
| 38 | - 'action' => 'query', |
|
| 39 | - 'format' => 'json', |
|
| 40 | - 'prop' => 'links', |
|
| 41 | - 'titles' => 'Access to nonpublic information policy/Noticeboard', |
|
| 42 | - // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
| 43 | - 'pltitles' => '', |
|
| 44 | - ); |
|
| 45 | - /** @var HttpHelper */ |
|
| 46 | - private $httpHelper; |
|
| 47 | - /** @var SiteConfiguration */ |
|
| 48 | - private $siteConfiguration; |
|
| 49 | - /** @var PdoDatabase */ |
|
| 50 | - private $dbObject; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * IdentificationVerifier constructor. |
|
| 54 | - * |
|
| 55 | - * @param HttpHelper $httpHelper |
|
| 56 | - * @param SiteConfiguration $siteConfiguration |
|
| 57 | - * @param PdoDatabase $dbObject |
|
| 58 | - */ |
|
| 59 | - public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 60 | - { |
|
| 61 | - $this->httpHelper = $httpHelper; |
|
| 62 | - $this->siteConfiguration = $siteConfiguration; |
|
| 63 | - $this->dbObject = $dbObject; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 68 | - * |
|
| 69 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 70 | - * |
|
| 71 | - * @return bool |
|
| 72 | - * @category Security-Critical |
|
| 73 | - */ |
|
| 74 | - public function isUserIdentified($onWikiName) |
|
| 75 | - { |
|
| 76 | - if ($this->checkIdentificationCache($onWikiName)) { |
|
| 77 | - return true; |
|
| 78 | - } |
|
| 79 | - else { |
|
| 80 | - if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
| 81 | - $this->cacheIdentificationStatus($onWikiName); |
|
| 82 | - |
|
| 83 | - return true; |
|
| 84 | - } |
|
| 85 | - else { |
|
| 86 | - return false; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Checks if the given user has a valid entry in the idcache table. |
|
| 93 | - * |
|
| 94 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 95 | - * |
|
| 96 | - * @return bool |
|
| 97 | - * @category Security-Critical |
|
| 98 | - */ |
|
| 99 | - private function checkIdentificationCache($onWikiName) |
|
| 100 | - { |
|
| 101 | - $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
| 102 | - |
|
| 103 | - $query = <<<SQL |
|
| 29 | + /** |
|
| 30 | + * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
| 31 | + * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
| 32 | + * of these values is *not* necessary; this is done automatically. |
|
| 33 | + * |
|
| 34 | + * @var string[] |
|
| 35 | + * @category Security-Critical |
|
| 36 | + */ |
|
| 37 | + private static $apiQueryParameters = array( |
|
| 38 | + 'action' => 'query', |
|
| 39 | + 'format' => 'json', |
|
| 40 | + 'prop' => 'links', |
|
| 41 | + 'titles' => 'Access to nonpublic information policy/Noticeboard', |
|
| 42 | + // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
| 43 | + 'pltitles' => '', |
|
| 44 | + ); |
|
| 45 | + /** @var HttpHelper */ |
|
| 46 | + private $httpHelper; |
|
| 47 | + /** @var SiteConfiguration */ |
|
| 48 | + private $siteConfiguration; |
|
| 49 | + /** @var PdoDatabase */ |
|
| 50 | + private $dbObject; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * IdentificationVerifier constructor. |
|
| 54 | + * |
|
| 55 | + * @param HttpHelper $httpHelper |
|
| 56 | + * @param SiteConfiguration $siteConfiguration |
|
| 57 | + * @param PdoDatabase $dbObject |
|
| 58 | + */ |
|
| 59 | + public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 60 | + { |
|
| 61 | + $this->httpHelper = $httpHelper; |
|
| 62 | + $this->siteConfiguration = $siteConfiguration; |
|
| 63 | + $this->dbObject = $dbObject; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 68 | + * |
|
| 69 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 70 | + * |
|
| 71 | + * @return bool |
|
| 72 | + * @category Security-Critical |
|
| 73 | + */ |
|
| 74 | + public function isUserIdentified($onWikiName) |
|
| 75 | + { |
|
| 76 | + if ($this->checkIdentificationCache($onWikiName)) { |
|
| 77 | + return true; |
|
| 78 | + } |
|
| 79 | + else { |
|
| 80 | + if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
| 81 | + $this->cacheIdentificationStatus($onWikiName); |
|
| 82 | + |
|
| 83 | + return true; |
|
| 84 | + } |
|
| 85 | + else { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Checks if the given user has a valid entry in the idcache table. |
|
| 93 | + * |
|
| 94 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 95 | + * |
|
| 96 | + * @return bool |
|
| 97 | + * @category Security-Critical |
|
| 98 | + */ |
|
| 99 | + private function checkIdentificationCache($onWikiName) |
|
| 100 | + { |
|
| 101 | + $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
| 102 | + |
|
| 103 | + $query = <<<SQL |
|
| 104 | 104 | SELECT COUNT(`id`) |
| 105 | 105 | FROM `idcache` |
| 106 | 106 | WHERE `onwikiusername` = :onwikiname |
| 107 | 107 | AND DATE_ADD(`checktime`, INTERVAL {$interval}) >= NOW(); |
| 108 | 108 | SQL; |
| 109 | - $stmt = $this->dbObject->prepare($query); |
|
| 110 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 111 | - $stmt->execute(); |
|
| 112 | - |
|
| 113 | - // Guaranteed by the query to only return a single row with a single column |
|
| 114 | - $results = $stmt->fetch(PDO::FETCH_NUM); |
|
| 115 | - |
|
| 116 | - // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
| 117 | - // unique key - but meh. |
|
| 118 | - return $results[0] != 0; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
| 123 | - * idcache table. Meant to be called periodically by a maintenance script. |
|
| 124 | - * |
|
| 125 | - * @param SiteConfiguration $siteConfiguration |
|
| 126 | - * @param PdoDatabase $dbObject |
|
| 127 | - * |
|
| 128 | - * @return void |
|
| 129 | - */ |
|
| 130 | - public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 131 | - { |
|
| 132 | - $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
| 133 | - |
|
| 134 | - $query = <<<SQL |
|
| 109 | + $stmt = $this->dbObject->prepare($query); |
|
| 110 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 111 | + $stmt->execute(); |
|
| 112 | + |
|
| 113 | + // Guaranteed by the query to only return a single row with a single column |
|
| 114 | + $results = $stmt->fetch(PDO::FETCH_NUM); |
|
| 115 | + |
|
| 116 | + // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
| 117 | + // unique key - but meh. |
|
| 118 | + return $results[0] != 0; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
| 123 | + * idcache table. Meant to be called periodically by a maintenance script. |
|
| 124 | + * |
|
| 125 | + * @param SiteConfiguration $siteConfiguration |
|
| 126 | + * @param PdoDatabase $dbObject |
|
| 127 | + * |
|
| 128 | + * @return void |
|
| 129 | + */ |
|
| 130 | + public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 131 | + { |
|
| 132 | + $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
| 133 | + |
|
| 134 | + $query = <<<SQL |
|
| 135 | 135 | DELETE FROM `idcache` |
| 136 | 136 | WHERE DATE_ADD(`checktime`, INTERVAL {$interval}) < NOW(); |
| 137 | 137 | SQL; |
| 138 | - $dbObject->prepare($query)->execute(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
| 143 | - * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
| 144 | - * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
| 145 | - * |
|
| 146 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 147 | - * |
|
| 148 | - * @return void |
|
| 149 | - * @category Security-Critical |
|
| 150 | - */ |
|
| 151 | - private function cacheIdentificationStatus($onWikiName) |
|
| 152 | - { |
|
| 153 | - $query = <<<SQL |
|
| 138 | + $dbObject->prepare($query)->execute(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
| 143 | + * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
| 144 | + * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
| 145 | + * |
|
| 146 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 147 | + * |
|
| 148 | + * @return void |
|
| 149 | + * @category Security-Critical |
|
| 150 | + */ |
|
| 151 | + private function cacheIdentificationStatus($onWikiName) |
|
| 152 | + { |
|
| 153 | + $query = <<<SQL |
|
| 154 | 154 | INSERT INTO `idcache` |
| 155 | 155 | (`onwikiusername`) |
| 156 | 156 | VALUES |
@@ -159,44 +159,44 @@ discard block |
||
| 159 | 159 | `onwikiusername` = VALUES(`onwikiusername`), |
| 160 | 160 | `checktime` = CURRENT_TIMESTAMP; |
| 161 | 161 | SQL; |
| 162 | - $stmt = $this->dbObject->prepare($query); |
|
| 163 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 164 | - $stmt->execute(); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
| 169 | - * |
|
| 170 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 171 | - * |
|
| 172 | - * @return bool |
|
| 173 | - * @throws EnvironmentException |
|
| 174 | - * @category Security-Critical |
|
| 175 | - */ |
|
| 176 | - private function isIdentifiedOnWiki($onWikiName) |
|
| 177 | - { |
|
| 178 | - $strings = new StringFunctions(); |
|
| 179 | - |
|
| 180 | - // First character of Wikipedia usernames is always capitalized. |
|
| 181 | - $onWikiName = $strings->ucfirst($onWikiName); |
|
| 182 | - |
|
| 183 | - $parameters = self::$apiQueryParameters; |
|
| 184 | - $parameters['pltitles'] = "User:" . $onWikiName; |
|
| 185 | - |
|
| 186 | - try { |
|
| 187 | - $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
| 188 | - $response = $this->httpHelper->get($endpoint, $parameters); |
|
| 189 | - $response = json_decode($response, true); |
|
| 190 | - } catch (CurlException $ex) { |
|
| 191 | - // failed getting identification status, so throw a nicer error. |
|
| 192 | - $m = 'Could not contact metawiki API to determine user\' identification status. ' |
|
| 193 | - . 'This is probably a transient error, so please try again.'; |
|
| 194 | - |
|
| 195 | - throw new EnvironmentException($m, 0, $ex); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $page = @array_pop($response['query']['pages']); |
|
| 199 | - |
|
| 200 | - return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
| 201 | - } |
|
| 162 | + $stmt = $this->dbObject->prepare($query); |
|
| 163 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 164 | + $stmt->execute(); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
| 169 | + * |
|
| 170 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 171 | + * |
|
| 172 | + * @return bool |
|
| 173 | + * @throws EnvironmentException |
|
| 174 | + * @category Security-Critical |
|
| 175 | + */ |
|
| 176 | + private function isIdentifiedOnWiki($onWikiName) |
|
| 177 | + { |
|
| 178 | + $strings = new StringFunctions(); |
|
| 179 | + |
|
| 180 | + // First character of Wikipedia usernames is always capitalized. |
|
| 181 | + $onWikiName = $strings->ucfirst($onWikiName); |
|
| 182 | + |
|
| 183 | + $parameters = self::$apiQueryParameters; |
|
| 184 | + $parameters['pltitles'] = "User:" . $onWikiName; |
|
| 185 | + |
|
| 186 | + try { |
|
| 187 | + $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
| 188 | + $response = $this->httpHelper->get($endpoint, $parameters); |
|
| 189 | + $response = json_decode($response, true); |
|
| 190 | + } catch (CurlException $ex) { |
|
| 191 | + // failed getting identification status, so throw a nicer error. |
|
| 192 | + $m = 'Could not contact metawiki API to determine user\' identification status. ' |
|
| 193 | + . 'This is probably a transient error, so please try again.'; |
|
| 194 | + |
|
| 195 | + throw new EnvironmentException($m, 0, $ex); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $page = @array_pop($response['query']['pages']); |
|
| 199 | + |
|
| 200 | + return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -187,7 +187,8 @@ |
||
| 187 | 187 | $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
| 188 | 188 | $response = $this->httpHelper->get($endpoint, $parameters); |
| 189 | 189 | $response = json_decode($response, true); |
| 190 | - } catch (CurlException $ex) { |
|
| 190 | + } |
|
| 191 | + catch (CurlException $ex) { |
|
| 191 | 192 | // failed getting identification status, so throw a nicer error. |
| 192 | 193 | $m = 'Could not contact metawiki API to determine user\' identification status. ' |
| 193 | 194 | . 'This is probably a transient error, so please try again.'; |
@@ -10,27 +10,27 @@ |
||
| 10 | 10 | |
| 11 | 11 | class IrcColourCode |
| 12 | 12 | { |
| 13 | - const BOLD = "\x02"; |
|
| 14 | - const ITALIC = "\x09"; |
|
| 15 | - const STRIKE = "\x13"; |
|
| 16 | - const UNDERLINE = "\x15"; |
|
| 17 | - const UNDERLINE2 = "\x1f"; |
|
| 18 | - const REVERSE = "\x16"; |
|
| 19 | - const RESET = "\x0f"; |
|
| 20 | - const WHITE = "\x0300"; |
|
| 21 | - const BLACK = "\x0301"; |
|
| 22 | - const DARK_BLUE = "\x0302"; |
|
| 23 | - const DARK_GREEN = "\x0303"; |
|
| 24 | - const RED = "\x0304"; |
|
| 25 | - const DARK_RED = "\x0305"; |
|
| 26 | - const DARK_VIOLET = "\x0306"; |
|
| 27 | - const ORANGE = "\x0307"; |
|
| 28 | - const YELLOW = "\x0308"; |
|
| 29 | - const LIGHT_GREEN = "\x0309"; |
|
| 30 | - const CYAN = "\x0310"; |
|
| 31 | - const LIGHT_CYAN = "\x0311"; |
|
| 32 | - const BLUE = "\x0312"; |
|
| 33 | - const VIOLET = "\x0313"; |
|
| 34 | - const DARK_GREY = "\x0314"; |
|
| 35 | - const LIGHT_GREY = "\x0315"; |
|
| 13 | + const BOLD = "\x02"; |
|
| 14 | + const ITALIC = "\x09"; |
|
| 15 | + const STRIKE = "\x13"; |
|
| 16 | + const UNDERLINE = "\x15"; |
|
| 17 | + const UNDERLINE2 = "\x1f"; |
|
| 18 | + const REVERSE = "\x16"; |
|
| 19 | + const RESET = "\x0f"; |
|
| 20 | + const WHITE = "\x0300"; |
|
| 21 | + const BLACK = "\x0301"; |
|
| 22 | + const DARK_BLUE = "\x0302"; |
|
| 23 | + const DARK_GREEN = "\x0303"; |
|
| 24 | + const RED = "\x0304"; |
|
| 25 | + const DARK_RED = "\x0305"; |
|
| 26 | + const DARK_VIOLET = "\x0306"; |
|
| 27 | + const ORANGE = "\x0307"; |
|
| 28 | + const YELLOW = "\x0308"; |
|
| 29 | + const LIGHT_GREEN = "\x0309"; |
|
| 30 | + const CYAN = "\x0310"; |
|
| 31 | + const LIGHT_CYAN = "\x0311"; |
|
| 32 | + const BLUE = "\x0312"; |
|
| 33 | + const VIOLET = "\x0313"; |
|
| 34 | + const DARK_GREY = "\x0314"; |
|
| 35 | + const LIGHT_GREY = "\x0315"; |
|
| 36 | 36 | } |
@@ -21,22 +21,22 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class ReadableException extends Exception |
| 23 | 23 | { |
| 24 | - use TemplateOutput; |
|
| 24 | + use TemplateOutput; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - abstract public function getReadableError(); |
|
| 26 | + /** |
|
| 27 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + abstract public function getReadableError(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return SiteConfiguration |
|
| 34 | - */ |
|
| 35 | - protected function getSiteConfiguration() |
|
| 36 | - { |
|
| 37 | - // Uck. However, we have encountered an exception. |
|
| 38 | - global $siteConfiguration; |
|
| 32 | + /** |
|
| 33 | + * @return SiteConfiguration |
|
| 34 | + */ |
|
| 35 | + protected function getSiteConfiguration() |
|
| 36 | + { |
|
| 37 | + // Uck. However, we have encountered an exception. |
|
| 38 | + global $siteConfiguration; |
|
| 39 | 39 | |
| 40 | - return $siteConfiguration; |
|
| 41 | - } |
|
| 40 | + return $siteConfiguration; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -21,13 +21,13 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class EnvironmentException extends Exception |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * EnvironmentException constructor. |
|
| 26 | - * |
|
| 27 | - * @param string $friendlyMessage |
|
| 28 | - */ |
|
| 29 | - public function __construct($friendlyMessage) |
|
| 30 | - { |
|
| 31 | - parent::__construct($friendlyMessage); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * EnvironmentException constructor. |
|
| 26 | + * |
|
| 27 | + * @param string $friendlyMessage |
|
| 28 | + */ |
|
| 29 | + public function __construct($friendlyMessage) |
|
| 30 | + { |
|
| 31 | + parent::__construct($friendlyMessage); |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |
@@ -15,112 +15,112 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PdoDatabase extends PDO |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var PdoDatabase[] |
|
| 20 | - */ |
|
| 21 | - private static $connections = array(); |
|
| 22 | - /** |
|
| 23 | - * @var bool True if a transaction is active |
|
| 24 | - */ |
|
| 25 | - protected $hasActiveTransaction = false; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Unless you're doing low-level work, this is not the function you want. |
|
| 29 | - * |
|
| 30 | - * @param string $connectionName |
|
| 31 | - * |
|
| 32 | - * @return PdoDatabase |
|
| 33 | - * @throws Exception |
|
| 34 | - */ |
|
| 35 | - public static function getDatabaseConnection($connectionName) |
|
| 36 | - { |
|
| 37 | - if (!isset(self::$connections[$connectionName])) { |
|
| 38 | - global $cDatabaseConfig; |
|
| 39 | - |
|
| 40 | - if (!array_key_exists($connectionName, $cDatabaseConfig)) { |
|
| 41 | - throw new Exception("Database configuration not found for alias $connectionName"); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - try { |
|
| 45 | - $databaseObject = new PdoDatabase( |
|
| 46 | - $cDatabaseConfig[$connectionName]["dsrcname"], |
|
| 47 | - $cDatabaseConfig[$connectionName]["username"], |
|
| 48 | - $cDatabaseConfig[$connectionName]["password"] |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - catch (PDOException $ex) { |
|
| 52 | - // wrap around any potential stack traces which may include passwords |
|
| 53 | - throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage()); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 57 | - |
|
| 58 | - // emulating prepared statements gives a performance boost on MySQL. |
|
| 59 | - // |
|
| 60 | - // however, our version of PDO doesn't seem to understand parameter types when emulating |
|
| 61 | - // the prepared statements, so we're forced to turn this off for now. |
|
| 62 | - // -- stw 2014-02-11 |
|
| 63 | - $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
|
| 64 | - |
|
| 65 | - self::$connections[$connectionName] = $databaseObject; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return self::$connections[$connectionName]; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Determines if this connection has a transaction in progress or not |
|
| 73 | - * @return boolean true if there is a transaction in progress. |
|
| 74 | - */ |
|
| 75 | - public function hasActiveTransaction() |
|
| 76 | - { |
|
| 77 | - return $this->hasActiveTransaction; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Summary of beginTransaction |
|
| 82 | - * @return bool |
|
| 83 | - */ |
|
| 84 | - public function beginTransaction() |
|
| 85 | - { |
|
| 86 | - // Override the pre-existing method, which doesn't stop you from |
|
| 87 | - // starting transactions within transactions - which doesn't work and |
|
| 88 | - // will throw an exception. This eliminates the need to catch exceptions |
|
| 89 | - // all over the rest of the code |
|
| 90 | - if ($this->hasActiveTransaction) { |
|
| 91 | - return false; |
|
| 92 | - } |
|
| 93 | - else { |
|
| 94 | - // set the transaction isolation level for every transaction. |
|
| 95 | - $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); |
|
| 96 | - |
|
| 97 | - // start a new transaction, and return whether or not the start was |
|
| 98 | - // successful |
|
| 99 | - $this->hasActiveTransaction = parent::beginTransaction(); |
|
| 100 | - |
|
| 101 | - return $this->hasActiveTransaction; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Commits the active transaction |
|
| 107 | - */ |
|
| 108 | - public function commit() |
|
| 109 | - { |
|
| 110 | - if ($this->hasActiveTransaction) { |
|
| 111 | - parent::commit(); |
|
| 112 | - $this->hasActiveTransaction = false; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Rolls back a transaction |
|
| 118 | - */ |
|
| 119 | - public function rollBack() |
|
| 120 | - { |
|
| 121 | - if ($this->hasActiveTransaction) { |
|
| 122 | - parent::rollback(); |
|
| 123 | - $this->hasActiveTransaction = false; |
|
| 124 | - } |
|
| 125 | - } |
|
| 18 | + /** |
|
| 19 | + * @var PdoDatabase[] |
|
| 20 | + */ |
|
| 21 | + private static $connections = array(); |
|
| 22 | + /** |
|
| 23 | + * @var bool True if a transaction is active |
|
| 24 | + */ |
|
| 25 | + protected $hasActiveTransaction = false; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Unless you're doing low-level work, this is not the function you want. |
|
| 29 | + * |
|
| 30 | + * @param string $connectionName |
|
| 31 | + * |
|
| 32 | + * @return PdoDatabase |
|
| 33 | + * @throws Exception |
|
| 34 | + */ |
|
| 35 | + public static function getDatabaseConnection($connectionName) |
|
| 36 | + { |
|
| 37 | + if (!isset(self::$connections[$connectionName])) { |
|
| 38 | + global $cDatabaseConfig; |
|
| 39 | + |
|
| 40 | + if (!array_key_exists($connectionName, $cDatabaseConfig)) { |
|
| 41 | + throw new Exception("Database configuration not found for alias $connectionName"); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + try { |
|
| 45 | + $databaseObject = new PdoDatabase( |
|
| 46 | + $cDatabaseConfig[$connectionName]["dsrcname"], |
|
| 47 | + $cDatabaseConfig[$connectionName]["username"], |
|
| 48 | + $cDatabaseConfig[$connectionName]["password"] |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + catch (PDOException $ex) { |
|
| 52 | + // wrap around any potential stack traces which may include passwords |
|
| 53 | + throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage()); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 57 | + |
|
| 58 | + // emulating prepared statements gives a performance boost on MySQL. |
|
| 59 | + // |
|
| 60 | + // however, our version of PDO doesn't seem to understand parameter types when emulating |
|
| 61 | + // the prepared statements, so we're forced to turn this off for now. |
|
| 62 | + // -- stw 2014-02-11 |
|
| 63 | + $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
|
| 64 | + |
|
| 65 | + self::$connections[$connectionName] = $databaseObject; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return self::$connections[$connectionName]; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Determines if this connection has a transaction in progress or not |
|
| 73 | + * @return boolean true if there is a transaction in progress. |
|
| 74 | + */ |
|
| 75 | + public function hasActiveTransaction() |
|
| 76 | + { |
|
| 77 | + return $this->hasActiveTransaction; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Summary of beginTransaction |
|
| 82 | + * @return bool |
|
| 83 | + */ |
|
| 84 | + public function beginTransaction() |
|
| 85 | + { |
|
| 86 | + // Override the pre-existing method, which doesn't stop you from |
|
| 87 | + // starting transactions within transactions - which doesn't work and |
|
| 88 | + // will throw an exception. This eliminates the need to catch exceptions |
|
| 89 | + // all over the rest of the code |
|
| 90 | + if ($this->hasActiveTransaction) { |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 93 | + else { |
|
| 94 | + // set the transaction isolation level for every transaction. |
|
| 95 | + $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); |
|
| 96 | + |
|
| 97 | + // start a new transaction, and return whether or not the start was |
|
| 98 | + // successful |
|
| 99 | + $this->hasActiveTransaction = parent::beginTransaction(); |
|
| 100 | + |
|
| 101 | + return $this->hasActiveTransaction; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Commits the active transaction |
|
| 107 | + */ |
|
| 108 | + public function commit() |
|
| 109 | + { |
|
| 110 | + if ($this->hasActiveTransaction) { |
|
| 111 | + parent::commit(); |
|
| 112 | + $this->hasActiveTransaction = false; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Rolls back a transaction |
|
| 118 | + */ |
|
| 119 | + public function rollBack() |
|
| 120 | + { |
|
| 121 | + if ($this->hasActiveTransaction) { |
|
| 122 | + parent::rollback(); |
|
| 123 | + $this->hasActiveTransaction = false; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | } |
| 51 | 51 | catch (PDOException $ex) { |
| 52 | 52 | // wrap around any potential stack traces which may include passwords |
| 53 | - throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage()); |
|
| 53 | + throw new EnvironmentException("Error connecting to database '$connectionName': ".$ex->getMessage()); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |