Failed Conditions
Push — sul3-quickfix ( f1546e...6b5732 )
by Michael
10:01 queued 05:48
created
includes/SiteConfiguration.php 1 patch
Indentation   +1110 added lines, -1110 removed lines patch added patch discarded remove patch
@@ -18,1114 +18,1114 @@
 block discarded – undo
18 18
  */
19 19
 class SiteConfiguration
20 20
 {
21
-    private $baseUrl = 'https://accounts.wmflabs.org';
22
-    private $filePath = __DIR__ . '/..';
23
-    private $schemaVersion = 50;
24
-    private $debuggingTraceEnabled = false;
25
-    private $debuggingCssBreakpointsEnabled = false;
26
-    private $dataClearIp = '127.0.0.1';
27
-    private $dataClearEmail = '[email protected]';
28
-    private $dataClearInterval = '15 DAY';
29
-    private $forceIdentification = true;
30
-    private $identificationCacheExpiry = '1 DAY';
31
-    private $metaWikimediaWebServiceEndpoint = 'https://meta.wikimedia.org/w/api.php';
32
-    private $enforceOAuth = false;
33
-    private $emailConfirmationEnabled = true;
34
-    private $emailConfirmationExpiryDays = 7;
35
-    private $miserModeLimit = 25;
36
-    private $squidList = array();
37
-    private $useStrictTransportSecurity = false;
38
-    private $userAgent = 'Wikipedia-ACC Tool/0.1 (+https://accounts.wmflabs.org/internal.php/team)';
39
-    private $curlDisableVerifyPeer = false;
40
-    private $useOAuthSignup = true;
41
-    private $oauthConsumerToken;
42
-    /** @var array */
43
-    private $oauthLegacyConsumerTokens;
44
-    private $oauthConsumerSecret;
45
-    private $oauthIdentityGraceTime = '24 hours';
46
-    private $oauthMediaWikiCanonicalServer = 'https://en.wikipedia.org';
47
-    private $xffTrustedHostsFile = '../TrustedXFF/trusted-hosts.txt';
48
-    private $crossOriginResourceSharingHosts = array(
49
-        "https://en.wikipedia.org",
50
-        "https://meta.wikimedia.org",
51
-    );
52
-    private $ircNotificationsEnabled = true;
53
-    private $ircNotificationsInstance = 'Development';
54
-    private $errorLog = 'errorlog';
55
-    private $titleBlacklistEnabled = false;
56
-    /** @var null|string $locationProviderApiKey */
57
-    private $locationProviderApiKey = null;
58
-    private $torExitPaths = array();
59
-    private $creationBotUsername = '';
60
-    private $creationBotPassword = '';
61
-    private $curlCookieJar = __DIR__ . '/../../cookies.txt';
62
-    private $yubicoApiId = 0;
63
-    private $yubicoApiKey = "";
64
-    private $totpEncryptionKey = "1234";
65
-    private $identificationNoticeboardPage = 'Access to nonpublic personal data policy/Noticeboard';
66
-    private $identificationNoticeboardWebserviceEndpoint = 'https://meta.wikimedia.org/w/api.php';
67
-    private $registrationAllowed = true;
68
-    private $cspReportUri = null;
69
-    private $resourceCacheEpoch = 1;
70
-    private $commonEmailDomains = ['gmail.com', 'hotmail.com', 'outlook.com'];
71
-    private $banMaxIpBlockRange = [4 => 20, 6 => 48];
72
-    private $banMaxIpRange = [4 => 16, 6 => 32];
73
-    private $jobQueueBatchSize = 10;
74
-    private $amqpConfiguration = ['host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => '', 'tls' => false];
75
-    private $emailSender = '[email protected]';
76
-    private $acceptClientHints = [];
77
-    private string $cookiePath = '/';
78
-    private string $cookieSessionName = 'ACC';
79
-    private array $offline = ['offline' => false, 'reason' => '', 'culprit' => ''];
80
-    private array $databaseConfig = [
81
-        'datasource' => 'mysql:host=localhost;dbname=waca',
82
-        'username' => 'waca',
83
-        'password' => 'waca'
84
-    ];
85
-    private string $privacyStatementPath = '';
86
-
87
-    /**
88
-     * Gets the base URL of the tool
89
-     *
90
-     * If the internal page of the tool is at http://localhost/path/internal.php, this would be set to
91
-     * http://localhost/path
92
-     * @return string
93
-     */
94
-    public function getBaseUrl()
95
-    {
96
-        return $this->baseUrl;
97
-    }
98
-
99
-    /**
100
-     * @param string $baseUrl
101
-     *
102
-     * @return SiteConfiguration
103
-     */
104
-    public function setBaseUrl($baseUrl)
105
-    {
106
-        $this->baseUrl = $baseUrl;
107
-
108
-        return $this;
109
-    }
110
-
111
-    /**
112
-     * Path on disk to the directory containing the tool's code
113
-     * @return string
114
-     */
115
-    public function getFilePath()
116
-    {
117
-        return $this->filePath;
118
-    }
119
-
120
-    /**
121
-     * @param string $filePath
122
-     *
123
-     * @return SiteConfiguration
124
-     */
125
-    public function setFilePath($filePath)
126
-    {
127
-        $this->filePath = $filePath;
128
-
129
-        return $this;
130
-    }
131
-
132
-    /**
133
-     * @return int
134
-     */
135
-    public function getSchemaVersion()
136
-    {
137
-        return $this->schemaVersion;
138
-    }
139
-
140
-    /**
141
-     * @param int $schemaVersion
142
-     *
143
-     * @return SiteConfiguration
144
-     */
145
-    public function setSchemaVersion($schemaVersion)
146
-    {
147
-        $this->schemaVersion = $schemaVersion;
148
-
149
-        return $this;
150
-    }
151
-
152
-    /**
153
-     * @return mixed
154
-     */
155
-    public function getDebuggingTraceEnabled()
156
-    {
157
-        return $this->debuggingTraceEnabled;
158
-    }
159
-
160
-    /**
161
-     * @param mixed $debuggingTraceEnabled
162
-     *
163
-     * @return SiteConfiguration
164
-     */
165
-    public function setDebuggingTraceEnabled($debuggingTraceEnabled)
166
-    {
167
-        $this->debuggingTraceEnabled = $debuggingTraceEnabled;
168
-
169
-        return $this;
170
-    }
171
-
172
-    public function getDebuggingCssBreakpointsEnabled() : bool
173
-    {
174
-        return $this->debuggingCssBreakpointsEnabled;
175
-    }
176
-
177
-    public function setDebuggingCssBreakpointsEnabled(bool $debuggingCssBreakpointsEnabled) : SiteConfiguration
178
-    {
179
-        $this->debuggingCssBreakpointsEnabled = $debuggingCssBreakpointsEnabled;
180
-
181
-        return $this;
182
-    }
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function getDataClearIp()
188
-    {
189
-        return $this->dataClearIp;
190
-    }
191
-
192
-    /**
193
-     * @param string $dataClearIp
194
-     *
195
-     * @return SiteConfiguration
196
-     */
197
-    public function setDataClearIp($dataClearIp)
198
-    {
199
-        $this->dataClearIp = $dataClearIp;
200
-
201
-        return $this;
202
-    }
203
-
204
-    /**
205
-     * @return string
206
-     */
207
-    public function getDataClearEmail()
208
-    {
209
-        return $this->dataClearEmail;
210
-    }
211
-
212
-    /**
213
-     * @param string $dataClearEmail
214
-     *
215
-     * @return SiteConfiguration
216
-     */
217
-    public function setDataClearEmail($dataClearEmail)
218
-    {
219
-        $this->dataClearEmail = $dataClearEmail;
220
-
221
-        return $this;
222
-    }
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public function getForceIdentification()
228
-    {
229
-        return $this->forceIdentification;
230
-    }
231
-
232
-    /**
233
-     * @param boolean $forceIdentification
234
-     *
235
-     * @return SiteConfiguration
236
-     */
237
-    public function setForceIdentification($forceIdentification)
238
-    {
239
-        $this->forceIdentification = $forceIdentification;
240
-
241
-        return $this;
242
-    }
243
-
244
-    /**
245
-     * @return string
246
-     */
247
-    public function getIdentificationCacheExpiry()
248
-    {
249
-        return $this->identificationCacheExpiry;
250
-    }
251
-
252
-    /**
253
-     * @param string $identificationCacheExpiry
254
-     *
255
-     * @return SiteConfiguration
256
-     */
257
-    public function setIdentificationCacheExpiry($identificationCacheExpiry)
258
-    {
259
-        $this->identificationCacheExpiry = $identificationCacheExpiry;
260
-
261
-        return $this;
262
-    }
263
-
264
-    /**
265
-     * @return string
266
-     */
267
-    public function getMetaWikimediaWebServiceEndpoint()
268
-    {
269
-        return $this->metaWikimediaWebServiceEndpoint;
270
-    }
271
-
272
-    /**
273
-     * @param string $metaWikimediaWebServiceEndpoint
274
-     *
275
-     * @return SiteConfiguration
276
-     */
277
-    public function setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)
278
-    {
279
-        $this->metaWikimediaWebServiceEndpoint = $metaWikimediaWebServiceEndpoint;
280
-
281
-        return $this;
282
-    }
283
-
284
-    /**
285
-     * @return boolean
286
-     */
287
-    public function getEnforceOAuth()
288
-    {
289
-        return $this->enforceOAuth;
290
-    }
291
-
292
-    /**
293
-     * @param boolean $enforceOAuth
294
-     *
295
-     * @return SiteConfiguration
296
-     */
297
-    public function setEnforceOAuth($enforceOAuth)
298
-    {
299
-        $this->enforceOAuth = $enforceOAuth;
300
-
301
-        return $this;
302
-    }
303
-
304
-    /**
305
-     * @return boolean
306
-     */
307
-    public function getEmailConfirmationEnabled()
308
-    {
309
-        return $this->emailConfirmationEnabled;
310
-    }
311
-
312
-    /**
313
-     * @param boolean $emailConfirmationEnabled
314
-     *
315
-     * @return $this
316
-     */
317
-    public function setEmailConfirmationEnabled($emailConfirmationEnabled)
318
-    {
319
-        $this->emailConfirmationEnabled = $emailConfirmationEnabled;
320
-
321
-        return $this;
322
-    }
323
-
324
-    /**
325
-     * @return int
326
-     */
327
-    public function getMiserModeLimit()
328
-    {
329
-        return $this->miserModeLimit;
330
-    }
331
-
332
-    /**
333
-     * @param int $miserModeLimit
334
-     *
335
-     * @return SiteConfiguration
336
-     */
337
-    public function setMiserModeLimit($miserModeLimit)
338
-    {
339
-        $this->miserModeLimit = $miserModeLimit;
340
-
341
-        return $this;
342
-    }
343
-
344
-    /**
345
-     * @return array
346
-     */
347
-    public function getSquidList()
348
-    {
349
-        return $this->squidList;
350
-    }
351
-
352
-    /**
353
-     * @param array $squidList
354
-     *
355
-     * @return SiteConfiguration
356
-     */
357
-    public function setSquidList($squidList)
358
-    {
359
-        $this->squidList = $squidList;
360
-
361
-        return $this;
362
-    }
363
-
364
-    /**
365
-     * @return boolean
366
-     */
367
-    public function getUseStrictTransportSecurity()
368
-    {
369
-        return $this->useStrictTransportSecurity;
370
-    }
371
-
372
-    /**
373
-     * @param boolean $useStrictTransportSecurity
374
-     *
375
-     * @return SiteConfiguration
376
-     */
377
-    public function setUseStrictTransportSecurity($useStrictTransportSecurity)
378
-    {
379
-        $this->useStrictTransportSecurity = $useStrictTransportSecurity;
380
-
381
-        return $this;
382
-    }
383
-
384
-    /**
385
-     * @return string
386
-     */
387
-    public function getUserAgent()
388
-    {
389
-        return $this->userAgent;
390
-    }
391
-
392
-    /**
393
-     * @param string $userAgent
394
-     *
395
-     * @return SiteConfiguration
396
-     */
397
-    public function setUserAgent($userAgent)
398
-    {
399
-        $this->userAgent = $userAgent;
400
-
401
-        return $this;
402
-    }
403
-
404
-    /**
405
-     * @return boolean
406
-     */
407
-    public function getCurlDisableVerifyPeer()
408
-    {
409
-        return $this->curlDisableVerifyPeer;
410
-    }
411
-
412
-    /**
413
-     * @param boolean $curlDisableVerifyPeer
414
-     *
415
-     * @return SiteConfiguration
416
-     */
417
-    public function setCurlDisableVerifyPeer($curlDisableVerifyPeer)
418
-    {
419
-        $this->curlDisableVerifyPeer = $curlDisableVerifyPeer;
420
-
421
-        return $this;
422
-    }
423
-
424
-    /**
425
-     * @return boolean
426
-     */
427
-    public function getUseOAuthSignup()
428
-    {
429
-        return $this->useOAuthSignup;
430
-    }
431
-
432
-    /**
433
-     * @param boolean $useOAuthSignup
434
-     *
435
-     * @return SiteConfiguration
436
-     */
437
-    public function setUseOAuthSignup($useOAuthSignup)
438
-    {
439
-        $this->useOAuthSignup = $useOAuthSignup;
440
-
441
-        return $this;
442
-    }
443
-
444
-    /**
445
-     * @return mixed
446
-     */
447
-    public function getOAuthConsumerToken()
448
-    {
449
-        return $this->oauthConsumerToken;
450
-    }
451
-
452
-    /**
453
-     * @param mixed $oauthConsumerToken
454
-     *
455
-     * @return SiteConfiguration
456
-     */
457
-    public function setOAuthConsumerToken($oauthConsumerToken)
458
-    {
459
-        $this->oauthConsumerToken = $oauthConsumerToken;
460
-
461
-        return $this;
462
-    }
463
-
464
-    /**
465
-     * @return mixed
466
-     */
467
-    public function getOAuthConsumerSecret()
468
-    {
469
-        return $this->oauthConsumerSecret;
470
-    }
471
-
472
-    /**
473
-     * @param mixed $oauthConsumerSecret
474
-     *
475
-     * @return SiteConfiguration
476
-     */
477
-    public function setOAuthConsumerSecret($oauthConsumerSecret)
478
-    {
479
-        $this->oauthConsumerSecret = $oauthConsumerSecret;
480
-
481
-        return $this;
482
-    }
483
-
484
-    /**
485
-     * @return string
486
-     */
487
-    public function getDataClearInterval()
488
-    {
489
-        return $this->dataClearInterval;
490
-    }
491
-
492
-    /**
493
-     * @param string $dataClearInterval
494
-     *
495
-     * @return SiteConfiguration
496
-     */
497
-    public function setDataClearInterval($dataClearInterval)
498
-    {
499
-        $this->dataClearInterval = $dataClearInterval;
500
-
501
-        return $this;
502
-    }
503
-
504
-    /**
505
-     * @return string
506
-     */
507
-    public function getXffTrustedHostsFile()
508
-    {
509
-        return $this->xffTrustedHostsFile;
510
-    }
511
-
512
-    /**
513
-     * @param string $xffTrustedHostsFile
514
-     *
515
-     * @return SiteConfiguration
516
-     */
517
-    public function setXffTrustedHostsFile($xffTrustedHostsFile)
518
-    {
519
-        $this->xffTrustedHostsFile = $xffTrustedHostsFile;
520
-
521
-        return $this;
522
-    }
523
-
524
-    /**
525
-     * @return array
526
-     */
527
-    public function getCrossOriginResourceSharingHosts()
528
-    {
529
-        return $this->crossOriginResourceSharingHosts;
530
-    }
531
-
532
-    /**
533
-     * @param array $crossOriginResourceSharingHosts
534
-     *
535
-     * @return SiteConfiguration
536
-     */
537
-    public function setCrossOriginResourceSharingHosts($crossOriginResourceSharingHosts)
538
-    {
539
-        $this->crossOriginResourceSharingHosts = $crossOriginResourceSharingHosts;
540
-
541
-        return $this;
542
-    }
543
-
544
-    /**
545
-     * @return boolean
546
-     */
547
-    public function getIrcNotificationsEnabled()
548
-    {
549
-        return $this->ircNotificationsEnabled;
550
-    }
551
-
552
-    /**
553
-     * @param boolean $ircNotificationsEnabled
554
-     *
555
-     * @return SiteConfiguration
556
-     */
557
-    public function setIrcNotificationsEnabled($ircNotificationsEnabled)
558
-    {
559
-        $this->ircNotificationsEnabled = $ircNotificationsEnabled;
560
-
561
-        return $this;
562
-    }
563
-
564
-    /**
565
-     * @param string $errorLog
566
-     *
567
-     * @return SiteConfiguration
568
-     */
569
-    public function setErrorLog($errorLog)
570
-    {
571
-        $this->errorLog = $errorLog;
572
-
573
-        return $this;
574
-    }
575
-
576
-    /**
577
-     * @return string
578
-     */
579
-    public function getErrorLog()
580
-    {
581
-        return $this->errorLog;
582
-    }
583
-
584
-    /**
585
-     * @param int $emailConfirmationExpiryDays
586
-     *
587
-     * @return SiteConfiguration
588
-     */
589
-    public function setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)
590
-    {
591
-        $this->emailConfirmationExpiryDays = $emailConfirmationExpiryDays;
592
-
593
-        return $this;
594
-    }
595
-
596
-    /**
597
-     * @return int
598
-     */
599
-    public function getEmailConfirmationExpiryDays()
600
-    {
601
-        return $this->emailConfirmationExpiryDays;
602
-    }
603
-
604
-    /**
605
-     * @param string $ircNotificationsInstance
606
-     *
607
-     * @return SiteConfiguration
608
-     */
609
-    public function setIrcNotificationsInstance($ircNotificationsInstance)
610
-    {
611
-        $this->ircNotificationsInstance = $ircNotificationsInstance;
612
-
613
-        return $this;
614
-    }
615
-
616
-    /**
617
-     * @return string
618
-     */
619
-    public function getIrcNotificationsInstance()
620
-    {
621
-        return $this->ircNotificationsInstance;
622
-    }
623
-
624
-    /**
625
-     * @param boolean $titleBlacklistEnabled
626
-     *
627
-     * @return SiteConfiguration
628
-     */
629
-    public function setTitleBlacklistEnabled($titleBlacklistEnabled)
630
-    {
631
-        $this->titleBlacklistEnabled = $titleBlacklistEnabled;
632
-
633
-        return $this;
634
-    }
635
-
636
-    /**
637
-     * @return boolean
638
-     */
639
-    public function getTitleBlacklistEnabled()
640
-    {
641
-        return $this->titleBlacklistEnabled;
642
-    }
643
-
644
-    /**
645
-     * @param string|null $locationProviderApiKey
646
-     *
647
-     * @return SiteConfiguration
648
-     */
649
-    public function setLocationProviderApiKey($locationProviderApiKey)
650
-    {
651
-        $this->locationProviderApiKey = $locationProviderApiKey;
652
-
653
-        return $this;
654
-    }
655
-
656
-    /**
657
-     * @return null|string
658
-     */
659
-    public function getLocationProviderApiKey()
660
-    {
661
-        return $this->locationProviderApiKey;
662
-    }
663
-
664
-    /**
665
-     * @param array $torExitPaths
666
-     *
667
-     * @return SiteConfiguration
668
-     */
669
-    public function setTorExitPaths($torExitPaths)
670
-    {
671
-        $this->torExitPaths = $torExitPaths;
672
-
673
-        return $this;
674
-    }
675
-
676
-    /**
677
-     * @return array
678
-     */
679
-    public function getTorExitPaths()
680
-    {
681
-        return $this->torExitPaths;
682
-    }
683
-
684
-    /**
685
-     * @param string $oauthIdentityGraceTime
686
-     *
687
-     * @return SiteConfiguration
688
-     */
689
-    public function setOauthIdentityGraceTime($oauthIdentityGraceTime)
690
-    {
691
-        $this->oauthIdentityGraceTime = $oauthIdentityGraceTime;
692
-
693
-        return $this;
694
-    }
695
-
696
-    /**
697
-     * @return string
698
-     */
699
-    public function getOauthIdentityGraceTime()
700
-    {
701
-        return $this->oauthIdentityGraceTime;
702
-    }
703
-
704
-    /**
705
-     * @param string $oauthMediaWikiCanonicalServer
706
-     *
707
-     * @return SiteConfiguration
708
-     */
709
-    public function setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer)
710
-    {
711
-        $this->oauthMediaWikiCanonicalServer = $oauthMediaWikiCanonicalServer;
712
-
713
-        return $this;
714
-    }
715
-
716
-    /**
717
-     * @return string
718
-     */
719
-    public function getOauthMediaWikiCanonicalServer()
720
-    {
721
-        return $this->oauthMediaWikiCanonicalServer;
722
-    }
723
-
724
-    /**
725
-     * @param string $creationBotUsername
726
-     *
727
-     * @return SiteConfiguration
728
-     */
729
-    public function setCreationBotUsername($creationBotUsername)
730
-    {
731
-        $this->creationBotUsername = $creationBotUsername;
732
-
733
-        return $this;
734
-    }
735
-
736
-    /**
737
-     * @return string
738
-     */
739
-    public function getCreationBotUsername()
740
-    {
741
-        return $this->creationBotUsername;
742
-    }
743
-
744
-    /**
745
-     * @param string $creationBotPassword
746
-     *
747
-     * @return SiteConfiguration
748
-     */
749
-    public function setCreationBotPassword($creationBotPassword)
750
-    {
751
-        $this->creationBotPassword = $creationBotPassword;
752
-
753
-        return $this;
754
-    }
755
-
756
-    /**
757
-     * @return string
758
-     */
759
-    public function getCreationBotPassword()
760
-    {
761
-        return $this->creationBotPassword;
762
-    }
763
-
764
-    /**
765
-     * @param string|null $curlCookieJar
766
-     *
767
-     * @return SiteConfiguration
768
-     */
769
-    public function setCurlCookieJar($curlCookieJar)
770
-    {
771
-        $this->curlCookieJar = $curlCookieJar;
772
-
773
-        return $this;
774
-    }
775
-
776
-    /**
777
-     * @return string|null
778
-     */
779
-    public function getCurlCookieJar()
780
-    {
781
-        return $this->curlCookieJar;
782
-    }
783
-
784
-    public function getYubicoApiId()
785
-    {
786
-        return $this->yubicoApiId;
787
-    }
788
-
789
-    public function setYubicoApiId($id)
790
-    {
791
-        $this->yubicoApiId = $id;
792
-
793
-        return $this;
794
-    }
795
-
796
-    public function getYubicoApiKey()
797
-    {
798
-        return $this->yubicoApiKey;
799
-    }
800
-
801
-    public function setYubicoApiKey($key)
802
-    {
803
-        $this->yubicoApiKey = $key;
804
-
805
-        return $this;
806
-    }
807
-
808
-    /**
809
-     * @return string
810
-     */
811
-    public function getTotpEncryptionKey()
812
-    {
813
-        return $this->totpEncryptionKey;
814
-    }
815
-
816
-    /**
817
-     * @param string $totpEncryptionKey
818
-     *
819
-     * @return SiteConfiguration
820
-     */
821
-    public function setTotpEncryptionKey($totpEncryptionKey)
822
-    {
823
-        $this->totpEncryptionKey = $totpEncryptionKey;
824
-
825
-        return $this;
826
-    }
827
-
828
-    /**
829
-     * @return string
830
-     */
831
-    public function getIdentificationNoticeboardPage()
832
-    {
833
-        return $this->identificationNoticeboardPage;
834
-    }
835
-
836
-    /**
837
-     * @param string $identificationNoticeboardPage
838
-     *
839
-     * @return SiteConfiguration
840
-     */
841
-    public function setIdentificationNoticeboardPage($identificationNoticeboardPage)
842
-    {
843
-        $this->identificationNoticeboardPage = $identificationNoticeboardPage;
844
-
845
-        return $this;
846
-    }
847
-
848
-    public function setIdentificationNoticeboardWebserviceEndpoint(string $identificationNoticeboardWebserviceEndpoint
849
-    ): SiteConfiguration {
850
-        $this->identificationNoticeboardWebserviceEndpoint = $identificationNoticeboardWebserviceEndpoint;
851
-
852
-        return $this;
853
-    }
854
-
855
-    public function getIdentificationNoticeboardWebserviceEndpoint(): string
856
-    {
857
-        return $this->identificationNoticeboardWebserviceEndpoint;
858
-    }
859
-
860
-    public function isRegistrationAllowed(): bool
861
-    {
862
-        return $this->registrationAllowed;
863
-    }
864
-
865
-    public function setRegistrationAllowed(bool $registrationAllowed): SiteConfiguration
866
-    {
867
-        $this->registrationAllowed = $registrationAllowed;
868
-
869
-        return $this;
870
-    }
871
-
872
-    /**
873
-     * @return string|null
874
-     */
875
-    public function getCspReportUri()
876
-    {
877
-        return $this->cspReportUri;
878
-    }
879
-
880
-    /**
881
-     * @param string|null $cspReportUri
882
-     *
883
-     * @return SiteConfiguration
884
-     */
885
-    public function setCspReportUri($cspReportUri)
886
-    {
887
-        $this->cspReportUri = $cspReportUri;
888
-
889
-        return $this;
890
-    }
891
-
892
-    /**
893
-     * @return int
894
-     */
895
-    public function getResourceCacheEpoch(): int
896
-    {
897
-        return $this->resourceCacheEpoch;
898
-    }
899
-
900
-    /**
901
-     * @param int $resourceCacheEpoch
902
-     *
903
-     * @return SiteConfiguration
904
-     */
905
-    public function setResourceCacheEpoch(int $resourceCacheEpoch): SiteConfiguration
906
-    {
907
-        $this->resourceCacheEpoch = $resourceCacheEpoch;
908
-
909
-        return $this;
910
-    }
911
-
912
-    /**
913
-     * @return array
914
-     */
915
-    public function getCommonEmailDomains(): array
916
-    {
917
-        return $this->commonEmailDomains;
918
-    }
919
-
920
-    /**
921
-     * @param array $commonEmailDomains
922
-     *
923
-     * @return SiteConfiguration
924
-     */
925
-    public function setCommonEmailDomains(array $commonEmailDomains): SiteConfiguration
926
-    {
927
-        $this->commonEmailDomains = $commonEmailDomains;
928
-
929
-        return $this;
930
-    }
931
-
932
-    /**
933
-     * @param int[] $banMaxIpBlockRange
934
-     *
935
-     * @return SiteConfiguration
936
-     */
937
-    public function setBanMaxIpBlockRange(array $banMaxIpBlockRange): SiteConfiguration
938
-    {
939
-        $this->banMaxIpBlockRange = $banMaxIpBlockRange;
940
-
941
-        return $this;
942
-    }
943
-
944
-    /**
945
-     * @return int[]
946
-     */
947
-    public function getBanMaxIpBlockRange(): array
948
-    {
949
-        return $this->banMaxIpBlockRange;
950
-    }
951
-
952
-    /**
953
-     * @param int[] $banMaxIpRange
954
-     *
955
-     * @return SiteConfiguration
956
-     */
957
-    public function setBanMaxIpRange(array $banMaxIpRange): SiteConfiguration
958
-    {
959
-        $this->banMaxIpRange = $banMaxIpRange;
960
-
961
-        return $this;
962
-    }
963
-
964
-    /**
965
-     * @return int[]
966
-     */
967
-    public function getBanMaxIpRange(): array
968
-    {
969
-        return $this->banMaxIpRange;
970
-    }
971
-
972
-    /**
973
-     * @param array $oauthLegacyConsumerTokens
974
-     *
975
-     * @return SiteConfiguration
976
-     */
977
-    public function setOauthLegacyConsumerTokens(array $oauthLegacyConsumerTokens): SiteConfiguration
978
-    {
979
-        $this->oauthLegacyConsumerTokens = $oauthLegacyConsumerTokens;
980
-
981
-        return $this;
982
-    }
983
-
984
-    /**
985
-     * @return array
986
-     */
987
-    public function getOauthLegacyConsumerTokens(): array
988
-    {
989
-        return $this->oauthLegacyConsumerTokens;
990
-    }
991
-
992
-    /**
993
-     * @return int
994
-     */
995
-    public function getJobQueueBatchSize(): int
996
-    {
997
-        return $this->jobQueueBatchSize;
998
-    }
999
-
1000
-    /**
1001
-     * @param int $jobQueueBatchSize
1002
-     *
1003
-     * @return SiteConfiguration
1004
-     */
1005
-    public function setJobQueueBatchSize(int $jobQueueBatchSize): SiteConfiguration
1006
-    {
1007
-        $this->jobQueueBatchSize = $jobQueueBatchSize;
1008
-
1009
-        return $this;
1010
-    }
1011
-
1012
-    /**
1013
-     * @return array
1014
-     */
1015
-    public function getAmqpConfiguration(): array
1016
-    {
1017
-        return $this->amqpConfiguration;
1018
-    }
1019
-
1020
-    /**
1021
-     * @param array $amqpConfiguration
1022
-     *
1023
-     * @return SiteConfiguration
1024
-     */
1025
-    public function setAmqpConfiguration(array $amqpConfiguration): SiteConfiguration
1026
-    {
1027
-        $this->amqpConfiguration = $amqpConfiguration;
1028
-
1029
-        return $this;
1030
-    }
1031
-
1032
-    /**
1033
-     * @return string
1034
-     */
1035
-    public function getEmailSender(): string
1036
-    {
1037
-        return $this->emailSender;
1038
-    }
1039
-
1040
-    /**
1041
-     * @param string $emailSender
1042
-     *
1043
-     * @return SiteConfiguration
1044
-     */
1045
-    public function setEmailSender(string $emailSender): SiteConfiguration
1046
-    {
1047
-        $this->emailSender = $emailSender;
1048
-
1049
-        return $this;
1050
-    }
1051
-
1052
-    /**
1053
-     * @param array $acceptClientHints
1054
-     *
1055
-     * @return SiteConfiguration
1056
-     */
1057
-    public function setAcceptClientHints(array $acceptClientHints): SiteConfiguration
1058
-    {
1059
-        $this->acceptClientHints = $acceptClientHints;
1060
-
1061
-        return $this;
1062
-    }
1063
-
1064
-    /**
1065
-     * @return array
1066
-     */
1067
-    public function getAcceptClientHints(): array
1068
-    {
1069
-        return $this->acceptClientHints;
1070
-    }
1071
-
1072
-    public function setCookiePath(string $cookiePath): SiteConfiguration
1073
-    {
1074
-        $this->cookiePath = $cookiePath;
1075
-
1076
-        return $this;
1077
-    }
1078
-
1079
-    public function getCookiePath(): string
1080
-    {
1081
-        return $this->cookiePath;
1082
-    }
1083
-
1084
-    public function setCookieSessionName(string $cookieSessionName): SiteConfiguration
1085
-    {
1086
-        $this->cookieSessionName = $cookieSessionName;
1087
-
1088
-        return $this;
1089
-    }
1090
-
1091
-    public function getCookieSessionName(): string
1092
-    {
1093
-        return $this->cookieSessionName;
1094
-    }
1095
-
1096
-    public function setOffline(array $offline): SiteConfiguration
1097
-    {
1098
-        $this->offline = $offline;
1099
-
1100
-        return $this;
1101
-    }
1102
-
1103
-    public function getOffline(): array
1104
-    {
1105
-        return $this->offline;
1106
-    }
1107
-
1108
-    public function setDatabaseConfig(array $databaseConfig): SiteConfiguration
1109
-    {
1110
-        $this->databaseConfig = $databaseConfig;
1111
-
1112
-        return $this;
1113
-    }
1114
-
1115
-    public function getDatabaseConfig(): array
1116
-    {
1117
-        return $this->databaseConfig;
1118
-    }
1119
-
1120
-    public function getPrivacyStatementPath(): string
1121
-    {
1122
-        return $this->privacyStatementPath;
1123
-    }
1124
-
1125
-    public function setPrivacyStatementPath(string $privacyStatementPath): SiteConfiguration
1126
-    {
1127
-        $this->privacyStatementPath = $privacyStatementPath;
1128
-
1129
-        return $this;
1130
-    }
21
+	private $baseUrl = 'https://accounts.wmflabs.org';
22
+	private $filePath = __DIR__ . '/..';
23
+	private $schemaVersion = 50;
24
+	private $debuggingTraceEnabled = false;
25
+	private $debuggingCssBreakpointsEnabled = false;
26
+	private $dataClearIp = '127.0.0.1';
27
+	private $dataClearEmail = '[email protected]';
28
+	private $dataClearInterval = '15 DAY';
29
+	private $forceIdentification = true;
30
+	private $identificationCacheExpiry = '1 DAY';
31
+	private $metaWikimediaWebServiceEndpoint = 'https://meta.wikimedia.org/w/api.php';
32
+	private $enforceOAuth = false;
33
+	private $emailConfirmationEnabled = true;
34
+	private $emailConfirmationExpiryDays = 7;
35
+	private $miserModeLimit = 25;
36
+	private $squidList = array();
37
+	private $useStrictTransportSecurity = false;
38
+	private $userAgent = 'Wikipedia-ACC Tool/0.1 (+https://accounts.wmflabs.org/internal.php/team)';
39
+	private $curlDisableVerifyPeer = false;
40
+	private $useOAuthSignup = true;
41
+	private $oauthConsumerToken;
42
+	/** @var array */
43
+	private $oauthLegacyConsumerTokens;
44
+	private $oauthConsumerSecret;
45
+	private $oauthIdentityGraceTime = '24 hours';
46
+	private $oauthMediaWikiCanonicalServer = 'https://en.wikipedia.org';
47
+	private $xffTrustedHostsFile = '../TrustedXFF/trusted-hosts.txt';
48
+	private $crossOriginResourceSharingHosts = array(
49
+		"https://en.wikipedia.org",
50
+		"https://meta.wikimedia.org",
51
+	);
52
+	private $ircNotificationsEnabled = true;
53
+	private $ircNotificationsInstance = 'Development';
54
+	private $errorLog = 'errorlog';
55
+	private $titleBlacklistEnabled = false;
56
+	/** @var null|string $locationProviderApiKey */
57
+	private $locationProviderApiKey = null;
58
+	private $torExitPaths = array();
59
+	private $creationBotUsername = '';
60
+	private $creationBotPassword = '';
61
+	private $curlCookieJar = __DIR__ . '/../../cookies.txt';
62
+	private $yubicoApiId = 0;
63
+	private $yubicoApiKey = "";
64
+	private $totpEncryptionKey = "1234";
65
+	private $identificationNoticeboardPage = 'Access to nonpublic personal data policy/Noticeboard';
66
+	private $identificationNoticeboardWebserviceEndpoint = 'https://meta.wikimedia.org/w/api.php';
67
+	private $registrationAllowed = true;
68
+	private $cspReportUri = null;
69
+	private $resourceCacheEpoch = 1;
70
+	private $commonEmailDomains = ['gmail.com', 'hotmail.com', 'outlook.com'];
71
+	private $banMaxIpBlockRange = [4 => 20, 6 => 48];
72
+	private $banMaxIpRange = [4 => 16, 6 => 32];
73
+	private $jobQueueBatchSize = 10;
74
+	private $amqpConfiguration = ['host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => '', 'tls' => false];
75
+	private $emailSender = '[email protected]';
76
+	private $acceptClientHints = [];
77
+	private string $cookiePath = '/';
78
+	private string $cookieSessionName = 'ACC';
79
+	private array $offline = ['offline' => false, 'reason' => '', 'culprit' => ''];
80
+	private array $databaseConfig = [
81
+		'datasource' => 'mysql:host=localhost;dbname=waca',
82
+		'username' => 'waca',
83
+		'password' => 'waca'
84
+	];
85
+	private string $privacyStatementPath = '';
86
+
87
+	/**
88
+	 * Gets the base URL of the tool
89
+	 *
90
+	 * If the internal page of the tool is at http://localhost/path/internal.php, this would be set to
91
+	 * http://localhost/path
92
+	 * @return string
93
+	 */
94
+	public function getBaseUrl()
95
+	{
96
+		return $this->baseUrl;
97
+	}
98
+
99
+	/**
100
+	 * @param string $baseUrl
101
+	 *
102
+	 * @return SiteConfiguration
103
+	 */
104
+	public function setBaseUrl($baseUrl)
105
+	{
106
+		$this->baseUrl = $baseUrl;
107
+
108
+		return $this;
109
+	}
110
+
111
+	/**
112
+	 * Path on disk to the directory containing the tool's code
113
+	 * @return string
114
+	 */
115
+	public function getFilePath()
116
+	{
117
+		return $this->filePath;
118
+	}
119
+
120
+	/**
121
+	 * @param string $filePath
122
+	 *
123
+	 * @return SiteConfiguration
124
+	 */
125
+	public function setFilePath($filePath)
126
+	{
127
+		$this->filePath = $filePath;
128
+
129
+		return $this;
130
+	}
131
+
132
+	/**
133
+	 * @return int
134
+	 */
135
+	public function getSchemaVersion()
136
+	{
137
+		return $this->schemaVersion;
138
+	}
139
+
140
+	/**
141
+	 * @param int $schemaVersion
142
+	 *
143
+	 * @return SiteConfiguration
144
+	 */
145
+	public function setSchemaVersion($schemaVersion)
146
+	{
147
+		$this->schemaVersion = $schemaVersion;
148
+
149
+		return $this;
150
+	}
151
+
152
+	/**
153
+	 * @return mixed
154
+	 */
155
+	public function getDebuggingTraceEnabled()
156
+	{
157
+		return $this->debuggingTraceEnabled;
158
+	}
159
+
160
+	/**
161
+	 * @param mixed $debuggingTraceEnabled
162
+	 *
163
+	 * @return SiteConfiguration
164
+	 */
165
+	public function setDebuggingTraceEnabled($debuggingTraceEnabled)
166
+	{
167
+		$this->debuggingTraceEnabled = $debuggingTraceEnabled;
168
+
169
+		return $this;
170
+	}
171
+
172
+	public function getDebuggingCssBreakpointsEnabled() : bool
173
+	{
174
+		return $this->debuggingCssBreakpointsEnabled;
175
+	}
176
+
177
+	public function setDebuggingCssBreakpointsEnabled(bool $debuggingCssBreakpointsEnabled) : SiteConfiguration
178
+	{
179
+		$this->debuggingCssBreakpointsEnabled = $debuggingCssBreakpointsEnabled;
180
+
181
+		return $this;
182
+	}
183
+
184
+	/**
185
+	 * @return string
186
+	 */
187
+	public function getDataClearIp()
188
+	{
189
+		return $this->dataClearIp;
190
+	}
191
+
192
+	/**
193
+	 * @param string $dataClearIp
194
+	 *
195
+	 * @return SiteConfiguration
196
+	 */
197
+	public function setDataClearIp($dataClearIp)
198
+	{
199
+		$this->dataClearIp = $dataClearIp;
200
+
201
+		return $this;
202
+	}
203
+
204
+	/**
205
+	 * @return string
206
+	 */
207
+	public function getDataClearEmail()
208
+	{
209
+		return $this->dataClearEmail;
210
+	}
211
+
212
+	/**
213
+	 * @param string $dataClearEmail
214
+	 *
215
+	 * @return SiteConfiguration
216
+	 */
217
+	public function setDataClearEmail($dataClearEmail)
218
+	{
219
+		$this->dataClearEmail = $dataClearEmail;
220
+
221
+		return $this;
222
+	}
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public function getForceIdentification()
228
+	{
229
+		return $this->forceIdentification;
230
+	}
231
+
232
+	/**
233
+	 * @param boolean $forceIdentification
234
+	 *
235
+	 * @return SiteConfiguration
236
+	 */
237
+	public function setForceIdentification($forceIdentification)
238
+	{
239
+		$this->forceIdentification = $forceIdentification;
240
+
241
+		return $this;
242
+	}
243
+
244
+	/**
245
+	 * @return string
246
+	 */
247
+	public function getIdentificationCacheExpiry()
248
+	{
249
+		return $this->identificationCacheExpiry;
250
+	}
251
+
252
+	/**
253
+	 * @param string $identificationCacheExpiry
254
+	 *
255
+	 * @return SiteConfiguration
256
+	 */
257
+	public function setIdentificationCacheExpiry($identificationCacheExpiry)
258
+	{
259
+		$this->identificationCacheExpiry = $identificationCacheExpiry;
260
+
261
+		return $this;
262
+	}
263
+
264
+	/**
265
+	 * @return string
266
+	 */
267
+	public function getMetaWikimediaWebServiceEndpoint()
268
+	{
269
+		return $this->metaWikimediaWebServiceEndpoint;
270
+	}
271
+
272
+	/**
273
+	 * @param string $metaWikimediaWebServiceEndpoint
274
+	 *
275
+	 * @return SiteConfiguration
276
+	 */
277
+	public function setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)
278
+	{
279
+		$this->metaWikimediaWebServiceEndpoint = $metaWikimediaWebServiceEndpoint;
280
+
281
+		return $this;
282
+	}
283
+
284
+	/**
285
+	 * @return boolean
286
+	 */
287
+	public function getEnforceOAuth()
288
+	{
289
+		return $this->enforceOAuth;
290
+	}
291
+
292
+	/**
293
+	 * @param boolean $enforceOAuth
294
+	 *
295
+	 * @return SiteConfiguration
296
+	 */
297
+	public function setEnforceOAuth($enforceOAuth)
298
+	{
299
+		$this->enforceOAuth = $enforceOAuth;
300
+
301
+		return $this;
302
+	}
303
+
304
+	/**
305
+	 * @return boolean
306
+	 */
307
+	public function getEmailConfirmationEnabled()
308
+	{
309
+		return $this->emailConfirmationEnabled;
310
+	}
311
+
312
+	/**
313
+	 * @param boolean $emailConfirmationEnabled
314
+	 *
315
+	 * @return $this
316
+	 */
317
+	public function setEmailConfirmationEnabled($emailConfirmationEnabled)
318
+	{
319
+		$this->emailConfirmationEnabled = $emailConfirmationEnabled;
320
+
321
+		return $this;
322
+	}
323
+
324
+	/**
325
+	 * @return int
326
+	 */
327
+	public function getMiserModeLimit()
328
+	{
329
+		return $this->miserModeLimit;
330
+	}
331
+
332
+	/**
333
+	 * @param int $miserModeLimit
334
+	 *
335
+	 * @return SiteConfiguration
336
+	 */
337
+	public function setMiserModeLimit($miserModeLimit)
338
+	{
339
+		$this->miserModeLimit = $miserModeLimit;
340
+
341
+		return $this;
342
+	}
343
+
344
+	/**
345
+	 * @return array
346
+	 */
347
+	public function getSquidList()
348
+	{
349
+		return $this->squidList;
350
+	}
351
+
352
+	/**
353
+	 * @param array $squidList
354
+	 *
355
+	 * @return SiteConfiguration
356
+	 */
357
+	public function setSquidList($squidList)
358
+	{
359
+		$this->squidList = $squidList;
360
+
361
+		return $this;
362
+	}
363
+
364
+	/**
365
+	 * @return boolean
366
+	 */
367
+	public function getUseStrictTransportSecurity()
368
+	{
369
+		return $this->useStrictTransportSecurity;
370
+	}
371
+
372
+	/**
373
+	 * @param boolean $useStrictTransportSecurity
374
+	 *
375
+	 * @return SiteConfiguration
376
+	 */
377
+	public function setUseStrictTransportSecurity($useStrictTransportSecurity)
378
+	{
379
+		$this->useStrictTransportSecurity = $useStrictTransportSecurity;
380
+
381
+		return $this;
382
+	}
383
+
384
+	/**
385
+	 * @return string
386
+	 */
387
+	public function getUserAgent()
388
+	{
389
+		return $this->userAgent;
390
+	}
391
+
392
+	/**
393
+	 * @param string $userAgent
394
+	 *
395
+	 * @return SiteConfiguration
396
+	 */
397
+	public function setUserAgent($userAgent)
398
+	{
399
+		$this->userAgent = $userAgent;
400
+
401
+		return $this;
402
+	}
403
+
404
+	/**
405
+	 * @return boolean
406
+	 */
407
+	public function getCurlDisableVerifyPeer()
408
+	{
409
+		return $this->curlDisableVerifyPeer;
410
+	}
411
+
412
+	/**
413
+	 * @param boolean $curlDisableVerifyPeer
414
+	 *
415
+	 * @return SiteConfiguration
416
+	 */
417
+	public function setCurlDisableVerifyPeer($curlDisableVerifyPeer)
418
+	{
419
+		$this->curlDisableVerifyPeer = $curlDisableVerifyPeer;
420
+
421
+		return $this;
422
+	}
423
+
424
+	/**
425
+	 * @return boolean
426
+	 */
427
+	public function getUseOAuthSignup()
428
+	{
429
+		return $this->useOAuthSignup;
430
+	}
431
+
432
+	/**
433
+	 * @param boolean $useOAuthSignup
434
+	 *
435
+	 * @return SiteConfiguration
436
+	 */
437
+	public function setUseOAuthSignup($useOAuthSignup)
438
+	{
439
+		$this->useOAuthSignup = $useOAuthSignup;
440
+
441
+		return $this;
442
+	}
443
+
444
+	/**
445
+	 * @return mixed
446
+	 */
447
+	public function getOAuthConsumerToken()
448
+	{
449
+		return $this->oauthConsumerToken;
450
+	}
451
+
452
+	/**
453
+	 * @param mixed $oauthConsumerToken
454
+	 *
455
+	 * @return SiteConfiguration
456
+	 */
457
+	public function setOAuthConsumerToken($oauthConsumerToken)
458
+	{
459
+		$this->oauthConsumerToken = $oauthConsumerToken;
460
+
461
+		return $this;
462
+	}
463
+
464
+	/**
465
+	 * @return mixed
466
+	 */
467
+	public function getOAuthConsumerSecret()
468
+	{
469
+		return $this->oauthConsumerSecret;
470
+	}
471
+
472
+	/**
473
+	 * @param mixed $oauthConsumerSecret
474
+	 *
475
+	 * @return SiteConfiguration
476
+	 */
477
+	public function setOAuthConsumerSecret($oauthConsumerSecret)
478
+	{
479
+		$this->oauthConsumerSecret = $oauthConsumerSecret;
480
+
481
+		return $this;
482
+	}
483
+
484
+	/**
485
+	 * @return string
486
+	 */
487
+	public function getDataClearInterval()
488
+	{
489
+		return $this->dataClearInterval;
490
+	}
491
+
492
+	/**
493
+	 * @param string $dataClearInterval
494
+	 *
495
+	 * @return SiteConfiguration
496
+	 */
497
+	public function setDataClearInterval($dataClearInterval)
498
+	{
499
+		$this->dataClearInterval = $dataClearInterval;
500
+
501
+		return $this;
502
+	}
503
+
504
+	/**
505
+	 * @return string
506
+	 */
507
+	public function getXffTrustedHostsFile()
508
+	{
509
+		return $this->xffTrustedHostsFile;
510
+	}
511
+
512
+	/**
513
+	 * @param string $xffTrustedHostsFile
514
+	 *
515
+	 * @return SiteConfiguration
516
+	 */
517
+	public function setXffTrustedHostsFile($xffTrustedHostsFile)
518
+	{
519
+		$this->xffTrustedHostsFile = $xffTrustedHostsFile;
520
+
521
+		return $this;
522
+	}
523
+
524
+	/**
525
+	 * @return array
526
+	 */
527
+	public function getCrossOriginResourceSharingHosts()
528
+	{
529
+		return $this->crossOriginResourceSharingHosts;
530
+	}
531
+
532
+	/**
533
+	 * @param array $crossOriginResourceSharingHosts
534
+	 *
535
+	 * @return SiteConfiguration
536
+	 */
537
+	public function setCrossOriginResourceSharingHosts($crossOriginResourceSharingHosts)
538
+	{
539
+		$this->crossOriginResourceSharingHosts = $crossOriginResourceSharingHosts;
540
+
541
+		return $this;
542
+	}
543
+
544
+	/**
545
+	 * @return boolean
546
+	 */
547
+	public function getIrcNotificationsEnabled()
548
+	{
549
+		return $this->ircNotificationsEnabled;
550
+	}
551
+
552
+	/**
553
+	 * @param boolean $ircNotificationsEnabled
554
+	 *
555
+	 * @return SiteConfiguration
556
+	 */
557
+	public function setIrcNotificationsEnabled($ircNotificationsEnabled)
558
+	{
559
+		$this->ircNotificationsEnabled = $ircNotificationsEnabled;
560
+
561
+		return $this;
562
+	}
563
+
564
+	/**
565
+	 * @param string $errorLog
566
+	 *
567
+	 * @return SiteConfiguration
568
+	 */
569
+	public function setErrorLog($errorLog)
570
+	{
571
+		$this->errorLog = $errorLog;
572
+
573
+		return $this;
574
+	}
575
+
576
+	/**
577
+	 * @return string
578
+	 */
579
+	public function getErrorLog()
580
+	{
581
+		return $this->errorLog;
582
+	}
583
+
584
+	/**
585
+	 * @param int $emailConfirmationExpiryDays
586
+	 *
587
+	 * @return SiteConfiguration
588
+	 */
589
+	public function setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)
590
+	{
591
+		$this->emailConfirmationExpiryDays = $emailConfirmationExpiryDays;
592
+
593
+		return $this;
594
+	}
595
+
596
+	/**
597
+	 * @return int
598
+	 */
599
+	public function getEmailConfirmationExpiryDays()
600
+	{
601
+		return $this->emailConfirmationExpiryDays;
602
+	}
603
+
604
+	/**
605
+	 * @param string $ircNotificationsInstance
606
+	 *
607
+	 * @return SiteConfiguration
608
+	 */
609
+	public function setIrcNotificationsInstance($ircNotificationsInstance)
610
+	{
611
+		$this->ircNotificationsInstance = $ircNotificationsInstance;
612
+
613
+		return $this;
614
+	}
615
+
616
+	/**
617
+	 * @return string
618
+	 */
619
+	public function getIrcNotificationsInstance()
620
+	{
621
+		return $this->ircNotificationsInstance;
622
+	}
623
+
624
+	/**
625
+	 * @param boolean $titleBlacklistEnabled
626
+	 *
627
+	 * @return SiteConfiguration
628
+	 */
629
+	public function setTitleBlacklistEnabled($titleBlacklistEnabled)
630
+	{
631
+		$this->titleBlacklistEnabled = $titleBlacklistEnabled;
632
+
633
+		return $this;
634
+	}
635
+
636
+	/**
637
+	 * @return boolean
638
+	 */
639
+	public function getTitleBlacklistEnabled()
640
+	{
641
+		return $this->titleBlacklistEnabled;
642
+	}
643
+
644
+	/**
645
+	 * @param string|null $locationProviderApiKey
646
+	 *
647
+	 * @return SiteConfiguration
648
+	 */
649
+	public function setLocationProviderApiKey($locationProviderApiKey)
650
+	{
651
+		$this->locationProviderApiKey = $locationProviderApiKey;
652
+
653
+		return $this;
654
+	}
655
+
656
+	/**
657
+	 * @return null|string
658
+	 */
659
+	public function getLocationProviderApiKey()
660
+	{
661
+		return $this->locationProviderApiKey;
662
+	}
663
+
664
+	/**
665
+	 * @param array $torExitPaths
666
+	 *
667
+	 * @return SiteConfiguration
668
+	 */
669
+	public function setTorExitPaths($torExitPaths)
670
+	{
671
+		$this->torExitPaths = $torExitPaths;
672
+
673
+		return $this;
674
+	}
675
+
676
+	/**
677
+	 * @return array
678
+	 */
679
+	public function getTorExitPaths()
680
+	{
681
+		return $this->torExitPaths;
682
+	}
683
+
684
+	/**
685
+	 * @param string $oauthIdentityGraceTime
686
+	 *
687
+	 * @return SiteConfiguration
688
+	 */
689
+	public function setOauthIdentityGraceTime($oauthIdentityGraceTime)
690
+	{
691
+		$this->oauthIdentityGraceTime = $oauthIdentityGraceTime;
692
+
693
+		return $this;
694
+	}
695
+
696
+	/**
697
+	 * @return string
698
+	 */
699
+	public function getOauthIdentityGraceTime()
700
+	{
701
+		return $this->oauthIdentityGraceTime;
702
+	}
703
+
704
+	/**
705
+	 * @param string $oauthMediaWikiCanonicalServer
706
+	 *
707
+	 * @return SiteConfiguration
708
+	 */
709
+	public function setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer)
710
+	{
711
+		$this->oauthMediaWikiCanonicalServer = $oauthMediaWikiCanonicalServer;
712
+
713
+		return $this;
714
+	}
715
+
716
+	/**
717
+	 * @return string
718
+	 */
719
+	public function getOauthMediaWikiCanonicalServer()
720
+	{
721
+		return $this->oauthMediaWikiCanonicalServer;
722
+	}
723
+
724
+	/**
725
+	 * @param string $creationBotUsername
726
+	 *
727
+	 * @return SiteConfiguration
728
+	 */
729
+	public function setCreationBotUsername($creationBotUsername)
730
+	{
731
+		$this->creationBotUsername = $creationBotUsername;
732
+
733
+		return $this;
734
+	}
735
+
736
+	/**
737
+	 * @return string
738
+	 */
739
+	public function getCreationBotUsername()
740
+	{
741
+		return $this->creationBotUsername;
742
+	}
743
+
744
+	/**
745
+	 * @param string $creationBotPassword
746
+	 *
747
+	 * @return SiteConfiguration
748
+	 */
749
+	public function setCreationBotPassword($creationBotPassword)
750
+	{
751
+		$this->creationBotPassword = $creationBotPassword;
752
+
753
+		return $this;
754
+	}
755
+
756
+	/**
757
+	 * @return string
758
+	 */
759
+	public function getCreationBotPassword()
760
+	{
761
+		return $this->creationBotPassword;
762
+	}
763
+
764
+	/**
765
+	 * @param string|null $curlCookieJar
766
+	 *
767
+	 * @return SiteConfiguration
768
+	 */
769
+	public function setCurlCookieJar($curlCookieJar)
770
+	{
771
+		$this->curlCookieJar = $curlCookieJar;
772
+
773
+		return $this;
774
+	}
775
+
776
+	/**
777
+	 * @return string|null
778
+	 */
779
+	public function getCurlCookieJar()
780
+	{
781
+		return $this->curlCookieJar;
782
+	}
783
+
784
+	public function getYubicoApiId()
785
+	{
786
+		return $this->yubicoApiId;
787
+	}
788
+
789
+	public function setYubicoApiId($id)
790
+	{
791
+		$this->yubicoApiId = $id;
792
+
793
+		return $this;
794
+	}
795
+
796
+	public function getYubicoApiKey()
797
+	{
798
+		return $this->yubicoApiKey;
799
+	}
800
+
801
+	public function setYubicoApiKey($key)
802
+	{
803
+		$this->yubicoApiKey = $key;
804
+
805
+		return $this;
806
+	}
807
+
808
+	/**
809
+	 * @return string
810
+	 */
811
+	public function getTotpEncryptionKey()
812
+	{
813
+		return $this->totpEncryptionKey;
814
+	}
815
+
816
+	/**
817
+	 * @param string $totpEncryptionKey
818
+	 *
819
+	 * @return SiteConfiguration
820
+	 */
821
+	public function setTotpEncryptionKey($totpEncryptionKey)
822
+	{
823
+		$this->totpEncryptionKey = $totpEncryptionKey;
824
+
825
+		return $this;
826
+	}
827
+
828
+	/**
829
+	 * @return string
830
+	 */
831
+	public function getIdentificationNoticeboardPage()
832
+	{
833
+		return $this->identificationNoticeboardPage;
834
+	}
835
+
836
+	/**
837
+	 * @param string $identificationNoticeboardPage
838
+	 *
839
+	 * @return SiteConfiguration
840
+	 */
841
+	public function setIdentificationNoticeboardPage($identificationNoticeboardPage)
842
+	{
843
+		$this->identificationNoticeboardPage = $identificationNoticeboardPage;
844
+
845
+		return $this;
846
+	}
847
+
848
+	public function setIdentificationNoticeboardWebserviceEndpoint(string $identificationNoticeboardWebserviceEndpoint
849
+	): SiteConfiguration {
850
+		$this->identificationNoticeboardWebserviceEndpoint = $identificationNoticeboardWebserviceEndpoint;
851
+
852
+		return $this;
853
+	}
854
+
855
+	public function getIdentificationNoticeboardWebserviceEndpoint(): string
856
+	{
857
+		return $this->identificationNoticeboardWebserviceEndpoint;
858
+	}
859
+
860
+	public function isRegistrationAllowed(): bool
861
+	{
862
+		return $this->registrationAllowed;
863
+	}
864
+
865
+	public function setRegistrationAllowed(bool $registrationAllowed): SiteConfiguration
866
+	{
867
+		$this->registrationAllowed = $registrationAllowed;
868
+
869
+		return $this;
870
+	}
871
+
872
+	/**
873
+	 * @return string|null
874
+	 */
875
+	public function getCspReportUri()
876
+	{
877
+		return $this->cspReportUri;
878
+	}
879
+
880
+	/**
881
+	 * @param string|null $cspReportUri
882
+	 *
883
+	 * @return SiteConfiguration
884
+	 */
885
+	public function setCspReportUri($cspReportUri)
886
+	{
887
+		$this->cspReportUri = $cspReportUri;
888
+
889
+		return $this;
890
+	}
891
+
892
+	/**
893
+	 * @return int
894
+	 */
895
+	public function getResourceCacheEpoch(): int
896
+	{
897
+		return $this->resourceCacheEpoch;
898
+	}
899
+
900
+	/**
901
+	 * @param int $resourceCacheEpoch
902
+	 *
903
+	 * @return SiteConfiguration
904
+	 */
905
+	public function setResourceCacheEpoch(int $resourceCacheEpoch): SiteConfiguration
906
+	{
907
+		$this->resourceCacheEpoch = $resourceCacheEpoch;
908
+
909
+		return $this;
910
+	}
911
+
912
+	/**
913
+	 * @return array
914
+	 */
915
+	public function getCommonEmailDomains(): array
916
+	{
917
+		return $this->commonEmailDomains;
918
+	}
919
+
920
+	/**
921
+	 * @param array $commonEmailDomains
922
+	 *
923
+	 * @return SiteConfiguration
924
+	 */
925
+	public function setCommonEmailDomains(array $commonEmailDomains): SiteConfiguration
926
+	{
927
+		$this->commonEmailDomains = $commonEmailDomains;
928
+
929
+		return $this;
930
+	}
931
+
932
+	/**
933
+	 * @param int[] $banMaxIpBlockRange
934
+	 *
935
+	 * @return SiteConfiguration
936
+	 */
937
+	public function setBanMaxIpBlockRange(array $banMaxIpBlockRange): SiteConfiguration
938
+	{
939
+		$this->banMaxIpBlockRange = $banMaxIpBlockRange;
940
+
941
+		return $this;
942
+	}
943
+
944
+	/**
945
+	 * @return int[]
946
+	 */
947
+	public function getBanMaxIpBlockRange(): array
948
+	{
949
+		return $this->banMaxIpBlockRange;
950
+	}
951
+
952
+	/**
953
+	 * @param int[] $banMaxIpRange
954
+	 *
955
+	 * @return SiteConfiguration
956
+	 */
957
+	public function setBanMaxIpRange(array $banMaxIpRange): SiteConfiguration
958
+	{
959
+		$this->banMaxIpRange = $banMaxIpRange;
960
+
961
+		return $this;
962
+	}
963
+
964
+	/**
965
+	 * @return int[]
966
+	 */
967
+	public function getBanMaxIpRange(): array
968
+	{
969
+		return $this->banMaxIpRange;
970
+	}
971
+
972
+	/**
973
+	 * @param array $oauthLegacyConsumerTokens
974
+	 *
975
+	 * @return SiteConfiguration
976
+	 */
977
+	public function setOauthLegacyConsumerTokens(array $oauthLegacyConsumerTokens): SiteConfiguration
978
+	{
979
+		$this->oauthLegacyConsumerTokens = $oauthLegacyConsumerTokens;
980
+
981
+		return $this;
982
+	}
983
+
984
+	/**
985
+	 * @return array
986
+	 */
987
+	public function getOauthLegacyConsumerTokens(): array
988
+	{
989
+		return $this->oauthLegacyConsumerTokens;
990
+	}
991
+
992
+	/**
993
+	 * @return int
994
+	 */
995
+	public function getJobQueueBatchSize(): int
996
+	{
997
+		return $this->jobQueueBatchSize;
998
+	}
999
+
1000
+	/**
1001
+	 * @param int $jobQueueBatchSize
1002
+	 *
1003
+	 * @return SiteConfiguration
1004
+	 */
1005
+	public function setJobQueueBatchSize(int $jobQueueBatchSize): SiteConfiguration
1006
+	{
1007
+		$this->jobQueueBatchSize = $jobQueueBatchSize;
1008
+
1009
+		return $this;
1010
+	}
1011
+
1012
+	/**
1013
+	 * @return array
1014
+	 */
1015
+	public function getAmqpConfiguration(): array
1016
+	{
1017
+		return $this->amqpConfiguration;
1018
+	}
1019
+
1020
+	/**
1021
+	 * @param array $amqpConfiguration
1022
+	 *
1023
+	 * @return SiteConfiguration
1024
+	 */
1025
+	public function setAmqpConfiguration(array $amqpConfiguration): SiteConfiguration
1026
+	{
1027
+		$this->amqpConfiguration = $amqpConfiguration;
1028
+
1029
+		return $this;
1030
+	}
1031
+
1032
+	/**
1033
+	 * @return string
1034
+	 */
1035
+	public function getEmailSender(): string
1036
+	{
1037
+		return $this->emailSender;
1038
+	}
1039
+
1040
+	/**
1041
+	 * @param string $emailSender
1042
+	 *
1043
+	 * @return SiteConfiguration
1044
+	 */
1045
+	public function setEmailSender(string $emailSender): SiteConfiguration
1046
+	{
1047
+		$this->emailSender = $emailSender;
1048
+
1049
+		return $this;
1050
+	}
1051
+
1052
+	/**
1053
+	 * @param array $acceptClientHints
1054
+	 *
1055
+	 * @return SiteConfiguration
1056
+	 */
1057
+	public function setAcceptClientHints(array $acceptClientHints): SiteConfiguration
1058
+	{
1059
+		$this->acceptClientHints = $acceptClientHints;
1060
+
1061
+		return $this;
1062
+	}
1063
+
1064
+	/**
1065
+	 * @return array
1066
+	 */
1067
+	public function getAcceptClientHints(): array
1068
+	{
1069
+		return $this->acceptClientHints;
1070
+	}
1071
+
1072
+	public function setCookiePath(string $cookiePath): SiteConfiguration
1073
+	{
1074
+		$this->cookiePath = $cookiePath;
1075
+
1076
+		return $this;
1077
+	}
1078
+
1079
+	public function getCookiePath(): string
1080
+	{
1081
+		return $this->cookiePath;
1082
+	}
1083
+
1084
+	public function setCookieSessionName(string $cookieSessionName): SiteConfiguration
1085
+	{
1086
+		$this->cookieSessionName = $cookieSessionName;
1087
+
1088
+		return $this;
1089
+	}
1090
+
1091
+	public function getCookieSessionName(): string
1092
+	{
1093
+		return $this->cookieSessionName;
1094
+	}
1095
+
1096
+	public function setOffline(array $offline): SiteConfiguration
1097
+	{
1098
+		$this->offline = $offline;
1099
+
1100
+		return $this;
1101
+	}
1102
+
1103
+	public function getOffline(): array
1104
+	{
1105
+		return $this->offline;
1106
+	}
1107
+
1108
+	public function setDatabaseConfig(array $databaseConfig): SiteConfiguration
1109
+	{
1110
+		$this->databaseConfig = $databaseConfig;
1111
+
1112
+		return $this;
1113
+	}
1114
+
1115
+	public function getDatabaseConfig(): array
1116
+	{
1117
+		return $this->databaseConfig;
1118
+	}
1119
+
1120
+	public function getPrivacyStatementPath(): string
1121
+	{
1122
+		return $this->privacyStatementPath;
1123
+	}
1124
+
1125
+	public function setPrivacyStatementPath(string $privacyStatementPath): SiteConfiguration
1126
+	{
1127
+		$this->privacyStatementPath = $privacyStatementPath;
1128
+
1129
+		return $this;
1130
+	}
1131 1131
 }
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -18,64 +18,64 @@
 block discarded – undo
