Passed
Push — dependabot/npm_and_yarn/sass-1... ( dd05dd )
by
unknown
05:21
created
includes/Pages/Statistics/StatsMonthlyStats.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsMonthlyStats extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Monthly Stats :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Monthly Stats :: Statistics');
19 19
 
20
-        $query = <<<SQL
20
+		$query = <<<SQL
21 21
 WITH activemonths AS (
22 22
     -- Pull all values from two generated sequences (values 2008 to 2050, and values 1 to 12) to generate dates.
23 23
     -- Filter the resulting set down to months between the earliest and latest log entries.
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
 ORDER BY sortkey ASC;
156 156
 SQL;
157 157
 
158
-        $database = $this->getDatabase();
159
-        $statement = $database->query($query);
160
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
158
+		$database = $this->getDatabase();
159
+		$statement = $database->query($query);
160
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
161 161
 
162
-        $this->assign('dataTable', $data);
163
-        $this->assign('statsPageTitle', 'Monthly Statistics');
164
-        $this->setTemplate('statistics/monthly-stats.tpl');
165
-    }
162
+		$this->assign('dataTable', $data);
163
+		$this->assign('statsPageTitle', 'Monthly Statistics');
164
+		$this->setTemplate('statistics/monthly-stats.tpl');
165
+	}
166 166
 }
Please login to merge, or discard this patch.
includes/Providers/IpLocationProvider.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -21,107 +21,107 @@
 block discarded – undo
21 21
  */
22 22
 class IpLocationProvider implements ILocationProvider
23 23
 {
24
-    /** @var string */
25
-    private $apiKey;
26
-    /** @var PdoDatabase */
27
-    private $database;
28
-    /** @var HttpHelper */
29
-    private $httpHelper;
30
-
31
-    /**
32
-     * IpLocationProvider constructor.
33
-     *
34
-     * @param PdoDatabase $database
35
-     * @param string      $apiKey
36
-     * @param HttpHelper  $httpHelper
37
-     */
38
-    public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
-    {
40
-        $this->database = $database;
41
-        $this->apiKey = $apiKey;
42
-        $this->httpHelper = $httpHelper;
43
-    }
44
-
45
-    /**
46
-     * @param string $address
47
-     *
48
-     * @return array|null
49
-     * @throws Exception
50
-     * @throws OptimisticLockFailedException
51
-     */
52
-    public function getIpLocation($address)
53
-    {
54
-        $address = trim($address);
55
-
56
-        // lets look in our database first.
57
-        $location = GeoLocation::getByAddress($address, $this->database, true);
58
-
59
-        if ($location != null) {
60
-            // touch cache timer
61
-            $location->save();
62
-
63
-            return $location->getData();
64
-        }
65
-
66
-        // OK, it's not there, let's do an IP2Location lookup.
67
-        $result = $this->getResult($address);
68
-
69
-        if ($result != null) {
70
-            $location = new GeoLocation();
71
-            $location->setDatabase($this->database);
72
-            $location->setAddress($address);
73
-            $location->setData($result);
74
-            $location->save();
75
-
76
-            return $result;
77
-        }
78
-
79
-        return null;
80
-    }
81
-
82
-    // adapted from http://www.ipinfodb.com/ip_location_api.php
83
-
84
-    /**
85
-     * @param string $ip
86
-     *
87
-     * @return array|null
88
-     */
89
-    private function getResult($ip)
90
-    {
91
-        try {
92
-            if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
-                $xml = $this->httpHelper->get($this->getApiBase(), array(
94
-                    'key'    => $this->apiKey,
95
-                    'ip'     => $ip,
96
-                    'format' => 'xml',
97
-                ));
98
-
99
-                $response = @new SimpleXMLElement($xml);
100
-
101
-                $result = array();
102
-
103
-                foreach ($response as $field => $value) {
104
-                    $result[(string)$field] = (string)$value;
105
-                }
106
-
107
-                return $result;
108
-            }
109
-        }
110
-        catch (Exception $ex) {
111
-            return null;
112
-
113
-            // LOGME: do something smart here, or wherever we use this value.
114
-            // This is just a temp hack to squash errors on the UI for now.
115
-        }
116
-
117
-        return null;
118
-    }
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    protected function getApiBase()
124
-    {
125
-        return "https://api.ipinfodb.com/v3/ip-city/";
126
-    }
24
+	/** @var string */
25
+	private $apiKey;
26
+	/** @var PdoDatabase */
27
+	private $database;
28
+	/** @var HttpHelper */
29
+	private $httpHelper;
30
+
31
+	/**
32
+	 * IpLocationProvider constructor.
33
+	 *
34
+	 * @param PdoDatabase $database
35
+	 * @param string      $apiKey
36
+	 * @param HttpHelper  $httpHelper
37
+	 */
38
+	public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
+	{
40
+		$this->database = $database;
41
+		$this->apiKey = $apiKey;
42
+		$this->httpHelper = $httpHelper;
43
+	}
44
+
45
+	/**
46
+	 * @param string $address
47
+	 *
48
+	 * @return array|null
49
+	 * @throws Exception
50
+	 * @throws OptimisticLockFailedException
51
+	 */
52
+	public function getIpLocation($address)
53
+	{
54
+		$address = trim($address);
55
+
56
+		// lets look in our database first.
57
+		$location = GeoLocation::getByAddress($address, $this->database, true);
58
+
59
+		if ($location != null) {
60
+			// touch cache timer
61
+			$location->save();
62
+
63
+			return $location->getData();
64
+		}
65
+
66
+		// OK, it's not there, let's do an IP2Location lookup.
67
+		$result = $this->getResult($address);
68
+
69
+		if ($result != null) {
70
+			$location = new GeoLocation();
71
+			$location->setDatabase($this->database);
72
+			$location->setAddress($address);
73
+			$location->setData($result);
74
+			$location->save();
75
+
76
+			return $result;
77
+		}
78
+
79
+		return null;
80
+	}
81
+
82
+	// adapted from http://www.ipinfodb.com/ip_location_api.php
83
+
84
+	/**
85
+	 * @param string $ip
86
+	 *
87
+	 * @return array|null
88
+	 */
89
+	private function getResult($ip)
90
+	{
91
+		try {
92
+			if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
+				$xml = $this->httpHelper->get($this->getApiBase(), array(
94
+					'key'    => $this->apiKey,
95
+					'ip'     => $ip,
96
+					'format' => 'xml',
97
+				));
98
+
99
+				$response = @new SimpleXMLElement($xml);
100
+
101
+				$result = array();
102
+
103
+				foreach ($response as $field => $value) {
104
+					$result[(string)$field] = (string)$value;
105
+				}
106
+
107
+				return $result;
108
+			}
109
+		}
110
+		catch (Exception $ex) {
111
+			return null;
112
+
113
+			// LOGME: do something smart here, or wherever we use this value.
114
+			// This is just a temp hack to squash errors on the UI for now.
115
+		}
116
+
117
+		return null;
118
+	}
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	protected function getApiBase()
124
+	{
125
+		return "https://api.ipinfodb.com/v3/ip-city/";
126
+	}
127 127
 }
