Passed
Push — newinternal-releasecandidate ( 40acd0...67549a )
by Simon
10:15
created
includes/ApplicationBase.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -25,155 +25,155 @@
 block discarded – undo
25 25
 
26 26
 abstract class ApplicationBase
27 27
 {
28
-    private $configuration;
29
-
30
-    public function __construct(SiteConfiguration $configuration)
31
-    {
32
-        $this->configuration = $configuration;
33
-    }
34
-
35
-    /**
36
-     * Application entry point.
37
-     *
38
-     * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
-     */
40
-    public function run()
41
-    {
42
-        try {
43
-            if ($this->setupEnvironment()) {
44
-                $this->main();
45
-            }
46
-        }
47
-        catch (Exception $ex) {
48
-            print $ex->getMessage();
49
-        }
50
-        finally {
51
-            $this->cleanupEnvironment();
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Environment setup
57
-     *
58
-     * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
-     * and shut down prematurely.
60
-     *
61
-     * @return bool
62
-     * @throws EnvironmentException
63
-     */
64
-    protected function setupEnvironment()
65
-    {
66
-        $this->setupDatabase();
67
-
68
-        return true;
69
-    }
70
-
71
-    /**
72
-     * @return PdoDatabase
73
-     * @throws EnvironmentException
74
-     * @throws Exception
75
-     */
76
-    protected function setupDatabase()
77
-    {
78
-        // check the schema version
79
-        $database = PdoDatabase::getDatabaseConnection('acc');
80
-
81
-        /** @var int $actualVersion */
82
-        $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
-        if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
-            throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
-        }
86
-
87
-        return $database;
88
-    }
89
-
90
-    /**
91
-     * @return SiteConfiguration
92
-     */
93
-    public function getConfiguration()
94
-    {
95
-        return $this->configuration;
96
-    }
97
-
98
-    /**
99
-     * Main application logic
100
-     * @return void
101
-     */
102
-    abstract protected function main();
103
-
104
-    /**
105
-     * Any cleanup tasks should go here
106
-     *
107
-     * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
-     * This should *only* be for cleaning up, no logic should go here.
109
-     *
110
-     * @return void
111
-     */
112
-    abstract protected function cleanupEnvironment();
113
-
114
-    /**
115
-     * @param ITask             $page
116
-     * @param SiteConfiguration $siteConfiguration
117
-     * @param PdoDatabase       $database
118
-     * @param PdoDatabase       $notificationsDatabase
119
-     *
120
-     * @return void
121
-     */
122
-    protected function setupHelpers(
123
-        ITask $page,
124
-        SiteConfiguration $siteConfiguration,
125
-        PdoDatabase $database,
126
-        PdoDatabase $notificationsDatabase = null
127
-    ) {
128
-        $page->setSiteConfiguration($siteConfiguration);
129
-
130
-        // setup the global database object
131
-        $page->setDatabase($database);
132
-
133
-        // set up helpers and inject them into the page.
134
-        $httpHelper = new HttpHelper(
135
-            $siteConfiguration->getUserAgent(),
136
-            $siteConfiguration->getCurlDisableVerifyPeer()
137
-        );
138
-
139
-        $page->setEmailHelper(new EmailHelper());
140
-        $page->setHttpHelper($httpHelper);
141
-        $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
-
143
-        if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
-            $page->setLocationProvider(new FakeLocationProvider());
145
-        }
146
-        else {
147
-            $page->setLocationProvider(
148
-                new IpLocationProvider(
149
-                    $database,
150
-                    $siteConfiguration->getLocationProviderApiKey(),
151
-                    $httpHelper
152
-                ));
153
-        }
154
-
155
-        $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
-
157
-        $page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
-
159
-        $page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
-            $database,
161
-            $this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
-            $httpHelper));
163
-
164
-        $page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
-            $siteConfiguration->getOAuthBaseUrl(),
166
-            $siteConfiguration->getOAuthConsumerToken(),
167
-            $siteConfiguration->getOAuthConsumerSecret(),
168
-            $httpHelper,
169
-            $siteConfiguration->getMediawikiWebServiceEndpoint()
170
-        ));
171
-
172
-        $page->setNotificationHelper(new IrcNotificationHelper(
173
-            $siteConfiguration,
174
-            $database,
175
-            $notificationsDatabase));
176
-
177
-        $page->setTorExitProvider(new TorExitProvider($database));
178
-    }
28
+	private $configuration;
29
+
30
+	public function __construct(SiteConfiguration $configuration)
31
+	{
32
+		$this->configuration = $configuration;
33
+	}
34
+
35
+	/**
36
+	 * Application entry point.
37
+	 *
38
+	 * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
+	 */
40
+	public function run()
41
+	{
42
+		try {
43
+			if ($this->setupEnvironment()) {
44
+				$this->main();
45
+			}
46
+		}
47
+		catch (Exception $ex) {
48
+			print $ex->getMessage();
49
+		}
50
+		finally {
51
+			$this->cleanupEnvironment();
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Environment setup
57
+	 *
58
+	 * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
+	 * and shut down prematurely.
60
+	 *
61
+	 * @return bool
62
+	 * @throws EnvironmentException
63
+	 */
64
+	protected function setupEnvironment()
65
+	{
66
+		$this->setupDatabase();
67
+
68
+		return true;
69
+	}
70
+
71
+	/**
72
+	 * @return PdoDatabase
73
+	 * @throws EnvironmentException
74
+	 * @throws Exception
75
+	 */
76
+	protected function setupDatabase()
77
+	{
78
+		// check the schema version
79
+		$database = PdoDatabase::getDatabaseConnection('acc');
80
+
81
+		/** @var int $actualVersion */
82
+		$actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
+		if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
+			throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
+		}
86
+
87
+		return $database;
88
+	}
89
+
90
+	/**
91
+	 * @return SiteConfiguration
92
+	 */
93
+	public function getConfiguration()
94
+	{
95
+		return $this->configuration;
96
+	}
97
+
98
+	/**
99
+	 * Main application logic
100
+	 * @return void
101
+	 */
102
+	abstract protected function main();
103
+
104
+	/**
105
+	 * Any cleanup tasks should go here
106
+	 *
107
+	 * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
+	 * This should *only* be for cleaning up, no logic should go here.
109
+	 *
110
+	 * @return void
111
+	 */
112
+	abstract protected function cleanupEnvironment();
113
+
114
+	/**
115
+	 * @param ITask             $page
116
+	 * @param SiteConfiguration $siteConfiguration
117
+	 * @param PdoDatabase       $database
118
+	 * @param PdoDatabase       $notificationsDatabase
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function setupHelpers(
123
+		ITask $page,
124
+		SiteConfiguration $siteConfiguration,
125
+		PdoDatabase $database,
126
+		PdoDatabase $notificationsDatabase = null
127
+	) {
128
+		$page->setSiteConfiguration($siteConfiguration);
129
+
130
+		// setup the global database object
131
+		$page->setDatabase($database);
132
+
133
+		// set up helpers and inject them into the page.
134
+		$httpHelper = new HttpHelper(
135
+			$siteConfiguration->getUserAgent(),
136
+			$siteConfiguration->getCurlDisableVerifyPeer()
137
+		);
138
+
139
+		$page->setEmailHelper(new EmailHelper());
140
+		$page->setHttpHelper($httpHelper);
141
+		$page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
+
143
+		if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
+			$page->setLocationProvider(new FakeLocationProvider());
145
+		}
146
+		else {
147
+			$page->setLocationProvider(
148
+				new IpLocationProvider(
149
+					$database,
150
+					$siteConfiguration->getLocationProviderApiKey(),
151
+					$httpHelper
152
+				));
153
+		}
154
+
155
+		$page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
+
157
+		$page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
+
159
+		$page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
+			$database,
161
+			$this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
+			$httpHelper));
163
+
164
+		$page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
+			$siteConfiguration->getOAuthBaseUrl(),
166
+			$siteConfiguration->getOAuthConsumerToken(),
167
+			$siteConfiguration->getOAuthConsumerSecret(),
168
+			$httpHelper,
169
+			$siteConfiguration->getMediawikiWebServiceEndpoint()
170
+		));
171
+
172
+		$page->setNotificationHelper(new IrcNotificationHelper(
173
+			$siteConfiguration,
174
+			$database,
175
+			$notificationsDatabase));
176
+
177
+		$page->setTorExitProvider(new TorExitProvider($database));
178
+	}
179 179
 }
180 180
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleStart.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 
16 16
 class ConsoleStart extends ApplicationBase
17 17
 {
18
-    /**
19
-     * @var ConsoleTaskBase
20
-     */
21
-    private $consoleTask;
18
+	/**
19
+	 * @var ConsoleTaskBase
20
+	 */
21
+	private $consoleTask;
22 22
 
23
-    /**
24
-     * ConsoleStart constructor.
25
-     *
26
-     * @param SiteConfiguration $configuration
27
-     * @param ConsoleTaskBase   $consoleTask
28
-     */
29
-    public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
-    {
31
-        parent::__construct($configuration);
32
-        $this->consoleTask = $consoleTask;
33
-    }
23
+	/**
24
+	 * ConsoleStart constructor.
25
+	 *
26
+	 * @param SiteConfiguration $configuration
27
+	 * @param ConsoleTaskBase   $consoleTask
28
+	 */
29
+	public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
+	{
31
+		parent::__construct($configuration);
32
+		$this->consoleTask = $consoleTask;
33
+	}
34 34
 
35
-    protected function setupEnvironment()
36
-    {
37
-        // initialise super-global providers
38
-        WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
35
+	protected function setupEnvironment()
36
+	{
37
+		// initialise super-global providers
38
+		WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
39 39
 
40
-        if (WebRequest::method() !== null) {
41
-            throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
-        }
40
+		if (WebRequest::method() !== null) {
41
+			throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
+		}
43 43
 
44
-        return parent::setupEnvironment();
45
-    }
44
+		return parent::setupEnvironment();
45
+	}
46 46
 
47
-    protected function cleanupEnvironment()
48
-    {
49
-    }
47
+	protected function cleanupEnvironment()
48
+	{
49
+	}
50 50
 
51
-    /**
52
-     * Main application logic
53
-     */
54
-    protected function main()
55
-    {
56
-        $database = PdoDatabase::getDatabaseConnection('acc');
51
+	/**
52
+	 * Main application logic
53
+	 */
54
+	protected function main()
55
+	{
56
+		$database = PdoDatabase::getDatabaseConnection('acc');
57 57
 
58
-        if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
-            $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
-        }
61
-        else {
62
-            // pass through null
63
-            $notificationsDatabase = null;
64
-        }
58
+		if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
+			$notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
+		}
61
+		else {
62
+			// pass through null
63
+			$notificationsDatabase = null;
64
+		}
65 65
 
66
-        $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
66
+		$this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
67 67
 
68
-        // initialise a database transaction
69
-        if (!$database->beginTransaction()) {
70
-            throw new Exception('Failed to start transaction on primary database.');
71
-        }
68
+		// initialise a database transaction
69
+		if (!$database->beginTransaction()) {
70
+			throw new Exception('Failed to start transaction on primary database.');
71
+		}
72 72
 
73
-        try {
74
-            // run the task
75
-            $this->consoleTask->execute();
73
+		try {
74
+			// run the task
75
+			$this->consoleTask->execute();
76 76
 
77
-            if ($database->hasActiveTransaction()) {
78
-                $database->commit();
79
-            }
80
-        }
81
-        finally {
82
-            // Catch any hanging on transactions
83
-            if ($database->hasActiveTransaction()) {
84
-                $database->rollBack();
85
-            }
86
-        }
87
-    }
77
+			if ($database->hasActiveTransaction()) {
78
+				$database->commit();
79
+			}
80
+		}
81
+		finally {
82
+			// Catch any hanging on transactions
83
+			if ($database->hasActiveTransaction()) {
84
+				$database->rollBack();
85
+			}
86
+		}
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/RefreshOAuthDataTask.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -17,35 +17,35 @@
 block discarded – undo