18 18
 
19 19
 class PageLog extends PagedInternalPageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Logs');
27
-
28
-        $filterUser = WebRequest::getString('filterUser');
29
-        $filterAction = WebRequest::getString('filterAction');
30
-        $filterObjectType = WebRequest::getString('filterObjectType');
31
-        $filterObjectId = WebRequest::getInt('filterObjectId');
32
-
33
-        $database = $this->getDatabase();
34
-
35
-        if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
-            $filterObjectType = null;
37
-        }
38
-
39
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
40
-
41
-        // FIXME: domains
42
-        $logSearch = LogSearchHelper::get($database, 1);
43
-
44
-        if ($filterUser !== null) {
45
-            $userObj = User::getByUsername($filterUser, $database);
46
-            if ($userObj !== false) {
47
-                $logSearch->byUser($userObj->getId());
48
-            }
49
-            else {
50
-                $logSearch->byUser(-1);
51
-            }
52
-        }
53
-        if ($filterAction !== null) {
54
-            $logSearch->byAction($filterAction);
55
-        }
56
-        if ($filterObjectType !== null) {
57
-            $logSearch->byObjectType($filterObjectType);
58
-        }
59
-        if ($filterObjectId !== null) {
60
-            $logSearch->byObjectId($filterObjectId);
61
-        }
62
-
63
-        $this->setSearchHelper($logSearch);
64
-        $this->setupLimits();
65
-
66
-        /** @var Log[] $logs */
67
-        $logs = $logSearch->getRecordCount($count)->fetch();
68
-
69
-        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
70
-
71
-        $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
72
-
73
-        $this->assign("logs", $logData);
74
-        $this->assign("users", $users);
75
-
76
-        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
77
-        $this->assign('allObjectTypes', LogHelper::getObjectTypes());
78
-
79
-        $this->setTemplate("logs/main.tpl");
80
-    }
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Logs');
27
+
28
+		$filterUser = WebRequest::getString('filterUser');
29
+		$filterAction = WebRequest::getString('filterAction');
30
+		$filterObjectType = WebRequest::getString('filterObjectType');
31
+		$filterObjectId = WebRequest::getInt('filterObjectId');
32
+
33
+		$database = $this->getDatabase();
34
+
35
+		if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
+			$filterObjectType = null;
37
+		}
38
+
39
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
40
+
41
+		// FIXME: domains
42
+		$logSearch = LogSearchHelper::get($database, 1);
43
+
44
+		if ($filterUser !== null) {
45
+			$userObj = User::getByUsername($filterUser, $database);
46
+			if ($userObj !== false) {
47
+				$logSearch->byUser($userObj->getId());
48
+			}
49
+			else {
50
+				$logSearch->byUser(-1);
51
+			}
52
+		}
53
+		if ($filterAction !== null) {
54
+			$logSearch->byAction($filterAction);
55
+		}
56
+		if ($filterObjectType !== null) {
57
+			$logSearch->byObjectType($filterObjectType);
58
+		}
59
+		if ($filterObjectId !== null) {
60
+			$logSearch->byObjectId($filterObjectId);
61
+		}
62
+
63
+		$this->setSearchHelper($logSearch);
64
+		$this->setupLimits();
65
+
66
+		/** @var Log[] $logs */
67
+		$logs = $logSearch->getRecordCount($count)->fetch();
68
+
69
+		list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
70
+
71
+		$this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
72
+
73
+		$this->assign("logs", $logData);
74
+		$this->assign("users", $users);
75
+
76
+		$this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
77
+		$this->assign('allObjectTypes', LogHelper::getObjectTypes());
78
+
79
+		$this->setTemplate("logs/main.tpl");
80
+	}
81 81
 }