Please login to merge, or discard this patch.
includes/WebRequest.php 2 patches
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -25,619 +25,619 @@
 block discarded – undo
25 25
  */
26 26
 class WebRequest
27 27
 {
28
-    /**
29
-     * @var IGlobalStateProvider Provides access to the global state.
30
-     */
31
-    private static $globalStateProvider;
32
-
33
-    /**
34
-     * Returns a boolean value if the request was submitted with the HTTP POST method.
35
-     * @return bool
36
-     */
37
-    public static function wasPosted()
38
-    {
39
-        return self::method() === 'POST';
40
-    }
41
-
42
-    /**
43
-     * Gets the HTTP Method used
44
-     * @return string|null
45
-     */
46
-    public static function method()
47
-    {
48
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
49
-
50
-        if (isset($server['REQUEST_METHOD'])) {
51
-            return $server['REQUEST_METHOD'];
52
-        }
53
-
54
-        return null;
55
-    }
56
-
57
-    /**
58
-     * Gets a boolean value stating whether the request was served over HTTPS or not.
59
-     * @return bool
60
-     */
61
-    public static function isHttps()
62
-    {
63
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
64
-
65
-        if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
66
-            if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') {
67
-                // Client <=> Proxy is encrypted
68
-                return true;
69
-            }
70
-            else {
71
-                // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.
72
-                return false;
73
-            }
74
-        }
75
-
76
-        if (isset($server['HTTPS'])) {
77
-            if ($server['HTTPS'] === 'off') {
78
-                // ISAPI on IIS breaks the spec. :(
79
-                return false;
80
-            }
81
-
82
-            if ($server['HTTPS'] !== '') {
83
-                // Set to a non-empty value
84
-                return true;
85
-            }
86
-        }
87
-
88
-        return false;
89
-    }
90
-
91
-    /**
92
-     * Gets the path info
93
-     *
94
-     * @return array Array of path info segments
95
-     */
96
-    public static function pathInfo()
97
-    {
98
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
99
-        if (!isset($server['PATH_INFO'])) {
100
-            return array();
101
-        }
102
-
103
-        $exploded = explode('/', $server['PATH_INFO']);
104
-
105
-        // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts
106
-        // with a /
107
-        return array_values(array_filter($exploded));
108
-    }
109
-
110
-    /**
111
-     * Gets the remote address of the web request
112
-     * @return null|string
113
-     */
114
-    public static function remoteAddress()
115
-    {
116
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
117
-
118
-        if (isset($server['REMOTE_ADDR'])) {
119
-            return $server['REMOTE_ADDR'];
120
-        }
121
-
122
-        return null;
123
-    }
124
-
125
-    /**
126
-     * Gets the remote address of the web request
127
-     * @return null|string
128
-     */
129
-    public static function httpHost()
130
-    {
131
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
132
-
133
-        if (isset($server['HTTP_HOST'])) {
134
-            return $server['HTTP_HOST'];
135
-        }
136
-
137
-        return null;
138
-    }
139
-
140
-    /**
141
-     * Gets the XFF header contents for the web request
142
-     * @return null|string
143
-     */
144
-    public static function forwardedAddress()
145
-    {
146
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
147
-
148
-        if (isset($server['HTTP_X_FORWARDED_FOR'])) {
149
-            return $server['HTTP_X_FORWARDED_FOR'];
150
-        }
151
-
152
-        return null;
153
-    }
154
-
155
-    /**
156
-     * Sets the global state provider.
157
-     *
158
-     * Almost guaranteed this is not the method you want in production code.
159
-     *
160
-     * @param IGlobalStateProvider $globalState
161
-     */
162
-    public static function setGlobalStateProvider($globalState)
163
-    {
164
-        self::$globalStateProvider = $globalState;
165
-    }
166
-
167
-    #region POST variables
168
-
169
-    /**
170
-     * @param string $key
171
-     *
172
-     * @return null|string
173
-     */
174
-    public static function postString($key)
175
-    {
176
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
177
-        if (!array_key_exists($key, $post)) {
178
-            return null;
179
-        }
180
-
181
-        if ($post[$key] === "") {
182
-            return null;
183
-        }
184
-
185
-        return (string)$post[$key];
186
-    }
187
-
188
-    /**
189
-     * @param string $key
190
-     *
191
-     * @return null|string
192
-     */
193
-    public static function postEmail($key)
194
-    {
195
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
196
-        if (!array_key_exists($key, $post)) {
197
-            return null;
198
-        }
199
-
200
-        $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);
201
-
202
-        if ($filteredValue === false) {
203
-            return null;
204
-        }
205
-
206
-        return (string)$filteredValue;
207
-    }
208
-
209
-    /**
210
-     * @param string $key
211
-     *
212
-     * @return int|null
213
-     */
214
-    public static function postInt($key)
215
-    {
216
-        $post = &self::$globalStateProvider->getPostSuperGlobal();
217
-        if (!array_key_exists($key, $post)) {
218
-            return null;
219
-        }
220
-
221
-        $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
222
-
223
-        if ($filteredValue === null) {
224
-            return null;
225
-        }
226
-
227
-        return (int)$filteredValue;
228
-    }
229
-
230
-    /**
231
-     * @param string $key
232
-     *
233
-     * @return bool
234
-     */
235
-    public static function postBoolean($key)
236
-    {
237
-        $get = &self::$globalStateProvider->getPostSuperGlobal();
238
-        if (!array_key_exists($key, $get)) {
239
-            return false;
240
-        }
241
-
242
-        // presence of parameter only
243
-        if ($get[$key] === "") {
244
-            return true;
245
-        }
246
-
247
-        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
248
-            return false;
249
-        }
250
-
251
-        return true;
252
-    }
253
-
254
-    #endregion
255
-
256
-    #region GET variables
257
-
258
-    /**
259
-     * @param string $key
260
-     *
261
-     * @return bool
262
-     */
263
-    public static function getBoolean($key)
264
-    {
265
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
266
-        if (!array_key_exists($key, $get)) {
267
-            return false;
268
-        }
269
-
270
-        // presence of parameter only
271
-        if ($get[$key] === "") {
272
-            return true;
273
-        }
274
-
275
-        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
276
-            return false;
277
-        }
278
-
279
-        return true;
280
-    }
281
-
282
-    /**
283
-     * @param string $key
284
-     *
285
-     * @return int|null
286
-     */
287
-    public static function getInt($key)
288
-    {
289
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
290
-        if (!array_key_exists($key, $get)) {
291
-            return null;
292
-        }
293
-
294
-        $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
295
-
296
-        if ($filteredValue === null) {
297
-            return null;
298
-        }
299
-
300
-        return (int)$filteredValue;
301
-    }
302
-
303
-    /**
304
-     * @param string $key
305
-     *
306
-     * @return null|string
307
-     */
308
-    public static function getString($key)
309
-    {
310
-        $get = &self::$globalStateProvider->getGetSuperGlobal();
311
-        if (!array_key_exists($key, $get)) {
312
-            return null;
313
-        }
314
-
315
-        if ($get[$key] === "") {
316
-            return null;
317
-        }
318
-
319
-        return (string)$get[$key];
320
-    }
321
-
322
-    #endregion
323
-
324
-    /**
325
-     * Sets the logged-in user to the specified user.
326
-     *
327
-     * @param User $user
328
-     */
329
-    public static function setLoggedInUser(User $user)
330
-    {
331
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
332
-
333
-        $session['userID'] = $user->getId();
334
-        unset($session['partialLogin']);
335
-    }
336
-
337
-    public static function setActiveDomain(Domain $domain)
338
-    {
339
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
340
-
341
-        $session['domainID'] = $domain->getId();
342
-    }
343
-
344
-    /**
345
-     * Sets the post-login redirect
346
-     *
347
-     * @param string|null $uri The URI to redirect to
348
-     */
349
-    public static function setPostLoginRedirect($uri = null)
350
-    {
351
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
352
-
353
-        if ($uri === null) {
354
-            $uri = self::requestUri();
355
-        }
356
-
357
-        $session['returnTo'] = $uri;
358
-    }
359
-
360
-    /**
361
-     * @return string|null
362
-     */
363
-    public static function requestUri()
364
-    {
365
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
366
-
367
-        if (isset($server['REQUEST_URI'])) {
368
-            return $server['REQUEST_URI'];
369
-        }
370
-
371
-        return null;
372
-    }
373
-
374
-    /**
375
-     * Clears the post-login redirect
376
-     * @return string
377
-     */
378
-    public static function clearPostLoginRedirect()
379
-    {
380
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
381
-        if (array_key_exists('returnTo', $session)) {
382
-            $path = $session['returnTo'];
383
-            unset($session['returnTo']);
384
-
385
-            return $path;
386
-        }
387
-
388
-        return null;
389
-    }
390
-
391
-    /**
392
-     * @return string|null
393
-     */
394
-    public static function serverName()
395
-    {
396
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
397
-
398
-        if (isset($server['SERVER_NAME'])) {
399
-            return $server['SERVER_NAME'];
400
-        }
401
-
402
-        return null;
403
-    }
404
-
405
-    /**
406
-     * You probably only want to deal with this through SessionAlert.
407
-     * @return void
408
-     */
409
-    public static function clearSessionAlertData()
410
-    {
411
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
412
-        if (array_key_exists('alerts', $session)) {
413
-            unset($session['alerts']);
414
-        }
415
-    }
416
-
417
-    /**
418
-     * You probably only want to deal with this through SessionAlert.
419
-     *
420
-     * @return string[]
421
-     */
422
-    public static function getSessionAlertData()
423
-    {
424
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
425
-        if (array_key_exists('alerts', $session)) {
426
-            return $session['alerts'];
427
-        }
428
-
429
-        return array();
430
-    }
431
-
432
-    /**
433
-     * You probably only want to deal with this through SessionAlert.
434
-     *
435
-     * @param string[] $data
436
-     */
437
-    public static function setSessionAlertData($data)
438
-    {
439
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
440
-        $session['alerts'] = $data;
441
-    }
442
-
443
-    /**
444
-     * You probably only want to deal with this through TokenManager.
445
-     *
446
-     * @return string[]
447
-     */
448
-    public static function getSessionTokenData()
449
-    {
450
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
451
-        if (array_key_exists('tokens', $session)) {
452
-            return $session['tokens'];
453
-        }
454
-
455
-        return array();
456
-    }
457
-
458
-    /**
459
-     * You probably only want to deal with this through TokenManager.
460
-     *
461
-     * @param string[] $data
462
-     */
463
-    public static function setSessionTokenData($data)
464
-    {
465
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
466
-        $session['tokens'] = $data;
467
-    }
468
-
469
-    /**
470
-     * @param string $key
471
-     *
472
-     * @return mixed
473
-     */
474
-    public static function getSessionContext($key)
475
-    {
476
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
477
-
478
-        if (!isset($session['context'])) {
479
-            $session['context'] = array();
480
-        }
481
-
482
-        if (!isset($session['context'][$key])) {
483
-            return null;
484
-        }
485
-
486
-        return $session['context'][$key];
487
-    }
488
-
489
-    /**
490
-     * @param string $key
491
-     * @param mixed  $data
492
-     */
493
-    public static function setSessionContext($key, $data)
494
-    {
495
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
496
-
497
-        if (!isset($session['context'])) {
498
-            $session['context'] = array();
499
-        }
500
-
501
-        $session['context'][$key] = $data;
502
-    }
503
-
504
-    /**
505
-     * @return int|null
506
-     */
507
-    public static function getSessionUserId()
508
-    {
509
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
510
-
511
-        return isset($session['userID']) ? (int)$session['userID'] : null;
512
-    }
513
-
514
-    /**
515
-     * @return int|null
516
-     */
517
-    public static function getSessionDomain()
518
-    {
519
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
520
-
521
-        return isset($session['domainID']) ? (int)$session['domainID'] : null;
522
-    }
523
-
524
-    /**
525
-     * @param User $user
526
-     */
527
-    public static function setOAuthPartialLogin(User $user)
528
-    {
529
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
530
-        $session['oauthPartialLogin'] = $user->getId();
531
-    }
532
-
533
-    /**
534
-     * @return int|null
535
-     */
536
-    public static function getOAuthPartialLogin()
537
-    {
538
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
539
-
540
-        return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null;
541
-    }
542
-
543
-    public static function setAuthPartialLogin($userId, $stage)
544
-    {
545
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
546
-        $session['authPartialLoginId'] = $userId;
547
-        $session['authPartialLoginStage'] = $stage;
548
-    }
549
-
550
-    public static function getAuthPartialLogin()
551
-    {
552
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
553
-
554
-        $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null;
555
-        $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null;
556
-
557
-        return array($userId, $stage);
558
-    }
559
-
560
-    public static function clearAuthPartialLogin()
561
-    {
562
-        $session = &self::$globalStateProvider->getSessionSuperGlobal();
563
-        unset($session['authPartialLoginId']);
564
-        unset($session['authPartialLoginStage']);
565
-    }
566
-
567
-    /**
568
-     * @return null|string
569
-     */
570
-    public static function userAgent()
571
-    {
572
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
573
-
574
-        if (isset($server['HTTP_USER_AGENT'])) {
575
-            return $server['HTTP_USER_AGENT'];
576
-        }
577
-
578
-        return null;
579
-    }
580
-
581
-    /**
582
-     * @return null|string
583
-     */
584
-    public static function scriptName()
585
-    {
586
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
587
-
588
-        if (isset($server['SCRIPT_NAME'])) {
589
-            return $server['SCRIPT_NAME'];
590
-        }
591
-
592
-        return null;
593
-    }
594
-
595
-    /**
596
-     * @return null|string
597
-     */
598
-    public static function origin()
599
-    {
600
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
601
-
602
-        if (isset($server['HTTP_ORIGIN'])) {
603
-            return $server['HTTP_ORIGIN'];
604
-        }
605
-
606
-        return null;
607
-    }
608
-
609
-    public static function httpHeader(string $headerName): ?string {
610
-        $server = &self::$globalStateProvider->getServerSuperGlobal();
611
-
612
-        $headerKey = strtoupper("HTTP_" . str_replace('-', '_', $headerName));
613
-
614
-        if (isset($server[$headerKey])) {
615
-            return $server[$headerKey];
616
-        }
617
-
618
-        return null;
619
-    }
620
-
621
-    public static function testSiteNoticeCookieValue($expectedHash)
622
-    {
623
-        $cookie = &self::$globalStateProvider->getCookieSuperGlobal();
624
-
625
-        if (isset($cookie['sitenotice'])) {
626
-            return $cookie['sitenotice'] === $expectedHash;
627
-        }
628
-
629
-        return false;
630
-    }
631
-
632
-    public static function requestListDefaultSort()
633
-    {
634
-        $cookie = &self::$globalStateProvider->getCookieSuperGlobal();
635
-
636
-        if (isset($cookie['request_table_sort'])) {
637
-            return explode('/', $cookie['request_table_sort'], 2);
638
-        }
639
-        else {
640
-            return ['id', 'asc'];
641
-        }
642
-    }
28
+	/**
29
+	 * @var IGlobalStateProvider Provides access to the global state.
30
+	 */
31
+	private static $globalStateProvider;
32
+
33
+	/**
34
+	 * Returns a boolean value if the request was submitted with the HTTP POST method.
35
+	 * @return bool
36
+	 */
37
+	public static function wasPosted()
38
+	{
39
+		return self::method() === 'POST';
40
+	}
41
+
42
+	/**
43
+	 * Gets the HTTP Method used
44
+	 * @return string|null
45
+	 */
46
+	public static function method()
47
+	{
48
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
49
+
50
+		if (isset($server['REQUEST_METHOD'])) {
51
+			return $server['REQUEST_METHOD'];
52
+		}
53
+
54
+		return null;
55
+	}
56
+
57
+	/**
58
+	 * Gets a boolean value stating whether the request was served over HTTPS or not.
59
+	 * @return bool
60
+	 */
61
+	public static function isHttps()
62
+	{
63
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
64
+
65
+		if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
66
+			if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') {
67
+				// Client <=> Proxy is encrypted
68
+				return true;
69
+			}
70
+			else {
71
+				// Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.
72
+				return false;
73
+			}
74
+		}
75
+
76
+		if (isset($server['HTTPS'])) {
77
+			if ($server['HTTPS'] === 'off') {
78
+				// ISAPI on IIS breaks the spec. :(
79
+				return false;
80
+			}
81
+
82
+			if ($server['HTTPS'] !== '') {
83
+				// Set to a non-empty value
84
+				return true;
85
+			}
86
+		}
87
+
88
+		return false;
89
+	}
90
+
91
+	/**
92
+	 * Gets the path info
93
+	 *
94
+	 * @return array Array of path info segments
95
+	 */
96
+	public static function pathInfo()
97
+	{
98
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
99
+		if (!isset($server['PATH_INFO'])) {
100
+			return array();
101
+		}
102
+
103
+		$exploded = explode('/', $server['PATH_INFO']);
104
+
105
+		// filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts
106
+		// with a /
107
+		return array_values(array_filter($exploded));
108
+	}
109
+
110
+	/**
111
+	 * Gets the remote address of the web request
112
+	 * @return null|string
113
+	 */
114
+	public static function remoteAddress()
115
+	{
116
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
117
+
118
+		if (isset($server['REMOTE_ADDR'])) {
119
+			return $server['REMOTE_ADDR'];
120
+		}
121
+
122
+		return null;
123
+	}
124
+
125
+	/**
126
+	 * Gets the remote address of the web request
127
+	 * @return null|string
128
+	 */
129
+	public static function httpHost()
130
+	{
131
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
132
+
133
+		if (isset($server['HTTP_HOST'])) {
134
+			return $server['HTTP_HOST'];
135
+		}
136
+
137
+		return null;
138
+	}
139
+
140
+	/**
141
+	 * Gets the XFF header contents for the web request
142
+	 * @return null|string
143
+	 */
144
+	public static function forwardedAddress()
145
+	{
146
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
147
+
148
+		if (isset($server['HTTP_X_FORWARDED_FOR'])) {
149
+			return $server['HTTP_X_FORWARDED_FOR'];
150
+		}
151
+
152
+		return null;
153
+	}
154
+
155
+	/**
156
+	 * Sets the global state provider.
157
+	 *
158
+	 * Almost guaranteed this is not the method you want in production code.
159
+	 *
160
+	 * @param IGlobalStateProvider $globalState
161
+	 */
162
+	public static function setGlobalStateProvider($globalState)
163
+	{
164
+		self::$globalStateProvider = $globalState;
165
+	}
166
+
167
+	#region POST variables
168
+
169
+	/**
170
+	 * @param string $key
171
+	 *
172
+	 * @return null|string
173
+	 */
174
+	public static function postString($key)
175
+	{
176
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
177
+		if (!array_key_exists($key, $post)) {
178
+			return null;
179
+		}
180
+
181
+		if ($post[$key] === "") {
182
+			return null;
183
+		}
184
+
185
+		return (string)$post[$key];
186
+	}
187
+
188
+	/**
189
+	 * @param string $key
190
+	 *
191
+	 * @return null|string
192
+	 */
193
+	public static function postEmail($key)
194
+	{
195
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
196
+		if (!array_key_exists($key, $post)) {
197
+			return null;
198
+		}
199
+
200
+		$filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);
201
+
202
+		if ($filteredValue === false) {
203
+			return null;
204
+		}
205
+
206
+		return (string)$filteredValue;
207
+	}
208
+
209
+	/**
210
+	 * @param string $key
211
+	 *
212
+	 * @return int|null
213
+	 */
214
+	public static function postInt($key)
215
+	{
216
+		$post = &self::$globalStateProvider->getPostSuperGlobal();
217
+		if (!array_key_exists($key, $post)) {
218
+			return null;
219
+		}
220
+
221
+		$filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
222
+
223
+		if ($filteredValue === null) {
224
+			return null;
225
+		}
226
+
227
+		return (int)$filteredValue;
228
+	}
229
+
230
+	/**
231
+	 * @param string $key
232
+	 *
233
+	 * @return bool
234
+	 */
235
+	public static function postBoolean($key)
236
+	{
237
+		$get = &self::$globalStateProvider->getPostSuperGlobal();
238
+		if (!array_key_exists($key, $get)) {
239
+			return false;
240
+		}
241
+
242
+		// presence of parameter only
243
+		if ($get[$key] === "") {
244
+			return true;
245
+		}
246
+
247
+		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
248
+			return false;
249
+		}
250
+
251
+		return true;
252
+	}
253
+
254
+	#endregion
255
+
256
+	#region GET variables
257
+
258
+	/**
259
+	 * @param string $key
260
+	 *
261
+	 * @return bool
262
+	 */
263
+	public static function getBoolean($key)
264
+	{
265
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
266
+		if (!array_key_exists($key, $get)) {
267
+			return false;
268
+		}
269
+
270
+		// presence of parameter only
271
+		if ($get[$key] === "") {
272
+			return true;
273
+		}
274
+
275
+		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) {
276
+			return false;
277
+		}
278
+
279
+		return true;
280
+	}
281
+
282
+	/**
283
+	 * @param string $key
284
+	 *
285
+	 * @return int|null
286
+	 */
287
+	public static function getInt($key)
288
+	{
289
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
290
+		if (!array_key_exists($key, $get)) {
291
+			return null;
292
+		}
293
+
294
+		$filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
295
+
296
+		if ($filteredValue === null) {
297
+			return null;
298
+		}
299
+
300
+		return (int)$filteredValue;
301
+	}
302
+
303
+	/**
304
+	 * @param string $key
305
+	 *
306
+	 * @return null|string
307
+	 */
308
+	public static function getString($key)
309
+	{
310
+		$get = &self::$globalStateProvider->getGetSuperGlobal();
311
+		if (!array_key_exists($key, $get)) {
312
+			return null;
313
+		}
314
+
315
+		if ($get[$key] === "") {
316
+			return null;
317
+		}
318
+
319
+		return (string)$get[$key];
320
+	}
321
+
322
+	#endregion
323
+
324
+	/**
325
+	 * Sets the logged-in user to the specified user.
326
+	 *
327
+	 * @param User $user
328
+	 */
329
+	public static function setLoggedInUser(User $user)
330
+	{
331
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
332
+
333
+		$session['userID'] = $user->getId();
334
+		unset($session['partialLogin']);
335
+	}
336
+
337
+	public static function setActiveDomain(Domain $domain)
338
+	{
339
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
340
+
341
+		$session['domainID'] = $domain->getId();
342
+	}
343
+
344
+	/**
345
+	 * Sets the post-login redirect
346
+	 *
347
+	 * @param string|null $uri The URI to redirect to
348
+	 */
349
+	public static function setPostLoginRedirect($uri = null)
350
+	{
351
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
352
+
353
+		if ($uri === null) {
354
+			$uri = self::requestUri();
355
+		}
356
+
357
+		$session['returnTo'] = $uri;
358
+	}
359
+
360
+	/**
361
+	 * @return string|null
362
+	 */
363
+	public static function requestUri()
364
+	{
365
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
366
+
367
+		if (isset($server['REQUEST_URI'])) {
368
+			return $server['REQUEST_URI'];
369
+		}
370
+
371
+		return null;
372
+	}
373
+
374
+	/**
375
+	 * Clears the post-login redirect
376
+	 * @return string
377
+	 */
378
+	public static function clearPostLoginRedirect()
379
+	{
380
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
381
+		if (array_key_exists('returnTo', $session)) {
382
+			$path = $session['returnTo'];
383
+			unset($session['returnTo']);
384
+
385
+			return $path;
386
+		}
387
+
388
+		return null;
389
+	}
390
+
391
+	/**
392
+	 * @return string|null
393
+	 */
394
+	public static function serverName()
395
+	{
396
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
397
+
398
+		if (isset($server['SERVER_NAME'])) {
399
+			return $server['SERVER_NAME'];
400
+		}
401
+
402
+		return null;
403
+	}
404
+
405
+	/**
406
+	 * You probably only want to deal with this through SessionAlert.
407
+	 * @return void
408
+	 */
409
+	public static function clearSessionAlertData()
410
+	{
411
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
412
+		if (array_key_exists('alerts', $session)) {
413
+			unset($session['alerts']);
414
+		}
415
+	}
416
+
417
+	/**
418
+	 * You probably only want to deal with this through SessionAlert.
419
+	 *
420
+	 * @return string[]
421
+	 */
422
+	public static function getSessionAlertData()
423
+	{
424
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
425
+		if (array_key_exists('alerts', $session)) {
426
+			return $session['alerts'];
427
+		}
428
+
429
+		return array();
430
+	}
431
+
432
+	/**
433
+	 * You probably only want to deal with this through SessionAlert.
434
+	 *
435
+	 * @param string[] $data
436
+	 */
437
+	public static function setSessionAlertData($data)
438
+	{
439
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
440
+		$session['alerts'] = $data;
441
+	}
442
+
443
+	/**
444
+	 * You probably only want to deal with this through TokenManager.
445
+	 *
446
+	 * @return string[]
447
+	 */
448
+	public static function getSessionTokenData()
449
+	{
450
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
451
+		if (array_key_exists('tokens', $session)) {
452
+			return $session['tokens'];
453
+		}
454
+
455
+		return array();
456
+	}
457
+
458
+	/**
459
+	 * You probably only want to deal with this through TokenManager.
460
+	 *
461
+	 * @param string[] $data
462
+	 */
463
+	public static function setSessionTokenData($data)
464
+	{
465
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
466
+		$session['tokens'] = $data;
467
+	}
468
+
469
+	/**
470
+	 * @param string $key
471
+	 *
472
+	 * @return mixed
473
+	 */
474
+	public static function getSessionContext($key)
475
+	{
476
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
477
+
478
+		if (!isset($session['context'])) {
479
+			$session['context'] = array();
480
+		}
481
+
482
+		if (!isset($session['context'][$key])) {
483
+			return null;
484
+		}
485
+
486
+		return $session['context'][$key];
487
+	}
488
+
489
+	/**
490
+	 * @param string $key
491
+	 * @param mixed  $data
492
+	 */
493
+	public static function setSessionContext($key, $data)
494
+	{
495
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
496
+
497
+		if (!isset($session['context'])) {
498
+			$session['context'] = array();
499
+		}
500
+
501
+		$session['context'][$key] = $data;
502
+	}
503
+
504
+	/**
505
+	 * @return int|null
506
+	 */
507
+	public static function getSessionUserId()
508
+	{
509
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
510
+
511
+		return isset($session['userID']) ? (int)$session['userID'] : null;
512
+	}
513
+
514
+	/**
515
+	 * @return int|null
516
+	 */
517
+	public static function getSessionDomain()
518
+	{
519
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
520
+
521
+		return isset($session['domainID']) ? (int)$session['domainID'] : null;
522
+	}
523
+
524
+	/**
525
+	 * @param User $user
526
+	 */
527
+	public static function setOAuthPartialLogin(User $user)
528
+	{
529
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
530
+		$session['oauthPartialLogin'] = $user->getId();
531
+	}
532
+
533
+	/**
534
+	 * @return int|null
535
+	 */
536
+	public static function getOAuthPartialLogin()
537
+	{
538
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
539
+
540
+		return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null;
541
+	}
542
+
543
+	public static function setAuthPartialLogin($userId, $stage)
544
+	{
545
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
546
+		$session['authPartialLoginId'] = $userId;
547
+		$session['authPartialLoginStage'] = $stage;
548
+	}
549
+
550
+	public static function getAuthPartialLogin()
551
+	{
552
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
553
+
554
+		$userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null;
555
+		$stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null;
556
+
557
+		return array($userId, $stage);
558
+	}
559
+
560
+	public static function clearAuthPartialLogin()
561
+	{
562
+		$session = &self::$globalStateProvider->getSessionSuperGlobal();
563
+		unset($session['authPartialLoginId']);
564
+		unset($session['authPartialLoginStage']);
565
+	}
566
+
567
+	/**
568
+	 * @return null|string
569
+	 */
570
+	public static function userAgent()
571
+	{
572
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
573
+
574
+		if (isset($server['HTTP_USER_AGENT'])) {
575
+			return $server['HTTP_USER_AGENT'];
576
+		}
577
+
578
+		return null;
579
+	}
580
+
581
+	/**
582
+	 * @return null|string
583
+	 */
584
+	public static function scriptName()
585
+	{
586
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
587
+
588
+		if (isset($server['SCRIPT_NAME'])) {
589
+			return $server['SCRIPT_NAME'];
590
+		}
591
+
592
+		return null;
593
+	}
594
+
595
+	/**
596
+	 * @return null|string
597
+	 */
598
+	public static function origin()
599
+	{
600
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
601
+
602
+		if (isset($server['HTTP_ORIGIN'])) {
603
+			return $server['HTTP_ORIGIN'];
604
+		}
605
+
606
+		return null;
607
+	}
608
+
609
+	public static function httpHeader(string $headerName): ?string {
610
+		$server = &self::$globalStateProvider->getServerSuperGlobal();
611
+
612
+		$headerKey = strtoupper("HTTP_" . str_replace('-', '_', $headerName));
613
+
614
+		if (isset($server[$headerKey])) {
615
+			return $server[$headerKey];
616
+		}
617
+
618
+		return null;
619
+	}
620
+
621
+	public static function testSiteNoticeCookieValue($expectedHash)
622
+	{
623
+		$cookie = &self::$globalStateProvider->getCookieSuperGlobal();
624
+
625
+		if (isset($cookie['sitenotice'])) {
626
+			return $cookie['sitenotice'] === $expectedHash;
627
+		}
628
+
629
+		return false;
630
+	}
631
+
632
+	public static function requestListDefaultSort()
633
+	{
634
+		$cookie = &self::$globalStateProvider->getCookieSuperGlobal();
635
+
636
+		if (isset($cookie['request_table_sort'])) {
637
+			return explode('/', $cookie['request_table_sort'], 2);
638
+		}
639
+		else {
640
+			return ['id', 'asc'];
641
+		}
642
+	}
643 643
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,8 +66,7 @@  discard block
 block discarded – undo