17 17
 
18 18
 class RefreshOAuthDataTask extends ConsoleTaskBase
19 19
 {
20
-    public function execute()
21
-    {
22
-        $database = $this->getDatabase();
23
-
24
-        $idList = $database
25
-            ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
-            ->fetchAll(PDO::FETCH_COLUMN);
27
-
28
-        if (count($idList) > 0) {
29
-            /** @var User[] $users */
30
-            $users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
-
32
-            $expiredStatement = $database
33
-                ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
-
35
-            foreach ($users as $u) {
36
-                $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
-                    $this->getSiteConfiguration());
38
-
39
-                try {
40
-                    $oauth->refreshIdentity();
41
-                }
42
-                catch (OAuthException $ex) {
43
-                    $expiredStatement->execute(array(':u' => $u->getId()));
44
-                }
45
-            }
46
-        }
47
-
48
-        $this->getDatabase()
49
-            ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
-    }
20
+	public function execute()
21
+	{
22
+		$database = $this->getDatabase();
23
+
24
+		$idList = $database
25
+			->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
+			->fetchAll(PDO::FETCH_COLUMN);
27
+
28
+		if (count($idList) > 0) {
29
+			/** @var User[] $users */
30
+			$users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
+
32
+			$expiredStatement = $database
33
+				->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
+
35
+			foreach ($users as $u) {
36
+				$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
+					$this->getSiteConfiguration());
38
+
39
+				try {
40
+					$oauth->refreshIdentity();
41
+				}
42
+				catch (OAuthException $ex) {
43
+					$expiredStatement->execute(array(':u' => $u->getId()));
44
+				}
45
+			}
46
+		}
47
+
48
+		$this->getDatabase()
49
+			->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearOAuthDataTask.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 
15 15
 class ClearOAuthDataTask extends ConsoleTaskBase
