Passed
Push — dependabot/composer/newinterna... ( 13eb18 )
by
unknown
04:37
created
includes/Pages/PageEmailManagement.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -19,175 +19,175 @@
 block discarded – undo
19 19
 
20 20
 class PageEmailManagement extends InternalPageBase
21 21
 {
22
-    /**
23
-     * Main function for this page, when no specific actions are called.
24
-     * @return void
25
-     */
26
-    protected function main()
27
-    {
28
-        $this->setHtmlTitle('Close Emails');
29
-
30
-        // Get all active email templates
31
-        $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
-        $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
-
34
-        $this->assign('activeTemplates', $activeTemplates);
35
-        $this->assign('inactiveTemplates', $inactiveTemplates);
36
-
37
-        $user = User::getCurrent($this->getDatabase());
38
-        $this->assign('canCreate', $this->barrierTest('create', $user));
39
-        $this->assign('canEdit', $this->barrierTest('edit', $user));
40
-
41
-        $this->setTemplate('email-management/main.tpl');
42
-    }
43
-
44
-    protected function view()
45
-    {
46
-        $this->setHtmlTitle('Close Emails');
47
-
48
-        $database = $this->getDatabase();
49
-        $template = $this->getTemplate($database);
50
-
51
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
53
-
54
-        $this->assign('id', $template->getId());
55
-        $this->assign('emailTemplate', $template);
56
-        $this->assign('createdid', $createdId);
57
-        $this->assign('requeststates', $requestStates);
58
-
59
-        $this->setTemplate('email-management/view.tpl');
60
-    }
61
-
62
-    /**
63
-     * @param PdoDatabase $database
64
-     *
65
-     * @return EmailTemplate
66
-     * @throws ApplicationLogicException
67
-     */
68
-    protected function getTemplate(PdoDatabase $database)
69
-    {
70
-        $templateId = WebRequest::getInt('id');
71
-        if ($templateId === null) {
72
-            throw new ApplicationLogicException('Template not specified');
73
-        }
74
-        $template = EmailTemplate::getById($templateId, $database);
75
-        if ($template === false || !is_a($template, EmailTemplate::class)) {
76
-            throw new ApplicationLogicException('Template not found');
77
-        }
78
-
79
-        return $template;
80
-    }
81
-
82
-    protected function edit()
83
-    {
84
-        $this->setHtmlTitle('Close Emails');
85
-
86
-        $database = $this->getDatabase();
87
-        $template = $this->getTemplate($database);
88
-
89
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
91
-
92
-        if (WebRequest::wasPosted()) {
93
-            $this->validateCSRFToken();
94
-
95
-            $this->modifyTemplateData($template);
96
-
97
-            $other = EmailTemplate::getByName($template->getName(), $database);
98
-            if ($other !== false && $other->getId() !== $template->getId()) {
99
-                throw new ApplicationLogicException('A template with this name already exists');
100
-            }
101
-
102
-            if ($template->getId() === $createdId) {
103
-                $template->setDefaultAction(EmailTemplate::CREATED);
104
-                $template->setActive(true);
105
-                $template->setPreloadOnly(false);
106
-            }
107
-
108
-            // optimistically lock on load of edit form
109
-            $updateVersion = WebRequest::postInt('updateversion');
110
-            $template->setUpdateVersion($updateVersion);
111
-
112
-            $template->save();
113
-            Logger::editedEmail($database, $template);
114
-            $this->getNotificationHelper()->emailEdited($template);
115
-            SessionAlert::success("Email template has been saved successfully.");
116
-
117
-            $this->redirect('emailManagement');
118
-        }
119
-        else {
120
-            $this->assignCSRFToken();
121
-            $this->assign('id', $template->getId());
122
-            $this->assign('emailTemplate', $template);
123
-            $this->assign('createdid', $createdId);
124
-            $this->assign('requeststates', $requestStates);
125
-
126
-            $this->setTemplate('email-management/edit.tpl');
127
-        }
128
-    }
129
-
130
-    /**
131
-     * @param EmailTemplate $template
132
-     *
133
-     * @throws ApplicationLogicException
134
-     */
135
-    private function modifyTemplateData(EmailTemplate $template)
136
-    {
137
-        $name = WebRequest::postString('name');
138
-        if ($name === null || $name === '') {
139
-            throw new ApplicationLogicException('Name not specified');
140
-        }
141
-
142
-        $template->setName($name);
143
-
144
-        $text = WebRequest::postString('text');
145
-        if ($text === null || $text === '') {
146
-            throw new ApplicationLogicException('Text not specified');
147
-        }
148
-
149
-        $template->setText($text);
150
-
151
-        $template->setJsquestion(WebRequest::postString('jsquestion'));
152
-
153
-        $template->setDefaultAction(WebRequest::postString('defaultaction'));
154
-        $template->setActive(WebRequest::postBoolean('active'));
155
-        $template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
-    }
157
-
158
-    protected function create()
159
-    {
160
-        $this->setHtmlTitle('Close Emails');
161
-
162
-        $database = $this->getDatabase();
163
-
164
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
165
-
166
-        if (WebRequest::wasPosted()) {
167
-            $this->validateCSRFToken();
168
-            $template = new EmailTemplate();
169
-            $template->setDatabase($database);
170
-
171
-            $this->modifyTemplateData($template);
172
-
173
-            $other = EmailTemplate::getByName($template->getName(), $database);
174
-            if ($other !== false) {
175
-                throw new ApplicationLogicException('A template with this name already exists');
176
-            }
177
-
178
-            $template->save();
179
-
180
-            Logger::createEmail($database, $template);
181
-            $this->getNotificationHelper()->emailCreated($template);
182
-
183
-            SessionAlert::success("Email template has been saved successfully.");
184
-
185
-            $this->redirect('emailManagement');
186
-        }
187
-        else {
188
-            $this->assignCSRFToken();
189
-            $this->assign('requeststates', $requestStates);
190
-            $this->setTemplate('email-management/create.tpl');
191
-        }
192
-    }
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->setHtmlTitle('Close Emails');
29
+
30
+		// Get all active email templates
31
+		$activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
+		$inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
+
34
+		$this->assign('activeTemplates', $activeTemplates);
35
+		$this->assign('inactiveTemplates', $inactiveTemplates);
36
+
37
+		$user = User::getCurrent($this->getDatabase());
38
+		$this->assign('canCreate', $this->barrierTest('create', $user));
39
+		$this->assign('canEdit', $this->barrierTest('edit', $user));
40
+
41
+		$this->setTemplate('email-management/main.tpl');
42
+	}
43
+
44
+	protected function view()
45
+	{
46
+		$this->setHtmlTitle('Close Emails');
47
+
48
+		$database = $this->getDatabase();
49
+		$template = $this->getTemplate($database);
50
+
51
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
53
+
54
+		$this->assign('id', $template->getId());
55
+		$this->assign('emailTemplate', $template);
56
+		$this->assign('createdid', $createdId);
57
+		$this->assign('requeststates', $requestStates);
58
+
59
+		$this->setTemplate('email-management/view.tpl');
60
+	}
61
+
62
+	/**
63
+	 * @param PdoDatabase $database
64
+	 *
65
+	 * @return EmailTemplate
66
+	 * @throws ApplicationLogicException
67
+	 */
68
+	protected function getTemplate(PdoDatabase $database)
69
+	{
70
+		$templateId = WebRequest::getInt('id');
71
+		if ($templateId === null) {
72
+			throw new ApplicationLogicException('Template not specified');
73
+		}
74
+		$template = EmailTemplate::getById($templateId, $database);
75
+		if ($template === false || !is_a($template, EmailTemplate::class)) {
76
+			throw new ApplicationLogicException('Template not found');
77
+		}
78
+
79
+		return $template;
80
+	}
81
+
82
+	protected function edit()
83
+	{
84
+		$this->setHtmlTitle('Close Emails');
85
+
86
+		$database = $this->getDatabase();
87
+		$template = $this->getTemplate($database);
88
+
89
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
91
+
92
+		if (WebRequest::wasPosted()) {
93
+			$this->validateCSRFToken();
94
+
95
+			$this->modifyTemplateData($template);
96
+
97
+			$other = EmailTemplate::getByName($template->getName(), $database);
98
+			if ($other !== false && $other->getId() !== $template->getId()) {
99
+				throw new ApplicationLogicException('A template with this name already exists');
100
+			}
101
+
102
+			if ($template->getId() === $createdId) {
103
+				$template->setDefaultAction(EmailTemplate::CREATED);
104
+				$template->setActive(true);
105
+				$template->setPreloadOnly(false);
106
+			}
107
+
108
+			// optimistically lock on load of edit form
109
+			$updateVersion = WebRequest::postInt('updateversion');
110
+			$template->setUpdateVersion($updateVersion);
111
+
112
+			$template->save();
113
+			Logger::editedEmail($database, $template);
114
+			$this->getNotificationHelper()->emailEdited($template);
115
+			SessionAlert::success("Email template has been saved successfully.");
116
+
117
+			$this->redirect('emailManagement');
118
+		}
119
+		else {
120
+			$this->assignCSRFToken();
121
+			$this->assign('id', $template->getId());
122
+			$this->assign('emailTemplate', $template);
123
+			$this->assign('createdid', $createdId);
124
+			$this->assign('requeststates', $requestStates);
125
+
126
+			$this->setTemplate('email-management/edit.tpl');
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * @param EmailTemplate $template
132
+	 *
133
+	 * @throws ApplicationLogicException
134
+	 */
135
+	private function modifyTemplateData(EmailTemplate $template)
136
+	{
137
+		$name = WebRequest::postString('name');
138
+		if ($name === null || $name === '') {
139
+			throw new ApplicationLogicException('Name not specified');
140
+		}
141
+
142
+		$template->setName($name);
143
+
144
+		$text = WebRequest::postString('text');
145
+		if ($text === null || $text === '') {
146
+			throw new ApplicationLogicException('Text not specified');
147
+		}
148
+
149
+		$template->setText($text);
150
+
151
+		$template->setJsquestion(WebRequest::postString('jsquestion'));
152
+
153
+		$template->setDefaultAction(WebRequest::postString('defaultaction'));
154
+		$template->setActive(WebRequest::postBoolean('active'));
155
+		$template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
+	}
157
+
158
+	protected function create()
159
+	{
160
+		$this->setHtmlTitle('Close Emails');
161
+
162
+		$database = $this->getDatabase();
163
+
164
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
165
+
166
+		if (WebRequest::wasPosted()) {
167
+			$this->validateCSRFToken();
168
+			$template = new EmailTemplate();
169
+			$template->setDatabase($database);
170
+
171
+			$this->modifyTemplateData($template);
172
+
173
+			$other = EmailTemplate::getByName($template->getName(), $database);
174
+			if ($other !== false) {
175
+				throw new ApplicationLogicException('A template with this name already exists');
176
+			}
177
+
178
+			$template->save();
179
+
180
+			Logger::createEmail($database, $template);
181
+			$this->getNotificationHelper()->emailCreated($template);
182
+
183
+			SessionAlert::success("Email template has been saved successfully.");
184
+
185
+			$this->redirect('emailManagement');
186
+		}
187
+		else {
188
+			$this->assignCSRFToken();
189
+			$this->assign('requeststates', $requestStates);
190
+			$this->setTemplate('email-management/create.tpl');
191
+		}
192
+	}
193 193
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -115,8 +115,7 @@  discard block
 block discarded – undo
115 115
             SessionAlert::success("Email template has been saved successfully.");
116 116
 
117 117
             $this->redirect('emailManagement');
118
-        }
119
-        else {
118
+        } else {
120 119
             $this->assignCSRFToken();
121 120
             $this->assign('id', $template->getId());
122 121
             $this->assign('emailTemplate', $template);
@@ -183,8 +182,7 @@  discard block
 block discarded – undo
183 182
             SessionAlert::success("Email template has been saved successfully.");
184 183
 
185 184
             $this->redirect('emailManagement');
186
-        }
187
-        else {
185
+        } else {
188 186
             $this->assignCSRFToken();
189 187
             $this->assign('requeststates', $requestStates);
190 188
             $this->setTemplate('email-management/create.tpl');
Please login to merge, or discard this patch.
includes/Pages/PageTeam.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -12,31 +12,31 @@
 block discarded – undo
12 12
 
13 13
 class PageTeam extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
-        $json = file_get_contents($path);
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
+		$json = file_get_contents($path);
23 23
 
24
-        $teamData = json_decode($json, true);
24
+		$teamData = json_decode($json, true);
25 25
 
26
-        $active = array();
27
-        $inactive = array();
26
+		$active = array();
27
+		$inactive = array();
28 28
 
29
-        foreach ($teamData as $name => $item) {
30
-            if (count($item['Role']) == 0) {
31
-                $inactive[$name] = $item;
32
-            }
33
-            else {
34
-                $active[$name] = $item;
35
-            }
36
-        }
29
+		foreach ($teamData as $name => $item) {
30
+			if (count($item['Role']) == 0) {
31
+				$inactive[$name] = $item;
32
+			}
33
+			else {
34
+				$active[$name] = $item;
35
+			}
36
+		}
37 37
 
38
-        $this->assign('developer', $active);
39
-        $this->assign('inactiveDeveloper', $inactive);
40
-        $this->setTemplate('team/team.tpl');
41
-    }
38
+		$this->assign('developer', $active);
39
+		$this->assign('inactiveDeveloper', $inactive);
40
+		$this->setTemplate('team/team.tpl');
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,7 @@
 block discarded – undo
29 29
         foreach ($teamData as $name => $item) {
30 30
             if (count($item['Role']) == 0) {
31 31
                 $inactive[$name] = $item;
32
-            }
33
-            else {
32
+            } else {
34 33
                 $active[$name] = $item;
35 34
             }
36 35
         }
Please login to merge, or discard this patch.
includes/Pages/PageOAuth.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -17,134 +17,134 @@
 block discarded – undo
17 17
 
18 18
 class PageOAuth extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Attach entry point
22
-     *
23
-     * must be posted, or will redirect to preferences
24
-     */
25
-    protected function attach()
26
-    {
27
-        if (!WebRequest::wasPosted()) {
28
-            $this->redirect('preferences');
29
-
30
-            return;
31
-        }
32
-
33
-        $this->validateCSRFToken();
34
-
35
-        $oauthHelper = $this->getOAuthHelper();
36
-        $user = User::getCurrent($this->getDatabase());
37
-
38
-        $requestToken = $oauthHelper->getRequestToken();
39
-
40
-        $user->setOAuthRequestToken($requestToken->key);
41
-        $user->setOAuthRequestSecret($requestToken->secret);
42
-        $user->save();
43
-
44
-        $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
45
-    }
46
-
47
-    /**
48
-     * Detach account entry point
49
-     */
50
-    protected function detach()
51
-    {
52
-        if ($this->getSiteConfiguration()->getEnforceOAuth()) {
53
-            throw new AccessDeniedException($this->getSecurityManager());
54
-        }
55
-
56
-        $user = User::getCurrent($this->getDatabase());
57
-
58
-        $user->setOnWikiName($user->getOnWikiName());
59
-        $user->setOAuthAccessSecret(null);
60
-        $user->setOAuthAccessToken(null);
61
-        $user->setOAuthRequestSecret(null);
62
-        $user->setOAuthRequestToken(null);
63
-
64
-        $user->clearOAuthData();
65
-
66
-        $user->setForcelogout(true);
67
-
68
-        $user->save();
69
-
70
-        // force the user to log out
71
-        Session::destroy();
72
-
73
-        $this->redirect('login');
74
-    }
75
-
76
-    /**
77
-     * Callback entry point
78
-     */
79
-    protected function callback()
80
-    {
81
-        $oauthToken = WebRequest::getString('oauth_token');
82
-        $oauthVerifier = WebRequest::getString('oauth_verifier');
83
-
84
-        $this->doCallbackValidation($oauthToken, $oauthVerifier);
85
-
86
-        $user = User::getByRequestToken($oauthToken, $this->getDatabase());
87
-        if ($user === false) {
88
-            throw new ApplicationLogicException('Token not found in store, please try again');
89
-        }
90
-
91
-        $accessToken = $this->getOAuthHelper()->callbackCompleted(
92
-            $user->getOAuthRequestToken(),
93
-            $user->getOAuthRequestSecret(),
94
-            $oauthVerifier);
95
-
96
-        $user->setOAuthRequestSecret(null);
97
-        $user->setOAuthRequestToken(null);
98
-        $user->setOAuthAccessToken($accessToken->key);
99
-        $user->setOAuthAccessSecret($accessToken->secret);
100
-
101
-        // @todo we really should stop doing this kind of thing... it adds performance bottlenecks and breaks 3NF
102
-        $user->setOnWikiName('##OAUTH##');
103
-
104
-        $user->save();
105
-
106
-        // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the
107
-        // login to a full login
108
-        if (WebRequest::getPartialLogin() === $user->getId()) {
109
-            WebRequest::setLoggedInUser($user);
110
-        }
111
-
112
-        // My thinking is there are three cases here:
113
-        //   a) new user => redirect to prefs - it's the only thing they can access other than stats
114
-        //   b) existing user hit the connect button in prefs => redirect to prefs since it's where they were
115
-        //   c) existing user logging in => redirect to wherever they came from
116
-        $redirectDestination = WebRequest::clearPostLoginRedirect();
117
-        if ($redirectDestination !== null && !$user->isNewUser()) {
118
-            $this->redirectUrl($redirectDestination);
119
-        }
120
-        else {
121
-            $this->redirect('preferences', null, null, 'internal.php');
122
-        }
123
-    }
124
-
125
-    /**
126
-     * Main function for this page, when no specific actions are called.
127
-     * @return void
128
-     */
129
-    protected function main()
130
-    {
131
-        $this->redirect('preferences');
132
-    }
133
-
134
-    /**
135
-     * @param string $oauthToken
136
-     * @param string $oauthVerifier
137
-     *
138
-     * @throws ApplicationLogicException
139
-     */
140
-    protected function doCallbackValidation($oauthToken, $oauthVerifier)
141
-    {
142
-        if ($oauthToken === null) {
143
-            throw new ApplicationLogicException('No token provided');
144
-        }
145
-
146
-        if ($oauthVerifier === null) {
147
-            throw new ApplicationLogicException('No oauth verifier provided.');
148
-        }
149
-    }
20
+	/**
21
+	 * Attach entry point
22
+	 *
23
+	 * must be posted, or will redirect to preferences
24
+	 */
25
+	protected function attach()
26
+	{
27
+		if (!WebRequest::wasPosted()) {
28
+			$this->redirect('preferences');
29
+
30
+			return;
31
+		}
32
+
33
+		$this->validateCSRFToken();
34
+
35
+		$oauthHelper = $this->getOAuthHelper();
36
+		$user = User::getCurrent($this->getDatabase());
37
+
38
+		$requestToken = $oauthHelper->getRequestToken();
39
+
40
+		$user->setOAuthRequestToken($requestToken->key);
41
+		$user->setOAuthRequestSecret($requestToken->secret);
42
+		$user->save();
43
+
44
+		$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
45
+	}
46
+
47
+	/**
48
+	 * Detach account entry point
49
+	 */
50
+	protected function detach()
51
+	{
52
+		if ($this->getSiteConfiguration()->getEnforceOAuth()) {
53
+			throw new AccessDeniedException($this->getSecurityManager());
54
+		}
55
+
56
+		$user = User::getCurrent($this->getDatabase());
57
+
58
+		$user->setOnWikiName($user->getOnWikiName());
59
+		$user->setOAuthAccessSecret(null);
60
+		$user->setOAuthAccessToken(null);
61
+		$user->setOAuthRequestSecret(null);
62
+		$user->setOAuthRequestToken(null);
63
+
64
+		$user->clearOAuthData();
65
+
66
+		$user->setForcelogout(true);
67
+
68
+		$user->save();
69
+
70
+		// force the user to log out
71
+		Session::destroy();
72
+
73
+		$this->redirect('login');
74
+	}
75
+
76
+	/**
77
+	 * Callback entry point
78
+	 */
79
+	protected function callback()
80
+	{
81
+		$oauthToken = WebRequest::getString('oauth_token');
82
+		$oauthVerifier = WebRequest::getString('oauth_verifier');
83
+
84
+		$this->doCallbackValidation($oauthToken, $oauthVerifier);
85
+
86
+		$user = User::getByRequestToken($oauthToken, $this->getDatabase());
87
+		if ($user === false) {
88
+			throw new ApplicationLogicException('Token not found in store, please try again');
89
+		}
90
+
91
+		$accessToken = $this->getOAuthHelper()->callbackCompleted(
92
+			$user->getOAuthRequestToken(),
93
+			$user->getOAuthRequestSecret(),
94
+			$oauthVerifier);
95
+
96
+		$user->setOAuthRequestSecret(null);
97
+		$user->setOAuthRequestToken(null);
98
+		$user->setOAuthAccessToken($accessToken->key);
99
+		$user->setOAuthAccessSecret($accessToken->secret);
100
+
101
+		// @todo we really should stop doing this kind of thing... it adds performance bottlenecks and breaks 3NF
102
+		$user->setOnWikiName('##OAUTH##');
103
+
104
+		$user->save();
105
+
106
+		// OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the
107
+		// login to a full login
108
+		if (WebRequest::getPartialLogin() === $user->getId()) {
109
+			WebRequest::setLoggedInUser($user);
110
+		}
111
+
112
+		// My thinking is there are three cases here:
113
+		//   a) new user => redirect to prefs - it's the only thing they can access other than stats
114
+		//   b) existing user hit the connect button in prefs => redirect to prefs since it's where they were
115
+		//   c) existing user logging in => redirect to wherever they came from
116
+		$redirectDestination = WebRequest::clearPostLoginRedirect();
117
+		if ($redirectDestination !== null && !$user->isNewUser()) {
118
+			$this->redirectUrl($redirectDestination);
119
+		}
120
+		else {
121
+			$this->redirect('preferences', null, null, 'internal.php');
122
+		}
123
+	}
124
+
125
+	/**
126
+	 * Main function for this page, when no specific actions are called.
127
+	 * @return void
128
+	 */
129
+	protected function main()
130
+	{
131
+		$this->redirect('preferences');
132
+	}
133
+
134
+	/**
135
+	 * @param string $oauthToken
136
+	 * @param string $oauthVerifier
137
+	 *
138
+	 * @throws ApplicationLogicException
139
+	 */
140
+	protected function doCallbackValidation($oauthToken, $oauthVerifier)
141
+	{
142
+		if ($oauthToken === null) {
143
+			throw new ApplicationLogicException('No token provided');
144
+		}
145
+
146
+		if ($oauthVerifier === null) {
147
+			throw new ApplicationLogicException('No oauth verifier provided.');
148
+		}
149
+	}
150 150
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -116,8 +116,7 @@
 block discarded – undo
116 116
         $redirectDestination = WebRequest::clearPostLoginRedirect();
117 117
         if ($redirectDestination !== null && !$user->isNewUser()) {
118 118
             $this->redirectUrl($redirectDestination);
119
-        }
120
-        else {
119
+        } else {
121 120
             $this->redirect('preferences', null, null, 'internal.php');
122 121
         }
123 122
     }