66 66
             if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') {
67 67
                 // Client <=> Proxy is encrypted
68 68
                 return true;
69
-            }
70
-            else {
69
+            } else {
71 70
                 // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.
72 71
                 return false;
73 72
             }
@@ -635,8 +634,7 @@  discard block
 block discarded – undo
635 634
 
636 635
         if (isset($cookie['request_table_sort'])) {
637 636
             return explode('/', $cookie['request_table_sort'], 2);
638
-        }
639
-        else {
637
+        } else {
640 638
             return ['id', 'asc'];
641 639
         }
642 640
     }
Please login to merge, or discard this patch.
includes/RequestStatus.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class RequestStatus
12 12
 {
13
-    const HOSPITAL = 'Hospital';
14
-    const JOBQUEUE = 'JobQueue';
15
-    const CLOSED = 'Closed';
16
-    const OPEN = 'Open';
13
+	const HOSPITAL = 'Hospital';
14
+	const JOBQUEUE = 'JobQueue';
15
+	const CLOSED = 'Closed';
16
+	const OPEN = 'Open';
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
includes/API/Actions/StatusAction.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class StatusAction extends XmlApiPageBase implements IXmlApiAction
22 22
 {
23
-    public function executeApiAction(DOMElement $apiDocument)
24
-    {
25
-        $statusElement = $this->document->createElement("status");
26
-        $apiDocument->appendChild($statusElement);
23
+	public function executeApiAction(DOMElement $apiDocument)
24
+	{
25
+		$statusElement = $this->document->createElement("status");
26
+		$apiDocument->appendChild($statusElement);
27 27
 
28
-        $query = $this->getDatabase()->prepare(<<<SQL
28
+		$query = $this->getDatabase()->prepare(<<<SQL
29 29
             SELECT /* Api/StatusAction */ COUNT(*) AS count
30 30
             FROM request
31 31
             WHERE
@@ -33,87 +33,87 @@  discard block
 block discarded – undo
33 33
                 AND queue = :queue
34 34
                 AND emailconfirm = 'Confirmed';
35 35
 SQL
36
-        );
37
-
38
-        $allQueues = RequestQueue::getAllQueues($this->getDatabase());
39
-
40
-        foreach ($allQueues as $value) {
41
-            $query->bindValue(":pstatus", RequestStatus::OPEN);
42
-            $query->bindValue(":queue", $value->getId());
43
-            $query->execute();
44
-            $sus = $query->fetchColumn();
45
-            $statusElement->setAttribute($value->getApiName(), $sus);
46
-            $query->closeCursor();
47
-        }
48
-
49
-        // hospital queue
50
-        // FIXME: domains
51
-        $search = RequestSearchHelper::get($this->getDatabase(), 1)->isHospitalised();
52
-
53
-        if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
54
-            $search->withConfirmedEmail();
55
-        }
56
-        $search->getRecordCount($hospitalCount);
57
-        $statusElement->setAttribute('x-hospital', $hospitalCount);
58
-
59
-        // job queue
60
-        // FIXME: domains
61
-        $search = RequestSearchHelper::get($this->getDatabase(), 1)
62
-            ->byStatus(RequestStatus::JOBQUEUE);
63
-
64
-        if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
65
-            $search->withConfirmedEmail();
66
-        }
67
-
68
-        $search->getRecordCount($jobQueueRequestCount);
69
-        $statusElement->setAttribute('x-jobqueue', $jobQueueRequestCount);
70
-
71
-        // bans
72
-        $query = $this->getDatabase()->prepare(<<<SQL
36
+		);
37
+
38
+		$allQueues = RequestQueue::getAllQueues($this->getDatabase());
39
+
40
+		foreach ($allQueues as $value) {
41
+			$query->bindValue(":pstatus", RequestStatus::OPEN);
42
+			$query->bindValue(":queue", $value->getId());
43
+			$query->execute();
44
+			$sus = $query->fetchColumn();
45
+			$statusElement->setAttribute($value->getApiName(), $sus);
46
+			$query->closeCursor();
47
+		}
48
+
49
+		// hospital queue
50
+		// FIXME: domains
51
+		$search = RequestSearchHelper::get($this->getDatabase(), 1)->isHospitalised();
52
+
53
+		if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
54
+			$search->withConfirmedEmail();
55
+		}
56
+		$search->getRecordCount($hospitalCount);
57
+		$statusElement->setAttribute('x-hospital', $hospitalCount);
58
+
59
+		// job queue
60
+		// FIXME: domains
61
+		$search = RequestSearchHelper::get($this->getDatabase(), 1)
62
+			->byStatus(RequestStatus::JOBQUEUE);
63
+
64
+		if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
65
+			$search->withConfirmedEmail();
66
+		}
67
+
68
+		$search->getRecordCount($jobQueueRequestCount);
69
+		$statusElement->setAttribute('x-jobqueue', $jobQueueRequestCount);
70
+
71
+		// bans
72
+		$query = $this->getDatabase()->prepare(<<<SQL
73 73
             SELECT /* Api/StatusAction */ COUNT(*) AS count
74 74
             FROM ban
75 75
             WHERE
76 76
                 (duration > UNIX_TIMESTAMP() OR duration is null)
77 77
                 AND active = 1;
78 78
 SQL
79
-        );
79
+		);
80 80
 
