Test Setup Failed
Push — dependabot/composer/twbs/boots... ( 3e72c6 )
by
unknown
13:19
created
includes/WebRequest.php 1 patch
Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -24,578 +24,578 @@
 block discarded – undo
24 24
  */
25 25
 class WebRequest
26 26
 {
27
-    /**
28
-     * @var IGlobalStateProvider Provides access to the global state.
29
-     */
30
-    private static $globalStateProvider;
31
-
32
-    /**
33
-     * Returns a boolean value if the request was submitted with the HTTP POST method.
34
-     * @return bool
35
-     */
36
-    public static function wasPosted()
37
-    {
38
-        return self::method() === 'POST';
39
-    }
40
-
41
-    /**
42
-     * Gets the HTTP Method used
43
-     * @return string|null
44
-     */
45
-    public static function method()
46
-    {
47
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
48
-
49
-        if (isset($server['REQUEST_METHOD'])) {
50
-            return $server['REQUEST_METHOD'];
51
-        }
52
-
53
-        return null;
54
-    }
55
-
56
-    /**
57
-     * Gets a boolean value stating whether the request was served over HTTPS or not.
58
-     * @return bool
59
-     */
60
-    public static function isHttps()
61
-    {
62
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
63
-
64
-        if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
65
-            if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') {
66
-                // Client <=> Proxy is encrypted
67
-                return true;
68
-            }
69
-            else {
70
-                // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.
71
-                return false;
72
-            }
73
-        }
74
-
75
-        if (isset($server['HTTPS'])) {
76
-            if ($server['HTTPS'] === 'off') {
77
-                // ISAPI on IIS breaks the spec. :(
78
-                return false;
79
-            }
80
-
81
-            if ($server['HTTPS'] !== '') {
82
-                // Set to a non-empty value
83
-                return true;
84
-            }
85
-        }
86
-
87
-        return false;
88
-    }
89
-
90
-    /**
91
-     * Gets the path info
92
-     *
93
-     * @return array Array of path info segments
94
-     */
95
-    public static function pathInfo()
96
-    {
97
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
98
-        if (!isset($server['PATH_INFO'])) {
99
-            return array();
100
-        }
101
-
102
-        $exploded = explode('/', $server['PATH_INFO']);
103
-
104
-        // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts
105
-        // with a /
106
-        return array_values(array_filter($exploded));
107
-    }
108
-
109
-    /**
110
-     * Gets the remote address of the web request
111
-     * @return null|string
112
-     */
113
-    public static function remoteAddress()
114
-    {
115
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
116
-
117
-        if (isset($server['REMOTE_ADDR'])) {
118
-            return $server['REMOTE_ADDR'];
119
-        }
120
-
121
-        return null;
122
-    }
123
-
124
-    /**
125
-     * Gets the remote address of the web request
126
-     * @return null|string
127
-     */
128
-    public static function httpHost()
129
-    {
130
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
131
-
132
-        if (isset($server['HTTP_HOST'])) {
133
-            return $server['HTTP_HOST'];
134
-        }
135
-
136
-        return null;
137
-    }
138
-
139
-    /**
140
-     * Gets the XFF header contents for the web request
141
-     * @return null|string
142
-     */
143
-    public static function forwardedAddress()
144
-    {
145
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
146
-
147
-        if (isset($server['HTTP_X_FORWARDED_FOR'])) {
148
-            return $server['HTTP_X_FORWARDED_FOR'];
149
-        }
150
-
151
-        return null;
152
-    }
153
-
154
-    /**
155
-     * Sets the global state provider.
156
-     *
157
-     * Almost guaranteed this is not the method you want in production code.
158
-     *
159
-     * @param IGlobalStateProvider $globalState
160
-     */
161
-    public static function setGlobalStateProvider($globalState)
162
-    {
163
-        self::$globalStateProvider = $globalState;
164
-    }
165
-
166
-    #region POST variables
167
-
168
-    /**
169
-     * @param string $key
170
-     *
171
-     * @return null|string
172
-     */
173
-    public static function postString($key)
174
-    {
175
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
176
-        if (!array_key_exists($key, $post)) {
177
-            return null;
178
-        }
179
-
180
-        if ($post[$key] === "") {
181
-            return null;
182
-        }
183
-
184
-        return (string)$post[$key];
185
-    }
186
-
187
-    /**
188
-     * @param string $key
189
-     *
190
-     * @return null|string
191
-     */
192
-    public static function postEmail($key)
193
-    {
194
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
195
-        if (!array_key_exists($key, $post)) {
196
-            return null;
197
-        }
198
-
199
-        $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);
200
-
201
-        if ($filteredValue === false) {
202
-            return null;
203
-        }
204
-
205
-        return (string)$filteredValue;
206
-    }
207
-
208
-    /**
209
-     * @param string $key
210
-     *
211
-     * @return int|null
212
-     */
213
-    public static function postInt($key)
214
-    {
215
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
216
-        if (!array_key_exists($key, $post)) {
217
-            return null;
218
-        }
219
-
220
-        $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
221
-
222
-        if ($filteredValue === null) {
223
-            return null;
224
-        }
225
-
226
-        return (int)$filteredValue;
227
-    }
228
-
229
-    /**
230
-     * @param string $key
231
-     *
232
-     * @return bool
233
-     */
234
-    public static function postBoolean($key)
235
-    {
236
-        $get = &self::$globalStateProvider->getPostSuperGlobal();
237
-        if (!array_key_exists($key, $get)) {
238
-            return false;
239
-        }
240
-
241
-        // presence of parameter only
242
-        if ($get[$key] === "") {
243
-            return true;
244
-        }
245
-
246
-        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
247
-            return false;
248
-        }
249
-
250
-        return true;
251
-    }
252
-
253
-    #endregion
254
-
255
-    #region GET variables
256
-
257
-    /**
258
-     * @param string $key
259
-     *
260
-     * @return bool
261
-     */
262
-    public static function getBoolean($key)
263
-    {
264
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
265
-        if (!array_key_exists($key, $get)) {
266
-            return false;
267
-        }
268
-
269
-        // presence of parameter only
270
-        if ($get[$key] === "") {
271
-            return true;
272
-        }
273
-
274
-        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
275
-            return false;
276
-        }
277
-
278
-        return true;
279
-    }
280
-
281
-    /**
282
-     * @param string $key
283
-     *
284
-     * @return int|null
285
-     */
286
-    public static function getInt($key)
287
-    {
288
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
289
-        if (!array_key_exists($key, $get)) {
290
-            return null;
291
-        }
292
-
293
-        $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
294
-
295
-        if ($filteredValue === null) {
296
-            return null;
297
-        }
298
-
299
-        return (int)$filteredValue;
300
-    }
301
-
302
-    /**
303
-     * @param string $key
304
-     *
305
-     * @return null|string
306
-     */
307
-    public static function getString($key)
308
-    {
309
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
310
-        if (!array_key_exists($key, $get)) {
311
-            return null;
312
-        }
313
-
314
-        if ($get[$key] === "") {
315
-            return null;
316
-        }
317
-
318
-        return (string)$get[$key];
319
-    }
320
-
321
-    #endregion
322
-
323
-    /**
324
-     * Sets the logged-in user to the specified user.
325
-     *
326
-     * @param User $user
327
-     */
328
-    public static function setLoggedInUser(User $user)
329
-    {
330
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
331
-
332
-        $session['userID'] = $user->getId();
333
-        unset($session['partialLogin']);
334
-    }
335
-
336
-    /**
337
-     * Sets the post-login redirect
338
-     *
339
-     * @param string|null $uri The URI to redirect to
340
-     */
341
-    public static function setPostLoginRedirect($uri = null)
342
-    {
343
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
344
-
345
-        if ($uri === null) {
346
-            $uri = self::requestUri();
347
-        }
348
-
349
-        $session['returnTo'] = $uri;
350
-    }
351
-
352
-    /**
353
-     * @return string|null
354
-     */
355
-    public static function requestUri()
356
-    {
357
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
358
-
359
-        if (isset($server['REQUEST_URI'])) {
360
-            return $server['REQUEST_URI'];
361
-        }
362
-
363
-        return null;
364
-    }
365
-
366
-    /**
367
-     * Clears the post-login redirect
368
-     * @return string
369
-     */
370
-    public static function clearPostLoginRedirect()
371
-    {
372
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
373
-        if (array_key_exists('returnTo', $session)) {
374
-            $path = $session['returnTo'];
375
-            unset($session['returnTo']);
376
-
377
-            return $path;
378
-        }
379
-
380
-        return null;
381
-    }
382
-
383
-    /**
384
-     * @return string|null
385
-     */
386
-    public static function serverName()
387
-    {
388
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
389
-
390
-        if (isset($server['SERVER_NAME'])) {
391
-            return $server['SERVER_NAME'];
392
-        }
393
-
394
-        return null;
395
-    }
396
-
397
-    /**
398
-     * You probably only want to deal with this through SessionAlert.
399
-     * @return void
400
-     */
401
-    public static function clearSessionAlertData()
402
-    {
403
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
404
-        if (array_key_exists('alerts', $session)) {
405
-            unset($session['alerts']);
406
-        }
407
-    }
408
-
409
-    /**
410
-     * You probably only want to deal with this through SessionAlert.
411
-     *
412
-     * @return string[]
413
-     */
414
-    public static function getSessionAlertData()
415
-    {
416
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
417
-        if (array_key_exists('alerts', $session)) {
418
-            return $session['alerts'];
419
-        }
420
-
421
-        return array();
422
-    }
423
-
424
-    /**
425
-     * You probably only want to deal with this through SessionAlert.
426
-     *
427
-     * @param string[] $data
428
-     */
429
-    public static function setSessionAlertData($data)
430
-    {
431
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
432
-        $session['alerts'] = $data;
433
-    }
434
-
435
-    /**
436
-     * You probably only want to deal with this through TokenManager.
437
-     *
438
-     * @return string[]
439
-     */
440
-    public static function getSessionTokenData()
441
-    {
442
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
443
-        if (array_key_exists('tokens', $session)) {
444
-            return $session['tokens'];
445
-        }
446
-
447
-        return array();
448
-    }
449
-
450
-    /**
451
-     * You probably only want to deal with this through TokenManager.
452
-     *
453
-     * @param string[] $data
454
-     */
455
-    public static function setSessionTokenData($data)
456
-    {
457
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
458
-        $session['tokens'] = $data;
459
-    }
460
-
461
-    /**
462
-     * @param string $key
463
-     *
464
-     * @return mixed
465
-     */
466
-    public static function getSessionContext($key)
467
-    {
468
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
469
-
470
-        if (!isset($session['context'])) {
471
-            $session['context'] = array();
472
-        }
473
-
474
-        if (!isset($session['context'][$key])) {
475
-            return null;
476
-        }
477
-
478
-        return $session['context'][$key];
479
-    }
480
-
481
-    /**
482
-     * @param string $key
483
-     * @param mixed  $data
484
-     */
485
-    public static function setSessionContext($key, $data)
486
-    {
487
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
488
-
489
-        if (!isset($session['context'])) {
490
-            $session['context'] = array();
491
-        }
492
-
493
-        $session['context'][$key] = $data;
494
-    }
495
-
496
-    /**
497
-     * @return int|null
498
-     */
499
-    public static function getSessionUserId()
500
-    {
501
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
502
-
503
-        return isset($session['userID']) ? (int)$session['userID'] : null;
504
-    }
505
-
506
-    /**
507
-     * @param User $user
508
-     */
509
-    public static function setOAuthPartialLogin(User $user)
510
-    {
511
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
512
-        $session['oauthPartialLogin'] = $user->getId();
513
-    }
514
-
515
-    /**
516
-     * @return int|null
517
-     */
518
-    public static function getOAuthPartialLogin()
519
-    {
520
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
521
-
522
-        return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null;
523
-    }
524
-
525
-    public static function setAuthPartialLogin($userId, $stage)
526
-    {
527
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
528
-        $session['authPartialLoginId'] = $userId;
529
-        $session['authPartialLoginStage'] = $stage;
530
-    }
531
-
532
-    public static function getAuthPartialLogin()
533
-    {
534
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
535
-
536
-        $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null;
537
-        $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null;
538
-
539
-        return array($userId, $stage);
540
-    }
541
-
542
-    public static function clearAuthPartialLogin()
543
-    {
544
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
545
-        unset($session['authPartialLoginId']);
546
-        unset($session['authPartialLoginStage']);
547
-    }
548
-
549
-    /**
550
-     * @return null|string
551
-     */
552
-    public static function userAgent()
553
-    {
554
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
555
-
556
-        if (isset($server['HTTP_USER_AGENT'])) {
557
-            return $server['HTTP_USER_AGENT'];
558
-        }
559
-
560
-        return null;
561
-    }
562
-
563
-    /**
564
-     * @return null|string
565
-     */
566
-    public static function scriptName()
567
-    {
568
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
569
-
570
-        if (isset($server['SCRIPT_NAME'])) {
571
-            return $server['SCRIPT_NAME'];
572
-        }
573
-
574
-        return null;
575
-    }
576
-
577
-    /**
578
-     * @return null|string
579
-     */
580
-    public static function origin()
581
-    {
582
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
583
-
584
-        if (isset($server['HTTP_ORIGIN'])) {
585
-            return $server['HTTP_ORIGIN'];
586
-        }
587
-
588
-        return null;
589
-    }
590
-
591
-    public static function testSiteNoticeCookieValue($expectedHash)
592
-    {
593
-        $cookie = &self::$globalStateProvider->getCookieSuperGlobal();
594
-
595
-        if(isset($cookie['sitenotice'])) {
596
-            return $cookie['sitenotice'] === $expectedHash;
597
-        }
598
-
599
-        return false;
600
-    }
27
+	/**
28
+	 * @var IGlobalStateProvider Provides access to the global state.
29
+	 */
30
+	private static $globalStateProvider;
31
+
32
+	/**
33
+	 * Returns a boolean value if the request was submitted with the HTTP POST method.
34
+	 * @return bool
35
+	 */
36
+	public static function wasPosted()
37
+	{
38
+		return self::method() === 'POST';
39
+	}
40
+
41
+	/**
42
+	 * Gets the HTTP Method used
43
+	 * @return string|null
44
+	 */
45
+	public static function method()
46
+	{
47
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
48
+
49
+		if (isset($server['REQUEST_METHOD'])) {
50
+			return $server['REQUEST_METHOD'];
51
+		}
52
+
53
+		return null;
54
+	}
55
+
56
+	/**
57
+	 * Gets a boolean value stating whether the request was served over HTTPS or not.
58
+	 * @return bool
59
+	 */
60
+	public static function isHttps()
61
+	{
62
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
63
+
64
+		if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
65
+			if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') {
66
+				// Client <=> Proxy is encrypted
67
+				return true;
68
+			}
69
+			else {
70
+				// Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.
71
+				return false;
72
+			}
73
+		}
74
+
75
+		if (isset($server['HTTPS'])) {
76
+			if ($server['HTTPS'] === 'off') {
77
+				// ISAPI on IIS breaks the spec. :(
78
+				return false;
79
+			}
80
+
81
+			if ($server['HTTPS'] !== '') {
82
+				// Set to a non-empty value
83
+				return true;
84
+			}
85
+		}
86
+
87
+		return false;
88
+	}
89
+
90
+	/**
91
+	 * Gets the path info
92
+	 *
93
+	 * @return array Array of path info segments
94
+	 */
95
+	public static function pathInfo()
96
+	{
97
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
98
+		if (!isset($server['PATH_INFO'])) {
99
+			return array();
100
+		}
101
+
102
+		$exploded = explode('/', $server['PATH_INFO']);
103
+
104
+		// filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts
105
+		// with a /
106
+		return array_values(array_filter($exploded));
107
+	}
108
+
109
+	/**
110
+	 * Gets the remote address of the web request
111
+	 * @return null|string
112
+	 */
113
+	public static function remoteAddress()
114
+	{
115
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
116
+
117
+		if (isset($server['REMOTE_ADDR'])) {
118
+			return $server['REMOTE_ADDR'];
119
+		}
120
+
121
+		return null;
122
+	}
123
+
124
+	/**
125
+	 * Gets the remote address of the web request
126
+	 * @return null|string
127
+	 */
128
+	public static function httpHost()
129
+	{
130
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
131
+
132
+		if (isset($server['HTTP_HOST'])) {
133
+			return $server['HTTP_HOST'];
134
+		}
135
+
136
+		return null;
137
+	}
138
+
139
+	/**
140
+	 * Gets the XFF header contents for the web request
141
+	 * @return null|string
142
+	 */
143
+	public static function forwardedAddress()
144
+	{
145
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
146
+
147
+		if (isset($server['HTTP_X_FORWARDED_FOR'])) {
148
+			return $server['HTTP_X_FORWARDED_FOR'];
149
+		}
150
+
151
+		return null;
152
+	}
153
+
154
+	/**
155
+	 * Sets the global state provider.
156
+	 *
157
+	 * Almost guaranteed this is not the method you want in production code.
158
+	 *
159
+	 * @param IGlobalStateProvider $globalState
160
+	 */
161
+	public static function setGlobalStateProvider($globalState)
162
+	{
163
+		self::$globalStateProvider = $globalState;
164
+	}
165
+
166
+	#region POST variables
167
+
168
+	/**
169
+	 * @param string $key
170
+	 *
171
+	 * @return null|string
172
+	 */
173
+	public static function postString($key)
174
+	{
175
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
176
+		if (!array_key_exists($key, $post)) {
177
+			return null;
178
+		}
179
+
180
+		if ($post[$key] === "") {
181
+			return null;
182
+		}
183
+
184
+		return (string)$post[$key];
185
+	}
186
+
187
+	/**
188
+	 * @param string $key
189
+	 *
190
+	 * @return null|string
191
+	 */
192
+	public static function postEmail($key)
193
+	{
194
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
195
+		if (!array_key_exists($key, $post)) {
196
+			return null;
197
+		}
198
+
199
+		$filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);
200
+
201
+		if ($filteredValue === false) {
202
+			return null;
203
+		}
204
+
205
+		return (string)$filteredValue;
206
+	}
207
+
208
+	/**
209
+	 * @param string $key
210
+	 *
211
+	 * @return int|null
212
+	 */
213
+	public static function postInt($key)
214
+	{
215
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
216
+		if (!array_key_exists($key, $post)) {
217
+			return null;
218
+		}
219
+
220
+		$filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
221
+
222
+		if ($filteredValue === null) {
223
+			return null;
224
+		}
225
+
226
+		return (int)$filteredValue;
227
+	}
228
+
229
+	/**
230
+	 * @param string $key
231
+	 *
232
+	 * @return bool
233
+	 */
234
+	public static function postBoolean($key)
235
+	{
236
+		$get = &self::$globalStateProvider->getPostSuperGlobal();
237
+		if (!array_key_exists($key, $get)) {
238
+			return false;
239
+		}
240
+
241
+		// presence of parameter only
242
+		if ($get[$key] === "") {
243
+			return true;
244
+		}
245
+
246
+		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
247
+			return false;
248
+		}
249
+
250
+		return true;
251
+	}
252
+
253
+	#endregion
254
+
255
+	#region GET variables
256
+
257
+	/**
258
+	 * @param string $key
259
+	 *
260
+	 * @return bool
261
+	 */
262
+	public static function getBoolean($key)
263
+	{
264
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
265
+		if (!array_key_exists($key, $get)) {
266
+			return false;
267
+		}
268
+
269
+		// presence of parameter only
270
+		if ($get[$key] === "") {
271
+			return true;
272
+		}
273
+
274
+		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
275
+			return false;
276
+		}
277
+
278
+		return true;
279
+	}
280
+
281
+	/**
282
+	 * @param string $key
283
+	 *
284
+	 * @return int|null
285
+	 */
286
+	public static function getInt($key)
287
+	{
288
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
289
+		if (!array_key_exists($key, $get)) {
290
+			return null;
291
+		}
292
+
293
+		$filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
294
+
295
+		if ($filteredValue === null) {
296
+			return null;
297
+		}
298
+
299
+		return (int)$filteredValue;
300
+	}
301
+
302
+	/**
303
+	 * @param string $key
304
+	 *
305
+	 * @return null|string
306
+	 */
307
+	public static function getString($key)
308
+	{
309
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
310
+		if (!array_key_exists($key, $get)) {
311
+			return null;
312
+		}
313
+
314
+		if ($get[$key] === "") {
315
+			return null;
316
+		}
317
+
318
+		return (string)$get[$key];
319
+	}
320
+
321
+	#endregion
322
+
323
+	/**
324
+	 * Sets the logged-in user to the specified user.
325
+	 *
326
+	 * @param User $user
327
+	 */
328
+	public static function setLoggedInUser(User $user)
329
+	{
330
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
331
+
332
+		$session['userID'] = $user->getId();
333
+		unset($session['partialLogin']);
334
+	}
335
+
336
+	/**
337
+	 * Sets the post-login redirect
338
+	 *
339
+	 * @param string|null $uri The URI to redirect to
340
+	 */
341
+	public static function setPostLoginRedirect($uri = null)
342
+	{
343
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
344
+
345
+		if ($uri === null) {
346
+			$uri = self::requestUri();
347
+		}
348
+
349
+		$session['returnTo'] = $uri;
350
+	}
351
+
352
+	/**
353
+	 * @return string|null
354
+	 */
355
+	public static function requestUri()
356
+	{
357
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
358
+
359
+		if (isset($server['REQUEST_URI'])) {
360
+			return $server['REQUEST_URI'];
361
+		}
362
+
363
+		return null;
364
+	}
365
+
366
+	/**
367
+	 * Clears the post-login redirect
368
+	 * @return string
369
+	 */
370
+	public static function clearPostLoginRedirect()
371
+	{
372
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
373
+		if (array_key_exists('returnTo', $session)) {
374
+			$path = $session['returnTo'];
375
+			unset($session['returnTo']);
376
+
377
+			return $path;
378
+		}
379
+
380
+		return null;
381
+	}
382
+
383
+	/**
384
+	 * @return string|null
385
+	 */
386
+	public static function serverName()
387
+	{
388
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
389
+
390
+		if (isset($server['SERVER_NAME'])) {
391
+			return $server['SERVER_NAME'];
392
+		}
393
+
394
+		return null;
395
+	}
396
+
397
+	/**
398
+	 * You probably only want to deal with this through SessionAlert.
399
+	 * @return void
400
+	 */
401
+	public static function clearSessionAlertData()
402
+	{
403
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
404
+		if (array_key_exists('alerts', $session)) {
405
+			unset($session['alerts']);
406
+		}
407
+	}
408
+
409
+	/**
410
+	 * You probably only want to deal with this through SessionAlert.
411
+	 *
412
+	 * @return string[]
413
+	 */
414
+	public static function getSessionAlertData()
415
+	{
416
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
417
+		if (array_key_exists('alerts', $session)) {
418
+			return $session['alerts'];
419
+		}
420
+
421
+		return array();
422
+	}
423
+
424
+	/**
425
+	 * You probably only want to deal with this through SessionAlert.
426
+	 *
427
+	 * @param string[] $data
428
+	 */
429
+	public static function setSessionAlertData($data)
430
+	{
431
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
432
+		$session['alerts'] = $data;
433
+	}
434
+
435
+	/**
436
+	 * You probably only want to deal with this through TokenManager.
437
+	 *
438
+	 * @return string[]
439
+	 */
440
+	public static function getSessionTokenData()
441
+	{
442
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
443
+		if (array_key_exists('tokens', $session)) {
444
+			return $session['tokens'];
445
+		}
446
+
447
+		return array();
448
+	}
449
+
450
+	/**
451
+	 * You probably only want to deal with this through TokenManager.
452
+	 *
453
+	 * @param string[] $data
454
+	 */
455
+	public static function setSessionTokenData($data)
456
+	{
457
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
458
+		$session['tokens'] = $data;
459
+	}
460
+
461
+	/**
462
+	 * @param string $key
463
+	 *
464
+	 * @return mixed
465
+	 */
466
+	public static function getSessionContext($key)
467
+	{
468
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
469
+
470
+		if (!isset($session['context'])) {
471
+			$session['context'] = array();
472
+		}
473
+
474
+		if (!isset($session['context'][$key])) {
475
+			return null;
476
+		}
477
+
478
+		return $session['context'][$key];
479
+	}
480
+
481
+	/**
482
+	 * @param string $key
483
+	 * @param mixed  $data
484
+	 */
485
+	public static function setSessionContext($key, $data)
486
+	{
487
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
488
+
489
+		if (!isset($session['context'])) {
490
+			$session['context'] = array();
491
+		}
492
+
493
+		$session['context'][$key] = $data;
494
+	}
495
+
496
+	/**
497
+	 * @return int|null
498
+	 */
499
+	public static function getSessionUserId()
500
+	{
501
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
502
+
503
+		return isset($session['userID']) ? (int)$session['userID'] : null;
504
+	}
505
+
506
+	/**
507
+	 * @param User $user
508
+	 */
509
+	public static function setOAuthPartialLogin(User $user)
510
+	{
511
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
512
+		$session['oauthPartialLogin'] = $user->getId();
513
+	}
514
+
515
+	/**
516
+	 * @return int|null
517
+	 */
518
+	public static function getOAuthPartialLogin()
519
+	{
520
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
521
+
522
+		return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null;
523
+	}
524
+
525
+	public static function setAuthPartialLogin($userId, $stage)
526
+	{
527
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
528
+		$session['authPartialLoginId'] = $userId;
529
+		$session['authPartialLoginStage'] = $stage;
530
+	}
531
+
532
+	public static function getAuthPartialLogin()
533
+	{
534
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
535
+
536
+		$userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null;
537
+		$stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null;
538
+
539
+		return array($userId, $stage);
540
+	}
541
+
542
+	public static function clearAuthPartialLogin()
543
+	{
544
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
545
+		unset($session['authPartialLoginId']);
546
+		unset($session['authPartialLoginStage']);
547
+	}
548
+
549
+	/**
550
+	 * @return null|string
551
+	 */
552
+	public static function userAgent()
553
+	{
554
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
555
+
556
+		if (isset($server['HTTP_USER_AGENT'])) {
557
+			return $server['HTTP_USER_AGENT'];
558
+		}
559
+
560
+		return null;
561
+	}
562
+
563
+	/**
564
+	 * @return null|string
565
+	 */
566
+	public static function scriptName()
567
+	{
568
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
569
+
570
+		if (isset($server['SCRIPT_NAME'])) {
571
+			return $server['SCRIPT_NAME'];
572
+		}
573
+
574
+		return null;
575
+	}
576
+
577
+	/**
578
+	 * @return null|string
579
+	 */
580
+	public static function origin()
581
+	{
582
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
583
+
584
+		if (isset($server['HTTP_ORIGIN'])) {
585
+			return $server['HTTP_ORIGIN'];
586
+		}
587
+
588
+		return null;
589
+	}
590
+
591
+	public static function testSiteNoticeCookieValue($expectedHash)
592
+	{
593
+		$cookie = &self::$globalStateProvider->getCookieSuperGlobal();
594
+
595
+		if(isset($cookie['sitenotice'])) {
596
+			return $cookie['sitenotice'] === $expectedHash;
597
+		}
598
+
599
+		return false;
600
+	}
601 601
 }
