@@ -12,20 +12,20 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Page404 extends InternalPageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no actions are called. |
|
| 17 | - */ |
|
| 18 | - protected function main() |
|
| 19 | - { |
|
| 20 | - if (!headers_sent()) { |
|
| 21 | - header("HTTP/1.1 404 Not Found"); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no actions are called. |
|
| 17 | + */ |
|
| 18 | + protected function main() |
|
| 19 | + { |
|
| 20 | + if (!headers_sent()) { |
|
| 21 | + header("HTTP/1.1 404 Not Found"); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $this->setTemplate("404.tpl"); |
|
| 25 | - } |
|
| 24 | + $this->setTemplate("404.tpl"); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function isProtectedPage() |
|
| 28 | - { |
|
| 29 | - return false; |
|
| 30 | - } |
|
| 27 | + protected function isProtectedPage() |
|
| 28 | + { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function getNameSearchResults($searchTerm) |
| 93 | 93 | { |
| 94 | - $padded = '%' . $searchTerm . '%'; |
|
| 94 | + $padded = '%'.$searchTerm.'%'; |
|
| 95 | 95 | |
| 96 | 96 | /** @var Request[] $requests */ |
| 97 | 97 | $requests = RequestSearchHelper::get($this->getDatabase()) |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | throw new ApplicationLogicException('The search term "@" is not valid for email address searches!'); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $padded = '%' . $searchTerm . '%'; |
|
| 119 | + $padded = '%'.$searchTerm.'%'; |
|
| 120 | 120 | |
| 121 | 121 | /** @var Request[] $requests */ |
| 122 | 122 | $requests = RequestSearchHelper::get($this->getDatabase()) |
@@ -20,190 +20,190 @@ |
||
| 20 | 20 | |
| 21 | 21 | class PageSearch extends InternalPageBase |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Main function for this page, when no specific actions are called. |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $this->setHtmlTitle('Search'); |
|
| 29 | - |
|
| 30 | - // Dual-mode page |
|
| 31 | - if (WebRequest::wasPosted()) { |
|
| 32 | - $searchType = WebRequest::postString('type'); |
|
| 33 | - $searchTerm = WebRequest::postString('term'); |
|
| 34 | - |
|
| 35 | - $validationError = ""; |
|
| 36 | - if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
|
| 37 | - SessionAlert::error($validationError, "Search error"); |
|
| 38 | - $this->redirect("search"); |
|
| 39 | - |
|
| 40 | - return; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $results = array(); |
|
| 44 | - |
|
| 45 | - switch ($searchType) { |
|
| 46 | - case 'name': |
|
| 47 | - $results = $this->getNameSearchResults($searchTerm); |
|
| 48 | - break; |
|
| 49 | - case 'email': |
|
| 50 | - $results = $this->getEmailSearchResults($searchTerm); |
|
| 51 | - break; |
|
| 52 | - case 'ip': |
|
| 53 | - $results = $this->getIpSearchResults($searchTerm); |
|
| 54 | - break; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // deal with results |
|
| 58 | - $this->assign('requests', $results); |
|
| 59 | - $this->assign('term', $searchTerm); |
|
| 60 | - $this->assign('target', $searchType); |
|
| 61 | - |
|
| 62 | - $userIds = array_map( |
|
| 63 | - function(Request $entry) { |
|
| 64 | - return $entry->getReserved(); |
|
| 65 | - }, |
|
| 66 | - $results); |
|
| 67 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 68 | - $this->assign('userList', $userList); |
|
| 69 | - |
|
| 70 | - $requestTrustedIp = []; |
|
| 71 | - $relatedEmailRequests = []; |
|
| 72 | - $relatedIpRequests = []; |
|
| 73 | - foreach ($results as $request) { |
|
| 74 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 75 | - $request->getIp(), |
|
| 76 | - $request->getForwardedIp() |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - RequestSearchHelper::get($this->getDatabase()) |
|
| 80 | - ->byIp($trustedIp) |
|
| 81 | - ->withConfirmedEmail() |
|
| 82 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 83 | - ->excludingRequest($request->getId()) |
|
| 84 | - ->getRecordCount($ipCount); |
|
| 85 | - |
|
| 86 | - RequestSearchHelper::get($this->getDatabase()) |
|
| 87 | - ->byEmailAddress($request->getEmail()) |
|
| 88 | - ->withConfirmedEmail() |
|
| 89 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 90 | - ->excludingRequest($request->getId()) |
|
| 91 | - ->getRecordCount($emailCount); |
|
| 92 | - |
|
| 93 | - $requestTrustedIp[$request->getId()] = $trustedIp; |
|
| 94 | - $relatedEmailRequests[$request->getId()] = $emailCount; |
|
| 95 | - $relatedIpRequests[$request->getId()] = $ipCount; |
|
| 96 | - } |
|
| 97 | - $this->assign('requestTrustedIp', $requestTrustedIp); |
|
| 98 | - $this->assign('relatedEmailRequests', $relatedEmailRequests); |
|
| 99 | - $this->assign('relatedIpRequests', $relatedIpRequests); |
|
| 100 | - |
|
| 101 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 102 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 103 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 104 | - |
|
| 105 | - $this->assign('showPrivateData', $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')); |
|
| 106 | - $this->assign('xff', $this->getXffTrustProvider()); |
|
| 107 | - |
|
| 108 | - $this->assign('dataClearEmail', $this->getSiteConfiguration()->getDataClearEmail()); |
|
| 109 | - $this->assign('dataClearIp', $this->getSiteConfiguration()->getDataClearIp()); |
|
| 110 | - |
|
| 111 | - $this->assignCSRFToken(); |
|
| 112 | - $this->setTemplate('search/searchResult.tpl'); |
|
| 113 | - } |
|
| 114 | - else { |
|
| 115 | - $this->assignCSRFToken(); |
|
| 116 | - $this->setTemplate('search/searchForm.tpl'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Gets search results by name |
|
| 122 | - * |
|
| 123 | - * @param string $searchTerm |
|
| 124 | - * |
|
| 125 | - * @returns Request[] |
|
| 126 | - */ |
|
| 127 | - private function getNameSearchResults($searchTerm) |
|
| 128 | - { |
|
| 129 | - $padded = '%' . $searchTerm . '%'; |
|
| 130 | - |
|
| 131 | - /** @var Request[] $requests */ |
|
| 132 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 133 | - ->byName($padded) |
|
| 134 | - ->fetch(); |
|
| 135 | - |
|
| 136 | - return $requests; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Gets search results by email |
|
| 141 | - * |
|
| 142 | - * @param string $searchTerm |
|
| 143 | - * |
|
| 144 | - * @return Request[] |
|
| 145 | - * @throws ApplicationLogicException |
|
| 146 | - */ |
|
| 147 | - private function getEmailSearchResults($searchTerm) |
|
| 148 | - { |
|
| 149 | - if ($searchTerm === "@") { |
|
| 150 | - throw new ApplicationLogicException('The search term "@" is not valid for email address searches!'); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $padded = '%' . $searchTerm . '%'; |
|
| 154 | - |
|
| 155 | - /** @var Request[] $requests */ |
|
| 156 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 157 | - ->byEmailAddress($padded) |
|
| 158 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 159 | - ->fetch(); |
|
| 160 | - |
|
| 161 | - return $requests; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Gets search results by IP address or XFF IP address |
|
| 166 | - * |
|
| 167 | - * @param string $searchTerm |
|
| 168 | - * |
|
| 169 | - * @returns Request[] |
|
| 170 | - */ |
|
| 171 | - private function getIpSearchResults($searchTerm) |
|
| 172 | - { |
|
| 173 | - /** @var Request[] $requests */ |
|
| 174 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 175 | - ->byIp($searchTerm) |
|
| 176 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 177 | - ->fetch(); |
|
| 178 | - |
|
| 179 | - return $requests; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @param string $searchType |
|
| 184 | - * @param string $searchTerm |
|
| 185 | - * |
|
| 186 | - * @param string $errorMessage |
|
| 187 | - * |
|
| 188 | - * @return bool true if parameters are valid |
|
| 189 | - * @throws ApplicationLogicException |
|
| 190 | - */ |
|
| 191 | - protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage) |
|
| 192 | - { |
|
| 193 | - if (!in_array($searchType, array('name', 'email', 'ip'))) { |
|
| 194 | - $errorMessage = 'Unknown search type'; |
|
| 195 | - |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) { |
|
| 200 | - $errorMessage = 'No search term specified entered'; |
|
| 201 | - |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $errorMessage = ""; |
|
| 206 | - |
|
| 207 | - return true; |
|
| 208 | - } |
|
| 23 | + /** |
|
| 24 | + * Main function for this page, when no specific actions are called. |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $this->setHtmlTitle('Search'); |
|
| 29 | + |
|
| 30 | + // Dual-mode page |
|
| 31 | + if (WebRequest::wasPosted()) { |
|
| 32 | + $searchType = WebRequest::postString('type'); |
|
| 33 | + $searchTerm = WebRequest::postString('term'); |
|
| 34 | + |
|
| 35 | + $validationError = ""; |
|
| 36 | + if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
|
| 37 | + SessionAlert::error($validationError, "Search error"); |
|
| 38 | + $this->redirect("search"); |
|
| 39 | + |
|
| 40 | + return; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $results = array(); |
|
| 44 | + |
|
| 45 | + switch ($searchType) { |
|
| 46 | + case 'name': |
|
| 47 | + $results = $this->getNameSearchResults($searchTerm); |
|
| 48 | + break; |
|
| 49 | + case 'email': |
|
| 50 | + $results = $this->getEmailSearchResults($searchTerm); |
|
| 51 | + break; |
|
| 52 | + case 'ip': |
|
| 53 | + $results = $this->getIpSearchResults($searchTerm); |
|
| 54 | + break; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // deal with results |
|
| 58 | + $this->assign('requests', $results); |
|
| 59 | + $this->assign('term', $searchTerm); |
|
| 60 | + $this->assign('target', $searchType); |
|
| 61 | + |
|
| 62 | + $userIds = array_map( |
|
| 63 | + function(Request $entry) { |
|
| 64 | + return $entry->getReserved(); |
|
| 65 | + }, |
|
| 66 | + $results); |
|
| 67 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 68 | + $this->assign('userList', $userList); |
|
| 69 | + |
|
| 70 | + $requestTrustedIp = []; |
|
| 71 | + $relatedEmailRequests = []; |
|
| 72 | + $relatedIpRequests = []; |
|
| 73 | + foreach ($results as $request) { |
|
| 74 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 75 | + $request->getIp(), |
|
| 76 | + $request->getForwardedIp() |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + RequestSearchHelper::get($this->getDatabase()) |
|
| 80 | + ->byIp($trustedIp) |
|
| 81 | + ->withConfirmedEmail() |
|
| 82 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 83 | + ->excludingRequest($request->getId()) |
|
| 84 | + ->getRecordCount($ipCount); |
|
| 85 | + |
|
| 86 | + RequestSearchHelper::get($this->getDatabase()) |
|
| 87 | + ->byEmailAddress($request->getEmail()) |
|
| 88 | + ->withConfirmedEmail() |
|
| 89 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 90 | + ->excludingRequest($request->getId()) |
|
| 91 | + ->getRecordCount($emailCount); |
|
| 92 | + |
|
| 93 | + $requestTrustedIp[$request->getId()] = $trustedIp; |
|
| 94 | + $relatedEmailRequests[$request->getId()] = $emailCount; |
|
| 95 | + $relatedIpRequests[$request->getId()] = $ipCount; |
|
| 96 | + } |
|
| 97 | + $this->assign('requestTrustedIp', $requestTrustedIp); |
|
| 98 | + $this->assign('relatedEmailRequests', $relatedEmailRequests); |
|
| 99 | + $this->assign('relatedIpRequests', $relatedIpRequests); |
|
| 100 | + |
|
| 101 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 102 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 103 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 104 | + |
|
| 105 | + $this->assign('showPrivateData', $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')); |
|
| 106 | + $this->assign('xff', $this->getXffTrustProvider()); |
|
| 107 | + |
|
| 108 | + $this->assign('dataClearEmail', $this->getSiteConfiguration()->getDataClearEmail()); |
|
| 109 | + $this->assign('dataClearIp', $this->getSiteConfiguration()->getDataClearIp()); |
|
| 110 | + |
|
| 111 | + $this->assignCSRFToken(); |
|
| 112 | + $this->setTemplate('search/searchResult.tpl'); |
|
| 113 | + } |
|
| 114 | + else { |
|
| 115 | + $this->assignCSRFToken(); |
|
| 116 | + $this->setTemplate('search/searchForm.tpl'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Gets search results by name |
|
| 122 | + * |
|
| 123 | + * @param string $searchTerm |
|
| 124 | + * |
|
| 125 | + * @returns Request[] |
|
| 126 | + */ |
|
| 127 | + private function getNameSearchResults($searchTerm) |
|
| 128 | + { |
|
| 129 | + $padded = '%' . $searchTerm . '%'; |
|
| 130 | + |
|
| 131 | + /** @var Request[] $requests */ |
|
| 132 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 133 | + ->byName($padded) |
|
| 134 | + ->fetch(); |
|
| 135 | + |
|
| 136 | + return $requests; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Gets search results by email |
|
| 141 | + * |
|
| 142 | + * @param string $searchTerm |
|
| 143 | + * |
|
| 144 | + * @return Request[] |
|
| 145 | + * @throws ApplicationLogicException |
|
| 146 | + */ |
|
| 147 | + private function getEmailSearchResults($searchTerm) |
|
| 148 | + { |
|
| 149 | + if ($searchTerm === "@") { |
|
| 150 | + throw new ApplicationLogicException('The search term "@" is not valid for email address searches!'); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $padded = '%' . $searchTerm . '%'; |
|
| 154 | + |
|
| 155 | + /** @var Request[] $requests */ |
|
| 156 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 157 | + ->byEmailAddress($padded) |
|
| 158 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 159 | + ->fetch(); |
|
| 160 | + |
|
| 161 | + return $requests; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Gets search results by IP address or XFF IP address |
|
| 166 | + * |
|
| 167 | + * @param string $searchTerm |
|
| 168 | + * |
|
| 169 | + * @returns Request[] |
|
| 170 | + */ |
|
| 171 | + private function getIpSearchResults($searchTerm) |
|
| 172 | + { |
|
| 173 | + /** @var Request[] $requests */ |
|
| 174 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
| 175 | + ->byIp($searchTerm) |
|
| 176 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
| 177 | + ->fetch(); |
|
| 178 | + |
|
| 179 | + return $requests; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @param string $searchType |
|
| 184 | + * @param string $searchTerm |
|
| 185 | + * |
|
| 186 | + * @param string $errorMessage |
|
| 187 | + * |
|
| 188 | + * @return bool true if parameters are valid |
|
| 189 | + * @throws ApplicationLogicException |
|
| 190 | + */ |
|
| 191 | + protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage) |
|
| 192 | + { |
|
| 193 | + if (!in_array($searchType, array('name', 'email', 'ip'))) { |
|
| 194 | + $errorMessage = 'Unknown search type'; |
|
| 195 | + |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) { |
|
| 200 | + $errorMessage = 'No search term specified entered'; |
|
| 201 | + |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $errorMessage = ""; |
|
| 206 | + |
|
| 207 | + return true; |
|
| 208 | + } |
|
| 209 | 209 | } |
@@ -21,310 +21,310 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageBan extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - */ |
|
| 27 | - protected function main() |
|
| 28 | - { |
|
| 29 | - $this->assignCSRFToken(); |
|
| 30 | - |
|
| 31 | - $this->setHtmlTitle('Bans'); |
|
| 32 | - |
|
| 33 | - $bans = Ban::getActiveBans(null, $this->getDatabase()); |
|
| 34 | - |
|
| 35 | - $userIds = array_map( |
|
| 36 | - function(Ban $entry) { |
|
| 37 | - return $entry->getUser(); |
|
| 38 | - }, |
|
| 39 | - $bans); |
|
| 40 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 41 | - |
|
| 42 | - $user = User::getCurrent($this->getDatabase()); |
|
| 43 | - $this->assign('canSet', $this->barrierTest('set', $user)); |
|
| 44 | - $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 45 | - |
|
| 46 | - $this->assign('usernames', $userList); |
|
| 47 | - $this->assign('activebans', $bans); |
|
| 48 | - $this->setTemplate('bans/banlist.tpl'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Entry point for the ban set action |
|
| 53 | - */ |
|
| 54 | - protected function set() |
|
| 55 | - { |
|
| 56 | - $this->setHtmlTitle('Bans'); |
|
| 57 | - |
|
| 58 | - // dual-mode action |
|
| 59 | - if (WebRequest::wasPosted()) { |
|
| 60 | - try { |
|
| 61 | - $this->handlePostMethodForSetBan(); |
|
| 62 | - } |
|
| 63 | - catch (ApplicationLogicException $ex) { |
|
| 64 | - SessionAlert::error($ex->getMessage()); |
|
| 65 | - $this->redirect("bans", "set"); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - $this->handleGetMethodForSetBan(); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Entry point for the ban remove action |
|
| 75 | - */ |
|
| 76 | - protected function remove() |
|
| 77 | - { |
|
| 78 | - $this->setHtmlTitle('Bans'); |
|
| 79 | - |
|
| 80 | - $ban = $this->getBanForUnban(); |
|
| 81 | - |
|
| 82 | - // dual mode |
|
| 83 | - if (WebRequest::wasPosted()) { |
|
| 84 | - $this->validateCSRFToken(); |
|
| 85 | - $unbanReason = WebRequest::postString('unbanreason'); |
|
| 86 | - |
|
| 87 | - if ($unbanReason === null || trim($unbanReason) === "") { |
|
| 88 | - SessionAlert::error('No unban reason specified'); |
|
| 89 | - $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // set optimistic locking from delete form page load |
|
| 93 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 94 | - $ban->setUpdateVersion($updateVersion); |
|
| 95 | - |
|
| 96 | - $database = $this->getDatabase(); |
|
| 97 | - $ban->setActive(false); |
|
| 98 | - $ban->save(); |
|
| 99 | - |
|
| 100 | - Logger::unbanned($database, $ban, $unbanReason); |
|
| 101 | - |
|
| 102 | - SessionAlert::quick('Disabled ban.'); |
|
| 103 | - $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
| 104 | - |
|
| 105 | - $this->redirect('bans'); |
|
| 106 | - } |
|
| 107 | - else { |
|
| 108 | - $this->assignCSRFToken(); |
|
| 109 | - $this->assign('ban', $ban); |
|
| 110 | - $this->setTemplate('bans/unban.tpl'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @throws ApplicationLogicException |
|
| 116 | - */ |
|
| 117 | - private function getBanDuration() |
|
| 118 | - { |
|
| 119 | - $duration = WebRequest::postString('duration'); |
|
| 120 | - if ($duration === "other") { |
|
| 121 | - $duration = strtotime(WebRequest::postString('otherduration')); |
|
| 122 | - |
|
| 123 | - if (!$duration) { |
|
| 124 | - throw new ApplicationLogicException('Invalid ban time'); |
|
| 125 | - } |
|
| 126 | - elseif (time() > $duration) { |
|
| 127 | - throw new ApplicationLogicException('Ban time has already expired!'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $duration; |
|
| 131 | - } |
|
| 132 | - elseif ($duration === "-1") { |
|
| 133 | - $duration = -1; |
|
| 134 | - |
|
| 135 | - return $duration; |
|
| 136 | - } |
|
| 137 | - else { |
|
| 138 | - $duration = WebRequest::postInt('duration') + time(); |
|
| 139 | - |
|
| 140 | - return $duration; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $type |
|
| 146 | - * @param string $target |
|
| 147 | - * |
|
| 148 | - * @throws ApplicationLogicException |
|
| 149 | - */ |
|
| 150 | - private function validateBanType($type, $target) |
|
| 151 | - { |
|
| 152 | - switch ($type) { |
|
| 153 | - case 'IP': |
|
| 154 | - $this->validateIpBan($target); |
|
| 155 | - |
|
| 156 | - return; |
|
| 157 | - case 'Name': |
|
| 158 | - // No validation needed here. |
|
| 159 | - return; |
|
| 160 | - case 'EMail': |
|
| 161 | - $this->validateEmailBanTarget($target); |
|
| 162 | - |
|
| 163 | - return; |
|
| 164 | - default: |
|
| 165 | - throw new ApplicationLogicException("Unknown ban type"); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Handles the POST method on the set action |
|
| 171 | - * |
|
| 172 | - * @throws ApplicationLogicException |
|
| 173 | - * @throws Exception |
|
| 174 | - */ |
|
| 175 | - private function handlePostMethodForSetBan() |
|
| 176 | - { |
|
| 177 | - $this->validateCSRFToken(); |
|
| 178 | - $reason = WebRequest::postString('banreason'); |
|
| 179 | - $target = WebRequest::postString('target'); |
|
| 180 | - |
|
| 181 | - // Checks whether there is a reason entered for ban. |
|
| 182 | - if ($reason === null || trim($reason) === "") { |
|
| 183 | - throw new ApplicationLogicException('You must specify a ban reason'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // Checks whether there is a target entered to ban. |
|
| 187 | - if ($target === null || trim($target) === "") { |
|
| 188 | - throw new ApplicationLogicException('You must specify a target to be banned'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Validate ban duration |
|
| 192 | - $duration = $this->getBanDuration(); |
|
| 193 | - |
|
| 194 | - // Validate ban type & target for that type |
|
| 195 | - $type = WebRequest::postString('type'); |
|
| 196 | - $this->validateBanType($type, $target); |
|
| 197 | - |
|
| 198 | - $database = $this->getDatabase(); |
|
| 199 | - |
|
| 200 | - if (count(Ban::getActiveBans($target, $database)) > 0) { |
|
| 201 | - throw new ApplicationLogicException('This target is already banned!'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $ban = new Ban(); |
|
| 205 | - $ban->setDatabase($database); |
|
| 206 | - $ban->setActive(true); |
|
| 207 | - $ban->setType($type); |
|
| 208 | - $ban->setTarget($target); |
|
| 209 | - $ban->setUser(User::getCurrent($database)->getId()); |
|
| 210 | - $ban->setReason($reason); |
|
| 211 | - $ban->setDuration($duration); |
|
| 212 | - |
|
| 213 | - $ban->save(); |
|
| 214 | - |
|
| 215 | - Logger::banned($database, $ban, $reason); |
|
| 216 | - |
|
| 217 | - $this->getNotificationHelper()->banned($ban); |
|
| 218 | - SessionAlert::quick('Ban has been set.'); |
|
| 219 | - |
|
| 220 | - $this->redirect('bans'); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Handles the GET method on the set action |
|
| 225 | - */ |
|
| 226 | - protected function handleGetMethodForSetBan() |
|
| 227 | - { |
|
| 228 | - $this->setTemplate('bans/banform.tpl'); |
|
| 229 | - $this->assignCSRFToken(); |
|
| 230 | - |
|
| 231 | - $banType = WebRequest::getString('type'); |
|
| 232 | - $banTarget = WebRequest::getInt('request'); |
|
| 233 | - |
|
| 234 | - $database = $this->getDatabase(); |
|
| 235 | - |
|
| 236 | - // if the parameters are null, skip loading a request. |
|
| 237 | - if ($banType === null |
|
| 238 | - || !in_array($banType, array('IP', 'Name', 'EMail')) |
|
| 239 | - || $banTarget === null |
|
| 240 | - || $banTarget === 0 |
|
| 241 | - ) { |
|
| 242 | - $this->assign('bantarget', ''); |
|
| 243 | - $this->assign('bantype', ''); |
|
| 244 | - |
|
| 245 | - return; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Set the ban type, which the user has indicated. |
|
| 249 | - $this->assign('bantype', $banType); |
|
| 250 | - |
|
| 251 | - // Attempt to resolve the correct target |
|
| 252 | - /** @var Request $request */ |
|
| 253 | - $request = Request::getById($banTarget, $database); |
|
| 254 | - if ($request === false) { |
|
| 255 | - $this->assign('bantarget', ''); |
|
| 256 | - |
|
| 257 | - return; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $realTarget = ''; |
|
| 261 | - switch ($banType) { |
|
| 262 | - case 'EMail': |
|
| 263 | - $realTarget = $request->getEmail(); |
|
| 264 | - break; |
|
| 265 | - case 'IP': |
|
| 266 | - $xffProvider = $this->getXffTrustProvider(); |
|
| 267 | - $realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 268 | - break; |
|
| 269 | - case 'Name': |
|
| 270 | - $realTarget = $request->getName(); |
|
| 271 | - break; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $this->assign('bantarget', $realTarget); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Validates an IP ban target |
|
| 279 | - * |
|
| 280 | - * @param string $target |
|
| 281 | - * |
|
| 282 | - * @throws ApplicationLogicException |
|
| 283 | - */ |
|
| 284 | - private function validateIpBan($target) |
|
| 285 | - { |
|
| 286 | - $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
| 287 | - |
|
| 288 | - if (filter_var($target, FILTER_VALIDATE_IP) === false) { |
|
| 289 | - throw new ApplicationLogicException('Invalid target - IP address expected.'); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if (in_array($target, $squidIpList)) { |
|
| 293 | - throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Validates an email address as a ban target |
|
| 299 | - * |
|
| 300 | - * @param string $target |
|
| 301 | - * |
|
| 302 | - * @throws ApplicationLogicException |
|
| 303 | - */ |
|
| 304 | - private function validateEmailBanTarget($target) |
|
| 305 | - { |
|
| 306 | - if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) { |
|
| 307 | - throw new ApplicationLogicException('Invalid target - email address expected.'); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @return Ban |
|
| 313 | - * @throws ApplicationLogicException |
|
| 314 | - */ |
|
| 315 | - private function getBanForUnban() |
|
| 316 | - { |
|
| 317 | - $banId = WebRequest::getInt('id'); |
|
| 318 | - if ($banId === null || $banId === 0) { |
|
| 319 | - throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $ban = Ban::getActiveId($banId, $this->getDatabase()); |
|
| 323 | - |
|
| 324 | - if ($ban === false) { |
|
| 325 | - throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return $ban; |
|
| 329 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + */ |
|
| 27 | + protected function main() |
|
| 28 | + { |
|
| 29 | + $this->assignCSRFToken(); |
|
| 30 | + |
|
| 31 | + $this->setHtmlTitle('Bans'); |
|
| 32 | + |
|
| 33 | + $bans = Ban::getActiveBans(null, $this->getDatabase()); |
|
| 34 | + |
|
| 35 | + $userIds = array_map( |
|
| 36 | + function(Ban $entry) { |
|
| 37 | + return $entry->getUser(); |
|
| 38 | + }, |
|
| 39 | + $bans); |
|
| 40 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 41 | + |
|
| 42 | + $user = User::getCurrent($this->getDatabase()); |
|
| 43 | + $this->assign('canSet', $this->barrierTest('set', $user)); |
|
| 44 | + $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 45 | + |
|
| 46 | + $this->assign('usernames', $userList); |
|
| 47 | + $this->assign('activebans', $bans); |
|
| 48 | + $this->setTemplate('bans/banlist.tpl'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Entry point for the ban set action |
|
| 53 | + */ |
|
| 54 | + protected function set() |
|
| 55 | + { |
|
| 56 | + $this->setHtmlTitle('Bans'); |
|
| 57 | + |
|
| 58 | + // dual-mode action |
|
| 59 | + if (WebRequest::wasPosted()) { |
|
| 60 | + try { |
|
| 61 | + $this->handlePostMethodForSetBan(); |
|
| 62 | + } |
|
| 63 | + catch (ApplicationLogicException $ex) { |
|
| 64 | + SessionAlert::error($ex->getMessage()); |
|
| 65 | + $this->redirect("bans", "set"); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + $this->handleGetMethodForSetBan(); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Entry point for the ban remove action |
|
| 75 | + */ |
|
| 76 | + protected function remove() |
|
| 77 | + { |
|
| 78 | + $this->setHtmlTitle('Bans'); |
|
| 79 | + |
|
| 80 | + $ban = $this->getBanForUnban(); |
|
| 81 | + |
|
| 82 | + // dual mode |
|
| 83 | + if (WebRequest::wasPosted()) { |
|
| 84 | + $this->validateCSRFToken(); |
|
| 85 | + $unbanReason = WebRequest::postString('unbanreason'); |
|
| 86 | + |
|
| 87 | + if ($unbanReason === null || trim($unbanReason) === "") { |
|
| 88 | + SessionAlert::error('No unban reason specified'); |
|
| 89 | + $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // set optimistic locking from delete form page load |
|
| 93 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 94 | + $ban->setUpdateVersion($updateVersion); |
|
| 95 | + |
|
| 96 | + $database = $this->getDatabase(); |
|
| 97 | + $ban->setActive(false); |
|
| 98 | + $ban->save(); |
|
| 99 | + |
|
| 100 | + Logger::unbanned($database, $ban, $unbanReason); |
|
| 101 | + |
|
| 102 | + SessionAlert::quick('Disabled ban.'); |
|
| 103 | + $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
| 104 | + |
|
| 105 | + $this->redirect('bans'); |
|
| 106 | + } |
|
| 107 | + else { |
|
| 108 | + $this->assignCSRFToken(); |
|
| 109 | + $this->assign('ban', $ban); |
|
| 110 | + $this->setTemplate('bans/unban.tpl'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @throws ApplicationLogicException |
|
| 116 | + */ |
|
| 117 | + private function getBanDuration() |
|
| 118 | + { |
|
| 119 | + $duration = WebRequest::postString('duration'); |
|
| 120 | + if ($duration === "other") { |
|
| 121 | + $duration = strtotime(WebRequest::postString('otherduration')); |
|
| 122 | + |
|
| 123 | + if (!$duration) { |
|
| 124 | + throw new ApplicationLogicException('Invalid ban time'); |
|
| 125 | + } |
|
| 126 | + elseif (time() > $duration) { |
|
| 127 | + throw new ApplicationLogicException('Ban time has already expired!'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $duration; |
|
| 131 | + } |
|
| 132 | + elseif ($duration === "-1") { |
|
| 133 | + $duration = -1; |
|
| 134 | + |
|
| 135 | + return $duration; |
|
| 136 | + } |
|
| 137 | + else { |
|
| 138 | + $duration = WebRequest::postInt('duration') + time(); |
|
| 139 | + |
|
| 140 | + return $duration; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $type |
|
| 146 | + * @param string $target |
|
| 147 | + * |
|
| 148 | + * @throws ApplicationLogicException |
|
| 149 | + */ |
|
| 150 | + private function validateBanType($type, $target) |
|
| 151 | + { |
|
| 152 | + switch ($type) { |
|
| 153 | + case 'IP': |
|
| 154 | + $this->validateIpBan($target); |
|
| 155 | + |
|
| 156 | + return; |
|
| 157 | + case 'Name': |
|
| 158 | + // No validation needed here. |
|
| 159 | + return; |
|
| 160 | + case 'EMail': |
|
| 161 | + $this->validateEmailBanTarget($target); |
|
| 162 | + |
|
| 163 | + return; |
|
| 164 | + default: |
|
| 165 | + throw new ApplicationLogicException("Unknown ban type"); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Handles the POST method on the set action |
|
| 171 | + * |
|
| 172 | + * @throws ApplicationLogicException |
|
| 173 | + * @throws Exception |
|
| 174 | + */ |
|
| 175 | + private function handlePostMethodForSetBan() |
|
| 176 | + { |
|
| 177 | + $this->validateCSRFToken(); |
|
| 178 | + $reason = WebRequest::postString('banreason'); |
|
| 179 | + $target = WebRequest::postString('target'); |
|
| 180 | + |
|
| 181 | + // Checks whether there is a reason entered for ban. |
|
| 182 | + if ($reason === null || trim($reason) === "") { |
|
| 183 | + throw new ApplicationLogicException('You must specify a ban reason'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // Checks whether there is a target entered to ban. |
|
| 187 | + if ($target === null || trim($target) === "") { |
|
| 188 | + throw new ApplicationLogicException('You must specify a target to be banned'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Validate ban duration |
|
| 192 | + $duration = $this->getBanDuration(); |
|
| 193 | + |
|
| 194 | + // Validate ban type & target for that type |
|
| 195 | + $type = WebRequest::postString('type'); |
|
| 196 | + $this->validateBanType($type, $target); |
|
| 197 | + |
|
| 198 | + $database = $this->getDatabase(); |
|
| 199 | + |
|
| 200 | + if (count(Ban::getActiveBans($target, $database)) > 0) { |
|
| 201 | + throw new ApplicationLogicException('This target is already banned!'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $ban = new Ban(); |
|
| 205 | + $ban->setDatabase($database); |
|
| 206 | + $ban->setActive(true); |
|
| 207 | + $ban->setType($type); |
|
| 208 | + $ban->setTarget($target); |
|
| 209 | + $ban->setUser(User::getCurrent($database)->getId()); |
|
| 210 | + $ban->setReason($reason); |
|
| 211 | + $ban->setDuration($duration); |
|
| 212 | + |
|
| 213 | + $ban->save(); |
|
| 214 | + |
|
| 215 | + Logger::banned($database, $ban, $reason); |
|
| 216 | + |
|
| 217 | + $this->getNotificationHelper()->banned($ban); |
|
| 218 | + SessionAlert::quick('Ban has been set.'); |
|
| 219 | + |
|
| 220 | + $this->redirect('bans'); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Handles the GET method on the set action |
|
| 225 | + */ |
|
| 226 | + protected function handleGetMethodForSetBan() |
|
| 227 | + { |
|
| 228 | + $this->setTemplate('bans/banform.tpl'); |
|
| 229 | + $this->assignCSRFToken(); |
|
| 230 | + |
|
| 231 | + $banType = WebRequest::getString('type'); |
|
| 232 | + $banTarget = WebRequest::getInt('request'); |
|
| 233 | + |
|
| 234 | + $database = $this->getDatabase(); |
|
| 235 | + |
|
| 236 | + // if the parameters are null, skip loading a request. |
|
| 237 | + if ($banType === null |
|
| 238 | + || !in_array($banType, array('IP', 'Name', 'EMail')) |
|
| 239 | + || $banTarget === null |
|
| 240 | + || $banTarget === 0 |
|
| 241 | + ) { |
|
| 242 | + $this->assign('bantarget', ''); |
|
| 243 | + $this->assign('bantype', ''); |
|
| 244 | + |
|
| 245 | + return; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Set the ban type, which the user has indicated. |
|
| 249 | + $this->assign('bantype', $banType); |
|
| 250 | + |
|
| 251 | + // Attempt to resolve the correct target |
|
| 252 | + /** @var Request $request */ |
|
| 253 | + $request = Request::getById($banTarget, $database); |
|
| 254 | + if ($request === false) { |
|
| 255 | + $this->assign('bantarget', ''); |
|
| 256 | + |
|
| 257 | + return; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $realTarget = ''; |
|
| 261 | + switch ($banType) { |
|
| 262 | + case 'EMail': |
|
| 263 | + $realTarget = $request->getEmail(); |
|
| 264 | + break; |
|
| 265 | + case 'IP': |
|
| 266 | + $xffProvider = $this->getXffTrustProvider(); |
|
| 267 | + $realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 268 | + break; |
|
| 269 | + case 'Name': |
|
| 270 | + $realTarget = $request->getName(); |
|
| 271 | + break; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $this->assign('bantarget', $realTarget); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Validates an IP ban target |
|
| 279 | + * |
|
| 280 | + * @param string $target |
|
| 281 | + * |
|
| 282 | + * @throws ApplicationLogicException |
|
| 283 | + */ |
|
| 284 | + private function validateIpBan($target) |
|
| 285 | + { |
|
| 286 | + $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
| 287 | + |
|
| 288 | + if (filter_var($target, FILTER_VALIDATE_IP) === false) { |
|
| 289 | + throw new ApplicationLogicException('Invalid target - IP address expected.'); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if (in_array($target, $squidIpList)) { |
|
| 293 | + throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Validates an email address as a ban target |
|
| 299 | + * |
|
| 300 | + * @param string $target |
|
| 301 | + * |
|
| 302 | + * @throws ApplicationLogicException |
|
| 303 | + */ |
|
| 304 | + private function validateEmailBanTarget($target) |
|
| 305 | + { |
|
| 306 | + if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) { |
|
| 307 | + throw new ApplicationLogicException('Invalid target - email address expected.'); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @return Ban |
|
| 313 | + * @throws ApplicationLogicException |
|
| 314 | + */ |
|
| 315 | + private function getBanForUnban() |
|
| 316 | + { |
|
| 317 | + $banId = WebRequest::getInt('id'); |
|
| 318 | + if ($banId === null || $banId === 0) { |
|
| 319 | + throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $ban = Ban::getActiveId($banId, $this->getDatabase()); |
|
| 323 | + |
|
| 324 | + if ($ban === false) { |
|
| 325 | + throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return $ban; |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | |
| 14 | 14 | class ClearOldDataTask extends ConsoleTaskBase |
| 15 | 15 | { |
| 16 | - public function execute() |
|
| 17 | - { |
|
| 18 | - $dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval(); |
|
| 16 | + public function execute() |
|
| 17 | + { |
|
| 18 | + $dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval(); |
|
| 19 | 19 | |
| 20 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 20 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 21 | 21 | UPDATE request |
| 22 | 22 | SET ip = :ip, forwardedip = null, email = :mail, useragent = '' |
| 23 | 23 | WHERE date < DATE_SUB(curdate(), INTERVAL {$dataClearInterval}) |
| 24 | 24 | AND status = 'Closed'; |
| 25 | 25 | SQL |
| 26 | - ); |
|
| 26 | + ); |
|
| 27 | 27 | |
| 28 | - $success = $query->execute(array( |
|
| 29 | - ":ip" => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 30 | - ":mail" => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 31 | - )); |
|
| 28 | + $success = $query->execute(array( |
|
| 29 | + ":ip" => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 30 | + ":mail" => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 31 | + )); |
|
| 32 | 32 | |
| 33 | - if (!$success) { |
|
| 34 | - throw new Exception("Error in transaction: Could not clear data."); |
|
| 35 | - } |
|
| 36 | - } |
|
| 33 | + if (!$success) { |
|
| 34 | + throw new Exception("Error in transaction: Could not clear data."); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -21,141 +21,141 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SessionAlert |
| 23 | 23 | { |
| 24 | - private $message; |
|
| 25 | - private $title; |
|
| 26 | - private $type; |
|
| 27 | - private $closable; |
|
| 28 | - private $block; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @param string $title |
|
| 33 | - * @param string $type |
|
| 34 | - * @param bool $closable |
|
| 35 | - * @param bool $block |
|
| 36 | - */ |
|
| 37 | - public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | - { |
|
| 39 | - $this->message = $message; |
|
| 40 | - $this->title = $title; |
|
| 41 | - $this->type = $type; |
|
| 42 | - $this->closable = $closable; |
|
| 43 | - $this->block = $block; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Shows a quick one-liner message |
|
| 48 | - * |
|
| 49 | - * @param string $message |
|
| 50 | - * @param string $type |
|
| 51 | - */ |
|
| 52 | - public static function quick($message, $type = "alert-info") |
|
| 53 | - { |
|
| 54 | - self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param SessionAlert $alert |
|
| 59 | - */ |
|
| 60 | - public static function append(SessionAlert $alert) |
|
| 61 | - { |
|
| 62 | - $data = WebRequest::getSessionAlertData(); |
|
| 63 | - $data[] = serialize($alert); |
|
| 64 | - WebRequest::setSessionAlertData($data); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Shows a quick one-liner success message |
|
| 69 | - * |
|
| 70 | - * @param string $message |
|
| 71 | - */ |
|
| 72 | - public static function success($message) |
|
| 73 | - { |
|
| 74 | - self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Shows a quick one-liner warning message |
|
| 79 | - * |
|
| 80 | - * @param string $message |
|
| 81 | - * @param string $title |
|
| 82 | - */ |
|
| 83 | - public static function warning($message, $title = "Warning!") |
|
| 84 | - { |
|
| 85 | - self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Shows a quick one-liner error message |
|
| 90 | - * |
|
| 91 | - * @param string $message |
|
| 92 | - * @param string $title |
|
| 93 | - */ |
|
| 94 | - public static function error($message, $title = "Error!") |
|
| 95 | - { |
|
| 96 | - self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Retrieves the alerts which have been saved to the session |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public static function getAlerts() |
|
| 104 | - { |
|
| 105 | - $alertData = array(); |
|
| 106 | - |
|
| 107 | - foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | - $alertData[] = unserialize($a); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $alertData; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Clears the alerts from the session |
|
| 116 | - */ |
|
| 117 | - public static function clearAlerts() |
|
| 118 | - { |
|
| 119 | - WebRequest::clearSessionAlertData(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return boolean |
|
| 124 | - */ |
|
| 125 | - public function isBlock() |
|
| 126 | - { |
|
| 127 | - return $this->block; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - public function isClosable() |
|
| 134 | - { |
|
| 135 | - return $this->closable; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getType() |
|
| 142 | - { |
|
| 143 | - return $this->type; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getTitle() |
|
| 150 | - { |
|
| 151 | - return $this->title; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getMessage() |
|
| 158 | - { |
|
| 159 | - return $this->message; |
|
| 160 | - } |
|
| 24 | + private $message; |
|
| 25 | + private $title; |
|
| 26 | + private $type; |
|
| 27 | + private $closable; |
|
| 28 | + private $block; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @param string $title |
|
| 33 | + * @param string $type |
|
| 34 | + * @param bool $closable |
|
| 35 | + * @param bool $block |
|
| 36 | + */ |
|
| 37 | + public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | + { |
|
| 39 | + $this->message = $message; |
|
| 40 | + $this->title = $title; |
|
| 41 | + $this->type = $type; |
|
| 42 | + $this->closable = $closable; |
|
| 43 | + $this->block = $block; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Shows a quick one-liner message |
|
| 48 | + * |
|
| 49 | + * @param string $message |
|
| 50 | + * @param string $type |
|
| 51 | + */ |
|
| 52 | + public static function quick($message, $type = "alert-info") |
|
| 53 | + { |
|
| 54 | + self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param SessionAlert $alert |
|
| 59 | + */ |
|
| 60 | + public static function append(SessionAlert $alert) |
|
| 61 | + { |
|
| 62 | + $data = WebRequest::getSessionAlertData(); |
|
| 63 | + $data[] = serialize($alert); |
|
| 64 | + WebRequest::setSessionAlertData($data); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Shows a quick one-liner success message |
|
| 69 | + * |
|
| 70 | + * @param string $message |
|
| 71 | + */ |
|
| 72 | + public static function success($message) |
|
| 73 | + { |
|
| 74 | + self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Shows a quick one-liner warning message |
|
| 79 | + * |
|
| 80 | + * @param string $message |
|
| 81 | + * @param string $title |
|
| 82 | + */ |
|
| 83 | + public static function warning($message, $title = "Warning!") |
|
| 84 | + { |
|
| 85 | + self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Shows a quick one-liner error message |
|
| 90 | + * |
|
| 91 | + * @param string $message |
|
| 92 | + * @param string $title |
|
| 93 | + */ |
|
| 94 | + public static function error($message, $title = "Error!") |
|
| 95 | + { |
|
| 96 | + self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Retrieves the alerts which have been saved to the session |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public static function getAlerts() |
|
| 104 | + { |
|
| 105 | + $alertData = array(); |
|
| 106 | + |
|
| 107 | + foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | + $alertData[] = unserialize($a); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $alertData; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Clears the alerts from the session |
|
| 116 | + */ |
|
| 117 | + public static function clearAlerts() |
|
| 118 | + { |
|
| 119 | + WebRequest::clearSessionAlertData(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return boolean |
|
| 124 | + */ |
|
| 125 | + public function isBlock() |
|
| 126 | + { |
|
| 127 | + return $this->block; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + public function isClosable() |
|
| 134 | + { |
|
| 135 | + return $this->closable; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getType() |
|
| 142 | + { |
|
| 143 | + return $this->type; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getTitle() |
|
| 150 | + { |
|
| 151 | + return $this->title; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getMessage() |
|
| 158 | + { |
|
| 159 | + return $this->message; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -16,136 +16,136 @@ |
||
| 16 | 16 | |
| 17 | 17 | class BotMediaWikiClient implements IMediaWikiClient |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var HttpHelper |
|
| 21 | - */ |
|
| 22 | - private $httpHelper; |
|
| 23 | - /** @var string */ |
|
| 24 | - private $mediawikiWebServiceEndpoint; |
|
| 25 | - /** @var string */ |
|
| 26 | - private $creationBotUsername; |
|
| 27 | - /** @var string */ |
|
| 28 | - private $creationBotPassword; |
|
| 29 | - /** @var bool */ |
|
| 30 | - private $knownLoggedIn = false; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * BotMediaWikiClient constructor. |
|
| 34 | - * |
|
| 35 | - * @param SiteConfiguration $siteConfiguration |
|
| 36 | - */ |
|
| 37 | - public function __construct(SiteConfiguration $siteConfiguration) |
|
| 38 | - { |
|
| 39 | - $this->mediawikiWebServiceEndpoint = $siteConfiguration->getMediawikiWebServiceEndpoint(); |
|
| 40 | - |
|
| 41 | - $this->creationBotUsername = $siteConfiguration->getCreationBotUsername(); |
|
| 42 | - $this->creationBotPassword = $siteConfiguration->getCreationBotPassword(); |
|
| 43 | - |
|
| 44 | - $this->httpHelper = new HttpHelper( |
|
| 45 | - $siteConfiguration->getUserAgent(), |
|
| 46 | - $siteConfiguration->getCurlDisableVerifyPeer(), |
|
| 47 | - $siteConfiguration->getCurlCookieJar() |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - function doApiCall($apiParams, $method = 'GET') |
|
| 52 | - { |
|
| 53 | - $this->ensureLoggedIn(); |
|
| 54 | - $apiParams['assert'] = 'user'; |
|
| 55 | - |
|
| 56 | - return $this->callApi($apiParams, $method); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - private function ensureLoggedIn() |
|
| 60 | - { |
|
| 61 | - if ($this->knownLoggedIn) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $userinfoResult = $this->callApi(array('action' => 'query', 'meta' => 'userinfo'), 'GET'); |
|
| 66 | - if (isset($userinfoResult->query->userinfo->anon)) { |
|
| 67 | - // not logged in. |
|
| 68 | - $this->logIn(); |
|
| 69 | - |
|
| 70 | - // retest |
|
| 71 | - $userinfoResult = $this->callApi(array('action' => 'query', 'meta' => 'userinfo'), 'GET'); |
|
| 72 | - if (isset($userinfoResult->query->userinfo->anon)) { |
|
| 73 | - throw new MediaWikiApiException('Unable to log in.'); |
|
| 74 | - } |
|
| 75 | - else { |
|
| 76 | - $this->knownLoggedIn = true; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - else { |
|
| 80 | - $this->knownLoggedIn = true; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param $apiParams |
|
| 86 | - * @param $method |
|
| 87 | - * |
|
| 88 | - * @return mixed |
|
| 89 | - * @throws ApplicationLogicException |
|
| 90 | - * @throws CurlException |
|
| 91 | - */ |
|
| 92 | - private function callApi($apiParams, $method) |
|
| 93 | - { |
|
| 94 | - $apiParams['format'] = 'json'; |
|
| 95 | - |
|
| 96 | - if ($method == 'GET') { |
|
| 97 | - $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams); |
|
| 98 | - } |
|
| 99 | - elseif ($method == 'POST') { |
|
| 100 | - $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams); |
|
| 101 | - } |
|
| 102 | - else { |
|
| 103 | - throw new ApplicationLogicException('Unsupported HTTP Method'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($data === false) { |
|
| 107 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $result = json_decode($data); |
|
| 111 | - |
|
| 112 | - return $result; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - private function logIn() |
|
| 116 | - { |
|
| 117 | - // get token |
|
| 118 | - $tokenParams = array( |
|
| 119 | - 'action' => 'query', |
|
| 120 | - 'meta' => 'tokens', |
|
| 121 | - 'type' => 'login', |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $response = $this->callApi($tokenParams, 'POST'); |
|
| 125 | - |
|
| 126 | - if (isset($response->error)) { |
|
| 127 | - throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $token = $response->query->tokens->logintoken; |
|
| 131 | - |
|
| 132 | - if ($token === null) { |
|
| 133 | - throw new MediaWikiApiException('Edit token could not be acquired'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $params = array( |
|
| 137 | - 'action' => 'login', |
|
| 138 | - 'lgname' => $this->creationBotUsername, |
|
| 139 | - 'lgpassword' => $this->creationBotPassword, |
|
| 140 | - 'lgtoken' => $token, |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - $loginResponse = $this->callApi($params, 'POST'); |
|
| 144 | - |
|
| 145 | - if($loginResponse->login->result == 'Success'){ |
|
| 146 | - return; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - throw new ApplicationLogicException(json_encode($loginResponse)); |
|
| 150 | - } |
|
| 19 | + /** |
|
| 20 | + * @var HttpHelper |
|
| 21 | + */ |
|
| 22 | + private $httpHelper; |
|
| 23 | + /** @var string */ |
|
| 24 | + private $mediawikiWebServiceEndpoint; |
|
| 25 | + /** @var string */ |
|
| 26 | + private $creationBotUsername; |
|
| 27 | + /** @var string */ |
|
| 28 | + private $creationBotPassword; |
|
| 29 | + /** @var bool */ |
|
| 30 | + private $knownLoggedIn = false; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * BotMediaWikiClient constructor. |
|
| 34 | + * |
|
| 35 | + * @param SiteConfiguration $siteConfiguration |
|
| 36 | + */ |
|
| 37 | + public function __construct(SiteConfiguration $siteConfiguration) |
|
| 38 | + { |
|
| 39 | + $this->mediawikiWebServiceEndpoint = $siteConfiguration->getMediawikiWebServiceEndpoint(); |
|
| 40 | + |
|
| 41 | + $this->creationBotUsername = $siteConfiguration->getCreationBotUsername(); |
|
| 42 | + $this->creationBotPassword = $siteConfiguration->getCreationBotPassword(); |
|
| 43 | + |
|
| 44 | + $this->httpHelper = new HttpHelper( |
|
| 45 | + $siteConfiguration->getUserAgent(), |
|
| 46 | + $siteConfiguration->getCurlDisableVerifyPeer(), |
|
| 47 | + $siteConfiguration->getCurlCookieJar() |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + function doApiCall($apiParams, $method = 'GET') |
|
| 52 | + { |
|
| 53 | + $this->ensureLoggedIn(); |
|
| 54 | + $apiParams['assert'] = 'user'; |
|
| 55 | + |
|
| 56 | + return $this->callApi($apiParams, $method); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + private function ensureLoggedIn() |
|
| 60 | + { |
|
| 61 | + if ($this->knownLoggedIn) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $userinfoResult = $this->callApi(array('action' => 'query', 'meta' => 'userinfo'), 'GET'); |
|
| 66 | + if (isset($userinfoResult->query->userinfo->anon)) { |
|
| 67 | + // not logged in. |
|
| 68 | + $this->logIn(); |
|
| 69 | + |
|
| 70 | + // retest |
|
| 71 | + $userinfoResult = $this->callApi(array('action' => 'query', 'meta' => 'userinfo'), 'GET'); |
|
| 72 | + if (isset($userinfoResult->query->userinfo->anon)) { |
|
| 73 | + throw new MediaWikiApiException('Unable to log in.'); |
|
| 74 | + } |
|
| 75 | + else { |
|
| 76 | + $this->knownLoggedIn = true; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + else { |
|
| 80 | + $this->knownLoggedIn = true; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param $apiParams |
|
| 86 | + * @param $method |
|
| 87 | + * |
|
| 88 | + * @return mixed |
|
| 89 | + * @throws ApplicationLogicException |
|
| 90 | + * @throws CurlException |
|
| 91 | + */ |
|
| 92 | + private function callApi($apiParams, $method) |
|
| 93 | + { |
|
| 94 | + $apiParams['format'] = 'json'; |
|
| 95 | + |
|
| 96 | + if ($method == 'GET') { |
|
| 97 | + $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams); |
|
| 98 | + } |
|
| 99 | + elseif ($method == 'POST') { |
|
| 100 | + $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams); |
|
| 101 | + } |
|
| 102 | + else { |
|
| 103 | + throw new ApplicationLogicException('Unsupported HTTP Method'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($data === false) { |
|
| 107 | + throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $result = json_decode($data); |
|
| 111 | + |
|
| 112 | + return $result; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + private function logIn() |
|
| 116 | + { |
|
| 117 | + // get token |
|
| 118 | + $tokenParams = array( |
|
| 119 | + 'action' => 'query', |
|
| 120 | + 'meta' => 'tokens', |
|
| 121 | + 'type' => 'login', |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $response = $this->callApi($tokenParams, 'POST'); |
|
| 125 | + |
|
| 126 | + if (isset($response->error)) { |
|
| 127 | + throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $token = $response->query->tokens->logintoken; |
|
| 131 | + |
|
| 132 | + if ($token === null) { |
|
| 133 | + throw new MediaWikiApiException('Edit token could not be acquired'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $params = array( |
|
| 137 | + 'action' => 'login', |
|
| 138 | + 'lgname' => $this->creationBotUsername, |
|
| 139 | + 'lgpassword' => $this->creationBotPassword, |
|
| 140 | + 'lgtoken' => $token, |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + $loginResponse = $this->callApi($params, 'POST'); |
|
| 144 | + |
|
| 145 | + if($loginResponse->login->result == 'Success'){ |
|
| 146 | + return; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + throw new ApplicationLogicException(json_encode($loginResponse)); |
|
| 150 | + } |
|
| 151 | 151 | } |
| 152 | 152 | \ No newline at end of file |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | if ($data === false) { |
| 107 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
| 107 | + throw new CurlException('Curl error: '.$this->httpHelper->getError()); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $result = json_decode($data); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $response = $this->callApi($tokenParams, 'POST'); |
| 125 | 125 | |
| 126 | 126 | if (isset($response->error)) { |
| 127 | - throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info); |
|
| 127 | + throw new MediaWikiApiException($response->error->code.': '.$response->error->info); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $token = $response->query->tokens->logintoken; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $loginResponse = $this->callApi($params, 'POST'); |
| 144 | 144 | |
| 145 | - if($loginResponse->login->result == 'Success'){ |
|
| 145 | + if ($loginResponse->login->result == 'Success') { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | |
| 143 | 143 | $loginResponse = $this->callApi($params, 'POST'); |
| 144 | 144 | |
| 145 | - if($loginResponse->login->result == 'Success'){ |
|
| 145 | + if($loginResponse->login->result == 'Success') { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -10,5 +10,5 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface IMediaWikiClient |
| 12 | 12 | { |
| 13 | - function doApiCall($params, $method); |
|
| 13 | + function doApiCall($params, $method); |
|
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -19,52 +19,52 @@ |
||
| 19 | 19 | |
| 20 | 20 | interface IOAuthProtocolHelper |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @return stdClass |
|
| 24 | - * |
|
| 25 | - * @throws Exception |
|
| 26 | - * @throws CurlException |
|
| 27 | - */ |
|
| 28 | - public function getRequestToken(); |
|
| 22 | + /** |
|
| 23 | + * @return stdClass |
|
| 24 | + * |
|
| 25 | + * @throws Exception |
|
| 26 | + * @throws CurlException |
|
| 27 | + */ |
|
| 28 | + public function getRequestToken(); |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $requestToken |
|
| 32 | - * |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function getAuthoriseUrl($requestToken); |
|
| 30 | + /** |
|
| 31 | + * @param string $requestToken |
|
| 32 | + * |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function getAuthoriseUrl($requestToken); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $oauthRequestToken |
|
| 39 | - * @param string $oauthRequestSecret |
|
| 40 | - * @param string $oauthVerifier |
|
| 41 | - * |
|
| 42 | - * @return stdClass |
|
| 43 | - * @throws CurlException |
|
| 44 | - * @throws Exception |
|
| 45 | - */ |
|
| 46 | - public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier); |
|
| 37 | + /** |
|
| 38 | + * @param string $oauthRequestToken |
|
| 39 | + * @param string $oauthRequestSecret |
|
| 40 | + * @param string $oauthVerifier |
|
| 41 | + * |
|
| 42 | + * @return stdClass |
|
| 43 | + * @throws CurlException |
|
| 44 | + * @throws Exception |
|
| 45 | + */ |
|
| 46 | + public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $oauthAccessToken |
|
| 50 | - * @param string $oauthAccessSecret |
|
| 51 | - * |
|
| 52 | - * @return stdClass |
|
| 53 | - * @throws CurlException |
|
| 54 | - * @throws Exception |
|
| 55 | - */ |
|
| 56 | - public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret); |
|
| 48 | + /** |
|
| 49 | + * @param string $oauthAccessToken |
|
| 50 | + * @param string $oauthAccessSecret |
|
| 51 | + * |
|
| 52 | + * @return stdClass |
|
| 53 | + * @throws CurlException |
|
| 54 | + * @throws Exception |
|
| 55 | + */ |
|
| 56 | + public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param array $apiParams array of parameters to send to the API |
|
| 60 | - * @param string $accessToken user's access token |
|
| 61 | - * @param string $accessSecret user's secret |
|
| 62 | - * @param string $method HTTP method |
|
| 63 | - * |
|
| 64 | - * @return stdClass |
|
| 65 | - * @throws ApplicationLogicException |
|
| 66 | - * @throws CurlException |
|
| 67 | - * @throws Exception |
|
| 68 | - */ |
|
| 69 | - public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET'); |
|
| 58 | + /** |
|
| 59 | + * @param array $apiParams array of parameters to send to the API |
|
| 60 | + * @param string $accessToken user's access token |
|
| 61 | + * @param string $accessSecret user's secret |
|
| 62 | + * @param string $method HTTP method |
|
| 63 | + * |
|
| 64 | + * @return stdClass |
|
| 65 | + * @throws ApplicationLogicException |
|
| 66 | + * @throws CurlException |
|
| 67 | + * @throws Exception |
|
| 68 | + */ |
|
| 69 | + public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET'); |
|
| 70 | 70 | } |
| 71 | 71 | \ No newline at end of file |
@@ -12,109 +12,109 @@ |
||
| 12 | 12 | |
| 13 | 13 | class HttpHelper |
| 14 | 14 | { |
| 15 | - private $curlHandle; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * HttpHelper constructor. |
|
| 19 | - * |
|
| 20 | - * @param string $userAgent |
|
| 21 | - * @param boolean $disableVerifyPeer |
|
| 22 | - * @param string $cookieJar |
|
| 23 | - */ |
|
| 24 | - public function __construct($userAgent, $disableVerifyPeer, $cookieJar = null) |
|
| 25 | - { |
|
| 26 | - $this->curlHandle = curl_init(); |
|
| 27 | - |
|
| 28 | - curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true); |
|
| 29 | - curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent); |
|
| 30 | - curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true); |
|
| 31 | - |
|
| 32 | - if ($disableVerifyPeer) { |
|
| 33 | - curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - if($cookieJar !== null) { |
|
| 37 | - curl_setopt($this->curlHandle, CURLOPT_COOKIEFILE, $cookieJar); |
|
| 38 | - curl_setopt($this->curlHandle, CURLOPT_COOKIEJAR, $cookieJar); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function __destruct() |
|
| 43 | - { |
|
| 44 | - curl_close($this->curlHandle); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Fetches the content of a URL, with an optional parameter set. |
|
| 49 | - * |
|
| 50 | - * @param string $url The URL to fetch. |
|
| 51 | - * @param null|array $parameters Key/value pair of GET parameters to add to the request. |
|
| 52 | - * Null lets you handle it yourself. |
|
| 53 | - * |
|
| 54 | - * @param array $headers |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - * @throws CurlException |
|
| 58 | - */ |
|
| 59 | - public function get($url, $parameters = null, $headers = array()) |
|
| 60 | - { |
|
| 61 | - if ($parameters !== null && is_array($parameters)) { |
|
| 62 | - $getString = '?' . http_build_query($parameters); |
|
| 63 | - $url .= $getString; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - curl_setopt($this->curlHandle, CURLOPT_URL, $url); |
|
| 67 | - |
|
| 68 | - // Make sure we're doing a GET |
|
| 69 | - curl_setopt($this->curlHandle, CURLOPT_POST, false); |
|
| 70 | - |
|
| 71 | - curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers); |
|
| 72 | - |
|
| 73 | - $result = curl_exec($this->curlHandle); |
|
| 74 | - |
|
| 75 | - if ($result === false) { |
|
| 76 | - $error = curl_error($this->curlHandle); |
|
| 77 | - throw new CurlException('Remote request failed with error ' . $error); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $result; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Posts data to a URL |
|
| 85 | - * |
|
| 86 | - * @param string $url The URL to fetch. |
|
| 87 | - * @param array $parameters Key/value pair of POST parameters to add to the request. |
|
| 88 | - * @param array $headers |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - * @throws CurlException |
|
| 92 | - */ |
|
| 93 | - public function post($url, $parameters, $headers = array()) |
|
| 94 | - { |
|
| 95 | - curl_setopt($this->curlHandle, CURLOPT_URL, $url); |
|
| 96 | - |
|
| 97 | - // Make sure we're doing a POST |
|
| 98 | - curl_setopt($this->curlHandle, CURLOPT_POST, true); |
|
| 99 | - curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters)); |
|
| 100 | - |
|
| 101 | - curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers); |
|
| 102 | - |
|
| 103 | - $result = curl_exec($this->curlHandle); |
|
| 104 | - |
|
| 105 | - if ($result === false) { |
|
| 106 | - $error = curl_error($this->curlHandle); |
|
| 107 | - throw new CurlException('Remote request failed with error ' . $error); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $result; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function getError() |
|
| 117 | - { |
|
| 118 | - return curl_error($this->curlHandle); |
|
| 119 | - } |
|
| 15 | + private $curlHandle; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * HttpHelper constructor. |
|
| 19 | + * |
|
| 20 | + * @param string $userAgent |
|
| 21 | + * @param boolean $disableVerifyPeer |
|
| 22 | + * @param string $cookieJar |
|
| 23 | + */ |
|
| 24 | + public function __construct($userAgent, $disableVerifyPeer, $cookieJar = null) |
|
| 25 | + { |
|
| 26 | + $this->curlHandle = curl_init(); |
|
| 27 | + |
|
| 28 | + curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true); |
|
| 29 | + curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent); |
|
| 30 | + curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true); |
|
| 31 | + |
|
| 32 | + if ($disableVerifyPeer) { |
|
| 33 | + curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + if($cookieJar !== null) { |
|
| 37 | + curl_setopt($this->curlHandle, CURLOPT_COOKIEFILE, $cookieJar); |
|
| 38 | + curl_setopt($this->curlHandle, CURLOPT_COOKIEJAR, $cookieJar); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function __destruct() |
|
| 43 | + { |
|
| 44 | + curl_close($this->curlHandle); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Fetches the content of a URL, with an optional parameter set. |
|
| 49 | + * |
|
| 50 | + * @param string $url The URL to fetch. |
|
| 51 | + * @param null|array $parameters Key/value pair of GET parameters to add to the request. |
|
| 52 | + * Null lets you handle it yourself. |
|
| 53 | + * |
|
| 54 | + * @param array $headers |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + * @throws CurlException |
|
| 58 | + */ |
|
| 59 | + public function get($url, $parameters = null, $headers = array()) |
|
| 60 | + { |
|
| 61 | + if ($parameters !== null && is_array($parameters)) { |
|
| 62 | + $getString = '?' . http_build_query($parameters); |
|
| 63 | + $url .= $getString; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + curl_setopt($this->curlHandle, CURLOPT_URL, $url); |
|
| 67 | + |
|
| 68 | + // Make sure we're doing a GET |
|
| 69 | + curl_setopt($this->curlHandle, CURLOPT_POST, false); |
|
| 70 | + |
|
| 71 | + curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers); |
|
| 72 | + |
|
| 73 | + $result = curl_exec($this->curlHandle); |
|
| 74 | + |
|
| 75 | + if ($result === false) { |
|
| 76 | + $error = curl_error($this->curlHandle); |
|
| 77 | + throw new CurlException('Remote request failed with error ' . $error); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $result; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Posts data to a URL |
|
| 85 | + * |
|
| 86 | + * @param string $url The URL to fetch. |
|
| 87 | + * @param array $parameters Key/value pair of POST parameters to add to the request. |
|
| 88 | + * @param array $headers |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + * @throws CurlException |
|
| 92 | + */ |
|
| 93 | + public function post($url, $parameters, $headers = array()) |
|
| 94 | + { |
|
| 95 | + curl_setopt($this->curlHandle, CURLOPT_URL, $url); |
|
| 96 | + |
|
| 97 | + // Make sure we're doing a POST |
|
| 98 | + curl_setopt($this->curlHandle, CURLOPT_POST, true); |
|
| 99 | + curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters)); |
|
| 100 | + |
|
| 101 | + curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers); |
|
| 102 | + |
|
| 103 | + $result = curl_exec($this->curlHandle); |
|
| 104 | + |
|
| 105 | + if ($result === false) { |
|
| 106 | + $error = curl_error($this->curlHandle); |
|
| 107 | + throw new CurlException('Remote request failed with error ' . $error); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $result; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function getError() |
|
| 117 | + { |
|
| 118 | + return curl_error($this->curlHandle); |
|
| 119 | + } |
|
| 120 | 120 | } |
| 121 | 121 | \ No newline at end of file |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if($cookieJar !== null) { |
|
| 36 | + if ($cookieJar !== null) { |
|
| 37 | 37 | curl_setopt($this->curlHandle, CURLOPT_COOKIEFILE, $cookieJar); |
| 38 | 38 | curl_setopt($this->curlHandle, CURLOPT_COOKIEJAR, $cookieJar); |
| 39 | 39 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | public function get($url, $parameters = null, $headers = array()) |
| 60 | 60 | { |
| 61 | 61 | if ($parameters !== null && is_array($parameters)) { |
| 62 | - $getString = '?' . http_build_query($parameters); |
|
| 62 | + $getString = '?'.http_build_query($parameters); |
|
| 63 | 63 | $url .= $getString; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | if ($result === false) { |
| 76 | 76 | $error = curl_error($this->curlHandle); |
| 77 | - throw new CurlException('Remote request failed with error ' . $error); |
|
| 77 | + throw new CurlException('Remote request failed with error '.$error); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | return $result; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | if ($result === false) { |
| 106 | 106 | $error = curl_error($this->curlHandle); |
| 107 | - throw new CurlException('Remote request failed with error ' . $error); |
|
| 107 | + throw new CurlException('Remote request failed with error '.$error); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $result; |