@@ -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 |
@@ -59,415 +59,415 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class RequestRouter implements IRequestRouter |
| 61 | 61 | { |
| 62 | - /** |
|
| 63 | - * This is the core routing table for the application. The basic idea is: |
|
| 64 | - * |
|
| 65 | - * array( |
|
| 66 | - * "foo" => |
|
| 67 | - * array( |
|
| 68 | - * "class" => PageFoo::class, |
|
| 69 | - * "actions" => array("bar", "other") |
|
| 70 | - * ), |
|
| 71 | - * ); |
|
| 72 | - * |
|
| 73 | - * Things to note: |
|
| 74 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 75 | - * |
|
| 76 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 77 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 78 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 79 | - * method. |
|
| 80 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 81 | - * |
|
| 82 | - * - Query parameters are ignored. |
|
| 83 | - * |
|
| 84 | - * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 85 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 86 | - * before we start calling random methods through the web UI. |
|
| 87 | - * |
|
| 88 | - * Examples: |
|
| 89 | - * /internal.php => returns instance of PageMain, routed to main() |
|
| 90 | - * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 91 | - * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 92 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 93 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 94 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 95 | - * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 96 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 97 | - * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 98 | - * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 99 | - * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 100 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 101 | - * |
|
| 102 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 103 | - * to change the key, then you'll likely have to update a lot of files. |
|
| 104 | - * |
|
| 105 | - * @var array |
|
| 106 | - */ |
|
| 107 | - private $routeMap = array( |
|
| 108 | - |
|
| 109 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 | - // Login and registration |
|
| 111 | - 'logout' => |
|
| 112 | - array( |
|
| 113 | - 'class' => PageLogout::class, |
|
| 114 | - 'actions' => array(), |
|
| 115 | - ), |
|
| 116 | - 'login' => |
|
| 117 | - array( |
|
| 118 | - 'class' => PageLogin::class, |
|
| 119 | - 'actions' => array(), |
|
| 120 | - ), |
|
| 121 | - 'forgotPassword' => |
|
| 122 | - array( |
|
| 123 | - 'class' => PageForgotPassword::class, |
|
| 124 | - 'actions' => array('reset'), |
|
| 125 | - ), |
|
| 126 | - 'register' => |
|
| 127 | - array( |
|
| 128 | - 'class' => PageRegisterOption::class, |
|
| 129 | - 'actions' => array(), |
|
| 130 | - ), |
|
| 131 | - 'register/standard' => |
|
| 132 | - array( |
|
| 133 | - 'class' => PageRegisterStandard::class, |
|
| 134 | - 'actions' => array('done'), |
|
| 135 | - ), |
|
| 136 | - |
|
| 137 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 | - // Discovery |
|
| 139 | - 'search' => |
|
| 140 | - array( |
|
| 141 | - 'class' => PageSearch::class, |
|
| 142 | - 'actions' => array(), |
|
| 143 | - ), |
|
| 144 | - 'logs' => |
|
| 145 | - array( |
|
| 146 | - 'class' => PageLog::class, |
|
| 147 | - 'actions' => array(), |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 151 | - // Administration |
|
| 152 | - 'bans' => |
|
| 153 | - array( |
|
| 154 | - 'class' => PageBan::class, |
|
| 155 | - 'actions' => array('set', 'remove'), |
|
| 156 | - ), |
|
| 157 | - 'userManagement' => |
|
| 158 | - array( |
|
| 159 | - 'class' => PageUserManagement::class, |
|
| 160 | - 'actions' => array( |
|
| 161 | - 'approve', |
|
| 162 | - 'decline', |
|
| 163 | - 'rename', |
|
| 164 | - 'editUser', |
|
| 165 | - 'suspend', |
|
| 166 | - 'editRoles', |
|
| 167 | - ), |
|
| 168 | - ), |
|
| 169 | - 'siteNotice' => |
|
| 170 | - array( |
|
| 171 | - 'class' => PageSiteNotice::class, |
|
| 172 | - 'actions' => array(), |
|
| 173 | - ), |
|
| 174 | - 'emailManagement' => |
|
| 175 | - array( |
|
| 176 | - 'class' => PageEmailManagement::class, |
|
| 177 | - 'actions' => array('create', 'edit', 'view'), |
|
| 178 | - ), |
|
| 179 | - 'jobQueue' => |
|
| 180 | - array( |
|
| 181 | - 'class' => PageJobQueue::class, |
|
| 182 | - 'actions' => array('acknowledge', 'requeue', 'view', 'all'), |
|
| 183 | - ), |
|
| 184 | - |
|
| 185 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 | - // Personal preferences |
|
| 187 | - 'preferences' => |
|
| 188 | - array( |
|
| 189 | - 'class' => PagePreferences::class, |
|
| 190 | - 'actions' => array(), |
|
| 191 | - ), |
|
| 192 | - 'changePassword' => |
|
| 193 | - array( |
|
| 194 | - 'class' => PageChangePassword::class, |
|
| 195 | - 'actions' => array(), |
|
| 196 | - ), |
|
| 197 | - 'oauth' => |
|
| 198 | - array( |
|
| 199 | - 'class' => PageOAuth::class, |
|
| 200 | - 'actions' => array('detach', 'attach'), |
|
| 201 | - ), |
|
| 202 | - 'oauth/callback' => |
|
| 203 | - array( |
|
| 204 | - 'class' => PageOAuthCallback::class, |
|
| 205 | - 'actions' => array('authorise', 'create'), |
|
| 206 | - ), |
|
| 207 | - |
|
| 208 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 | - // Welcomer configuration |
|
| 210 | - 'welcomeTemplates' => |
|
| 211 | - array( |
|
| 212 | - 'class' => PageWelcomeTemplateManagement::class, |
|
| 213 | - 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 214 | - ), |
|
| 215 | - |
|
| 216 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 217 | - // Statistics |
|
| 218 | - 'statistics' => |
|
| 219 | - array( |
|
| 220 | - 'class' => StatsMain::class, |
|
| 221 | - 'actions' => array(), |
|
| 222 | - ), |
|
| 223 | - 'statistics/fastCloses' => |
|
| 224 | - array( |
|
| 225 | - 'class' => StatsFastCloses::class, |
|
| 226 | - 'actions' => array(), |
|
| 227 | - ), |
|
| 228 | - 'statistics/inactiveUsers' => |
|
| 229 | - array( |
|
| 230 | - 'class' => StatsInactiveUsers::class, |
|
| 231 | - 'actions' => array(), |
|
| 232 | - ), |
|
| 233 | - 'statistics/monthlyStats' => |
|
| 234 | - array( |
|
| 235 | - 'class' => StatsMonthlyStats::class, |
|
| 236 | - 'actions' => array(), |
|
| 237 | - ), |
|
| 238 | - 'statistics/reservedRequests' => |
|
| 239 | - array( |
|
| 240 | - 'class' => StatsReservedRequests::class, |
|
| 241 | - 'actions' => array(), |
|
| 242 | - ), |
|
| 243 | - 'statistics/templateStats' => |
|
| 244 | - array( |
|
| 245 | - 'class' => StatsTemplateStats::class, |
|
| 246 | - 'actions' => array(), |
|
| 247 | - ), |
|
| 248 | - 'statistics/topCreators' => |
|
| 249 | - array( |
|
| 250 | - 'class' => StatsTopCreators::class, |
|
| 251 | - 'actions' => array(), |
|
| 252 | - ), |
|
| 253 | - 'statistics/users' => |
|
| 254 | - array( |
|
| 255 | - 'class' => StatsUsers::class, |
|
| 256 | - 'actions' => array('detail'), |
|
| 257 | - ), |
|
| 258 | - |
|
| 259 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 260 | - // Zoom page |
|
| 261 | - 'viewRequest' => |
|
| 262 | - array( |
|
| 263 | - 'class' => PageViewRequest::class, |
|
| 264 | - 'actions' => array(), |
|
| 265 | - ), |
|
| 266 | - 'viewRequest/reserve' => |
|
| 267 | - array( |
|
| 268 | - 'class' => PageReservation::class, |
|
| 269 | - 'actions' => array(), |
|
| 270 | - ), |
|
| 271 | - 'viewRequest/breakReserve' => |
|
| 272 | - array( |
|
| 273 | - 'class' => PageBreakReservation::class, |
|
| 274 | - 'actions' => array(), |
|
| 275 | - ), |
|
| 276 | - 'viewRequest/defer' => |
|
| 277 | - array( |
|
| 278 | - 'class' => PageDeferRequest::class, |
|
| 279 | - 'actions' => array(), |
|
| 280 | - ), |
|
| 281 | - 'viewRequest/comment' => |
|
| 282 | - array( |
|
| 283 | - 'class' => PageComment::class, |
|
| 284 | - 'actions' => array(), |
|
| 285 | - ), |
|
| 286 | - 'viewRequest/sendToUser' => |
|
| 287 | - array( |
|
| 288 | - 'class' => PageSendToUser::class, |
|
| 289 | - 'actions' => array(), |
|
| 290 | - ), |
|
| 291 | - 'viewRequest/close' => |
|
| 292 | - array( |
|
| 293 | - 'class' => PageCloseRequest::class, |
|
| 294 | - 'actions' => array(), |
|
| 295 | - ), |
|
| 296 | - 'viewRequest/create' => |
|
| 297 | - array( |
|
| 298 | - 'class' => PageCreateRequest::class, |
|
| 299 | - 'actions' => array(), |
|
| 300 | - ), |
|
| 301 | - 'viewRequest/drop' => |
|
| 302 | - array( |
|
| 303 | - 'class' => PageDropRequest::class, |
|
| 304 | - 'actions' => array(), |
|
| 305 | - ), |
|
| 306 | - 'viewRequest/custom' => |
|
| 307 | - array( |
|
| 308 | - 'class' => PageCustomClose::class, |
|
| 309 | - 'actions' => array(), |
|
| 310 | - ), |
|
| 311 | - 'editComment' => |
|
| 312 | - array( |
|
| 313 | - 'class' => PageEditComment::class, |
|
| 314 | - 'actions' => array(), |
|
| 315 | - ), |
|
| 316 | - |
|
| 317 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 318 | - // Misc stuff |
|
| 319 | - 'team' => |
|
| 320 | - array( |
|
| 321 | - 'class' => PageTeam::class, |
|
| 322 | - 'actions' => array(), |
|
| 323 | - ), |
|
| 324 | - 'requestList' => |
|
| 325 | - array( |
|
| 326 | - 'class' => PageExpandedRequestList::class, |
|
| 327 | - 'actions' => array(), |
|
| 328 | - ), |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @return IRoutedTask |
|
| 333 | - * @throws Exception |
|
| 334 | - */ |
|
| 335 | - final public function route() |
|
| 336 | - { |
|
| 337 | - $pathInfo = WebRequest::pathInfo(); |
|
| 338 | - |
|
| 339 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 340 | - |
|
| 341 | - /** @var IRoutedTask $page */ |
|
| 342 | - $page = new $pageClass(); |
|
| 343 | - |
|
| 344 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 345 | - // let's use our own. |
|
| 346 | - if (!($page instanceof IRoutedTask)) { |
|
| 347 | - throw new Exception('Expected a page, but this is not a page.'); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 351 | - // inherits PageBase and has been created from the routing map. |
|
| 352 | - $page->setRoute($action); |
|
| 353 | - |
|
| 354 | - return $page; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * @param $pathInfo |
|
| 359 | - * |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - protected function getRouteFromPath($pathInfo) |
|
| 363 | - { |
|
| 364 | - if (count($pathInfo) === 0) { |
|
| 365 | - // No pathInfo, so no page to load. Load the main page. |
|
| 366 | - return $this->getDefaultRoute(); |
|
| 367 | - } |
|
| 368 | - elseif (count($pathInfo) === 1) { |
|
| 369 | - // Exactly one path info segment, it's got to be a page. |
|
| 370 | - $classSegment = $pathInfo[0]; |
|
| 371 | - |
|
| 372 | - return $this->routeSinglePathSegment($classSegment); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // OK, we have two or more segments now. |
|
| 376 | - if (count($pathInfo) > 2) { |
|
| 377 | - // Let's handle more than two, and collapse it down into two. |
|
| 378 | - $requestedAction = array_pop($pathInfo); |
|
| 379 | - $classSegment = implode('/', $pathInfo); |
|
| 380 | - } |
|
| 381 | - else { |
|
| 382 | - // Two path info segments. |
|
| 383 | - $classSegment = $pathInfo[0]; |
|
| 384 | - $requestedAction = $pathInfo[1]; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 388 | - |
|
| 389 | - if ($routeMap[0] === Page404::class) { |
|
| 390 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - return $routeMap; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * @param $classSegment |
|
| 398 | - * |
|
| 399 | - * @return array |
|
| 400 | - */ |
|
| 401 | - final protected function routeSinglePathSegment($classSegment) |
|
| 402 | - { |
|
| 403 | - $routeMap = $this->getRouteMap(); |
|
| 404 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 405 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 406 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 407 | - $action = 'main'; |
|
| 408 | - |
|
| 409 | - return array($pageClass, $action); |
|
| 410 | - } |
|
| 411 | - else { |
|
| 412 | - // Doesn't exist in map. Fall back to 404 |
|
| 413 | - $pageClass = Page404::class; |
|
| 414 | - $action = "main"; |
|
| 415 | - |
|
| 416 | - return array($pageClass, $action); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @param $classSegment |
|
| 422 | - * @param $requestedAction |
|
| 423 | - * |
|
| 424 | - * @return array |
|
| 425 | - */ |
|
| 426 | - final protected function routePathSegments($classSegment, $requestedAction) |
|
| 427 | - { |
|
| 428 | - $routeMap = $this->getRouteMap(); |
|
| 429 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 430 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 431 | - |
|
| 432 | - if (isset($routeMap[$classSegment]['actions']) |
|
| 433 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 434 | - ) { |
|
| 435 | - // Action exists in allowed action list. Allow both the page and the action |
|
| 436 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 437 | - $action = $requestedAction; |
|
| 438 | - |
|
| 439 | - return array($pageClass, $action); |
|
| 440 | - } |
|
| 441 | - else { |
|
| 442 | - // Valid page, invalid action. 404 our way out. |
|
| 443 | - $pageClass = Page404::class; |
|
| 444 | - $action = 'main'; |
|
| 445 | - |
|
| 446 | - return array($pageClass, $action); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - else { |
|
| 450 | - // Class doesn't exist in map. Fall back to 404 |
|
| 451 | - $pageClass = Page404::class; |
|
| 452 | - $action = 'main'; |
|
| 453 | - |
|
| 454 | - return array($pageClass, $action); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @return array |
|
| 460 | - */ |
|
| 461 | - protected function getRouteMap() |
|
| 462 | - { |
|
| 463 | - return $this->routeMap; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @return callable |
|
| 468 | - */ |
|
| 469 | - protected function getDefaultRoute() |
|
| 470 | - { |
|
| 471 | - return array(PageMain::class, "main"); |
|
| 472 | - } |
|
| 62 | + /** |
|
| 63 | + * This is the core routing table for the application. The basic idea is: |
|
| 64 | + * |
|
| 65 | + * array( |
|
| 66 | + * "foo" => |
|
| 67 | + * array( |
|
| 68 | + * "class" => PageFoo::class, |
|
| 69 | + * "actions" => array("bar", "other") |
|
| 70 | + * ), |
|
| 71 | + * ); |
|
| 72 | + * |
|
| 73 | + * Things to note: |
|
| 74 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 75 | + * |
|
| 76 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 77 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 78 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 79 | + * method. |
|
| 80 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 81 | + * |
|
| 82 | + * - Query parameters are ignored. |
|
| 83 | + * |
|
| 84 | + * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 85 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 86 | + * before we start calling random methods through the web UI. |
|
| 87 | + * |
|
| 88 | + * Examples: |
|
| 89 | + * /internal.php => returns instance of PageMain, routed to main() |
|
| 90 | + * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 91 | + * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 92 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 93 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 94 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 95 | + * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 96 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 97 | + * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 98 | + * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 99 | + * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 100 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 101 | + * |
|
| 102 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 103 | + * to change the key, then you'll likely have to update a lot of files. |
|
| 104 | + * |
|
| 105 | + * @var array |
|
| 106 | + */ |
|
| 107 | + private $routeMap = array( |
|
| 108 | + |
|
| 109 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 | + // Login and registration |
|
| 111 | + 'logout' => |
|
| 112 | + array( |
|
| 113 | + 'class' => PageLogout::class, |
|
| 114 | + 'actions' => array(), |
|
| 115 | + ), |
|
| 116 | + 'login' => |
|
| 117 | + array( |
|
| 118 | + 'class' => PageLogin::class, |
|
| 119 | + 'actions' => array(), |
|
| 120 | + ), |
|
| 121 | + 'forgotPassword' => |
|
| 122 | + array( |
|
| 123 | + 'class' => PageForgotPassword::class, |
|
| 124 | + 'actions' => array('reset'), |
|
| 125 | + ), |
|
| 126 | + 'register' => |
|
| 127 | + array( |
|
| 128 | + 'class' => PageRegisterOption::class, |
|
| 129 | + 'actions' => array(), |
|
| 130 | + ), |
|
| 131 | + 'register/standard' => |
|
| 132 | + array( |
|
| 133 | + 'class' => PageRegisterStandard::class, |
|
| 134 | + 'actions' => array('done'), |
|
| 135 | + ), |
|
| 136 | + |
|
| 137 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 | + // Discovery |
|
| 139 | + 'search' => |
|
| 140 | + array( |
|
| 141 | + 'class' => PageSearch::class, |
|
| 142 | + 'actions' => array(), |
|
| 143 | + ), |
|
| 144 | + 'logs' => |
|
| 145 | + array( |
|
| 146 | + 'class' => PageLog::class, |
|
| 147 | + 'actions' => array(), |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 151 | + // Administration |
|
| 152 | + 'bans' => |
|
| 153 | + array( |
|
| 154 | + 'class' => PageBan::class, |
|
| 155 | + 'actions' => array('set', 'remove'), |
|
| 156 | + ), |
|
| 157 | + 'userManagement' => |
|
| 158 | + array( |
|
| 159 | + 'class' => PageUserManagement::class, |
|
| 160 | + 'actions' => array( |
|
| 161 | + 'approve', |
|
| 162 | + 'decline', |
|
| 163 | + 'rename', |
|
| 164 | + 'editUser', |
|
| 165 | + 'suspend', |
|
| 166 | + 'editRoles', |
|
| 167 | + ), |
|
| 168 | + ), |
|
| 169 | + 'siteNotice' => |
|
| 170 | + array( |
|
| 171 | + 'class' => PageSiteNotice::class, |
|
| 172 | + 'actions' => array(), |
|
| 173 | + ), |
|
| 174 | + 'emailManagement' => |
|
| 175 | + array( |
|
| 176 | + 'class' => PageEmailManagement::class, |
|
| 177 | + 'actions' => array('create', 'edit', 'view'), |
|
| 178 | + ), |
|
| 179 | + 'jobQueue' => |
|
| 180 | + array( |
|
| 181 | + 'class' => PageJobQueue::class, |
|
| 182 | + 'actions' => array('acknowledge', 'requeue', 'view', 'all'), |
|
| 183 | + ), |
|
| 184 | + |
|
| 185 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 | + // Personal preferences |
|
| 187 | + 'preferences' => |
|
| 188 | + array( |
|
| 189 | + 'class' => PagePreferences::class, |
|
| 190 | + 'actions' => array(), |
|
| 191 | + ), |
|
| 192 | + 'changePassword' => |
|
| 193 | + array( |
|
| 194 | + 'class' => PageChangePassword::class, |
|
| 195 | + 'actions' => array(), |
|
| 196 | + ), |
|
| 197 | + 'oauth' => |
|
| 198 | + array( |
|
| 199 | + 'class' => PageOAuth::class, |
|
| 200 | + 'actions' => array('detach', 'attach'), |
|
| 201 | + ), |
|
| 202 | + 'oauth/callback' => |
|
| 203 | + array( |
|
| 204 | + 'class' => PageOAuthCallback::class, |
|
| 205 | + 'actions' => array('authorise', 'create'), |
|
| 206 | + ), |
|
| 207 | + |
|
| 208 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 | + // Welcomer configuration |
|
| 210 | + 'welcomeTemplates' => |
|
| 211 | + array( |
|
| 212 | + 'class' => PageWelcomeTemplateManagement::class, |
|
| 213 | + 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 214 | + ), |
|
| 215 | + |
|
| 216 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 217 | + // Statistics |
|
| 218 | + 'statistics' => |
|
| 219 | + array( |
|
| 220 | + 'class' => StatsMain::class, |
|
| 221 | + 'actions' => array(), |
|
| 222 | + ), |
|
| 223 | + 'statistics/fastCloses' => |
|
| 224 | + array( |
|
| 225 | + 'class' => StatsFastCloses::class, |
|
| 226 | + 'actions' => array(), |
|
| 227 | + ), |
|
| 228 | + 'statistics/inactiveUsers' => |
|
| 229 | + array( |
|
| 230 | + 'class' => StatsInactiveUsers::class, |
|
| 231 | + 'actions' => array(), |
|
| 232 | + ), |
|
| 233 | + 'statistics/monthlyStats' => |
|
| 234 | + array( |
|
| 235 | + 'class' => StatsMonthlyStats::class, |
|
| 236 | + 'actions' => array(), |
|
| 237 | + ), |
|
| 238 | + 'statistics/reservedRequests' => |
|
| 239 | + array( |
|
| 240 | + 'class' => StatsReservedRequests::class, |
|
| 241 | + 'actions' => array(), |
|
| 242 | + ), |
|
| 243 | + 'statistics/templateStats' => |
|
| 244 | + array( |
|
| 245 | + 'class' => StatsTemplateStats::class, |
|
| 246 | + 'actions' => array(), |
|
| 247 | + ), |
|
| 248 | + 'statistics/topCreators' => |
|
| 249 | + array( |
|
| 250 | + 'class' => StatsTopCreators::class, |
|
| 251 | + 'actions' => array(), |
|
| 252 | + ), |
|
| 253 | + 'statistics/users' => |
|
| 254 | + array( |
|
| 255 | + 'class' => StatsUsers::class, |
|
| 256 | + 'actions' => array('detail'), |
|
| 257 | + ), |
|
| 258 | + |
|
| 259 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 260 | + // Zoom page |
|
| 261 | + 'viewRequest' => |
|
| 262 | + array( |
|
| 263 | + 'class' => PageViewRequest::class, |
|
| 264 | + 'actions' => array(), |
|
| 265 | + ), |
|
| 266 | + 'viewRequest/reserve' => |
|
| 267 | + array( |
|
| 268 | + 'class' => PageReservation::class, |
|
| 269 | + 'actions' => array(), |
|
| 270 | + ), |
|
| 271 | + 'viewRequest/breakReserve' => |
|
| 272 | + array( |
|
| 273 | + 'class' => PageBreakReservation::class, |
|
| 274 | + 'actions' => array(), |
|
| 275 | + ), |
|
| 276 | + 'viewRequest/defer' => |
|
| 277 | + array( |
|
| 278 | + 'class' => PageDeferRequest::class, |
|
| 279 | + 'actions' => array(), |
|
| 280 | + ), |
|
| 281 | + 'viewRequest/comment' => |
|
| 282 | + array( |
|
| 283 | + 'class' => PageComment::class, |
|
| 284 | + 'actions' => array(), |
|
| 285 | + ), |
|
| 286 | + 'viewRequest/sendToUser' => |
|
| 287 | + array( |
|
| 288 | + 'class' => PageSendToUser::class, |
|
| 289 | + 'actions' => array(), |
|
| 290 | + ), |
|
| 291 | + 'viewRequest/close' => |
|
| 292 | + array( |
|
| 293 | + 'class' => PageCloseRequest::class, |
|
| 294 | + 'actions' => array(), |
|
| 295 | + ), |
|
| 296 | + 'viewRequest/create' => |
|
| 297 | + array( |
|
| 298 | + 'class' => PageCreateRequest::class, |
|
| 299 | + 'actions' => array(), |
|
| 300 | + ), |
|
| 301 | + 'viewRequest/drop' => |
|
| 302 | + array( |
|
| 303 | + 'class' => PageDropRequest::class, |
|
| 304 | + 'actions' => array(), |
|
| 305 | + ), |
|
| 306 | + 'viewRequest/custom' => |
|
| 307 | + array( |
|
| 308 | + 'class' => PageCustomClose::class, |
|
| 309 | + 'actions' => array(), |
|
| 310 | + ), |
|
| 311 | + 'editComment' => |
|
| 312 | + array( |
|
| 313 | + 'class' => PageEditComment::class, |
|
| 314 | + 'actions' => array(), |
|
| 315 | + ), |
|
| 316 | + |
|
| 317 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 318 | + // Misc stuff |
|
| 319 | + 'team' => |
|
| 320 | + array( |
|
| 321 | + 'class' => PageTeam::class, |
|
| 322 | + 'actions' => array(), |
|
| 323 | + ), |
|
| 324 | + 'requestList' => |
|
| 325 | + array( |
|
| 326 | + 'class' => PageExpandedRequestList::class, |
|
| 327 | + 'actions' => array(), |
|
| 328 | + ), |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @return IRoutedTask |
|
| 333 | + * @throws Exception |
|
| 334 | + */ |
|
| 335 | + final public function route() |
|
| 336 | + { |
|
| 337 | + $pathInfo = WebRequest::pathInfo(); |
|
| 338 | + |
|
| 339 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 340 | + |
|
| 341 | + /** @var IRoutedTask $page */ |
|
| 342 | + $page = new $pageClass(); |
|
| 343 | + |
|
| 344 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 345 | + // let's use our own. |
|
| 346 | + if (!($page instanceof IRoutedTask)) { |
|
| 347 | + throw new Exception('Expected a page, but this is not a page.'); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 351 | + // inherits PageBase and has been created from the routing map. |
|
| 352 | + $page->setRoute($action); |
|
| 353 | + |
|
| 354 | + return $page; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * @param $pathInfo |
|
| 359 | + * |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + protected function getRouteFromPath($pathInfo) |
|
| 363 | + { |
|
| 364 | + if (count($pathInfo) === 0) { |
|
| 365 | + // No pathInfo, so no page to load. Load the main page. |
|
| 366 | + return $this->getDefaultRoute(); |
|
| 367 | + } |
|
| 368 | + elseif (count($pathInfo) === 1) { |
|
| 369 | + // Exactly one path info segment, it's got to be a page. |
|
| 370 | + $classSegment = $pathInfo[0]; |
|
| 371 | + |
|
| 372 | + return $this->routeSinglePathSegment($classSegment); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // OK, we have two or more segments now. |
|
| 376 | + if (count($pathInfo) > 2) { |
|
| 377 | + // Let's handle more than two, and collapse it down into two. |
|
| 378 | + $requestedAction = array_pop($pathInfo); |
|
| 379 | + $classSegment = implode('/', $pathInfo); |
|
| 380 | + } |
|
| 381 | + else { |
|
| 382 | + // Two path info segments. |
|
| 383 | + $classSegment = $pathInfo[0]; |
|
| 384 | + $requestedAction = $pathInfo[1]; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 388 | + |
|
| 389 | + if ($routeMap[0] === Page404::class) { |
|
| 390 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + return $routeMap; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * @param $classSegment |
|
| 398 | + * |
|
| 399 | + * @return array |
|
| 400 | + */ |
|
| 401 | + final protected function routeSinglePathSegment($classSegment) |
|
| 402 | + { |
|
| 403 | + $routeMap = $this->getRouteMap(); |
|
| 404 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 405 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 406 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 407 | + $action = 'main'; |
|
| 408 | + |
|
| 409 | + return array($pageClass, $action); |
|
| 410 | + } |
|
| 411 | + else { |
|
| 412 | + // Doesn't exist in map. Fall back to 404 |
|
| 413 | + $pageClass = Page404::class; |
|
| 414 | + $action = "main"; |
|
| 415 | + |
|
| 416 | + return array($pageClass, $action); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @param $classSegment |
|
| 422 | + * @param $requestedAction |
|
| 423 | + * |
|
| 424 | + * @return array |
|
| 425 | + */ |
|
| 426 | + final protected function routePathSegments($classSegment, $requestedAction) |
|
| 427 | + { |
|
| 428 | + $routeMap = $this->getRouteMap(); |
|
| 429 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 430 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 431 | + |
|
| 432 | + if (isset($routeMap[$classSegment]['actions']) |
|
| 433 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 434 | + ) { |
|
| 435 | + // Action exists in allowed action list. Allow both the page and the action |
|
| 436 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 437 | + $action = $requestedAction; |
|
| 438 | + |
|
| 439 | + return array($pageClass, $action); |
|
| 440 | + } |
|
| 441 | + else { |
|
| 442 | + // Valid page, invalid action. 404 our way out. |
|
| 443 | + $pageClass = Page404::class; |
|
| 444 | + $action = 'main'; |
|
| 445 | + |
|
| 446 | + return array($pageClass, $action); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + else { |
|
| 450 | + // Class doesn't exist in map. Fall back to 404 |
|
| 451 | + $pageClass = Page404::class; |
|
| 452 | + $action = 'main'; |
|
| 453 | + |
|
| 454 | + return array($pageClass, $action); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @return array |
|
| 460 | + */ |
|
| 461 | + protected function getRouteMap() |
|
| 462 | + { |
|
| 463 | + return $this->routeMap; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @return callable |
|
| 468 | + */ |
|
| 469 | + protected function getDefaultRoute() |
|
| 470 | + { |
|
| 471 | + return array(PageMain::class, "main"); |
|
| 472 | + } |
|
| 473 | 473 | } |
@@ -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 |
@@ -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 |
@@ -21,353 +21,353 @@ |
||
| 21 | 21 | |
| 22 | 22 | abstract class PageBase extends TaskBase implements IRoutedTask |
| 23 | 23 | { |
| 24 | - use TemplateOutput; |
|
| 25 | - /** @var string Smarty template to display */ |
|
| 26 | - protected $template = "base.tpl"; |
|
| 27 | - /** @var string HTML title. Currently unused. */ |
|
| 28 | - protected $htmlTitle; |
|
| 29 | - /** @var bool Determines if the page is a redirect or not */ |
|
| 30 | - protected $isRedirecting = false; |
|
| 31 | - /** @var array Queue of headers to be sent on successful completion */ |
|
| 32 | - protected $headerQueue = array(); |
|
| 33 | - /** @var string The name of the route to use, as determined by the request router. */ |
|
| 34 | - private $routeName = null; |
|
| 35 | - /** @var TokenManager */ |
|
| 36 | - protected $tokenManager; |
|
| 37 | - /** @var string[] Extra CSS files to include */ |
|
| 38 | - private $extraCss = array(); |
|
| 39 | - /** @var string[] Extra JS files to include */ |
|
| 40 | - private $extraJs = array(); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
| 44 | - * |
|
| 45 | - * @param string $routeName The name of the route |
|
| 46 | - * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
| 47 | - * |
|
| 48 | - * @throws Exception |
|
| 49 | - * @category Security-Critical |
|
| 50 | - */ |
|
| 51 | - final public function setRoute($routeName, $skipCallableTest = false) |
|
| 52 | - { |
|
| 53 | - // Test the new route is callable before adopting it. |
|
| 54 | - if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
| 55 | - throw new Exception("Proposed route '$routeName' is not callable."); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // Adopt the new route |
|
| 59 | - $this->routeName = $routeName; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Gets the name of the route that has been passed from the request router. |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - final public function getRouteName() |
|
| 67 | - { |
|
| 68 | - return $this->routeName; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Performs generic page setup actions |
|
| 73 | - */ |
|
| 74 | - final protected function setupPage() |
|
| 75 | - { |
|
| 76 | - $this->setUpSmarty(); |
|
| 77 | - |
|
| 78 | - $siteNoticeText = SiteNotice::get($this->getDatabase()); |
|
| 79 | - |
|
| 80 | - $this->assign('siteNoticeText', $siteNoticeText); |
|
| 81 | - |
|
| 82 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 83 | - $this->assign('currentUser', $currentUser); |
|
| 84 | - $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Runs the page logic as routed by the RequestRouter |
|
| 89 | - * |
|
| 90 | - * Only should be called after a security barrier! That means only from execute(). |
|
| 91 | - */ |
|
| 92 | - final protected function runPage() |
|
| 93 | - { |
|
| 94 | - $database = $this->getDatabase(); |
|
| 95 | - |
|
| 96 | - // initialise a database transaction |
|
| 97 | - if (!$database->beginTransaction()) { |
|
| 98 | - throw new Exception('Failed to start transaction on primary database.'); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - try { |
|
| 102 | - // run the page code |
|
| 103 | - $this->{$this->getRouteName()}(); |
|
| 104 | - |
|
| 105 | - $database->commit(); |
|
| 106 | - } |
|
| 107 | - catch (ApplicationLogicException $ex) { |
|
| 108 | - // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
| 109 | - // standard templating system for this. |
|
| 110 | - |
|
| 111 | - // Firstly, let's undo anything that happened to the database. |
|
| 112 | - $database->rollBack(); |
|
| 113 | - |
|
| 114 | - // Reset smarty |
|
| 115 | - $this->setUpSmarty(); |
|
| 116 | - |
|
| 117 | - // Set the template |
|
| 118 | - $this->setTemplate('exception/application-logic.tpl'); |
|
| 119 | - $this->assign('message', $ex->getMessage()); |
|
| 120 | - |
|
| 121 | - // Force this back to false |
|
| 122 | - $this->isRedirecting = false; |
|
| 123 | - $this->headerQueue = array(); |
|
| 124 | - } |
|
| 125 | - catch (OptimisticLockFailedException $ex) { |
|
| 126 | - // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
| 127 | - // standard templating system for this. |
|
| 128 | - |
|
| 129 | - // Firstly, let's undo anything that happened to the database. |
|
| 130 | - $database->rollBack(); |
|
| 131 | - |
|
| 132 | - // Reset smarty |
|
| 133 | - $this->setUpSmarty(); |
|
| 134 | - |
|
| 135 | - // Set the template |
|
| 136 | - $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
| 137 | - $this->assign('message', $ex->getMessage()); |
|
| 138 | - |
|
| 139 | - $this->assign('debugTrace', false); |
|
| 140 | - |
|
| 141 | - if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 142 | - ob_start(); |
|
| 143 | - var_dump(ExceptionHandler::getExceptionData($ex)); |
|
| 144 | - $textErrorData = ob_get_contents(); |
|
| 145 | - ob_end_clean(); |
|
| 146 | - |
|
| 147 | - $this->assign('exceptionData', $textErrorData); |
|
| 148 | - $this->assign('debugTrace', true); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Force this back to false |
|
| 152 | - $this->isRedirecting = false; |
|
| 153 | - $this->headerQueue = array(); |
|
| 154 | - } |
|
| 155 | - finally { |
|
| 156 | - // Catch any hanging on transactions |
|
| 157 | - if ($database->hasActiveTransaction()) { |
|
| 158 | - $database->rollBack(); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // run any finalisation code needed before we send the output to the browser. |
|
| 163 | - $this->finalisePage(); |
|
| 164 | - |
|
| 165 | - // Send the headers |
|
| 166 | - $this->sendResponseHeaders(); |
|
| 167 | - |
|
| 168 | - // Check we have a template to use! |
|
| 169 | - if ($this->template !== null) { |
|
| 170 | - $content = $this->fetchTemplate($this->template); |
|
| 171 | - ob_clean(); |
|
| 172 | - print($content); |
|
| 173 | - ob_flush(); |
|
| 174 | - |
|
| 175 | - return; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Performs final tasks needed before rendering the page. |
|
| 181 | - */ |
|
| 182 | - protected function finalisePage() |
|
| 183 | - { |
|
| 184 | - if ($this->isRedirecting) { |
|
| 185 | - $this->template = null; |
|
| 186 | - |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $this->assign('extraCss', $this->extraCss); |
|
| 191 | - $this->assign('extraJs', $this->extraJs); |
|
| 192 | - |
|
| 193 | - // If we're actually displaying content, we want to add the session alerts here! |
|
| 194 | - $this->assign('alerts', SessionAlert::getAlerts()); |
|
| 195 | - SessionAlert::clearAlerts(); |
|
| 196 | - |
|
| 197 | - $this->assign('htmlTitle', $this->htmlTitle); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @return TokenManager |
|
| 202 | - */ |
|
| 203 | - public function getTokenManager() |
|
| 204 | - { |
|
| 205 | - return $this->tokenManager; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param TokenManager $tokenManager |
|
| 210 | - */ |
|
| 211 | - public function setTokenManager($tokenManager) |
|
| 212 | - { |
|
| 213 | - $this->tokenManager = $tokenManager; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Sends the redirect headers to perform a GET at the destination page. |
|
| 218 | - * |
|
| 219 | - * Also nullifies the set template so Smarty does not render it. |
|
| 220 | - * |
|
| 221 | - * @param string $page The page to redirect requests to (as used in the UR) |
|
| 222 | - * @param null|string $action The action to use on the page. |
|
| 223 | - * @param null|array $parameters |
|
| 224 | - * @param null|string $script The script (relative to index.php) to redirect to |
|
| 225 | - */ |
|
| 226 | - final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
| 227 | - { |
|
| 228 | - $currentScriptName = WebRequest::scriptName(); |
|
| 229 | - |
|
| 230 | - // Are we changing script? |
|
| 231 | - if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
| 232 | - $targetScriptName = $currentScriptName; |
|
| 233 | - } |
|
| 234 | - else { |
|
| 235 | - $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $pathInfo = array($targetScriptName); |
|
| 239 | - |
|
| 240 | - $pathInfo[1] = $page; |
|
| 241 | - |
|
| 242 | - if ($action !== null) { |
|
| 243 | - $pathInfo[2] = $action; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $url = implode('/', $pathInfo); |
|
| 247 | - |
|
| 248 | - if (is_array($parameters) && count($parameters) > 0) { |
|
| 249 | - $url .= '?' . http_build_query($parameters); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $this->redirectUrl($url); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Sends the redirect headers to perform a GET at the new address. |
|
| 257 | - * |
|
| 258 | - * Also nullifies the set template so Smarty does not render it. |
|
| 259 | - * |
|
| 260 | - * @param string $path URL to redirect to |
|
| 261 | - */ |
|
| 262 | - final protected function redirectUrl($path) |
|
| 263 | - { |
|
| 264 | - // 303 See Other = re-request at new address with a GET. |
|
| 265 | - $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
| 266 | - $this->headerQueue[] = "Location: $path"; |
|
| 267 | - |
|
| 268 | - $this->setTemplate(null); |
|
| 269 | - $this->isRedirecting = true; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Sets the name of the template this page should display. |
|
| 274 | - * |
|
| 275 | - * @param string $name |
|
| 276 | - * |
|
| 277 | - * @throws Exception |
|
| 278 | - */ |
|
| 279 | - final protected function setTemplate($name) |
|
| 280 | - { |
|
| 281 | - if ($this->isRedirecting) { |
|
| 282 | - throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $this->template = $name; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Adds an extra CSS file to to the page |
|
| 290 | - * |
|
| 291 | - * @param string $path The path (relative to the application root) of the file |
|
| 292 | - */ |
|
| 293 | - final protected function addCss($path) { |
|
| 294 | - if(in_array($path, $this->extraCss)){ |
|
| 295 | - // nothing to do |
|
| 296 | - return; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->extraCss[] = $path; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Adds an extra JS file to to the page |
|
| 304 | - * |
|
| 305 | - * @param string $path The path (relative to the application root) of the file |
|
| 306 | - */ |
|
| 307 | - final protected function addJs($path){ |
|
| 308 | - if(in_array($path, $this->extraJs)){ |
|
| 309 | - // nothing to do |
|
| 310 | - return; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $this->extraJs[] = $path; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Main function for this page, when no specific actions are called. |
|
| 318 | - * @return void |
|
| 319 | - */ |
|
| 320 | - abstract protected function main(); |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @param string $title |
|
| 324 | - */ |
|
| 325 | - final protected function setHtmlTitle($title) |
|
| 326 | - { |
|
| 327 | - $this->htmlTitle = $title; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public function execute() |
|
| 331 | - { |
|
| 332 | - if ($this->getRouteName() === null) { |
|
| 333 | - throw new Exception('Request is unrouted.'); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($this->getSiteConfiguration() === null) { |
|
| 337 | - throw new Exception('Page has no configuration!'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $this->setupPage(); |
|
| 341 | - |
|
| 342 | - $this->runPage(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - public function assignCSRFToken() |
|
| 346 | - { |
|
| 347 | - $token = $this->tokenManager->getNewToken(); |
|
| 348 | - $this->assign('csrfTokenData', $token->getTokenData()); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - public function validateCSRFToken() |
|
| 352 | - { |
|
| 353 | - if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
| 354 | - throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - protected function sendResponseHeaders() |
|
| 359 | - { |
|
| 360 | - if (headers_sent()) { |
|
| 361 | - throw new ApplicationLogicException ('Headers have already been sent! This is likely a bug in the application.'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - foreach ($this->headerQueue as $item) { |
|
| 365 | - if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
| 366 | - // Oops. We're not allowed to do this. |
|
| 367 | - throw new Exception('Unable to split header'); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - header($item); |
|
| 371 | - } |
|
| 372 | - } |
|
| 24 | + use TemplateOutput; |
|
| 25 | + /** @var string Smarty template to display */ |
|
| 26 | + protected $template = "base.tpl"; |
|
| 27 | + /** @var string HTML title. Currently unused. */ |
|
| 28 | + protected $htmlTitle; |
|
| 29 | + /** @var bool Determines if the page is a redirect or not */ |
|
| 30 | + protected $isRedirecting = false; |
|
| 31 | + /** @var array Queue of headers to be sent on successful completion */ |
|
| 32 | + protected $headerQueue = array(); |
|
| 33 | + /** @var string The name of the route to use, as determined by the request router. */ |
|
| 34 | + private $routeName = null; |
|
| 35 | + /** @var TokenManager */ |
|
| 36 | + protected $tokenManager; |
|
| 37 | + /** @var string[] Extra CSS files to include */ |
|
| 38 | + private $extraCss = array(); |
|
| 39 | + /** @var string[] Extra JS files to include */ |
|
| 40 | + private $extraJs = array(); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
| 44 | + * |
|
| 45 | + * @param string $routeName The name of the route |
|
| 46 | + * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
| 47 | + * |
|
| 48 | + * @throws Exception |
|
| 49 | + * @category Security-Critical |
|
| 50 | + */ |
|
| 51 | + final public function setRoute($routeName, $skipCallableTest = false) |
|
| 52 | + { |
|
| 53 | + // Test the new route is callable before adopting it. |
|
| 54 | + if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
| 55 | + throw new Exception("Proposed route '$routeName' is not callable."); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // Adopt the new route |
|
| 59 | + $this->routeName = $routeName; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Gets the name of the route that has been passed from the request router. |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + final public function getRouteName() |
|
| 67 | + { |
|
| 68 | + return $this->routeName; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Performs generic page setup actions |
|
| 73 | + */ |
|
| 74 | + final protected function setupPage() |
|
| 75 | + { |
|
| 76 | + $this->setUpSmarty(); |
|
| 77 | + |
|
| 78 | + $siteNoticeText = SiteNotice::get($this->getDatabase()); |
|
| 79 | + |
|
| 80 | + $this->assign('siteNoticeText', $siteNoticeText); |
|
| 81 | + |
|
| 82 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 83 | + $this->assign('currentUser', $currentUser); |
|
| 84 | + $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Runs the page logic as routed by the RequestRouter |
|
| 89 | + * |
|
| 90 | + * Only should be called after a security barrier! That means only from execute(). |
|
| 91 | + */ |
|
| 92 | + final protected function runPage() |
|
| 93 | + { |
|
| 94 | + $database = $this->getDatabase(); |
|
| 95 | + |
|
| 96 | + // initialise a database transaction |
|
| 97 | + if (!$database->beginTransaction()) { |
|
| 98 | + throw new Exception('Failed to start transaction on primary database.'); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + try { |
|
| 102 | + // run the page code |
|
| 103 | + $this->{$this->getRouteName()}(); |
|
| 104 | + |
|
| 105 | + $database->commit(); |
|
| 106 | + } |
|
| 107 | + catch (ApplicationLogicException $ex) { |
|
| 108 | + // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
| 109 | + // standard templating system for this. |
|
| 110 | + |
|
| 111 | + // Firstly, let's undo anything that happened to the database. |
|
| 112 | + $database->rollBack(); |
|
| 113 | + |
|
| 114 | + // Reset smarty |
|
| 115 | + $this->setUpSmarty(); |
|
| 116 | + |
|
| 117 | + // Set the template |
|
| 118 | + $this->setTemplate('exception/application-logic.tpl'); |
|
| 119 | + $this->assign('message', $ex->getMessage()); |
|
| 120 | + |
|
| 121 | + // Force this back to false |
|
| 122 | + $this->isRedirecting = false; |
|
| 123 | + $this->headerQueue = array(); |
|
| 124 | + } |
|
| 125 | + catch (OptimisticLockFailedException $ex) { |
|
| 126 | + // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
| 127 | + // standard templating system for this. |
|
| 128 | + |
|
| 129 | + // Firstly, let's undo anything that happened to the database. |
|
| 130 | + $database->rollBack(); |
|
| 131 | + |
|
| 132 | + // Reset smarty |
|
| 133 | + $this->setUpSmarty(); |
|
| 134 | + |
|
| 135 | + // Set the template |
|
| 136 | + $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
| 137 | + $this->assign('message', $ex->getMessage()); |
|
| 138 | + |
|
| 139 | + $this->assign('debugTrace', false); |
|
| 140 | + |
|
| 141 | + if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 142 | + ob_start(); |
|
| 143 | + var_dump(ExceptionHandler::getExceptionData($ex)); |
|
| 144 | + $textErrorData = ob_get_contents(); |
|
| 145 | + ob_end_clean(); |
|
| 146 | + |
|
| 147 | + $this->assign('exceptionData', $textErrorData); |
|
| 148 | + $this->assign('debugTrace', true); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Force this back to false |
|
| 152 | + $this->isRedirecting = false; |
|
| 153 | + $this->headerQueue = array(); |
|
| 154 | + } |
|
| 155 | + finally { |
|
| 156 | + // Catch any hanging on transactions |
|
| 157 | + if ($database->hasActiveTransaction()) { |
|
| 158 | + $database->rollBack(); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // run any finalisation code needed before we send the output to the browser. |
|
| 163 | + $this->finalisePage(); |
|
| 164 | + |
|
| 165 | + // Send the headers |
|
| 166 | + $this->sendResponseHeaders(); |
|
| 167 | + |
|
| 168 | + // Check we have a template to use! |
|
| 169 | + if ($this->template !== null) { |
|
| 170 | + $content = $this->fetchTemplate($this->template); |
|
| 171 | + ob_clean(); |
|
| 172 | + print($content); |
|
| 173 | + ob_flush(); |
|
| 174 | + |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Performs final tasks needed before rendering the page. |
|
| 181 | + */ |
|
| 182 | + protected function finalisePage() |
|
| 183 | + { |
|
| 184 | + if ($this->isRedirecting) { |
|
| 185 | + $this->template = null; |
|
| 186 | + |
|
| 187 | + return; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $this->assign('extraCss', $this->extraCss); |
|
| 191 | + $this->assign('extraJs', $this->extraJs); |
|
| 192 | + |
|
| 193 | + // If we're actually displaying content, we want to add the session alerts here! |
|
| 194 | + $this->assign('alerts', SessionAlert::getAlerts()); |
|
| 195 | + SessionAlert::clearAlerts(); |
|
| 196 | + |
|
| 197 | + $this->assign('htmlTitle', $this->htmlTitle); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @return TokenManager |
|
| 202 | + */ |
|
| 203 | + public function getTokenManager() |
|
| 204 | + { |
|
| 205 | + return $this->tokenManager; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param TokenManager $tokenManager |
|
| 210 | + */ |
|
| 211 | + public function setTokenManager($tokenManager) |
|
| 212 | + { |
|
| 213 | + $this->tokenManager = $tokenManager; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Sends the redirect headers to perform a GET at the destination page. |
|
| 218 | + * |
|
| 219 | + * Also nullifies the set template so Smarty does not render it. |
|
| 220 | + * |
|
| 221 | + * @param string $page The page to redirect requests to (as used in the UR) |
|
| 222 | + * @param null|string $action The action to use on the page. |
|
| 223 | + * @param null|array $parameters |
|
| 224 | + * @param null|string $script The script (relative to index.php) to redirect to |
|
| 225 | + */ |
|
| 226 | + final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
| 227 | + { |
|
| 228 | + $currentScriptName = WebRequest::scriptName(); |
|
| 229 | + |
|
| 230 | + // Are we changing script? |
|
| 231 | + if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
| 232 | + $targetScriptName = $currentScriptName; |
|
| 233 | + } |
|
| 234 | + else { |
|
| 235 | + $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $pathInfo = array($targetScriptName); |
|
| 239 | + |
|
| 240 | + $pathInfo[1] = $page; |
|
| 241 | + |
|
| 242 | + if ($action !== null) { |
|
| 243 | + $pathInfo[2] = $action; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $url = implode('/', $pathInfo); |
|
| 247 | + |
|
| 248 | + if (is_array($parameters) && count($parameters) > 0) { |
|
| 249 | + $url .= '?' . http_build_query($parameters); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $this->redirectUrl($url); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Sends the redirect headers to perform a GET at the new address. |
|
| 257 | + * |
|
| 258 | + * Also nullifies the set template so Smarty does not render it. |
|
| 259 | + * |
|
| 260 | + * @param string $path URL to redirect to |
|
| 261 | + */ |
|
| 262 | + final protected function redirectUrl($path) |
|
| 263 | + { |
|
| 264 | + // 303 See Other = re-request at new address with a GET. |
|
| 265 | + $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
| 266 | + $this->headerQueue[] = "Location: $path"; |
|
| 267 | + |
|
| 268 | + $this->setTemplate(null); |
|
| 269 | + $this->isRedirecting = true; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Sets the name of the template this page should display. |
|
| 274 | + * |
|
| 275 | + * @param string $name |
|
| 276 | + * |
|
| 277 | + * @throws Exception |
|
| 278 | + */ |
|
| 279 | + final protected function setTemplate($name) |
|
| 280 | + { |
|
| 281 | + if ($this->isRedirecting) { |
|
| 282 | + throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $this->template = $name; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Adds an extra CSS file to to the page |
|
| 290 | + * |
|
| 291 | + * @param string $path The path (relative to the application root) of the file |
|
| 292 | + */ |
|
| 293 | + final protected function addCss($path) { |
|
| 294 | + if(in_array($path, $this->extraCss)){ |
|
| 295 | + // nothing to do |
|
| 296 | + return; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->extraCss[] = $path; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Adds an extra JS file to to the page |
|
| 304 | + * |
|
| 305 | + * @param string $path The path (relative to the application root) of the file |
|
| 306 | + */ |
|
| 307 | + final protected function addJs($path){ |
|
| 308 | + if(in_array($path, $this->extraJs)){ |
|
| 309 | + // nothing to do |
|
| 310 | + return; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $this->extraJs[] = $path; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Main function for this page, when no specific actions are called. |
|
| 318 | + * @return void |
|
| 319 | + */ |
|
| 320 | + abstract protected function main(); |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @param string $title |
|
| 324 | + */ |
|
| 325 | + final protected function setHtmlTitle($title) |
|
| 326 | + { |
|
| 327 | + $this->htmlTitle = $title; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public function execute() |
|
| 331 | + { |
|
| 332 | + if ($this->getRouteName() === null) { |
|
| 333 | + throw new Exception('Request is unrouted.'); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($this->getSiteConfiguration() === null) { |
|
| 337 | + throw new Exception('Page has no configuration!'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $this->setupPage(); |
|
| 341 | + |
|
| 342 | + $this->runPage(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + public function assignCSRFToken() |
|
| 346 | + { |
|
| 347 | + $token = $this->tokenManager->getNewToken(); |
|
| 348 | + $this->assign('csrfTokenData', $token->getTokenData()); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + public function validateCSRFToken() |
|
| 352 | + { |
|
| 353 | + if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
| 354 | + throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + protected function sendResponseHeaders() |
|
| 359 | + { |
|
| 360 | + if (headers_sent()) { |
|
| 361 | + throw new ApplicationLogicException ('Headers have already been sent! This is likely a bug in the application.'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + foreach ($this->headerQueue as $item) { |
|
| 365 | + if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
| 366 | + // Oops. We're not allowed to do this. |
|
| 367 | + throw new Exception('Unable to split header'); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + header($item); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | 373 | } |
@@ -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 |
@@ -21,159 +21,159 @@ 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 | - /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 45 | - private static $currentUser; |
|
| 46 | - #region Object load methods |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Gets the currently logged in user |
|
| 50 | - * |
|
| 51 | - * @param PdoDatabase $database |
|
| 52 | - * |
|
| 53 | - * @return User|CommunityUser |
|
| 54 | - */ |
|
| 55 | - public static function getCurrent(PdoDatabase $database) |
|
| 56 | - { |
|
| 57 | - if (self::$currentUser === null) { |
|
| 58 | - $sessionId = WebRequest::getSessionUserId(); |
|
| 59 | - |
|
| 60 | - if ($sessionId !== null) { |
|
| 61 | - /** @var User $user */ |
|
| 62 | - $user = self::getById($sessionId, $database); |
|
| 63 | - |
|
| 64 | - if ($user === false) { |
|
| 65 | - self::$currentUser = new CommunityUser(); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - self::$currentUser = $user; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - else { |
|
| 72 | - $anonymousCoward = new CommunityUser(); |
|
| 73 | - |
|
| 74 | - self::$currentUser = $anonymousCoward; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return self::$currentUser; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Gets a user by their user ID |
|
| 83 | - * |
|
| 84 | - * Pass -1 to get the community user. |
|
| 85 | - * |
|
| 86 | - * @param int|null $id |
|
| 87 | - * @param PdoDatabase $database |
|
| 88 | - * |
|
| 89 | - * @return User|false |
|
| 90 | - */ |
|
| 91 | - public static function getById($id, PdoDatabase $database) |
|
| 92 | - { |
|
| 93 | - if ($id === null || $id == -1) { |
|
| 94 | - return new CommunityUser(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** @var User|false $user */ |
|
| 98 | - $user = parent::getById($id, $database); |
|
| 99 | - |
|
| 100 | - return $user; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @return CommunityUser |
|
| 105 | - */ |
|
| 106 | - public static function getCommunity() |
|
| 107 | - { |
|
| 108 | - return new CommunityUser(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Gets a user by their username |
|
| 113 | - * |
|
| 114 | - * @param string $username |
|
| 115 | - * @param PdoDatabase $database |
|
| 116 | - * |
|
| 117 | - * @return CommunityUser|User|false |
|
| 118 | - */ |
|
| 119 | - public static function getByUsername($username, PdoDatabase $database) |
|
| 120 | - { |
|
| 121 | - global $communityUsername; |
|
| 122 | - if ($username == $communityUsername) { |
|
| 123 | - return new CommunityUser(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 127 | - $statement->bindValue(":id", $username); |
|
| 128 | - |
|
| 129 | - $statement->execute(); |
|
| 130 | - |
|
| 131 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 132 | - |
|
| 133 | - if ($resultObject != false) { |
|
| 134 | - $resultObject->setDatabase($database); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $resultObject; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Gets a user by their on-wiki username. |
|
| 142 | - * |
|
| 143 | - * @param string $username |
|
| 144 | - * @param PdoDatabase $database |
|
| 145 | - * |
|
| 146 | - * @return User|false |
|
| 147 | - */ |
|
| 148 | - public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 149 | - { |
|
| 150 | - $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 151 | - $statement->bindValue(":id", $username); |
|
| 152 | - $statement->execute(); |
|
| 153 | - |
|
| 154 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 155 | - |
|
| 156 | - if ($resultObject != false) { |
|
| 157 | - $resultObject->setDatabase($database); |
|
| 158 | - |
|
| 159 | - return $resultObject; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - #endregion |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves the current object |
|
| 169 | - * |
|
| 170 | - * @throws Exception |
|
| 171 | - */ |
|
| 172 | - public function save() |
|
| 173 | - { |
|
| 174 | - if ($this->isNew()) { |
|
| 175 | - // insert |
|
| 176 | - $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 | + /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 45 | + private static $currentUser; |
|
| 46 | + #region Object load methods |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Gets the currently logged in user |
|
| 50 | + * |
|
| 51 | + * @param PdoDatabase $database |
|
| 52 | + * |
|
| 53 | + * @return User|CommunityUser |
|
| 54 | + */ |
|
| 55 | + public static function getCurrent(PdoDatabase $database) |
|
| 56 | + { |
|
| 57 | + if (self::$currentUser === null) { |
|
| 58 | + $sessionId = WebRequest::getSessionUserId(); |
|
| 59 | + |
|
| 60 | + if ($sessionId !== null) { |
|
| 61 | + /** @var User $user */ |
|
| 62 | + $user = self::getById($sessionId, $database); |
|
| 63 | + |
|
| 64 | + if ($user === false) { |
|
| 65 | + self::$currentUser = new CommunityUser(); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + self::$currentUser = $user; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + else { |
|
| 72 | + $anonymousCoward = new CommunityUser(); |
|
| 73 | + |
|
| 74 | + self::$currentUser = $anonymousCoward; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return self::$currentUser; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Gets a user by their user ID |
|
| 83 | + * |
|
| 84 | + * Pass -1 to get the community user. |
|
| 85 | + * |
|
| 86 | + * @param int|null $id |
|
| 87 | + * @param PdoDatabase $database |
|
| 88 | + * |
|
| 89 | + * @return User|false |
|
| 90 | + */ |
|
| 91 | + public static function getById($id, PdoDatabase $database) |
|
| 92 | + { |
|
| 93 | + if ($id === null || $id == -1) { |
|
| 94 | + return new CommunityUser(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** @var User|false $user */ |
|
| 98 | + $user = parent::getById($id, $database); |
|
| 99 | + |
|
| 100 | + return $user; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @return CommunityUser |
|
| 105 | + */ |
|
| 106 | + public static function getCommunity() |
|
| 107 | + { |
|
| 108 | + return new CommunityUser(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Gets a user by their username |
|
| 113 | + * |
|
| 114 | + * @param string $username |
|
| 115 | + * @param PdoDatabase $database |
|
| 116 | + * |
|
| 117 | + * @return CommunityUser|User|false |
|
| 118 | + */ |
|
| 119 | + public static function getByUsername($username, PdoDatabase $database) |
|
| 120 | + { |
|
| 121 | + global $communityUsername; |
|
| 122 | + if ($username == $communityUsername) { |
|
| 123 | + return new CommunityUser(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 127 | + $statement->bindValue(":id", $username); |
|
| 128 | + |
|
| 129 | + $statement->execute(); |
|
| 130 | + |
|
| 131 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 132 | + |
|
| 133 | + if ($resultObject != false) { |
|
| 134 | + $resultObject->setDatabase($database); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $resultObject; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Gets a user by their on-wiki username. |
|
| 142 | + * |
|
| 143 | + * @param string $username |
|
| 144 | + * @param PdoDatabase $database |
|
| 145 | + * |
|
| 146 | + * @return User|false |
|
| 147 | + */ |
|
| 148 | + public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 149 | + { |
|
| 150 | + $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 151 | + $statement->bindValue(":id", $username); |
|
| 152 | + $statement->execute(); |
|
| 153 | + |
|
| 154 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 155 | + |
|
| 156 | + if ($resultObject != false) { |
|
| 157 | + $resultObject->setDatabase($database); |
|
| 158 | + |
|
| 159 | + return $resultObject; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + #endregion |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves the current object |
|
| 169 | + * |
|
| 170 | + * @throws Exception |
|
| 171 | + */ |
|
| 172 | + public function save() |
|
| 173 | + { |
|
| 174 | + if ($this->isNew()) { |
|
| 175 | + // insert |
|
| 176 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 177 | 177 | INSERT INTO `user` ( |
| 178 | 178 | username, email, status, onwikiname, welcome_sig, |
| 179 | 179 | lastactive, forcelogout, forceidentified, |
@@ -184,31 +184,31 @@ discard block |
||
| 184 | 184 | :welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode |
| 185 | 185 | ); |
| 186 | 186 | SQL |
| 187 | - ); |
|
| 188 | - $statement->bindValue(":username", $this->username); |
|
| 189 | - $statement->bindValue(":email", $this->email); |
|
| 190 | - $statement->bindValue(":status", $this->status); |
|
| 191 | - $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 192 | - $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 193 | - $statement->bindValue(":lastactive", $this->lastactive); |
|
| 194 | - $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 195 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 196 | - $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 197 | - $statement->bindValue(":abortpref", $this->abortpref); |
|
| 198 | - $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 199 | - $statement->bindValue(":emailsig", $this->emailsig); |
|
| 200 | - $statement->bindValue(":creationmode", $this->creationmode); |
|
| 201 | - |
|
| 202 | - if ($statement->execute()) { |
|
| 203 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 204 | - } |
|
| 205 | - else { |
|
| 206 | - throw new Exception($statement->errorInfo()); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - else { |
|
| 210 | - // update |
|
| 211 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 187 | + ); |
|
| 188 | + $statement->bindValue(":username", $this->username); |
|
| 189 | + $statement->bindValue(":email", $this->email); |
|
| 190 | + $statement->bindValue(":status", $this->status); |
|
| 191 | + $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 192 | + $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 193 | + $statement->bindValue(":lastactive", $this->lastactive); |
|
| 194 | + $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 195 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 196 | + $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 197 | + $statement->bindValue(":abortpref", $this->abortpref); |
|
| 198 | + $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 199 | + $statement->bindValue(":emailsig", $this->emailsig); |
|
| 200 | + $statement->bindValue(":creationmode", $this->creationmode); |
|
| 201 | + |
|
| 202 | + if ($statement->execute()) { |
|
| 203 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 204 | + } |
|
| 205 | + else { |
|
| 206 | + throw new Exception($statement->errorInfo()); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + else { |
|
| 210 | + // update |
|
| 211 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 212 | 212 | UPDATE `user` SET |
| 213 | 213 | username = :username, email = :email, |
| 214 | 214 | status = :status, |
@@ -221,364 +221,364 @@ discard block |
||
| 221 | 221 | WHERE id = :id AND updateversion = :updateversion |
| 222 | 222 | LIMIT 1; |
| 223 | 223 | SQL |
| 224 | - ); |
|
| 225 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 226 | - |
|
| 227 | - $statement->bindValue(':id', $this->id); |
|
| 228 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 229 | - |
|
| 230 | - $statement->bindValue(':username', $this->username); |
|
| 231 | - $statement->bindValue(':email', $this->email); |
|
| 232 | - $statement->bindValue(':status', $this->status); |
|
| 233 | - $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 234 | - $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 235 | - $statement->bindValue(':lastactive', $this->lastactive); |
|
| 236 | - $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 237 | - $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 238 | - $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 239 | - $statement->bindValue(':abortpref', $this->abortpref); |
|
| 240 | - $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 241 | - $statement->bindValue(':emailsig', $this->emailsig); |
|
| 242 | - $statement->bindValue(':creationmode', $this->creationmode); |
|
| 243 | - |
|
| 244 | - if (!$statement->execute()) { |
|
| 245 | - throw new Exception($statement->errorInfo()); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if ($statement->rowCount() !== 1) { |
|
| 249 | - throw new OptimisticLockFailedException(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $this->updateversion++; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - #region properties |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Gets the tool username |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getUsername() |
|
| 263 | - { |
|
| 264 | - return $this->username; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Sets the tool username |
|
| 269 | - * |
|
| 270 | - * @param string $username |
|
| 271 | - */ |
|
| 272 | - public function setUsername($username) |
|
| 273 | - { |
|
| 274 | - $this->username = $username; |
|
| 275 | - |
|
| 276 | - // If this isn't a brand new user, then it's a rename, force the logout |
|
| 277 | - if (!$this->isNew()) { |
|
| 278 | - $this->forcelogout = 1; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Gets the user's email address |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function getEmail() |
|
| 287 | - { |
|
| 288 | - return $this->email; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Sets the user's email address |
|
| 293 | - * |
|
| 294 | - * @param string $email |
|
| 295 | - */ |
|
| 296 | - public function setEmail($email) |
|
| 297 | - { |
|
| 298 | - $this->email = $email; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - public function getStatus() |
|
| 306 | - { |
|
| 307 | - return $this->status; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param string $status |
|
| 312 | - */ |
|
| 313 | - public function setStatus($status) |
|
| 314 | - { |
|
| 315 | - $this->status = $status; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Gets the user's on-wiki name |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 322 | - public function getOnWikiName() |
|
| 323 | - { |
|
| 324 | - return $this->onwikiname; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Sets the user's on-wiki name |
|
| 329 | - * |
|
| 330 | - * This can have interesting side-effects with OAuth. |
|
| 331 | - * |
|
| 332 | - * @param string $onWikiName |
|
| 333 | - */ |
|
| 334 | - public function setOnWikiName($onWikiName) |
|
| 335 | - { |
|
| 336 | - $this->onwikiname = $onWikiName; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Gets the welcome signature |
|
| 341 | - * @return string |
|
| 342 | - */ |
|
| 343 | - public function getWelcomeSig() |
|
| 344 | - { |
|
| 345 | - return $this->welcome_sig; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Sets the welcome signature |
|
| 350 | - * |
|
| 351 | - * @param string $welcomeSig |
|
| 352 | - */ |
|
| 353 | - public function setWelcomeSig($welcomeSig) |
|
| 354 | - { |
|
| 355 | - $this->welcome_sig = $welcomeSig; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Gets the last activity date for the user |
|
| 360 | - * |
|
| 361 | - * @return string |
|
| 362 | - * @todo This should probably return an instance of DateTime |
|
| 363 | - */ |
|
| 364 | - public function getLastActive() |
|
| 365 | - { |
|
| 366 | - return $this->lastactive; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Gets the user's forced logout status |
|
| 371 | - * |
|
| 372 | - * @return bool |
|
| 373 | - */ |
|
| 374 | - public function getForceLogout() |
|
| 375 | - { |
|
| 376 | - return $this->forcelogout == 1; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Sets the user's forced logout status |
|
| 381 | - * |
|
| 382 | - * @param bool $forceLogout |
|
| 383 | - */ |
|
| 384 | - public function setForceLogout($forceLogout) |
|
| 385 | - { |
|
| 386 | - $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Returns the ID of the welcome template used. |
|
| 391 | - * @return int |
|
| 392 | - */ |
|
| 393 | - public function getWelcomeTemplate() |
|
| 394 | - { |
|
| 395 | - return $this->welcome_template; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Sets the ID of the welcome template used. |
|
| 400 | - * |
|
| 401 | - * @param int $welcomeTemplate |
|
| 402 | - */ |
|
| 403 | - public function setWelcomeTemplate($welcomeTemplate) |
|
| 404 | - { |
|
| 405 | - $this->welcome_template = $welcomeTemplate; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Gets the user's abort preference |
|
| 410 | - * @todo this is badly named too! Also a bool that's actually an int. |
|
| 411 | - * @return int |
|
| 412 | - */ |
|
| 413 | - public function getAbortPref() |
|
| 414 | - { |
|
| 415 | - return $this->abortpref; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Sets the user's abort preference |
|
| 420 | - * @todo rename, retype, and re-comment. |
|
| 421 | - * |
|
| 422 | - * @param int $abortPreference |
|
| 423 | - */ |
|
| 424 | - public function setAbortPref($abortPreference) |
|
| 425 | - { |
|
| 426 | - $this->abortpref = $abortPreference; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 431 | - * @return int the diff ID |
|
| 432 | - */ |
|
| 433 | - public function getConfirmationDiff() |
|
| 434 | - { |
|
| 435 | - return $this->confirmationdiff; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Sets the user's confirmation diff. |
|
| 440 | - * |
|
| 441 | - * @param int $confirmationDiff |
|
| 442 | - */ |
|
| 443 | - public function setConfirmationDiff($confirmationDiff) |
|
| 444 | - { |
|
| 445 | - $this->confirmationdiff = $confirmationDiff; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Gets the users' email signature used on outbound mail. |
|
| 450 | - * @todo rename me! |
|
| 451 | - * @return string |
|
| 452 | - */ |
|
| 453 | - public function getEmailSig() |
|
| 454 | - { |
|
| 455 | - return $this->emailsig; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Sets the user's email signature for outbound mail. |
|
| 460 | - * |
|
| 461 | - * @param string $emailSignature |
|
| 462 | - */ |
|
| 463 | - public function setEmailSig($emailSignature) |
|
| 464 | - { |
|
| 465 | - $this->emailsig = $emailSignature; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @return int |
|
| 470 | - */ |
|
| 471 | - public function getCreationMode() |
|
| 472 | - { |
|
| 473 | - return $this->creationmode; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * @param $creationMode int |
|
| 478 | - */ |
|
| 479 | - public function setCreationMode($creationMode) |
|
| 480 | - { |
|
| 481 | - $this->creationmode = $creationMode; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - #endregion |
|
| 485 | - |
|
| 486 | - #region user access checks |
|
| 487 | - |
|
| 488 | - public function isActive() |
|
| 489 | - { |
|
| 490 | - return $this->status == self::STATUS_ACTIVE; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Tests if the user is identified |
|
| 495 | - * |
|
| 496 | - * @param IdentificationVerifier $iv |
|
| 497 | - * |
|
| 498 | - * @return bool |
|
| 499 | - * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 500 | - * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 501 | - * to play it safe for now. |
|
| 502 | - * @category Security-Critical |
|
| 503 | - */ |
|
| 504 | - public function isIdentified(IdentificationVerifier $iv) |
|
| 505 | - { |
|
| 506 | - if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 507 | - // User forced to unidentified in the database. |
|
| 508 | - return false; |
|
| 509 | - } |
|
| 510 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 511 | - // User forced to identified in the database. |
|
| 512 | - return true; |
|
| 513 | - } |
|
| 514 | - else { |
|
| 515 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 516 | - return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Tests if the user is suspended |
|
| 522 | - * @return bool |
|
| 523 | - * @category Security-Critical |
|
| 524 | - */ |
|
| 525 | - public function isSuspended() |
|
| 526 | - { |
|
| 527 | - return $this->status == self::STATUS_SUSPENDED; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Tests if the user is new |
|
| 532 | - * @return bool |
|
| 533 | - * @category Security-Critical |
|
| 534 | - */ |
|
| 535 | - public function isNewUser() |
|
| 536 | - { |
|
| 537 | - return $this->status == self::STATUS_NEW; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * Tests if the user has been declined access to the tool |
|
| 542 | - * @return bool |
|
| 543 | - * @category Security-Critical |
|
| 544 | - */ |
|
| 545 | - public function isDeclined() |
|
| 546 | - { |
|
| 547 | - return $this->status == self::STATUS_DECLINED; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Tests if the user is the community user |
|
| 552 | - * |
|
| 553 | - * @todo decide if this means logged out. I think it usually does. |
|
| 554 | - * @return bool |
|
| 555 | - * @category Security-Critical |
|
| 556 | - */ |
|
| 557 | - public function isCommunityUser() |
|
| 558 | - { |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - #endregion |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Gets a hash of data for the user to reset their password with. |
|
| 566 | - * @category Security-Critical |
|
| 567 | - * @return string |
|
| 568 | - */ |
|
| 569 | - public function getForgottenPasswordHash() |
|
| 570 | - { |
|
| 571 | - // FIXME |
|
| 572 | - return md5($this->username . $this->email . $this->welcome_template . $this->id); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Gets the approval date of the user |
|
| 577 | - * @return DateTime|false |
|
| 578 | - */ |
|
| 579 | - public function getApprovalDate() |
|
| 580 | - { |
|
| 581 | - $query = $this->dbObject->prepare(<<<SQL |
|
| 224 | + ); |
|
| 225 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 226 | + |
|
| 227 | + $statement->bindValue(':id', $this->id); |
|
| 228 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 229 | + |
|
| 230 | + $statement->bindValue(':username', $this->username); |
|
| 231 | + $statement->bindValue(':email', $this->email); |
|
| 232 | + $statement->bindValue(':status', $this->status); |
|
| 233 | + $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 234 | + $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 235 | + $statement->bindValue(':lastactive', $this->lastactive); |
|
| 236 | + $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 237 | + $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 238 | + $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 239 | + $statement->bindValue(':abortpref', $this->abortpref); |
|
| 240 | + $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 241 | + $statement->bindValue(':emailsig', $this->emailsig); |
|
| 242 | + $statement->bindValue(':creationmode', $this->creationmode); |
|
| 243 | + |
|
| 244 | + if (!$statement->execute()) { |
|
| 245 | + throw new Exception($statement->errorInfo()); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if ($statement->rowCount() !== 1) { |
|
| 249 | + throw new OptimisticLockFailedException(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $this->updateversion++; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + #region properties |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Gets the tool username |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getUsername() |
|
| 263 | + { |
|
| 264 | + return $this->username; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Sets the tool username |
|
| 269 | + * |
|
| 270 | + * @param string $username |
|
| 271 | + */ |
|
| 272 | + public function setUsername($username) |
|
| 273 | + { |
|
| 274 | + $this->username = $username; |
|
| 275 | + |
|
| 276 | + // If this isn't a brand new user, then it's a rename, force the logout |
|
| 277 | + if (!$this->isNew()) { |
|
| 278 | + $this->forcelogout = 1; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Gets the user's email address |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function getEmail() |
|
| 287 | + { |
|
| 288 | + return $this->email; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Sets the user's email address |
|
| 293 | + * |
|
| 294 | + * @param string $email |
|
| 295 | + */ |
|
| 296 | + public function setEmail($email) |
|
| 297 | + { |
|
| 298 | + $this->email = $email; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + public function getStatus() |
|
| 306 | + { |
|
| 307 | + return $this->status; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param string $status |
|
| 312 | + */ |
|
| 313 | + public function setStatus($status) |
|
| 314 | + { |
|
| 315 | + $this->status = $status; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Gets the user's on-wiki name |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | + public function getOnWikiName() |
|
| 323 | + { |
|
| 324 | + return $this->onwikiname; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Sets the user's on-wiki name |
|
| 329 | + * |
|
| 330 | + * This can have interesting side-effects with OAuth. |
|
| 331 | + * |
|
| 332 | + * @param string $onWikiName |
|
| 333 | + */ |
|
| 334 | + public function setOnWikiName($onWikiName) |
|
| 335 | + { |
|
| 336 | + $this->onwikiname = $onWikiName; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Gets the welcome signature |
|
| 341 | + * @return string |
|
| 342 | + */ |
|
| 343 | + public function getWelcomeSig() |
|
| 344 | + { |
|
| 345 | + return $this->welcome_sig; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Sets the welcome signature |
|
| 350 | + * |
|
| 351 | + * @param string $welcomeSig |
|
| 352 | + */ |
|
| 353 | + public function setWelcomeSig($welcomeSig) |
|
| 354 | + { |
|
| 355 | + $this->welcome_sig = $welcomeSig; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Gets the last activity date for the user |
|
| 360 | + * |
|
| 361 | + * @return string |
|
| 362 | + * @todo This should probably return an instance of DateTime |
|
| 363 | + */ |
|
| 364 | + public function getLastActive() |
|
| 365 | + { |
|
| 366 | + return $this->lastactive; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Gets the user's forced logout status |
|
| 371 | + * |
|
| 372 | + * @return bool |
|
| 373 | + */ |
|
| 374 | + public function getForceLogout() |
|
| 375 | + { |
|
| 376 | + return $this->forcelogout == 1; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Sets the user's forced logout status |
|
| 381 | + * |
|
| 382 | + * @param bool $forceLogout |
|
| 383 | + */ |
|
| 384 | + public function setForceLogout($forceLogout) |
|
| 385 | + { |
|
| 386 | + $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Returns the ID of the welcome template used. |
|
| 391 | + * @return int |
|
| 392 | + */ |
|
| 393 | + public function getWelcomeTemplate() |
|
| 394 | + { |
|
| 395 | + return $this->welcome_template; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Sets the ID of the welcome template used. |
|
| 400 | + * |
|
| 401 | + * @param int $welcomeTemplate |
|
| 402 | + */ |
|
| 403 | + public function setWelcomeTemplate($welcomeTemplate) |
|
| 404 | + { |
|
| 405 | + $this->welcome_template = $welcomeTemplate; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Gets the user's abort preference |
|
| 410 | + * @todo this is badly named too! Also a bool that's actually an int. |
|
| 411 | + * @return int |
|
| 412 | + */ |
|
| 413 | + public function getAbortPref() |
|
| 414 | + { |
|
| 415 | + return $this->abortpref; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Sets the user's abort preference |
|
| 420 | + * @todo rename, retype, and re-comment. |
|
| 421 | + * |
|
| 422 | + * @param int $abortPreference |
|
| 423 | + */ |
|
| 424 | + public function setAbortPref($abortPreference) |
|
| 425 | + { |
|
| 426 | + $this->abortpref = $abortPreference; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 431 | + * @return int the diff ID |
|
| 432 | + */ |
|
| 433 | + public function getConfirmationDiff() |
|
| 434 | + { |
|
| 435 | + return $this->confirmationdiff; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Sets the user's confirmation diff. |
|
| 440 | + * |
|
| 441 | + * @param int $confirmationDiff |
|
| 442 | + */ |
|
| 443 | + public function setConfirmationDiff($confirmationDiff) |
|
| 444 | + { |
|
| 445 | + $this->confirmationdiff = $confirmationDiff; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Gets the users' email signature used on outbound mail. |
|
| 450 | + * @todo rename me! |
|
| 451 | + * @return string |
|
| 452 | + */ |
|
| 453 | + public function getEmailSig() |
|
| 454 | + { |
|
| 455 | + return $this->emailsig; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Sets the user's email signature for outbound mail. |
|
| 460 | + * |
|
| 461 | + * @param string $emailSignature |
|
| 462 | + */ |
|
| 463 | + public function setEmailSig($emailSignature) |
|
| 464 | + { |
|
| 465 | + $this->emailsig = $emailSignature; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @return int |
|
| 470 | + */ |
|
| 471 | + public function getCreationMode() |
|
| 472 | + { |
|
| 473 | + return $this->creationmode; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * @param $creationMode int |
|
| 478 | + */ |
|
| 479 | + public function setCreationMode($creationMode) |
|
| 480 | + { |
|
| 481 | + $this->creationmode = $creationMode; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + #endregion |
|
| 485 | + |
|
| 486 | + #region user access checks |
|
| 487 | + |
|
| 488 | + public function isActive() |
|
| 489 | + { |
|
| 490 | + return $this->status == self::STATUS_ACTIVE; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Tests if the user is identified |
|
| 495 | + * |
|
| 496 | + * @param IdentificationVerifier $iv |
|
| 497 | + * |
|
| 498 | + * @return bool |
|
| 499 | + * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 500 | + * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 501 | + * to play it safe for now. |
|
| 502 | + * @category Security-Critical |
|
| 503 | + */ |
|
| 504 | + public function isIdentified(IdentificationVerifier $iv) |
|
| 505 | + { |
|
| 506 | + if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 507 | + // User forced to unidentified in the database. |
|
| 508 | + return false; |
|
| 509 | + } |
|
| 510 | + elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 511 | + // User forced to identified in the database. |
|
| 512 | + return true; |
|
| 513 | + } |
|
| 514 | + else { |
|
| 515 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 516 | + return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Tests if the user is suspended |
|
| 522 | + * @return bool |
|
| 523 | + * @category Security-Critical |
|
| 524 | + */ |
|
| 525 | + public function isSuspended() |
|
| 526 | + { |
|
| 527 | + return $this->status == self::STATUS_SUSPENDED; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Tests if the user is new |
|
| 532 | + * @return bool |
|
| 533 | + * @category Security-Critical |
|
| 534 | + */ |
|
| 535 | + public function isNewUser() |
|
| 536 | + { |
|
| 537 | + return $this->status == self::STATUS_NEW; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * Tests if the user has been declined access to the tool |
|
| 542 | + * @return bool |
|
| 543 | + * @category Security-Critical |
|
| 544 | + */ |
|
| 545 | + public function isDeclined() |
|
| 546 | + { |
|
| 547 | + return $this->status == self::STATUS_DECLINED; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Tests if the user is the community user |
|
| 552 | + * |
|
| 553 | + * @todo decide if this means logged out. I think it usually does. |
|
| 554 | + * @return bool |
|
| 555 | + * @category Security-Critical |
|
| 556 | + */ |
|
| 557 | + public function isCommunityUser() |
|
| 558 | + { |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + #endregion |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Gets a hash of data for the user to reset their password with. |
|
| 566 | + * @category Security-Critical |
|
| 567 | + * @return string |
|
| 568 | + */ |
|
| 569 | + public function getForgottenPasswordHash() |
|
| 570 | + { |
|
| 571 | + // FIXME |
|
| 572 | + return md5($this->username . $this->email . $this->welcome_template . $this->id); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Gets the approval date of the user |
|
| 577 | + * @return DateTime|false |
|
| 578 | + */ |
|
| 579 | + public function getApprovalDate() |
|
| 580 | + { |
|
| 581 | + $query = $this->dbObject->prepare(<<<SQL |
|
| 582 | 582 | SELECT timestamp |
| 583 | 583 | FROM log |
| 584 | 584 | WHERE objectid = :userid |
@@ -587,12 +587,12 @@ discard block |
||
| 587 | 587 | ORDER BY id DESC |
| 588 | 588 | LIMIT 1; |
| 589 | 589 | SQL |
| 590 | - ); |
|
| 591 | - $query->execute(array(":userid" => $this->id)); |
|
| 590 | + ); |
|
| 591 | + $query->execute(array(":userid" => $this->id)); |
|
| 592 | 592 | |
| 593 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 594 | - $query->closeCursor(); |
|
| 593 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 594 | + $query->closeCursor(); |
|
| 595 | 595 | |
| 596 | - return $data; |
|
| 597 | - } |
|
| 596 | + return $data; |
|
| 597 | + } |
|
| 598 | 598 | } |
@@ -14,122 +14,122 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class Credential extends DataObject |
| 16 | 16 | { |
| 17 | - /** @var int */ |
|
| 18 | - private $user; |
|
| 19 | - /** @var int */ |
|
| 20 | - private $factor; |
|
| 21 | - /** @var string */ |
|
| 22 | - private $type; |
|
| 23 | - /** @var string */ |
|
| 24 | - private $data; |
|
| 25 | - /** @var int */ |
|
| 26 | - private $version; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return int |
|
| 30 | - */ |
|
| 31 | - public function getUserId() |
|
| 32 | - { |
|
| 33 | - return $this->user; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param int $user |
|
| 38 | - */ |
|
| 39 | - public function setUserId($user) |
|
| 40 | - { |
|
| 41 | - $this->user = $user; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return int |
|
| 46 | - */ |
|
| 47 | - public function getFactor() |
|
| 48 | - { |
|
| 49 | - return $this->factor; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param int $factor |
|
| 54 | - */ |
|
| 55 | - public function setFactor($factor) |
|
| 56 | - { |
|
| 57 | - $this->factor = $factor; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function getType() |
|
| 64 | - { |
|
| 65 | - return $this->type; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param string $type |
|
| 70 | - */ |
|
| 71 | - public function setType($type) |
|
| 72 | - { |
|
| 73 | - $this->type = $type; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function getData() |
|
| 80 | - { |
|
| 81 | - return $this->data; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param string $data |
|
| 86 | - */ |
|
| 87 | - public function setData($data) |
|
| 88 | - { |
|
| 89 | - $this->data = $data; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return int |
|
| 94 | - */ |
|
| 95 | - public function getVersion() |
|
| 96 | - { |
|
| 97 | - return $this->version; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param int $version |
|
| 102 | - */ |
|
| 103 | - public function setVersion($version) |
|
| 104 | - { |
|
| 105 | - $this->version = $version; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function save() |
|
| 109 | - { |
|
| 110 | - if ($this->isNew()) { |
|
| 111 | - // insert |
|
| 112 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 17 | + /** @var int */ |
|
| 18 | + private $user; |
|
| 19 | + /** @var int */ |
|
| 20 | + private $factor; |
|
| 21 | + /** @var string */ |
|
| 22 | + private $type; |
|
| 23 | + /** @var string */ |
|
| 24 | + private $data; |
|
| 25 | + /** @var int */ |
|
| 26 | + private $version; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return int |
|
| 30 | + */ |
|
| 31 | + public function getUserId() |
|
| 32 | + { |
|
| 33 | + return $this->user; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param int $user |
|
| 38 | + */ |
|
| 39 | + public function setUserId($user) |
|
| 40 | + { |
|
| 41 | + $this->user = $user; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return int |
|
| 46 | + */ |
|
| 47 | + public function getFactor() |
|
| 48 | + { |
|
| 49 | + return $this->factor; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param int $factor |
|
| 54 | + */ |
|
| 55 | + public function setFactor($factor) |
|
| 56 | + { |
|
| 57 | + $this->factor = $factor; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function getType() |
|
| 64 | + { |
|
| 65 | + return $this->type; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param string $type |
|
| 70 | + */ |
|
| 71 | + public function setType($type) |
|
| 72 | + { |
|
| 73 | + $this->type = $type; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function getData() |
|
| 80 | + { |
|
| 81 | + return $this->data; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param string $data |
|
| 86 | + */ |
|
| 87 | + public function setData($data) |
|
| 88 | + { |
|
| 89 | + $this->data = $data; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return int |
|
| 94 | + */ |
|
| 95 | + public function getVersion() |
|
| 96 | + { |
|
| 97 | + return $this->version; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param int $version |
|
| 102 | + */ |
|
| 103 | + public function setVersion($version) |
|
| 104 | + { |
|
| 105 | + $this->version = $version; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function save() |
|
| 109 | + { |
|
| 110 | + if ($this->isNew()) { |
|
| 111 | + // insert |
|
| 112 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 113 | 113 | INSERT INTO credential ( updateversion, user, factor, type, data, version ) |
| 114 | 114 | VALUES ( 0, :user, :factor, :type, :data, :version ); |
| 115 | 115 | SQL |
| 116 | - ); |
|
| 117 | - $statement->bindValue(":user", $this->user); |
|
| 118 | - $statement->bindValue(":factor", $this->factor); |
|
| 119 | - $statement->bindValue(":type", $this->type); |
|
| 120 | - $statement->bindValue(":data", $this->data); |
|
| 121 | - $statement->bindValue(":version", $this->version); |
|
| 122 | - |
|
| 123 | - if ($statement->execute()) { |
|
| 124 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 125 | - } |
|
| 126 | - else { |
|
| 127 | - throw new Exception($statement->errorInfo()); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - else { |
|
| 131 | - // update |
|
| 132 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 116 | + ); |
|
| 117 | + $statement->bindValue(":user", $this->user); |
|
| 118 | + $statement->bindValue(":factor", $this->factor); |
|
| 119 | + $statement->bindValue(":type", $this->type); |
|
| 120 | + $statement->bindValue(":data", $this->data); |
|
| 121 | + $statement->bindValue(":version", $this->version); |
|
| 122 | + |
|
| 123 | + if ($statement->execute()) { |
|
| 124 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 125 | + } |
|
| 126 | + else { |
|
| 127 | + throw new Exception($statement->errorInfo()); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + else { |
|
| 131 | + // update |
|
| 132 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 133 | 133 | UPDATE credential |
| 134 | 134 | SET factor = :factor |
| 135 | 135 | , data = :data |
@@ -137,24 +137,24 @@ discard block |
||
| 137 | 137 | , updateversion = updateversion + 1 |
| 138 | 138 | WHERE id = :id AND updateversion = :updateversion; |
| 139 | 139 | SQL |
| 140 | - ); |
|
| 140 | + ); |
|
| 141 | 141 | |
| 142 | - $statement->bindValue(':id', $this->id); |
|
| 143 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 142 | + $statement->bindValue(':id', $this->id); |
|
| 143 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 144 | 144 | |
| 145 | - $statement->bindValue(":factor", $this->factor); |
|
| 146 | - $statement->bindValue(":data", $this->data); |
|
| 147 | - $statement->bindValue(":version", $this->version); |
|
| 145 | + $statement->bindValue(":factor", $this->factor); |
|
| 146 | + $statement->bindValue(":data", $this->data); |
|
| 147 | + $statement->bindValue(":version", $this->version); |
|
| 148 | 148 | |
| 149 | - if (!$statement->execute()) { |
|
| 150 | - throw new Exception($statement->errorInfo()); |
|
| 151 | - } |
|
| 149 | + if (!$statement->execute()) { |
|
| 150 | + throw new Exception($statement->errorInfo()); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($statement->rowCount() !== 1) { |
|
| 154 | - throw new OptimisticLockFailedException(); |
|
| 155 | - } |
|
| 153 | + if ($statement->rowCount() !== 1) { |
|
| 154 | + throw new OptimisticLockFailedException(); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $this->updateversion++; |
|
| 158 | - } |
|
| 159 | - } |
|
| 157 | + $this->updateversion++; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | \ No newline at end of file |