Please login to merge, or discard this patch.
includes/RequestList.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
  */
17 17
 class RequestList
18 18
 {
19
-    public $requests;
20
-    public $showPrivateData;
21
-    public $dataClearEmail;
22
-    public $dataClearIp;
23
-    public $relatedEmailRequests;
24
-    public $relatedIpRequests;
25
-    public $requestTrustedIp;
26
-    public $canBan;
27
-    public $canBreakReservation;
28
-    public $userList;
19
+	public $requests;
20
+	public $showPrivateData;
21
+	public $dataClearEmail;
22
+	public $dataClearIp;
23
+	public $relatedEmailRequests;
24
+	public $relatedIpRequests;
25
+	public $requestTrustedIp;
26
+	public $canBan;
27
+	public $canBreakReservation;
28
+	public $userList;
29 29
 }
Please login to merge, or discard this patch.
includes/Router/ApiRequestRouter.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -22,49 +22,49 @@
 block discarded – undo
22 22
 
23 23
 class ApiRequestRouter implements IRequestRouter
24 24
 {
25
-    /**
26
-     * @return string[]
27
-     */
28
-    public static function getActionList()
29
-    {
30
-        return array("count", "status", "stats", "help", "monitor");
31
-    }
25
+	/**
26
+	 * @return string[]
27
+	 */
28
+	public static function getActionList()
29
+	{
30
+		return array("count", "status", "stats", "help", "monitor");
31
+	}
32 32
 
33
-    /**
34
-     * @return IRoutedTask
35
-     * @throws Exception
36
-     */
37
-    public function route()
38
-    {
39
-        $requestAction = WebRequest::getString('action');
33
+	/**
34
+	 * @return IRoutedTask
35
+	 * @throws Exception
36
+	 */
37
+	public function route()
38
+	{
39
+		$requestAction = WebRequest::getString('action');
40 40
 
41
-        switch ($requestAction) {
42
-            case "count":
43
-                $result = new CountAction();
44
-                break;
45
-            case "status":
46
-                $result = new StatusAction();
47
-                break;
48
-            case "stats":
49
-                $result = new StatsAction();
50
-                break;
51
-            case "help":
52
-                $result = new HelpAction();
53
-                break;
54
-            case "monitor":
55
-                $result = new MonitorAction();
56
-                break;
57
-            case "users":
58
-                $result = new JsUsersAction();
59
-                break;
60
-            case "templates":
61
-                $result = new JsTemplateConfirmsAction();
62
-                break;
63
-            default:
64
-                $result = new UnknownAction();
65
-                break;
66
-        }
41
+		switch ($requestAction) {
42
+			case "count":
43
+				$result = new CountAction();
44
+				break;
45
+			case "status":
46
+				$result = new StatusAction();
47
+				break;
48
+			case "stats":
49
+				$result = new StatsAction();
50
+				break;
51
+			case "help":
52
+				$result = new HelpAction();
53
+				break;
54
+			case "monitor":
55
+				$result = new MonitorAction();
56
+				break;
57
+			case "users":
58
+				$result = new JsUsersAction();
59
+				break;
60
+			case "templates":
61
+				$result = new JsTemplateConfirmsAction();
62
+				break;
63
+			default:
64
+				$result = new UnknownAction();
65
+				break;
66
+		}
67 67
 
68
-        return $result;
69
-    }
68
+		return $result;
69
+	}
70 70
 }