81
-        $query->execute();
82
-        $sus = $query->fetchColumn();
83
-        $statusElement->setAttribute("bans", $sus);
84
-        $query->closeCursor();
81
+		$query->execute();
82
+		$sus = $query->fetchColumn();
83
+		$statusElement->setAttribute("bans", $sus);
84
+		$query->closeCursor();
85 85
 
86
-        $query = $this->getDatabase()->prepare(<<<SQL
86
+		$query = $this->getDatabase()->prepare(<<<SQL
87 87
 SELECT /* Api/StatusAction */ COUNT(*) AS count
88 88
 FROM user WHERE status = :ulevel;
89 89
 SQL
90
-        );
90
+		);
91 91
 
92
-        $query->bindValue(":ulevel", "New");
93
-        $query->execute();
94
-        $sus = $query->fetchColumn();
95
-        $statusElement->setAttribute("usernew", $sus);
96
-        $query->closeCursor();
92
+		$query->bindValue(":ulevel", "New");
93
+		$query->execute();
94
+		$sus = $query->fetchColumn();
95
+		$statusElement->setAttribute("usernew", $sus);
96
+		$query->closeCursor();
97 97
 
98
-        $query = $this->getDatabase()->prepare(<<<SQL
98
+		$query = $this->getDatabase()->prepare(<<<SQL
99 99
 select /* Api/StatusAction */ COUNT(*) from user u
100 100
 inner join userrole ur on u.id = ur.user
101 101
 where u.status = 'Active' and ur.role = :ulevel
102 102
 SQL
103
-        );
104
-
105
-        $query->bindValue(":ulevel", "admin");
106
-        $query->execute();
107
-        $sus = $query->fetchColumn();
108
-        $statusElement->setAttribute("useradmin", $sus);
109
-        $query->closeCursor();
110
-
111
-        $query->bindValue(":ulevel", "user");
112
-        $query->execute();
113
-        $sus = $query->fetchColumn();
114
-        $statusElement->setAttribute("user", $sus);
115
-        $query->closeCursor();
116
-
117
-        return $apiDocument;
118
-    }
103
+		);
104
+
105
+		$query->bindValue(":ulevel", "admin");
106
+		$query->execute();
107
+		$sus = $query->fetchColumn();
108
+		$statusElement->setAttribute("useradmin", $sus);
109
+		$query->closeCursor();
110
+
111
+		$query->bindValue(":ulevel", "user");
112
+		$query->execute();
113
+		$sus = $query->fetchColumn();
114
+		$statusElement->setAttribute("user", $sus);
115
+		$query->closeCursor();
116
+
117
+		return $apiDocument;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
includes/API/Actions/JsUsersAction.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
16 16
 