Please login to merge, or discard this patch.
includes/Pages/PageMain.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -17,71 +17,71 @@  discard block
 block discarded – undo
17 17
 
18 18
 class PageMain extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no actions are called.
22
-     */
23
-    protected function main()
24
-    {
25
-        $this->assignCSRFToken();
26
-
27
-        $config = $this->getSiteConfiguration();
28
-
29
-        $database = $this->getDatabase();
30
-
31
-        $requestSectionData = array();
32
-
33
-        if ($config->getEmailConfirmationEnabled()) {
34
-            $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed' LIMIT :lim;";
35
-            $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';";
36
-        }
37
-        else {
38
-            $query = "SELECT * FROM request WHERE status = :type LIMIT :lim;";
39
-            $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;";
40
-        }
41
-
42
-        $statement = $database->prepare($query);
43
-        $statement->bindValue(':lim', $config->getMiserModeLimit(), PDO::PARAM_INT);
44
-
45
-        $totalRequestsStatement = $database->prepare($totalQuery);
46
-
47
-        $this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
48
-
49
-        foreach ($config->getRequestStates() as $type => $v) {
50
-            $statement->bindValue(":type", $type);
51
-            $statement->execute();
52
-
53
-            $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class);
54
-
55
-            /** @var Request $req */
56
-            foreach ($requests as $req) {
57
-                $req->setDatabase($database);
58
-            }
59
-
60
-            $totalRequestsStatement->bindValue(':type', $type);
61
-            $totalRequestsStatement->execute();
62
-            $totalRequests = $totalRequestsStatement->fetchColumn();
63
-            $totalRequestsStatement->closeCursor();
64
-
65
-            $userIds = array_map(
66
-                function(Request $entry) {
67
-                    return $entry->getReserved();
68
-                },
69
-                $requests);
70
-            $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
71
-            $this->assign('userlist', $userList);
72
-
73
-            $requestSectionData[$v['header']] = array(
74
-                'requests' => $requests,
75
-                'total'    => $totalRequests,
76
-                'api'      => $v['api'],
77
-                'type'     => $type,
78
-                'userlist' => $userList,
79
-            );
80
-        }
81
-
82
-        $this->assign('requestLimitShowOnly', $config->getMiserModeLimit());
83
-
84
-        $query = <<<SQL
20
+	/**
21
+	 * Main function for this page, when no actions are called.
22
+	 */
23
+	protected function main()
24
+	{
25
+		$this->assignCSRFToken();
26
+
27
+		$config = $this->getSiteConfiguration();
28
+
29
+		$database = $this->getDatabase();
30
+
31
+		$requestSectionData = array();
32
+
33
+		if ($config->getEmailConfirmationEnabled()) {
34
+			$query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed' LIMIT :lim;";
35
+			$totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';";
36
+		}
37
+		else {
38
+			$query = "SELECT * FROM request WHERE status = :type LIMIT :lim;";
39
+			$totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;";
40
+		}
41
+
42
+		$statement = $database->prepare($query);
43
+		$statement->bindValue(':lim', $config->getMiserModeLimit(), PDO::PARAM_INT);
44
+
45
+		$totalRequestsStatement = $database->prepare($totalQuery);
46
+
47
+		$this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
48
+
49
+		foreach ($config->getRequestStates() as $type => $v) {
50
+			$statement->bindValue(":type", $type);
51
+			$statement->execute();
52
+
53
+			$requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class);
54
+
55
+			/** @var Request $req */
56
+			foreach ($requests as $req) {
57
+				$req->setDatabase($database);
58
+			}
59
+
60
+			$totalRequestsStatement->bindValue(':type', $type);
61
+			$totalRequestsStatement->execute();
62
+			$totalRequests = $totalRequestsStatement->fetchColumn();
63
+			$totalRequestsStatement->closeCursor();
64
+
65
+			$userIds = array_map(
66
+				function(Request $entry) {
67
+					return $entry->getReserved();
68
+				},
69
+				$requests);
70
+			$userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
71
+			$this->assign('userlist', $userList);
72
+
73
+			$requestSectionData[$v['header']] = array(
74
+				'requests' => $requests,
75
+				'total'    => $totalRequests,
76
+				'api'      => $v['api'],
77
+				'type'     => $type,
78
+				'userlist' => $userList,
79
+			);
80
+		}
81
+
82
+		$this->assign('requestLimitShowOnly', $config->getMiserModeLimit());
83
+
84
+		$query = <<<SQL
85 85
 		SELECT request.id, request.name, request.updateversion
