@@ -24,324 +24,324 @@ |
||
| 24 | 24 | |
| 25 | 25 | trait RequestData |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * @var array Array of IP address classed as 'private' by RFC1918. |
|
| 29 | - */ |
|
| 30 | - protected static $rfc1918ips = array( |
|
| 31 | - "10.0.0.0" => "10.255.255.255", |
|
| 32 | - "172.16.0.0" => "172.31.255.255", |
|
| 33 | - "192.168.0.0" => "192.168.255.255", |
|
| 34 | - "169.254.0.0" => "169.254.255.255", |
|
| 35 | - "127.0.0.0" => "127.255.255.255", |
|
| 36 | - ); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets a request object |
|
| 40 | - * |
|
| 41 | - * @param PdoDatabase $database The database connection |
|
| 42 | - * @param int $requestId The ID of the request to retrieve |
|
| 43 | - * |
|
| 44 | - * @return Request |
|
| 45 | - * @throws ApplicationLogicException |
|
| 46 | - */ |
|
| 47 | - protected function getRequest(PdoDatabase $database, $requestId) |
|
| 48 | - { |
|
| 49 | - if ($requestId === null) { |
|
| 50 | - throw new ApplicationLogicException("No request specified"); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $request = Request::getById($requestId, $database); |
|
| 54 | - if ($request === false || !is_a($request, Request::class)) { |
|
| 55 | - throw new ApplicationLogicException('Could not load the requested request!'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $request; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Returns a value stating whether the user is allowed to see private data or not |
|
| 63 | - * |
|
| 64 | - * @param Request $request |
|
| 65 | - * @param User $currentUser |
|
| 66 | - * |
|
| 67 | - * @return bool |
|
| 68 | - * @category Security-Critical |
|
| 69 | - */ |
|
| 70 | - protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
| 71 | - { |
|
| 72 | - // Test the main security barrier for private data access using SecurityManager |
|
| 73 | - if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 74 | - // Tool admins/check-users can always see private data |
|
| 75 | - return true; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // reserving user is allowed to see the data |
|
| 79 | - if ($currentUser->getId() === $request->getReserved() |
|
| 80 | - && $request->getReserved() !== null |
|
| 81 | - && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
| 82 | - ) { |
|
| 83 | - return true; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // user has the reveal hash |
|
| 87 | - if (WebRequest::getString('hash') === $request->getRevealHash() |
|
| 88 | - && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
| 89 | - ) { |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // nope. Not allowed. |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Tests the security barrier for a specified action. |
|
| 99 | - * |
|
| 100 | - * Don't use within templates |
|
| 101 | - * |
|
| 102 | - * @param string $action |
|
| 103 | - * |
|
| 104 | - * @param User $user |
|
| 105 | - * @param null|string $pageName |
|
| 106 | - * |
|
| 107 | - * @return bool |
|
| 108 | - * @category Security-Critical |
|
| 109 | - */ |
|
| 110 | - abstract protected function barrierTest($action, User $user, $pageName = null); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets the name of the route that has been passed from the request router. |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - abstract protected function getRouteName(); |
|
| 117 | - |
|
| 118 | - /** @return SecurityManager */ |
|
| 119 | - abstract protected function getSecurityManager(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sets the name of the template this page should display. |
|
| 123 | - * |
|
| 124 | - * @param string $name |
|
| 125 | - */ |
|
| 126 | - abstract protected function setTemplate($name); |
|
| 127 | - |
|
| 128 | - /** @return IXffTrustProvider */ |
|
| 129 | - abstract protected function getXffTrustProvider(); |
|
| 130 | - |
|
| 131 | - /** @return ILocationProvider */ |
|
| 132 | - abstract protected function getLocationProvider(); |
|
| 133 | - |
|
| 134 | - /** @return IRDnsProvider */ |
|
| 135 | - abstract protected function getRdnsProvider(); |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Assigns a Smarty variable |
|
| 139 | - * |
|
| 140 | - * @param array|string $name the template variable name(s) |
|
| 141 | - * @param mixed $value the value to assign |
|
| 142 | - */ |
|
| 143 | - abstract protected function assign($name, $value); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param int $requestReservationId |
|
| 147 | - * @param PdoDatabase $database |
|
| 148 | - * @param User $currentUser |
|
| 149 | - */ |
|
| 150 | - protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
| 151 | - { |
|
| 152 | - $requestIsReserved = $requestReservationId !== null; |
|
| 153 | - $this->assign('requestIsReserved', $requestIsReserved); |
|
| 154 | - $this->assign('requestIsReservedByMe', false); |
|
| 155 | - |
|
| 156 | - if ($requestIsReserved) { |
|
| 157 | - $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
| 158 | - $this->assign('requestReservedById', $requestReservationId); |
|
| 159 | - |
|
| 160 | - if ($requestReservationId === $currentUser->getId()) { |
|
| 161 | - $this->assign('requestIsReservedByMe', true); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 170 | - * |
|
| 171 | - * @param Request $request |
|
| 172 | - * @param User $currentUser |
|
| 173 | - * @param SiteConfiguration $configuration |
|
| 174 | - * |
|
| 175 | - * @param PdoDatabase $database |
|
| 176 | - */ |
|
| 177 | - protected function setupPrivateData( |
|
| 178 | - $request, |
|
| 179 | - User $currentUser, |
|
| 180 | - SiteConfiguration $configuration, |
|
| 181 | - PdoDatabase $database |
|
| 182 | - ) { |
|
| 183 | - $xffProvider = $this->getXffTrustProvider(); |
|
| 184 | - |
|
| 185 | - $relatedEmailRequests = RequestSearchHelper::get($database) |
|
| 186 | - ->byEmailAddress($request->getEmail()) |
|
| 187 | - ->withConfirmedEmail() |
|
| 188 | - ->excludingPurgedData($configuration) |
|
| 189 | - ->excludingRequest($request->getId()) |
|
| 190 | - ->fetch(); |
|
| 191 | - |
|
| 192 | - $this->assign('requestEmail', $request->getEmail()); |
|
| 193 | - $emailDomain = explode("@", $request->getEmail())[1]; |
|
| 194 | - $this->assign("emailurl", $emailDomain); |
|
| 195 | - $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
| 196 | - $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
| 197 | - |
|
| 198 | - $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 199 | - $this->assign('requestTrustedIp', $trustedIp); |
|
| 200 | - $this->assign('requestRealIp', $request->getIp()); |
|
| 201 | - $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
| 202 | - |
|
| 203 | - $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
| 204 | - $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
| 205 | - |
|
| 206 | - $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
| 207 | - |
|
| 208 | - $relatedIpRequests = RequestSearchHelper::get($database) |
|
| 209 | - ->byIp($trustedIp) |
|
| 210 | - ->withConfirmedEmail() |
|
| 211 | - ->excludingPurgedData($configuration) |
|
| 212 | - ->excludingRequest($request->getId()) |
|
| 213 | - ->fetch(); |
|
| 214 | - |
|
| 215 | - $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
| 216 | - $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
| 217 | - |
|
| 218 | - $this->assign('showRevealLink', false); |
|
| 219 | - if ($request->getReserved() === $currentUser->getId() || |
|
| 220 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 221 | - ) { |
|
| 222 | - $this->assign('showRevealLink', true); |
|
| 223 | - $this->assign('revealHash', $request->getRevealHash()); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $this->setupForwardedIpData($request); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 231 | - * |
|
| 232 | - * @param Request $request |
|
| 233 | - */ |
|
| 234 | - protected function setupCheckUserData(Request $request) |
|
| 235 | - { |
|
| 236 | - $this->assign('requestUserAgent', $request->getUserAgent()); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Sets up the basic data for this request, and adds it to Smarty |
|
| 241 | - * |
|
| 242 | - * @param Request $request |
|
| 243 | - * @param SiteConfiguration $config |
|
| 244 | - */ |
|
| 245 | - protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
| 246 | - { |
|
| 247 | - $this->assign('requestId', $request->getId()); |
|
| 248 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 249 | - $this->assign('requestName', $request->getName()); |
|
| 250 | - $this->assign('requestDate', $request->getDate()); |
|
| 251 | - $this->assign('requestStatus', $request->getStatus()); |
|
| 252 | - |
|
| 253 | - $isClosed = !array_key_exists($request->getStatus(), $config->getRequestStates()) |
|
| 254 | - && $request->getStatus() !== RequestStatus::HOSPITAL; |
|
| 255 | - $this->assign('requestIsClosed', $isClosed); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Sets up the forwarded IP data for this request and adds it to Smarty |
|
| 260 | - * |
|
| 261 | - * @param Request $request |
|
| 262 | - */ |
|
| 263 | - protected function setupForwardedIpData(Request $request) |
|
| 264 | - { |
|
| 265 | - if ($request->getForwardedIp() !== null) { |
|
| 266 | - $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
| 267 | - $proxyIndex = 0; |
|
| 268 | - |
|
| 269 | - // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
| 270 | - // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
| 271 | - $proxies = explode(",", $request->getForwardedIp()); |
|
| 272 | - $proxies[] = $request->getIp(); |
|
| 273 | - |
|
| 274 | - // Origin is the supposed "client" IP. |
|
| 275 | - $origin = $proxies[0]; |
|
| 276 | - $this->assign("forwardedOrigin", $origin); |
|
| 277 | - |
|
| 278 | - // We step through the servers in reverse order, from closest to furthest |
|
| 279 | - $proxies = array_reverse($proxies); |
|
| 280 | - |
|
| 281 | - // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
| 282 | - $trust = true; |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @var int $index The zero-based index of the proxy. |
|
| 286 | - * @var string $proxyData The proxy IP address (although possibly not!) |
|
| 287 | - */ |
|
| 288 | - foreach ($proxies as $index => $proxyData) { |
|
| 289 | - $proxyAddress = trim($proxyData); |
|
| 290 | - $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
| 291 | - |
|
| 292 | - // get data on this IP. |
|
| 293 | - $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
| 294 | - |
|
| 295 | - $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
| 296 | - ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
| 297 | - |
|
| 298 | - if (!$proxyIsInPrivateRange) { |
|
| 299 | - $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
| 300 | - $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
| 301 | - } |
|
| 302 | - else { |
|
| 303 | - // this is going to fail, so why bother trying? |
|
| 304 | - $proxyReverseDns = false; |
|
| 305 | - $proxyLocation = false; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // current trust chain status BEFORE this link |
|
| 309 | - $preLinkTrust = $trust; |
|
| 310 | - |
|
| 311 | - // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
| 312 | - $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
| 313 | - |
|
| 314 | - // set the trust status of the chain to this point |
|
| 315 | - $trust = $trust & $thisProxyIsTrusted; |
|
| 316 | - |
|
| 317 | - // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
| 318 | - // the origin. |
|
| 319 | - if ($preLinkTrust && $proxyAddress == $origin) { |
|
| 320 | - // if this is the origin, then we are at the last point in the chain. |
|
| 321 | - // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
| 322 | - // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
| 323 | - $trust = true; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
| 327 | - |
|
| 328 | - $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
| 329 | - $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
| 330 | - $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
| 331 | - |
|
| 332 | - $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
| 333 | - |
|
| 334 | - if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
| 335 | - $requestProxyData[$proxyIndex]['rdns'] = null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
| 339 | - $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
| 340 | - |
|
| 341 | - $proxyIndex++; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $this->assign("requestProxyData", $requestProxyData); |
|
| 345 | - } |
|
| 346 | - } |
|
| 27 | + /** |
|
| 28 | + * @var array Array of IP address classed as 'private' by RFC1918. |
|
| 29 | + */ |
|
| 30 | + protected static $rfc1918ips = array( |
|
| 31 | + "10.0.0.0" => "10.255.255.255", |
|
| 32 | + "172.16.0.0" => "172.31.255.255", |
|
| 33 | + "192.168.0.0" => "192.168.255.255", |
|
| 34 | + "169.254.0.0" => "169.254.255.255", |
|
| 35 | + "127.0.0.0" => "127.255.255.255", |
|
| 36 | + ); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets a request object |
|
| 40 | + * |
|
| 41 | + * @param PdoDatabase $database The database connection |
|
| 42 | + * @param int $requestId The ID of the request to retrieve |
|
| 43 | + * |
|
| 44 | + * @return Request |
|
| 45 | + * @throws ApplicationLogicException |
|
| 46 | + */ |
|
| 47 | + protected function getRequest(PdoDatabase $database, $requestId) |
|
| 48 | + { |
|
| 49 | + if ($requestId === null) { |
|
| 50 | + throw new ApplicationLogicException("No request specified"); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $request = Request::getById($requestId, $database); |
|
| 54 | + if ($request === false || !is_a($request, Request::class)) { |
|
| 55 | + throw new ApplicationLogicException('Could not load the requested request!'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $request; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Returns a value stating whether the user is allowed to see private data or not |
|
| 63 | + * |
|
| 64 | + * @param Request $request |
|
| 65 | + * @param User $currentUser |
|
| 66 | + * |
|
| 67 | + * @return bool |
|
| 68 | + * @category Security-Critical |
|
| 69 | + */ |
|
| 70 | + protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
| 71 | + { |
|
| 72 | + // Test the main security barrier for private data access using SecurityManager |
|
| 73 | + if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 74 | + // Tool admins/check-users can always see private data |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // reserving user is allowed to see the data |
|
| 79 | + if ($currentUser->getId() === $request->getReserved() |
|
| 80 | + && $request->getReserved() !== null |
|
| 81 | + && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
| 82 | + ) { |
|
| 83 | + return true; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // user has the reveal hash |
|
| 87 | + if (WebRequest::getString('hash') === $request->getRevealHash() |
|
| 88 | + && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
| 89 | + ) { |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // nope. Not allowed. |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Tests the security barrier for a specified action. |
|
| 99 | + * |
|
| 100 | + * Don't use within templates |
|
| 101 | + * |
|
| 102 | + * @param string $action |
|
| 103 | + * |
|
| 104 | + * @param User $user |
|
| 105 | + * @param null|string $pageName |
|
| 106 | + * |
|
| 107 | + * @return bool |
|
| 108 | + * @category Security-Critical |
|
| 109 | + */ |
|
| 110 | + abstract protected function barrierTest($action, User $user, $pageName = null); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets the name of the route that has been passed from the request router. |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + abstract protected function getRouteName(); |
|
| 117 | + |
|
| 118 | + /** @return SecurityManager */ |
|
| 119 | + abstract protected function getSecurityManager(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sets the name of the template this page should display. |
|
| 123 | + * |
|
| 124 | + * @param string $name |
|
| 125 | + */ |
|
| 126 | + abstract protected function setTemplate($name); |
|
| 127 | + |
|
| 128 | + /** @return IXffTrustProvider */ |
|
| 129 | + abstract protected function getXffTrustProvider(); |
|
| 130 | + |
|
| 131 | + /** @return ILocationProvider */ |
|
| 132 | + abstract protected function getLocationProvider(); |
|
| 133 | + |
|
| 134 | + /** @return IRDnsProvider */ |
|
| 135 | + abstract protected function getRdnsProvider(); |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Assigns a Smarty variable |
|
| 139 | + * |
|
| 140 | + * @param array|string $name the template variable name(s) |
|
| 141 | + * @param mixed $value the value to assign |
|
| 142 | + */ |
|
| 143 | + abstract protected function assign($name, $value); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param int $requestReservationId |
|
| 147 | + * @param PdoDatabase $database |
|
| 148 | + * @param User $currentUser |
|
| 149 | + */ |
|
| 150 | + protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
| 151 | + { |
|
| 152 | + $requestIsReserved = $requestReservationId !== null; |
|
| 153 | + $this->assign('requestIsReserved', $requestIsReserved); |
|
| 154 | + $this->assign('requestIsReservedByMe', false); |
|
| 155 | + |
|
| 156 | + if ($requestIsReserved) { |
|
| 157 | + $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
| 158 | + $this->assign('requestReservedById', $requestReservationId); |
|
| 159 | + |
|
| 160 | + if ($requestReservationId === $currentUser->getId()) { |
|
| 161 | + $this->assign('requestIsReservedByMe', true); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 170 | + * |
|
| 171 | + * @param Request $request |
|
| 172 | + * @param User $currentUser |
|
| 173 | + * @param SiteConfiguration $configuration |
|
| 174 | + * |
|
| 175 | + * @param PdoDatabase $database |
|
| 176 | + */ |
|
| 177 | + protected function setupPrivateData( |
|
| 178 | + $request, |
|
| 179 | + User $currentUser, |
|
| 180 | + SiteConfiguration $configuration, |
|
| 181 | + PdoDatabase $database |
|
| 182 | + ) { |
|
| 183 | + $xffProvider = $this->getXffTrustProvider(); |
|
| 184 | + |
|
| 185 | + $relatedEmailRequests = RequestSearchHelper::get($database) |
|
| 186 | + ->byEmailAddress($request->getEmail()) |
|
| 187 | + ->withConfirmedEmail() |
|
| 188 | + ->excludingPurgedData($configuration) |
|
| 189 | + ->excludingRequest($request->getId()) |
|
| 190 | + ->fetch(); |
|
| 191 | + |
|
| 192 | + $this->assign('requestEmail', $request->getEmail()); |
|
| 193 | + $emailDomain = explode("@", $request->getEmail())[1]; |
|
| 194 | + $this->assign("emailurl", $emailDomain); |
|
| 195 | + $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
| 196 | + $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
| 197 | + |
|
| 198 | + $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 199 | + $this->assign('requestTrustedIp', $trustedIp); |
|
| 200 | + $this->assign('requestRealIp', $request->getIp()); |
|
| 201 | + $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
| 202 | + |
|
| 203 | + $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
| 204 | + $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
| 205 | + |
|
| 206 | + $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
| 207 | + |
|
| 208 | + $relatedIpRequests = RequestSearchHelper::get($database) |
|
| 209 | + ->byIp($trustedIp) |
|
| 210 | + ->withConfirmedEmail() |
|
| 211 | + ->excludingPurgedData($configuration) |
|
| 212 | + ->excludingRequest($request->getId()) |
|
| 213 | + ->fetch(); |
|
| 214 | + |
|
| 215 | + $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
| 216 | + $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
| 217 | + |
|
| 218 | + $this->assign('showRevealLink', false); |
|
| 219 | + if ($request->getReserved() === $currentUser->getId() || |
|
| 220 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 221 | + ) { |
|
| 222 | + $this->assign('showRevealLink', true); |
|
| 223 | + $this->assign('revealHash', $request->getRevealHash()); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $this->setupForwardedIpData($request); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 231 | + * |
|
| 232 | + * @param Request $request |
|
| 233 | + */ |
|
| 234 | + protected function setupCheckUserData(Request $request) |
|
| 235 | + { |
|
| 236 | + $this->assign('requestUserAgent', $request->getUserAgent()); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Sets up the basic data for this request, and adds it to Smarty |
|
| 241 | + * |
|
| 242 | + * @param Request $request |
|
| 243 | + * @param SiteConfiguration $config |
|
| 244 | + */ |
|
| 245 | + protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
| 246 | + { |
|
| 247 | + $this->assign('requestId', $request->getId()); |
|
| 248 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 249 | + $this->assign('requestName', $request->getName()); |
|
| 250 | + $this->assign('requestDate', $request->getDate()); |
|
| 251 | + $this->assign('requestStatus', $request->getStatus()); |
|
| 252 | + |
|
| 253 | + $isClosed = !array_key_exists($request->getStatus(), $config->getRequestStates()) |
|
| 254 | + && $request->getStatus() !== RequestStatus::HOSPITAL; |
|
| 255 | + $this->assign('requestIsClosed', $isClosed); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Sets up the forwarded IP data for this request and adds it to Smarty |
|
| 260 | + * |
|
| 261 | + * @param Request $request |
|
| 262 | + */ |
|
| 263 | + protected function setupForwardedIpData(Request $request) |
|
| 264 | + { |
|
| 265 | + if ($request->getForwardedIp() !== null) { |
|
| 266 | + $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
| 267 | + $proxyIndex = 0; |
|
| 268 | + |
|
| 269 | + // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
| 270 | + // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
| 271 | + $proxies = explode(",", $request->getForwardedIp()); |
|
| 272 | + $proxies[] = $request->getIp(); |
|
| 273 | + |
|
| 274 | + // Origin is the supposed "client" IP. |
|
| 275 | + $origin = $proxies[0]; |
|
| 276 | + $this->assign("forwardedOrigin", $origin); |
|
| 277 | + |
|
| 278 | + // We step through the servers in reverse order, from closest to furthest |
|
| 279 | + $proxies = array_reverse($proxies); |
|
| 280 | + |
|
| 281 | + // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
| 282 | + $trust = true; |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @var int $index The zero-based index of the proxy. |
|
| 286 | + * @var string $proxyData The proxy IP address (although possibly not!) |
|
| 287 | + */ |
|
| 288 | + foreach ($proxies as $index => $proxyData) { |
|
| 289 | + $proxyAddress = trim($proxyData); |
|
| 290 | + $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
| 291 | + |
|
| 292 | + // get data on this IP. |
|
| 293 | + $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
| 294 | + |
|
| 295 | + $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
| 296 | + ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
| 297 | + |
|
| 298 | + if (!$proxyIsInPrivateRange) { |
|
| 299 | + $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
| 300 | + $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
| 301 | + } |
|
| 302 | + else { |
|
| 303 | + // this is going to fail, so why bother trying? |
|
| 304 | + $proxyReverseDns = false; |
|
| 305 | + $proxyLocation = false; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // current trust chain status BEFORE this link |
|
| 309 | + $preLinkTrust = $trust; |
|
| 310 | + |
|
| 311 | + // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
| 312 | + $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
| 313 | + |
|
| 314 | + // set the trust status of the chain to this point |
|
| 315 | + $trust = $trust & $thisProxyIsTrusted; |
|
| 316 | + |
|
| 317 | + // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
| 318 | + // the origin. |
|
| 319 | + if ($preLinkTrust && $proxyAddress == $origin) { |
|
| 320 | + // if this is the origin, then we are at the last point in the chain. |
|
| 321 | + // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
| 322 | + // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
| 323 | + $trust = true; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
| 327 | + |
|
| 328 | + $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
| 329 | + $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
| 330 | + $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
| 331 | + |
|
| 332 | + $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
| 333 | + |
|
| 334 | + if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
| 335 | + $requestProxyData[$proxyIndex]['rdns'] = null; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
| 339 | + $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
| 340 | + |
|
| 341 | + $proxyIndex++; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $this->assign("requestProxyData", $requestProxyData); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | 347 | } |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class OAuthRequestRouter extends RequestRouter |
| 19 | 19 | { |
| 20 | - protected function getRouteFromPath($pathInfo) |
|
| 21 | - { |
|
| 22 | - // Hardcode the route for this entry point |
|
| 23 | - return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | - } |
|
| 20 | + protected function getRouteFromPath($pathInfo) |
|
| 21 | + { |
|
| 22 | + // Hardcode the route for this entry point |
|
| 23 | + return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -13,97 +13,97 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class PagedInternalPageBase extends InternalPageBase |
| 15 | 15 | { |
| 16 | - /** @var SearchHelperBase */ |
|
| 17 | - private $searchHelper; |
|
| 18 | - private $page; |
|
| 19 | - private $limit; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Sets up the pager with the current page, current limit, and total number of records. |
|
| 23 | - * |
|
| 24 | - * @param int $count |
|
| 25 | - * @param array $formParameters |
|
| 26 | - */ |
|
| 27 | - protected function setupPageData($count, $formParameters) |
|
| 28 | - { |
|
| 29 | - $page = $this->page; |
|
| 30 | - $limit = $this->limit; |
|
| 31 | - |
|
| 32 | - // The number of pages on the pager to show. Must be odd |
|
| 33 | - $pageLimit = 9; |
|
| 34 | - |
|
| 35 | - $pageData = array( |
|
| 36 | - // Can the user go to the previous page? |
|
| 37 | - 'canprev' => $page != 1, |
|
| 38 | - // Can the user go to the next page? |
|
| 39 | - 'cannext' => ($page * $limit) < $count, |
|
| 40 | - // Maximum page number |
|
| 41 | - 'maxpage' => ceil($count / $limit), |
|
| 42 | - // Limit to the number of pages to display |
|
| 43 | - 'pagelimit' => $pageLimit, |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - // number of pages either side of the current to show |
|
| 47 | - $pageMargin = (($pageLimit - 1) / 2); |
|
| 48 | - |
|
| 49 | - // Calculate the number of pages either side to show - this is for situations like: |
|
| 50 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 51 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 52 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 53 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 54 | - |
|
| 55 | - if ($pageCount < $pageLimit) { |
|
| 56 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 57 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 58 | - } |
|
| 59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 60 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Put the range of pages into the page data |
|
| 65 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 66 | - |
|
| 67 | - $this->assign("pagedata", $pageData); |
|
| 68 | - |
|
| 69 | - $this->assign("limit", $limit); |
|
| 70 | - $this->assign("page", $page); |
|
| 71 | - |
|
| 72 | - $this->setupFormParameters($formParameters); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
| 76 | - { |
|
| 77 | - $this->searchHelper = $searchHelper; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected function setupLimits() |
|
| 81 | - { |
|
| 82 | - $limit = WebRequest::getInt('limit'); |
|
| 83 | - if ($limit === null) { |
|
| 84 | - $limit = 100; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $page = WebRequest::getInt('page'); |
|
| 88 | - if ($page === null) { |
|
| 89 | - $page = 1; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $offset = ($page - 1) * $limit; |
|
| 93 | - |
|
| 94 | - $this->searchHelper->limit($limit, $offset); |
|
| 95 | - |
|
| 96 | - $this->page = $page; |
|
| 97 | - $this->limit = $limit; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - private function setupFormParameters($formParameters) |
|
| 101 | - { |
|
| 102 | - $formParameters['limit'] = $this->limit; |
|
| 103 | - $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
| 104 | - |
|
| 105 | - foreach ($formParameters as $key => $value) { |
|
| 106 | - $this->assign($key, $value); |
|
| 107 | - } |
|
| 108 | - } |
|
| 16 | + /** @var SearchHelperBase */ |
|
| 17 | + private $searchHelper; |
|
| 18 | + private $page; |
|
| 19 | + private $limit; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Sets up the pager with the current page, current limit, and total number of records. |
|
| 23 | + * |
|
| 24 | + * @param int $count |
|
| 25 | + * @param array $formParameters |
|
| 26 | + */ |
|
| 27 | + protected function setupPageData($count, $formParameters) |
|
| 28 | + { |
|
| 29 | + $page = $this->page; |
|
| 30 | + $limit = $this->limit; |
|
| 31 | + |
|
| 32 | + // The number of pages on the pager to show. Must be odd |
|
| 33 | + $pageLimit = 9; |
|
| 34 | + |
|
| 35 | + $pageData = array( |
|
| 36 | + // Can the user go to the previous page? |
|
| 37 | + 'canprev' => $page != 1, |
|
| 38 | + // Can the user go to the next page? |
|
| 39 | + 'cannext' => ($page * $limit) < $count, |
|
| 40 | + // Maximum page number |
|
| 41 | + 'maxpage' => ceil($count / $limit), |
|
| 42 | + // Limit to the number of pages to display |
|
| 43 | + 'pagelimit' => $pageLimit, |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + // number of pages either side of the current to show |
|
| 47 | + $pageMargin = (($pageLimit - 1) / 2); |
|
| 48 | + |
|
| 49 | + // Calculate the number of pages either side to show - this is for situations like: |
|
| 50 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 51 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 52 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 53 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 54 | + |
|
| 55 | + if ($pageCount < $pageLimit) { |
|
| 56 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 57 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 58 | + } |
|
| 59 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 60 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Put the range of pages into the page data |
|
| 65 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 66 | + |
|
| 67 | + $this->assign("pagedata", $pageData); |
|
| 68 | + |
|
| 69 | + $this->assign("limit", $limit); |
|
| 70 | + $this->assign("page", $page); |
|
| 71 | + |
|
| 72 | + $this->setupFormParameters($formParameters); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
| 76 | + { |
|
| 77 | + $this->searchHelper = $searchHelper; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected function setupLimits() |
|
| 81 | + { |
|
| 82 | + $limit = WebRequest::getInt('limit'); |
|
| 83 | + if ($limit === null) { |
|
| 84 | + $limit = 100; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $page = WebRequest::getInt('page'); |
|
| 88 | + if ($page === null) { |
|
| 89 | + $page = 1; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $offset = ($page - 1) * $limit; |
|
| 93 | + |
|
| 94 | + $this->searchHelper->limit($limit, $offset); |
|
| 95 | + |
|
| 96 | + $this->page = $page; |
|
| 97 | + $this->limit = $limit; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + private function setupFormParameters($formParameters) |
|
| 101 | + { |
|
| 102 | + $formParameters['limit'] = $this->limit; |
|
| 103 | + $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
| 104 | + |
|
| 105 | + foreach ($formParameters as $key => $value) { |
|
| 106 | + $this->assign($key, $value); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
| 110 | 110 | \ No newline at end of file |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | $formParameters['limit'] = $this->limit; |
| 103 | 103 | $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
| 104 | 104 | |
| 105 | - foreach ($formParameters as $key => $value) { |
|
| 105 | + foreach ($formParameters as $key => $value) { |
|
| 106 | 106 | $this->assign($key, $value); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | $formParameters['limit'] = $this->limit; |
| 103 | 103 | $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
| 104 | 104 | |
| 105 | - foreach ($formParameters as $key => $value) { |
|
| 105 | + foreach ($formParameters as $key => $value) { |
|
| 106 | 106 | $this->assign($key, $value); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -23,149 +23,149 @@ |
||
| 23 | 23 | |
| 24 | 24 | interface ITask |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @return IEmailHelper |
|
| 28 | - */ |
|
| 29 | - public function getEmailHelper(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param IEmailHelper $emailHelper |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function setEmailHelper($emailHelper); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @return HttpHelper |
|
| 40 | - */ |
|
| 41 | - public function getHttpHelper(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param HttpHelper $httpHelper |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function setHttpHelper($httpHelper); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return WikiTextHelper |
|
| 52 | - */ |
|
| 53 | - public function getWikiTextHelper(); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param WikiTextHelper $wikiTextHelper |
|
| 57 | - * |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function setWikiTextHelper($wikiTextHelper); |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return ILocationProvider |
|
| 64 | - */ |
|
| 65 | - public function getLocationProvider(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param ILocationProvider $locationProvider |
|
| 69 | - * |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return IXffTrustProvider |
|
| 76 | - */ |
|
| 77 | - public function getXffTrustProvider(); |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param IXffTrustProvider $xffTrustProvider |
|
| 81 | - * |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return IRDnsProvider |
|
| 88 | - */ |
|
| 89 | - public function getRdnsProvider(); |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param IRDnsProvider $rdnsProvider |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function setRdnsProvider($rdnsProvider); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return IAntiSpoofProvider |
|
| 100 | - */ |
|
| 101 | - public function getAntiSpoofProvider(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 105 | - * |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return PdoDatabase |
|
| 112 | - */ |
|
| 113 | - public function getDatabase(); |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param PdoDatabase $database |
|
| 117 | - * |
|
| 118 | - * @return void |
|
| 119 | - */ |
|
| 120 | - public function setDatabase($database); |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return IOAuthProtocolHelper |
|
| 124 | - */ |
|
| 125 | - public function getOAuthProtocolHelper(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 129 | - * |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 137 | - public function execute(); |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Sets the site configuration object for this page |
|
| 141 | - * |
|
| 142 | - * @param SiteConfiguration $configuration |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function setSiteConfiguration($configuration); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return IrcNotificationHelper |
|
| 150 | - */ |
|
| 151 | - public function getNotificationHelper(); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param IrcNotificationHelper $notificationHelper |
|
| 155 | - * |
|
| 156 | - * @return void |
|
| 157 | - */ |
|
| 158 | - public function setNotificationHelper($notificationHelper); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return TorExitProvider |
|
| 162 | - */ |
|
| 163 | - public function getTorExitProvider(); |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param TorExitProvider $torExitProvider |
|
| 167 | - * |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function setTorExitProvider($torExitProvider); |
|
| 26 | + /** |
|
| 27 | + * @return IEmailHelper |
|
| 28 | + */ |
|
| 29 | + public function getEmailHelper(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param IEmailHelper $emailHelper |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function setEmailHelper($emailHelper); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @return HttpHelper |
|
| 40 | + */ |
|
| 41 | + public function getHttpHelper(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param HttpHelper $httpHelper |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function setHttpHelper($httpHelper); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return WikiTextHelper |
|
| 52 | + */ |
|
| 53 | + public function getWikiTextHelper(); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param WikiTextHelper $wikiTextHelper |
|
| 57 | + * |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function setWikiTextHelper($wikiTextHelper); |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return ILocationProvider |
|
| 64 | + */ |
|
| 65 | + public function getLocationProvider(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param ILocationProvider $locationProvider |
|
| 69 | + * |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return IXffTrustProvider |
|
| 76 | + */ |
|
| 77 | + public function getXffTrustProvider(); |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param IXffTrustProvider $xffTrustProvider |
|
| 81 | + * |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return IRDnsProvider |
|
| 88 | + */ |
|
| 89 | + public function getRdnsProvider(); |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param IRDnsProvider $rdnsProvider |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function setRdnsProvider($rdnsProvider); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return IAntiSpoofProvider |
|
| 100 | + */ |
|
| 101 | + public function getAntiSpoofProvider(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 105 | + * |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return PdoDatabase |
|
| 112 | + */ |
|
| 113 | + public function getDatabase(); |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param PdoDatabase $database |
|
| 117 | + * |
|
| 118 | + * @return void |
|
| 119 | + */ |
|
| 120 | + public function setDatabase($database); |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return IOAuthProtocolHelper |
|
| 124 | + */ |
|
| 125 | + public function getOAuthProtocolHelper(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 129 | + * |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | + public function execute(); |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Sets the site configuration object for this page |
|
| 141 | + * |
|
| 142 | + * @param SiteConfiguration $configuration |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function setSiteConfiguration($configuration); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return IrcNotificationHelper |
|
| 150 | + */ |
|
| 151 | + public function getNotificationHelper(); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param IrcNotificationHelper $notificationHelper |
|
| 155 | + * |
|
| 156 | + * @return void |
|
| 157 | + */ |
|
| 158 | + public function setNotificationHelper($notificationHelper); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return TorExitProvider |
|
| 162 | + */ |
|
| 163 | + public function getTorExitProvider(); |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param TorExitProvider $torExitProvider |
|
| 167 | + * |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function setTorExitProvider($torExitProvider); |
|
| 171 | 171 | } |
| 172 | 172 | \ No newline at end of file |
@@ -23,229 +23,229 @@ |
||
| 23 | 23 | |
| 24 | 24 | abstract class TaskBase implements ITask |
| 25 | 25 | { |
| 26 | - /** @var SiteConfiguration */ |
|
| 27 | - private $siteConfiguration; |
|
| 28 | - /** @var IEmailHelper */ |
|
| 29 | - private $emailHelper; |
|
| 30 | - /** @var HttpHelper */ |
|
| 31 | - private $httpHelper; |
|
| 32 | - /** @var WikiTextHelper */ |
|
| 33 | - private $wikiTextHelper; |
|
| 34 | - /** @var ILocationProvider */ |
|
| 35 | - private $locationProvider; |
|
| 36 | - /** @var IXffTrustProvider */ |
|
| 37 | - private $xffTrustProvider; |
|
| 38 | - /** @var IRDnsProvider */ |
|
| 39 | - private $rdnsProvider; |
|
| 40 | - /** @var IAntiSpoofProvider */ |
|
| 41 | - private $antiSpoofProvider; |
|
| 42 | - /** @var IOAuthProtocolHelper */ |
|
| 43 | - private $oauthHelper; |
|
| 44 | - /** @var PdoDatabase */ |
|
| 45 | - private $database; |
|
| 46 | - /** @var IrcNotificationHelper */ |
|
| 47 | - private $notificationHelper; |
|
| 48 | - /** @var TorExitProvider */ |
|
| 49 | - private $torExitProvider; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return IEmailHelper |
|
| 53 | - */ |
|
| 54 | - final public function getEmailHelper() |
|
| 55 | - { |
|
| 56 | - return $this->emailHelper; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param IEmailHelper $emailHelper |
|
| 61 | - */ |
|
| 62 | - final public function setEmailHelper($emailHelper) |
|
| 63 | - { |
|
| 64 | - $this->emailHelper = $emailHelper; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return HttpHelper |
|
| 69 | - */ |
|
| 70 | - final public function getHttpHelper() |
|
| 71 | - { |
|
| 72 | - return $this->httpHelper; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param HttpHelper $httpHelper |
|
| 77 | - */ |
|
| 78 | - final public function setHttpHelper($httpHelper) |
|
| 79 | - { |
|
| 80 | - $this->httpHelper = $httpHelper; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return WikiTextHelper |
|
| 85 | - */ |
|
| 86 | - final public function getWikiTextHelper() |
|
| 87 | - { |
|
| 88 | - return $this->wikiTextHelper; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param WikiTextHelper $wikiTextHelper |
|
| 93 | - */ |
|
| 94 | - final public function setWikiTextHelper($wikiTextHelper) |
|
| 95 | - { |
|
| 96 | - $this->wikiTextHelper = $wikiTextHelper; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return ILocationProvider |
|
| 101 | - */ |
|
| 102 | - final public function getLocationProvider() |
|
| 103 | - { |
|
| 104 | - return $this->locationProvider; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param ILocationProvider $locationProvider |
|
| 109 | - */ |
|
| 110 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
| 111 | - { |
|
| 112 | - $this->locationProvider = $locationProvider; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return IXffTrustProvider |
|
| 117 | - */ |
|
| 118 | - final public function getXffTrustProvider() |
|
| 119 | - { |
|
| 120 | - return $this->xffTrustProvider; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param IXffTrustProvider $xffTrustProvider |
|
| 125 | - */ |
|
| 126 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
| 127 | - { |
|
| 128 | - $this->xffTrustProvider = $xffTrustProvider; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return IRDnsProvider |
|
| 133 | - */ |
|
| 134 | - final public function getRdnsProvider() |
|
| 135 | - { |
|
| 136 | - return $this->rdnsProvider; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param IRDnsProvider $rdnsProvider |
|
| 141 | - */ |
|
| 142 | - public function setRdnsProvider($rdnsProvider) |
|
| 143 | - { |
|
| 144 | - $this->rdnsProvider = $rdnsProvider; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return IAntiSpoofProvider |
|
| 149 | - */ |
|
| 150 | - public function getAntiSpoofProvider() |
|
| 151 | - { |
|
| 152 | - return $this->antiSpoofProvider; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 157 | - */ |
|
| 158 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
| 159 | - { |
|
| 160 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return PdoDatabase |
|
| 165 | - */ |
|
| 166 | - final public function getDatabase() |
|
| 167 | - { |
|
| 168 | - return $this->database; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param PdoDatabase $database |
|
| 173 | - */ |
|
| 174 | - final public function setDatabase($database) |
|
| 175 | - { |
|
| 176 | - $this->database = $database; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return IOAuthProtocolHelper |
|
| 181 | - */ |
|
| 182 | - public function getOAuthProtocolHelper() |
|
| 183 | - { |
|
| 184 | - return $this->oauthHelper; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 189 | - */ |
|
| 190 | - public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
| 191 | - { |
|
| 192 | - $this->oauthHelper = $oauthProtocolHelper; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - abstract public function execute(); |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @return IrcNotificationHelper |
|
| 202 | - */ |
|
| 203 | - public function getNotificationHelper() |
|
| 204 | - { |
|
| 205 | - return $this->notificationHelper; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param IrcNotificationHelper $notificationHelper |
|
| 210 | - */ |
|
| 211 | - public function setNotificationHelper($notificationHelper) |
|
| 212 | - { |
|
| 213 | - $this->notificationHelper = $notificationHelper; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return TorExitProvider |
|
| 218 | - */ |
|
| 219 | - public function getTorExitProvider() |
|
| 220 | - { |
|
| 221 | - return $this->torExitProvider; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param TorExitProvider $torExitProvider |
|
| 226 | - */ |
|
| 227 | - public function setTorExitProvider($torExitProvider) |
|
| 228 | - { |
|
| 229 | - $this->torExitProvider = $torExitProvider; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Gets the site configuration object |
|
| 234 | - * |
|
| 235 | - * @return SiteConfiguration |
|
| 236 | - */ |
|
| 237 | - final protected function getSiteConfiguration() |
|
| 238 | - { |
|
| 239 | - return $this->siteConfiguration; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Sets the site configuration object for this page |
|
| 244 | - * |
|
| 245 | - * @param SiteConfiguration $configuration |
|
| 246 | - */ |
|
| 247 | - final public function setSiteConfiguration($configuration) |
|
| 248 | - { |
|
| 249 | - $this->siteConfiguration = $configuration; |
|
| 250 | - } |
|
| 26 | + /** @var SiteConfiguration */ |
|
| 27 | + private $siteConfiguration; |
|
| 28 | + /** @var IEmailHelper */ |
|
| 29 | + private $emailHelper; |
|
| 30 | + /** @var HttpHelper */ |
|
| 31 | + private $httpHelper; |
|
| 32 | + /** @var WikiTextHelper */ |
|
| 33 | + private $wikiTextHelper; |
|
| 34 | + /** @var ILocationProvider */ |
|
| 35 | + private $locationProvider; |
|
| 36 | + /** @var IXffTrustProvider */ |
|
| 37 | + private $xffTrustProvider; |
|
| 38 | + /** @var IRDnsProvider */ |
|
| 39 | + private $rdnsProvider; |
|
| 40 | + /** @var IAntiSpoofProvider */ |
|
| 41 | + private $antiSpoofProvider; |
|
| 42 | + /** @var IOAuthProtocolHelper */ |
|
| 43 | + private $oauthHelper; |
|
| 44 | + /** @var PdoDatabase */ |
|
| 45 | + private $database; |
|
| 46 | + /** @var IrcNotificationHelper */ |
|
| 47 | + private $notificationHelper; |
|
| 48 | + /** @var TorExitProvider */ |
|
| 49 | + private $torExitProvider; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return IEmailHelper |
|
| 53 | + */ |
|
| 54 | + final public function getEmailHelper() |
|
| 55 | + { |
|
| 56 | + return $this->emailHelper; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param IEmailHelper $emailHelper |
|
| 61 | + */ |
|
| 62 | + final public function setEmailHelper($emailHelper) |
|
| 63 | + { |
|
| 64 | + $this->emailHelper = $emailHelper; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return HttpHelper |
|
| 69 | + */ |
|
| 70 | + final public function getHttpHelper() |
|
| 71 | + { |
|
| 72 | + return $this->httpHelper; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param HttpHelper $httpHelper |
|
| 77 | + */ |
|
| 78 | + final public function setHttpHelper($httpHelper) |
|
| 79 | + { |
|
| 80 | + $this->httpHelper = $httpHelper; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return WikiTextHelper |
|
| 85 | + */ |
|
| 86 | + final public function getWikiTextHelper() |
|
| 87 | + { |
|
| 88 | + return $this->wikiTextHelper; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param WikiTextHelper $wikiTextHelper |
|
| 93 | + */ |
|
| 94 | + final public function setWikiTextHelper($wikiTextHelper) |
|
| 95 | + { |
|
| 96 | + $this->wikiTextHelper = $wikiTextHelper; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return ILocationProvider |
|
| 101 | + */ |
|
| 102 | + final public function getLocationProvider() |
|
| 103 | + { |
|
| 104 | + return $this->locationProvider; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param ILocationProvider $locationProvider |
|
| 109 | + */ |
|
| 110 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
| 111 | + { |
|
| 112 | + $this->locationProvider = $locationProvider; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return IXffTrustProvider |
|
| 117 | + */ |
|
| 118 | + final public function getXffTrustProvider() |
|
| 119 | + { |
|
| 120 | + return $this->xffTrustProvider; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param IXffTrustProvider $xffTrustProvider |
|
| 125 | + */ |
|
| 126 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
| 127 | + { |
|
| 128 | + $this->xffTrustProvider = $xffTrustProvider; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return IRDnsProvider |
|
| 133 | + */ |
|
| 134 | + final public function getRdnsProvider() |
|
| 135 | + { |
|
| 136 | + return $this->rdnsProvider; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param IRDnsProvider $rdnsProvider |
|
| 141 | + */ |
|
| 142 | + public function setRdnsProvider($rdnsProvider) |
|
| 143 | + { |
|
| 144 | + $this->rdnsProvider = $rdnsProvider; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return IAntiSpoofProvider |
|
| 149 | + */ |
|
| 150 | + public function getAntiSpoofProvider() |
|
| 151 | + { |
|
| 152 | + return $this->antiSpoofProvider; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 157 | + */ |
|
| 158 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
| 159 | + { |
|
| 160 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return PdoDatabase |
|
| 165 | + */ |
|
| 166 | + final public function getDatabase() |
|
| 167 | + { |
|
| 168 | + return $this->database; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param PdoDatabase $database |
|
| 173 | + */ |
|
| 174 | + final public function setDatabase($database) |
|
| 175 | + { |
|
| 176 | + $this->database = $database; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return IOAuthProtocolHelper |
|
| 181 | + */ |
|
| 182 | + public function getOAuthProtocolHelper() |
|
| 183 | + { |
|
| 184 | + return $this->oauthHelper; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 189 | + */ |
|
| 190 | + public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
| 191 | + { |
|
| 192 | + $this->oauthHelper = $oauthProtocolHelper; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + abstract public function execute(); |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @return IrcNotificationHelper |
|
| 202 | + */ |
|
| 203 | + public function getNotificationHelper() |
|
| 204 | + { |
|
| 205 | + return $this->notificationHelper; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param IrcNotificationHelper $notificationHelper |
|
| 210 | + */ |
|
| 211 | + public function setNotificationHelper($notificationHelper) |
|
| 212 | + { |
|
| 213 | + $this->notificationHelper = $notificationHelper; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return TorExitProvider |
|
| 218 | + */ |
|
| 219 | + public function getTorExitProvider() |
|
| 220 | + { |
|
| 221 | + return $this->torExitProvider; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param TorExitProvider $torExitProvider |
|
| 226 | + */ |
|
| 227 | + public function setTorExitProvider($torExitProvider) |
|
| 228 | + { |
|
| 229 | + $this->torExitProvider = $torExitProvider; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Gets the site configuration object |
|
| 234 | + * |
|
| 235 | + * @return SiteConfiguration |
|
| 236 | + */ |
|
| 237 | + final protected function getSiteConfiguration() |
|
| 238 | + { |
|
| 239 | + return $this->siteConfiguration; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Sets the site configuration object for this page |
|
| 244 | + * |
|
| 245 | + * @param SiteConfiguration $configuration |
|
| 246 | + */ |
|
| 247 | + final public function setSiteConfiguration($configuration) |
|
| 248 | + { |
|
| 249 | + $this->siteConfiguration = $configuration; |
|
| 250 | + } |
|
| 251 | 251 | } |
| 252 | 252 | \ No newline at end of file |
@@ -14,42 +14,42 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class OAuthToken extends DataObject |
| 16 | 16 | { |
| 17 | - /** @var int */ |
|
| 18 | - private $user; |
|
| 19 | - /** @var string */ |
|
| 20 | - private $token; |
|
| 21 | - /** @var string */ |
|
| 22 | - private $secret; |
|
| 23 | - /** @var string */ |
|
| 24 | - private $type; |
|
| 25 | - /** @var string */ |
|
| 26 | - private $expiry; |
|
| 27 | - |
|
| 28 | - public function save() |
|
| 29 | - { |
|
| 30 | - if ($this->isNew()) { |
|
| 31 | - // insert |
|
| 32 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 17 | + /** @var int */ |
|
| 18 | + private $user; |
|
| 19 | + /** @var string */ |
|
| 20 | + private $token; |
|
| 21 | + /** @var string */ |
|
| 22 | + private $secret; |
|
| 23 | + /** @var string */ |
|
| 24 | + private $type; |
|
| 25 | + /** @var string */ |
|
| 26 | + private $expiry; |
|
| 27 | + |
|
| 28 | + public function save() |
|
| 29 | + { |
|
| 30 | + if ($this->isNew()) { |
|
| 31 | + // insert |
|
| 32 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 33 | 33 | INSERT INTO oauthtoken ( user, token, secret, type, expiry ) |
| 34 | 34 | VALUES ( :user, :token, :secret, :type, :expiry ); |
| 35 | 35 | SQL |
| 36 | - ); |
|
| 37 | - $statement->bindValue(":user", $this->user); |
|
| 38 | - $statement->bindValue(":token", $this->token); |
|
| 39 | - $statement->bindValue(":secret", $this->secret); |
|
| 40 | - $statement->bindValue(":type", $this->type); |
|
| 41 | - $statement->bindValue(":expiry", $this->expiry); |
|
| 42 | - |
|
| 43 | - if ($statement->execute()) { |
|
| 44 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - throw new Exception($statement->errorInfo()); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - else { |
|
| 51 | - // update |
|
| 52 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 36 | + ); |
|
| 37 | + $statement->bindValue(":user", $this->user); |
|
| 38 | + $statement->bindValue(":token", $this->token); |
|
| 39 | + $statement->bindValue(":secret", $this->secret); |
|
| 40 | + $statement->bindValue(":type", $this->type); |
|
| 41 | + $statement->bindValue(":expiry", $this->expiry); |
|
| 42 | + |
|
| 43 | + if ($statement->execute()) { |
|
| 44 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + throw new Exception($statement->errorInfo()); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + else { |
|
| 51 | + // update |
|
| 52 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 53 | 53 | UPDATE oauthtoken |
| 54 | 54 | SET token = :token |
| 55 | 55 | , secret = :secret |
@@ -58,109 +58,109 @@ discard block |
||
| 58 | 58 | , updateversion = updateversion + 1 |
| 59 | 59 | WHERE id = :id AND updateversion = :updateversion; |
| 60 | 60 | SQL |
| 61 | - ); |
|
| 62 | - |
|
| 63 | - $statement->bindValue(':id', $this->id); |
|
| 64 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 65 | - |
|
| 66 | - $statement->bindValue(":token", $this->token); |
|
| 67 | - $statement->bindValue(":secret", $this->secret); |
|
| 68 | - $statement->bindValue(":type", $this->type); |
|
| 69 | - $statement->bindValue(":expiry", $this->expiry); |
|
| 70 | - |
|
| 71 | - if (!$statement->execute()) { |
|
| 72 | - throw new Exception($statement->errorInfo()); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ($statement->rowCount() !== 1) { |
|
| 76 | - throw new OptimisticLockFailedException(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $this->updateversion++; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - #region properties |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return mixed |
|
| 87 | - */ |
|
| 88 | - public function getUserId() |
|
| 89 | - { |
|
| 90 | - return $this->user; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param mixed $user |
|
| 95 | - */ |
|
| 96 | - public function setUserId($user) |
|
| 97 | - { |
|
| 98 | - $this->user = $user; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return mixed |
|
| 103 | - */ |
|
| 104 | - public function getToken() |
|
| 105 | - { |
|
| 106 | - return $this->token; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param mixed $token |
|
| 111 | - */ |
|
| 112 | - public function setToken($token) |
|
| 113 | - { |
|
| 114 | - $this->token = $token; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return mixed |
|
| 119 | - */ |
|
| 120 | - public function getSecret() |
|
| 121 | - { |
|
| 122 | - return $this->secret; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param mixed $secret |
|
| 127 | - */ |
|
| 128 | - public function setSecret($secret) |
|
| 129 | - { |
|
| 130 | - $this->secret = $secret; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function getType() |
|
| 137 | - { |
|
| 138 | - return $this->type; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param mixed $type |
|
| 143 | - */ |
|
| 144 | - public function setType($type) |
|
| 145 | - { |
|
| 146 | - $this->type = $type; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function getExpiry() |
|
| 153 | - { |
|
| 154 | - return $this->expiry; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param string $expiry |
|
| 159 | - */ |
|
| 160 | - public function setExpiry($expiry) |
|
| 161 | - { |
|
| 162 | - $this->expiry = $expiry; |
|
| 163 | - } |
|
| 164 | - #endregion |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + $statement->bindValue(':id', $this->id); |
|
| 64 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 65 | + |
|
| 66 | + $statement->bindValue(":token", $this->token); |
|
| 67 | + $statement->bindValue(":secret", $this->secret); |
|
| 68 | + $statement->bindValue(":type", $this->type); |
|
| 69 | + $statement->bindValue(":expiry", $this->expiry); |
|
| 70 | + |
|
| 71 | + if (!$statement->execute()) { |
|
| 72 | + throw new Exception($statement->errorInfo()); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ($statement->rowCount() !== 1) { |
|
| 76 | + throw new OptimisticLockFailedException(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $this->updateversion++; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + #region properties |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return mixed |
|
| 87 | + */ |
|
| 88 | + public function getUserId() |
|
| 89 | + { |
|
| 90 | + return $this->user; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param mixed $user |
|
| 95 | + */ |
|
| 96 | + public function setUserId($user) |
|
| 97 | + { |
|
| 98 | + $this->user = $user; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return mixed |
|
| 103 | + */ |
|
| 104 | + public function getToken() |
|
| 105 | + { |
|
| 106 | + return $this->token; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param mixed $token |
|
| 111 | + */ |
|
| 112 | + public function setToken($token) |
|
| 113 | + { |
|
| 114 | + $this->token = $token; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return mixed |
|
| 119 | + */ |
|
| 120 | + public function getSecret() |
|
| 121 | + { |
|
| 122 | + return $this->secret; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param mixed $secret |
|
| 127 | + */ |
|
| 128 | + public function setSecret($secret) |
|
| 129 | + { |
|
| 130 | + $this->secret = $secret; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function getType() |
|
| 137 | + { |
|
| 138 | + return $this->type; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param mixed $type |
|
| 143 | + */ |
|
| 144 | + public function setType($type) |
|
| 145 | + { |
|
| 146 | + $this->type = $type; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function getExpiry() |
|
| 153 | + { |
|
| 154 | + return $this->expiry; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param string $expiry |
|
| 159 | + */ |
|
| 160 | + public function setExpiry($expiry) |
|
| 161 | + { |
|
| 162 | + $this->expiry = $expiry; |
|
| 163 | + } |
|
| 164 | + #endregion |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | \ No newline at end of file |
@@ -569,7 +569,7 @@ |
||
| 569 | 569 | public function getForgottenPasswordHash() |
| 570 | 570 | { |
| 571 | 571 | // FIXME |
| 572 | - return md5($this->username . $this->email . $this->welcome_template . $this->id); |
|
| 572 | + return md5($this->username.$this->email.$this->welcome_template.$this->id); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -21,160 +21,160 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class User extends DataObject |
| 23 | 23 | { |
| 24 | - const STATUS_ACTIVE = 'Active'; |
|
| 25 | - const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | - const STATUS_DECLINED = 'Declined'; |
|
| 27 | - const STATUS_NEW = 'New'; |
|
| 28 | - const CREATION_MANUAL = 0; |
|
| 29 | - const CREATION_OAUTH = 1; |
|
| 30 | - const CREATION_BOT = 2; |
|
| 31 | - private $username; |
|
| 32 | - private $email; |
|
| 33 | - private $status = self::STATUS_NEW; |
|
| 34 | - private $onwikiname; |
|
| 35 | - private $welcome_sig = ""; |
|
| 36 | - private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | - private $forcelogout = 0; |
|
| 38 | - private $forceidentified = null; |
|
| 39 | - private $welcome_template = 0; |
|
| 40 | - private $abortpref = 0; |
|
| 41 | - private $confirmationdiff = 0; |
|
| 42 | - private $emailsig = ""; |
|
| 43 | - private $creationmode = 0; |
|
| 44 | - private $skin = "main"; |
|
| 45 | - /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | - private static $currentUser; |
|
| 47 | - #region Object load methods |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Gets the currently logged in user |
|
| 51 | - * |
|
| 52 | - * @param PdoDatabase $database |
|
| 53 | - * |
|
| 54 | - * @return User|CommunityUser |
|
| 55 | - */ |
|
| 56 | - public static function getCurrent(PdoDatabase $database) |
|
| 57 | - { |
|
| 58 | - if (self::$currentUser === null) { |
|
| 59 | - $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | - |
|
| 61 | - if ($sessionId !== null) { |
|
| 62 | - /** @var User $user */ |
|
| 63 | - $user = self::getById($sessionId, $database); |
|
| 64 | - |
|
| 65 | - if ($user === false) { |
|
| 66 | - self::$currentUser = new CommunityUser(); |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - self::$currentUser = $user; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - else { |
|
| 73 | - $anonymousCoward = new CommunityUser(); |
|
| 74 | - |
|
| 75 | - self::$currentUser = $anonymousCoward; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return self::$currentUser; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Gets a user by their user ID |
|
| 84 | - * |
|
| 85 | - * Pass -1 to get the community user. |
|
| 86 | - * |
|
| 87 | - * @param int|null $id |
|
| 88 | - * @param PdoDatabase $database |
|
| 89 | - * |
|
| 90 | - * @return User|false |
|
| 91 | - */ |
|
| 92 | - public static function getById($id, PdoDatabase $database) |
|
| 93 | - { |
|
| 94 | - if ($id === null || $id == -1) { |
|
| 95 | - return new CommunityUser(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** @var User|false $user */ |
|
| 99 | - $user = parent::getById($id, $database); |
|
| 100 | - |
|
| 101 | - return $user; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return CommunityUser |
|
| 106 | - */ |
|
| 107 | - public static function getCommunity() |
|
| 108 | - { |
|
| 109 | - return new CommunityUser(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets a user by their username |
|
| 114 | - * |
|
| 115 | - * @param string $username |
|
| 116 | - * @param PdoDatabase $database |
|
| 117 | - * |
|
| 118 | - * @return CommunityUser|User|false |
|
| 119 | - */ |
|
| 120 | - public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | - { |
|
| 122 | - global $communityUsername; |
|
| 123 | - if ($username == $communityUsername) { |
|
| 124 | - return new CommunityUser(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | - $statement->bindValue(":id", $username); |
|
| 129 | - |
|
| 130 | - $statement->execute(); |
|
| 131 | - |
|
| 132 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | - |
|
| 134 | - if ($resultObject != false) { |
|
| 135 | - $resultObject->setDatabase($database); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $resultObject; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Gets a user by their on-wiki username. |
|
| 143 | - * |
|
| 144 | - * @param string $username |
|
| 145 | - * @param PdoDatabase $database |
|
| 146 | - * |
|
| 147 | - * @return User|false |
|
| 148 | - */ |
|
| 149 | - public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | - { |
|
| 151 | - $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | - $statement->bindValue(":id", $username); |
|
| 153 | - $statement->execute(); |
|
| 154 | - |
|
| 155 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | - |
|
| 157 | - if ($resultObject != false) { |
|
| 158 | - $resultObject->setDatabase($database); |
|
| 159 | - |
|
| 160 | - return $resultObject; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - #endregion |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Saves the current object |
|
| 170 | - * |
|
| 171 | - * @throws Exception |
|
| 172 | - */ |
|
| 173 | - public function save() |
|
| 174 | - { |
|
| 175 | - if ($this->isNew()) { |
|
| 176 | - // insert |
|
| 177 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 24 | + const STATUS_ACTIVE = 'Active'; |
|
| 25 | + const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | + const STATUS_DECLINED = 'Declined'; |
|
| 27 | + const STATUS_NEW = 'New'; |
|
| 28 | + const CREATION_MANUAL = 0; |
|
| 29 | + const CREATION_OAUTH = 1; |
|
| 30 | + const CREATION_BOT = 2; |
|
| 31 | + private $username; |
|
| 32 | + private $email; |
|
| 33 | + private $status = self::STATUS_NEW; |
|
| 34 | + private $onwikiname; |
|
| 35 | + private $welcome_sig = ""; |
|
| 36 | + private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | + private $forcelogout = 0; |
|
| 38 | + private $forceidentified = null; |
|
| 39 | + private $welcome_template = 0; |
|
| 40 | + private $abortpref = 0; |
|
| 41 | + private $confirmationdiff = 0; |
|
| 42 | + private $emailsig = ""; |
|
| 43 | + private $creationmode = 0; |
|
| 44 | + private $skin = "main"; |
|
| 45 | + /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | + private static $currentUser; |
|
| 47 | + #region Object load methods |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Gets the currently logged in user |
|
| 51 | + * |
|
| 52 | + * @param PdoDatabase $database |
|
| 53 | + * |
|
| 54 | + * @return User|CommunityUser |
|
| 55 | + */ |
|
| 56 | + public static function getCurrent(PdoDatabase $database) |
|
| 57 | + { |
|
| 58 | + if (self::$currentUser === null) { |
|
| 59 | + $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | + |
|
| 61 | + if ($sessionId !== null) { |
|
| 62 | + /** @var User $user */ |
|
| 63 | + $user = self::getById($sessionId, $database); |
|
| 64 | + |
|
| 65 | + if ($user === false) { |
|
| 66 | + self::$currentUser = new CommunityUser(); |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + self::$currentUser = $user; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + else { |
|
| 73 | + $anonymousCoward = new CommunityUser(); |
|
| 74 | + |
|
| 75 | + self::$currentUser = $anonymousCoward; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return self::$currentUser; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Gets a user by their user ID |
|
| 84 | + * |
|
| 85 | + * Pass -1 to get the community user. |
|
| 86 | + * |
|
| 87 | + * @param int|null $id |
|
| 88 | + * @param PdoDatabase $database |
|
| 89 | + * |
|
| 90 | + * @return User|false |
|
| 91 | + */ |
|
| 92 | + public static function getById($id, PdoDatabase $database) |
|
| 93 | + { |
|
| 94 | + if ($id === null || $id == -1) { |
|
| 95 | + return new CommunityUser(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** @var User|false $user */ |
|
| 99 | + $user = parent::getById($id, $database); |
|
| 100 | + |
|
| 101 | + return $user; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return CommunityUser |
|
| 106 | + */ |
|
| 107 | + public static function getCommunity() |
|
| 108 | + { |
|
| 109 | + return new CommunityUser(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets a user by their username |
|
| 114 | + * |
|
| 115 | + * @param string $username |
|
| 116 | + * @param PdoDatabase $database |
|
| 117 | + * |
|
| 118 | + * @return CommunityUser|User|false |
|
| 119 | + */ |
|
| 120 | + public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | + { |
|
| 122 | + global $communityUsername; |
|
| 123 | + if ($username == $communityUsername) { |
|
| 124 | + return new CommunityUser(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | + $statement->bindValue(":id", $username); |
|
| 129 | + |
|
| 130 | + $statement->execute(); |
|
| 131 | + |
|
| 132 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | + |
|
| 134 | + if ($resultObject != false) { |
|
| 135 | + $resultObject->setDatabase($database); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $resultObject; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Gets a user by their on-wiki username. |
|
| 143 | + * |
|
| 144 | + * @param string $username |
|
| 145 | + * @param PdoDatabase $database |
|
| 146 | + * |
|
| 147 | + * @return User|false |
|
| 148 | + */ |
|
| 149 | + public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | + { |
|
| 151 | + $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | + $statement->bindValue(":id", $username); |
|
| 153 | + $statement->execute(); |
|
| 154 | + |
|
| 155 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | + |
|
| 157 | + if ($resultObject != false) { |
|
| 158 | + $resultObject->setDatabase($database); |
|
| 159 | + |
|
| 160 | + return $resultObject; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + #endregion |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Saves the current object |
|
| 170 | + * |
|
| 171 | + * @throws Exception |
|
| 172 | + */ |
|
| 173 | + public function save() |
|
| 174 | + { |
|
| 175 | + if ($this->isNew()) { |
|
| 176 | + // insert |
|
| 177 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 178 | 178 | INSERT INTO `user` ( |
| 179 | 179 | username, email, status, onwikiname, welcome_sig, |
| 180 | 180 | lastactive, forcelogout, forceidentified, |
@@ -185,32 +185,32 @@ discard block |
||
| 185 | 185 | :welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode, :skin |
| 186 | 186 | ); |
| 187 | 187 | SQL |
| 188 | - ); |
|
| 189 | - $statement->bindValue(":username", $this->username); |
|
| 190 | - $statement->bindValue(":email", $this->email); |
|
| 191 | - $statement->bindValue(":status", $this->status); |
|
| 192 | - $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | - $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | - $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | - $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | - $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | - $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | - $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | - $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | - $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | - $statement->bindValue(":skin", $this->skin); |
|
| 203 | - |
|
| 204 | - if ($statement->execute()) { |
|
| 205 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | - } |
|
| 207 | - else { |
|
| 208 | - throw new Exception($statement->errorInfo()); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - // update |
|
| 213 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 188 | + ); |
|
| 189 | + $statement->bindValue(":username", $this->username); |
|
| 190 | + $statement->bindValue(":email", $this->email); |
|
| 191 | + $statement->bindValue(":status", $this->status); |
|
| 192 | + $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | + $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | + $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | + $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | + $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | + $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | + $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | + $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | + $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | + $statement->bindValue(":skin", $this->skin); |
|
| 203 | + |
|
| 204 | + if ($statement->execute()) { |
|
| 205 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | + } |
|
| 207 | + else { |
|
| 208 | + throw new Exception($statement->errorInfo()); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + // update |
|
| 213 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 214 | 214 | UPDATE `user` SET |
| 215 | 215 | username = :username, email = :email, |
| 216 | 216 | status = :status, |
@@ -223,389 +223,389 @@ discard block |
||
| 223 | 223 | updateversion = updateversion + 1 |
| 224 | 224 | WHERE id = :id AND updateversion = :updateversion; |
| 225 | 225 | SQL |
| 226 | - ); |
|
| 227 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | - |
|
| 229 | - $statement->bindValue(':id', $this->id); |
|
| 230 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | - |
|
| 232 | - $statement->bindValue(':username', $this->username); |
|
| 233 | - $statement->bindValue(':email', $this->email); |
|
| 234 | - $statement->bindValue(':status', $this->status); |
|
| 235 | - $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | - $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | - $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | - $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | - $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | - $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | - $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | - $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | - $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | - $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | - $statement->bindValue(':skin', $this->skin); |
|
| 246 | - |
|
| 247 | - if (!$statement->execute()) { |
|
| 248 | - throw new Exception($statement->errorInfo()); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if ($statement->rowCount() !== 1) { |
|
| 252 | - throw new OptimisticLockFailedException(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $this->updateversion++; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - #region properties |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Gets the tool username |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function getUsername() |
|
| 266 | - { |
|
| 267 | - return $this->username; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Sets the tool username |
|
| 272 | - * |
|
| 273 | - * @param string $username |
|
| 274 | - */ |
|
| 275 | - public function setUsername($username) |
|
| 276 | - { |
|
| 277 | - $this->username = $username; |
|
| 278 | - |
|
| 279 | - // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | - if (!$this->isNew()) { |
|
| 281 | - $this->forcelogout = 1; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Gets the user's email address |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function getEmail() |
|
| 290 | - { |
|
| 291 | - return $this->email; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Sets the user's email address |
|
| 296 | - * |
|
| 297 | - * @param string $email |
|
| 298 | - */ |
|
| 299 | - public function setEmail($email) |
|
| 300 | - { |
|
| 301 | - $this->email = $email; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function getStatus() |
|
| 309 | - { |
|
| 310 | - return $this->status; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param string $status |
|
| 315 | - */ |
|
| 316 | - public function setStatus($status) |
|
| 317 | - { |
|
| 318 | - $this->status = $status; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Gets the user's on-wiki name |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function getOnWikiName() |
|
| 326 | - { |
|
| 327 | - return $this->onwikiname; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets the user's on-wiki name |
|
| 332 | - * |
|
| 333 | - * This can have interesting side-effects with OAuth. |
|
| 334 | - * |
|
| 335 | - * @param string $onWikiName |
|
| 336 | - */ |
|
| 337 | - public function setOnWikiName($onWikiName) |
|
| 338 | - { |
|
| 339 | - $this->onwikiname = $onWikiName; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Gets the welcome signature |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function getWelcomeSig() |
|
| 347 | - { |
|
| 348 | - return $this->welcome_sig; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Sets the welcome signature |
|
| 353 | - * |
|
| 354 | - * @param string $welcomeSig |
|
| 355 | - */ |
|
| 356 | - public function setWelcomeSig($welcomeSig) |
|
| 357 | - { |
|
| 358 | - $this->welcome_sig = $welcomeSig; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Gets the last activity date for the user |
|
| 363 | - * |
|
| 364 | - * @return string |
|
| 365 | - * @todo This should probably return an instance of DateTime |
|
| 366 | - */ |
|
| 367 | - public function getLastActive() |
|
| 368 | - { |
|
| 369 | - return $this->lastactive; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Gets the user's forced logout status |
|
| 374 | - * |
|
| 375 | - * @return bool |
|
| 376 | - */ |
|
| 377 | - public function getForceLogout() |
|
| 378 | - { |
|
| 379 | - return $this->forcelogout == 1; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Sets the user's forced logout status |
|
| 384 | - * |
|
| 385 | - * @param bool $forceLogout |
|
| 386 | - */ |
|
| 387 | - public function setForceLogout($forceLogout) |
|
| 388 | - { |
|
| 389 | - $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the ID of the welcome template used. |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 396 | - public function getWelcomeTemplate() |
|
| 397 | - { |
|
| 398 | - return $this->welcome_template; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Sets the ID of the welcome template used. |
|
| 403 | - * |
|
| 404 | - * @param int $welcomeTemplate |
|
| 405 | - */ |
|
| 406 | - public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | - { |
|
| 408 | - $this->welcome_template = $welcomeTemplate; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets the user's abort preference |
|
| 413 | - * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | - * @return int |
|
| 415 | - */ |
|
| 416 | - public function getAbortPref() |
|
| 417 | - { |
|
| 418 | - return $this->abortpref; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Sets the user's abort preference |
|
| 423 | - * @todo rename, retype, and re-comment. |
|
| 424 | - * |
|
| 425 | - * @param int $abortPreference |
|
| 426 | - */ |
|
| 427 | - public function setAbortPref($abortPreference) |
|
| 428 | - { |
|
| 429 | - $this->abortpref = $abortPreference; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | - * @return int the diff ID |
|
| 435 | - */ |
|
| 436 | - public function getConfirmationDiff() |
|
| 437 | - { |
|
| 438 | - return $this->confirmationdiff; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Sets the user's confirmation diff. |
|
| 443 | - * |
|
| 444 | - * @param int $confirmationDiff |
|
| 445 | - */ |
|
| 446 | - public function setConfirmationDiff($confirmationDiff) |
|
| 447 | - { |
|
| 448 | - $this->confirmationdiff = $confirmationDiff; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Gets the users' email signature used on outbound mail. |
|
| 453 | - * @todo rename me! |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function getEmailSig() |
|
| 457 | - { |
|
| 458 | - return $this->emailsig; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Sets the user's email signature for outbound mail. |
|
| 463 | - * |
|
| 464 | - * @param string $emailSignature |
|
| 465 | - */ |
|
| 466 | - public function setEmailSig($emailSignature) |
|
| 467 | - { |
|
| 468 | - $this->emailsig = $emailSignature; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - */ |
|
| 474 | - public function getCreationMode() |
|
| 475 | - { |
|
| 476 | - return $this->creationmode; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @param $creationMode int |
|
| 481 | - */ |
|
| 482 | - public function setCreationMode($creationMode) |
|
| 483 | - { |
|
| 484 | - $this->creationmode = $creationMode; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @return boolean |
|
| 489 | - */ |
|
| 490 | - public function getUseAlternateSkin() |
|
| 491 | - { |
|
| 492 | - return $this->skin === 'alt'; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - public function getSkin() |
|
| 499 | - { |
|
| 500 | - return $this->skin; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * @param $skin string |
|
| 505 | - */ |
|
| 506 | - public function setSkin($skin) |
|
| 507 | - { |
|
| 508 | - $this->skin = $skin; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - #endregion |
|
| 512 | - |
|
| 513 | - #region user access checks |
|
| 514 | - |
|
| 515 | - public function isActive() |
|
| 516 | - { |
|
| 517 | - return $this->status == self::STATUS_ACTIVE; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Tests if the user is identified |
|
| 522 | - * |
|
| 523 | - * @param IdentificationVerifier $iv |
|
| 524 | - * |
|
| 525 | - * @return bool |
|
| 526 | - * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 527 | - * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 528 | - * to play it safe for now. |
|
| 529 | - * @category Security-Critical |
|
| 530 | - */ |
|
| 531 | - public function isIdentified(IdentificationVerifier $iv) |
|
| 532 | - { |
|
| 533 | - if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 534 | - // User forced to unidentified in the database. |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 538 | - // User forced to identified in the database. |
|
| 539 | - return true; |
|
| 540 | - } |
|
| 541 | - else { |
|
| 542 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 543 | - return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Tests if the user is suspended |
|
| 549 | - * @return bool |
|
| 550 | - * @category Security-Critical |
|
| 551 | - */ |
|
| 552 | - public function isSuspended() |
|
| 553 | - { |
|
| 554 | - return $this->status == self::STATUS_SUSPENDED; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Tests if the user is new |
|
| 559 | - * @return bool |
|
| 560 | - * @category Security-Critical |
|
| 561 | - */ |
|
| 562 | - public function isNewUser() |
|
| 563 | - { |
|
| 564 | - return $this->status == self::STATUS_NEW; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Tests if the user has been declined access to the tool |
|
| 569 | - * @return bool |
|
| 570 | - * @category Security-Critical |
|
| 571 | - */ |
|
| 572 | - public function isDeclined() |
|
| 573 | - { |
|
| 574 | - return $this->status == self::STATUS_DECLINED; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Tests if the user is the community user |
|
| 579 | - * |
|
| 580 | - * @todo decide if this means logged out. I think it usually does. |
|
| 581 | - * @return bool |
|
| 582 | - * @category Security-Critical |
|
| 583 | - */ |
|
| 584 | - public function isCommunityUser() |
|
| 585 | - { |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - #endregion |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * Gets a hash of data for the user to reset their password with. |
|
| 593 | - * @category Security-Critical |
|
| 594 | - * @return string |
|
| 595 | - */ |
|
| 596 | - public function getForgottenPasswordHash() |
|
| 597 | - { |
|
| 598 | - // FIXME |
|
| 599 | - return md5($this->username . $this->email . $this->welcome_template . $this->id); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Gets the approval date of the user |
|
| 604 | - * @return DateTime|false |
|
| 605 | - */ |
|
| 606 | - public function getApprovalDate() |
|
| 607 | - { |
|
| 608 | - $query = $this->dbObject->prepare(<<<SQL |
|
| 226 | + ); |
|
| 227 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | + |
|
| 229 | + $statement->bindValue(':id', $this->id); |
|
| 230 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | + |
|
| 232 | + $statement->bindValue(':username', $this->username); |
|
| 233 | + $statement->bindValue(':email', $this->email); |
|
| 234 | + $statement->bindValue(':status', $this->status); |
|
| 235 | + $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | + $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | + $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | + $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | + $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | + $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | + $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | + $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | + $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | + $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | + $statement->bindValue(':skin', $this->skin); |
|
| 246 | + |
|
| 247 | + if (!$statement->execute()) { |
|
| 248 | + throw new Exception($statement->errorInfo()); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if ($statement->rowCount() !== 1) { |
|
| 252 | + throw new OptimisticLockFailedException(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $this->updateversion++; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + #region properties |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Gets the tool username |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function getUsername() |
|
| 266 | + { |
|
| 267 | + return $this->username; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Sets the tool username |
|
| 272 | + * |
|
| 273 | + * @param string $username |
|
| 274 | + */ |
|
| 275 | + public function setUsername($username) |
|
| 276 | + { |
|
| 277 | + $this->username = $username; |
|
| 278 | + |
|
| 279 | + // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | + if (!$this->isNew()) { |
|
| 281 | + $this->forcelogout = 1; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Gets the user's email address |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function getEmail() |
|
| 290 | + { |
|
| 291 | + return $this->email; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Sets the user's email address |
|
| 296 | + * |
|
| 297 | + * @param string $email |
|
| 298 | + */ |
|
| 299 | + public function setEmail($email) |
|
| 300 | + { |
|
| 301 | + $this->email = $email; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function getStatus() |
|
| 309 | + { |
|
| 310 | + return $this->status; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param string $status |
|
| 315 | + */ |
|
| 316 | + public function setStatus($status) |
|
| 317 | + { |
|
| 318 | + $this->status = $status; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Gets the user's on-wiki name |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function getOnWikiName() |
|
| 326 | + { |
|
| 327 | + return $this->onwikiname; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets the user's on-wiki name |
|
| 332 | + * |
|
| 333 | + * This can have interesting side-effects with OAuth. |
|
| 334 | + * |
|
| 335 | + * @param string $onWikiName |
|
| 336 | + */ |
|
| 337 | + public function setOnWikiName($onWikiName) |
|
| 338 | + { |
|
| 339 | + $this->onwikiname = $onWikiName; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Gets the welcome signature |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function getWelcomeSig() |
|
| 347 | + { |
|
| 348 | + return $this->welcome_sig; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Sets the welcome signature |
|
| 353 | + * |
|
| 354 | + * @param string $welcomeSig |
|
| 355 | + */ |
|
| 356 | + public function setWelcomeSig($welcomeSig) |
|
| 357 | + { |
|
| 358 | + $this->welcome_sig = $welcomeSig; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Gets the last activity date for the user |
|
| 363 | + * |
|
| 364 | + * @return string |
|
| 365 | + * @todo This should probably return an instance of DateTime |
|
| 366 | + */ |
|
| 367 | + public function getLastActive() |
|
| 368 | + { |
|
| 369 | + return $this->lastactive; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Gets the user's forced logout status |
|
| 374 | + * |
|
| 375 | + * @return bool |
|
| 376 | + */ |
|
| 377 | + public function getForceLogout() |
|
| 378 | + { |
|
| 379 | + return $this->forcelogout == 1; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Sets the user's forced logout status |
|
| 384 | + * |
|
| 385 | + * @param bool $forceLogout |
|
| 386 | + */ |
|
| 387 | + public function setForceLogout($forceLogout) |
|
| 388 | + { |
|
| 389 | + $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the ID of the welcome template used. |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | + public function getWelcomeTemplate() |
|
| 397 | + { |
|
| 398 | + return $this->welcome_template; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Sets the ID of the welcome template used. |
|
| 403 | + * |
|
| 404 | + * @param int $welcomeTemplate |
|
| 405 | + */ |
|
| 406 | + public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | + { |
|
| 408 | + $this->welcome_template = $welcomeTemplate; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets the user's abort preference |
|
| 413 | + * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | + * @return int |
|
| 415 | + */ |
|
| 416 | + public function getAbortPref() |
|
| 417 | + { |
|
| 418 | + return $this->abortpref; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Sets the user's abort preference |
|
| 423 | + * @todo rename, retype, and re-comment. |
|
| 424 | + * |
|
| 425 | + * @param int $abortPreference |
|
| 426 | + */ |
|
| 427 | + public function setAbortPref($abortPreference) |
|
| 428 | + { |
|
| 429 | + $this->abortpref = $abortPreference; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | + * @return int the diff ID |
|
| 435 | + */ |
|
| 436 | + public function getConfirmationDiff() |
|
| 437 | + { |
|
| 438 | + return $this->confirmationdiff; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Sets the user's confirmation diff. |
|
| 443 | + * |
|
| 444 | + * @param int $confirmationDiff |
|
| 445 | + */ |
|
| 446 | + public function setConfirmationDiff($confirmationDiff) |
|
| 447 | + { |
|
| 448 | + $this->confirmationdiff = $confirmationDiff; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Gets the users' email signature used on outbound mail. |
|
| 453 | + * @todo rename me! |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function getEmailSig() |
|
| 457 | + { |
|
| 458 | + return $this->emailsig; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Sets the user's email signature for outbound mail. |
|
| 463 | + * |
|
| 464 | + * @param string $emailSignature |
|
| 465 | + */ |
|
| 466 | + public function setEmailSig($emailSignature) |
|
| 467 | + { |
|
| 468 | + $this->emailsig = $emailSignature; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + */ |
|
| 474 | + public function getCreationMode() |
|
| 475 | + { |
|
| 476 | + return $this->creationmode; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @param $creationMode int |
|
| 481 | + */ |
|
| 482 | + public function setCreationMode($creationMode) |
|
| 483 | + { |
|
| 484 | + $this->creationmode = $creationMode; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @return boolean |
|
| 489 | + */ |
|
| 490 | + public function getUseAlternateSkin() |
|
| 491 | + { |
|
| 492 | + return $this->skin === 'alt'; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + public function getSkin() |
|
| 499 | + { |
|
| 500 | + return $this->skin; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * @param $skin string |
|
| 505 | + */ |
|
| 506 | + public function setSkin($skin) |
|
| 507 | + { |
|
| 508 | + $this->skin = $skin; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + #endregion |
|
| 512 | + |
|
| 513 | + #region user access checks |
|
| 514 | + |
|
| 515 | + public function isActive() |
|
| 516 | + { |
|
| 517 | + return $this->status == self::STATUS_ACTIVE; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Tests if the user is identified |
|
| 522 | + * |
|
| 523 | + * @param IdentificationVerifier $iv |
|
| 524 | + * |
|
| 525 | + * @return bool |
|
| 526 | + * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 527 | + * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 528 | + * to play it safe for now. |
|
| 529 | + * @category Security-Critical |
|
| 530 | + */ |
|
| 531 | + public function isIdentified(IdentificationVerifier $iv) |
|
| 532 | + { |
|
| 533 | + if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 534 | + // User forced to unidentified in the database. |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 538 | + // User forced to identified in the database. |
|
| 539 | + return true; |
|
| 540 | + } |
|
| 541 | + else { |
|
| 542 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 543 | + return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Tests if the user is suspended |
|
| 549 | + * @return bool |
|
| 550 | + * @category Security-Critical |
|
| 551 | + */ |
|
| 552 | + public function isSuspended() |
|
| 553 | + { |
|
| 554 | + return $this->status == self::STATUS_SUSPENDED; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Tests if the user is new |
|
| 559 | + * @return bool |
|
| 560 | + * @category Security-Critical |
|
| 561 | + */ |
|
| 562 | + public function isNewUser() |
|
| 563 | + { |
|
| 564 | + return $this->status == self::STATUS_NEW; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Tests if the user has been declined access to the tool |
|
| 569 | + * @return bool |
|
| 570 | + * @category Security-Critical |
|
| 571 | + */ |
|
| 572 | + public function isDeclined() |
|
| 573 | + { |
|
| 574 | + return $this->status == self::STATUS_DECLINED; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Tests if the user is the community user |
|
| 579 | + * |
|
| 580 | + * @todo decide if this means logged out. I think it usually does. |
|
| 581 | + * @return bool |
|
| 582 | + * @category Security-Critical |
|
| 583 | + */ |
|
| 584 | + public function isCommunityUser() |
|
| 585 | + { |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + #endregion |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * Gets a hash of data for the user to reset their password with. |
|
| 593 | + * @category Security-Critical |
|
| 594 | + * @return string |
|
| 595 | + */ |
|
| 596 | + public function getForgottenPasswordHash() |
|
| 597 | + { |
|
| 598 | + // FIXME |
|
| 599 | + return md5($this->username . $this->email . $this->welcome_template . $this->id); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Gets the approval date of the user |
|
| 604 | + * @return DateTime|false |
|
| 605 | + */ |
|
| 606 | + public function getApprovalDate() |
|
| 607 | + { |
|
| 608 | + $query = $this->dbObject->prepare(<<<SQL |
|
| 609 | 609 | SELECT timestamp |
| 610 | 610 | FROM log |
| 611 | 611 | WHERE objectid = :userid |
@@ -614,12 +614,12 @@ discard block |
||
| 614 | 614 | ORDER BY id DESC |
| 615 | 615 | LIMIT 1; |
| 616 | 616 | SQL |
| 617 | - ); |
|
| 618 | - $query->execute(array(":userid" => $this->id)); |
|
| 617 | + ); |
|
| 618 | + $query->execute(array(":userid" => $this->id)); |
|
| 619 | 619 | |
| 620 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 621 | - $query->closeCursor(); |
|
| 620 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 621 | + $query->closeCursor(); |
|
| 622 | 622 | |
| 623 | - return $data; |
|
| 624 | - } |
|
| 623 | + return $data; |
|
| 624 | + } |
|
| 625 | 625 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class JobQueue extends DataObject |
| 19 | 19 | { |
| 20 | - /* |
|
| 20 | + /* |
|
| 21 | 21 | * Status workflow is this: |
| 22 | 22 | * |
| 23 | 23 | * 1) Ready. The job has been added to the queue |
@@ -26,78 +26,78 @@ discard block |
||
| 26 | 26 | * 3) Complete / Failed. The job has been processed |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | - const STATUS_READY = 'ready'; |
|
| 30 | - const STATUS_WAITING = 'waiting'; |
|
| 31 | - const STATUS_RUNNING = 'running'; |
|
| 32 | - const STATUS_COMPLETE = 'complete'; |
|
| 33 | - const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | - const STATUS_FAILED = 'failed'; |
|
| 35 | - const STATUS_HELD = 'held'; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - private $task; |
|
| 39 | - /** @var int */ |
|
| 40 | - private $user; |
|
| 41 | - /** @var int */ |
|
| 42 | - private $request; |
|
| 43 | - /** @var int */ |
|
| 44 | - private $emailtemplate; |
|
| 45 | - /** @var string */ |
|
| 46 | - private $status; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $enqueue; |
|
| 49 | - /** @var string */ |
|
| 50 | - private $parameters; |
|
| 51 | - /** @var string */ |
|
| 52 | - private $error; |
|
| 53 | - /** @var int */ |
|
| 54 | - private $acknowledged; |
|
| 55 | - /** @var int */ |
|
| 56 | - private $parent; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * This feels like the least bad place to put this method. |
|
| 60 | - */ |
|
| 61 | - public static function getTaskDescriptions() { |
|
| 62 | - return array( |
|
| 63 | - BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | - UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | - WelcomeUserTask::class => 'Welcome user', |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | - * @return void |
|
| 72 | - * @throws Exception |
|
| 73 | - * @throws OptimisticLockFailedException |
|
| 74 | - */ |
|
| 75 | - public function save() |
|
| 76 | - { |
|
| 77 | - if ($this->isNew()) { |
|
| 78 | - // insert |
|
| 79 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 29 | + const STATUS_READY = 'ready'; |
|
| 30 | + const STATUS_WAITING = 'waiting'; |
|
| 31 | + const STATUS_RUNNING = 'running'; |
|
| 32 | + const STATUS_COMPLETE = 'complete'; |
|
| 33 | + const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | + const STATUS_FAILED = 'failed'; |
|
| 35 | + const STATUS_HELD = 'held'; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + private $task; |
|
| 39 | + /** @var int */ |
|
| 40 | + private $user; |
|
| 41 | + /** @var int */ |
|
| 42 | + private $request; |
|
| 43 | + /** @var int */ |
|
| 44 | + private $emailtemplate; |
|
| 45 | + /** @var string */ |
|
| 46 | + private $status; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $enqueue; |
|
| 49 | + /** @var string */ |
|
| 50 | + private $parameters; |
|
| 51 | + /** @var string */ |
|
| 52 | + private $error; |
|
| 53 | + /** @var int */ |
|
| 54 | + private $acknowledged; |
|
| 55 | + /** @var int */ |
|
| 56 | + private $parent; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * This feels like the least bad place to put this method. |
|
| 60 | + */ |
|
| 61 | + public static function getTaskDescriptions() { |
|
| 62 | + return array( |
|
| 63 | + BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | + UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | + WelcomeUserTask::class => 'Welcome user', |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | + * @return void |
|
| 72 | + * @throws Exception |
|
| 73 | + * @throws OptimisticLockFailedException |
|
| 74 | + */ |
|
| 75 | + public function save() |
|
| 76 | + { |
|
| 77 | + if ($this->isNew()) { |
|
| 78 | + // insert |
|
| 79 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 80 | 80 | INSERT INTO jobqueue (task, user, request, emailtemplate, parameters, parent) |
| 81 | 81 | VALUES (:task, :user, :request, :emailtemplate, :parameters, :parent) |
| 82 | 82 | SQL |
| 83 | - ); |
|
| 84 | - $statement->bindValue(":task", $this->task); |
|
| 85 | - $statement->bindValue(":user", $this->user); |
|
| 86 | - $statement->bindValue(":request", $this->request); |
|
| 87 | - $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | - $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | - $statement->bindValue(":parent", $this->parent); |
|
| 90 | - |
|
| 91 | - if ($statement->execute()) { |
|
| 92 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 95 | - throw new Exception($statement->errorInfo()); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - // update |
|
| 100 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 83 | + ); |
|
| 84 | + $statement->bindValue(":task", $this->task); |
|
| 85 | + $statement->bindValue(":user", $this->user); |
|
| 86 | + $statement->bindValue(":request", $this->request); |
|
| 87 | + $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | + $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | + $statement->bindValue(":parent", $this->parent); |
|
| 90 | + |
|
| 91 | + if ($statement->execute()) { |
|
| 92 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | + throw new Exception($statement->errorInfo()); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + // update |
|
| 100 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 101 | 101 | UPDATE jobqueue SET |
| 102 | 102 | status = :status |
| 103 | 103 | , error = :error |
@@ -105,187 +105,187 @@ discard block |
||
| 105 | 105 | , updateversion = updateversion + 1 |
| 106 | 106 | WHERE id = :id AND updateversion = :updateversion; |
| 107 | 107 | SQL |
| 108 | - ); |
|
| 109 | - |
|
| 110 | - $statement->bindValue(":id", $this->id); |
|
| 111 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | - |
|
| 113 | - $statement->bindValue(":status", $this->status); |
|
| 114 | - $statement->bindValue(":error", $this->error); |
|
| 115 | - $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | - |
|
| 117 | - if (!$statement->execute()) { |
|
| 118 | - throw new Exception($statement->errorInfo()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($statement->rowCount() !== 1) { |
|
| 122 | - throw new OptimisticLockFailedException(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $this->updateversion++; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - #region Properties |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function getTask() |
|
| 135 | - { |
|
| 136 | - return $this->task; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $task |
|
| 141 | - */ |
|
| 142 | - public function setTask($task) |
|
| 143 | - { |
|
| 144 | - $this->task = $task; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return int |
|
| 149 | - */ |
|
| 150 | - public function getTriggerUserId() |
|
| 151 | - { |
|
| 152 | - return $this->user; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param int $user |
|
| 157 | - */ |
|
| 158 | - public function setTriggerUserId($user) |
|
| 159 | - { |
|
| 160 | - $this->user = $user; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return int |
|
| 165 | - */ |
|
| 166 | - public function getRequest() |
|
| 167 | - { |
|
| 168 | - return $this->request; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param int $request |
|
| 173 | - */ |
|
| 174 | - public function setRequest($request) |
|
| 175 | - { |
|
| 176 | - $this->request = $request; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function getStatus() |
|
| 183 | - { |
|
| 184 | - return $this->status; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param string $status |
|
| 189 | - */ |
|
| 190 | - public function setStatus($status) |
|
| 191 | - { |
|
| 192 | - $this->status = $status; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public function getEnqueue() |
|
| 199 | - { |
|
| 200 | - return $this->enqueue; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param string $enqueue |
|
| 205 | - */ |
|
| 206 | - public function setEnqueue($enqueue) |
|
| 207 | - { |
|
| 208 | - $this->enqueue = $enqueue; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getParameters() |
|
| 215 | - { |
|
| 216 | - return $this->parameters; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param string $parameters |
|
| 221 | - */ |
|
| 222 | - public function setParameters($parameters) |
|
| 223 | - { |
|
| 224 | - $this->parameters = $parameters; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return mixed |
|
| 229 | - */ |
|
| 230 | - public function getError() |
|
| 231 | - { |
|
| 232 | - return $this->error; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param mixed $error |
|
| 237 | - */ |
|
| 238 | - public function setError($error) |
|
| 239 | - { |
|
| 240 | - $this->error = $error; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return int |
|
| 245 | - */ |
|
| 246 | - public function getAcknowledged() |
|
| 247 | - { |
|
| 248 | - return $this->acknowledged; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param int $acknowledged |
|
| 253 | - */ |
|
| 254 | - public function setAcknowledged($acknowledged) |
|
| 255 | - { |
|
| 256 | - $this->acknowledged = $acknowledged; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return int |
|
| 261 | - */ |
|
| 262 | - public function getParent() |
|
| 263 | - { |
|
| 264 | - return $this->parent; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param int $parent |
|
| 269 | - */ |
|
| 270 | - public function setParent($parent) |
|
| 271 | - { |
|
| 272 | - $this->parent = $parent; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return int |
|
| 277 | - */ |
|
| 278 | - public function getEmailTemplate() |
|
| 279 | - { |
|
| 280 | - return $this->emailtemplate; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param int $emailTemplate |
|
| 285 | - */ |
|
| 286 | - public function setEmailTemplate($emailTemplate) |
|
| 287 | - { |
|
| 288 | - $this->emailtemplate = $emailTemplate; |
|
| 289 | - } |
|
| 290 | - #endregion |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + $statement->bindValue(":id", $this->id); |
|
| 111 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | + |
|
| 113 | + $statement->bindValue(":status", $this->status); |
|
| 114 | + $statement->bindValue(":error", $this->error); |
|
| 115 | + $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | + |
|
| 117 | + if (!$statement->execute()) { |
|
| 118 | + throw new Exception($statement->errorInfo()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($statement->rowCount() !== 1) { |
|
| 122 | + throw new OptimisticLockFailedException(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $this->updateversion++; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + #region Properties |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function getTask() |
|
| 135 | + { |
|
| 136 | + return $this->task; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $task |
|
| 141 | + */ |
|
| 142 | + public function setTask($task) |
|
| 143 | + { |
|
| 144 | + $this->task = $task; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return int |
|
| 149 | + */ |
|
| 150 | + public function getTriggerUserId() |
|
| 151 | + { |
|
| 152 | + return $this->user; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param int $user |
|
| 157 | + */ |
|
| 158 | + public function setTriggerUserId($user) |
|
| 159 | + { |
|
| 160 | + $this->user = $user; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return int |
|
| 165 | + */ |
|
| 166 | + public function getRequest() |
|
| 167 | + { |
|
| 168 | + return $this->request; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param int $request |
|
| 173 | + */ |
|
| 174 | + public function setRequest($request) |
|
| 175 | + { |
|
| 176 | + $this->request = $request; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function getStatus() |
|
| 183 | + { |
|
| 184 | + return $this->status; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param string $status |
|
| 189 | + */ |
|
| 190 | + public function setStatus($status) |
|
| 191 | + { |
|
| 192 | + $this->status = $status; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public function getEnqueue() |
|
| 199 | + { |
|
| 200 | + return $this->enqueue; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param string $enqueue |
|
| 205 | + */ |
|
| 206 | + public function setEnqueue($enqueue) |
|
| 207 | + { |
|
| 208 | + $this->enqueue = $enqueue; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getParameters() |
|
| 215 | + { |
|
| 216 | + return $this->parameters; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param string $parameters |
|
| 221 | + */ |
|
| 222 | + public function setParameters($parameters) |
|
| 223 | + { |
|
| 224 | + $this->parameters = $parameters; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return mixed |
|
| 229 | + */ |
|
| 230 | + public function getError() |
|
| 231 | + { |
|
| 232 | + return $this->error; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param mixed $error |
|
| 237 | + */ |
|
| 238 | + public function setError($error) |
|
| 239 | + { |
|
| 240 | + $this->error = $error; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return int |
|
| 245 | + */ |
|
| 246 | + public function getAcknowledged() |
|
| 247 | + { |
|
| 248 | + return $this->acknowledged; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param int $acknowledged |
|
| 253 | + */ |
|
| 254 | + public function setAcknowledged($acknowledged) |
|
| 255 | + { |
|
| 256 | + $this->acknowledged = $acknowledged; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return int |
|
| 261 | + */ |
|
| 262 | + public function getParent() |
|
| 263 | + { |
|
| 264 | + return $this->parent; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param int $parent |
|
| 269 | + */ |
|
| 270 | + public function setParent($parent) |
|
| 271 | + { |
|
| 272 | + $this->parent = $parent; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return int |
|
| 277 | + */ |
|
| 278 | + public function getEmailTemplate() |
|
| 279 | + { |
|
| 280 | + return $this->emailtemplate; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param int $emailTemplate |
|
| 285 | + */ |
|
| 286 | + public function setEmailTemplate($emailTemplate) |
|
| 287 | + { |
|
| 288 | + $this->emailtemplate = $emailTemplate; |
|
| 289 | + } |
|
| 290 | + #endregion |
|
| 291 | 291 | } |
| 292 | 292 | \ No newline at end of file |
@@ -58,7 +58,8 @@ |
||
| 58 | 58 | /** |
| 59 | 59 | * This feels like the least bad place to put this method. |
| 60 | 60 | */ |
| 61 | - public static function getTaskDescriptions() { |
|
| 61 | + public static function getTaskDescriptions() |
|
| 62 | + { |
|
| 62 | 63 | return array( |
| 63 | 64 | BotCreationTask::class => 'Create account (via bot)', |
| 64 | 65 | UserCreationTask::class => 'Create account (via OAuth)', |
@@ -25,155 +25,155 @@ |
||
| 25 | 25 | |
| 26 | 26 | abstract class ApplicationBase |
| 27 | 27 | { |
| 28 | - private $configuration; |
|
| 29 | - |
|
| 30 | - public function __construct(SiteConfiguration $configuration) |
|
| 31 | - { |
|
| 32 | - $this->configuration = $configuration; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Application entry point. |
|
| 37 | - * |
|
| 38 | - * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
| 39 | - */ |
|
| 40 | - public function run() |
|
| 41 | - { |
|
| 42 | - try { |
|
| 43 | - if ($this->setupEnvironment()) { |
|
| 44 | - $this->main(); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - catch (Exception $ex) { |
|
| 48 | - print $ex->getMessage(); |
|
| 49 | - } |
|
| 50 | - finally { |
|
| 51 | - $this->cleanupEnvironment(); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Environment setup |
|
| 57 | - * |
|
| 58 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
| 59 | - * and shut down prematurely. |
|
| 60 | - * |
|
| 61 | - * @return bool |
|
| 62 | - * @throws EnvironmentException |
|
| 63 | - */ |
|
| 64 | - protected function setupEnvironment() |
|
| 65 | - { |
|
| 66 | - $this->setupDatabase(); |
|
| 67 | - |
|
| 68 | - return true; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return PdoDatabase |
|
| 73 | - * @throws EnvironmentException |
|
| 74 | - * @throws Exception |
|
| 75 | - */ |
|
| 76 | - protected function setupDatabase() |
|
| 77 | - { |
|
| 78 | - // check the schema version |
|
| 79 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
| 80 | - |
|
| 81 | - /** @var int $actualVersion */ |
|
| 82 | - $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
| 83 | - if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
| 84 | - throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $database; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return SiteConfiguration |
|
| 92 | - */ |
|
| 93 | - public function getConfiguration() |
|
| 94 | - { |
|
| 95 | - return $this->configuration; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Main application logic |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - abstract protected function main(); |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Any cleanup tasks should go here |
|
| 106 | - * |
|
| 107 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
| 108 | - * This should *only* be for cleaning up, no logic should go here. |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - abstract protected function cleanupEnvironment(); |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param ITask $page |
|
| 116 | - * @param SiteConfiguration $siteConfiguration |
|
| 117 | - * @param PdoDatabase $database |
|
| 118 | - * @param PdoDatabase $notificationsDatabase |
|
| 119 | - * |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - protected function setupHelpers( |
|
| 123 | - ITask $page, |
|
| 124 | - SiteConfiguration $siteConfiguration, |
|
| 125 | - PdoDatabase $database, |
|
| 126 | - PdoDatabase $notificationsDatabase = null |
|
| 127 | - ) { |
|
| 128 | - $page->setSiteConfiguration($siteConfiguration); |
|
| 129 | - |
|
| 130 | - // setup the global database object |
|
| 131 | - $page->setDatabase($database); |
|
| 132 | - |
|
| 133 | - // set up helpers and inject them into the page. |
|
| 134 | - $httpHelper = new HttpHelper( |
|
| 135 | - $siteConfiguration->getUserAgent(), |
|
| 136 | - $siteConfiguration->getCurlDisableVerifyPeer() |
|
| 137 | - ); |
|
| 138 | - |
|
| 139 | - $page->setEmailHelper(new EmailHelper()); |
|
| 140 | - $page->setHttpHelper($httpHelper); |
|
| 141 | - $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
| 142 | - |
|
| 143 | - if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
| 144 | - $page->setLocationProvider(new FakeLocationProvider()); |
|
| 145 | - } |
|
| 146 | - else { |
|
| 147 | - $page->setLocationProvider( |
|
| 148 | - new IpLocationProvider( |
|
| 149 | - $database, |
|
| 150 | - $siteConfiguration->getLocationProviderApiKey(), |
|
| 151 | - $httpHelper |
|
| 152 | - )); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
| 156 | - |
|
| 157 | - $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
| 158 | - |
|
| 159 | - $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
| 160 | - $database, |
|
| 161 | - $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 162 | - $httpHelper)); |
|
| 163 | - |
|
| 164 | - $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
| 165 | - $siteConfiguration->getOAuthBaseUrl(), |
|
| 166 | - $siteConfiguration->getOAuthConsumerToken(), |
|
| 167 | - $siteConfiguration->getOAuthConsumerSecret(), |
|
| 168 | - $httpHelper, |
|
| 169 | - $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
| 170 | - )); |
|
| 171 | - |
|
| 172 | - $page->setNotificationHelper(new IrcNotificationHelper( |
|
| 173 | - $siteConfiguration, |
|
| 174 | - $database, |
|
| 175 | - $notificationsDatabase)); |
|
| 176 | - |
|
| 177 | - $page->setTorExitProvider(new TorExitProvider($database)); |
|
| 178 | - } |
|
| 28 | + private $configuration; |
|
| 29 | + |
|
| 30 | + public function __construct(SiteConfiguration $configuration) |
|
| 31 | + { |
|
| 32 | + $this->configuration = $configuration; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Application entry point. |
|
| 37 | + * |
|
| 38 | + * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
| 39 | + */ |
|
| 40 | + public function run() |
|
| 41 | + { |
|
| 42 | + try { |
|
| 43 | + if ($this->setupEnvironment()) { |
|
| 44 | + $this->main(); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + catch (Exception $ex) { |
|
| 48 | + print $ex->getMessage(); |
|
| 49 | + } |
|
| 50 | + finally { |
|
| 51 | + $this->cleanupEnvironment(); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Environment setup |
|
| 57 | + * |
|
| 58 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
| 59 | + * and shut down prematurely. |
|
| 60 | + * |
|
| 61 | + * @return bool |
|
| 62 | + * @throws EnvironmentException |
|
| 63 | + */ |
|
| 64 | + protected function setupEnvironment() |
|
| 65 | + { |
|
| 66 | + $this->setupDatabase(); |
|
| 67 | + |
|
| 68 | + return true; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return PdoDatabase |
|
| 73 | + * @throws EnvironmentException |
|
| 74 | + * @throws Exception |
|
| 75 | + */ |
|
| 76 | + protected function setupDatabase() |
|
| 77 | + { |
|
| 78 | + // check the schema version |
|
| 79 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
| 80 | + |
|
| 81 | + /** @var int $actualVersion */ |
|
| 82 | + $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
| 83 | + if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
| 84 | + throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $database; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return SiteConfiguration |
|
| 92 | + */ |
|
| 93 | + public function getConfiguration() |
|
| 94 | + { |
|
| 95 | + return $this->configuration; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Main application logic |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + abstract protected function main(); |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Any cleanup tasks should go here |
|
| 106 | + * |
|
| 107 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
| 108 | + * This should *only* be for cleaning up, no logic should go here. |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + abstract protected function cleanupEnvironment(); |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param ITask $page |
|
| 116 | + * @param SiteConfiguration $siteConfiguration |
|
| 117 | + * @param PdoDatabase $database |
|
| 118 | + * @param PdoDatabase $notificationsDatabase |
|
| 119 | + * |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + protected function setupHelpers( |
|
| 123 | + ITask $page, |
|
| 124 | + SiteConfiguration $siteConfiguration, |
|
| 125 | + PdoDatabase $database, |
|
| 126 | + PdoDatabase $notificationsDatabase = null |
|
| 127 | + ) { |
|
| 128 | + $page->setSiteConfiguration($siteConfiguration); |
|
| 129 | + |
|
| 130 | + // setup the global database object |
|
| 131 | + $page->setDatabase($database); |
|
| 132 | + |
|
| 133 | + // set up helpers and inject them into the page. |
|
| 134 | + $httpHelper = new HttpHelper( |
|
| 135 | + $siteConfiguration->getUserAgent(), |
|
| 136 | + $siteConfiguration->getCurlDisableVerifyPeer() |
|
| 137 | + ); |
|
| 138 | + |
|
| 139 | + $page->setEmailHelper(new EmailHelper()); |
|
| 140 | + $page->setHttpHelper($httpHelper); |
|
| 141 | + $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
| 142 | + |
|
| 143 | + if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
| 144 | + $page->setLocationProvider(new FakeLocationProvider()); |
|
| 145 | + } |
|
| 146 | + else { |
|
| 147 | + $page->setLocationProvider( |
|
| 148 | + new IpLocationProvider( |
|
| 149 | + $database, |
|
| 150 | + $siteConfiguration->getLocationProviderApiKey(), |
|
| 151 | + $httpHelper |
|
| 152 | + )); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
| 156 | + |
|
| 157 | + $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
| 158 | + |
|
| 159 | + $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
| 160 | + $database, |
|
| 161 | + $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 162 | + $httpHelper)); |
|
| 163 | + |
|
| 164 | + $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
| 165 | + $siteConfiguration->getOAuthBaseUrl(), |
|
| 166 | + $siteConfiguration->getOAuthConsumerToken(), |
|
| 167 | + $siteConfiguration->getOAuthConsumerSecret(), |
|
| 168 | + $httpHelper, |
|
| 169 | + $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
| 170 | + )); |
|
| 171 | + |
|
| 172 | + $page->setNotificationHelper(new IrcNotificationHelper( |
|
| 173 | + $siteConfiguration, |
|
| 174 | + $database, |
|
| 175 | + $notificationsDatabase)); |
|
| 176 | + |
|
| 177 | + $page->setTorExitProvider(new TorExitProvider($database)); |
|
| 178 | + } |
|
| 179 | 179 | } |
| 180 | 180 | \ No newline at end of file |