17 17
 class JsUsersAction extends JsonApiPageBase implements IJsonApiAction
18 18
 {
19
-    public function executeApiAction()
20
-    {
21
-        $userSearchHelper = UserSearchHelper::get($this->getDatabase());
19
+	public function executeApiAction()
20
+	{
21
+		$userSearchHelper = UserSearchHelper::get($this->getDatabase());
22 22
 
23
-        if (WebRequest::getString('all') === null) {
24
-            $userSearchHelper->byStatus(User::STATUS_ACTIVE);
23
+		if (WebRequest::getString('all') === null) {
24
+			$userSearchHelper->byStatus(User::STATUS_ACTIVE);
25 25
 
26
-        }
26
+		}
27 27
 
28
-        $dataset = $userSearchHelper->fetchColumn('username');
29
-        return $dataset;
30
-    }
28
+		$dataset = $userSearchHelper->fetchColumn('username');
29
+		return $dataset;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
includes/API/Actions/JsTemplateConfirmsAction.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 
15 15
 class JsTemplateConfirmsAction extends JsonApiPageBase implements IJsonApiAction
16 16
 {
17
-    public function executeApiAction()
18
-    {
19
-        /** @var EmailTemplate[] $templates */
20
-        // FIXME: domains!
21
-        $templates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase(), 1);
17
+	public function executeApiAction()
18
+	{
19
+		/** @var EmailTemplate[] $templates */
20
+		// FIXME: domains!
21
+		$templates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase(), 1);
22 22
 
23
-        $dataset = [];
24
-        foreach ($templates as $tpl) {
25
-            if ($tpl->getJsquestion() != "") {
26
-                $dataset[$tpl->getId()] = $tpl->getJsquestion();
27
-            }
28
-        }
23
+		$dataset = [];
24
+		foreach ($templates as $tpl) {
25
+			if ($tpl->getJsquestion() != "") {
26
+				$dataset[$tpl->getId()] = $tpl->getJsquestion();
27
+			}
28
+		}
29 29
 
30
-        return $dataset;
31
-    }
30
+		return $dataset;
31
+	}
32 32
 }