86 86
 		FROM request /* PageMain::main() */
87 87
 		JOIN log ON log.objectid = request.id AND log.objecttype = 'Request'
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		LIMIT 5;
91 91
 SQL;
92 92
 
93
-        $statement = $database->prepare($query);
94
-        $statement->execute();
93
+		$statement = $database->prepare($query);
94
+		$statement->execute();
95 95
 
96
-        $last5result = $statement->fetchAll(PDO::FETCH_ASSOC);
96
+		$last5result = $statement->fetchAll(PDO::FETCH_ASSOC);
97 97
 
98
-        $this->assign('lastFive', $last5result);
99
-        $this->assign('requestSectionData', $requestSectionData);
98
+		$this->assign('lastFive', $last5result);
99
+		$this->assign('requestSectionData', $requestSectionData);
100 100
 
101
-        $currentUser = User::getCurrent($database);
102
-        $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
103
-        $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
101
+		$currentUser = User::getCurrent($database);
102
+		$this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
103
+		$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
104 104
 
105
-        $this->setTemplate('mainpage/mainpage.tpl');
106
-    }
105
+		$this->setTemplate('mainpage/mainpage.tpl');
106
+	}
107 107
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,8 +33,7 @@  discard block
 block discarded – undo
33 33
         if ($config->getEmailConfirmationEnabled()) {
34 34
             $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed' LIMIT :lim;";
35 35
             $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';";
36
-        }
37
-        else {
36
+        } else {
38 37
             $query = "SELECT * FROM request WHERE status = :type LIMIT :lim;";
39 38
             $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;";
40 39
         }
@@ -63,7 +62,8 @@  discard block
 block discarded – undo
63 62
             $totalRequestsStatement->closeCursor();
64 63
 