Please login to merge, or discard this patch.
includes/Router/OAuthRequestRouter.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
includes/Router/RequestRouter.php 1 patch
Indentation   +441 added lines, -441 removed lines patch added patch discarded remove patch
@@ -63,445 +63,445 @@
 block discarded – undo
63 63
  */
64 64
 class RequestRouter implements IRequestRouter
65 65
 {
66
-    /**
67
-     * This is the core routing table for the application. The basic idea is:
68
-     *
69
-     *      array(
70
-     *          "foo" =>
71
-     *              array(
72
-     *                  "class"   => PageFoo::class,
73
-     *                  "actions" => array("bar", "other")
74
-     *              ),
75
-     * );
76
-     *
77
-     * Things to note:
78
-     *     - If no page is requested, we go to PageMain. PageMain can't have actions defined.
79
-     *
80
-     *     - If a page is defined and requested, but no action is requested, go to that page's main() method
81
-     *     - If a page is defined and requested, and an action is defined and requested, go to that action's method.
82
-     *     - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()
83
-     *       method.
84
-     *     - If a page is NOT defined and requested, go to Page404 and it's main() method.
85
-     *
86
-     *     - Query parameters are ignored.
87
-     *
88
-     * The key point here is request routing with validation that this is allowed, before we start hitting the
89
-     * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested
90
-     * before we start calling random methods through the web UI.
91
-     *
92
-     * Examples:
93
-     * /internal.php                => returns instance of PageMain, routed to main()
94
-     * /internal.php?query          => returns instance of PageMain, routed to main()
95
-     * /internal.php/foo            => returns instance of PageFoo, routed to main()
96
-     * /internal.php/foo?query      => returns instance of PageFoo, routed to main()
97
-     * /internal.php/foo/bar        => returns instance of PageFoo, routed to bar()
98
-     * /internal.php/foo/bar?query  => returns instance of PageFoo, routed to bar()
99
-     * /internal.php/foo/baz        => returns instance of Page404, routed to main()
100
-     * /internal.php/foo/baz?query  => returns instance of Page404, routed to main()
101
-     * /internal.php/bar            => returns instance of Page404, routed to main()
102
-     * /internal.php/bar?query      => returns instance of Page404, routed to main()
103
-     * /internal.php/bar/baz        => returns instance of Page404, routed to main()
104
-     * /internal.php/bar/baz?query  => returns instance of Page404, routed to main()
105
-     *
106
-     * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need
107
-     * to change the key, then you'll likely have to update a lot of files.
108
-     *
109
-     * @var array
110
-     */
111
-    private $routeMap = array(
112
-
113
-        //////////////////////////////////////////////////////////////////////////////////////////////////
114
-        // Login and registration
115
-        'logout'                      =>
116
-            array(
117
-                'class'   => PageLogout::class,
118
-                'actions' => array(),
119
-            ),
120
-        'login'                       =>
121
-            array(
122
-                'class'   => PagePasswordLogin::class,
123
-                'actions' => array(),
124
-            ),
125
-        'login/otp'                   =>
126
-            array(
127
-                'class'   => PageOtpLogin::class,
128
-                'actions' => array(),
129
-            ),
130
-        'login/u2f'                   =>
131
-            array(
132
-                'class'   => PageU2FLogin::class,
133
-                'actions' => array(),
134
-            ),
135
-        'forgotPassword'              =>
136
-            array(
137
-                'class'   => PageForgotPassword::class,
138
-                'actions' => array('reset'),
139
-            ),
140
-        'register'                    =>
141
-            array(
142
-                'class'   => PageRegisterOption::class,
143
-                'actions' => array(),
144
-            ),
145
-        'register/standard'           =>
146
-            array(
147
-                'class'   => PageRegisterStandard::class,
148
-                'actions' => array('done'),
149
-            ),
150
-
151
-        //////////////////////////////////////////////////////////////////////////////////////////////////
152
-        // Discovery
153
-        'search'                      =>
154
-            array(
155
-                'class'   => PageSearch::class,
156
-                'actions' => array(),
157
-            ),
158
-        'logs'                        =>
159
-            array(
160
-                'class'   => PageLog::class,
161
-                'actions' => array(),
162
-            ),
163
-
164
-        //////////////////////////////////////////////////////////////////////////////////////////////////
165
-        // Administration
166
-        'bans'                        =>
167
-            array(
168
-                'class'   => PageBan::class,
169
-                'actions' => array('set', 'remove'),
170
-            ),
171
-        'userManagement'              =>
172
-            array(
173
-                'class'   => PageUserManagement::class,
174
-                'actions' => array(
175
-                    'approve',
176
-                    'decline',
177
-                    'rename',
178
-                    'editUser',
179
-                    'suspend',
180
-                    'editRoles',
181
-                ),
182
-            ),
183
-        'siteNotice'                  =>
184
-            array(
185
-                'class'   => PageSiteNotice::class,
186
-                'actions' => array(),
187
-            ),
188
-        'emailManagement'             =>
189
-            array(
190
-                'class'   => PageEmailManagement::class,
191
-                'actions' => array('create', 'edit', 'view'),
192
-            ),
193
-        'jobQueue'                    =>
194
-            array(
195
-                'class'   => PageJobQueue::class,
196
-                'actions' => array('acknowledge', 'requeue', 'view', 'all'),
197
-            ),
198
-
199
-        //////////////////////////////////////////////////////////////////////////////////////////////////
200
-        // Personal preferences
201
-        'preferences'                 =>
202
-            array(
203
-                'class'   => PagePreferences::class,
204
-                'actions' => array(
205
-                    'refreshOAuth'
206
-                ),
207
-            ),
208
-        'changePassword'              =>
209
-            array(
210
-                'class'   => PageChangePassword::class,
211
-                'actions' => array(),
212
-            ),
213
-        'multiFactor'                 =>
214
-            array(
215
-                'class'   => PageMultiFactor::class,
216
-                'actions' => array(
217
-                    'scratch',
218
-                    'enableYubikeyOtp',
219
-                    'disableYubikeyOtp',
220
-                    'enableTotp',
221
-                    'disableTotp',
222
-                    'enableU2F',
223
-                    'disableU2F',
224
-                ),
225
-            ),
226
-        'oauth'                       =>
227
-            array(
228
-                'class'   => PageOAuth::class,
229
-                'actions' => array('detach', 'attach'),
230
-            ),
231
-        'oauth/callback'              =>
232
-            array(
233
-                'class'   => PageOAuthCallback::class,
234
-                'actions' => array('authorise', 'create'),
235
-            ),
236
-
237
-        //////////////////////////////////////////////////////////////////////////////////////////////////
238
-        // Welcomer configuration
239
-        'welcomeTemplates'            =>
240
-            array(
241
-                'class'   => PageWelcomeTemplateManagement::class,
242
-                'actions' => array('select', 'edit', 'delete', 'add', 'view'),
243
-            ),
244
-
245
-        //////////////////////////////////////////////////////////////////////////////////////////////////
246
-        // Statistics
247
-        'statistics'                  =>
248
-            array(
249
-                'class'   => StatsMain::class,
250
-                'actions' => array(),
251
-            ),
252
-        'statistics/fastCloses'       =>
253
-            array(
254
-                'class'   => StatsFastCloses::class,
255
-                'actions' => array(),
256
-            ),
257
-        'statistics/inactiveUsers'    =>
258
-            array(
259
-                'class'   => StatsInactiveUsers::class,
260
-                'actions' => array(),
261
-            ),
262
-        'statistics/monthlyStats'     =>
263
-            array(
264
-                'class'   => StatsMonthlyStats::class,
265
-                'actions' => array(),
266
-            ),
267
-        'statistics/reservedRequests' =>
268
-            array(
269
-                'class'   => StatsReservedRequests::class,
270
-                'actions' => array(),
271
-            ),
272
-        'statistics/templateStats'    =>
273
-            array(
274
-                'class'   => StatsTemplateStats::class,
275
-                'actions' => array(),
276
-            ),
277
-        'statistics/topCreators'      =>
278
-            array(
279
-                'class'   => StatsTopCreators::class,
280
-                'actions' => array(),
281
-            ),
282
-        'statistics/users'            =>
283
-            array(
284
-                'class'   => StatsUsers::class,
285
-                'actions' => array('detail'),
286
-            ),
287
-
288
-        //////////////////////////////////////////////////////////////////////////////////////////////////
289
-        // Zoom page
290
-        'viewRequest'                 =>
291
-            array(
292
-                'class'   => PageViewRequest::class,
293
-                'actions' => array(),
294
-            ),
295
-        'viewRequest/reserve'         =>
296
-            array(
297
-                'class'   => PageReservation::class,
298
-                'actions' => array(),
299
-            ),
300
-        'viewRequest/breakReserve'    =>
301
-            array(
302
-                'class'   => PageBreakReservation::class,
303
-                'actions' => array(),
304
-            ),
305
-        'viewRequest/defer'           =>
306
-            array(
307
-                'class'   => PageDeferRequest::class,
308
-                'actions' => array(),
309
-            ),
310
-        'viewRequest/comment'         =>
311
-            array(
312
-                'class'   => PageComment::class,
313
-                'actions' => array(),
314
-            ),
315
-        'viewRequest/sendToUser'      =>
316
-            array(
317
-                'class'   => PageSendToUser::class,
318
-                'actions' => array(),
319
-            ),
320
-        'viewRequest/close'           =>
321
-            array(
322
-                'class'   => PageCloseRequest::class,
323
-                'actions' => array(),
324
-            ),
325
-        'viewRequest/create'          =>
326
-            array(
327
-                'class'   => PageCreateRequest::class,
328
-                'actions' => array(),
329
-            ),
330
-        'viewRequest/drop'            =>
331
-            array(
332
-                'class'   => PageDropRequest::class,
333
-                'actions' => array(),
334
-            ),
335
-        'viewRequest/custom'          =>
336
-            array(
337
-                'class'   => PageCustomClose::class,
338
-                'actions' => array(),
339
-            ),
340
-        'editComment'                 =>
341
-            array(
342
-                'class'   => PageEditComment::class,
343
-                'actions' => array(),
344
-            ),
345
-
346
-        //////////////////////////////////////////////////////////////////////////////////////////////////
347
-        // Misc stuff
348
-        'team'                        =>
349
-            array(
350
-                'class'   => PageTeam::class,
351
-                'actions' => array(),
352
-            ),
353
-        'requestList'                 =>
354
-            array(
355
-                'class'   => PageExpandedRequestList::class,
356
-                'actions' => array(),
357
-            ),
358
-        'xffdemo'                     =>
359
-            array(
360
-                'class'   => PageXffDemo::class,
361
-                'actions' => array(),
362
-            ),
363
-    );
364
-
365
-    /**
366
-     * @return IRoutedTask
367
-     * @throws Exception
368
-     */
369
-    final public function route()
370
-    {
371
-        $pathInfo = WebRequest::pathInfo();
372
-
373
-        list($pageClass, $action) = $this->getRouteFromPath($pathInfo);
374
-
375
-        /** @var IRoutedTask $page */
376
-        $page = new $pageClass();
377
-
378
-        // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so
379
-        // let's use our own.
380
-        if (!($page instanceof IRoutedTask)) {
381
-            throw new Exception('Expected a page, but this is not a page.');
382
-        }
383
-
384
-        // 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
385
-        // inherits PageBase and has been created from the routing map.
386
-        $page->setRoute($action);
387
-
388
-        return $page;
389
-    }
390
-
391
-    /**
392
-     * @param $pathInfo
393
-     *
394
-     * @return array
395
-     */
396
-    protected function getRouteFromPath($pathInfo)
397
-    {
398
-        if (count($pathInfo) === 0) {
399
-            // No pathInfo, so no page to load. Load the main page.
400
-            return $this->getDefaultRoute();
401
-        }
402
-        elseif (count($pathInfo) === 1) {
403
-            // Exactly one path info segment, it's got to be a page.
404
-            $classSegment = $pathInfo[0];
405
-
406
-            return $this->routeSinglePathSegment($classSegment);
407
-        }
408
-
409
-        // OK, we have two or more segments now.
410
-        if (count($pathInfo) > 2) {
411
-            // Let's handle more than two, and collapse it down into two.
412
-            $requestedAction = array_pop($pathInfo);
413
-            $classSegment = implode('/', $pathInfo);
414
-        }
415
-        else {
416
-            // Two path info segments.
417
-            $classSegment = $pathInfo[0];
418
-            $requestedAction = $pathInfo[1];
419
-        }
420
-
421
-        $routeMap = $this->routePathSegments($classSegment, $requestedAction);
422
-
423
-        if ($routeMap[0] === Page404::class) {
424
-            $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);
425
-        }
426
-
427
-        return $routeMap;
428
-    }
429
-
430
-    /**
431
-     * @param $classSegment
432
-     *
433
-     * @return array
434
-     */
435
-    final protected function routeSinglePathSegment($classSegment)
436
-    {
437
-        $routeMap = $this->getRouteMap();
438
-        if (array_key_exists($classSegment, $routeMap)) {
439
-            // Route exists, but we don't have an action in path info, so default to main.
440
-            $pageClass = $routeMap[$classSegment]['class'];
441
-            $action = 'main';
442
-
443
-            return array($pageClass, $action);
444
-        }
445
-        else {
446
-            // Doesn't exist in map. Fall back to 404
447
-            $pageClass = Page404::class;
448
-            $action = "main";
449
-
450
-            return array($pageClass, $action);
451
-        }
452
-    }
453
-
454
-    /**
455
-     * @param $classSegment
456
-     * @param $requestedAction
457
-     *
458
-     * @return array
459
-     */
460
-    final protected function routePathSegments($classSegment, $requestedAction)
461
-    {
462
-        $routeMap = $this->getRouteMap();
463
-        if (array_key_exists($classSegment, $routeMap)) {
464
-            // Route exists, but we don't have an action in path info, so default to main.
465
-
466
-            if (isset($routeMap[$classSegment]['actions'])
467
-                && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false
468
-            ) {
469
-                // Action exists in allowed action list. Allow both the page and the action
470
-                $pageClass = $routeMap[$classSegment]['class'];
471
-                $action = $requestedAction;
472
-
473
-                return array($pageClass, $action);
474
-            }
475
-            else {
476
-                // Valid page, invalid action. 404 our way out.
477
-                $pageClass = Page404::class;
478
-                $action = 'main';
479
-
480
-                return array($pageClass, $action);
481
-            }
482
-        }
483
-        else {
484
-            // Class doesn't exist in map. Fall back to 404
485
-            $pageClass = Page404::class;
486
-            $action = 'main';
487
-
488
-            return array($pageClass, $action);
489
-        }
490
-    }
491
-
492
-    /**
493
-     * @return array
494
-     */
495
-    protected function getRouteMap()
496
-    {
497
-        return $this->routeMap;
498
-    }
499
-
500
-    /**
501
-     * @return array
502
-     */
503
-    protected function getDefaultRoute()
504
-    {
505
-        return array(PageMain::class, "main");
506
-    }
66
+	/**
67
+	 * This is the core routing table for the application. The basic idea is:
68
+	 *
69
+	 *      array(
70
+	 *          "foo" =>
71
+	 *              array(
72
+	 *                  "class"   => PageFoo::class,
73
+	 *                  "actions" => array("bar", "other")
74
+	 *              ),
75
+	 * );
76
+	 *
77
+	 * Things to note:
78
+	 *     - If no page is requested, we go to PageMain. PageMain can't have actions defined.
79
+	 *
80
+	 *     - If a page is defined and requested, but no action is requested, go to that page's main() method
81
+	 *     - If a page is defined and requested, and an action is defined and requested, go to that action's method.
82
+	 *     - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()
83
+	 *       method.
84
+	 *     - If a page is NOT defined and requested, go to Page404 and it's main() method.
85
+	 *
86
+	 *     - Query parameters are ignored.
87
+	 *
88
+	 * The key point here is request routing with validation that this is allowed, before we start hitting the
89
+	 * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested
90
+	 * before we start calling random methods through the web UI.
91
+	 *
92
+	 * Examples:
93
+	 * /internal.php                => returns instance of PageMain, routed to main()
94
+	 * /internal.php?query          => returns instance of PageMain, routed to main()
95
+	 * /internal.php/foo            => returns instance of PageFoo, routed to main()
96
+	 * /internal.php/foo?query      => returns instance of PageFoo, routed to main()
97
+	 * /internal.php/foo/bar        => returns instance of PageFoo, routed to bar()
98
+	 * /internal.php/foo/bar?query  => returns instance of PageFoo, routed to bar()
99
+	 * /internal.php/foo/baz        => returns instance of Page404, routed to main()
100
+	 * /internal.php/foo/baz?query  => returns instance of Page404, routed to main()
101
+	 * /internal.php/bar            => returns instance of Page404, routed to main()
102
+	 * /internal.php/bar?query      => returns instance of Page404, routed to main()
103
+	 * /internal.php/bar/baz        => returns instance of Page404, routed to main()
104
+	 * /internal.php/bar/baz?query  => returns instance of Page404, routed to main()
105
+	 *
106
+	 * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need
107
+	 * to change the key, then you'll likely have to update a lot of files.
108
+	 *
109
+	 * @var array
110
+	 */
111
+	private $routeMap = array(
112
+
113
+		//////////////////////////////////////////////////////////////////////////////////////////////////
114
+		// Login and registration
115
+		'logout'                      =>
116
+			array(
117
+				'class'   => PageLogout::class,
118
+				'actions' => array(),
119
+			),
120
+		'login'                       =>
121
+			array(
122
+				'class'   => PagePasswordLogin::class,
123
+				'actions' => array(),
124
+			),
125
+		'login/otp'                   =>
126
+			array(
127
+				'class'   => PageOtpLogin::class,
128
+				'actions' => array(),
129
+			),
130
+		'login/u2f'                   =>
131
+			array(
132
+				'class'   => PageU2FLogin::class,
133
+				'actions' => array(),
134
+			),
135
+		'forgotPassword'              =>
136
+			array(
137
+				'class'   => PageForgotPassword::class,
138
+				'actions' => array('reset'),
139
+			),
140
+		'register'                    =>
141
+			array(
142
+				'class'   => PageRegisterOption::class,
143
+				'actions' => array(),
144
+			),
145
+		'register/standard'           =>
146
+			array(
147
+				'class'   => PageRegisterStandard::class,
148
+				'actions' => array('done'),
149
+			),
150
+
151
+		//////////////////////////////////////////////////////////////////////////////////////////////////
152
+		// Discovery
153
+		'search'                      =>
154
+			array(
155
+				'class'   => PageSearch::class,
156
+				'actions' => array(),
157
+			),
158
+		'logs'                        =>
159
+			array(
160
+				'class'   => PageLog::class,
161
+				'actions' => array(),
162
+			),
163
+
164
+		//////////////////////////////////////////////////////////////////////////////////////////////////
165
+		// Administration
166
+		'bans'                        =>
167
+			array(
168
+				'class'   => PageBan::class,
169
+				'actions' => array('set', 'remove'),
170
+			),
171
+		'userManagement'              =>
172
+			array(
173
+				'class'   => PageUserManagement::class,
174
+				'actions' => array(
175
+					'approve',
176
+					'decline',
177
+					'rename',
178
+					'editUser',
179
+					'suspend',
180
+					'editRoles',
181
+				),
182
+			),
183
+		'siteNotice'                  =>
184
+			array(
185
+				'class'   => PageSiteNotice::class,
186
+				'actions' => array(),
187
+			),
188
+		'emailManagement'             =>
189
+			array(
190
+				'class'   => PageEmailManagement::class,
191
+				'actions' => array('create', 'edit', 'view'),
192
+			),
193
+		'jobQueue'                    =>
194
+			array(
195
+				'class'   => PageJobQueue::class,
196
+				'actions' => array('acknowledge', 'requeue', 'view', 'all'),
197
+			),
198
+
199
+		//////////////////////////////////////////////////////////////////////////////////////////////////
200
+		// Personal preferences
201
+		'preferences'                 =>
202
+			array(
203
+				'class'   => PagePreferences::class,
204
+				'actions' => array(
205
+					'refreshOAuth'
206
+				),
207
+			),
208
+		'changePassword'              =>
209
+			array(
210
+				'class'   => PageChangePassword::class,
211
+				'actions' => array(),
212
+			),
213
+		'multiFactor'                 =>
214
+			array(
215
+				'class'   => PageMultiFactor::class,
216
+				'actions' => array(
217
+					'scratch',
218
+					'enableYubikeyOtp',
219
+					'disableYubikeyOtp',
220
+					'enableTotp',
221
+					'disableTotp',
222
+					'enableU2F',
223
+					'disableU2F',
224
+				),
225
+			),
226
+		'oauth'                       =>
227
+			array(
228
+				'class'   => PageOAuth::class,
229
+				'actions' => array('detach', 'attach'),
230
+			),
231
+		'oauth/callback'              =>
232
+			array(
233
+				'class'   => PageOAuthCallback::class,
234
+				'actions' => array('authorise', 'create'),
235
+			),
236
+
237
+		//////////////////////////////////////////////////////////////////////////////////////////////////
238
+		// Welcomer configuration
239
+		'welcomeTemplates'            =>
240
+			array(
241
+				'class'   => PageWelcomeTemplateManagement::class,
242
+				'actions' => array('select', 'edit', 'delete', 'add', 'view'),
243
+			),
244
+
245
+		//////////////////////////////////////////////////////////////////////////////////////////////////
246
+		// Statistics
247
+		'statistics'                  =>
248
+			array(
249
+				'class'   => StatsMain::class,
250
+				'actions' => array(),
251
+			),
252
+		'statistics/fastCloses'       =>
253
+			array(
254
+				'class'   => StatsFastCloses::class,
255
+				'actions' => array(),
256
+			),
257
+		'statistics/inactiveUsers'    =>
258
+			array(
259
+				'class'   => StatsInactiveUsers::class,
260
+				'actions' => array(),
261
+			),
262
+		'statistics/monthlyStats'     =>
263
+			array(
264
+				'class'   => StatsMonthlyStats::class,
265
+				'actions' => array(),
266
+			),
267
+		'statistics/reservedRequests' =>
268
+			array(
269
+				'class'   => StatsReservedRequests::class,
270
+				'actions' => array(),
271
+			),
272
+		'statistics/templateStats'    =>
273
+			array(
274
+				'class'   => StatsTemplateStats::class,
275
+				'actions' => array(),
276
+			),
277
+		'statistics/topCreators'      =>
278
+			array(
279
+				'class'   => StatsTopCreators::class,
280
+				'actions' => array(),
281
+			),
282
+		'statistics/users'            =>
283
+			array(
284
+				'class'   => StatsUsers::class,
285
+				'actions' => array('detail'),
286
+			),
287
+
288
+		//////////////////////////////////////////////////////////////////////////////////////////////////
289
+		// Zoom page
290
+		'viewRequest'                 =>
291
+			array(
292
+				'class'   => PageViewRequest::class,
293
+				'actions' => array(),
294
+			),
295
+		'viewRequest/reserve'         =>
296
+			array(
297
+				'class'   => PageReservation::class,
298
+				'actions' => array(),
299
+			),
300
+		'viewRequest/breakReserve'    =>
301
+			array(
302
+				'class'   => PageBreakReservation::class,
303
+				'actions' => array(),
304
+			),
305
+		'viewRequest/defer'           =>
306
+			array(
307
+				'class'   => PageDeferRequest::class,
308
+				'actions' => array(),
309
+			),
310
+		'viewRequest/comment'         =>
311
+			array(
312
+				'class'   => PageComment::class,
313
+				'actions' => array(),
314
+			),
315
+		'viewRequest/sendToUser'      =>
316
+			array(
317
+				'class'   => PageSendToUser::class,
318
+				'actions' => array(),
319
+			),
320
+		'viewRequest/close'           =>
321
+			array(
322
+				'class'   => PageCloseRequest::class,
323
+				'actions' => array(),
324
+			),
325
+		'viewRequest/create'          =>
326
+			array(
327
+				'class'   => PageCreateRequest::class,
328
+				'actions' => array(),
329
+			),
330
+		'viewRequest/drop'            =>
331
+			array(
332
+				'class'   => PageDropRequest::class,
333
+				'actions' => array(),
334
+			),
335
+		'viewRequest/custom'          =>
336
+			array(
337
+				'class'   => PageCustomClose::class,
338
+				'actions' => array(),
339
+			),
340
+		'editComment'                 =>
341
+			array(
342
+				'class'   => PageEditComment::class,
343
+				'actions' => array(),
344
+			),
345
+
346
+		//////////////////////////////////////////////////////////////////////////////////////////////////
347
+		// Misc stuff
348
+		'team'                        =>
349
+			array(
350
+				'class'   => PageTeam::class,
351
+				'actions' => array(),
352
+			),
353
+		'requestList'                 =>
354
+			array(
355
+				'class'   => PageExpandedRequestList::class,
356
+				'actions' => array(),
357
+			),
358
+		'xffdemo'                     =>
359
+			array(
360
+				'class'   => PageXffDemo::class,
361
+				'actions' => array(),
362
+			),
363
+	);
364
+
365
+	/**
366
+	 * @return IRoutedTask
367
+	 * @throws Exception
368
+	 */
369
+	final public function route()
370
+	{
371
+		$pathInfo = WebRequest::pathInfo();
372
+
373
+		list($pageClass, $action) = $this->getRouteFromPath($pathInfo);
374
+
375
+		/** @var IRoutedTask $page */
376
+		$page = new $pageClass();
377
+
378
+		// Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so
379
+		// let's use our own.
380
+		if (!($page instanceof IRoutedTask)) {
381
+			throw new Exception('Expected a page, but this is not a page.');
382
+		}
383
+
384
+		// 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
385
+		// inherits PageBase and has been created from the routing map.
386
+		$page->setRoute($action);
387
+
388
+		return $page;
389
+	}
390
+
391
+	/**
392
+	 * @param $pathInfo
393
+	 *
394
+	 * @return array
395
+	 */
396
+	protected function getRouteFromPath($pathInfo)
397
+	{
398
+		if (count($pathInfo) === 0) {
399
+			// No pathInfo, so no page to load. Load the main page.
400
+			return $this->getDefaultRoute();
401
+		}
402
+		elseif (count($pathInfo) === 1) {
403
+			// Exactly one path info segment, it's got to be a page.
404
+			$classSegment = $pathInfo[0];
405
+
406
+			return $this->routeSinglePathSegment($classSegment);
407
+		}
408
+
409
+		// OK, we have two or more segments now.
410
+		if (count($pathInfo) > 2) {
411
+			// Let's handle more than two, and collapse it down into two.
412
+			$requestedAction = array_pop($pathInfo);
413
+			$classSegment = implode('/', $pathInfo);
414
+		}
415
+		else {
416
+			// Two path info segments.
417
+			$classSegment = $pathInfo[0];
418
+			$requestedAction = $pathInfo[1];
419
+		}
420
+
421
+		$routeMap = $this->routePathSegments($classSegment, $requestedAction);
422
+
423
+		if ($routeMap[0] === Page404::class) {
424
+			$routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);
425
+		}
426
+
427
+		return $routeMap;
428
+	}
429
+
430
+	/**
431
+	 * @param $classSegment
432
+	 *
433
+	 * @return array
434
+	 */
435
+	final protected function routeSinglePathSegment($classSegment)
436
+	{
437
+		$routeMap = $this->getRouteMap();
438
+		if (array_key_exists($classSegment, $routeMap)) {
439
+			// Route exists, but we don't have an action in path info, so default to main.
440
+			$pageClass = $routeMap[$classSegment]['class'];
441
+			$action = 'main';
442
+
443
+			return array($pageClass, $action);
444
+		}
445
+		else {
446
+			// Doesn't exist in map. Fall back to 404
447
+			$pageClass = Page404::class;
448
+			$action = "main";
449
+
450
+			return array($pageClass, $action);
451
+		}
452
+	}
453
+
454
+	/**
455
+	 * @param $classSegment
456
+	 * @param $requestedAction
457
+	 *
458
+	 * @return array
459
+	 */
460
+	final protected function routePathSegments($classSegment, $requestedAction)
461
+	{
462
+		$routeMap = $this->getRouteMap();
463
+		if (array_key_exists($classSegment, $routeMap)) {
464
+			// Route exists, but we don't have an action in path info, so default to main.
465
+
466
+			if (isset($routeMap[$classSegment]['actions'])
467
+				&& array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false
468
+			) {
469
+				// Action exists in allowed action list. Allow both the page and the action
470
+				$pageClass = $routeMap[$classSegment]['class'];
471
+				$action = $requestedAction;
472
+
473
+				return array($pageClass, $action);
474
+			}
475
+			else {
476
+				// Valid page, invalid action. 404 our way out.
477
+				$pageClass = Page404::class;
478
+				$action = 'main';
479
+
480
+				return array($pageClass, $action);
481
+			}
482
+		}
483
+		else {
484
+			// Class doesn't exist in map. Fall back to 404
485
+			$pageClass = Page404::class;
486
+			$action = 'main';
487
+
488
+			return array($pageClass, $action);
489
+		}
490
+	}
491
+
492
+	/**
493
+	 * @return array
494
+	 */
495
+	protected function getRouteMap()
496
+	{
497
+		return $this->routeMap;
498
+	}
499
+
500
+	/**
501
+	 * @return array
502
+	 */
503
+	protected function getDefaultRoute()
504
+	{
505
+		return array(PageMain::class, "main");
506
+	}
507 507
 }