Please login to merge, or discard this patch.
includes/Pages/PageJobQueue.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -29,309 +29,309 @@
 block discarded – undo
29 29
 
30 30
 class PageJobQueue extends PagedInternalPageBase
31 31
 {
32
-    /**
33
-     * Main function for this page, when no specific actions are called.
34
-     * @return void
35
-     */
36
-    protected function main()
37
-    {
38
-        $this->setHtmlTitle('Job Queue Management');
39
-
40
-        $this->prepareMaps();
41
-
42
-        $database = $this->getDatabase();
43
-
44
-        /** @var JobQueue[] $jobList */
45
-        // FIXME: domains
46
-        $jobList = JobQueueSearchHelper::get($database, 1)
47
-            ->statusIn([
48
-                JobQueue::STATUS_QUEUED,
49
-                JobQueue::STATUS_READY,
50
-                JobQueue::STATUS_WAITING,
51
-                JobQueue::STATUS_RUNNING,
52
-                JobQueue::STATUS_FAILED,
53
-            ])
54
-            ->notAcknowledged()
55
-            ->fetch();
56
-
57
-        $userIds = array();
58
-        $requestIds = array();
59
-
60
-        foreach ($jobList as $job) {
61
-            $userIds[] = $job->getTriggerUserId();
62
-            $requestIds[] = $job->getRequest();
63
-
64
-            $job->setDatabase($database);
65
-        }
66
-
67
-        $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
68
-
69
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
70
-        // FIXME: domains
71
-        $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
72
-
73
-        $this->assign('joblist', $jobList);
74
-        $this->setTemplate('jobqueue/main.tpl');
75
-    }
76
-
77
-    protected function all()
78
-    {
79
-        $this->setHtmlTitle('All Jobs');
80
-
81
-        $this->prepareMaps();
82
-
83
-        $database = $this->getDatabase();
84
-
85
-        // FIXME: domains
86
-        $searchHelper = JobQueueSearchHelper::get($database, 1);
87
-        $this->setSearchHelper($searchHelper);
88
-        $this->setupLimits();
89
-
90
-        $filterUser = WebRequest::getString('filterUser');
91
-        $filterTask = WebRequest::getString('filterTask');
92
-        $filterStatus = WebRequest::getString('filterStatus');
93
-        $filterRequest = WebRequest::getString('filterRequest');
94
-        $order = WebRequest::getString('order');
95
-
96
-        if ($filterUser !== null) {
97
-            $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
98
-        }
99
-
100
-        if ($filterTask !== null) {
101
-            $searchHelper->byTask($filterTask);
102
-        }
103
-
104
-        if ($filterStatus !== null) {
105
-            $searchHelper->byStatus($filterStatus);
106
-        }
107
-
108
-        if ($filterRequest !== null) {
109
-            $searchHelper->byRequest($filterRequest);
110
-        }
32
+	/**
33
+	 * Main function for this page, when no specific actions are called.
34
+	 * @return void
35
+	 */
36
+	protected function main()
37
+	{
38
+		$this->setHtmlTitle('Job Queue Management');
39
+
40
+		$this->prepareMaps();
41
+
42
+		$database = $this->getDatabase();
43
+
44
+		/** @var JobQueue[] $jobList */
45
+		// FIXME: domains
46
+		$jobList = JobQueueSearchHelper::get($database, 1)
47
+			->statusIn([
48
+				JobQueue::STATUS_QUEUED,
49
+				JobQueue::STATUS_READY,
50
+				JobQueue::STATUS_WAITING,
51
+				JobQueue::STATUS_RUNNING,
52
+				JobQueue::STATUS_FAILED,
53
+			])
54
+			->notAcknowledged()
55
+			->fetch();
56
+
57
+		$userIds = array();
58
+		$requestIds = array();
59
+
60
+		foreach ($jobList as $job) {
61
+			$userIds[] = $job->getTriggerUserId();
62
+			$requestIds[] = $job->getRequest();
63
+
64
+			$job->setDatabase($database);
65
+		}
66
+
67
+		$this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
68
+
69
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
70
+		// FIXME: domains
71
+		$this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
72
+
73
+		$this->assign('joblist', $jobList);
74
+		$this->setTemplate('jobqueue/main.tpl');
75
+	}
76
+
77
+	protected function all()
78
+	{
79
+		$this->setHtmlTitle('All Jobs');
80
+
81
+		$this->prepareMaps();
82
+
83
+		$database = $this->getDatabase();
84
+
85
+		// FIXME: domains
86
+		$searchHelper = JobQueueSearchHelper::get($database, 1);
87
+		$this->setSearchHelper($searchHelper);
88
+		$this->setupLimits();
89
+
90
+		$filterUser = WebRequest::getString('filterUser');
91
+		$filterTask = WebRequest::getString('filterTask');
92
+		$filterStatus = WebRequest::getString('filterStatus');
93
+		$filterRequest = WebRequest::getString('filterRequest');
94
+		$order = WebRequest::getString('order');
95
+
96
+		if ($filterUser !== null) {
97
+			$searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
98
+		}
99
+
100
+		if ($filterTask !== null) {
101
+			$searchHelper->byTask($filterTask);
102
+		}
103
+
104
+		if ($filterStatus !== null) {
105
+			$searchHelper->byStatus($filterStatus);
106
+		}
107
+
108
+		if ($filterRequest !== null) {
109
+			$searchHelper->byRequest($filterRequest);
110
+		}
111 111
         
112
-        if ($order === null) {
113
-            $searchHelper->newestFirst();
114
-        }
115
-
116
-        /** @var JobQueue[] $jobList */
117
-        $jobList = $searchHelper->getRecordCount($count)->fetch();
112
+		if ($order === null) {
113
+			$searchHelper->newestFirst();
114
+		}
115
+
116
+		/** @var JobQueue[] $jobList */
117
+		$jobList = $searchHelper->getRecordCount($count)->fetch();
118 118
 
119
-        $this->setupPageData($count, array(
120
-            'filterUser' => $filterUser,
121
-            'filterTask' => $filterTask,
122
-            'filterStatus' => $filterStatus,
123
-            'filterRequest' => $filterRequest,
124
-            'order' => $order,
125
-        ));
119
+		$this->setupPageData($count, array(
120
+			'filterUser' => $filterUser,
121
+			'filterTask' => $filterTask,
122
+			'filterStatus' => $filterStatus,
123
+			'filterRequest' => $filterRequest,
124
+			'order' => $order,
125
+		));
126 126
 
127
-        $userIds = array();
128
-        $requestIds = array();
127
+		$userIds = array();
128
+		$requestIds = array();
129 129
 
130
-        foreach ($jobList as $job) {
131
-            $userIds[] = $job->getTriggerUserId();
132
-            $requestIds[] = $job->getRequest();
130
+		foreach ($jobList as $job) {
131
+			$userIds[] = $job->getTriggerUserId();
132
+			$requestIds[] = $job->getRequest();
133 133
 
134
-            $job->setDatabase($database);
135
-        }
134
+			$job->setDatabase($database);
135
+		}
136 136
 
137
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
138
-            return UserSearchHelper::get($database)->fetchColumn('username');
139
-        });
137
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
138
+			return UserSearchHelper::get($database)->fetchColumn('username');
139
+		});
140 140
 