65 64
             $userIds = array_map(
66
-                function(Request $entry) {
65
+                function(Request $entry)
66
+                {
67 67
                     return $entry->getReserved();
68 68
                 },
69 69
                 $requests);
Please login to merge, or discard this patch.
includes/Pages/PageUserManagement.php 2 patches
Indentation   +529 added lines, -529 removed lines patch added patch discarded remove patch
@@ -23,533 +23,533 @@
 block discarded – undo
23 23
  */
24 24
 class PageUserManagement extends InternalPageBase
25 25
 {
26
-    /** @var string */
27
-    private $adminMailingList = '[email protected]';
28
-
29
-    /**
30
-     * Main function for this page, when no specific actions are called.
31
-     */
32
-    protected function main()
33
-    {
34
-        $this->setHtmlTitle('User Management');
35
-
36
-        $database = $this->getDatabase();
37
-        $currentUser = User::getCurrent($database);
38
-
39
-        if (WebRequest::getBoolean("showAll")) {
40
-            $this->assign("showAll", true);
41
-
42
-            $this->assign("suspendedUsers",
43
-                UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch());
44
-            $this->assign("declinedUsers", UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch());
45
-
46
-            UserSearchHelper::get($database)->getRoleMap($roleMap);
47
-        }
48
-        else {
49
-            $this->assign("showAll", false);
50
-            $this->assign("suspendedUsers", array());
51
-            $this->assign("declinedUsers", array());
52
-
53
-            UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
54
-        }
55
-
56
-        $this->assign('newUsers', UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch());
57
-        $this->assign('normalUsers',
58
-            UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch());
59
-        $this->assign('adminUsers',
60
-            UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch());
61
-        $this->assign('checkUsers',
62
-            UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch());
63
-        $this->assign('toolRoots',
64
-            UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch());
65
-
66
-        $this->assign('roles', $roleMap);
67
-
68
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
69
-            return UserSearchHelper::get($database)->fetchColumn('username');
70
-        });
71
-
72
-        $this->assign('canApprove', $this->barrierTest('approve', $currentUser));
73
-        $this->assign('canDecline', $this->barrierTest('decline', $currentUser));
74
-        $this->assign('canRename', $this->barrierTest('rename', $currentUser));
75
-        $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
76
-        $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser));
77
-        $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
78
-
79
-        $this->setTemplate("usermanagement/main.tpl");
80
-    }
81
-
82
-    #region Access control
83
-
84
-    /**
85
-     * Action target for editing the roles assigned to a user
86
-     */
87
-    protected function editRoles()
88
-    {
89
-        $this->setHtmlTitle('User Management');
90
-        $database = $this->getDatabase();
91
-        $userId = WebRequest::getInt('user');
92
-
93
-        /** @var User $user */
94
-        $user = User::getById($userId, $database);
95
-
96
-        if ($user === false) {
97
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
98
-        }
99
-
100
-        $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database));
101
-
102
-        // Dual-mode action
103
-        if (WebRequest::wasPosted()) {
104
-            $this->validateCSRFToken();
105
-
106
-            $reason = WebRequest::postString('reason');
107
-            if ($reason === false || trim($reason) === '') {
108
-                throw new ApplicationLogicException('No reason specified for roles change');
109
-            }
110
-
111
-            /** @var UserRole[] $delete */
112
-            $delete = array();
113
-            /** @var string[] $delete */
114
-            $add = array();
115
-
116
-            foreach ($roleData as $name => $r) {
117
-                if ($r['allowEdit'] !== 1) {
118
-                    // not allowed, to touch this, so ignore it
119
-                    continue;
120
-                }
121
-
122
-                $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
123
-                if ($newValue !== $r['active']) {
124
-                    if ($newValue === 0) {
125
-                        $delete[] = $r['object'];
126
-                    }
127
-
128
-                    if ($newValue === 1) {
129
-                        $add[] = $name;
130
-                    }
131
-                }
132
-            }
133
-
134
-            // Check there's something to do
135
-            if ((count($add) + count($delete)) === 0) {
136
-                $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
137
-                SessionAlert::warning('No changes made to roles.');
138
-
139
-                return;
140
-            }
141
-
142
-            $removed = array();
143
-
144
-            /** @var UserRole $d */
145
-            foreach ($delete as $d) {
146
-                $removed[] = $d->getRole();
147
-                $d->delete();
148
-            }
149
-
150
-            foreach ($add as $x) {
151
-                $a = new UserRole();
152
-                $a->setUser($user->getId());
153
-                $a->setRole($x);
154
-                $a->setDatabase($database);
155
-                $a->save();
156
-            }
157
-
158
-            Logger::userRolesEdited($database, $user, $reason, $add, $removed);
159
-
160
-            // dummy save for optimistic locking. If this fails, the entire txn will roll back.
161
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
162
-            $user->save();
163
-
164
-            $this->getNotificationHelper()->userRolesEdited($user, $reason);
165
-            SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
166
-
167
-            $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
168
-            return;
169
-        }
170
-        else {
171
-            $this->assignCSRFToken();
172
-            $this->setTemplate('usermanagement/roleedit.tpl');
173
-            $this->assign('user', $user);
174
-            $this->assign('roleData', $roleData);
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Action target for suspending users
180
-     *
181
-     * @throws ApplicationLogicException
182
-     */
183
-    protected function suspend()
184
-    {
185
-        $this->setHtmlTitle('User Management');
186
-
187
-        $database = $this->getDatabase();
188
-
189
-        $userId = WebRequest::getInt('user');
190
-
191
-        /** @var User $user */
192
-        $user = User::getById($userId, $database);
193
-
194
-        if ($user === false) {
195
-            throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.');
196
-        }
197
-
198
-        if ($user->isSuspended()) {
199
-            throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.');
200
-        }
201
-
202
-        // Dual-mode action
203
-        if (WebRequest::wasPosted()) {
204
-            $this->validateCSRFToken();
205
-            $reason = WebRequest::postString('reason');
206
-
207
-            if ($reason === null || trim($reason) === "") {
208
-                throw new ApplicationLogicException('No reason provided');
209
-            }
210
-
211
-            $user->setStatus(User::STATUS_SUSPENDED);
212
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
213
-            $user->save();
214
-            Logger::suspendedUser($database, $user, $reason);
215
-
216
-            $this->getNotificationHelper()->userSuspended($user, $reason);
217
-            SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
218
-
219
-            // send email
220
-            $this->sendStatusChangeEmail(
221
-                'Your WP:ACC account has been suspended',
222
-                'usermanagement/emails/suspended.tpl',
223
-                $reason,
224
-                $user,
225
-                User::getCurrent($database)->getUsername()
226
-            );
227
-
228
-            $this->redirect('userManagement');
229
-
230
-            return;
231
-        }
232
-        else {
233
-            $this->assignCSRFToken();
234
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
235
-            $this->assign('user', $user);
236
-            $this->assign('status', 'Suspended');
237
-            $this->assign("showReason", true);
238
-        }
239
-    }
240
-
241
-    /**
242
-     * Entry point for the decline action
243
-     *
244
-     * @throws ApplicationLogicException
245
-     */
246
-    protected function decline()
247
-    {
248
-        $this->setHtmlTitle('User Management');
249
-
250
-        $database = $this->getDatabase();
251
-
252
-        $userId = WebRequest::getInt('user');
253
-        $user = User::getById($userId, $database);
254
-
255
-        if ($user === false) {
256
-            throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.');
257
-        }
258
-
259
-        if (!$user->isNewUser()) {
260
-            throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.');
261
-        }
262
-
263
-        // Dual-mode action
264
-        if (WebRequest::wasPosted()) {
265
-            $this->validateCSRFToken();
266
-            $reason = WebRequest::postString('reason');
267
-
268
-            if ($reason === null || trim($reason) === "") {
269
-                throw new ApplicationLogicException('No reason provided');
270
-            }
271
-
272
-            $user->setStatus(User::STATUS_DECLINED);
273
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
274
-            $user->save();
275
-            Logger::declinedUser($database, $user, $reason);
276
-
277
-            $this->getNotificationHelper()->userDeclined($user, $reason);
278
-            SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
279
-
280
-            // send email
281
-            $this->sendStatusChangeEmail(
282
-                'Your WP:ACC account has been declined',
283
-                'usermanagement/emails/declined.tpl',
284
-                $reason,
285
-                $user,
286
-                User::getCurrent($database)->getUsername()
287
-            );
288
-
289
-            $this->redirect('userManagement');
290
-
291
-            return;
292
-        }
293
-        else {
294
-            $this->assignCSRFToken();
295
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
296
-            $this->assign('user', $user);
297
-            $this->assign('status', 'Declined');
298
-            $this->assign("showReason", true);
299
-        }
300
-    }
301
-
302
-    /**
303
-     * Entry point for the approve action
304
-     *
305
-     * @throws ApplicationLogicException
306
-     */
307
-    protected function approve()
308
-    {
309
-        $this->setHtmlTitle('User Management');
310
-
311
-        $database = $this->getDatabase();
312
-
313
-        $userId = WebRequest::getInt('user');
314
-        $user = User::getById($userId, $database);
315
-
316
-        if ($user === false) {
317
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
318
-        }
319
-
320
-        if ($user->isActive()) {
321
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
322
-        }
323
-
324
-        // Dual-mode action
325
-        if (WebRequest::wasPosted()) {
326
-            $this->validateCSRFToken();
327
-            $user->setStatus(User::STATUS_ACTIVE);
328
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
329
-            $user->save();
330
-            Logger::approvedUser($database, $user);
331
-
332
-            $this->getNotificationHelper()->userApproved($user);
333
-            SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
334
-
335
-            // send email
336
-            $this->sendStatusChangeEmail(
337
-                'Your WP:ACC account has been approved',
338
-                'usermanagement/emails/approved.tpl',
339
-                null,
340
-                $user,
341
-                User::getCurrent($database)->getUsername()
342
-            );
343
-
344
-            $this->redirect("userManagement");
345
-
346
-            return;
347
-        }
348
-        else {
349
-            $this->assignCSRFToken();
350
-            $this->setTemplate("usermanagement/changelevel-reason.tpl");
351
-            $this->assign("user", $user);
352
-            $this->assign("status", "User");
353
-            $this->assign("showReason", false);
354
-        }
355
-    }
356
-
357
-    #endregion
358
-
359
-    #region Renaming / Editing
360
-
361
-    /**
362
-     * Entry point for the rename action
363
-     *
364
-     * @throws ApplicationLogicException
365
-     */
366
-    protected function rename()
367
-    {
368
-        $this->setHtmlTitle('User Management');
369
-
370
-        $database = $this->getDatabase();
371
-
372
-        $userId = WebRequest::getInt('user');
373
-        $user = User::getById($userId, $database);
374
-
375
-        if ($user === false) {
376
-            throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
377
-        }
378
-
379
-        // Dual-mode action
380
-        if (WebRequest::wasPosted()) {
381
-            $this->validateCSRFToken();
382
-            $newUsername = WebRequest::postString('newname');
383
-
384
-            if ($newUsername === null || trim($newUsername) === "") {
385
-                throw new ApplicationLogicException('The new username cannot be empty');
386
-            }
387
-
388
-            if (User::getByUsername($newUsername, $database) != false) {
389
-                throw new ApplicationLogicException('The new username already exists');
390
-            }
391
-
392
-            $oldUsername = $user->getUsername();
393
-            $user->setUsername($newUsername);
394
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
395
-
396
-            $user->save();
397
-
398
-            $logEntryData = serialize(array(
399
-                'old' => $oldUsername,
400
-                'new' => $newUsername,
401
-            ));
402
-
403
-            Logger::renamedUser($database, $user, $logEntryData);
404
-
405
-            SessionAlert::quick("Changed User "
406
-                . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
407
-                . " name to "
408
-                . htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
409
-
410
-            $this->getNotificationHelper()->userRenamed($user, $oldUsername);
411
-
412
-            // send an email to the user.
413
-            $this->assign('targetUsername', $user->getUsername());
414
-            $this->assign('toolAdmin', User::getCurrent($database)->getUsername());
415
-            $this->assign('oldUsername', $oldUsername);
416
-            $this->assign('mailingList', $this->adminMailingList);
417
-
418
-            $this->getEmailHelper()->sendMail(
419
-                $user->getEmail(),
420
-                'Your username on WP:ACC has been changed',
421
-                $this->fetchTemplate('usermanagement/emails/renamed.tpl'),
422
-                array('Reply-To' => $this->adminMailingList)
423
-            );
424
-
425
-            $this->redirect("userManagement");
426
-
427
-            return;
428
-        }
429
-        else {
430
-            $this->assignCSRFToken();
431
-            $this->setTemplate('usermanagement/renameuser.tpl');
432
-            $this->assign('user', $user);
433
-        }
434
-    }
435
-
436
-    /**
437
-     * Entry point for the edit action
438
-     *
439
-     * @throws ApplicationLogicException
440
-     */
441
-    protected function editUser()
442
-    {
443
-        $this->setHtmlTitle('User Management');
444
-
445
-        $database = $this->getDatabase();
446
-
447
-        $userId = WebRequest::getInt('user');
448
-        $user = User::getById($userId, $database);
449
-
450
-        if ($user === false) {
451
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
452
-        }
453
-
454
-        // Dual-mode action
455
-        if (WebRequest::wasPosted()) {
456
-            $this->validateCSRFToken();
457
-            $newEmail = WebRequest::postEmail('user_email');
458
-            $newOnWikiName = WebRequest::postString('user_onwikiname');
459
-
460
-            if ($newEmail === null) {
461
-                throw new ApplicationLogicException('Invalid email address');
462
-            }
463
-
464
-            if (!$user->isOAuthLinked()) {
465
-                if (trim($newOnWikiName) == "") {
466
-                    throw new ApplicationLogicException('New on-wiki username cannot be blank');
467
-                }
468
-
469
-                $user->setOnWikiName($newOnWikiName);
470
-            }
471
-
472
-            $user->setEmail($newEmail);
473
-
474
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
475
-
476
-            $user->save();
477
-
478
-            Logger::userPreferencesChange($database, $user);
479
-            $this->getNotificationHelper()->userPrefChange($user);
480
-            SessionAlert::quick('Changes to user\'s preferences have been saved');
481
-
482
-            $this->redirect("userManagement");
483
-
484
-            return;
485
-        }
486
-        else {
487
-            $this->assignCSRFToken();
488
-            $this->setTemplate('usermanagement/edituser.tpl');
489
-            $this->assign('user', $user);
490
-        }
491
-    }
492
-
493
-    #endregion
494
-
495
-    /**
496
-     * Sends a status change email to the user.
497
-     *
498
-     * @param string      $subject           The subject of the email
499
-     * @param string      $template          The smarty template to use
500
-     * @param string|null $reason            The reason for performing the status change
501
-     * @param User        $user              The user affected
502
-     * @param string      $toolAdminUsername The tool admin's username who is making the edit
503
-     */
504
-    private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
505
-    {
506
-        $this->assign('targetUsername', $user->getUsername());
507
-        $this->assign('toolAdmin', $toolAdminUsername);
508
-        $this->assign('actionReason', $reason);
509
-        $this->assign('mailingList', $this->adminMailingList);
510
-
511
-        $this->getEmailHelper()->sendMail(
512
-            $user->getEmail(),
513
-            $subject,
514
-            $this->fetchTemplate($template),
515
-            array('Reply-To' => $this->adminMailingList)
516
-        );
517
-    }
518
-
519
-    /**
520
-     * @param UserRole[] $activeRoles
521
-     *
522
-     * @return array
523
-     */
524
-    private function getRoleData($activeRoles)
525
-    {
526
-        $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles();
527
-
528
-        $currentUser = User::getCurrent($this->getDatabase());
529
-        $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
530
-
531
-        $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
532
-
533
-        $roleData = array();
534
-        foreach ($availableRoles as $role => $data) {
535
-            $intersection = array_intersect($data['editableBy'], $userRoles);
536
-
537
-            $roleData[$role] = $initialValue;
538
-            $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
539
-            $roleData[$role]['description'] = $data['description'];
540
-        }
541
-
542
-        foreach ($activeRoles as $role) {
543
-            if (!isset($roleData[$role->getRole()])) {
544
-                // This value is no longer available in the configuration, allow changing (aka removing) it.
545
-                $roleData[$role->getRole()] = $initialValue;
546
-                $roleData[$role->getRole()]['allowEdit'] = 1;
547
-            }
548
-
549
-            $roleData[$role->getRole()]['object'] = $role;
550
-            $roleData[$role->getRole()]['active'] = 1;
551
-        }
552
-
553
-        return $roleData;
554
-    }
26
+	/** @var string */
27
+	private $adminMailingList = '[email protected]';
28
+
29
+	/**
30
+	 * Main function for this page, when no specific actions are called.
31
+	 */
32
+	protected function main()
33
+	{
34
+		$this->setHtmlTitle('User Management');
35
+
36
+		$database = $this->getDatabase();
37
+		$currentUser = User::getCurrent($database);
38
+
39
+		if (WebRequest::getBoolean("showAll")) {
40
+			$this->assign("showAll", true);
41
+
42
+			$this->assign("suspendedUsers",
43
+				UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch());
44
+			$this->assign("declinedUsers", UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch());
45
+
46
+			UserSearchHelper::get($database)->getRoleMap($roleMap);
47
+		}
48
+		else {
49
+			$this->assign("showAll", false);
50
+			$this->assign("suspendedUsers", array());
51
+			$this->assign("declinedUsers", array());
52
+
53
+			UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
54
+		}
55
+
56
+		$this->assign('newUsers', UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch());
57
+		$this->assign('normalUsers',
58
+			UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch());
59
+		$this->assign('adminUsers',
60
+			UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch());
61
+		$this->assign('checkUsers',
62
+			UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch());
63
+		$this->assign('toolRoots',
64
+			UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch());
65
+
66
+		$this->assign('roles', $roleMap);
67
+
68
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
69
+			return UserSearchHelper::get($database)->fetchColumn('username');
70
+		});
71
+
72
+		$this->assign('canApprove', $this->barrierTest('approve', $currentUser));
73
+		$this->assign('canDecline', $this->barrierTest('decline', $currentUser));
74
+		$this->assign('canRename', $this->barrierTest('rename', $currentUser));
75
+		$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
76
+		$this->assign('canSuspend', $this->barrierTest('suspend', $currentUser));
77
+		$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
78
+
79
+		$this->setTemplate("usermanagement/main.tpl");
80
+	}
81
+
82
+	#region Access control
83
+
84
+	/**
85
+	 * Action target for editing the roles assigned to a user
86
+	 */
87
+	protected function editRoles()
88
+	{
89
+		$this->setHtmlTitle('User Management');
90
+		$database = $this->getDatabase();
91
+		$userId = WebRequest::getInt('user');
92
+
93
+		/** @var User $user */
94
+		$user = User::getById($userId, $database);
95
+
96
+		if ($user === false) {
97
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
98
+		}
99
+
100
+		$roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database));
101
+
102
+		// Dual-mode action
103
+		if (WebRequest::wasPosted()) {
104
+			$this->validateCSRFToken();
105
+
106
+			$reason = WebRequest::postString('reason');
107
+			if ($reason === false || trim($reason) === '') {
108
+				throw new ApplicationLogicException('No reason specified for roles change');
109
+			}
110
+
111
+			/** @var UserRole[] $delete */
112
+			$delete = array();
113
+			/** @var string[] $delete */
114
+			$add = array();
115
+
116
+			foreach ($roleData as $name => $r) {
117
+				if ($r['allowEdit'] !== 1) {
118
+					// not allowed, to touch this, so ignore it
119
+					continue;
120
+				}
121
+
122
+				$newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
123
+				if ($newValue !== $r['active']) {
124
+					if ($newValue === 0) {
125
+						$delete[] = $r['object'];
126
+					}
127
+
128
+					if ($newValue === 1) {
129
+						$add[] = $name;
130
+					}
131
+				}
132
+			}
133
+
134
+			// Check there's something to do
135
+			if ((count($add) + count($delete)) === 0) {
136
+				$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
137
+				SessionAlert::warning('No changes made to roles.');
138
+
139
+				return;
140
+			}
141
+
142
+			$removed = array();
143
+
144
+			/** @var UserRole $d */
145
+			foreach ($delete as $d) {
146
+				$removed[] = $d->getRole();
147
+				$d->delete();
148
+			}
149
+
150
+			foreach ($add as $x) {
151
+				$a = new UserRole();
152
+				$a->setUser($user->getId());
153
+				$a->setRole($x);
154
+				$a->setDatabase($database);
155
+				$a->save();
156
+			}
157
+
158
+			Logger::userRolesEdited($database, $user, $reason, $add, $removed);
159
+
160
+			// dummy save for optimistic locking. If this fails, the entire txn will roll back.
161
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
162
+			$user->save();
163
+
164
+			$this->getNotificationHelper()->userRolesEdited($user, $reason);
165
+			SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
166
+
167
+			$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
168
+			return;
169
+		}
170
+		else {
171
+			$this->assignCSRFToken();
172
+			$this->setTemplate('usermanagement/roleedit.tpl');
173
+			$this->assign('user', $user);
174
+			$this->assign('roleData', $roleData);
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Action target for suspending users
180
+	 *
181
+	 * @throws ApplicationLogicException
182
+	 */
183
+	protected function suspend()
184
+	{
185
+		$this->setHtmlTitle('User Management');
186
+
187
+		$database = $this->getDatabase();
188
+
189
+		$userId = WebRequest::getInt('user');
190
+
191
+		/** @var User $user */
192
+		$user = User::getById($userId, $database);
193
+
194
+		if ($user === false) {
195
+			throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.');
196
+		}
197
+
198
+		if ($user->isSuspended()) {
199
+			throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.');
200
+		}
201
+
202
+		// Dual-mode action
203
+		if (WebRequest::wasPosted()) {
204
+			$this->validateCSRFToken();
205
+			$reason = WebRequest::postString('reason');
206
+
207
+			if ($reason === null || trim($reason) === "") {
208
+				throw new ApplicationLogicException('No reason provided');
209
+			}
210
+
211
+			$user->setStatus(User::STATUS_SUSPENDED);
212
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
213
+			$user->save();
214
+			Logger::suspendedUser($database, $user, $reason);
215
+
216
+			$this->getNotificationHelper()->userSuspended($user, $reason);
217
+			SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
218
+
219
+			// send email
220
+			$this->sendStatusChangeEmail(
221
+				'Your WP:ACC account has been suspended',
222
+				'usermanagement/emails/suspended.tpl',
223
+				$reason,
224
+				$user,
225
+				User::getCurrent($database)->getUsername()
226
+			);
227
+
228
+			$this->redirect('userManagement');
229
+
230
+			return;
231
+		}
232
+		else {
233
+			$this->assignCSRFToken();
234
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
235
+			$this->assign('user', $user);
236
+			$this->assign('status', 'Suspended');
237
+			$this->assign("showReason", true);
238
+		}
239
+	}
240
+
241
+	/**
242
+	 * Entry point for the decline action
243
+	 *
244
+	 * @throws ApplicationLogicException
245
+	 */
246
+	protected function decline()
247
+	{
248
+		$this->setHtmlTitle('User Management');
249
+
250
+		$database = $this->getDatabase();
251
+
252
+		$userId = WebRequest::getInt('user');
253
+		$user = User::getById($userId, $database);
254
+
255
+		if ($user === false) {
256
+			throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.');
257
+		}
258
+
259
+		if (!$user->isNewUser()) {
260
+			throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.');
261
+		}
262
+
263
+		// Dual-mode action
264
+		if (WebRequest::wasPosted()) {
265
+			$this->validateCSRFToken();
266
+			$reason = WebRequest::postString('reason');
267
+
268
+			if ($reason === null || trim($reason) === "") {
269
+				throw new ApplicationLogicException('No reason provided');
270
+			}
271
+
272
+			$user->setStatus(User::STATUS_DECLINED);
273
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
274
+			$user->save();
275
+			Logger::declinedUser($database, $user, $reason);
276
+
277
+			$this->getNotificationHelper()->userDeclined($user, $reason);
278
+			SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
279
+
280
+			// send email
281
+			$this->sendStatusChangeEmail(
282
+				'Your WP:ACC account has been declined',
283
+				'usermanagement/emails/declined.tpl',
284
+				$reason,
285
+				$user,
286
+				User::getCurrent($database)->getUsername()
287
+			);
288
+
289
+			$this->redirect('userManagement');
290
+
291
+			return;
292
+		}
293
+		else {
294
+			$this->assignCSRFToken();
295
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
296
+			$this->assign('user', $user);
297
+			$this->assign('status', 'Declined');
298
+			$this->assign("showReason", true);
299
+		}
300
+	}
301
+
302
+	/**
303
+	 * Entry point for the approve action
304
+	 *
305
+	 * @throws ApplicationLogicException
306
+	 */
307
+	protected function approve()
308
+	{
309
+		$this->setHtmlTitle('User Management');
310
+
311
+		$database = $this->getDatabase();
312
+
313
+		$userId = WebRequest::getInt('user');
314
+		$user = User::getById($userId, $database);
315
+
316
+		if ($user === false) {
317
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
318
+		}
319
+
320
+		if ($user->isActive()) {
321
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
322
+		}
323
+
324
+		// Dual-mode action
325
+		if (WebRequest::wasPosted()) {
326
+			$this->validateCSRFToken();
327
+			$user->setStatus(User::STATUS_ACTIVE);
328
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
329
+			$user->save();
330
+			Logger::approvedUser($database, $user);
331
+
332
+			$this->getNotificationHelper()->userApproved($user);
333
+			SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
334
+
335
+			// send email
336
+			$this->sendStatusChangeEmail(
337
+				'Your WP:ACC account has been approved',
338
+				'usermanagement/emails/approved.tpl',
339
+				null,
340
+				$user,
341
+				User::getCurrent($database)->getUsername()
342
+			);
343
+
344
+			$this->redirect("userManagement");
345
+
346
+			return;
347
+		}
348
+		else {
349
+			$this->assignCSRFToken();
350
+			$this->setTemplate("usermanagement/changelevel-reason.tpl");
351
+			$this->assign("user", $user);
352
+			$this->assign("status", "User");
353
+			$this->assign("showReason", false);
354
+		}
355
+	}
356
+
357
+	#endregion
358
+
359
+	#region Renaming / Editing
360
+
361
+	/**
362
+	 * Entry point for the rename action
363
+	 *
364
+	 * @throws ApplicationLogicException
365
+	 */
366
+	protected function rename()
367
+	{
368
+		$this->setHtmlTitle('User Management');
369
+
370
+		$database = $this->getDatabase();
371
+
372
+		$userId = WebRequest::getInt('user');
373
+		$user = User::getById($userId, $database);
374
+
375
+		if ($user === false) {
376
+			throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
377
+		}
378
+
379
+		// Dual-mode action
380
+		if (WebRequest::wasPosted()) {
381
+			$this->validateCSRFToken();
382
+			$newUsername = WebRequest::postString('newname');
383
+
384
+			if ($newUsername === null || trim($newUsername) === "") {
385
+				throw new ApplicationLogicException('The new username cannot be empty');
386
+			}
387
+
388
+			if (User::getByUsername($newUsername, $database) != false) {
389
+				throw new ApplicationLogicException('The new username already exists');
390
+			}
391
+
392
+			$oldUsername = $user->getUsername();
393
+			$user->setUsername($newUsername);
394
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
395
+
396
+			$user->save();
397
+
398
+			$logEntryData = serialize(array(
399
+				'old' => $oldUsername,
400
+				'new' => $newUsername,
401
+			));
402
+
403
+			Logger::renamedUser($database, $user, $logEntryData);
404
+
405
+			SessionAlert::quick("Changed User "
406
+				. htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
407
+				. " name to "
408
+				. htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
409
+
410
+			$this->getNotificationHelper()->userRenamed($user, $oldUsername);
411
+
412
+			// send an email to the user.
413
+			$this->assign('targetUsername', $user->getUsername());
414
+			$this->assign('toolAdmin', User::getCurrent($database)->getUsername());
415
+			$this->assign('oldUsername', $oldUsername);
416
+			$this->assign('mailingList', $this->adminMailingList);
417
+
418
+			$this->getEmailHelper()->sendMail(
419
+				$user->getEmail(),
420
+				'Your username on WP:ACC has been changed',
421
+				$this->fetchTemplate('usermanagement/emails/renamed.tpl'),
422
+				array('Reply-To' => $this->adminMailingList)
423
+			);
424
+
425
+			$this->redirect("userManagement");
426
+
427
+			return;
428
+		}
429
+		else {
430
+			$this->assignCSRFToken();
431
+			$this->setTemplate('usermanagement/renameuser.tpl');
432
+			$this->assign('user', $user);
433
+		}
434
+	}
435
+
436
+	/**
437
+	 * Entry point for the edit action
438
+	 *
439
+	 * @throws ApplicationLogicException
440
+	 */
441
+	protected function editUser()
442
+	{
443
+		$this->setHtmlTitle('User Management');
444
+
445
+		$database = $this->getDatabase();
446
+
447
+		$userId = WebRequest::getInt('user');
448
+		$user = User::getById($userId, $database);
449
+
450
+		if ($user === false) {
451
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
452
+		}
453
+
454
+		// Dual-mode action
455
+		if (WebRequest::wasPosted()) {
456
+			$this->validateCSRFToken();
457
+			$newEmail = WebRequest::postEmail('user_email');
458
+			$newOnWikiName = WebRequest::postString('user_onwikiname');
459
+
460
+			if ($newEmail === null) {
461
+				throw new ApplicationLogicException('Invalid email address');
462
+			}
463
+
464
+			if (!$user->isOAuthLinked()) {
465
+				if (trim($newOnWikiName) == "") {
466
+					throw new ApplicationLogicException('New on-wiki username cannot be blank');
467
+				}
468
+
469
+				$user->setOnWikiName($newOnWikiName);
470
+			}
471
+
472
+			$user->setEmail($newEmail);
473
+
474
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
475
+
476
+			$user->save();
477
+
478
+			Logger::userPreferencesChange($database, $user);
479
+			$this->getNotificationHelper()->userPrefChange($user);
480
+			SessionAlert::quick('Changes to user\'s preferences have been saved');
481
+
482
+			$this->redirect("userManagement");
483
+
484
+			return;
485
+		}
486
+		else {
487
+			$this->assignCSRFToken();
488
+			$this->setTemplate('usermanagement/edituser.tpl');
489
+			$this->assign('user', $user);
490
+		}
491
+	}
492
+
493
+	#endregion
494
+
495
+	/**
496
+	 * Sends a status change email to the user.
497
+	 *
498
+	 * @param string      $subject           The subject of the email
499
+	 * @param string      $template          The smarty template to use
500
+	 * @param string|null $reason            The reason for performing the status change
501
+	 * @param User        $user              The user affected
502
+	 * @param string      $toolAdminUsername The tool admin's username who is making the edit
503
+	 */
504
+	private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
505
+	{
506
+		$this->assign('targetUsername', $user->getUsername());
507
+		$this->assign('toolAdmin', $toolAdminUsername);
508
+		$this->assign('actionReason', $reason);
509
+		$this->assign('mailingList', $this->adminMailingList);
510
+
511
+		$this->getEmailHelper()->sendMail(
512
+			$user->getEmail(),
513
+			$subject,
514
+			$this->fetchTemplate($template),
515
+			array('Reply-To' => $this->adminMailingList)
516
+		);
517
+	}
518
+
519
+	/**
520
+	 * @param UserRole[] $activeRoles
521
+	 *
522
+	 * @return array
523
+	 */
524
+	private function getRoleData($activeRoles)
525
+	{
526
+		$availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles();
527
+
528
+		$currentUser = User::getCurrent($this->getDatabase());
529
+		$this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
530
+
531
+		$initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
532
+
533
+		$roleData = array();
534
+		foreach ($availableRoles as $role => $data) {
535
+			$intersection = array_intersect($data['editableBy'], $userRoles);
536
+
537
+			$roleData[$role] = $initialValue;
538
+			$roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
539
+			$roleData[$role]['description'] = $data['description'];
540
+		}
541
+
542
+		foreach ($activeRoles as $role) {
543
+			if (!isset($roleData[$role->getRole()])) {
544
+				// This value is no longer available in the configuration, allow changing (aka removing) it.
545
+				$roleData[$role->getRole()] = $initialValue;
546
+				$roleData[$role->getRole()]['allowEdit'] = 1;
547
+			}
548
+
549
+			$roleData[$role->getRole()]['object'] = $role;
550
+			$roleData[$role->getRole()]['active'] = 1;
551
+		}
552
+
553
+		return $roleData;
554
+	}
555 555
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -15 removed lines patch added patch discarded remove patch
@@ -44,8 +44,7 @@  discard block
 block discarded – undo
44 44
             $this->assign("declinedUsers", UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch());
45 45
 
46 46
             UserSearchHelper::get($database)->getRoleMap($roleMap);
47
-        }
48
-        else {
47
+        } else {
49 48
             $this->assign("showAll", false);
50 49
             $this->assign("suspendedUsers", array());
51 50
             $this->assign("declinedUsers", array());
@@ -65,7 +64,8 @@  discard block
 block discarded – undo
65 64
 
66 65
         $this->assign('roles', $roleMap);
67 66
 
68
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
67
+        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database)
68
+        {
69 69
             return UserSearchHelper::get($database)->fetchColumn('username');
70 70
         });