Please login to merge, or discard this patch.
includes/ApplicationBase.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -25,150 +25,150 @@
 block discarded – undo
25 25
 
26 26
 abstract class ApplicationBase
27 27
 {
28
-    private $configuration;
29
-
30
-    public function __construct(SiteConfiguration $configuration)
31
-    {
32
-        $this->configuration = $configuration;
33
-    }
34
-
35
-    /**
36
-     * Application entry point.
37
-     *
38
-     * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
-     */
40
-    public function run()
41
-    {
42
-        try {
43
-            if ($this->setupEnvironment()) {
44
-                $this->main();
45
-            }
46
-        }
47
-        catch (Exception $ex) {
48
-            print $ex->getMessage();
49
-        }
50
-        finally {
51
-            $this->cleanupEnvironment();
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Environment setup
57
-     *
58
-     * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
-     * and shut down prematurely.
60
-     *
61
-     * @return bool
62
-     * @throws EnvironmentException
63
-     */
64
-    protected function setupEnvironment()
65
-    {
66
-        $this->setupDatabase();
67
-
68
-        return true;
69
-    }
70
-
71
-    /**
72
-     * @return PdoDatabase
73
-     * @throws EnvironmentException
74
-     * @throws Exception
75
-     */
76
-    protected function setupDatabase()
77
-    {
78
-        // check the schema version
79
-        $database = PdoDatabase::getDatabaseConnection('acc');
80
-
81
-        $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
82
-        if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
83
-            throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
84
-        }
85
-
86
-        return $database;
87
-    }
88
-
89
-    /**
90
-     * @return SiteConfiguration
91
-     */
92
-    public function getConfiguration()
93
-    {
94
-        return $this->configuration;
95
-    }
96
-
97
-    /**
98
-     * Main application logic
99
-     * @return void
100
-     */
101
-    abstract protected function main();
102
-
103
-    /**
104
-     * Any cleanup tasks should go here
105
-     *
106
-     * Note that we need to be very careful here, as exceptions may have been thrown and handled.
107
-     * This should *only* be for cleaning up, no logic should go here.
108
-     *
109
-     * @return void
110
-     */
111
-    abstract protected function cleanupEnvironment();
112
-
113
-    /**
114
-     * @param ITask             $page
115
-     * @param SiteConfiguration $siteConfiguration
116
-     * @param PdoDatabase       $database
117
-     * @param PdoDatabase       $notificationsDatabase
118
-     *
119
-     * @return void
120
-     */
121
-    protected function setupHelpers(
122
-        ITask $page,
123
-        SiteConfiguration $siteConfiguration,
124
-        PdoDatabase $database,
125
-        PdoDatabase $notificationsDatabase = null
126
-    ) {
127
-        $page->setSiteConfiguration($siteConfiguration);
128
-
129
-        // setup the global database object
130
-        $page->setDatabase($database);
131
-
132
-        // set up helpers and inject them into the page.
133
-        $httpHelper = new HttpHelper($siteConfiguration);
134
-
135
-        $page->setEmailHelper(new EmailHelper());
136
-        $page->setHttpHelper($httpHelper);
137
-        $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
138
-
139
-        if ($siteConfiguration->getLocationProviderApiKey() === null) {
140
-            $page->setLocationProvider(new FakeLocationProvider());
141
-        }
142
-        else {
143
-            $page->setLocationProvider(
144
-                new IpLocationProvider(
145
-                    $database,
146
-                    $siteConfiguration->getLocationProviderApiKey(),
147
-                    $httpHelper
148
-                ));
149
-        }
150
-
151
-        $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
152
-
153
-        $page->setRdnsProvider(new CachedRDnsLookupProvider($database));
154
-
155
-        $page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
156
-            $database,
157
-            $this->getConfiguration()->getMediawikiWebServiceEndpoint(),
158
-            $httpHelper));
159
-
160
-        $page->setOAuthProtocolHelper(new OAuthProtocolHelper(
161
-            $siteConfiguration->getOAuthBaseUrl(),
162
-            $siteConfiguration->getOAuthConsumerToken(),
163
-            $siteConfiguration->getOAuthConsumerSecret(),
164
-            $siteConfiguration->getMediawikiWebServiceEndpoint()
165
-        ));
166
-
167
-        $page->setNotificationHelper(new IrcNotificationHelper(
168
-            $siteConfiguration,
169
-            $database,
170
-            $notificationsDatabase));
171
-
172
-        $page->setTorExitProvider(new TorExitProvider($database));
173
-    }
28
+	private $configuration;
29
+
30
+	public function __construct(SiteConfiguration $configuration)
31
+	{
32
+		$this->configuration = $configuration;
33
+	}
34
+
35
+	/**
36
+	 * Application entry point.
37
+	 *
38
+	 * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
+	 */
40
+	public function run()
41
+	{
42
+		try {
43
+			if ($this->setupEnvironment()) {
44
+				$this->main();
45
+			}
46
+		}
47
+		catch (Exception $ex) {
48
+			print $ex->getMessage();
49
+		}
50
+		finally {
51
+			$this->cleanupEnvironment();
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Environment setup
57
+	 *
58
+	 * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
+	 * and shut down prematurely.
60
+	 *
61
+	 * @return bool
62
+	 * @throws EnvironmentException
63
+	 */
64
+	protected function setupEnvironment()
65
+	{
66
+		$this->setupDatabase();
67
+
68
+		return true;
69
+	}
70
+
71
+	/**
72
+	 * @return PdoDatabase
73
+	 * @throws EnvironmentException
74
+	 * @throws Exception
75
+	 */
76
+	protected function setupDatabase()
77
+	{
78
+		// check the schema version
79
+		$database = PdoDatabase::getDatabaseConnection('acc');
80
+
81
+		$actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
82
+		if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
83
+			throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
84
+		}
85
+
86
+		return $database;
87
+	}
88
+
89
+	/**
90
+	 * @return SiteConfiguration
91
+	 */
92
+	public function getConfiguration()
93
+	{
94
+		return $this->configuration;
95
+	}
96
+
97
+	/**
98
+	 * Main application logic
99
+	 * @return void
100
+	 */
101
+	abstract protected function main();
102
+
103
+	/**
104
+	 * Any cleanup tasks should go here
105
+	 *
106
+	 * Note that we need to be very careful here, as exceptions may have been thrown and handled.
107
+	 * This should *only* be for cleaning up, no logic should go here.
108
+	 *
109
+	 * @return void
110
+	 */
111
+	abstract protected function cleanupEnvironment();
112
+
113
+	/**
114
+	 * @param ITask             $page
115
+	 * @param SiteConfiguration $siteConfiguration
116
+	 * @param PdoDatabase       $database
117
+	 * @param PdoDatabase       $notificationsDatabase
118
+	 *
119
+	 * @return void
120
+	 */
121
+	protected function setupHelpers(
122
+		ITask $page,
123
+		SiteConfiguration $siteConfiguration,
124
+		PdoDatabase $database,
125
+		PdoDatabase $notificationsDatabase = null
126
+	) {
127
+		$page->setSiteConfiguration($siteConfiguration);
128
+
129
+		// setup the global database object
130
+		$page->setDatabase($database);
131
+
132
+		// set up helpers and inject them into the page.
133
+		$httpHelper = new HttpHelper($siteConfiguration);
134
+
135
+		$page->setEmailHelper(new EmailHelper());
136
+		$page->setHttpHelper($httpHelper);
137
+		$page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
138
+
139
+		if ($siteConfiguration->getLocationProviderApiKey() === null) {
140
+			$page->setLocationProvider(new FakeLocationProvider());
141
+		}
142
+		else {
143
+			$page->setLocationProvider(
144
+				new IpLocationProvider(
145
+					$database,
146
+					$siteConfiguration->getLocationProviderApiKey(),
147
+					$httpHelper
148
+				));
149
+		}
150
+
151
+		$page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
152
+
153
+		$page->setRdnsProvider(new CachedRDnsLookupProvider($database));
154
+
155
+		$page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
156
+			$database,
157
+			$this->getConfiguration()->getMediawikiWebServiceEndpoint(),
158
+			$httpHelper));
159
+
160
+		$page->setOAuthProtocolHelper(new OAuthProtocolHelper(
161
+			$siteConfiguration->getOAuthBaseUrl(),
162
+			$siteConfiguration->getOAuthConsumerToken(),
163
+			$siteConfiguration->getOAuthConsumerSecret(),
164
+			$siteConfiguration->getMediawikiWebServiceEndpoint()
165
+		));
166
+
167
+		$page->setNotificationHelper(new IrcNotificationHelper(
168
+			$siteConfiguration,
169
+			$database,
170
+			$notificationsDatabase));
171
+
172
+		$page->setTorExitProvider(new TorExitProvider($database));
173
+	}
174 174
 }