141
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
142
-        // FIXME: domains!
143
-        $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
141
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
142
+		// FIXME: domains!
143
+		$this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
144 144
 
145
-        $this->assign('joblist', $jobList);
145
+		$this->assign('joblist', $jobList);
146 146
 
147
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
147
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
148 148
 
149
-        $this->setTemplate('jobqueue/all.tpl');
150
-    }
149
+		$this->setTemplate('jobqueue/all.tpl');
150
+	}
151 151
 
152
-    protected function view()
153
-    {
154
-        $jobId = WebRequest::getInt('id');
155
-        $database = $this->getDatabase();
152
+	protected function view()
153
+	{
154
+		$jobId = WebRequest::getInt('id');
155
+		$database = $this->getDatabase();
156 156
 
157
-        if ($jobId === null) {
158
-            throw new ApplicationLogicException('No job specified');
159
-        }
157
+		if ($jobId === null) {
158
+			throw new ApplicationLogicException('No job specified');
159
+		}
160 160
 
161
-        /** @var JobQueue $job */
162
-        $job = JobQueue::getById($jobId, $database);
161
+		/** @var JobQueue $job */
162
+		$job = JobQueue::getById($jobId, $database);
163 163
 
164
-        if ($job === false) {
165
-            throw new ApplicationLogicException('Could not find requested job');
166
-        }
164
+		if ($job === false) {
165
+			throw new ApplicationLogicException('Could not find requested job');
166
+		}
167 167
 
168
-        $this->prepareMaps();
168
+		$this->prepareMaps();
169 169
 
170
-        $this->assign('user', User::getById($job->getTriggerUserId(), $database));
171
-        $this->assign('request', Request::getById($job->getRequest(), $database));
172
-        $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
173
-        $this->assign('parent', JobQueue::getById($job->getParent(), $database));
170
+		$this->assign('user', User::getById($job->getTriggerUserId(), $database));
171
+		$this->assign('request', Request::getById($job->getRequest(), $database));
172
+		$this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
173
+		$this->assign('parent', JobQueue::getById($job->getParent(), $database));
174 174
 
175
-        /** @var Log[] $logs */
176
-        // FIXME: domains
177
-        $logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue')
178
-            ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
179
-        if ($logCount === 0) {
180
-            $this->assign('log', array());
181
-        }
182
-        else {
183
-            list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
175
+		/** @var Log[] $logs */
176
+		// FIXME: domains
177
+		$logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue')
178
+			->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
179
+		if ($logCount === 0) {
180
+			$this->assign('log', array());
181
+		}
182
+		else {
183
+			list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
184 184
 
185
-            $this->assign("log", $logData);
186
-            $this->assign("users", $users);
187
-        }
185
+			$this->assign("log", $logData);
186
+			$this->assign("users", $users);
187
+		}
188 188
 
189
-        $this->assignCSRFToken();
189
+		$this->assignCSRFToken();
190 190
 
191
-        $this->assign('job', $job);
191
+		$this->assign('job', $job);
192 192
 
193
-        $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
194
-        $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
195
-        $this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database)));
193
+		$this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
194
+		$this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
195
+		$this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database)));
196 196
 
197
-        if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) {
198
-            if ($job->getEmailTemplate() === null) {
199
-                $params = json_decode($job->getParameters());
197
+		if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) {
198
+			if ($job->getEmailTemplate() === null) {
199
+				$params = json_decode($job->getParameters());
200 200
 
201
-                if (isset($params->emailText)) {
202
-                    $this->assign("creationEmailText", $params->emailText);
203
-                }
204
-            }
205
-        }
201
+				if (isset($params->emailText)) {
202
+					$this->assign("creationEmailText", $params->emailText);
203
+				}
204
+			}
205
+		}
206 206
 
207
-        $this->setHtmlTitle('Job #{$job->getId()|escape}');
208
-        $this->setTemplate('jobqueue/view.tpl');
209
-    }
207
+		$this->setHtmlTitle('Job #{$job->getId()|escape}');
208
+		$this->setTemplate('jobqueue/view.tpl');
209
+	}
210 210
 
211
-    protected function acknowledge()
212
-    {
213
-        if (!WebRequest::wasPosted()) {
214
-            throw new ApplicationLogicException('This page does not support GET methods.');
215
-        }
211
+	protected function acknowledge()
212
+	{
213
+		if (!WebRequest::wasPosted()) {
214
+			throw new ApplicationLogicException('This page does not support GET methods.');
215
+		}
216 216
 
217
-        $this->validateCSRFToken();
217
+		$this->validateCSRFToken();
218 218
 
219
-        $jobId = WebRequest::postInt('job');
220
-        $database = $this->getDatabase();
219
+		$jobId = WebRequest::postInt('job');
220
+		$database = $this->getDatabase();
221 221
 
222
-        if ($jobId === null) {
223
-            throw new ApplicationLogicException('No job specified');
224
-        }
222
+		if ($jobId === null) {
223
+			throw new ApplicationLogicException('No job specified');
224
+		}
225 225
 
226
-        /** @var JobQueue $job */
227
-        $job = JobQueue::getById($jobId, $database);
226
+		/** @var JobQueue $job */
227
+		$job = JobQueue::getById($jobId, $database);
228 228
 
229
-        if ($job === false) {
230
-            throw new ApplicationLogicException('Could not find requested job');
231
-        }
229
+		if ($job === false) {
230
+			throw new ApplicationLogicException('Could not find requested job');
231
+		}
232 232
 
233
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
234
-        $job->setAcknowledged(true);
235
-        $job->save();
233
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
234
+		$job->setAcknowledged(true);
235
+		$job->save();
236 236
 
237
-        Logger::backgroundJobAcknowledged($database, $job);
237
+		Logger::backgroundJobAcknowledged($database, $job);
238 238
 
239
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
240
-    }
241
-
242
-    protected function cancel()
243
-    {
244
-        if (!WebRequest::wasPosted()) {
245
-            throw new ApplicationLogicException('This page does not support GET methods.');
246
-        }
247
-
248
-        $this->validateCSRFToken();
249
-
250
-        $jobId = WebRequest::postInt('job');
251
-        $database = $this->getDatabase();
252
-
253
-        if ($jobId === null) {
254
-            throw new ApplicationLogicException('No job specified');
255
-        }
256
-
257
-        /** @var JobQueue $job */
258
-        $job = JobQueue::getById($jobId, $database);
259
-
260
-        if ($job === false) {
261
-            throw new ApplicationLogicException('Could not find requested job');
262
-        }
263
-
264
-        if ($job->getStatus() !== JobQueue::STATUS_READY
265
-            && $job->getStatus() !== JobQueue::STATUS_QUEUED
266
-            && $job->getStatus() === JobQueue::STATUS_WAITING) {
267
-            throw new ApplicationLogicException('Cannot cancel job not queued for execution');
268
-        }
269
-
270
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
271
-        $job->setStatus(JobQueue::STATUS_CANCELLED);
272
-        $job->setError("Manually cancelled");
273
-        $job->setAcknowledged(null);
274
-        $job->save();
275
-
276
-        Logger::backgroundJobCancelled($this->getDatabase(), $job);
277
-
278
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
279
-    }
280
-
281
-    protected function requeue()
282
-    {
283
-        if (!WebRequest::wasPosted()) {
284
-            throw new ApplicationLogicException('This page does not support GET methods.');
285
-        }
239
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
240
+	}
241
+
242
+	protected function cancel()
243
+	{
244
+		if (!WebRequest::wasPosted()) {
245
+			throw new ApplicationLogicException('This page does not support GET methods.');
246
+		}
247
+
248
+		$this->validateCSRFToken();
249
+
250
+		$jobId = WebRequest::postInt('job');
251
+		$database = $this->getDatabase();
252
+
253
+		if ($jobId === null) {
254
+			throw new ApplicationLogicException('No job specified');
255
+		}
256
+
257
+		/** @var JobQueue $job */
258
+		$job = JobQueue::getById($jobId, $database);
259
+
260
+		if ($job === false) {
261
+			throw new ApplicationLogicException('Could not find requested job');
262
+		}
263
+
264
+		if ($job->getStatus() !== JobQueue::STATUS_READY
265
+			&& $job->getStatus() !== JobQueue::STATUS_QUEUED
266
+			&& $job->getStatus() === JobQueue::STATUS_WAITING) {
267
+			throw new ApplicationLogicException('Cannot cancel job not queued for execution');
268
+		}
269
+
270
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
271
+		$job->setStatus(JobQueue::STATUS_CANCELLED);
272
+		$job->setError("Manually cancelled");
273
+		$job->setAcknowledged(null);
274
+		$job->save();
275
+
276
+		Logger::backgroundJobCancelled($this->getDatabase(), $job);
277
+
278
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
279
+	}
280
+
281
+	protected function requeue()
282
+	{
283
+		if (!WebRequest::wasPosted()) {
284
+			throw new ApplicationLogicException('This page does not support GET methods.');
285
+		}
286 286
 
287
-        $this->validateCSRFToken();
287
+		$this->validateCSRFToken();
288 288
 
289
-        $jobId = WebRequest::postInt('job');
290
-        $database = $this->getDatabase();
291
-
292
-        if ($jobId === null) {
293
-            throw new ApplicationLogicException('No job specified');
294
-        }
295
-
296
-        /** @var JobQueue|false $job */
297
-        $job = JobQueue::getById($jobId, $database);
298
-
299
-        if ($job === false) {
300
-            throw new ApplicationLogicException('Could not find requested job');
301
-        }
302
-
303
-        $job->setStatus(JobQueue::STATUS_QUEUED);
304
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
305
-        $job->setAcknowledged(null);
306
-        $job->setError(null);
307
-        $job->save();
308
-
309
-        /** @var Request $request */
310
-        $request = Request::getById($job->getRequest(), $database);
311
-        $request->setStatus(RequestStatus::JOBQUEUE);
312
-        $request->save();
313
-
314
-        Logger::enqueuedJobQueue($database, $request);
315
-        Logger::backgroundJobRequeued($database, $job);
289
+		$jobId = WebRequest::postInt('job');
290
+		$database = $this->getDatabase();
291
+
292
+		if ($jobId === null) {
293
+			throw new ApplicationLogicException('No job specified');
294
+		}
295
+
296
+		/** @var JobQueue|false $job */
297
+		$job = JobQueue::getById($jobId, $database);
298
+
299
+		if ($job === false) {
300
+			throw new ApplicationLogicException('Could not find requested job');
301
+		}
302
+
303
+		$job->setStatus(JobQueue::STATUS_QUEUED);
304
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
305
+		$job->setAcknowledged(null);
306
+		$job->setError(null);
307
+		$job->save();
308
+
309
+		/** @var Request $request */
310
+		$request = Request::getById($job->getRequest(), $database);
311
+		$request->setStatus(RequestStatus::JOBQUEUE);
312
+		$request->save();
313
+
314
+		Logger::enqueuedJobQueue($database, $request);
315
+		Logger::backgroundJobRequeued($database, $job);
316 316
 
317
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
318
-    }
319
-
320
-    protected function prepareMaps()
321
-    {
322
-        $taskNameMap = JobQueue::getTaskDescriptions();
323
-
324
-        $statusDecriptionMap = array(
325
-            JobQueue::STATUS_CANCELLED => 'The job was cancelled',
326
-            JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
327
-            JobQueue::STATUS_FAILED    => 'The job encountered an error',
328
-            JobQueue::STATUS_QUEUED    => 'The job is in the queue',
329
-            JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
330
-            JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
331
-            JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
332
-            JobQueue::STATUS_HELD      => 'The job has manually held from processing',
333
-        );
334
-        $this->assign('taskNameMap', $taskNameMap);
335
-        $this->assign('statusDescriptionMap', $statusDecriptionMap);
336
-    }
317
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
318
+	}
319
+
320
+	protected function prepareMaps()
321
+	{
322
+		$taskNameMap = JobQueue::getTaskDescriptions();
323
+
324
+		$statusDecriptionMap = array(
325
+			JobQueue::STATUS_CANCELLED => 'The job was cancelled',
326
+			JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
327
+			JobQueue::STATUS_FAILED    => 'The job encountered an error',
328
+			JobQueue::STATUS_QUEUED    => 'The job is in the queue',
329
+			JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
330
+			JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
331
+			JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
332
+			JobQueue::STATUS_HELD      => 'The job has manually held from processing',
333
+		);
334
+		$this->assign('taskNameMap', $taskNameMap);
335
+		$this->assign('statusDescriptionMap', $statusDecriptionMap);
336
+	}
337 337
 }
Please login to merge, or discard this patch.
includes/Pages/PageUserManagement.php 1 patch
Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -30,578 +30,578 @@
 block discarded – undo
30 30
  */
31 31
 class PageUserManagement extends InternalPageBase