71 71
 
@@ -166,8 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
             $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
168 168
             return;
169
-        }
170
-        else {
169
+        } else {
171 170
             $this->assignCSRFToken();
172 171
             $this->setTemplate('usermanagement/roleedit.tpl');
173 172
             $this->assign('user', $user);
@@ -228,8 +227,7 @@  discard block
 block discarded – undo
228 227
             $this->redirect('userManagement');
229 228
 
230 229
             return;
231
-        }
232
-        else {
230
+        } else {
233 231
             $this->assignCSRFToken();
234 232
             $this->setTemplate('usermanagement/changelevel-reason.tpl');
235 233
             $this->assign('user', $user);
@@ -289,8 +287,7 @@  discard block
 block discarded – undo
289 287
             $this->redirect('userManagement');
290 288
 
291 289
             return;
292
-        }
293
-        else {
290
+        } else {
294 291
             $this->assignCSRFToken();
295 292
             $this->setTemplate('usermanagement/changelevel-reason.tpl');
296 293
             $this->assign('user', $user);
@@ -344,8 +341,7 @@  discard block
 block discarded – undo
344 341
             $this->redirect("userManagement");
345 342
 
346 343
             return;
347
-        }
348
-        else {
344
+        } else {
349 345
             $this->assignCSRFToken();
350 346
             $this->setTemplate("usermanagement/changelevel-reason.tpl");
351 347
             $this->assign("user", $user);
@@ -425,8 +421,7 @@  discard block
 block discarded – undo
425 421
             $this->redirect("userManagement");
426 422
 
427 423
             return;
428
-        }
429
-        else {
424
+        } else {
430 425
             $this->assignCSRFToken();
431 426
             $this->setTemplate('usermanagement/renameuser.tpl');
432 427
             $this->assign('user', $user);
@@ -482,8 +477,7 @@  discard block
 block discarded – undo
482 477
             $this->redirect("userManagement");
483 478
 
484 479
             return;
485
-        }
486
-        else {
480
+        } else {
487 481
             $this->assignCSRFToken();
488 482
             $this->setTemplate('usermanagement/edituser.tpl');
489 483
             $this->assign('user', $user);
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCustomClose.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -23,264 +23,264 @@
 block discarded – undo
23 23
 
24 24
 class PageCustomClose extends PageCloseRequest
25 25
 {
26
-    use RequestData;
27
-
28
-    protected function main()
29
-    {
30
-        $database = $this->getDatabase();
31
-
32
-        $request = $this->getRequest($database);
33
-        $currentUser = User::getCurrent($this->getDatabase());
34
-
35
-        if ($request->getStatus() === 'Closed') {
36
-            throw new ApplicationLogicException('Request is already closed');
37
-        }
38
-
39
-        // Dual-mode page
40
-        if (WebRequest::wasPosted()) {
41
-            $this->validateCSRFToken();
42
-            $this->doCustomClose($currentUser, $request, $database);
43
-
44
-            $this->redirect();
45
-        }
46
-        else {
47
-            $this->assignCSRFToken();
48
-            $this->showCustomCloseForm($database, $request);
49
-        }
50
-    }
51
-
52
-    /**
53
-     * @param $database
54
-     *
55
-     * @return Request
56
-     * @throws ApplicationLogicException
57
-     */
58
-    protected function getRequest(PdoDatabase $database)
59
-    {
60
-        $requestId = WebRequest::getInt('request');
61
-        if ($requestId === null) {
62
-            throw new ApplicationLogicException('Request ID not found');
63
-        }
64
-
65
-        /** @var Request $request */
66
-        $request = Request::getById($requestId, $database);
67
-
68
-        if ($request === false) {
69
-            throw new ApplicationLogicException('Request not found');
70
-        }
71
-
72
-        return $request;
73
-    }
74
-
75
-    /**
76
-     * @param PdoDatabase $database
77
-     *
78
-     * @return EmailTemplate|null
79
-     */
80
-    protected function getTemplate(PdoDatabase $database)
81
-    {
82
-        $templateId = WebRequest::getInt('template');
83
-        if ($templateId === null) {
84
-            return null;
85
-        }
86
-
87
-        /** @var EmailTemplate $template */
88
-        $template = EmailTemplate::getById($templateId, $database);
89
-        if ($template === false || !$template->getActive()) {
90
-            return null;
91
-        }
92
-
93
-        return $template;
94
-    }
95
-
96
-    /**
97
-     * @param $database
98
-     * @param $request
99
-     *
100
-     * @throws Exception
101
-     */
102
-    protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
-    {
104
-        $currentUser = User::getCurrent($database);
105
-        $config = $this->getSiteConfiguration();
106
-
107
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
-        if (!$allowedPrivateData) {
109
-            // we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
-            throw new AccessDeniedException($this->getSecurityManager());
111
-        }
112
-
113
-        $template = $this->getTemplate($database);
114
-
115
-        // Preload data
116
-        $this->assign('defaultAction', '');
117
-        $this->assign('preloadText', '');
118
-        $this->assign('preloadTitle', '');
119
-
120
-        if ($template !== null) {
121
-            $this->assign('defaultAction', $template->getDefaultAction());
122
-            $this->assign('preloadText', $template->getText());
123
-            $this->assign('preloadTitle', $template->getName());
124
-        }
125
-
126
-        // Static data
127
-        $this->assign('requeststates', $config->getRequestStates());
128
-
129
-        // request data
130
-        $this->assign('requestId', $request->getIp());
131
-        $this->assign('updateVersion', $request->getUpdateVersion());
132
-        $this->setupBasicData($request, $config);
133
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
-        $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
-
136
-        // IP location
137
-        $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
-        $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
-
140
-        // Confirmations
141
-        $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
-        $this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
-
144
-        $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
-
146
-        // template
147
-        $this->setTemplate('custom-close.tpl');
148
-    }
149
-
150
-    /**
151
-     * @param User        $currentUser
152
-     * @param Request     $request
153
-     * @param PdoDatabase $database
154
-     *
155
-     * @throws ApplicationLogicException
156
-     */
157
-    protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
-    {
159
-        $messageBody = WebRequest::postString('msgbody');
160
-        if ($messageBody === null || trim($messageBody) === '') {
161
-            throw new ApplicationLogicException('Message body cannot be blank');
162
-        }
163
-
164
-        $ccMailingList = true;
165
-        if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
-            $ccMailingList = WebRequest::postBoolean('ccMailingList');
167
-        }
168
-
169
-        if ($request->getStatus() === 'Closed') {
170
-            throw new ApplicationLogicException('Request is already closed');
171
-        }
172
-
173
-        if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
-            && WebRequest::postBoolean('confirmReserveOverride'))
175
-        ) {
176
-            throw new ApplicationLogicException('Not all confirmations checked');
177
-        }
178
-
179
-        $action = WebRequest::postString('action');
180
-        $availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
-
182
-        if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
-            // Close request
184
-            $this->closeRequest($request, $database, $action, $messageBody);
185
-
186
-            // Send the mail after the save, since save can be rolled back
187
-            $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
-        }
189
-        else {
190
-            if (array_key_exists($action, $availableRequestStates)) {
191
-                // Defer to other state
192
-                $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
-
194
-                // Send the mail after the save, since save can be rolled back
195
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
-            }
197
-            else {
198
-                $request->setReserved(null);
199
-                $request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
-                $request->save();
201
-
202
-                // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
-                // and be rolled back.
204
-
205
-                // Send mail
206
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
-
208
-                Logger::sentMail($database, $request, $messageBody);
209
-                Logger::unreserve($database, $request);
210
-
211
-                $this->getNotificationHelper()->sentMail($request);
212
-                SessionAlert::success("Sent mail to Request {$request->getId()}");
213
-            }
214
-        }
215
-    }
216
-
217
-    /**
218
-     * @param Request     $request
219
-     * @param PdoDatabase $database
220
-     * @param string      $action
221
-     * @param string      $messageBody
222
-     *
223
-     * @throws Exception
224
-     * @throws OptimisticLockFailedException
225
-     */
226
-    protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
-    {
228
-        $request->setStatus('Closed');
229
-        $request->setReserved(null);
230
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
-        $request->save();
232
-
233
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
-        // be rolled back.
235
-
236
-        if ($action == EmailTemplate::CREATED) {
237
-            $logCloseType = 'custom-y';
238
-            $notificationCloseType = "Custom, Created";
239
-        }
240
-        else {
241
-            $logCloseType = 'custom-n';
242
-            $notificationCloseType = "Custom, Not Created";
243
-        }
244
-
245
-        Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
-        $this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
-
248
-        $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
-        SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'.");
250
-    }
251
-
252
-    /**
253
-     * @param Request     $request
254
-     * @param PdoDatabase $database
255
-     * @param string      $action
256
-     * @param             $availableRequestStates
257
-     * @param string      $messageBody
258
-     *
259
-     * @throws Exception
260
-     * @throws OptimisticLockFailedException
261
-     */
262
-    protected function deferRequest(
263
-        Request $request,
264
-        PdoDatabase $database,
265
-        $action,
266
-        $availableRequestStates,
267
-        $messageBody
268
-    ) {
269
-        $request->setStatus($action);
270
-        $request->setReserved(null);
271
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
-        $request->save();
273
-
274
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
-        // and be rolled back.
276
-
277
-        $deferToLog = $availableRequestStates[$action]['defertolog'];
278
-        Logger::sentMail($database, $request, $messageBody);
279
-        Logger::deferRequest($database, $request, $deferToLog);
280
-
281
-        $this->getNotificationHelper()->requestDeferredWithMail($request);
282
-
283
-        $deferTo = $availableRequestStates[$action]['deferto'];
284
-        SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
-    }
26
+	use RequestData;
27
+
28
+	protected function main()
29
+	{
30
+		$database = $this->getDatabase();
31
+
32
+		$request = $this->getRequest($database);
33
+		$currentUser = User::getCurrent($this->getDatabase());
34
+
35
+		if ($request->getStatus() === 'Closed') {
36
+			throw new ApplicationLogicException('Request is already closed');
37
+		}
38
+
39
+		// Dual-mode page
40
+		if (WebRequest::wasPosted()) {
41
+			$this->validateCSRFToken();
42
+			$this->doCustomClose($currentUser, $request, $database);
43
+
44
+			$this->redirect();
45
+		}
46
+		else {
47
+			$this->assignCSRFToken();
48
+			$this->showCustomCloseForm($database, $request);
49
+		}
50
+	}
51
+
52
+	/**
53
+	 * @param $database
54
+	 *
55
+	 * @return Request
56
+	 * @throws ApplicationLogicException
57
+	 */
58
+	protected function getRequest(PdoDatabase $database)
59
+	{
60
+		$requestId = WebRequest::getInt('request');
61
+		if ($requestId === null) {
62
+			throw new ApplicationLogicException('Request ID not found');
63
+		}
64
+
65
+		/** @var Request $request */
66
+		$request = Request::getById($requestId, $database);
67
+
68
+		if ($request === false) {
69
+			throw new ApplicationLogicException('Request not found');
70
+		}
71
+
72
+		return $request;
73
+	}
74
+
75
+	/**
76
+	 * @param PdoDatabase $database
77
+	 *
78
+	 * @return EmailTemplate|null
79
+	 */
80
+	protected function getTemplate(PdoDatabase $database)
81
+	{
82
+		$templateId = WebRequest::getInt('template');
83
+		if ($templateId === null) {
84
+			return null;
85
+		}
86
+
87
+		/** @var EmailTemplate $template */
88
+		$template = EmailTemplate::getById($templateId, $database);
89
+		if ($template === false || !$template->getActive()) {
90
+			return null;
91
+		}
92
+
93
+		return $template;
94
+	}
95
+
96
+	/**
97
+	 * @param $database
98
+	 * @param $request
99
+	 *
100
+	 * @throws Exception
101
+	 */
102
+	protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
+	{
104
+		$currentUser = User::getCurrent($database);
105
+		$config = $this->getSiteConfiguration();
106
+
107
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
+		if (!$allowedPrivateData) {
109
+			// we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
+			throw new AccessDeniedException($this->getSecurityManager());
111
+		}
112
+
113
+		$template = $this->getTemplate($database);
114
+
115
+		// Preload data
116
+		$this->assign('defaultAction', '');
117
+		$this->assign('preloadText', '');
118
+		$this->assign('preloadTitle', '');
119
+
120
+		if ($template !== null) {
121
+			$this->assign('defaultAction', $template->getDefaultAction());
122
+			$this->assign('preloadText', $template->getText());
123
+			$this->assign('preloadTitle', $template->getName());
124
+		}
125
+
126
+		// Static data
127
+		$this->assign('requeststates', $config->getRequestStates());
128
+
129
+		// request data
130
+		$this->assign('requestId', $request->getIp());
131
+		$this->assign('updateVersion', $request->getUpdateVersion());
132
+		$this->setupBasicData($request, $config);
133
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
+		$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
+
136
+		// IP location
137
+		$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
+		$this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
+
140
+		// Confirmations
141
+		$this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
+		$this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
+
144
+		$this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
+
146
+		// template
147
+		$this->setTemplate('custom-close.tpl');
148
+	}
149
+
150
+	/**
151
+	 * @param User        $currentUser
152
+	 * @param Request     $request
153
+	 * @param PdoDatabase $database
154
+	 *
155
+	 * @throws ApplicationLogicException
156
+	 */
157
+	protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
+	{
159
+		$messageBody = WebRequest::postString('msgbody');
160
+		if ($messageBody === null || trim($messageBody) === '') {
161
+			throw new ApplicationLogicException('Message body cannot be blank');
162
+		}
163
+
164
+		$ccMailingList = true;
165
+		if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
+			$ccMailingList = WebRequest::postBoolean('ccMailingList');
167
+		}
168
+
169
+		if ($request->getStatus() === 'Closed') {
170
+			throw new ApplicationLogicException('Request is already closed');
171
+		}
172
+
173
+		if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
+			&& WebRequest::postBoolean('confirmReserveOverride'))
175
+		) {
176
+			throw new ApplicationLogicException('Not all confirmations checked');
177
+		}
178
+
179
+		$action = WebRequest::postString('action');
180
+		$availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
+
182
+		if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
+			// Close request
184
+			$this->closeRequest($request, $database, $action, $messageBody);
185
+
186
+			// Send the mail after the save, since save can be rolled back
187
+			$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
+		}
189
+		else {
190
+			if (array_key_exists($action, $availableRequestStates)) {
191
+				// Defer to other state
192
+				$this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
+
194
+				// Send the mail after the save, since save can be rolled back
195
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
+			}
197
+			else {
198
+				$request->setReserved(null);
199
+				$request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
+				$request->save();
201
+
202
+				// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
+				// and be rolled back.
204
+
205
+				// Send mail
206
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
+
208
+				Logger::sentMail($database, $request, $messageBody);
209
+				Logger::unreserve($database, $request);
210
+
211
+				$this->getNotificationHelper()->sentMail($request);
212
+				SessionAlert::success("Sent mail to Request {$request->getId()}");
213
+			}
214
+		}
215
+	}
216
+
217
+	/**
218
+	 * @param Request     $request
219
+	 * @param PdoDatabase $database
220
+	 * @param string      $action
221
+	 * @param string      $messageBody
222
+	 *
223
+	 * @throws Exception
224
+	 * @throws OptimisticLockFailedException
225
+	 */
226
+	protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
+	{
228
+		$request->setStatus('Closed');
229
+		$request->setReserved(null);
230
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
+		$request->save();
232
+
233
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
+		// be rolled back.
235
+
236
+		if ($action == EmailTemplate::CREATED) {
237
+			$logCloseType = 'custom-y';
238
+			$notificationCloseType = "Custom, Created";
239
+		}
240
+		else {
241
+			$logCloseType = 'custom-n';
242
+			$notificationCloseType = "Custom, Not Created";
243
+		}
244
+
245
+		Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
+		$this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
+
248
+		$requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
+		SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'.");
250
+	}
251
+
252
+	/**
253
+	 * @param Request     $request
254
+	 * @param PdoDatabase $database
255
+	 * @param string      $action
256
+	 * @param             $availableRequestStates
257
+	 * @param string      $messageBody
258
+	 *
259
+	 * @throws Exception
260
+	 * @throws OptimisticLockFailedException
261
+	 */
262
+	protected function deferRequest(
263
+		Request $request,
264
+		PdoDatabase $database,
265
+		$action,
266
+		$availableRequestStates,
267
+		$messageBody
268
+	) {
269
+		$request->setStatus($action);
270
+		$request->setReserved(null);
271
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
+		$request->save();
273
+
274
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
+		// and be rolled back.
276
+
277
+		$deferToLog = $availableRequestStates[$action]['defertolog'];
278
+		Logger::sentMail($database, $request, $messageBody);
279
+		Logger::deferRequest($database, $request, $deferToLog);
280
+
281
+		$this->getNotificationHelper()->requestDeferredWithMail($request);
282
+
283
+		$deferTo = $availableRequestStates[$action]['deferto'];
284
+		SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
+	}
286 286
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,8 +42,7 @@  discard block
 block discarded – undo