Please login to merge, or discard this patch.
includes/Router/PublicRequestRouter.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@
 block discarded – undo
59 59
         if (count($pathInfo) === 3 && $pathInfo[0] === 'r') {
60 60
             // this request should be routed to the dynamic request form handler
61 61
             return [PageRequestAccount::class, 'dynamic'];
62
-        }
63
-        else {
62
+        } else {
64 63
             return parent::getRouteFromPath($pathInfo);
65 64
         }
66 65
     }
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -17,59 +17,59 @@
 block discarded – undo
17 17
 
18 18
 class PublicRequestRouter extends RequestRouter
19 19
 {
20
-    /**
21
-     * Gets the route map to be used by this request router.
22
-     *
23
-     * @return array
24
-     */
25
-    protected function getRouteMap()
26
-    {
27
-        return array(
28
-            // Page showing a message stating the request has been submitted to our internal queues
29
-            'requestSubmitted'          =>
30
-                array(
31
-                    'class'   => PageRequestSubmitted::class,
32
-                    'actions' => array(),
33
-                ),
34
-            // Page showing a message stating that email confirmation is required to continue
35
-            'emailConfirmationRequired' =>
36
-                array(
37
-                    'class'   => PageEmailConfirmationRequired::class,
38
-                    'actions' => array(),
39
-                ),
40
-            // Action page which handles email confirmation
41
-            'confirmEmail'              =>
42
-                array(
43
-                    'class'   => PageConfirmEmail::class,
44
-                    'actions' => array(),
45
-                ),
46
-            // Page showing the privacy statement
47
-            'privacy'                   =>
48
-                array(
49
-                    'class'   => PagePublicPrivacy::class,
50
-                    'actions' => array(),
51
-                ),
52
-        );
53
-    }
20
+	/**
21
+	 * Gets the route map to be used by this request router.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	protected function getRouteMap()
26
+	{
27
+		return array(
28
+			// Page showing a message stating the request has been submitted to our internal queues
29
+			'requestSubmitted'          =>
30
+				array(
31
+					'class'   => PageRequestSubmitted::class,
32
+					'actions' => array(),
33
+				),
34
+			// Page showing a message stating that email confirmation is required to continue
35
+			'emailConfirmationRequired' =>
36
+				array(
37
+					'class'   => PageEmailConfirmationRequired::class,
38
+					'actions' => array(),
39
+				),
40
+			// Action page which handles email confirmation
41
+			'confirmEmail'              =>
42
+				array(
43
+					'class'   => PageConfirmEmail::class,
44
+					'actions' => array(),
45
+				),
46
+			// Page showing the privacy statement
47
+			'privacy'                   =>
48
+				array(
49
+					'class'   => PagePublicPrivacy::class,
50
+					'actions' => array(),
51
+				),
52
+		);
53
+	}
54 54
 
55
-    /**
56
-     * Gets the default route if no explicit route is requested.
57
-     *
58
-     * @return callable
59
-     */
60
-    protected function getDefaultRoute()
61
-    {
62
-        return array(PageRequestAccount::class, 'main');
63
-    }
55
+	/**
56
+	 * Gets the default route if no explicit route is requested.
57
+	 *
58
+	 * @return callable
59
+	 */
60
+	protected function getDefaultRoute()
61
+	{
62
+		return array(PageRequestAccount::class, 'main');
63
+	}
64 64
 
65
-    public function getRouteFromPath($pathInfo): array
66
-    {
67
-        if (count($pathInfo) === 3 && $pathInfo[0] === 'r') {
68
-            // this request should be routed to the dynamic request form handler
69
-            return [PageRequestAccount::class, 'dynamic'];
70
-        }
71
-        else {
72
-            return parent::getRouteFromPath($pathInfo);
73
-        }
74
-    }
65
+	public function getRouteFromPath($pathInfo): array
66
+	{
67
+		if (count($pathInfo) === 3 && $pathInfo[0] === 'r') {
68
+			// this request should be routed to the dynamic request form handler
69
+			return [PageRequestAccount::class, 'dynamic'];
70
+		}
71
+		else {
72
+			return parent::getRouteFromPath($pathInfo);
73
+		}
74
+	}
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Background/Task/BotCreationTask.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,20 +17,20 @@
 block discarded – undo
17 17
 
18 18
 class BotCreationTask extends CreationTaskBase
19 19
 {
20
-    /**
21
-     * @return IMediaWikiClient
22
-     */
23
-    protected function getMediaWikiClient()
24
-    {
25
-        // FIXME: domains!
26
-        /** @var Domain $domain */
27
-        $domain = Domain::getById(1, $this->getDatabase());
20
+	/**
21
+	 * @return IMediaWikiClient
22
+	 */
23
+	protected function getMediaWikiClient()
24
+	{
25
+		// FIXME: domains!
26
+		/** @var Domain $domain */
27
+		$domain = Domain::getById(1, $this->getDatabase());
28 28
 
29
-        return new BotMediaWikiClient($this->getSiteConfiguration(), $domain);
30
-    }
29
+		return new BotMediaWikiClient($this->getSiteConfiguration(), $domain);
30
+	}
31 31
 
32
-    protected function getCreationReason(Request $request, User $user)
33
-    {
34
-        return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]';
35
-    }
32
+	protected function getCreationReason(Request $request, User $user)
33
+	{
34
+		return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]';
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.