32 32
 {
33
-    // FIXME: domains
34
-    /** @var string */
35
-    private $adminMailingList = '[email protected]';
36
-
37
-    /**
38
-     * Main function for this page, when no specific actions are called.
39
-     */
40
-    protected function main()
41
-    {
42
-        $this->setHtmlTitle('User Management');
43
-
44
-        $database = $this->getDatabase();
45
-        $currentUser = User::getCurrent($database);
46
-
47
-        $userSearchRequest = WebRequest::getString('usersearch');
48
-        if ($userSearchRequest !== null) {
49
-            $searchedUser = User::getByUsername($userSearchRequest, $database);
50
-            if ($searchedUser !== false) {
51
-                $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]);
52
-                return;
53
-            }
54
-        }
55
-
56
-        // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to
57
-        // the template. I still don't have a particularly good way of handling this.
58
-        OAuthUserHelper::prepareTokenCountStatement($database);
59
-
60
-        if (WebRequest::getBoolean("showAll")) {
61
-            $this->assign("showAll", true);
62
-
63
-            $deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch();
64
-            $this->assign('deactivatedUsers', $deactivatedUsers);
65
-
66
-            UserSearchHelper::get($database)->getRoleMap($roleMap);
67
-        }
68
-        else {
69
-            $this->assign("showAll", false);
70
-            $this->assign('deactivatedUsers', array());
71
-
72
-            UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
73
-        }
74
-
75
-        $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
76
-        $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
77
-        $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
78
-        $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
79
-        $stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch();
80
-        $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
81
-        $this->assign('newUsers', $newUsers);
82
-        $this->assign('normalUsers', $normalUsers);
83
-        $this->assign('adminUsers', $adminUsers);
84
-        $this->assign('checkUsers', $checkUsers);
85
-        $this->assign('stewards', $stewards);
86
-        $this->assign('toolRoots', $toolRoots);
87
-
88
-        $this->assign('roles', $roleMap);
89
-
90
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
91
-
92
-        $this->assign('canApprove', $this->barrierTest('approve', $currentUser));
93
-        $this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser));
94
-        $this->assign('canRename', $this->barrierTest('rename', $currentUser));
95
-        $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
96
-        $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
97
-
98
-        // FIXME: domains!
99
-        /** @var Domain $domain */
100
-        $domain = Domain::getById(1, $this->getDatabase());
101
-        $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
102
-
103
-        $this->setTemplate("usermanagement/main.tpl");
104
-    }
105
-
106
-    #region Access control
107
-
108
-    /**
109
-     * Action target for editing the roles assigned to a user
110
-     *
111
-     * @throws ApplicationLogicException
112
-     * @throws SmartyException
113
-     * @throws OptimisticLockFailedException
114
-     * @throws Exception
115
-     */
116
-    protected function editRoles(): void
117
-    {
118
-        $this->setHtmlTitle('User Management');
119
-        $database = $this->getDatabase();
120
-        $domain = Domain::getCurrent($database);
121
-        $userId = WebRequest::getInt('user');
122
-
123
-        /** @var User|false $user */
124
-        $user = User::getById($userId, $database);
125
-
126
-        if ($user === false || $user->isCommunityUser()) {
127
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
128
-        }
129
-
130
-        $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId()));
131
-
132
-        // Dual-mode action
133
-        if (WebRequest::wasPosted()) {
134
-            $this->validateCSRFToken();
135
-
136
-            $reason = WebRequest::postString('reason');
137
-            if ($reason === false || trim($reason) === '') {
138
-                throw new ApplicationLogicException('No reason specified for roles change');
139
-            }
140
-
141
-            /** @var UserRole[] $delete */
142
-            $delete = array();
143
-            /** @var string[] $add */
144
-            $add = array();
145
-
146
-            /** @var UserRole[] $globalDelete */
147
-            $globalDelete = array();
148
-            /** @var string[] $globalAdd */
149
-            $globalAdd = array();
150
-
151
-            foreach ($roleData as $name => $r) {
152
-                if ($r['allowEdit'] !== 1) {
153
-                    // not allowed, to touch this, so ignore it
154
-                    continue;
155
-                }
156
-
157
-                $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
158
-                if ($newValue !== $r['active']) {
159
-                    if ($newValue === 0) {
160
-                        if ($r['globalOnly']) {
161
-                            $globalDelete[] = $r['object'];
162
-                        }
163
-                        else {
164
-                            $delete[] = $r['object'];
165
-                        }
166
-                    }
167
-
168
-                    if ($newValue === 1) {
169
-                        if ($r['globalOnly']) {
170
-                            $globalAdd[] = $name;
171
-                        }
172
-                        else {
173
-                            $add[] = $name;
174
-                        }
175
-                    }
176
-                }
177
-            }
178
-
179
-            // Check there's something to do
180
-            if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) {
181
-                $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
182
-                SessionAlert::warning('No changes made to roles.');
183
-
184
-                return;
185
-            }
186
-
187
-            $removed = array();
188
-            $globalRemoved = array();
189
-
190
-            foreach ($delete as $d) {
191
-                $removed[] = $d->getRole();
192
-                $d->delete();
193
-            }
194
-
195
-            foreach ($globalDelete as $d) {
196
-                $globalRemoved[] = $d->getRole();
197
-                $d->delete();
198
-            }
199
-
200
-            foreach ($add as $x) {
201
-                $a = new UserRole();
202
-                $a->setUser($user->getId());
203
-                $a->setRole($x);
204
-                $a->setDomain($domain->getId());
205
-                $a->setDatabase($database);
206
-                $a->save();
207
-            }
208
-
209
-            foreach ($globalAdd as $x) {
210
-                $a = new UserRole();
211
-                $a->setUser($user->getId());
212
-                $a->setRole($x);
213
-                $a->setDomain(null);
214
-                $a->setDatabase($database);
215
-                $a->save();
216
-            }
217
-
218
-            if ((count($add) + count($delete)) > 0) {
219
-                Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId());
220
-            }
221
-
222
-            if ((count($globalAdd) + count($globalDelete)) > 0) {
223
-                Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved);
224
-            }
225
-
226
-            // dummy save for optimistic locking. If this fails, the entire txn will roll back.
227
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
228
-            $user->save();
229
-
230
-            $this->getNotificationHelper()->userRolesEdited($user, $reason);
231
-            SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
232
-
233
-            $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
234
-        }
235
-        else {
236
-            $this->assignCSRFToken();
237
-            $this->setTemplate('usermanagement/roleedit.tpl');
238
-            $this->assign('user', $user);
239
-            $this->assign('roleData', $roleData);
240
-        }
241
-    }
242
-
243
-    /**
244
-     * Action target for deactivating users
245
-     *
246
-     * @throws ApplicationLogicException
247
-     */
248
-    protected function deactivate()
249
-    {
250
-        $this->setHtmlTitle('User Management');
251
-
252
-        $database = $this->getDatabase();
253
-
254
-        $userId = WebRequest::getInt('user');
255
-
256
-        /** @var User $user */
257
-        $user = User::getById($userId, $database);
258
-
259
-        if ($user === false || $user->isCommunityUser()) {
260
-            throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.');
261
-        }
262
-
263
-        if ($user->isDeactivated()) {
264
-            throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.');
265
-        }
266
-
267
-        // Dual-mode action
268
-        if (WebRequest::wasPosted()) {
269
-            $this->validateCSRFToken();
270
-            $reason = WebRequest::postString('reason');
271
-
272
-            if ($reason === null || trim($reason) === '') {
273
-                throw new ApplicationLogicException('No reason provided');
274
-            }
275
-
276
-            $user->setStatus(User::STATUS_DEACTIVATED);
277
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
278
-            $user->save();
279
-            Logger::deactivatedUser($database, $user, $reason);
280
-
281
-            $this->getNotificationHelper()->userDeactivated($user);
282
-            SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
283
-
284
-            // send email
285
-            $this->sendStatusChangeEmail(
286
-                'Your WP:ACC account has been deactivated',
287
-                'usermanagement/emails/deactivated.tpl',
288
-                $reason,
289
-                $user,
290
-                User::getCurrent($database)->getUsername()
291
-            );
292
-
293
-            $this->redirect('userManagement');
294
-
295
-            return;
296
-        }
297
-        else {
298
-            $this->assignCSRFToken();
299
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
300
-            $this->assign('user', $user);
301
-            $this->assign('status', User::STATUS_DEACTIVATED);
302
-            $this->assign("showReason", true);
303
-
304
-            if (WebRequest::getString('preload')) {
305
-                $this->assign('preload', WebRequest::getString('preload'));
306
-            }
307
-        }
308
-    }
309
-
310
-    /**
311
-     * Entry point for the approve action
312
-     *
313
-     * @throws ApplicationLogicException
314
-     */
315
-    protected function approve()
316
-    {
317
-        $this->setHtmlTitle('User Management');
318
-
319
-        $database = $this->getDatabase();
320
-
321
-        $userId = WebRequest::getInt('user');
322
-        $user = User::getById($userId, $database);
323
-
324
-        if ($user === false || $user->isCommunityUser()) {
325
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
326
-        }
327
-
328
-        if ($user->isActive()) {
329
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
330
-        }
331
-
332
-        // Dual-mode action
333
-        if (WebRequest::wasPosted()) {
334
-            $this->validateCSRFToken();
335
-            $user->setStatus(User::STATUS_ACTIVE);
336
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
337
-            $user->save();
338
-            Logger::approvedUser($database, $user);
339
-
340
-            $this->getNotificationHelper()->userApproved($user);
341
-            SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
342
-
343
-            // send email
344
-            $this->sendStatusChangeEmail(
345
-                'Your WP:ACC account has been approved',
346
-                'usermanagement/emails/approved.tpl',
347
-                null,
348
-                $user,
349
-                User::getCurrent($database)->getUsername()
350
-            );
351
-
352
-            $this->redirect("userManagement");
353
-
354
-            return;
355
-        }
356
-        else {
357
-            $this->assignCSRFToken();
358
-            $this->setTemplate("usermanagement/changelevel-reason.tpl");
359
-            $this->assign("user", $user);
360
-            $this->assign("status", "Active");
361
-            $this->assign("showReason", false);
362
-        }
363
-    }
364
-
365
-    #endregion
366
-
367
-    #region Renaming / Editing
368
-
369
-    /**
370
-     * Entry point for the rename action
371
-     *
372
-     * @throws ApplicationLogicException
373
-     */
374
-    protected function rename()
375
-    {
376
-        $this->setHtmlTitle('User Management');
377
-
378
-        $database = $this->getDatabase();
379
-
380
-        $userId = WebRequest::getInt('user');
381
-        $user = User::getById($userId, $database);
382
-
383
-        if ($user === false || $user->isCommunityUser()) {
384
-            throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
385
-        }
386
-
387
-        // Dual-mode action
388
-        if (WebRequest::wasPosted()) {
389
-            $this->validateCSRFToken();
390
-            $newUsername = WebRequest::postString('newname');
391
-
392
-            if ($newUsername === null || trim($newUsername) === "") {
393
-                throw new ApplicationLogicException('The new username cannot be empty');
394
-            }
395
-
396
-            if (User::getByUsername($newUsername, $database) != false) {
397
-                throw new ApplicationLogicException('The new username already exists');
398
-            }
399
-
400
-            $oldUsername = $user->getUsername();
401
-            $user->setUsername($newUsername);
402
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
403
-
404
-            $user->save();
405
-
406
-            $logEntryData = serialize(array(
407
-                'old' => $oldUsername,
408
-                'new' => $newUsername,
409
-            ));
410
-
411
-            Logger::renamedUser($database, $user, $logEntryData);
412
-
413
-            SessionAlert::quick("Changed User "
414
-                . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
415
-                . " name to "
416
-                . htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
417
-
418
-            $this->getNotificationHelper()->userRenamed($user, $oldUsername);
419
-
420
-            // send an email to the user.
421
-            $this->assign('targetUsername', $user->getUsername());
422
-            $this->assign('toolAdmin', User::getCurrent($database)->getUsername());
423
-            $this->assign('oldUsername', $oldUsername);
424
-            $this->assign('mailingList', $this->adminMailingList);
425
-
426
-            // FIXME: domains!
427
-            /** @var Domain $domain */
428
-            $domain = Domain::getById(1, $database);
429
-            $this->getEmailHelper()->sendMail(
430
-                $this->adminMailingList,
431
-                $user->getEmail(),
432
-                'Your username on WP:ACC has been changed',
433
-                $this->fetchTemplate('usermanagement/emails/renamed.tpl')
434
-            );
435
-
436
-            $this->redirect("userManagement");
437
-
438
-            return;
439
-        }
440
-        else {
441
-            $this->assignCSRFToken();
442
-            $this->setTemplate('usermanagement/renameuser.tpl');
443
-            $this->assign('user', $user);
444
-        }
445
-    }
446
-
447
-    /**
448
-     * Entry point for the edit action
449
-     *
450
-     * @throws ApplicationLogicException
451
-     */
452
-    protected function editUser()
453
-    {
454
-        $this->setHtmlTitle('User Management');
455
-
456
-        $database = $this->getDatabase();
457
-
458
-        $userId = WebRequest::getInt('user');
459
-        $user = User::getById($userId, $database);
460
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
461
-
462
-        if ($user === false || $user->isCommunityUser()) {
463
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
464
-        }
465
-
466
-        // FIXME: domains
467
-        $prefs = new PreferenceManager($database, $user->getId(), 1);
468
-
469
-        // Dual-mode action
470
-        if (WebRequest::wasPosted()) {
471
-            $this->validateCSRFToken();
472
-            $newEmail = WebRequest::postEmail('user_email');
473
-            $newOnWikiName = WebRequest::postString('user_onwikiname');
474
-
475
-            if ($newEmail === null) {
476
-                throw new ApplicationLogicException('Invalid email address');
477
-            }
478
-
479
-            if ($this->validateUnusedEmail($newEmail, $userId)) {
480
-                throw new ApplicationLogicException('The specified email address is already in use.');
481
-            }
482
-
483
-            if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) {
484
-                if (trim($newOnWikiName) == "") {
485
-                    throw new ApplicationLogicException('New on-wiki username cannot be blank');
486
-                }
487
-
488
-                $user->setOnWikiName($newOnWikiName);
489
-            }
490
-
491
-            $user->setEmail($newEmail);
492
-
493
-            $prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode'));
494
-
495
-            $prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation'));
496
-
497
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
498
-
499
-            $user->save();
500
-
501
-            Logger::userPreferencesChange($database, $user);
502
-            $this->getNotificationHelper()->userPrefChange($user);
503
-            SessionAlert::quick('Changes to user\'s preferences have been saved');
504
-
505
-            $this->redirect("userManagement");
506
-
507
-            return;
508
-        }
509
-        else {
510
-            $this->assignCSRFToken();
511
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
512
-                $this->getSiteConfiguration());
513
-            $this->setTemplate('usermanagement/edituser.tpl');
514
-            $this->assign('user', $user);
515
-            $this->assign('oauth', $oauth);
516
-
517
-            $this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE));
518
-            $this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE));
519
-
520
-            $this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false);
521
-
522
-            $this->assign('canManualCreate',
523
-                $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
524
-            $this->assign('canOauthCreate',
525
-                $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
526
-            $this->assign('canBotCreate',
527
-                $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
528
-        }
529
-    }
530
-
531
-    #endregion
532
-
533
-    private function validateUnusedEmail(string $email, int $userId) : bool {
534
-        $query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid';
535
-        $statement = $this->getDatabase()->prepare($query);
536
-        $statement->execute(array(':email' => $email, ':uid' => $userId));
537
-        $inUse = $statement->fetchColumn() > 0;
538
-        $statement->closeCursor();
539
-
540
-        return $inUse;
541
-    }
542
-
543
-    /**
544
-     * Sends a status change email to the user.
545
-     *
546
-     * @param string      $subject           The subject of the email
547
-     * @param string      $template          The smarty template to use
548
-     * @param string|null $reason            The reason for performing the status change
549
-     * @param User        $user              The user affected
550
-     * @param string      $toolAdminUsername The tool admin's username who is making the edit
551
-     */
552
-    private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
553
-    {
554
-        $this->assign('targetUsername', $user->getUsername());
555
-        $this->assign('toolAdmin', $toolAdminUsername);
556
-        $this->assign('actionReason', $reason);
557
-        $this->assign('mailingList', $this->adminMailingList);
558
-
559
-        // FIXME: domains!
560
-        /** @var Domain $domain */
561
-        $domain = Domain::getById(1, $this->getDatabase());
562
-        $this->getEmailHelper()->sendMail(
563
-            $this->adminMailingList,
564
-            $user->getEmail(),
565
-            $subject,
566
-            $this->fetchTemplate($template)
567
-        );
568
-    }
569
-
570
-    /**
571
-     * @param UserRole[] $activeRoles
572
-     *
573
-     * @return array
574
-     */
575
-    private function getRoleData($activeRoles)
576
-    {
577
-        $availableRoles = $this->getSecurityManager()->getAvailableRoles();
578
-
579
-        $currentUser = User::getCurrent($this->getDatabase());
580
-        $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
581
-
582
-        $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
583
-
584
-        $roleData = array();
585
-        foreach ($availableRoles as $role => $data) {
586
-            $intersection = array_intersect($data['editableBy'], $userRoles);
587
-
588
-            $roleData[$role] = $initialValue;
589
-            $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
590
-            $roleData[$role]['description'] = $data['description'];
591
-            $roleData[$role]['globalOnly'] = $data['globalOnly'];
592
-        }
593
-
594
-        foreach ($activeRoles as $role) {
595
-            if (!isset($roleData[$role->getRole()])) {
596
-                // This value is no longer available in the configuration, allow changing (aka removing) it.
597
-                $roleData[$role->getRole()] = $initialValue;
598
-                $roleData[$role->getRole()]['allowEdit'] = 1;
599
-            }
600
-
601
-            $roleData[$role->getRole()]['object'] = $role;
602
-            $roleData[$role->getRole()]['active'] = 1;
603
-        }
604
-
605
-        return $roleData;
606
-    }
33
+	// FIXME: domains
34
+	/** @var string */
35
+	private $adminMailingList = '[email protected]';
36
+
37
+	/**
38
+	 * Main function for this page, when no specific actions are called.
39
+	 */
40
+	protected function main()
41
+	{
42
+		$this->setHtmlTitle('User Management');
43
+
44
+		$database = $this->getDatabase();
45
+		$currentUser = User::getCurrent($database);
46
+
47
+		$userSearchRequest = WebRequest::getString('usersearch');
48
+		if ($userSearchRequest !== null) {
49
+			$searchedUser = User::getByUsername($userSearchRequest, $database);
50
+			if ($searchedUser !== false) {
51
+				$this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]);
52
+				return;
53
+			}
54
+		}
55
+
56
+		// A bit hacky, but it's better than my last solution of creating an object for each user and passing that to
57
+		// the template. I still don't have a particularly good way of handling this.
58
+		OAuthUserHelper::prepareTokenCountStatement($database);
59
+
60
+		if (WebRequest::getBoolean("showAll")) {
61
+			$this->assign("showAll", true);
62
+
63
+			$deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch();
64
+			$this->assign('deactivatedUsers', $deactivatedUsers);
65
+
66
+			UserSearchHelper::get($database)->getRoleMap($roleMap);
67
+		}
68
+		else {
69
+			$this->assign("showAll", false);
70
+			$this->assign('deactivatedUsers', array());
71
+
72
+			UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
73
+		}
74
+
75
+		$newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
76
+		$normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
77
+		$adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
78
+		$checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
79
+		$stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch();
80
+		$toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
81
+		$this->assign('newUsers', $newUsers);
82
+		$this->assign('normalUsers', $normalUsers);
83
+		$this->assign('adminUsers', $adminUsers);
84
+		$this->assign('checkUsers', $checkUsers);
85
+		$this->assign('stewards', $stewards);
86
+		$this->assign('toolRoots', $toolRoots);
87
+
88
+		$this->assign('roles', $roleMap);
89
+
90
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
91
+
92
+		$this->assign('canApprove', $this->barrierTest('approve', $currentUser));
93
+		$this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser));
94
+		$this->assign('canRename', $this->barrierTest('rename', $currentUser));
95
+		$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
96
+		$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
97
+
98
+		// FIXME: domains!
99
+		/** @var Domain $domain */
100
+		$domain = Domain::getById(1, $this->getDatabase());
101
+		$this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
102
+
103
+		$this->setTemplate("usermanagement/main.tpl");
104
+	}
105
+
106
+	#region Access control
107
+
108
+	/**
109
+	 * Action target for editing the roles assigned to a user
110
+	 *
111
+	 * @throws ApplicationLogicException
112
+	 * @throws SmartyException
113
+	 * @throws OptimisticLockFailedException
114
+	 * @throws Exception
115
+	 */
116
+	protected function editRoles(): void
117
+	{
118
+		$this->setHtmlTitle('User Management');
119
+		$database = $this->getDatabase();
120
+		$domain = Domain::getCurrent($database);
121
+		$userId = WebRequest::getInt('user');
122
+
123
+		/** @var User|false $user */
124
+		$user = User::getById($userId, $database);
125
+
126
+		if ($user === false || $user->isCommunityUser()) {
127
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
128
+		}
129
+
130
+		$roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId()));
131
+
132
+		// Dual-mode action
133
+		if (WebRequest::wasPosted()) {
134
+			$this->validateCSRFToken();
135
+
136
+			$reason = WebRequest::postString('reason');
137
+			if ($reason === false || trim($reason) === '') {
138
+				throw new ApplicationLogicException('No reason specified for roles change');
139
+			}
140
+
141
+			/** @var UserRole[] $delete */
142
+			$delete = array();
143
+			/** @var string[] $add */
144
+			$add = array();
145
+
146
+			/** @var UserRole[] $globalDelete */
147
+			$globalDelete = array();
148
+			/** @var string[] $globalAdd */
149
+			$globalAdd = array();
150
+
151
+			foreach ($roleData as $name => $r) {
152
+				if ($r['allowEdit'] !== 1) {
153
+					// not allowed, to touch this, so ignore it
154
+					continue;
155
+				}
156
+
157
+				$newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
158
+				if ($newValue !== $r['active']) {
159
+					if ($newValue === 0) {
160
+						if ($r['globalOnly']) {
161
+							$globalDelete[] = $r['object'];
162
+						}
163
+						else {
164
+							$delete[] = $r['object'];
165
+						}
166
+					}
167
+
168
+					if ($newValue === 1) {
169
+						if ($r['globalOnly']) {
170
+							$globalAdd[] = $name;
171
+						}
172
+						else {
173
+							$add[] = $name;
174
+						}
175
+					}
176
+				}
177
+			}
178
+
179
+			// Check there's something to do
180
+			if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) {
181
+				$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
182
+				SessionAlert::warning('No changes made to roles.');
183
+
184
+				return;
185
+			}
186
+
187
+			$removed = array();
188
+			$globalRemoved = array();
189
+
190
+			foreach ($delete as $d) {
191
+				$removed[] = $d->getRole();
192
+				$d->delete();
193
+			}
194
+
195
+			foreach ($globalDelete as $d) {
196
+				$globalRemoved[] = $d->getRole();
197
+				$d->delete();
198
+			}
199
+
200
+			foreach ($add as $x) {
201
+				$a = new UserRole();
202
+				$a->setUser($user->getId());
203
+				$a->setRole($x);
204
+				$a->setDomain($domain->getId());
205
+				$a->setDatabase($database);
206
+				$a->save();
207
+			}
208
+
209
+			foreach ($globalAdd as $x) {
210
+				$a = new UserRole();
211
+				$a->setUser($user->getId());
212
+				$a->setRole($x);
213
+				$a->setDomain(null);
214
+				$a->setDatabase($database);
215
+				$a->save();
216
+			}
217
+
218
+			if ((count($add) + count($delete)) > 0) {
219
+				Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId());
220
+			}
221
+
222
+			if ((count($globalAdd) + count($globalDelete)) > 0) {
223
+				Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved);
224
+			}
225
+
226
+			// dummy save for optimistic locking. If this fails, the entire txn will roll back.
227
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
228
+			$user->save();
229
+
230
+			$this->getNotificationHelper()->userRolesEdited($user, $reason);
231
+			SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
232
+
233
+			$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
234
+		}
235
+		else {
236
+			$this->assignCSRFToken();
237
+			$this->setTemplate('usermanagement/roleedit.tpl');
238
+			$this->assign('user', $user);
239
+			$this->assign('roleData', $roleData);
240
+		}
241
+	}
242
+
243
+	/**
244
+	 * Action target for deactivating users
245
+	 *
246
+	 * @throws ApplicationLogicException
247
+	 */
248
+	protected function deactivate()
249
+	{
250
+		$this->setHtmlTitle('User Management');
251
+
252
+		$database = $this->getDatabase();
253
+
254
+		$userId = WebRequest::getInt('user');
255
+
256
+		/** @var User $user */
257
+		$user = User::getById($userId, $database);
258
+
259
+		if ($user === false || $user->isCommunityUser()) {
260
+			throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.');
261
+		}
262
+
263
+		if ($user->isDeactivated()) {
264
+			throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.');
265
+		}
266
+
267
+		// Dual-mode action
268
+		if (WebRequest::wasPosted()) {
269
+			$this->validateCSRFToken();
270
+			$reason = WebRequest::postString('reason');
271
+
272
+			if ($reason === null || trim($reason) === '') {
273
+				throw new ApplicationLogicException('No reason provided');
274
+			}
275
+
276
+			$user->setStatus(User::STATUS_DEACTIVATED);
277
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
278
+			$user->save();
279
+			Logger::deactivatedUser($database, $user, $reason);
280
+
281
+			$this->getNotificationHelper()->userDeactivated($user);
282
+			SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
283
+
284
+			// send email
285
+			$this->sendStatusChangeEmail(
286
+				'Your WP:ACC account has been deactivated',
287
+				'usermanagement/emails/deactivated.tpl',
288
+				$reason,
289
+				$user,
290
+				User::getCurrent($database)->getUsername()
291
+			);
292
+
293
+			$this->redirect('userManagement');
294
+
295
+			return;
296
+		}
297
+		else {
298
+			$this->assignCSRFToken();
299
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
300
+			$this->assign('user', $user);
301
+			$this->assign('status', User::STATUS_DEACTIVATED);
302
+			$this->assign("showReason", true);
303
+
304
+			if (WebRequest::getString('preload')) {
305
+				$this->assign('preload', WebRequest::getString('preload'));
306
+			}
307
+		}
308
+	}
309
+
310
+	/**
311
+	 * Entry point for the approve action
312
+	 *
313
+	 * @throws ApplicationLogicException
314
+	 */
315
+	protected function approve()
316
+	{
317
+		$this->setHtmlTitle('User Management');
318
+
319
+		$database = $this->getDatabase();
320
+
321
+		$userId = WebRequest::getInt('user');
322
+		$user = User::getById($userId, $database);
323
+
324
+		if ($user === false || $user->isCommunityUser()) {
325
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
326
+		}
327
+
328
+		if ($user->isActive()) {
329
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
330
+		}
331
+
332
+		// Dual-mode action
333
+		if (WebRequest::wasPosted()) {
334
+			$this->validateCSRFToken();
335
+			$user->setStatus(User::STATUS_ACTIVE);
336
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
337
+			$user->save();
338
+			Logger::approvedUser($database, $user);
339
+
340
+			$this->getNotificationHelper()->userApproved($user);
341
+			SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
342
+
343
+			// send email
344
+			$this->sendStatusChangeEmail(
345
+				'Your WP:ACC account has been approved',
346
+				'usermanagement/emails/approved.tpl',
347
+				null,
348
+				$user,
349
+				User::getCurrent($database)->getUsername()
350
+			);
351
+
352
+			$this->redirect("userManagement");
353
+
354
+			return;
355
+		}
356
+		else {
357
+			$this->assignCSRFToken();
358
+			$this->setTemplate("usermanagement/changelevel-reason.tpl");
359
+			$this->assign("user", $user);
360
+			$this->assign("status", "Active");
361
+			$this->assign("showReason", false);
362
+		}
363
+	}
364
+
365
+	#endregion
366
+
367
+	#region Renaming / Editing
368
+
369
+	/**
370
+	 * Entry point for the rename action
371
+	 *
372
+	 * @throws ApplicationLogicException
373
+	 */
374
+	protected function rename()
375
+	{
376
+		$this->setHtmlTitle('User Management');
377
+
378
+		$database = $this->getDatabase();
379
+
380
+		$userId = WebRequest::getInt('user');
381
+		$user = User::getById($userId, $database);
382
+
383
+		if ($user === false || $user->isCommunityUser()) {
384
+			throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
385
+		}
386
+
387
+		// Dual-mode action
388
+		if (WebRequest::wasPosted()) {
389
+			$this->validateCSRFToken();
390
+			$newUsername = WebRequest::postString('newname');
391
+
392
+			if ($newUsername === null || trim($newUsername) === "") {
393
+				throw new ApplicationLogicException('The new username cannot be empty');
394
+			}
395
+
396
+			if (User::getByUsername($newUsername, $database) != false) {
397
+				throw new ApplicationLogicException('The new username already exists');
398
+			}
399
+
400
+			$oldUsername = $user->getUsername();
401
+			$user->setUsername($newUsername);
402
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
403
+
404
+			$user->save();
405
+
406
+			$logEntryData = serialize(array(
407
+				'old' => $oldUsername,
408
+				'new' => $newUsername,
409
+			));
410
+
411
+			Logger::renamedUser($database, $user, $logEntryData);
412
+
413
+			SessionAlert::quick("Changed User "
414
+				. htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
415
+				. " name to "
416
+				. htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
417
+
418
+			$this->getNotificationHelper()->userRenamed($user, $oldUsername);
419
+
420
+			// send an email to the user.
421
+			$this->assign('targetUsername', $user->getUsername());
422
+			$this->assign('toolAdmin', User::getCurrent($database)->getUsername());
423
+			$this->assign('oldUsername', $oldUsername);
424
+			$this->assign('mailingList', $this->adminMailingList);
425
+
426
+			// FIXME: domains!
427
+			/** @var Domain $domain */
428
+			$domain = Domain::getById(1, $database);
429
+			$this->getEmailHelper()->sendMail(
430
+				$this->adminMailingList,
431
+				$user->getEmail(),
432
+				'Your username on WP:ACC has been changed',
433
+				$this->fetchTemplate('usermanagement/emails/renamed.tpl')
434
+			);
435
+
436
+			$this->redirect("userManagement");
437
+
438
+			return;
439
+		}
440
+		else {
441
+			$this->assignCSRFToken();
442
+			$this->setTemplate('usermanagement/renameuser.tpl');
443
+			$this->assign('user', $user);
444
+		}
445
+	}
446
+
447
+	/**
448
+	 * Entry point for the edit action
449
+	 *
450
+	 * @throws ApplicationLogicException
451
+	 */
452
+	protected function editUser()
453
+	{
454
+		$this->setHtmlTitle('User Management');
455
+
456
+		$database = $this->getDatabase();
457
+
458
+		$userId = WebRequest::getInt('user');
459
+		$user = User::getById($userId, $database);
460
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
461
+
462
+		if ($user === false || $user->isCommunityUser()) {
463
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
464
+		}
465
+
466
+		// FIXME: domains
467
+		$prefs = new PreferenceManager($database, $user->getId(), 1);
468
+
469
+		// Dual-mode action
470
+		if (WebRequest::wasPosted()) {
471
+			$this->validateCSRFToken();
472
+			$newEmail = WebRequest::postEmail('user_email');
473
+			$newOnWikiName = WebRequest::postString('user_onwikiname');
474
+
475
+			if ($newEmail === null) {
476
+				throw new ApplicationLogicException('Invalid email address');
477
+			}
478
+
479
+			if ($this->validateUnusedEmail($newEmail, $userId)) {
480
+				throw new ApplicationLogicException('The specified email address is already in use.');
481
+			}
482
+
483
+			if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) {
484
+				if (trim($newOnWikiName) == "") {
485
+					throw new ApplicationLogicException('New on-wiki username cannot be blank');
486
+				}
487
+
488
+				$user->setOnWikiName($newOnWikiName);
489
+			}
490
+
491
+			$user->setEmail($newEmail);
492
+
493
+			$prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode'));
494
+
495
+			$prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation'));
496
+
497
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
498
+
499
+			$user->save();
500
+
501
+			Logger::userPreferencesChange($database, $user);
502
+			$this->getNotificationHelper()->userPrefChange($user);
503
+			SessionAlert::quick('Changes to user\'s preferences have been saved');
504
+
505
+			$this->redirect("userManagement");
506
+
507
+			return;
508
+		}
509
+		else {
510
+			$this->assignCSRFToken();
511
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
512
+				$this->getSiteConfiguration());
513
+			$this->setTemplate('usermanagement/edituser.tpl');
514
+			$this->assign('user', $user);
515
+			$this->assign('oauth', $oauth);
516
+
517
+			$this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE));
518
+			$this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE));
519
+
520
+			$this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false);
521
+
522
+			$this->assign('canManualCreate',
523
+				$this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
524
+			$this->assign('canOauthCreate',
525
+				$this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
526
+			$this->assign('canBotCreate',
527
+				$this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
528
+		}
529
+	}
530
+
531
+	#endregion
532
+
533
+	private function validateUnusedEmail(string $email, int $userId) : bool {
534
+		$query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid';
535
+		$statement = $this->getDatabase()->prepare($query);
536
+		$statement->execute(array(':email' => $email, ':uid' => $userId));
537
+		$inUse = $statement->fetchColumn() > 0;
538
+		$statement->closeCursor();
539
+
540
+		return $inUse;
541
+	}
542
+
543
+	/**
544
+	 * Sends a status change email to the user.
545
+	 *
546
+	 * @param string      $subject           The subject of the email
547
+	 * @param string      $template          The smarty template to use
548
+	 * @param string|null $reason            The reason for performing the status change
549
+	 * @param User        $user              The user affected
550
+	 * @param string      $toolAdminUsername The tool admin's username who is making the edit
551
+	 */
552
+	private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
553
+	{
554
+		$this->assign('targetUsername', $user->getUsername());
555
+		$this->assign('toolAdmin', $toolAdminUsername);
556
+		$this->assign('actionReason', $reason);
557
+		$this->assign('mailingList', $this->adminMailingList);
558
+
559
+		// FIXME: domains!
560
+		/** @var Domain $domain */
561
+		$domain = Domain::getById(1, $this->getDatabase());
562
+		$this->getEmailHelper()->sendMail(
563
+			$this->adminMailingList,
564
+			$user->getEmail(),
565
+			$subject,
566
+			$this->fetchTemplate($template)
567
+		);
568
+	}
569
+
570
+	/**
571
+	 * @param UserRole[] $activeRoles
572
+	 *
573
+	 * @return array
574
+	 */
575
+	private function getRoleData($activeRoles)
576
+	{
577
+		$availableRoles = $this->getSecurityManager()->getAvailableRoles();
578
+
579
+		$currentUser = User::getCurrent($this->getDatabase());
580
+		$this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
581
+
582
+		$initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
583
+
584
+		$roleData = array();
585
+		foreach ($availableRoles as $role => $data) {
586
+			$intersection = array_intersect($data['editableBy'], $userRoles);
587
+
588
+			$roleData[$role] = $initialValue;
589
+			$roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
590
+			$roleData[$role]['description'] = $data['description'];
591
+			$roleData[$role]['globalOnly'] = $data['globalOnly'];
592
+		}
593
+
594
+		foreach ($activeRoles as $role) {
595
+			if (!isset($roleData[$role->getRole()])) {
596
+				// This value is no longer available in the configuration, allow changing (aka removing) it.
597
+				$roleData[$role->getRole()] = $initialValue;
598
+				$roleData[$role->getRole()]['allowEdit'] = 1;
599
+			}
600
+
601
+			$roleData[$role->getRole()]['object'] = $role;
602
+			$roleData[$role->getRole()]['active'] = 1;
603
+		}
604
+
605
+		return $roleData;
606
+	}
607 607
 }