16 16
 {
17
-    public function execute()
18
-    {
19
-        $database = $this->getDatabase();
17
+	public function execute()
18
+	{
19
+		$database = $this->getDatabase();
20 20
 
21
-        $users = UserSearchHelper::get($database)->inIds(
22
-            $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
21
+		$users = UserSearchHelper::get($database)->inIds(
22
+			$database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
25
-            $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
-            $oauth->detach();
27
-        }
24
+		foreach ($users as $u){
25
+			$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
+			$oauth->detach();
27
+		}
28 28
 
29
-        $database->exec('DELETE FROM oauthtoken');
30
-        $database->exec('DELETE FROM oauthidentity');
31
-    }
29
+		$database->exec('DELETE FROM oauthtoken');
30
+		$database->exec('DELETE FROM oauthidentity');
31
+	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $users = UserSearchHelper::get($database)->inIds(
22 22
             $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
24
+        foreach ($users as $u) {
25 25
             $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26 26
             $oauth->detach();
27 27
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $users = UserSearchHelper::get($database)->inIds(
22 22
             $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
24
+        foreach ($users as $u) {
25 25
             $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26 26
             $oauth->detach();
27 27
         }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/RequestActionBase.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -19,54 +19,54 @@
 block discarded – undo
19 19
 
20 20
 abstract class RequestActionBase extends InternalPageBase
21 21
 {
22
-    /**
23
-     * @param PdoDatabase $database
24
-     *
25
-     * @return Request
26
-     * @throws ApplicationLogicException
27
-     */
28
-    protected function getRequest(PdoDatabase $database)
29
-    {
30
-        $requestId = WebRequest::postInt('request');
31
-        if ($requestId === null) {
32
-            throw new ApplicationLogicException('Request ID not found');
33
-        }
22
+	/**
23
+	 * @param PdoDatabase $database
24
+	 *
25
+	 * @return Request
26
+	 * @throws ApplicationLogicException
27
+	 */
28
+	protected function getRequest(PdoDatabase $database)
29
+	{
30
+		$requestId = WebRequest::postInt('request');
31
+		if ($requestId === null) {
32
+			throw new ApplicationLogicException('Request ID not found');
33
+		}
34 34
 
35
-        /** @var Request $request */
36
-        $request = Request::getById($requestId, $database);
35
+		/** @var Request $request */
36
+		$request = Request::getById($requestId, $database);
37 37
 
38
-        if ($request === false) {
39
-            throw new ApplicationLogicException('Request not found');
40
-        }
38
+		if ($request === false) {
39
+			throw new ApplicationLogicException('Request not found');
40
+		}
41 41
 
42
-        return $request;
43
-    }
42
+		return $request;
43
+	}
44 44
 
45
-    final protected function checkPosted()
46
-    {
47
-        // if the request was not posted, send the user away.
48
-        if (!WebRequest::wasPosted()) {
49
-            throw new ApplicationLogicException('This page does not support GET methods.');
50
-        }
45
+	final protected function checkPosted()
46
+	{
47
+		// if the request was not posted, send the user away.
48
+		if (!WebRequest::wasPosted()) {
49
+			throw new ApplicationLogicException('This page does not support GET methods.');
50
+		}
51 51
 
52
-        // validate the CSRF token
53
-        $this->validateCSRFToken();
54
-    }
52
+		// validate the CSRF token
53
+		$this->validateCSRFToken();
54
+	}
55 55
 
56
-    /**
57
-     * @param Request     $request
58
-     * @param             $parentTaskId
59
-     * @param User        $user
60
-     * @param PdoDatabase $database
61
-     */
62
-    protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database)
63
-    {
64
-        $welcomeTask = new JobQueue();
65
-        $welcomeTask->setTask(WelcomeUserTask::class);
66
-        $welcomeTask->setRequest($request->getId());
67
-        $welcomeTask->setParent($parentTaskId);
68
-        $welcomeTask->setTriggerUserId($user->getId());
69
-        $welcomeTask->setDatabase($database);
70
-        $welcomeTask->save();
71
-    }
56
+	/**
57
+	 * @param Request     $request
58
+	 * @param             $parentTaskId
59
+	 * @param User        $user
60
+	 * @param PdoDatabase $database
61
+	 */
62
+	protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database)
63
+	{
64
+		$welcomeTask = new JobQueue();
65
+		$welcomeTask->setTask(WelcomeUserTask::class);
66
+		$welcomeTask->setRequest($request->getId());
67
+		$welcomeTask->setParent($parentTaskId);
68
+		$welcomeTask->setTriggerUserId($user->getId());
69
+		$welcomeTask->setDatabase($database);
70
+		$welcomeTask->save();
71
+	}
72 72
 }
73 73
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDropRequest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 
16 16
 class PageDropRequest extends PageCloseRequest
17 17
 {
18
-    protected function getTemplate(PdoDatabase $database)
19
-    {
20
-        return EmailTemplate::getDroppedTemplate();
21
-    }
18
+	protected function getTemplate(PdoDatabase $database)
19
+	{
20
+		return EmailTemplate::getDroppedTemplate();
21
+	}
22 22
 
23
-    protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
-    {
25
-        return false;
26
-    }
23
+	protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
+	{
25
+		return false;
26
+	}
27 27
 
28
-    protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
-    {
30
-        return false;
31
-    }
28
+	protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
+	{
30
+		return false;
31
+	}
32 32
 
33
-    protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
34
-    {
35
-    }
33
+	protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
34
+	{
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageViewRequest.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             }
131 131
         }
132 132
 
133
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
133
+        $this->setHtmlTitle($statusSymbol.' #'.$request->getId());
134 134
     }
135 135
 
136 136
     /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
                 $entryComment = $entry->getComment();
229 229
 
230
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
230
+                if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
231 231
                     $data = unserialize($entry->getComment());
232 232
                     /** @var JobQueue $job */
233 233
                     $job = JobQueue::getById($data['job'], $database);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
                 $entryComment = $entry->getComment();
229 229
 
230
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
230
+                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
231 231
                     $data = unserialize($entry->getComment());
232 232
                     /** @var JobQueue $job */
233 233
                     $job = JobQueue::getById($data['job'], $database);
@@ -243,7 +243,8 @@  discard block
 block discarded – undo
243 243
                         'jobId'    => $job->getId(),
244 244
                         'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
245 245
                     );
246
-                } else {
246
+                }
247
+                else {
247 248
                     $requestLogs[] = array(
248 249
                         'type'     => 'log',
249 250
                         'security' => 'user',
Please login to merge, or discard this patch.
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -25,288 +25,288 @@
 block discarded – undo
25 25
 
26 26
 class PageViewRequest extends InternalPageBase
27 27
 {
28
-    use RequestData;
29
-    const STATUS_SYMBOL_OPEN = '&#x2610';
30
-    const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
-    const STATUS_SYMBOL_REJECTED = '&#x2612';
32
-
33
-    /**
34
-     * Main function for this page, when no specific actions are called.
35
-     * @throws ApplicationLogicException
36
-     */
37
-    protected function main()
38
-    {
39
-        // set up csrf protection
40
-        $this->assignCSRFToken();
41
-
42
-        // get some useful objects
43
-        $database = $this->getDatabase();
44
-        $request = $this->getRequest($database, WebRequest::getInt('id'));
45
-        $config = $this->getSiteConfiguration();
46
-        $currentUser = User::getCurrent($database);
47
-
48
-        // Test we should be able to look at this request
49
-        if ($config->getEmailConfirmationEnabled()) {
50
-            if ($request->getEmailConfirm() !== 'Confirmed') {
51
-                // Not allowed to look at this yet.
52
-                throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
-            }
54
-        }
55
-
56
-        $this->setupBasicData($request, $config);
57
-
58
-        $this->setupUsernameData($request);
59
-
60
-        $this->setupTitle($request);
61
-
62
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
-        $this->setupGeneralData($database);
64
-
65
-        $this->assign('requestDataCleared', false);
66
-        if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
-            $this->assign('requestDataCleared', true);
68
-        }
69
-
70
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
-
72
-        $this->setupCreationTypes($currentUser);
73
-
74
-        $this->setupLogData($request, $database);
75
-
76
-        $this->addJs("/api.php?action=templates&targetVariable=templateconfirms");
77
-
78
-        $this->assign('showRevealLink', false);
79
-        if ($request->getReserved() === $currentUser->getId() ||
80
-            $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
81
-        ) {
82
-            $this->assign('showRevealLink', true);
83
-            $this->assign('revealHash', $request->getRevealHash());
84
-        }
85
-
86
-        if ($allowedPrivateData) {
87
-            $this->setTemplate('view-request/main-with-data.tpl');
88
-            $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
89
-
90
-            $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
91
-            $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
92
-
93
-            if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
94
-                $this->setTemplate('view-request/main-with-checkuser-data.tpl');
95
-                $this->setupCheckUserData($request);
96
-            }
97
-        }
98
-        else {
99
-            $this->setTemplate('view-request/main.tpl');
100
-        }
101
-    }
102
-
103
-    /**
104
-     * @param Request $request
105
-     */
106
-    protected function setupTitle(Request $request)
107
-    {
108
-        $statusSymbol = self::STATUS_SYMBOL_OPEN;
109
-        if ($request->getStatus() === 'Closed') {
110
-            if ($request->getWasCreated()) {
111
-                $statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
112
-            }
113
-            else {
114
-                $statusSymbol = self::STATUS_SYMBOL_REJECTED;
115
-            }
116
-        }
117
-
118
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
119
-    }
120
-
121
-    /**
122
-     * Sets up data unrelated to the request, such as the email template information
123
-     *
124
-     * @param PdoDatabase $database
125
-     */
126
-    protected function setupGeneralData(PdoDatabase $database)
127
-    {
128
-        $config = $this->getSiteConfiguration();
129
-
130
-        $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
131
-
132
-        $this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
133
-
134
-        $this->assign('requestStates', $config->getRequestStates());
135
-
136
-        /** @var EmailTemplate $createdTemplate */
137
-        $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
138
-
139
-        $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
140
-        $this->assign('createdId', $createdTemplate->getId());
141
-        $this->assign('createdName', $createdTemplate->getName());
142
-
143
-        $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
144
-        $this->assign("createReasons", $createReasons);
145
-        $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
146
-        $this->assign("declineReasons", $declineReasons);
147
-
148
-        $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
149
-        $this->assign("allCreateReasons", $allCreateReasons);
150
-        $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
151
-        $this->assign("allDeclineReasons", $allDeclineReasons);
152
-        $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
153
-        $this->assign("allOtherReasons", $allOtherReasons);
154
-    }
155
-
156
-    private function setupLogData(Request $request, PdoDatabase $database)
157
-    {
158
-        $currentUser = User::getCurrent($database);
159
-
160
-        $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
161
-        $requestLogs = array();
162
-
163
-        if (trim($request->getComment()) !== "") {
164
-            $requestLogs[] = array(
165
-                'type'     => 'comment',
166
-                'security' => 'user',
167
-                'userid'   => null,
168
-                'user'     => $request->getName(),
169
-                'entry'    => null,
170
-                'time'     => $request->getDate(),
171
-                'canedit'  => false,
172
-                'id'       => $request->getId(),
173
-                'comment'  => $request->getComment(),
174
-            );
175
-        }
176
-
177
-        /** @var User[] $nameCache */
178
-        $nameCache = array();
179
-
180
-        $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
181
-
182
-        /** @var Log|Comment $entry */
183
-        foreach ($logs as $entry) {
184
-            // both log and comment have a 'user' field
185
-            if (!array_key_exists($entry->getUser(), $nameCache)) {
186
-                $entryUser = User::getById($entry->getUser(), $database);
187
-                $nameCache[$entry->getUser()] = $entryUser;
188
-            }
189
-
190
-            if ($entry instanceof Comment) {
191
-                $requestLogs[] = array(
192
-                    'type'     => 'comment',
193
-                    'security' => $entry->getVisibility(),
194
-                    'user'     => $nameCache[$entry->getUser()]->getUsername(),
195
-                    'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
196
-                    'entry'    => null,
197
-                    'time'     => $entry->getTime(),
198
-                    'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
199
-                    'id'       => $entry->getId(),
200
-                    'comment'  => $entry->getComment(),
201
-                );
202
-            }
203
-
204
-            if ($entry instanceof Log) {
205
-                $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
206
-                $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
207
-
208
-                $entryComment = $entry->getComment();
209
-
210
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
211
-                    $data = unserialize($entry->getComment());
212
-                    /** @var JobQueue $job */
213
-                    $job = JobQueue::getById($data['job'], $database);
214
-                    $requestLogs[] = array(
215
-                        'type'     => 'joblog',
216
-                        'security' => 'user',
217
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
218
-                        'user'     => $entryUser->getUsername(),
219
-                        'entry'    => LogHelper::getLogDescription($entry),
220
-                        'time'     => $entry->getTimestamp(),
221
-                        'canedit'  => false,
222
-                        'id'       => $entry->getId(),
223
-                        'jobId'    => $job->getId(),
224
-                        'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
225
-                    );
226
-                } else {
227
-                    $requestLogs[] = array(
228
-                        'type'     => 'log',
229
-                        'security' => 'user',
230
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
231
-                        'user'     => $entryUser->getUsername(),
232
-                        'entry'    => LogHelper::getLogDescription($entry),
233
-                        'time'     => $entry->getTimestamp(),
234
-                        'canedit'  => false,
235
-                        'id'       => $entry->getId(),
236
-                        'comment'  => $entryComment,
237
-                    );
238
-                }
239
-            }
240
-        }
241
-
242
-        $this->addJs("/api.php?action=users&targetVariable=typeaheaddata");
243
-
244
-        $this->assign("requestLogs", $requestLogs);
245
-    }
246
-
247
-    /**
248
-     * @param Request $request
249
-     */
250
-    protected function setupUsernameData(Request $request)
251
-    {
252
-        $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
253
-
254
-        $this->assign('requestIsBlacklisted', $blacklistData !== false);
255
-        $this->assign('requestBlacklist', $blacklistData);
256
-
257
-        try {
258
-            $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
259
-        }
260
-        catch (Exception $ex) {
261
-            $spoofs = $ex->getMessage();
262
-        }
263
-
264
-        $this->assign("spoofs", $spoofs);
265
-    }
266
-
267
-    private function setupCreationTypes(User $user)
268
-    {
269
-        $this->assign('allowWelcomeSkip', false);
270
-        $this->assign('forceWelcomeSkip', false);
271
-
272
-        $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
273
-
274
-        if ($user->getWelcomeTemplate() != 0) {
275
-            $this->assign('allowWelcomeSkip', true);
276
-
277
-            if (!$oauth->canWelcome()) {
278
-                $this->assign('forceWelcomeSkip', true);
279
-            }
280
-        }
281
-
282
-        // test credentials
283
-        $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation');
284
-        $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation');
285
-        $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation');
286
-
287
-        $this->assign('canManualCreate', $canManualCreate);
288
-        $this->assign('canOauthCreate', $canOauthCreate);
289
-        $this->assign('canBotCreate', $canBotCreate);
290
-
291
-        // show/hide the type radio buttons
292
-        $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1;
293
-
294
-        if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) {
295
-            // user is not allowed to use their default. Force a choice.
296
-            $creationHasChoice = true;
297
-        }
298
-
299
-        $this->assign('creationHasChoice', $creationHasChoice);
300
-
301
-        // determine problems in creation types
302
-        $this->assign('botProblem', false);
303
-        if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) {
304
-            $this->assign('botProblem', true);
305
-        }
306
-
307
-        $this->assign('oauthProblem', false);
308
-        if ($canOauthCreate && !$oauth->canCreateAccount()) {
309
-            $this->assign('oauthProblem', true);
310
-        }
311
-    }
28
+	use RequestData;
29
+	const STATUS_SYMBOL_OPEN = '&#x2610';
30
+	const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
+	const STATUS_SYMBOL_REJECTED = '&#x2612';
32
+
33
+	/**
34
+	 * Main function for this page, when no specific actions are called.
35
+	 * @throws ApplicationLogicException
36
+	 */
37
+	protected function main()
38
+	{
39
+		// set up csrf protection
40
+		$this->assignCSRFToken();
41
+
42
+		// get some useful objects
43
+		$database = $this->getDatabase();
44
+		$request = $this->getRequest($database, WebRequest::getInt('id'));
45
+		$config = $this->getSiteConfiguration();
46
+		$currentUser = User::getCurrent($database);
47
+
48
+		// Test we should be able to look at this request
49
+		if ($config->getEmailConfirmationEnabled()) {
50
+			if ($request->getEmailConfirm() !== 'Confirmed') {
51
+				// Not allowed to look at this yet.
52
+				throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
+			}
54
+		}
55
+
56
+		$this->setupBasicData($request, $config);
57
+
58
+		$this->setupUsernameData($request);
59
+
60
+		$this->setupTitle($request);
61
+
62
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
+		$this->setupGeneralData($database);
64
+
65
+		$this->assign('requestDataCleared', false);
66
+		if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
+			$this->assign('requestDataCleared', true);
68
+		}
69
+
70
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
+
72
+		$this->setupCreationTypes($currentUser);
73
+
74
+		$this->setupLogData($request, $database);
75
+
76
+		$this->addJs("/api.php?action=templates&targetVariable=templateconfirms");
77
+
78
+		$this->assign('showRevealLink', false);
79
+		if ($request->getReserved() === $currentUser->getId() ||
80
+			$this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
81
+		) {
82
+			$this->assign('showRevealLink', true);
83
+			$this->assign('revealHash', $request->getRevealHash());
84
+		}
85
+
86
+		if ($allowedPrivateData) {
87
+			$this->setTemplate('view-request/main-with-data.tpl');
88
+			$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
89
+
90
+			$this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
91
+			$this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
92
+
93
+			if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
94
+				$this->setTemplate('view-request/main-with-checkuser-data.tpl');
95
+				$this->setupCheckUserData($request);
96
+			}
97
+		}
98
+		else {
99
+			$this->setTemplate('view-request/main.tpl');
100
+		}
101
+	}
102
+
103
+	/**
104
+	 * @param Request $request
105
+	 */
106
+	protected function setupTitle(Request $request)
107
+	{
108
+		$statusSymbol = self::STATUS_SYMBOL_OPEN;
109
+		if ($request->getStatus() === 'Closed') {
110
+			if ($request->getWasCreated()) {
111
+				$statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
112
+			}
113
+			else {
114
+				$statusSymbol = self::STATUS_SYMBOL_REJECTED;
115
+			}
116
+		}
117
+
118
+		$this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
119
+	}
120
+
121
+	/**
122
+	 * Sets up data unrelated to the request, such as the email template information
123
+	 *
124
+	 * @param PdoDatabase $database
125
+	 */
126
+	protected function setupGeneralData(PdoDatabase $database)
127
+	{
128
+		$config = $this->getSiteConfiguration();
129
+
130
+		$this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
131
+
132
+		$this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
133
+
134
+		$this->assign('requestStates', $config->getRequestStates());
135
+
136
+		/** @var EmailTemplate $createdTemplate */
137
+		$createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
138
+
139
+		$this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
140
+		$this->assign('createdId', $createdTemplate->getId());
141
+		$this->assign('createdName', $createdTemplate->getName());
142
+
143
+		$createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
144
+		$this->assign("createReasons", $createReasons);
145
+		$declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
146
+		$this->assign("declineReasons", $declineReasons);
147
+
148
+		$allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
149
+		$this->assign("allCreateReasons", $allCreateReasons);
150
+		$allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
151
+		$this->assign("allDeclineReasons", $allDeclineReasons);
152
+		$allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
153
+		$this->assign("allOtherReasons", $allOtherReasons);
154
+	}
155
+
156
+	private function setupLogData(Request $request, PdoDatabase $database)
157
+	{
158
+		$currentUser = User::getCurrent($database);
159
+
160
+		$logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
161
+		$requestLogs = array();
162
+
163
+		if (trim($request->getComment()) !== "") {
164
+			$requestLogs[] = array(
165
+				'type'     => 'comment',
166
+				'security' => 'user',
167
+				'userid'   => null,
168
+				'user'     => $request->getName(),
169
+				'entry'    => null,
170
+				'time'     => $request->getDate(),
171
+				'canedit'  => false,
172
+				'id'       => $request->getId(),
173
+				'comment'  => $request->getComment(),
174
+			);
175
+		}
176
+
177
+		/** @var User[] $nameCache */
178
+		$nameCache = array();
179
+
180
+		$editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
181
+
182
+		/** @var Log|Comment $entry */
183
+		foreach ($logs as $entry) {
184
+			// both log and comment have a 'user' field
185
+			if (!array_key_exists($entry->getUser(), $nameCache)) {
186
+				$entryUser = User::getById($entry->getUser(), $database);
187
+				$nameCache[$entry->getUser()] = $entryUser;
188
+			}
189
+
190
+			if ($entry instanceof Comment) {
191
+				$requestLogs[] = array(
192
+					'type'     => 'comment',
193
+					'security' => $entry->getVisibility(),
194
+					'user'     => $nameCache[$entry->getUser()]->getUsername(),
195
+					'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
196
+					'entry'    => null,
197
+					'time'     => $entry->getTime(),
198
+					'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
199
+					'id'       => $entry->getId(),
200
+					'comment'  => $entry->getComment(),
201
+				);
202
+			}
203
+
204
+			if ($entry instanceof Log) {
205
+				$invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
206
+				$entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
207
+
208
+				$entryComment = $entry->getComment();
209
+
210
+				if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
211
+					$data = unserialize($entry->getComment());
212
+					/** @var JobQueue $job */
213
+					$job = JobQueue::getById($data['job'], $database);
214
+					$requestLogs[] = array(
215
+						'type'     => 'joblog',
216
+						'security' => 'user',
217
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
218
+						'user'     => $entryUser->getUsername(),
219
+						'entry'    => LogHelper::getLogDescription($entry),
220
+						'time'     => $entry->getTimestamp(),
221
+						'canedit'  => false,
222
+						'id'       => $entry->getId(),
223
+						'jobId'    => $job->getId(),
224
+						'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
225
+					);
226
+				} else {
227
+					$requestLogs[] = array(
228
+						'type'     => 'log',
229
+						'security' => 'user',
230
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
231
+						'user'     => $entryUser->getUsername(),
232
+						'entry'    => LogHelper::getLogDescription($entry),
233
+						'time'     => $entry->getTimestamp(),
234
+						'canedit'  => false,
235
+						'id'       => $entry->getId(),
236
+						'comment'  => $entryComment,
237
+					);
238
+				}
239
+			}
240
+		}
241
+
242
+		$this->addJs("/api.php?action=users&targetVariable=typeaheaddata");
243
+
244
+		$this->assign("requestLogs", $requestLogs);
245
+	}
246
+
247
+	/**
248
+	 * @param Request $request
249
+	 */
250
+	protected function setupUsernameData(Request $request)
251
+	{
252
+		$blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
253
+
254
+		$this->assign('requestIsBlacklisted', $blacklistData !== false);
255
+		$this->assign('requestBlacklist', $blacklistData);
256
+
257
+		try {
258
+			$spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
259
+		}
260
+		catch (Exception $ex) {
261
+			$spoofs = $ex->getMessage();
262
+		}
263
+
264
+		$this->assign("spoofs", $spoofs);
265
+	}
266
+
267
+	private function setupCreationTypes(User $user)
268
+	{
269
+		$this->assign('allowWelcomeSkip', false);
270
+		$this->assign('forceWelcomeSkip', false);
271
+
272
+		$oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
273
+
274
+		if ($user->getWelcomeTemplate() != 0) {
275
+			$this->assign('allowWelcomeSkip', true);
276
+
277
+			if (!$oauth->canWelcome()) {
278
+				$this->assign('forceWelcomeSkip', true);
279
+			}
280
+		}
281
+
282
+		// test credentials
283
+		$canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation');
284
+		$canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation');
285
+		$canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation');
286
+
287
+		$this->assign('canManualCreate', $canManualCreate);
288
+		$this->assign('canOauthCreate', $canOauthCreate);
289
+		$this->assign('canBotCreate', $canBotCreate);
290
+
291
+		// show/hide the type radio buttons
292
+		$creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1;
293
+
294
+		if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) {
295
+			// user is not allowed to use their default. Force a choice.
296
+			$creationHasChoice = true;
297
+		}
298
+
299
+		$this->assign('creationHasChoice', $creationHasChoice);
300
+
301
+		// determine problems in creation types
302
+		$this->assign('botProblem', false);
303
+		if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) {
304
+			$this->assign('botProblem', true);
305
+		}
306
+
307
+		$this->assign('oauthProblem', false);
308
+		if ($canOauthCreate && !$oauth->canCreateAccount()) {
309
+			$this->assign('oauthProblem', true);
310
+		}
311
+	}
312 312
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageOAuth.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -21,77 +21,77 @@
 block discarded – undo