Please login to merge, or discard this patch.
includes/DataObjects/OAuthIdentity.php 1 patch
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -16,51 +16,51 @@  discard block
 block discarded – undo
16 16
 
17 17
 class OAuthIdentity extends DataObject
18 18
 {
19
-    #region Fields
20
-    /** @var int */
21
-    private $user;
22
-    /** @var string */
23
-    private $iss;
24
-    /** @var int */
25
-    private $sub;
26
-    /** @var string */
27
-    private $aud;
28
-    /** @var int */
29
-    private $exp;
30
-    /** @var int */
31
-    private $iat;
32
-    /** @var string */
33
-    private $username;
34
-    /** @var int */
35
-    private $editcount;
36
-    /** @var int */
37
-    private $confirmed_email;
38
-    /** @var int */
39
-    private $blocked;
40
-    /** @var string */
41
-    private $registered;
42
-    /** @var int */
43
-    private $checkuser;
44
-    /** @var int */
45
-    private $grantbasic;
46
-    /** @var int */
47
-    private $grantcreateaccount;
48
-    /** @var int */
49
-    private $granthighvolume;
50
-    /** @var int */
51
-    private $grantcreateeditmovepage;
52
-    #endregion
53
-
54
-    /**
55
-     * Saves a data object to the database, either updating or inserting a record.
56
-     * @return void
57
-     * @throws Exception
58
-     * @throws OptimisticLockFailedException
59
-     */
60
-    public function save()
61
-    {
62
-        if ($this->isNew()) {
63
-            $statement = $this->dbObject->prepare(<<<SQL
19
+	#region Fields
20
+	/** @var int */
21
+	private $user;
22
+	/** @var string */
23
+	private $iss;
24
+	/** @var int */
25
+	private $sub;
26
+	/** @var string */
27
+	private $aud;
28
+	/** @var int */
29
+	private $exp;
30
+	/** @var int */
31
+	private $iat;
32
+	/** @var string */
33
+	private $username;
34
+	/** @var int */
35
+	private $editcount;
36
+	/** @var int */
37
+	private $confirmed_email;
38
+	/** @var int */
39
+	private $blocked;
40
+	/** @var string */
41
+	private $registered;
42
+	/** @var int */
43
+	private $checkuser;
44
+	/** @var int */
45
+	private $grantbasic;
46
+	/** @var int */
47
+	private $grantcreateaccount;
48
+	/** @var int */
49
+	private $granthighvolume;
50
+	/** @var int */
51
+	private $grantcreateeditmovepage;
52
+	#endregion
53
+
54
+	/**
55
+	 * Saves a data object to the database, either updating or inserting a record.
56
+	 * @return void
57
+	 * @throws Exception
58
+	 * @throws OptimisticLockFailedException
59
+	 */
60
+	public function save()
61
+	{
62
+		if ($this->isNew()) {
63
+			$statement = $this->dbObject->prepare(<<<SQL
64 64
                 INSERT INTO oauthidentity (
65 65
                     user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, 
66 66
                     grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage
@@ -69,34 +69,34 @@  discard block
 block discarded – undo
69 69
                     :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage
70 70
                 )
71 71
 SQL
72
-            );
73
-
74
-            $statement->bindValue(':user', $this->user);
75
-            $statement->bindValue(':iss', $this->iss);
76
-            $statement->bindValue(':sub', $this->sub);
77
-            $statement->bindValue(':aud', $this->aud);
78
-            $statement->bindValue(':exp', $this->exp);
79
-            $statement->bindValue(':iat', $this->iat);
80
-            $statement->bindValue(':username', $this->username);
81
-            $statement->bindValue(':editcount', $this->editcount);
82
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
83
-            $statement->bindValue(':blocked', $this->blocked);
84
-            $statement->bindValue(':registered', $this->registered);
85
-            $statement->bindValue(':checkuser', $this->checkuser);
86
-            $statement->bindValue(':grantbasic', $this->grantbasic);
87
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
89
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
90
-
91
-            if ($statement->execute()) {
92
-                $this->id = (int)$this->dbObject->lastInsertId();
93
-            }
94
-            else {
95
-                throw new Exception($statement->errorInfo());
96
-            }
97
-        }
98
-        else {
99
-            $statement = $this->dbObject->prepare(<<<SQL
72
+			);
73
+
74
+			$statement->bindValue(':user', $this->user);
75
+			$statement->bindValue(':iss', $this->iss);
76
+			$statement->bindValue(':sub', $this->sub);
77
+			$statement->bindValue(':aud', $this->aud);
78
+			$statement->bindValue(':exp', $this->exp);
79
+			$statement->bindValue(':iat', $this->iat);
80
+			$statement->bindValue(':username', $this->username);
81
+			$statement->bindValue(':editcount', $this->editcount);
82
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
83
+			$statement->bindValue(':blocked', $this->blocked);
84
+			$statement->bindValue(':registered', $this->registered);
85
+			$statement->bindValue(':checkuser', $this->checkuser);
86
+			$statement->bindValue(':grantbasic', $this->grantbasic);
87
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
89
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
90
+
91
+			if ($statement->execute()) {
92
+				$this->id = (int)$this->dbObject->lastInsertId();
93
+			}
94
+			else {
95
+				throw new Exception($statement->errorInfo());
96
+			}
97
+		}
98
+		else {
99
+			$statement = $this->dbObject->prepare(<<<SQL
100 100
                 UPDATE oauthidentity SET
101 101
                       iss                     = :iss
102 102
                     , sub                     = :sub
@@ -116,211 +116,211 @@  discard block
 block discarded – undo
116 116
                     , updateversion           = updateversion + 1
117 117
                 WHERE  id = :id AND updateversion = :updateversion
118 118
 SQL
119
-            );
120
-
121
-            $statement->bindValue(':iss', $this->iss);
122
-            $statement->bindValue(':sub', $this->sub);
123
-            $statement->bindValue(':aud', $this->aud);
124
-            $statement->bindValue(':exp', $this->exp);
125
-            $statement->bindValue(':iat', $this->iat);
126
-            $statement->bindValue(':username', $this->username);
127
-            $statement->bindValue(':editcount', $this->editcount);
128
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
129
-            $statement->bindValue(':blocked', $this->blocked);
130
-            $statement->bindValue(':registered', $this->registered);
131
-            $statement->bindValue(':checkuser', $this->checkuser);
132
-            $statement->bindValue(':grantbasic', $this->grantbasic);
133
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
135
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
-
137
-            $statement->bindValue(':id', $this->id);
138
-            $statement->bindValue(':updateversion', $this->updateversion);
139
-
140
-            if (!$statement->execute()) {
141
-                throw new Exception($statement->errorInfo());
142
-            }
143
-
144
-            if ($statement->rowCount() !== 1) {
145
-                throw new OptimisticLockFailedException();
146
-            }
147
-
148
-            $this->updateversion++;
149
-        }
150
-    }
151
-
152
-    #region Properties
153
-
154
-    /**
155
-     * @return int
156
-     */
157
-    public function getUserId()
158
-    {
159
-        return $this->user;
160
-    }
161
-
162
-    /**
163
-     * @param int $user
164
-     */
165
-    public function setUserId($user)
166
-    {
167
-        $this->user = $user;
168
-    }
169
-
170
-    /**
171
-     * @return string
172
-     */
173
-    public function getIssuer()
174
-    {
175
-        return $this->iss;
176
-    }
177
-
178
-    /**
179
-     * @return int
180
-     */
181
-    public function getSubject()
182
-    {
183
-        return $this->sub;
184
-    }
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function getAudience()
190
-    {
191
-        return $this->aud;
192
-    }
193
-
194
-    /**
195
-     * @return int
196
-     */
197
-    public function getExpirationTime()
198
-    {
199
-        return $this->exp;
200
-    }
201
-
202
-    /**
203
-     * @return int
204
-     */
205
-    public function getIssuedAtTime()
206
-    {
207
-        return $this->iat;
208
-    }
209
-
210
-    /**
211
-     * @return string
212
-     */
213
-    public function getUsername()
214
-    {
215
-        return $this->username;
216
-    }
217
-
218
-    /**
219
-     * @return int
220
-     */
221
-    public function getEditCount()
222
-    {
223
-        return $this->editcount;
224
-    }
225
-
226
-    /**
227
-     * @return bool
228
-     */
229
-    public function getConfirmedEmail()
230
-    {
231
-        return $this->confirmed_email == 1;
232
-    }
233
-
234
-    /**
235
-     * @return bool
236
-     */
237
-    public function getBlocked()
238
-    {
239
-        return $this->blocked == 1;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    public function getRegistered()
246
-    {
247
-        return $this->registered;
248
-    }
249
-
250
-    public function getRegistrationDate()
251
-    {
252
-        return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
-    }
254
-
255
-    public function getAccountAge()
256
-    {
257
-        $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
-        $interval = $regDate->diff(new DateTimeImmutable(), true);
259
-
260
-        return $interval->days;
261
-    }
262
-
263
-    /**
264
-     * @return bool
265
-     */
266
-    public function getCheckuser()
267
-    {
268
-        return $this->checkuser == 1;
269
-    }
270
-
271
-    /**
272
-     * @return bool
273
-     */
274
-    public function getGrantBasic()
275
-    {
276
-        return $this->grantbasic == 1;
277
-    }
278
-
279
-    /**
280
-     * @return bool
281
-     */
282
-    public function getGrantCreateAccount()
283
-    {
284
-        return $this->grantcreateaccount == 1;
285
-    }
286
-
287
-    /**
288
-     * @return bool
289
-     */
290
-    public function getGrantHighVolume()
291
-    {
292
-        return $this->granthighvolume == 1;
293
-    }
294
-
295
-    /**
296
-     * @return bool
297
-     */
298
-    public function getGrantCreateEditMovePage()
299
-    {
300
-        return $this->grantcreateeditmovepage == 1;
301
-    }
302
-
303
-    #endregion Properties
304
-
305
-    /**
306
-     * Populates the fields of this instance from a provided JSON Web Token
307
-     *
308
-     * @param stdClass $jwt
309
-     */
310
-    public function populate($jwt)
311
-    {
312
-        $this->iss = $jwt->iss;
313
-        $this->sub = $jwt->sub;
314
-        $this->aud = $jwt->aud;
315
-        $this->exp = $jwt->exp;
316
-        $this->iat = $jwt->iat;
317
-        $this->username = $jwt->username;
318
-        $this->editcount = $jwt->editcount;
319
-        $this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
-        $this->blocked = $jwt->blocked ? 1 : 0;
321
-        $this->registered = $jwt->registered;
322
-
323
-        /*
119
+			);
120
+
121
+			$statement->bindValue(':iss', $this->iss);
122
+			$statement->bindValue(':sub', $this->sub);
123
+			$statement->bindValue(':aud', $this->aud);
124
+			$statement->bindValue(':exp', $this->exp);
125
+			$statement->bindValue(':iat', $this->iat);
126
+			$statement->bindValue(':username', $this->username);
127
+			$statement->bindValue(':editcount', $this->editcount);
128
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
129
+			$statement->bindValue(':blocked', $this->blocked);
130
+			$statement->bindValue(':registered', $this->registered);
131
+			$statement->bindValue(':checkuser', $this->checkuser);
132
+			$statement->bindValue(':grantbasic', $this->grantbasic);
133
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
135
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
+
137
+			$statement->bindValue(':id', $this->id);
138
+			$statement->bindValue(':updateversion', $this->updateversion);
139
+
140
+			if (!$statement->execute()) {
141
+				throw new Exception($statement->errorInfo());
142
+			}
143
+
144
+			if ($statement->rowCount() !== 1) {
145
+				throw new OptimisticLockFailedException();
146
+			}
147
+
148
+			$this->updateversion++;
149
+		}
150
+	}
151
+
152
+	#region Properties
153
+
154
+	/**
155
+	 * @return int
156
+	 */
157
+	public function getUserId()
158
+	{
159
+		return $this->user;
160
+	}
161
+
162
+	/**
163
+	 * @param int $user
164
+	 */
165
+	public function setUserId($user)
166
+	{
167
+		$this->user = $user;
168
+	}
169
+
170
+	/**
171
+	 * @return string
172
+	 */
173
+	public function getIssuer()
174
+	{
175
+		return $this->iss;
176
+	}
177
+
178
+	/**
179
+	 * @return int
180
+	 */
181
+	public function getSubject()
182
+	{
183
+		return $this->sub;
184
+	}
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function getAudience()
190
+	{
191
+		return $this->aud;
192
+	}
193
+
194
+	/**
195
+	 * @return int
196
+	 */
197
+	public function getExpirationTime()
198
+	{
199
+		return $this->exp;
200
+	}
201
+
202
+	/**
203
+	 * @return int
204
+	 */
205
+	public function getIssuedAtTime()
206
+	{
207
+		return $this->iat;
208
+	}
209
+
210
+	/**
211
+	 * @return string
212
+	 */
213
+	public function getUsername()
214
+	{
215
+		return $this->username;
216
+	}
217
+
218
+	/**
219
+	 * @return int
220
+	 */
221
+	public function getEditCount()
222
+	{
223
+		return $this->editcount;
224
+	}
225
+
226
+	/**
227
+	 * @return bool
228
+	 */
229
+	public function getConfirmedEmail()
230
+	{
231
+		return $this->confirmed_email == 1;
232
+	}
233
+
234
+	/**
235
+	 * @return bool
236
+	 */
237
+	public function getBlocked()
238
+	{
239
+		return $this->blocked == 1;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	public function getRegistered()
246
+	{
247
+		return $this->registered;
248
+	}
249
+
250
+	public function getRegistrationDate()
251
+	{
252
+		return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
+	}
254
+
255
+	public function getAccountAge()
256
+	{
257
+		$regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
+		$interval = $regDate->diff(new DateTimeImmutable(), true);
259
+
260
+		return $interval->days;
261
+	}
262
+
263
+	/**
264
+	 * @return bool
265
+	 */
266
+	public function getCheckuser()
267
+	{
268
+		return $this->checkuser == 1;
269
+	}
270
+
271
+	/**
272
+	 * @return bool
273
+	 */
274
+	public function getGrantBasic()
275
+	{
276
+		return $this->grantbasic == 1;
277
+	}
278
+
279
+	/**
280
+	 * @return bool
281
+	 */
282
+	public function getGrantCreateAccount()
283
+	{
284
+		return $this->grantcreateaccount == 1;
285
+	}
286
+
287
+	/**
288
+	 * @return bool
289
+	 */
290
+	public function getGrantHighVolume()
291
+	{
292
+		return $this->granthighvolume == 1;
293
+	}
294
+
295
+	/**
296
+	 * @return bool
297
+	 */
298
+	public function getGrantCreateEditMovePage()
299
+	{
300
+		return $this->grantcreateeditmovepage == 1;
301
+	}
302
+
303
+	#endregion Properties
304
+
305
+	/**
306
+	 * Populates the fields of this instance from a provided JSON Web Token
307
+	 *
308
+	 * @param stdClass $jwt
309
+	 */
310
+	public function populate($jwt)
311
+	{
312
+		$this->iss = $jwt->iss;
313
+		$this->sub = $jwt->sub;
314
+		$this->aud = $jwt->aud;
315
+		$this->exp = $jwt->exp;
316
+		$this->iat = $jwt->iat;
317
+		$this->username = $jwt->username;
318
+		$this->editcount = $jwt->editcount;
319
+		$this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
+		$this->blocked = $jwt->blocked ? 1 : 0;
321
+		$this->registered = $jwt->registered;
322
+
323
+		/*
324 324
          * Rights we need:
325 325
          *  Account creation
326 326
          *      createaccount      => createaccount
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
          * Any antispoof conflicts will still have to be resolved manually using the normal creation form.
343 343
          */
344 344
 
345
-        $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
-        $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
-        $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
348
-        $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0;
345
+		$this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
+		$this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
+		$this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
348
+		$this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0;
349 349
 
350
-        $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0;
351
-    }
350
+		$this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0;
351
+	}
352 352
 }
Please login to merge, or discard this patch.
includes/DataObjects/SiteNotice.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,74 +20,74 @@
 block discarded – undo
20 20
  */
21 21
 class SiteNotice extends DataObject
22 22
 {
23
-    /** @var string */
24
-    private $content;
23
+	/** @var string */
24
+	private $content;
25 25
 
26
-    /**
27
-     * Get a message.
28
-     *
29
-     * @param PdoDatabase $database
30
-     *
31
-     * @return string The content for display
32
-     */
33
-    public static function get(PdoDatabase $database)
34
-    {
35
-        /** @var SiteNotice $message */
36
-        $message = self::getById(1, $database);
26
+	/**
27
+	 * Get a message.
28
+	 *
29
+	 * @param PdoDatabase $database
30
+	 *
31
+	 * @return string The content for display
32
+	 */
33
+	public static function get(PdoDatabase $database)
34
+	{
35
+		/** @var SiteNotice $message */
36
+		$message = self::getById(1, $database);
37 37
 
38
-        return $message->getContent();
39
-    }
38
+		return $message->getContent();
39
+	}
40 40
 
41
-    /**
42
-     * Saves the object
43
-     * @throws Exception
44
-     */
45
-    public function save()
46
-    {
47
-        if ($this->isNew()) {
48
-            // insert
49
-            throw new Exception('Not allowed to create new site notice object');
50
-        }
51
-        else {
52
-            // update
53
-            $statement = $this->dbObject->prepare(<<<SQL
41
+	/**
42
+	 * Saves the object
43
+	 * @throws Exception
44
+	 */
45
+	public function save()
46
+	{
47
+		if ($this->isNew()) {
48
+			// insert
49
+			throw new Exception('Not allowed to create new site notice object');
50
+		}
51
+		else {
52
+			// update
53
+			$statement = $this->dbObject->prepare(<<<SQL
54 54
 UPDATE sitenotice
55 55
 SET content = :content, updateversion = updateversion + 1
56 56
 WHERE updateversion = :updateversion;
57 57
 SQL
58
-            );
59
-            $statement->bindValue(':updateversion', $this->updateversion);
58
+			);
59
+			$statement->bindValue(':updateversion', $this->updateversion);
60 60
 
61
-            $statement->bindValue(':content', $this->content);
61
+			$statement->bindValue(':content', $this->content);
62 62
 
63
-            if (!$statement->execute()) {
64
-                throw new Exception($statement->errorInfo());
65
-            }
63
+			if (!$statement->execute()) {
64
+				throw new Exception($statement->errorInfo());
65
+			}
66 66
 
67
-            if ($statement->rowCount() !== 1) {
68
-                throw new OptimisticLockFailedException();
69
-            }
67
+			if ($statement->rowCount() !== 1) {
68
+				throw new OptimisticLockFailedException();
69
+			}
70 70
 
71
-            $this->updateversion++;
72
-        }
73
-    }
71
+			$this->updateversion++;
72
+		}
73
+	}
74 74
 
75
-    /**
76
-     * Gets the content of the message
77
-     * @return string
78
-     */
79
-    public function getContent()
80
-    {
81
-        return $this->content;
82
-    }
75
+	/**
76
+	 * Gets the content of the message
77
+	 * @return string
78
+	 */
79
+	public function getContent()
80
+	{
81
+		return $this->content;
82
+	}
83 83
 
84
-    /**
85
-     * Sets the content of the message
86
-     *
87
-     * @param string $content
88
-     */
89
-    public function setContent($content)
90
-    {
91
-        $this->content = $content;
92
-    }
84
+	/**
85
+	 * Sets the content of the message
86
+	 *
87
+	 * @param string $content
88
+	 */
89
+	public function setContent($content)
90
+	{
91
+		$this->content = $content;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
includes/DataObjects/Credential.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -15,187 +15,187 @@  discard block
 block discarded – undo
15 15
 
16 16
 class Credential extends DataObject
17 17
 {
18
-    /** @var int */
19
-    private $user;
20
-    /** @var int */
21
-    private $factor;
22
-    /** @var string */
23
-    private $type;
24
-    /** @var string */
25
-    private $data;
26
-    /** @var int */
27
-    private $version;
28
-    private $timeout;
29
-    /** @var int */
30
-    private $disabled = 0;
31
-    /** @var int */
32
-    private $priority;
33
-
34
-    /**
35
-     * @return int
36
-     */
37
-    public function getUserId()
38
-    {
39
-        return $this->user;
40
-    }
41
-
42
-    /**
43
-     * @param int $user
44
-     */
45
-    public function setUserId($user)
46
-    {
47
-        $this->user = $user;
48
-    }
49
-
50
-    /**
51
-     * @return int
52
-     */
53
-    public function getFactor()
54
-    {
55
-        return $this->factor;
56
-    }
57
-
58
-    /**
59
-     * @param int $factor
60
-     */
61
-    public function setFactor($factor)
62
-    {
63
-        $this->factor = $factor;
64
-    }
65
-
66
-    /**
67
-     * @return string
68
-     */
69
-    public function getType()
70
-    {
71
-        return $this->type;
72
-    }
73
-
74
-    /**
75
-     * @param string $type
76
-     */
77
-    public function setType($type)
78
-    {
79
-        $this->type = $type;
80
-    }
81
-
82
-    /**
83
-     * @return string
84
-     */
85
-    public function getData()
86
-    {
87
-        return $this->data;
88
-    }
89
-
90
-    /**
91
-     * @param string $data
92
-     */
93
-    public function setData($data)
94
-    {
95
-        $this->data = $data;
96
-    }
97
-
98
-    /**
99
-     * @return int
100
-     */
101
-    public function getVersion()
102
-    {
103
-        return $this->version;
104
-    }
105
-
106
-    /**
107
-     * @param int $version
108
-     */
109
-    public function setVersion($version)
110
-    {
111
-        $this->version = $version;
112
-    }
113
-
114
-    /**
115
-     * @return mixed
116
-     */
117
-    public function getTimeout()
118
-    {
119
-        if ($this->timeout === null) {
120
-            return null;
121
-        }
122
-
123
-        return new DateTimeImmutable($this->timeout);
124
-    }
125
-
126
-    /**
127
-     * @param mixed $timeout
128
-     */
129
-    public function setTimeout(DateTimeImmutable $timeout = null)
130
-    {
131
-        if ($timeout === null) {
132
-            $this->timeout = null;
133
-        }
134
-        else {
135
-            $this->timeout = $timeout->format('Y-m-d H:i:s');
136
-        }
137
-    }
138
-
139
-    /**
140
-     * @return int
141
-     */
142
-    public function getDisabled()
143
-    {
144
-        return $this->disabled;
145
-    }
146
-
147
-    /**
148
-     * @param int $disabled
149
-     */
150
-    public function setDisabled($disabled)
151
-    {
152
-        $this->disabled = $disabled;
153
-    }
154
-
155
-    /**
156
-     * @return int
157
-     */
158
-    public function getPriority()
159
-    {
160
-        return $this->priority;
161
-    }
162
-
163
-    /**
164
-     * @param int $priority
165
-     */
166
-    public function setPriority($priority)
167
-    {
168
-        $this->priority = $priority;
169
-    }
170
-
171
-    public function save()
172
-    {
173
-        if ($this->isNew()) {
174
-            // insert
175
-            $statement = $this->dbObject->prepare(<<<SQL
18
+	/** @var int */
19
+	private $user;
20
+	/** @var int */
21
+	private $factor;
22
+	/** @var string */
23
+	private $type;
24
+	/** @var string */
25
+	private $data;
26
+	/** @var int */
27
+	private $version;
28
+	private $timeout;
29
+	/** @var int */
30
+	private $disabled = 0;
31
+	/** @var int */
32
+	private $priority;
33
+
34
+	/**
35
+	 * @return int
36
+	 */
37
+	public function getUserId()
38
+	{
39
+		return $this->user;
40
+	}
41
+
42
+	/**
43
+	 * @param int $user
44
+	 */
45
+	public function setUserId($user)
46
+	{
47
+		$this->user = $user;
48
+	}
49
+
50
+	/**
51
+	 * @return int
52
+	 */
53
+	public function getFactor()
54
+	{
55
+		return $this->factor;
56
+	}
57
+
58
+	/**
59
+	 * @param int $factor
60
+	 */
61
+	public function setFactor($factor)
62
+	{
63
+		$this->factor = $factor;
64
+	}
65
+
66
+	/**
67
+	 * @return string
68
+	 */
69
+	public function getType()
70
+	{
71
+		return $this->type;
72
+	}
73
+
74
+	/**
75
+	 * @param string $type
76
+	 */
77
+	public function setType($type)
78
+	{
79
+		$this->type = $type;
80
+	}
81
+
82
+	/**
83
+	 * @return string
84
+	 */
85
+	public function getData()
86
+	{
87
+		return $this->data;
88
+	}
89
+
90
+	/**
91
+	 * @param string $data
92
+	 */
93
+	public function setData($data)
94
+	{
95
+		$this->data = $data;
96
+	}
97
+
98
+	/**
99
+	 * @return int
100
+	 */
101
+	public function getVersion()
102
+	{
103
+		return $this->version;
104
+	}
105
+
106
+	/**
107
+	 * @param int $version
108
+	 */
109
+	public function setVersion($version)
110
+	{
111
+		$this->version = $version;
112
+	}
113
+
114
+	/**
115
+	 * @return mixed
116
+	 */
117
+	public function getTimeout()
118
+	{
119
+		if ($this->timeout === null) {
120
+			return null;
121
+		}
122
+
123
+		return new DateTimeImmutable($this->timeout);
124
+	}
125
+
126
+	/**
127
+	 * @param mixed $timeout
128
+	 */
129
+	public function setTimeout(DateTimeImmutable $timeout = null)
130
+	{
131
+		if ($timeout === null) {
132
+			$this->timeout = null;
133
+		}
134
+		else {
135
+			$this->timeout = $timeout->format('Y-m-d H:i:s');
136
+		}
137
+	}
138
+
139
+	/**
140
+	 * @return int
141
+	 */
142
+	public function getDisabled()
143
+	{
144
+		return $this->disabled;
145
+	}
146
+
147
+	/**
148
+	 * @param int $disabled
149
+	 */
150
+	public function setDisabled($disabled)
151
+	{
152
+		$this->disabled = $disabled;
153
+	}
154
+
155
+	/**
156
+	 * @return int
157
+	 */
158
+	public function getPriority()
159
+	{
160
+		return $this->priority;
161
+	}
162
+
163
+	/**
164
+	 * @param int $priority
165
+	 */
166
+	public function setPriority($priority)
167
+	{
168
+		$this->priority = $priority;
169
+	}
170
+
171
+	public function save()
172
+	{
173
+		if ($this->isNew()) {
174
+			// insert
175
+			$statement = $this->dbObject->prepare(<<<SQL
176 176
 INSERT INTO credential ( updateversion, user, factor, type, data, version, timeout, disabled, priority )
177 177
 VALUES ( 0, :user, :factor, :type, :data, :version, :timeout, :disabled, :priority );
178 178
 SQL
179
-            );
180
-            $statement->bindValue(":user", $this->user);
181
-            $statement->bindValue(":factor", $this->factor);
182
-            $statement->bindValue(":type", $this->type);
183
-            $statement->bindValue(":data", $this->data);
184
-            $statement->bindValue(":version", $this->version);
185
-            $statement->bindValue(":timeout", $this->timeout);
186
-            $statement->bindValue(":disabled", $this->disabled);
187
-            $statement->bindValue(":priority", $this->priority);
188
-
189
-            if ($statement->execute()) {
190
-                $this->id = (int)$this->dbObject->lastInsertId();
191
-            }
192
-            else {
193
-                throw new Exception($statement->errorInfo());
194
-            }
195
-        }
196
-        else {
197
-            // update
198
-            $statement = $this->dbObject->prepare(<<<SQL
179
+			);
180
+			$statement->bindValue(":user", $this->user);
181
+			$statement->bindValue(":factor", $this->factor);
182
+			$statement->bindValue(":type", $this->type);
183
+			$statement->bindValue(":data", $this->data);
184
+			$statement->bindValue(":version", $this->version);
185
+			$statement->bindValue(":timeout", $this->timeout);
186
+			$statement->bindValue(":disabled", $this->disabled);
187
+			$statement->bindValue(":priority", $this->priority);
188
+
189
+			if ($statement->execute()) {
190
+				$this->id = (int)$this->dbObject->lastInsertId();
191
+			}
192
+			else {
193
+				throw new Exception($statement->errorInfo());
194
+			}
195
+		}
196
+		else {
197
+			// update
198
+			$statement = $this->dbObject->prepare(<<<SQL
199 199
                 UPDATE credential
200 200
                 SET   factor = :factor
201 201
                     , data = :data
@@ -206,27 +206,27 @@  discard block
 block discarded – undo
206 206
                     , updateversion = updateversion + 1
207 207
                 WHERE id = :id AND updateversion = :updateversion;
208 208
 SQL
209
-            );
209
+			);
210 210
 
211
-            $statement->bindValue(':id', $this->id);
212
-            $statement->bindValue(':updateversion', $this->updateversion);
211
+			$statement->bindValue(':id', $this->id);
212
+			$statement->bindValue(':updateversion', $this->updateversion);
213 213
 
214
-            $statement->bindValue(":factor", $this->factor);
215
-            $statement->bindValue(":data", $this->data);
216
-            $statement->bindValue(":version", $this->version);
217
-            $statement->bindValue(":timeout", $this->timeout);
218
-            $statement->bindValue(":disabled", $this->disabled);
219
-            $statement->bindValue(":priority", $this->priority);
214
+			$statement->bindValue(":factor", $this->factor);
215
+			$statement->bindValue(":data", $this->data);
216
+			$statement->bindValue(":version", $this->version);
217
+			$statement->bindValue(":timeout", $this->timeout);
218
+			$statement->bindValue(":disabled", $this->disabled);
219
+			$statement->bindValue(":priority", $this->priority);
220 220
 
221
-            if (!$statement->execute()) {
222
-                throw new Exception($statement->errorInfo());
223
-            }
221
+			if (!$statement->execute()) {
222
+				throw new Exception($statement->errorInfo());
223
+			}
224 224
 
225
-            if ($statement->rowCount() !== 1) {
226
-                throw new OptimisticLockFailedException();
227
-            }
225
+			if ($statement->rowCount() !== 1) {
226
+				throw new OptimisticLockFailedException();
227
+			}
228 228
 
229
-            $this->updateversion++;
230
-        }
231
-    }
229
+			$this->updateversion++;
230
+		}
231
+	}
232 232
 }
233 233
\ No newline at end of file
Please login to merge, or discard this patch.