Please login to merge, or discard this patch.
includes/Pages/PageViewRequest.php 1 patch
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -33,369 +33,369 @@
 block discarded – undo
33 33
 
34 34
 class PageViewRequest extends InternalPageBase
35 35
 {
36
-    use RequestData;
37
-
38
-    const STATUS_SYMBOL_OPEN = '&#927';
39
-    const STATUS_SYMBOL_ACCEPTED = '&#x2611';
40
-    const STATUS_SYMBOL_REJECTED = '&#x2612';
41
-
42
-    /**
43
-     * Main function for this page, when no specific actions are called.
44
-     * @throws ApplicationLogicException
45
-     */
46
-    protected function main()
47
-    {
48
-        // set up csrf protection
49
-        $this->assignCSRFToken();
50
-
51
-        // get some useful objects
52
-        $database = $this->getDatabase();
53
-        $request = $this->getRequest($database, WebRequest::getInt('id'));
54
-        $config = $this->getSiteConfiguration();
55
-        $currentUser = User::getCurrent($database);
56
-
57
-        // FIXME: domains!
58
-        /** @var Domain $domain */
59
-        $domain = Domain::getById(1, $this->getDatabase());
60
-        $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
61
-
62
-        // Shows a page if the email is not confirmed.
63
-        if ($request->getEmailConfirm() !== 'Confirmed') {
64
-            // Show a banner if the user can manually confirm the request
65
-            $viewConfirm = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageManuallyConfirm::class);
66
-
67
-            // If the request is purged, there's nothing to confirm!
68
-            if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
69
-                $viewConfirm = false;
70
-            }
71
-
72
-            // Render
73
-            $this->setTemplate("view-request/not-confirmed.tpl");
74
-            $this->assign("requestId", $request->getId());
75
-            $this->assign("requestVersion", $request->getUpdateVersion());
76
-            $this->assign('canViewConfirmButton', $viewConfirm);
77
-
78
-            // Make sure to return, to prevent the leaking of other information.
79
-            return;
80
-        }
81
-
82
-        $this->setupBasicData($request, $config);
83
-
84
-        $this->setupUsernameData($request);
85
-
86
-        $this->setupTitle($request);
87
-
88
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
89
-        $this->setupGeneralData($database);
90
-
91
-        $this->assign('requestDataCleared', false);
92
-        if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
93
-            $this->assign('requestDataCleared', true);
94
-        }
95
-
96
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
97
-
98
-        $this->setupCreationTypes($currentUser);
99
-
100
-        $this->setupLogData($request, $database, $allowedPrivateData);
101
-
102
-        $this->addJs("/api.php?action=templates&targetVariable=templateconfirms");
103
-
104
-        $this->assign('showRevealLink', false);
105
-        if ($request->getReserved() === $currentUser->getId() ||
106
-            $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
107
-        ) {
108
-            $this->assign('showRevealLink', true);
109
-            $this->assign('revealHash', $request->getRevealHash());
110
-        }
111
-
112
-        $this->assign('canSeeRelatedRequests', false);
113
-        if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) {
114
-            $this->setupRelatedRequests($request, $config, $database);
115
-        }
116
-
117
-        $this->assign('canCreateLocalAccount', $this->barrierTest('createLocalAccount', $currentUser, 'RequestData'));
118
-
119
-        $closureDate = $request->getClosureDate();
120
-        $date = new DateTime();
121
-        $date->modify("-7 days");
122
-        if ($request->getStatus() == "Closed" && $closureDate < $date) {
123
-            $this->assign('isOldRequest', true);
124
-        }
125
-        $this->assign('canResetOldRequest', $this->barrierTest('reopenOldRequest', $currentUser, 'RequestData'));
126
-        $this->assign('canResetPurgedRequest', $this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData'));
127
-
128
-        $this->assign('requestEmailSent', $request->getEmailSent());
129
-
130
-        if ($allowedPrivateData) {
131
-            $this->setTemplate('view-request/main-with-data.tpl');
132
-            $this->setupPrivateData($request, $config);
133
-            $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
134
-            $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
135
-
136
-            if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
137
-                $this->setTemplate('view-request/main-with-checkuser-data.tpl');
138
-                $this->setupCheckUserData($request);
139
-            }
140
-        }
141
-        else {
142
-            $this->setTemplate('view-request/main.tpl');
143
-        }
144
-    }
145
-
146
-    /**
147
-     * @param Request $request
148
-     */
149
-    protected function setupTitle(Request $request)
150
-    {
151
-        $statusSymbol = self::STATUS_SYMBOL_OPEN;
152
-        if ($request->getStatus() === RequestStatus::CLOSED) {
153
-            if ($request->getWasCreated()) {
154
-                $statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
155
-            }
156
-            else {
157
-                $statusSymbol = self::STATUS_SYMBOL_REJECTED;
158
-            }
159
-        }
160
-
161
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
162
-    }
163
-
164
-    /**
165
-     * Sets up data unrelated to the request, such as the email template information
166
-     *
167
-     * @param PdoDatabase $database
168
-     */
169
-    protected function setupGeneralData(PdoDatabase $database)
170
-    {
171
-        $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
172
-
173
-        // FIXME: domains
174
-        /** @var Domain $domain */
175
-        $domain = Domain::getById(1, $database);
176
-        $this->assign('defaultRequestState', RequestQueue::getDefaultQueue($database, 1)->getApiName());
177
-        $this->assign('activeRequestQueues', RequestQueue::getEnabledQueues($database));
178
-
179
-        /** @var EmailTemplate $createdTemplate */
180
-        $createdTemplate = EmailTemplate::getById($domain->getDefaultClose(), $database);
181
-
182
-        $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
183
-        $this->assign('createdId', $createdTemplate->getId());
184
-        $this->assign('createdName', $createdTemplate->getName());
185
-
186
-        $preferenceManager = PreferenceManager::getForCurrent($database);
187
-        $skipJsAborts = $preferenceManager->getPreference(PreferenceManager::PREF_SKIP_JS_ABORT);
188
-        $preferredCreationMode = (int)$preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE);
189
-        $this->assign('skipJsAborts', $skipJsAborts);
190
-        $this->assign('preferredCreationMode', $preferredCreationMode);
191
-
192
-        $createReasons = EmailTemplate::getActiveNonpreloadTemplates(
193
-            EmailTemplate::ACTION_CREATED,
194
-            $database,
195
-            $domain->getId(),
196
-            $domain->getDefaultClose());
197
-        $this->assign("createReasons", $createReasons);
198
-
199
-        $declineReasons = EmailTemplate::getActiveNonpreloadTemplates(
200
-            EmailTemplate::ACTION_NOT_CREATED,
201
-            $database,
202
-            $domain->getId());
203
-        $this->assign("declineReasons", $declineReasons);
204
-
205
-        $allCreateReasons = EmailTemplate::getAllActiveTemplates(
206
-            EmailTemplate::ACTION_CREATED,
207
-            $database,
208
-            $domain->getId());
209
-        $this->assign("allCreateReasons", $allCreateReasons);
210
-
211
-        $allDeclineReasons = EmailTemplate::getAllActiveTemplates(
212
-            EmailTemplate::ACTION_NOT_CREATED,
213
-            $database,
214
-            $domain->getId());
215
-        $this->assign("allDeclineReasons", $allDeclineReasons);
216
-
217
-        $allOtherReasons = EmailTemplate::getAllActiveTemplates(
218
-            false,
219
-            $database,
220
-            $domain->getId());
221
-        $this->assign("allOtherReasons", $allOtherReasons);
222
-    }
223
-
224
-    private function setupLogData(Request $request, PdoDatabase $database, bool $allowedPrivateData)
225
-    {
226
-        $currentUser = User::getCurrent($database);
227
-
228
-        $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
229
-        $requestLogs = array();
230
-
231
-        /** @var User[] $nameCache */
232
-        $nameCache = array();
233
-
234
-        $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
235
-
236
-        $canFlag = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class);
237
-        $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class);
238
-
239
-        /** @var Log|Comment $entry */
240
-        foreach ($logs as $entry) {
241
-            // both log and comment have a 'user' field
242
-            if (!array_key_exists($entry->getUser(), $nameCache)) {
243
-                $entryUser = User::getById($entry->getUser(), $database);
244
-                $nameCache[$entry->getUser()] = $entryUser;
245
-            }
246
-
247
-            if ($entry instanceof Comment) {
248
-                // Determine if the comment contains private information.
249
-                // Private defined as flagged or restricted visibility, but only when the user isn't allowed
250
-                // to see private data
251
-                $commentIsRestricted =
252
-                    ($entry->getFlagged()
253
-                        || $entry->getVisibility() == 'admin' || $entry->getVisibility() == 'checkuser')
254
-                    && !$allowedPrivateData;
255
-
256
-                // Only allow comment editing if the user is able to edit comments or this is the user's own comment,
257
-                // but only when they're allowed to see the comment itself.
258
-                $commentIsEditable = ($editableComments || $entry->getUser() == $currentUser->getId())
259
-                    && !$commentIsRestricted;
260
-
261
-                // Flagging/unflagging can only be done if you can see the comment
262
-                $canFlagThisComment = $canFlag
263
-                    && (
264
-                        (!$entry->getFlagged() && !$commentIsRestricted)
265
-                        || ($entry->getFlagged() && $canUnflag && $commentIsEditable)
266
-                    );
267
-
268
-                $requestLogs[] = array(
269
-                    'type'          => 'comment',
270
-                    'security'      => $entry->getVisibility(),
271
-                    'user'          => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(),
272
-                    'userid'        => $entry->getUser() == -1 ? null : $entry->getUser(),
273
-                    'entry'         => null,
274
-                    'time'          => $entry->getTime(),
275
-                    'canedit'       => $commentIsEditable,
276
-                    'id'            => $entry->getId(),
277
-                    'comment'       => $entry->getComment(),
278
-                    'flagged'       => $entry->getFlagged(),
279
-                    'canflag'       => $canFlagThisComment,
280
-                    'updateversion' => $entry->getUpdateVersion(),
281
-                    'edited'        => $entry->getEdited(),
282
-                    'hidden'        => $commentIsRestricted
283
-                );
284
-            }
285
-
286
-            if ($entry instanceof Log) {
287
-                $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
288
-                $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
289
-
290
-                $entryComment = $entry->getComment();
291
-
292
-                if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
293
-                    $data = unserialize($entry->getComment());
294
-                    /** @var JobQueue $job */
295
-                    $job = JobQueue::getById($data['job'], $database);
296
-                    $requestLogs[] = array(
297
-                        'type'     => 'joblog',
298
-                        'security' => 'user',
299
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
300
-                        'user'     => $entryUser->getUsername(),
301
-                        'entry'    => LogHelper::getLogDescription($entry),
302
-                        'time'     => $entry->getTimestamp(),
303
-                        'canedit'  => false,
304
-                        'id'       => $entry->getId(),
305
-                        'jobId'    => $job->getId(),
306
-                        'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
307
-                    );
308
-                }
309
-                else {
310
-                    $requestLogs[] = array(
311
-                        'type'     => 'log',
312
-                        'security' => 'user',
313
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
314
-                        'user'     => $entryUser->getUsername(),
315
-                        'entry'    => LogHelper::getLogDescription($entry),
316
-                        'time'     => $entry->getTimestamp(),
317
-                        'canedit'  => false,
318
-                        'id'       => $entry->getId(),
319
-                        'comment'  => $entryComment,
320
-                    );
321
-                }
322
-            }
323
-        }
324
-
325
-        $this->addJs("/api.php?action=users&targetVariable=typeaheaddata");
326
-
327
-        $this->assign("requestLogs", $requestLogs);
328
-    }
329
-
330
-    /**
331
-     * @param Request $request
332
-     */
333
-    protected function setupUsernameData(Request $request)
334
-    {
335
-        $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
336
-
337
-        $this->assign('requestIsBlacklisted', $blacklistData !== false);
338
-        $this->assign('requestBlacklist', $blacklistData);
339
-
340
-        try {
341
-            $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
342
-        }
343
-        catch (Exception $ex) {
344
-            $spoofs = $ex->getMessage();
345
-        }
346
-
347
-        $this->assign("spoofs", $spoofs);
348
-    }
349
-
350
-    private function setupCreationTypes(User $user)
351
-    {
352
-        $this->assign('allowWelcomeSkip', false);
353
-        $this->assign('forceWelcomeSkip', false);
354
-
355
-        $database = $this->getDatabase();
356
-        $preferenceManager = PreferenceManager::getForCurrent($database);
357
-
358
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
359
-
360
-        $welcomeTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE);
361
-
362
-        if ($welcomeTemplate != null) {
363
-            $this->assign('allowWelcomeSkip', true);
364
-
365
-            if (!$oauth->canWelcome()) {
366
-                $this->assign('forceWelcomeSkip', true);
367
-            }
368
-        }
369
-
370
-        // test credentials
371
-        $canManualCreate = $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation');
372
-        $canOauthCreate = $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation');
373
-        $canBotCreate = $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation');
374
-
375
-        $this->assign('canManualCreate', $canManualCreate);
376
-        $this->assign('canOauthCreate', $canOauthCreate);
377
-        $this->assign('canBotCreate', $canBotCreate);
378
-
379
-        // show/hide the type radio buttons
380
-        $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1;
381
-
382
-        $creationModePreference = $preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE);
383
-        if (!$this->barrierTest($creationModePreference, $user, 'RequestCreation')) {
384
-            // user is not allowed to use their default. Force a choice.
385
-            $creationHasChoice = true;
386
-        }
387
-
388
-        $this->assign('creationHasChoice', $creationHasChoice);
389
-
390
-        // determine problems in creation types
391
-        $this->assign('botProblem', false);
392
-        if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) {
393
-            $this->assign('botProblem', true);
394
-        }
395
-
396
-        $this->assign('oauthProblem', false);
397
-        if ($canOauthCreate && !$oauth->canCreateAccount()) {
398
-            $this->assign('oauthProblem', true);
399
-        }
400
-    }
36
+	use RequestData;
37
+
38
+	const STATUS_SYMBOL_OPEN = '&#927';
39
+	const STATUS_SYMBOL_ACCEPTED = '&#x2611';
40
+	const STATUS_SYMBOL_REJECTED = '&#x2612';
41
+
42
+	/**
43
+	 * Main function for this page, when no specific actions are called.
44
+	 * @throws ApplicationLogicException
45
+	 */
46
+	protected function main()
47
+	{
48
+		// set up csrf protection
49
+		$this->assignCSRFToken();
50
+
51
+		// get some useful objects
52
+		$database = $this->getDatabase();
53
+		$request = $this->getRequest($database, WebRequest::getInt('id'));
54
+		$config = $this->getSiteConfiguration();
55
+		$currentUser = User::getCurrent($database);
56
+
57
+		// FIXME: domains!
58
+		/** @var Domain $domain */
59
+		$domain = Domain::getById(1, $this->getDatabase());
60
+		$this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
61
+
62
+		// Shows a page if the email is not confirmed.
63
+		if ($request->getEmailConfirm() !== 'Confirmed') {
64
+			// Show a banner if the user can manually confirm the request
65
+			$viewConfirm = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageManuallyConfirm::class);
66
+
67
+			// If the request is purged, there's nothing to confirm!
68
+			if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
69
+				$viewConfirm = false;
70
+			}
71
+
72
+			// Render
73
+			$this->setTemplate("view-request/not-confirmed.tpl");
74
+			$this->assign("requestId", $request->getId());
75
+			$this->assign("requestVersion", $request->getUpdateVersion());
76
+			$this->assign('canViewConfirmButton', $viewConfirm);
77
+
78
+			// Make sure to return, to prevent the leaking of other information.
79
+			return;
80
+		}
81
+
82
+		$this->setupBasicData($request, $config);
83
+
84
+		$this->setupUsernameData($request);
85
+
86
+		$this->setupTitle($request);
87
+
88
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
89
+		$this->setupGeneralData($database);
90
+
91
+		$this->assign('requestDataCleared', false);
92
+		if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
93
+			$this->assign('requestDataCleared', true);
94
+		}
95
+
96
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
97
+
98
+		$this->setupCreationTypes($currentUser);
99
+
100
+		$this->setupLogData($request, $database, $allowedPrivateData);
101
+
102
+		$this->addJs("/api.php?action=templates&targetVariable=templateconfirms");
103
+
104
+		$this->assign('showRevealLink', false);
105
+		if ($request->getReserved() === $currentUser->getId() ||
106
+			$this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
107
+		) {
108
+			$this->assign('showRevealLink', true);
109
+			$this->assign('revealHash', $request->getRevealHash());
110
+		}
111
+
112
+		$this->assign('canSeeRelatedRequests', false);
113
+		if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) {
114
+			$this->setupRelatedRequests($request, $config, $database);
115
+		}
116
+
117
+		$this->assign('canCreateLocalAccount', $this->barrierTest('createLocalAccount', $currentUser, 'RequestData'));
118
+
119
+		$closureDate = $request->getClosureDate();
120
+		$date = new DateTime();
121
+		$date->modify("-7 days");
122
+		if ($request->getStatus() == "Closed" && $closureDate < $date) {
123
+			$this->assign('isOldRequest', true);
124
+		}
125
+		$this->assign('canResetOldRequest', $this->barrierTest('reopenOldRequest', $currentUser, 'RequestData'));
126
+		$this->assign('canResetPurgedRequest', $this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData'));
127
+
128
+		$this->assign('requestEmailSent', $request->getEmailSent());
129
+
130
+		if ($allowedPrivateData) {
131
+			$this->setTemplate('view-request/main-with-data.tpl');
132
+			$this->setupPrivateData($request, $config);
133
+			$this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
134
+			$this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
135
+
136
+			if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
137
+				$this->setTemplate('view-request/main-with-checkuser-data.tpl');
138
+				$this->setupCheckUserData($request);
139
+			}
140
+		}
141
+		else {
142
+			$this->setTemplate('view-request/main.tpl');
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * @param Request $request
148
+	 */
149
+	protected function setupTitle(Request $request)
150
+	{
151
+		$statusSymbol = self::STATUS_SYMBOL_OPEN;
152
+		if ($request->getStatus() === RequestStatus::CLOSED) {
153
+			if ($request->getWasCreated()) {
154
+				$statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
155
+			}
156
+			else {
157
+				$statusSymbol = self::STATUS_SYMBOL_REJECTED;
158
+			}
159
+		}
160
+
161
+		$this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
162
+	}
163
+
164
+	/**
165
+	 * Sets up data unrelated to the request, such as the email template information
166
+	 *
167
+	 * @param PdoDatabase $database
168
+	 */
169
+	protected function setupGeneralData(PdoDatabase $database)
170
+	{
171
+		$this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
172
+
173
+		// FIXME: domains
174
+		/** @var Domain $domain */
175
+		$domain = Domain::getById(1, $database);
176
+		$this->assign('defaultRequestState', RequestQueue::getDefaultQueue($database, 1)->getApiName());
177
+		$this->assign('activeRequestQueues', RequestQueue::getEnabledQueues($database));
178
+
179
+		/** @var EmailTemplate $createdTemplate */
180
+		$createdTemplate = EmailTemplate::getById($domain->getDefaultClose(), $database);
181
+
182
+		$this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
183
+		$this->assign('createdId', $createdTemplate->getId());
184
+		$this->assign('createdName', $createdTemplate->getName());
185
+
186
+		$preferenceManager = PreferenceManager::getForCurrent($database);
187
+		$skipJsAborts = $preferenceManager->getPreference(PreferenceManager::PREF_SKIP_JS_ABORT);
188
+		$preferredCreationMode = (int)$preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE);
189
+		$this->assign('skipJsAborts', $skipJsAborts);
190
+		$this->assign('preferredCreationMode', $preferredCreationMode);
191
+
192
+		$createReasons = EmailTemplate::getActiveNonpreloadTemplates(
193
+			EmailTemplate::ACTION_CREATED,
194
+			$database,
195
+			$domain->getId(),
196
+			$domain->getDefaultClose());
197
+		$this->assign("createReasons", $createReasons);
198
+
199
+		$declineReasons = EmailTemplate::getActiveNonpreloadTemplates(
200
+			EmailTemplate::ACTION_NOT_CREATED,
201
+			$database,
202
+			$domain->getId());
203
+		$this->assign("declineReasons", $declineReasons);
204
+
205
+		$allCreateReasons = EmailTemplate::getAllActiveTemplates(
206
+			EmailTemplate::ACTION_CREATED,
207
+			$database,
208
+			$domain->getId());
209
+		$this->assign("allCreateReasons", $allCreateReasons);
210
+
211
+		$allDeclineReasons = EmailTemplate::getAllActiveTemplates(
212
+			EmailTemplate::ACTION_NOT_CREATED,
213
+			$database,
214
+			$domain->getId());
215
+		$this->assign("allDeclineReasons", $allDeclineReasons);
216
+
217
+		$allOtherReasons = EmailTemplate::getAllActiveTemplates(
218
+			false,
219
+			$database,
220
+			$domain->getId());
221
+		$this->assign("allOtherReasons", $allOtherReasons);
222
+	}
223
+
224
+	private function setupLogData(Request $request, PdoDatabase $database, bool $allowedPrivateData)
225
+	{
226
+		$currentUser = User::getCurrent($database);
227
+
228
+		$logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
229
+		$requestLogs = array();
230
+
231
+		/** @var User[] $nameCache */
232
+		$nameCache = array();
233
+
234
+		$editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
235
+
236
+		$canFlag = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class);
237
+		$canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class);
238
+
239
+		/** @var Log|Comment $entry */
240
+		foreach ($logs as $entry) {
241
+			// both log and comment have a 'user' field
242
+			if (!array_key_exists($entry->getUser(), $nameCache)) {
243
+				$entryUser = User::getById($entry->getUser(), $database);
244
+				$nameCache[$entry->getUser()] = $entryUser;
245
+			}
246
+
247
+			if ($entry instanceof Comment) {
248
+				// Determine if the comment contains private information.
249
+				// Private defined as flagged or restricted visibility, but only when the user isn't allowed
250
+				// to see private data
251
+				$commentIsRestricted =
252
+					($entry->getFlagged()
253
+						|| $entry->getVisibility() == 'admin' || $entry->getVisibility() == 'checkuser')
254
+					&& !$allowedPrivateData;
255
+
256
+				// Only allow comment editing if the user is able to edit comments or this is the user's own comment,
257
+				// but only when they're allowed to see the comment itself.
258
+				$commentIsEditable = ($editableComments || $entry->getUser() == $currentUser->getId())
259
+					&& !$commentIsRestricted;
260
+
261
+				// Flagging/unflagging can only be done if you can see the comment
262
+				$canFlagThisComment = $canFlag
263
+					&& (
264
+						(!$entry->getFlagged() && !$commentIsRestricted)
265
+						|| ($entry->getFlagged() && $canUnflag && $commentIsEditable)
266
+					);
267
+
268
+				$requestLogs[] = array(
269
+					'type'          => 'comment',
270
+					'security'      => $entry->getVisibility(),
271
+					'user'          => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(),
272
+					'userid'        => $entry->getUser() == -1 ? null : $entry->getUser(),
273
+					'entry'         => null,
274
+					'time'          => $entry->getTime(),
275
+					'canedit'       => $commentIsEditable,
276
+					'id'            => $entry->getId(),
277
+					'comment'       => $entry->getComment(),
278
+					'flagged'       => $entry->getFlagged(),
279
+					'canflag'       => $canFlagThisComment,
280
+					'updateversion' => $entry->getUpdateVersion(),
281
+					'edited'        => $entry->getEdited(),
282
+					'hidden'        => $commentIsRestricted
283
+				);
284
+			}
285
+
286
+			if ($entry instanceof Log) {
287
+				$invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
288
+				$entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
289
+
290
+				$entryComment = $entry->getComment();
291
+
292
+				if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
293
+					$data = unserialize($entry->getComment());
294
+					/** @var JobQueue $job */
295
+					$job = JobQueue::getById($data['job'], $database);
296
+					$requestLogs[] = array(
297
+						'type'     => 'joblog',
298
+						'security' => 'user',
299
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
300
+						'user'     => $entryUser->getUsername(),
301
+						'entry'    => LogHelper::getLogDescription($entry),
302
+						'time'     => $entry->getTimestamp(),
303
+						'canedit'  => false,
304
+						'id'       => $entry->getId(),
305
+						'jobId'    => $job->getId(),
306
+						'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
307
+					);
308
+				}
309
+				else {
310
+					$requestLogs[] = array(
311
+						'type'     => 'log',
312
+						'security' => 'user',
313
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
314
+						'user'     => $entryUser->getUsername(),
315
+						'entry'    => LogHelper::getLogDescription($entry),
316
+						'time'     => $entry->getTimestamp(),
317
+						'canedit'  => false,
318
+						'id'       => $entry->getId(),
319
+						'comment'  => $entryComment,
320
+					);
321
+				}
322
+			}
323
+		}
324
+
325
+		$this->addJs("/api.php?action=users&targetVariable=typeaheaddata");
326
+
327
+		$this->assign("requestLogs", $requestLogs);
328
+	}
329
+
330
+	/**
331
+	 * @param Request $request
332
+	 */
333
+	protected function setupUsernameData(Request $request)
334
+	{
335
+		$blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
336
+
337
+		$this->assign('requestIsBlacklisted', $blacklistData !== false);
338
+		$this->assign('requestBlacklist', $blacklistData);
339
+
340
+		try {
341
+			$spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
342
+		}
343
+		catch (Exception $ex) {
344
+			$spoofs = $ex->getMessage();
345
+		}
346
+
347
+		$this->assign("spoofs", $spoofs);
348
+	}
349
+
350
+	private function setupCreationTypes(User $user)
351
+	{
352
+		$this->assign('allowWelcomeSkip', false);
353
+		$this->assign('forceWelcomeSkip', false);
354
+
355
+		$database = $this->getDatabase();
356
+		$preferenceManager = PreferenceManager::getForCurrent($database);
357
+
358
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
359
+
360
+		$welcomeTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE);
361
+
362
+		if ($welcomeTemplate != null) {
363
+			$this->assign('allowWelcomeSkip', true);
364
+
365
+			if (!$oauth->canWelcome()) {
366
+				$this->assign('forceWelcomeSkip', true);
367
+			}
368
+		}
369
+
370
+		// test credentials
371
+		$canManualCreate = $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation');
372
+		$canOauthCreate = $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation');
373
+		$canBotCreate = $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation');
374
+
375
+		$this->assign('canManualCreate', $canManualCreate);
376
+		$this->assign('canOauthCreate', $canOauthCreate);
377
+		$this->assign('canBotCreate', $canBotCreate);
378
+
379
+		// show/hide the type radio buttons
380
+		$creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1;
381
+
382
+		$creationModePreference = $preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE);
383
+		if (!$this->barrierTest($creationModePreference, $user, 'RequestCreation')) {
384
+			// user is not allowed to use their default. Force a choice.
385
+			$creationHasChoice = true;
386
+		}
387
+
388
+		$this->assign('creationHasChoice', $creationHasChoice);
389
+
390
+		// determine problems in creation types
391
+		$this->assign('botProblem', false);
392
+		if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) {
393
+			$this->assign('botProblem', true);
394
+		}
395
+
396
+		$this->assign('oauthProblem', false);
397
+		if ($canOauthCreate && !$oauth->canCreateAccount()) {
398
+			$this->assign('oauthProblem', true);
399
+		}
400
+	}
401 401
 }