42 42
             $this->doCustomClose($currentUser, $request, $database);
43 43
 
44 44
             $this->redirect();
45
-        }
46
-        else {
45
+        } else {
47 46
             $this->assignCSRFToken();
48 47
             $this->showCustomCloseForm($database, $request);
49 48
         }
@@ -185,16 +184,14 @@  discard block
 block discarded – undo
185 184
 
186 185
             // Send the mail after the save, since save can be rolled back
187 186
             $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
-        }
189
-        else {
187
+        } else {
190 188
             if (array_key_exists($action, $availableRequestStates)) {
191 189
                 // Defer to other state
192 190
                 $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193 191
 
194 192
                 // Send the mail after the save, since save can be rolled back
195 193
                 $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
-            }
197
-            else {
194
+            } else {
198 195
                 $request->setReserved(null);
199 196
                 $request->setUpdateVersion(WebRequest::postInt('updateversion'));
200 197
                 $request->save();
@@ -236,8 +233,7 @@  discard block
 block discarded – undo
236 233
         if ($action == EmailTemplate::CREATED) {
237 234
             $logCloseType = 'custom-y';
238 235
             $notificationCloseType = "Custom, Created";
239
-        }
240
-        else {
236
+        } else {
241 237
             $logCloseType = 'custom-n';
242 238
             $notificationCloseType = "Custom, Not Created";
243 239
         }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/RequestActionBase.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,37 +16,37 @@
 block discarded – undo
16 16
 
17 17
 abstract class RequestActionBase extends InternalPageBase
18 18
 {
19
-    /**
20
-     * @param PdoDatabase $database
21
-     *
22
-     * @return Request
23
-     * @throws ApplicationLogicException
24
-     */
25
-    protected function getRequest(PdoDatabase $database)
26
-    {
27
-        $requestId = WebRequest::postInt('request');
28
-        if ($requestId === null) {
29
-            throw new ApplicationLogicException('Request ID not found');
30
-        }
31
-
32
-        /** @var Request $request */
33
-        $request = Request::getById($requestId, $database);
34
-
35
-        if ($request === false) {
36
-            throw new ApplicationLogicException('Request not found');
37
-        }
38
-
39
-        return $request;
40
-    }
41
-
42
-    final protected function checkPosted()
43
-    {
44
-        // if the request was not posted, send the user away.
45
-        if (!WebRequest::wasPosted()) {
46
-            throw new ApplicationLogicException('This page does not support GET methods.');
47
-        }
48
-
49
-        // validate the CSRF token
50
-        $this->validateCSRFToken();
51
-    }
19
+	/**
20
+	 * @param PdoDatabase $database
21
+	 *
22
+	 * @return Request
23
+	 * @throws ApplicationLogicException
24
+	 */
25
+	protected function getRequest(PdoDatabase $database)
26
+	{
27
+		$requestId = WebRequest::postInt('request');
28
+		if ($requestId === null) {
29
+			throw new ApplicationLogicException('Request ID not found');
30
+		}
31
+
32
+		/** @var Request $request */
33
+		$request = Request::getById($requestId, $database);
34
+
35
+		if ($request === false) {
36
+			throw new ApplicationLogicException('Request not found');
37
+		}
38
+
39
+		return $request;
40
+	}
41
+
42
+	final protected function checkPosted()
43
+	{
44
+		// if the request was not posted, send the user away.
45
+		if (!WebRequest::wasPosted()) {
46
+			throw new ApplicationLogicException('This page does not support GET methods.');
47
+		}
48
+
49
+		// validate the CSRF token
50
+		$this->validateCSRFToken();
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageBreakReservation.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,79 +19,79 @@
 block discarded – undo
19 19
 
20 20
 class PageBreakReservation extends RequestActionBase
21 21
 {
22
-    protected function main()
23
-    {
24
-        $this->checkPosted();
25
-        $database = $this->getDatabase();
26
-        $request = $this->getRequest($database);
22
+	protected function main()
23
+	{
24
+		$this->checkPosted();
25
+		$database = $this->getDatabase();
26
+		$request = $this->getRequest($database);
27 27
 
28
-        if ($request->getReserved() === null) {
29
-            throw new ApplicationLogicException('Request is not reserved!');
30
-        }
28
+		if ($request->getReserved() === null) {
29
+			throw new ApplicationLogicException('Request is not reserved!');
30
+		}
31 31
 
32
-        $currentUser = User::getCurrent($database);
32
+		$currentUser = User::getCurrent($database);
33 33
 
34
-        if ($currentUser->getId() === $request->getReserved()) {
35
-            $this->doUnreserve($request, $database);
36
-        }
37
-        else {
38
-            // not the same user!
39
-            if ($this->barrierTest('force', $currentUser)) {
40
-                $this->doBreakReserve($request, $database);
41
-            }
42
-            else {
43
-                throw new AccessDeniedException($this->getSecurityManager());
44
-            }
45
-        }
46
-    }
34
+		if ($currentUser->getId() === $request->getReserved()) {
35
+			$this->doUnreserve($request, $database);
36
+		}
37
+		else {
38
+			// not the same user!
39
+			if ($this->barrierTest('force', $currentUser)) {
40
+				$this->doBreakReserve($request, $database);
41
+			}
42
+			else {
43
+				throw new AccessDeniedException($this->getSecurityManager());
44
+			}
45
+		}
46
+	}
47 47
 
48
-    /**
49
-     * @param Request     $request
50
-     * @param PdoDatabase $database
51
-     *
52
-     * @throws Exception
53
-     */
54
-    protected function doUnreserve(Request $request, PdoDatabase $database)
55
-    {
56
-        // same user! we allow people to unreserve their own stuff
57
-        $request->setReserved(null);
58
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
59
-        $request->save();
48
+	/**
49
+	 * @param Request     $request
50
+	 * @param PdoDatabase $database
51
+	 *
52
+	 * @throws Exception
53
+	 */
54
+	protected function doUnreserve(Request $request, PdoDatabase $database)
55
+	{
56
+		// same user! we allow people to unreserve their own stuff
57
+		$request->setReserved(null);
58
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
59
+		$request->save();
60 60
 
61
-        Logger::unreserve($database, $request);
62
-        $this->getNotificationHelper()->requestUnreserved($request);
61
+		Logger::unreserve($database, $request);
62
+		$this->getNotificationHelper()->requestUnreserved($request);
63 63
 
64
-        // Redirect home!
65
-        $this->redirect();
66
-    }
64
+		// Redirect home!
65
+		$this->redirect();
66
+	}
67 67
 
68
-    /**
69
-     * @param Request     $request
70
-     * @param PdoDatabase $database
71
-     *
72
-     * @throws Exception
73
-     */
74
-    protected function doBreakReserve(Request $request, PdoDatabase $database)
75
-    {
76
-        if (!WebRequest::postBoolean("confirm")) {
77
-            $this->assignCSRFToken();
68
+	/**
69
+	 * @param Request     $request
70
+	 * @param PdoDatabase $database
71
+	 *
72
+	 * @throws Exception
73
+	 */
74
+	protected function doBreakReserve(Request $request, PdoDatabase $database)
75
+	{
76
+		if (!WebRequest::postBoolean("confirm")) {
77
+			$this->assignCSRFToken();
78 78
 
79
-            $this->assign("request", $request->getId());
80
-            $this->assign("reservedUser", User::getById($request->getReserved(), $database));
81
-            $this->assign("updateversion", WebRequest::postInt('updateversion'));
79
+			$this->assign("request", $request->getId());
80
+			$this->assign("reservedUser", User::getById($request->getReserved(), $database));
81
+			$this->assign("updateversion", WebRequest::postInt('updateversion'));
82 82
 
83
-            $this->setTemplate("confirmations/breakreserve.tpl");
84
-        }
85
-        else {
86
-            $request->setReserved(null);
87
-            $request->setUpdateVersion(WebRequest::postInt('updateversion'));
88
-            $request->save();
83
+			$this->setTemplate("confirmations/breakreserve.tpl");
84
+		}
85
+		else {
86
+			$request->setReserved(null);
87
+			$request->setUpdateVersion(WebRequest::postInt('updateversion'));
88
+			$request->save();
89 89
 
90
-            Logger::breakReserve($database, $request);
91
-            $this->getNotificationHelper()->requestReserveBroken($request);
90
+			Logger::breakReserve($database, $request);
91
+			$this->getNotificationHelper()->requestReserveBroken($request);
92 92
 
93
-            // Redirect home!
94
-            $this->redirect();
95
-        }
96
-    }
93
+			// Redirect home!
94
+			$this->redirect();
95
+		}
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,13 +33,11 @@  discard block
 block discarded – undo
33 33
 
34 34
         if ($currentUser->getId() === $request->getReserved()) {
35 35
             $this->doUnreserve($request, $database);
36
-        }
37
-        else {
36
+        } else {
38 37
             // not the same user!
39 38
             if ($this->barrierTest('force', $currentUser)) {
40 39
                 $this->doBreakReserve($request, $database);
41
-            }
42
-            else {
40
+            } else {
43 41
                 throw new AccessDeniedException($this->getSecurityManager());
44 42
             }
45 43
         }
@@ -81,8 +79,7 @@  discard block
 block discarded – undo
81 79
             $this->assign("updateversion", WebRequest::postInt('updateversion'));
82 80
 
83 81
             $this->setTemplate("confirmations/breakreserve.tpl");
84
-        }
85
-        else {
82
+        } else {
86 83
             $request->setReserved(null);
87 84
             $request->setUpdateVersion(WebRequest::postInt('updateversion'));
88 85
             $request->save();
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageComment.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -15,51 +15,51 @@
 block discarded – undo
15 15
 
16 16
 class PageComment extends RequestActionBase
17 17
 {
18
-    /**
19
-     * Main function for this page, when no specific actions are called.
20
-     * @return void
21
-     */
22
-    protected function main()
23
-    {
24
-        $this->checkPosted();
25
-        $database = $this->getDatabase();
26
-        $request = $this->getRequest($database);
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->checkPosted();
25
+		$database = $this->getDatabase();
26
+		$request = $this->getRequest($database);
27 27
 
28
-        $commentText = WebRequest::postString('comment');
29
-        if ($commentText === false || $commentText == '') {
30
-            $this->redirect('viewRequest', null, array('id' => $request->getId()));
28
+		$commentText = WebRequest::postString('comment');
29
+		if ($commentText === false || $commentText == '') {
30
+			$this->redirect('viewRequest', null, array('id' => $request->getId()));
31 31
 
32
-            return;
33
-        }
32
+			return;
33
+		}
34 34
 
35
-        //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter.
36
-        $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/';
37
-        $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/';
35
+		//Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter.
36
+		$ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/';
37
+		$ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/';
38 38
 
39
-        $overridePolicy = WebRequest::postBoolean('privpol-check-override');
39
+		$overridePolicy = WebRequest::postBoolean('privpol-check-override');
40 40
 
41
-        if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) {
42
-            $this->assignCSRFToken();
43
-            $this->assign("request", $request);
44
-            $this->assign("comment", $commentText);
45
-            $this->setTemplate("privpol-warning.tpl");
41
+		if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) {
42
+			$this->assignCSRFToken();
43
+			$this->assign("request", $request);
44
+			$this->assign("comment", $commentText);
45
+			$this->setTemplate("privpol-warning.tpl");
46 46
 
47
-            return;
48
-        }
47
+			return;
48
+		}
49 49
 
50
-        $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user';
50
+		$visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user';
51 51
 
52
-        $comment = new Comment();
53
-        $comment->setDatabase($database);
52
+		$comment = new Comment();
53
+		$comment->setDatabase($database);
54 54
 
55
-        $comment->setRequest($request->getId());
56
-        $comment->setVisibility($visibility);
57
-        $comment->setUser(User::getCurrent($database)->getId());
58
-        $comment->setComment($commentText);
55
+		$comment->setRequest($request->getId());
56
+		$comment->setVisibility($visibility);
57
+		$comment->setUser(User::getCurrent($database)->getId());
58
+		$comment->setComment($commentText);
59 59
 
60
-        $comment->save();
60
+		$comment->save();
61 61
 
62
-        $this->getNotificationHelper()->commentCreated($comment, $request);
63
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
64
-    }
62
+		$this->getNotificationHelper()->commentCreated($comment, $request);
63
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
64
+	}
65 65
 }
Please login to merge, or discard this patch.