21 21
 
22 22
 class PageOAuth extends InternalPageBase
23 23
 {
24
-    /**
25
-     * Attach entry point
26
-     *
27
-     * must be posted, or will redirect to preferences
28
-     */
29
-    protected function attach()
30
-    {
31
-        if (!WebRequest::wasPosted()) {
32
-            $this->redirect('preferences');
33
-
34
-            return;
35
-        }
36
-
37
-        $database = $this->getDatabase();
38
-
39
-        $this->validateCSRFToken();
40
-
41
-        $oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
-        $user = User::getCurrent($database);
43
-        $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
-
45
-        try {
46
-            $authoriseUrl = $oauth->getRequestToken();
47
-            $this->redirectUrl($authoriseUrl);
48
-        }
49
-        catch (CurlException $ex) {
50
-            throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Detach account entry point
56
-     */
57
-    protected function detach()
58
-    {
59
-        if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
-            throw new AccessDeniedException($this->getSecurityManager());
61
-        }
62
-
63
-        $database = $this->getDatabase();
64
-        $user = User::getCurrent($database);
65
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
-
67
-        try {
68
-            $oauth->refreshIdentity();
69
-        }
70
-        catch (CurlException $ex) {
71
-            // do nothing. The user's already revoked this access anyway.
72
-        }
73
-        catch (OAuthException $ex) {
74
-            // do nothing. The user's already revoked this access anyway.
75
-        }
76
-
77
-        $oauth->detach();
78
-
79
-        // TODO: figure out why we need to force logout after a detach.
80
-        $user->setForcelogout(true);
81
-        $user->save();
82
-
83
-        // force the user to log out
84
-        Session::destroy();
85
-
86
-        $this->redirect('login');
87
-    }
88
-
89
-    /**
90
-     * Main function for this page, when no specific actions are called.
91
-     * @return void
92
-     */
93
-    protected function main()
94
-    {
95
-        $this->redirect('preferences');
96
-    }
24
+	/**
25
+	 * Attach entry point
26
+	 *
27
+	 * must be posted, or will redirect to preferences
28
+	 */
29
+	protected function attach()
30
+	{
31
+		if (!WebRequest::wasPosted()) {
32
+			$this->redirect('preferences');
33
+
34
+			return;
35
+		}
36
+
37
+		$database = $this->getDatabase();
38
+
39
+		$this->validateCSRFToken();
40
+
41
+		$oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
+		$user = User::getCurrent($database);
43
+		$oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
+
45
+		try {
46
+			$authoriseUrl = $oauth->getRequestToken();
47
+			$this->redirectUrl($authoriseUrl);
48
+		}
49
+		catch (CurlException $ex) {
50
+			throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Detach account entry point
56
+	 */
57
+	protected function detach()
58
+	{
59
+		if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
+			throw new AccessDeniedException($this->getSecurityManager());
61
+		}
62
+
63
+		$database = $this->getDatabase();
64
+		$user = User::getCurrent($database);
65
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
+
67
+		try {
68
+			$oauth->refreshIdentity();
69
+		}
70
+		catch (CurlException $ex) {
71
+			// do nothing. The user's already revoked this access anyway.
72
+		}
73
+		catch (OAuthException $ex) {
74
+			// do nothing. The user's already revoked this access anyway.
75
+		}
76
+
77
+		$oauth->detach();
78
+
79
+		// TODO: figure out why we need to force logout after a detach.
80
+		$user->setForcelogout(true);
81
+		$user->save();
82
+
83
+		// force the user to log out
84
+		Session::destroy();
85
+
86
+		$this->redirect('login');
87
+	}
88
+
89
+	/**
90
+	 * Main function for this page, when no specific actions are called.
91
+	 * @return void
92
+	 */
93
+	protected function main()
94
+	{
95
+		$this->redirect('preferences');
96
+	}
97 97
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageChangePassword.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
 
18 18
 class PageChangePassword extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @return void
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Change Password');
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @return void
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Change Password');
27 27
 
28
-        if (WebRequest::wasPosted()) {
29
-            $this->validateCSRFToken();
30
-            try {
31
-                $oldPassword = WebRequest::postString('oldpassword');
32
-                $newPassword = WebRequest::postString('newpassword');
33
-                $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
28
+		if (WebRequest::wasPosted()) {
29
+			$this->validateCSRFToken();
30
+			try {
31
+				$oldPassword = WebRequest::postString('oldpassword');
32
+				$newPassword = WebRequest::postString('newpassword');
33
+				$newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
34 34
 
35
-                $user = User::getCurrent($this->getDatabase());
36
-                if (!$user instanceof User) {
37
-                    throw new ApplicationLogicException('User not found');
38
-                }
35
+				$user = User::getCurrent($this->getDatabase());
36
+				if (!$user instanceof User) {
37
+					throw new ApplicationLogicException('User not found');
38
+				}
39 39
 
40
-                $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
-            }
42
-            catch (ApplicationLogicException $ex) {
43
-                SessionAlert::error($ex->getMessage());
44
-                $this->redirect('changePassword');
40
+				$this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
+			}
42
+			catch (ApplicationLogicException $ex) {
43
+				SessionAlert::error($ex->getMessage());
44
+				$this->redirect('changePassword');
45 45
 
46
-                return;
47
-            }
46
+				return;
47
+			}
48 48
 
49
-            $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
-            $passwordProvider->setCredential($user, 1, $newPassword);
49
+			$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
+			$passwordProvider->setCredential($user, 1, $newPassword);
51 51
 
52
-            SessionAlert::success('Password changed successfully!');
52
+			SessionAlert::success('Password changed successfully!');
53 53
 
54
-            $this->redirect('preferences');
55
-        }
56
-        else {
57
-            $this->assignCSRFToken();
58
-            $this->setTemplate('preferences/changePassword.tpl');
59
-        }
60
-    }
54
+			$this->redirect('preferences');
55
+		}
56
+		else {
57
+			$this->assignCSRFToken();
58
+			$this->setTemplate('preferences/changePassword.tpl');
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @param string $oldPassword
64
-     * @param string $newPassword
65
-     * @param string $newPasswordConfirmation
66
-     * @param User   $user
67
-     *
68
-     * @throws ApplicationLogicException
69
-     */
70
-    protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
-    {
72
-        if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
-            throw new ApplicationLogicException('All three fields must be completed to change your password');
74
-        }
62
+	/**
63
+	 * @param string $oldPassword
64
+	 * @param string $newPassword
65
+	 * @param string $newPasswordConfirmation
66
+	 * @param User   $user
67
+	 *
68
+	 * @throws ApplicationLogicException
69
+	 */
70
+	protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
+	{
72
+		if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
+			throw new ApplicationLogicException('All three fields must be completed to change your password');
74
+		}
75 75
 
76
-        if ($newPassword !== $newPasswordConfirmation) {
77
-            throw new ApplicationLogicException('Your new passwords did not match!');
78
-        }
76
+		if ($newPassword !== $newPasswordConfirmation) {
77
+			throw new ApplicationLogicException('Your new passwords did not match!');
78
+		}
79 79
 
80
-        // TODO: adapt for MFA support
81
-        $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
-        if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
-            throw new ApplicationLogicException('The password you entered was incorrect.');
84
-        }
85
-    }
80
+		// TODO: adapt for MFA support
81
+		$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
+		if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
+			throw new ApplicationLogicException('The password you entered was incorrect.');
84
+		}
85
+	}
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.