Please login to merge, or discard this patch.
includes/Pages/PageDomainSwitch.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -19,48 +19,48 @@
 block discarded – undo
19 19
 
20 20
 class PageDomainSwitch extends InternalPageBase
21 21
 {
22
-    /**
23
-     * @inheritDoc
24
-     */
25
-    protected function main()
26
-    {
27
-        if (!WebRequest::wasPosted()) {
28
-            $this->redirect('/');
22
+	/**
23
+	 * @inheritDoc
24
+	 */
25
+	protected function main()
26
+	{
27
+		if (!WebRequest::wasPosted()) {
28
+			$this->redirect('/');
29 29
 
30
-            return;
31
-        }
30
+			return;
31
+		}
32 32
 
33
-        $database = $this->getDatabase();
34
-        $currentUser = User::getCurrent($database);
33
+		$database = $this->getDatabase();
34
+		$currentUser = User::getCurrent($database);
35 35
 
36
-        /** @var Domain|false $newDomain */
37
-        $newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database);
36
+		/** @var Domain|false $newDomain */
37
+		$newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database);
38 38
 
39
-        if ($newDomain === false) {
40
-            $this->redirect('/');
39
+		if ($newDomain === false) {
40
+			$this->redirect('/');
41 41
 
42
-            return;
43
-        }
42
+			return;
43
+		}
44 44
 
45
-        try {
46
-            $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47
-        }
48
-        catch(DomainSwitchNotAllowedException $ex){
49
-            throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50
-        }
45
+		try {
46
+			$this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47
+		}
48
+		catch(DomainSwitchNotAllowedException $ex){
49
+			throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50
+		}
51 51
 
52
-        // try to stay on the same page if possible.
53
-        // This only checks basic ACLs and not domain privileges, so this may still result in a 403.
52
+		// try to stay on the same page if possible.
53
+		// This only checks basic ACLs and not domain privileges, so this may still result in a 403.
54 54
 
55
-        $referrer = WebRequest::postString('referrer');
56
-        $priorPath = explode('/', $referrer);
57
-        $router = new RequestRouter();
58
-        $route = $router->getRouteFromPath($priorPath);
55
+		$referrer = WebRequest::postString('referrer');
56
+		$priorPath = explode('/', $referrer);
57
+		$router = new RequestRouter();
58
+		$route = $router->getRouteFromPath($priorPath);
59 59
 
60
-        if ($this->barrierTest($route[1], $currentUser, $route[0])) {
61
-            $this->redirect('/' . $referrer);
62
-        } else {
63
-            $this->redirect('/');
64
-        }
65
-    }
60
+		if ($this->barrierTest($route[1], $currentUser, $route[0])) {
61
+			$this->redirect('/' . $referrer);
62
+		} else {
63
+			$this->redirect('/');
64
+		}
65
+	}
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageUserReactivate.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -22,58 +22,58 @@
 block discarded – undo
22 22
 
23 23
 class PageUserReactivate extends InternalPageBase
24 24
 {
25
-    use LogEntryLookup;
25
+	use LogEntryLookup;
26 26
 
27
-    /**
28
-     * @throws ApplicationLogicException
29
-     * @throws Exception
30
-     */
31
-    protected function main()
32
-    {
33
-        $db = $this->getDatabase();
34
-        $currentUser = User::getCurrent($db);
27
+	/**
28
+	 * @throws ApplicationLogicException
29
+	 * @throws Exception
30
+	 */
31
+	protected function main()
32
+	{
33
+		$db = $this->getDatabase();
34
+		$currentUser = User::getCurrent($db);
35 35
 
36
-        // *Only* deactivated users should be able to access this.
37
-        // Redirect anyone else away.
38
-        if (!$currentUser->isDeactivated()) {
39
-            $this->redirect();
40
-            return;
41
-        }
36
+		// *Only* deactivated users should be able to access this.
37
+		// Redirect anyone else away.
38
+		if (!$currentUser->isDeactivated()) {
39
+			$this->redirect();
40
+			return;
41
+		}
42 42
 
43
-        $ableToAppeal = true;
44
-        $prefs = new PreferenceManager($db, $currentUser->getId(), Domain::getCurrent($db)->getId());
45
-        if ($prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false) {
46
-            $ableToAppeal = false;
47
-        }
43
+		$ableToAppeal = true;
44
+		$prefs = new PreferenceManager($db, $currentUser->getId(), Domain::getCurrent($db)->getId());
45
+		if ($prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false) {
46
+			$ableToAppeal = false;
47
+		}
48 48
 
49
-        if (WebRequest::wasPosted()) {
50
-            $this->validateCSRFToken();
49
+		if (WebRequest::wasPosted()) {
50
+			$this->validateCSRFToken();
51 51
 
52
-            $reason = WebRequest::postString('reason');
53
-            $updateVersion = WebRequest::postInt('updateVersion');
52
+			$reason = WebRequest::postString('reason');
53
+			$updateVersion = WebRequest::postInt('updateVersion');
54 54
 
55
-            if (!$ableToAppeal) {
56
-                throw new ApplicationLogicException('Appeal is disabled');
57
-            }
55
+			if (!$ableToAppeal) {
56
+				throw new ApplicationLogicException('Appeal is disabled');
57
+			}
58 58
 
59
-            if ($reason === null || trim($reason) === '') {
60
-                throw new ApplicationLogicException('The reason field cannot be empty.');
61
-            }
59
+			if ($reason === null || trim($reason) === '') {
60
+				throw new ApplicationLogicException('The reason field cannot be empty.');
61
+			}
62 62
 
63
-            Logger::requestedReactivation($db, $currentUser, $reason);
64
-            $currentUser->setStatus(User::STATUS_NEW);
65
-            $currentUser->setUpdateVersion($updateVersion);
66
-            $currentUser->save();
63
+			Logger::requestedReactivation($db, $currentUser, $reason);
64
+			$currentUser->setStatus(User::STATUS_NEW);
65
+			$currentUser->setUpdateVersion($updateVersion);
66
+			$currentUser->save();
67 67
 
68
-            SessionAlert::success('Reactivation request has been saved. Please wait for a response from the tool admin team.');
69
-            $this->redirect();
70
-        }
71
-        else {
72
-            $this->assignCSRFToken();
73
-            $this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $db));
74
-            $this->assign('updateVersion', $currentUser->getUpdateVersion());
75
-            $this->assign('ableToAppeal', $ableToAppeal);
76
-            $this->setTemplate('reactivate.tpl');
77
-        }
78
-    }
68
+			SessionAlert::success('Reactivation request has been saved. Please wait for a response from the tool admin team.');
69
+			$this->redirect();
70
+		}
71
+		else {
72
+			$this->assignCSRFToken();
73
+			$this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $db));
74
+			$this->assign('updateVersion', $currentUser->getUpdateVersion());
75
+			$this->assign('ableToAppeal', $ableToAppeal);
76
+			$this->setTemplate('reactivate.tpl');
77
+		}
78
+	}
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PagePreferences.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -21,170 +21,170 @@
 block discarded – undo
21 21
 
22 22
 class PagePreferences extends InternalPageBase
23 23
 {
24
-    /**
25
-     * Main function for this page, when no specific actions are called.
26
-     * @return void
27
-     */
28
-    protected function main()
29
-    {
30
-        $this->setHtmlTitle('Preferences');
31
-
32
-        $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
33
-        $database = $this->getDatabase();
34
-        $user = User::getCurrent($database);
35
-        $preferencesManager = PreferenceManager::getForCurrent($database);
36
-
37
-        // Dual mode
38
-        if (WebRequest::wasPosted()) {
39
-            $this->validateCSRFToken();
40
-
41
-            $this->setPreference($preferencesManager,PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature');
42
-            $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', WebRequest::postBoolean('skipJsAbort') ? 1 : 0);
43
-            $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', WebRequest::postBoolean('showQueueHelp') ? 1 : 0);
44
-            $this->setCreationMode($user, $preferencesManager);
45
-            $this->setSkin($preferencesManager);
46
-            $preferencesManager->setGlobalPreference(PreferenceManager::PREF_DEFAULT_DOMAIN, WebRequest::postInt('defaultDomain'));
47
-
48
-            $email = WebRequest::postEmail('email');
49
-            if ($email !== null) {
50
-                $user->setEmail($email);
51
-            }
52
-
53
-            $user->save();
54
-            SessionAlert::success("Preferences updated!");
55
-
56
-            if ($this->barrierTest(RoleConfigurationBase::MAIN, $user, PageMain::class)) {
57
-                $this->redirect('');
58
-            }
59
-            else {
60
-                $this->redirect('preferences');
61
-            }
62
-        }
63
-        else {
64
-            $this->assignCSRFToken();
65
-            $this->setTemplate('preferences/prefs.tpl');
66
-
67
-            // FIXME: domains!
68
-            /** @var Domain $domain */
69
-            $domain = Domain::getById(1, $this->getDatabase());
70
-            $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
71
-
72
-            $this->assign("enforceOAuth", $enforceOAuth);
73
-
74
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature', false);
75
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_CREATION_MODE, 'creationMode', false);
76
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin', true);
77
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', false);
78
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', false, true);
79
-            $this->assignPreference($preferencesManager, PreferenceManager::PREF_DEFAULT_DOMAIN, 'defaultDomain', true);
80
-
81
-            $this->assign('canManualCreate',
82
-                $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
83
-            $this->assign('canOauthCreate',
84
-                $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
85
-            $this->assign('canBotCreate',
86
-                $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
87
-
88
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
89
-                $this->getSiteConfiguration());
90
-            $this->assign('oauth', $oauth);
91
-
92
-            $identity = null;
93
-            if ($oauth->isFullyLinked()) {
94
-                $identity = $oauth->getIdentity(true);
95
-            }
96
-
97
-            $this->assign('identity', $identity);
98
-            $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
99
-        }
100
-    }
101
-
102
-    private function assignPreference(
103
-        PreferenceManager $preferencesManager,
104
-        string $preference,
105
-        string $fieldName,
106
-        bool $defaultGlobal,
107
-        $defaultValue = null
108
-    ): void {
109
-        $this->assign($fieldName, $preferencesManager->getPreference($preference) ?? $defaultValue);
110
-        $this->assign($fieldName . 'Global', $preferencesManager->isGlobalPreference($preference) ?? $defaultGlobal);
111
-    }
112
-
113
-    private function setPreferenceWithValue(
114
-        PreferenceManager $preferencesManager,
115
-        string $preferenceName,
116
-        string $fieldName,
117
-        $value
118
-    ): void {
119
-        $globalDefinition = WebRequest::postBoolean($fieldName . 'Global');
120
-        if ($globalDefinition) {
121
-            $preferencesManager->setGlobalPreference($preferenceName, $value);
122
-        }
123
-        else {
124
-            $preferencesManager->setLocalPreference($preferenceName, $value);
125
-        }
126
-    }
127
-
128
-    private function setPreference(
129
-        PreferenceManager $preferencesManager,
130
-        string $preferenceName,
131
-        string $fieldName
132
-    ): void {
133
-        $this->setPreferenceWithValue($preferencesManager, $preferenceName, $fieldName, WebRequest::postString($fieldName));
134
-    }
135
-
136
-    protected function refreshOAuth()
137
-    {
138
-        if (!WebRequest::wasPosted()) {
139
-            $this->redirect('preferences');
140
-
141
-            return;
142
-        }
143
-
144
-        $database = $this->getDatabase();
145
-        $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(),
146
-            $this->getSiteConfiguration());
147
-
148
-        // token is for old consumer, run through the approval workflow again
149
-        if ($oauth->getIdentity(true)->getAudience() !== $this->getSiteConfiguration()->getOAuthConsumerToken()) {
150
-            $authoriseUrl = $oauth->getRequestToken();
151
-            $this->redirectUrl($authoriseUrl);
152
-
153
-            return;
154
-        }
155
-
156
-        if ($oauth->isFullyLinked()) {
157
-            $oauth->refreshIdentity();
158
-        }
159
-
160
-        $this->redirect('preferences');
161
-
162
-        return;
163
-    }
164
-
165
-    private function setCreationMode(User $user, PreferenceManager $preferenceManager)
166
-    {
167
-        // if the user is selecting a creation mode that they are not allowed, do nothing.
168
-        // this has the side effect of allowing them to keep a selected mode that either has been changed for them,
169
-        // or that they have kept from when they previously had certain access.
170
-        // This setting is only settable locally, as ACLs may change between domains.
171
-        $creationMode = WebRequest::postInt('creationMode');
172
-
173
-        if ($creationMode === null) {
174
-            return;
175
-        }
176
-
177
-        if ($this->barrierTest($creationMode, $user, 'RequestCreation')) {
178
-            $preferenceManager->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postString('creationMode'));
179
-        }
180
-    }
181
-
182
-    private function setSkin(PreferenceManager $preferencesManager): void
183
-    {
184
-        $newSkin = WebRequest::postString('skin');
185
-        $allowedSkins = ['main', 'alt', 'auto'];
186
-        if (in_array($newSkin, $allowedSkins)) {
187
-            $this->setPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin');
188
-        }
189
-    }
24
+	/**
25
+	 * Main function for this page, when no specific actions are called.
26
+	 * @return void
27
+	 */
28
+	protected function main()
29
+	{
30
+		$this->setHtmlTitle('Preferences');
31
+
32
+		$enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
33
+		$database = $this->getDatabase();
34
+		$user = User::getCurrent($database);
35
+		$preferencesManager = PreferenceManager::getForCurrent($database);
36
+
37
+		// Dual mode
38
+		if (WebRequest::wasPosted()) {
39
+			$this->validateCSRFToken();
40
+
41
+			$this->setPreference($preferencesManager,PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature');
42
+			$this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', WebRequest::postBoolean('skipJsAbort') ? 1 : 0);
43
+			$this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', WebRequest::postBoolean('showQueueHelp') ? 1 : 0);
44
+			$this->setCreationMode($user, $preferencesManager);
45
+			$this->setSkin($preferencesManager);
46
+			$preferencesManager->setGlobalPreference(PreferenceManager::PREF_DEFAULT_DOMAIN, WebRequest::postInt('defaultDomain'));
47
+
48
+			$email = WebRequest::postEmail('email');
49
+			if ($email !== null) {
50
+				$user->setEmail($email);
51
+			}
52
+
53
+			$user->save();
54
+			SessionAlert::success("Preferences updated!");
55
+
56
+			if ($this->barrierTest(RoleConfigurationBase::MAIN, $user, PageMain::class)) {
57
+				$this->redirect('');
58
+			}
59
+			else {
60
+				$this->redirect('preferences');
61
+			}
62
+		}
63
+		else {
64
+			$this->assignCSRFToken();
65
+			$this->setTemplate('preferences/prefs.tpl');
66
+
67
+			// FIXME: domains!
68
+			/** @var Domain $domain */
69
+			$domain = Domain::getById(1, $this->getDatabase());
70
+			$this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
71
+
72
+			$this->assign("enforceOAuth", $enforceOAuth);
73
+
74
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature', false);
75
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_CREATION_MODE, 'creationMode', false);
76
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin', true);
77
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', false);
78
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', false, true);
79
+			$this->assignPreference($preferencesManager, PreferenceManager::PREF_DEFAULT_DOMAIN, 'defaultDomain', true);
80
+
81
+			$this->assign('canManualCreate',
82
+				$this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
83
+			$this->assign('canOauthCreate',
84
+				$this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
85
+			$this->assign('canBotCreate',
86
+				$this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
87
+
88
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
89
+				$this->getSiteConfiguration());
90
+			$this->assign('oauth', $oauth);
91
+
92
+			$identity = null;
93
+			if ($oauth->isFullyLinked()) {
94
+				$identity = $oauth->getIdentity(true);
95
+			}
96
+
97
+			$this->assign('identity', $identity);
98
+			$this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
99
+		}
100
+	}
101
+
102
+	private function assignPreference(
103
+		PreferenceManager $preferencesManager,
104
+		string $preference,
105
+		string $fieldName,
106
+		bool $defaultGlobal,
107
+		$defaultValue = null
108
+	): void {
109
+		$this->assign($fieldName, $preferencesManager->getPreference($preference) ?? $defaultValue);
110
+		$this->assign($fieldName . 'Global', $preferencesManager->isGlobalPreference($preference) ?? $defaultGlobal);
111
+	}
112
+
113
+	private function setPreferenceWithValue(
114
+		PreferenceManager $preferencesManager,
115
+		string $preferenceName,
116
+		string $fieldName,
117
+		$value
118
+	): void {
119
+		$globalDefinition = WebRequest::postBoolean($fieldName . 'Global');
120
+		if ($globalDefinition) {
121
+			$preferencesManager->setGlobalPreference($preferenceName, $value);
122
+		}
123
+		else {
124
+			$preferencesManager->setLocalPreference($preferenceName, $value);
125
+		}
126
+	}
127
+
128
+	private function setPreference(
129
+		PreferenceManager $preferencesManager,
130
+		string $preferenceName,
131
+		string $fieldName
132
+	): void {
133
+		$this->setPreferenceWithValue($preferencesManager, $preferenceName, $fieldName, WebRequest::postString($fieldName));
134
+	}
135
+
136
+	protected function refreshOAuth()
137
+	{
138
+		if (!WebRequest::wasPosted()) {
139
+			$this->redirect('preferences');
140
+
141
+			return;
142
+		}
143
+
144
+		$database = $this->getDatabase();
145
+		$oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(),
146
+			$this->getSiteConfiguration());
147
+
148
+		// token is for old consumer, run through the approval workflow again
149
+		if ($oauth->getIdentity(true)->getAudience() !== $this->getSiteConfiguration()->getOAuthConsumerToken()) {
150
+			$authoriseUrl = $oauth->getRequestToken();
151
+			$this->redirectUrl($authoriseUrl);
152
+
153
+			return;
154
+		}
155
+
156
+		if ($oauth->isFullyLinked()) {
157
+			$oauth->refreshIdentity();
158
+		}
159
+
160
+		$this->redirect('preferences');
161
+
162
+		return;
163
+	}
164
+
165
+	private function setCreationMode(User $user, PreferenceManager $preferenceManager)
166
+	{
167
+		// if the user is selecting a creation mode that they are not allowed, do nothing.
168
+		// this has the side effect of allowing them to keep a selected mode that either has been changed for them,
169
+		// or that they have kept from when they previously had certain access.
170
+		// This setting is only settable locally, as ACLs may change between domains.
171
+		$creationMode = WebRequest::postInt('creationMode');
172
+
173
+		if ($creationMode === null) {
174
+			return;
175
+		}
176
+
177
+		if ($this->barrierTest($creationMode, $user, 'RequestCreation')) {
178
+			$preferenceManager->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postString('creationMode'));
179
+		}
180
+	}
181
+
182
+	private function setSkin(PreferenceManager $preferencesManager): void
183
+	{
184
+		$newSkin = WebRequest::postString('skin');
185
+		$allowedSkins = ['main', 'alt', 'auto'];
186
+		if (in_array($newSkin, $allowedSkins)) {
187
+			$this->setPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin');
188
+		}
189
+	}
190 190
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsMain.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -15,102 +15,102 @@
 block discarded – undo
15 15
 
16 16
 class StatsMain extends InternalPageBase
17 17
 {
18
-    public function main()
19
-    {
20
-        $this->setHtmlTitle('Statistics');
21
-
22
-        $this->assign('statsPageTitle', 'Account Creation Statistics');
23
-
24
-        $statsPages = array(
25
-            'fastCloses'       => 'Requests closed less than 30 seconds after reservation in the past 3 months',
26
-            'inactiveUsers'    => 'Inactive tool users',
27
-            'monthlyStats'     => 'Monthly Statistics',
28
-            'reservedRequests' => 'All currently reserved requests',
29
-            'templateStats'    => 'Template Stats',
30
-            'topCreators'      => 'Top Account Creators',
31
-            'users'            => 'Account Creation Tool users',
32
-        );
33
-
34
-        $this->generateSmallStatsTable();
35
-
36
-        $this->assign('statsPages', $statsPages);
37
-
38
-        $graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month');
39
-        $this->assign('graphList', $graphList);
40
-
41
-        $this->setTemplate('statistics/main.tpl');
42
-    }
43
-
44
-    /**
45
-     * Gets the relevant statistics from the database for the small statistics table
46
-     */
47
-    private function generateSmallStatsTable()
48
-    {
49
-        $database = $this->getDatabase();
50
-        $requestsQuery = <<<'SQL'
18
+	public function main()
19
+	{
20
+		$this->setHtmlTitle('Statistics');
21
+
22
+		$this->assign('statsPageTitle', 'Account Creation Statistics');
23
+
24
+		$statsPages = array(
25
+			'fastCloses'       => 'Requests closed less than 30 seconds after reservation in the past 3 months',
26
+			'inactiveUsers'    => 'Inactive tool users',
27
+			'monthlyStats'     => 'Monthly Statistics',
28
+			'reservedRequests' => 'All currently reserved requests',
29
+			'templateStats'    => 'Template Stats',
30
+			'topCreators'      => 'Top Account Creators',
31
+			'users'            => 'Account Creation Tool users',
32
+		);
33
+
34
+		$this->generateSmallStatsTable();
35
+
36
+		$this->assign('statsPages', $statsPages);
37
+
38
+		$graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month');
39
+		$this->assign('graphList', $graphList);
40
+
41
+		$this->setTemplate('statistics/main.tpl');
42
+	}
43
+
44
+	/**
45
+	 * Gets the relevant statistics from the database for the small statistics table
46
+	 */
47
+	private function generateSmallStatsTable()
48
+	{
49
+		$database = $this->getDatabase();
50
+		$requestsQuery = <<<'SQL'
51 51
 SELECT COUNT(*) FROM request WHERE status = :status AND queue = :queue AND emailconfirm = 'Confirmed';
52 52
 SQL;
53
-        $requestsStatement = $database->prepare($requestsQuery);
53
+		$requestsStatement = $database->prepare($requestsQuery);
54 54
 
55
-        $requestStateData = array();
55
+		$requestStateData = array();
56 56
 
57
-        foreach (RequestQueue::getEnabledQueues($database) as $queue) {
58
-            $requestsStatement->execute(array(
59
-                ':status' => RequestStatus::OPEN,
60
-                ':queue'  => $queue->getId(),
61
-            ));
62
-            $requestCount = $requestsStatement->fetchColumn();
63
-            $requestsStatement->closeCursor();
64
-            $headerText = $queue->getHeader();
65
-            $requestStateData[$headerText] = $requestCount;
66
-        }
57
+		foreach (RequestQueue::getEnabledQueues($database) as $queue) {
58
+			$requestsStatement->execute(array(
59
+				':status' => RequestStatus::OPEN,
60
+				':queue'  => $queue->getId(),
61
+			));
62
+			$requestCount = $requestsStatement->fetchColumn();
63
+			$requestsStatement->closeCursor();
64
+			$headerText = $queue->getHeader();
65
+			$requestStateData[$headerText] = $requestCount;
66
+		}
67 67
 
68
-        $this->assign('requestCountData', $requestStateData);
68
+		$this->assign('requestCountData', $requestStateData);
69 69
 
70
-        // Unconfirmed requests
71
-        $unconfirmedStatement = $database->query(<<<SQL
70
+		// Unconfirmed requests
71
+		$unconfirmedStatement = $database->query(<<<SQL
72 72
 SELECT COUNT(*) FROM request WHERE emailconfirm != 'Confirmed' AND emailconfirm != '';
73 73
 SQL
74
-        );
75
-        $unconfirmed = $unconfirmedStatement->fetchColumn();
76
-        $unconfirmedStatement->closeCursor();
77
-        $this->assign('statsUnconfirmed', $unconfirmed);
78
-
79
-        $userRoleStatement = $database->prepare('SELECT COUNT(*) FROM user INNER JOIN userrole ON user.id = userrole.user WHERE userrole.role = :role AND user.status = \'Active\';');
80
-
81
-        // Admin users
82
-        $userRoleStatement->execute(array(':role' => 'admin'));
83
-        $adminUsers = $userRoleStatement->fetchColumn();
84
-        $userRoleStatement->closeCursor();
85
-        $this->assign('statsAdminUsers', $adminUsers);
86
-
87
-        // Users
88
-        $userRoleStatement->execute(array(':role' => 'user'));
89
-        $users = $userRoleStatement->fetchColumn();
90
-        $userRoleStatement->closeCursor();
91
-        $this->assign('statsUsers', $users);
92
-
93
-        $userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;');
74
+		);
75
+		$unconfirmed = $unconfirmedStatement->fetchColumn();
76
+		$unconfirmedStatement->closeCursor();
77
+		$this->assign('statsUnconfirmed', $unconfirmed);
78
+
79
+		$userRoleStatement = $database->prepare('SELECT COUNT(*) FROM user INNER JOIN userrole ON user.id = userrole.user WHERE userrole.role = :role AND user.status = \'Active\';');
80
+
81
+		// Admin users
82
+		$userRoleStatement->execute(array(':role' => 'admin'));
83
+		$adminUsers = $userRoleStatement->fetchColumn();
84
+		$userRoleStatement->closeCursor();
85
+		$this->assign('statsAdminUsers', $adminUsers);
86
+
87
+		// Users
88
+		$userRoleStatement->execute(array(':role' => 'user'));
89
+		$users = $userRoleStatement->fetchColumn();
90
+		$userRoleStatement->closeCursor();
91
+		$this->assign('statsUsers', $users);
92
+
93
+		$userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;');
94 94
         
95
-        // Deactivated users
96
-        $userStatusStatement->execute(array(':status' => 'Deactivated'));
97
-        $deactivatedUsers = $userStatusStatement->fetchColumn();
98
-        $userStatusStatement->closeCursor();
99
-        $this->assign('statsDeactivatedUsers', $deactivatedUsers);
100
-
101
-        // New users
102
-        $userStatusStatement->execute(array(':status' => 'New'));
103
-        $newUsers = $userStatusStatement->fetchColumn();
104
-        $userStatusStatement->closeCursor();
105
-        $this->assign('statsNewUsers', $newUsers);
106
-
107
-        // Most comments on a request
108
-        $mostCommentsStatement = $database->query(<<<SQL
95
+		// Deactivated users
96
+		$userStatusStatement->execute(array(':status' => 'Deactivated'));
97
+		$deactivatedUsers = $userStatusStatement->fetchColumn();
98
+		$userStatusStatement->closeCursor();
99
+		$this->assign('statsDeactivatedUsers', $deactivatedUsers);
100
+
101
+		// New users
102
+		$userStatusStatement->execute(array(':status' => 'New'));
103
+		$newUsers = $userStatusStatement->fetchColumn();
104
+		$userStatusStatement->closeCursor();
105
+		$this->assign('statsNewUsers', $newUsers);
106
+
107
+		// Most comments on a request
108
+		$mostCommentsStatement = $database->query(<<<SQL
109 109
 SELECT request FROM comment GROUP BY request ORDER BY COUNT(*) DESC LIMIT 1;
110 110
 SQL
111
-        );
112
-        $mostComments = $mostCommentsStatement->fetchColumn();
113
-        $mostCommentsStatement->closeCursor();
114
-        $this->assign('mostComments', $mostComments);
115
-    }
111
+		);
112
+		$mostComments = $mostCommentsStatement->fetchColumn();
113
+		$mostCommentsStatement->closeCursor();
114
+		$this->assign('mostComments', $mostComments);
115
+	}
116 116
 }
Please login to merge, or discard this patch.