Failed Conditions
Pull Request — newinternal-bugfixing (#286)
by Simon
06:57 queued 03:32
created
includes/Pages/PageTeam.php 1 patch
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.
includes/Pages/PageWelcomeTemplateManagement.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -19,223 +19,223 @@
 block discarded – undo
19 19
 
20 20
 class PageWelcomeTemplateManagement 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
-        $templateList = WelcomeTemplate::getAll($this->getDatabase());
29
-
30
-        $this->assignCSRFToken();
31
-
32
-        $user = User::getCurrent($this->getDatabase());
33
-        $this->assign('canEdit', $this->barrierTest('edit', $user));
34
-        $this->assign('canAdd', $this->barrierTest('add', $user));
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		$templateList = WelcomeTemplate::getAll($this->getDatabase());
29
+
30
+		$this->assignCSRFToken();
31
+
32
+		$user = User::getCurrent($this->getDatabase());
33
+		$this->assign('canEdit', $this->barrierTest('edit', $user));
34
+		$this->assign('canAdd', $this->barrierTest('add', $user));
35 35
 
36
-        $this->assign('templateList', $templateList);
37
-        $this->setTemplate('welcome-template/list.tpl');
38
-    }
36
+		$this->assign('templateList', $templateList);
37
+		$this->setTemplate('welcome-template/list.tpl');
38
+	}
39 39
 
40
-    /**
41
-     * Handles the requests for selecting a template to use.
42
-     *
43
-     * @throws ApplicationLogicException
44
-     */
45
-    protected function select()
46
-    {
47
-        // get rid of GETs
48
-        if (!WebRequest::wasPosted()) {
49
-            $this->redirect('welcomeTemplates');
50
-        }
51
-
52
-        $this->validateCSRFToken();
53
-
54
-        $user = User::getCurrent($this->getDatabase());
55
-
56
-        if (WebRequest::postBoolean('disable')) {
57
-            $user->setWelcomeTemplate(null);
58
-            $user->save();
59
-
60
-            SessionAlert::success('Disabled automatic user welcoming.');
61
-            $this->redirect('welcomeTemplates');
62
-
63
-            return;
64
-        }
65
-
66
-        $database = $this->getDatabase();
40
+	/**
41
+	 * Handles the requests for selecting a template to use.
42
+	 *
43
+	 * @throws ApplicationLogicException
44
+	 */
45
+	protected function select()
46
+	{
47
+		// get rid of GETs
48
+		if (!WebRequest::wasPosted()) {
49
+			$this->redirect('welcomeTemplates');
50
+		}
51
+
52
+		$this->validateCSRFToken();
53
+
54
+		$user = User::getCurrent($this->getDatabase());
55
+
56
+		if (WebRequest::postBoolean('disable')) {
57
+			$user->setWelcomeTemplate(null);
58
+			$user->save();
59
+
60
+			SessionAlert::success('Disabled automatic user welcoming.');
61
+			$this->redirect('welcomeTemplates');
62
+
63
+			return;
64
+		}
65
+
66
+		$database = $this->getDatabase();
67 67
 
68
-        $templateId = WebRequest::postInt('template');
69
-        /** @var false|WelcomeTemplate $template */
70
-        $template = WelcomeTemplate::getById($templateId, $database);
68
+		$templateId = WebRequest::postInt('template');
69
+		/** @var false|WelcomeTemplate $template */
70
+		$template = WelcomeTemplate::getById($templateId, $database);
71 71
 
72
-        if ($template === false || $template->isDeleted()) {
73
-            throw new ApplicationLogicException('Unknown template');
74
-        }
72
+		if ($template === false || $template->isDeleted()) {
73
+			throw new ApplicationLogicException('Unknown template');
74
+		}
75 75
 
76
-        $user->setWelcomeTemplate($template->getId());
77
-        $user->save();
76
+		$user->setWelcomeTemplate($template->getId());
77
+		$user->save();
78 78
 
79
-        SessionAlert::success("Updated selected welcome template for automatic welcoming.");
79
+		SessionAlert::success("Updated selected welcome template for automatic welcoming.");
80 80
 
81
-        $this->redirect('welcomeTemplates');
82
-    }
81
+		$this->redirect('welcomeTemplates');
82
+	}
83 83
 
84
-    /**
85
-     * Handles the requests for viewing a template.
86
-     *
87
-     * @throws ApplicationLogicException
88
-     */
89
-    protected function view()
90
-    {
91
-        $database = $this->getDatabase();
84
+	/**
85
+	 * Handles the requests for viewing a template.
86
+	 *
87
+	 * @throws ApplicationLogicException
88
+	 */
89
+	protected function view()
90
+	{
91
+		$database = $this->getDatabase();
92 92
 
93
-        $templateId = WebRequest::getInt('template');
93
+		$templateId = WebRequest::getInt('template');
94 94
 
95
-        /** @var WelcomeTemplate $template */
96
-        $template = WelcomeTemplate::getById($templateId, $database);
95
+		/** @var WelcomeTemplate $template */
96
+		$template = WelcomeTemplate::getById($templateId, $database);
97 97
 
98
-        if ($template === false) {
99
-            throw new ApplicationLogicException('Cannot find requested template');
100
-        }
98
+		if ($template === false) {
99
+			throw new ApplicationLogicException('Cannot find requested template');
100
+		}
101 101
 
102
-        $templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
102
+		$templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
103 103
 
104
-        $this->assign('templateHtml', $templateHtml);
105
-        $this->assign('template', $template);
106
-        $this->setTemplate('welcome-template/view.tpl');
107
-    }
104
+		$this->assign('templateHtml', $templateHtml);
105
+		$this->assign('template', $template);
106
+		$this->setTemplate('welcome-template/view.tpl');
107
+	}
108 108
 
109
-    /**
110
-     * Handler for the add action to create a new welcome template
111
-     *
112
-     * @throws Exception
113
-     */
114
-    protected function add()
115
-    {
116
-        if (WebRequest::wasPosted()) {
117
-            $this->validateCSRFToken();
118
-            $database = $this->getDatabase();
109
+	/**
110
+	 * Handler for the add action to create a new welcome template
111
+	 *
112
+	 * @throws Exception
113
+	 */
114
+	protected function add()
115
+	{
116
+		if (WebRequest::wasPosted()) {
117
+			$this->validateCSRFToken();
118
+			$database = $this->getDatabase();
119 119
 
120
-            $userCode = WebRequest::postString('usercode');
121
-            $botCode = WebRequest::postString('botcode');
120
+			$userCode = WebRequest::postString('usercode');
121
+			$botCode = WebRequest::postString('botcode');
122 122
 
123
-            $this->validate($userCode, $botCode);
123
+			$this->validate($userCode, $botCode);
124 124
 
125
-            $template = new WelcomeTemplate();
126
-            $template->setDatabase($database);
127
-            $template->setUserCode($userCode);
128
-            $template->setBotCode($botCode);
129
-            $template->save();
125
+			$template = new WelcomeTemplate();
126
+			$template->setDatabase($database);
127
+			$template->setUserCode($userCode);
128
+			$template->setBotCode($botCode);
129
+			$template->save();
130 130
 
131
-            Logger::welcomeTemplateCreated($database, $template);
131
+			Logger::welcomeTemplateCreated($database, $template);
132 132
 
133
-            $this->getNotificationHelper()->welcomeTemplateCreated($template);
133
+			$this->getNotificationHelper()->welcomeTemplateCreated($template);
134 134
 
135
-            SessionAlert::success("Template successfully created.");
135
+			SessionAlert::success("Template successfully created.");
136 136
 
137
-            $this->redirect('welcomeTemplates');
138
-        }
139
-        else {
140
-            $this->assignCSRFToken();
141
-            $this->setTemplate("welcome-template/add.tpl");
142
-        }
143
-    }
137
+			$this->redirect('welcomeTemplates');
138
+		}
139
+		else {
140
+			$this->assignCSRFToken();
141
+			$this->setTemplate("welcome-template/add.tpl");
142
+		}
143
+	}
144 144
 
145
-    /**
146
-     * Hander for editing templates
147
-     */
148
-    protected function edit()
149
-    {
150
-        $database = $this->getDatabase();
145
+	/**
146
+	 * Hander for editing templates
147
+	 */
148
+	protected function edit()
149
+	{
150
+		$database = $this->getDatabase();
151 151
 
152
-        $templateId = WebRequest::getInt('template');
152
+		$templateId = WebRequest::getInt('template');
153 153
 
154
-        /** @var WelcomeTemplate $template */
155
-        $template = WelcomeTemplate::getById($templateId, $database);
154
+		/** @var WelcomeTemplate $template */
155
+		$template = WelcomeTemplate::getById($templateId, $database);
156 156
 
157
-        if ($template === false) {
158
-            throw new ApplicationLogicException('Cannot find requested template');
159
-        }
157
+		if ($template === false) {
158
+			throw new ApplicationLogicException('Cannot find requested template');
159
+		}
160 160
 
161
-        if ($template->isDeleted()) {
162
-            throw new ApplicationLogicException('The specified template has been deleted');
163
-        }
161
+		if ($template->isDeleted()) {
162
+			throw new ApplicationLogicException('The specified template has been deleted');
163
+		}
164 164
 
165
-        if (WebRequest::wasPosted()) {
166
-            $this->validateCSRFToken();
165
+		if (WebRequest::wasPosted()) {
166
+			$this->validateCSRFToken();
167 167
 
168
-            $userCode = WebRequest::postString('usercode');
169
-            $botCode = WebRequest::postString('botcode');
168
+			$userCode = WebRequest::postString('usercode');
169
+			$botCode = WebRequest::postString('botcode');
170 170
 
171
-            $this->validate($userCode, $botCode);
171
+			$this->validate($userCode, $botCode);
172 172
 
173
-            $template->setUserCode($userCode);
174
-            $template->setBotCode($botCode);
175
-            $template->setUpdateVersion(WebRequest::postInt('updateversion'));
176
-            $template->save();
173
+			$template->setUserCode($userCode);
174
+			$template->setBotCode($botCode);
175
+			$template->setUpdateVersion(WebRequest::postInt('updateversion'));
176
+			$template->save();
177 177
 
178
-            Logger::welcomeTemplateEdited($database, $template);
178
+			Logger::welcomeTemplateEdited($database, $template);
179 179
 
180
-            SessionAlert::success("Template updated.");
180
+			SessionAlert::success("Template updated.");
181 181
 
182
-            $this->getNotificationHelper()->welcomeTemplateEdited($template);
182
+			$this->getNotificationHelper()->welcomeTemplateEdited($template);
183 183
 
184
-            $this->redirect('welcomeTemplates');
185
-        }
186
-        else {
187
-            $this->assignCSRFToken();
188
-            $this->assign('template', $template);
189
-            $this->setTemplate('welcome-template/edit.tpl');
190
-        }
191
-    }
184
+			$this->redirect('welcomeTemplates');
185
+		}
186
+		else {
187
+			$this->assignCSRFToken();
188
+			$this->assign('template', $template);
189
+			$this->setTemplate('welcome-template/edit.tpl');
190
+		}
191
+	}
192 192
 
193
-    protected function delete()
194
-    {
195
-        $this->redirect('welcomeTemplates');
193
+	protected function delete()
194
+	{
195
+		$this->redirect('welcomeTemplates');
196 196
 
197
-        if (!WebRequest::wasPosted()) {
198
-            return;
199
-        }
197
+		if (!WebRequest::wasPosted()) {
198
+			return;
199
+		}
200 200
 
201
-        $this->validateCSRFToken();
201
+		$this->validateCSRFToken();
202 202
 
203
-        $database = $this->getDatabase();
203
+		$database = $this->getDatabase();
204 204
 
205
-        $templateId = WebRequest::postInt('template');
206
-        $updateVersion = WebRequest::postInt('updateversion');
205
+		$templateId = WebRequest::postInt('template');
206
+		$updateVersion = WebRequest::postInt('updateversion');
207 207
 
208
-        /** @var WelcomeTemplate $template */
209
-        $template = WelcomeTemplate::getById($templateId, $database);
208
+		/** @var WelcomeTemplate $template */
209
+		$template = WelcomeTemplate::getById($templateId, $database);
210 210
 
211
-        if ($template === false || $template->isDeleted()) {
212
-            throw new ApplicationLogicException('Cannot find requested template');
213
-        }
211
+		if ($template === false || $template->isDeleted()) {
212
+			throw new ApplicationLogicException('Cannot find requested template');
213
+		}
214 214
 
215
-        // set the update version to the version sent by the client (optimisticly lock from initial page load)
216
-        $template->setUpdateVersion($updateVersion);
215
+		// set the update version to the version sent by the client (optimisticly lock from initial page load)
216
+		$template->setUpdateVersion($updateVersion);
217 217
 
218
-        $database
219
-            ->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
220
-            ->execute(array(":id" => $templateId));
218
+		$database
219
+			->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
220
+			->execute(array(":id" => $templateId));
221 221
 
222
-        Logger::welcomeTemplateDeleted($database, $template);
222
+		Logger::welcomeTemplateDeleted($database, $template);
223 223
 
224
-        $template->delete();
224
+		$template->delete();
225 225
 
226
-        SessionAlert::success(
227
-            "Template deleted. Any users who were using this template have had automatic welcoming disabled.");
228
-        $this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
229
-    }
226
+		SessionAlert::success(
227
+			"Template deleted. Any users who were using this template have had automatic welcoming disabled.");
228
+		$this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
229
+	}
230 230
 
231
-    private function validate($userCode, $botCode)
232
-    {
233
-        if ($userCode === null) {
234
-            throw new ApplicationLogicException('User code cannot be null');
235
-        }
231
+	private function validate($userCode, $botCode)
232
+	{
233
+		if ($userCode === null) {
234
+			throw new ApplicationLogicException('User code cannot be null');
235
+		}
236 236
 
237
-        if ($botCode === null) {
238
-            throw new ApplicationLogicException('Bot code cannot be null');
239
-        }
240
-    }
237
+		if ($botCode === null) {
238
+			throw new ApplicationLogicException('Bot code cannot be null');
239
+		}
240
+	}
241 241
 }
Please login to merge, or discard this patch.
includes/Pages/PageEditComment.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -20,67 +20,67 @@
 block discarded – undo
20 20
 
21 21
 class PageEditComment extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     * @throws ApplicationLogicException
26
-     */
27
-    protected function main()
28
-    {
29
-        $commentId = WebRequest::getInt('id');
30
-        if ($commentId === null) {
31
-            throw new ApplicationLogicException('Comment ID not specified');
32
-        }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 * @throws ApplicationLogicException
26
+	 */
27
+	protected function main()
28
+	{
29
+		$commentId = WebRequest::getInt('id');
30
+		if ($commentId === null) {
31
+			throw new ApplicationLogicException('Comment ID not specified');
32
+		}
33 33
 
34
-        $database = $this->getDatabase();
34
+		$database = $this->getDatabase();
35 35
 
36
-        /** @var Comment $comment */
37
-        $comment = Comment::getById($commentId, $database);
38
-        if ($comment === false) {
39
-            throw new ApplicationLogicException('Comment not found');
40
-        }
36
+		/** @var Comment $comment */
37
+		$comment = Comment::getById($commentId, $database);
38
+		if ($comment === false) {
39
+			throw new ApplicationLogicException('Comment not found');
40
+		}
41 41
 
42
-        $currentUser = User::getCurrent($database);
43
-        if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
-            throw new AccessDeniedException($this->getSecurityManager());
45
-        }
42
+		$currentUser = User::getCurrent($database);
43
+		if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
+			throw new AccessDeniedException($this->getSecurityManager());
45
+		}
46 46
 
47
-        /** @var Request $request */
48
-        $request = Request::getById($comment->getRequest(), $database);
47
+		/** @var Request $request */
48
+		$request = Request::getById($comment->getRequest(), $database);
49 49
 
50
-        if ($request === false) {
51
-            throw new ApplicationLogicException('Request was not found.');
52
-        }
50
+		if ($request === false) {
51
+			throw new ApplicationLogicException('Request was not found.');
52
+		}
53 53
 
54
-        if (WebRequest::wasPosted()) {
55
-            $this->validateCSRFToken();
56
-            $newComment = WebRequest::postString('newcomment');
57
-            $visibility = WebRequest::postString('visibility');
54
+		if (WebRequest::wasPosted()) {
55
+			$this->validateCSRFToken();
56
+			$newComment = WebRequest::postString('newcomment');
57
+			$visibility = WebRequest::postString('visibility');
58 58
 
59
-            if ($visibility !== 'user' && $visibility !== 'admin') {
60
-                throw new ApplicationLogicException('Comment visibility is not valid');
61
-            }
59
+			if ($visibility !== 'user' && $visibility !== 'admin') {
60
+				throw new ApplicationLogicException('Comment visibility is not valid');
61
+			}
62 62
 
63
-            // optimisticly lock from the load of the edit comment form
64
-            $updateVersion = WebRequest::postInt('updateversion');
65
-            $comment->setUpdateVersion($updateVersion);
63
+			// optimisticly lock from the load of the edit comment form
64
+			$updateVersion = WebRequest::postInt('updateversion');
65
+			$comment->setUpdateVersion($updateVersion);
66 66
 
67
-            $comment->setComment($newComment);
68
-            $comment->setVisibility($visibility);
67
+			$comment->setComment($newComment);
68
+			$comment->setVisibility($visibility);
69 69
 
70
-            $comment->save();
70
+			$comment->save();
71 71
 
72
-            Logger::editComment($database, $comment, $request);
73
-            $this->getNotificationHelper()->commentEdited($comment, $request);
74
-            SessionAlert::success("Comment has been saved successfully");
72
+			Logger::editComment($database, $comment, $request);
73
+			$this->getNotificationHelper()->commentEdited($comment, $request);
74
+			SessionAlert::success("Comment has been saved successfully");
75 75
 
76
-            $this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
-        }
78
-        else {
79
-            $this->assignCSRFToken();
80
-            $this->assign('comment', $comment);
81
-            $this->assign('request', $request);
82
-            $this->assign('user', User::getById($comment->getUser(), $database));
83
-            $this->setTemplate('edit-comment.tpl');
84
-        }
85
-    }
76
+			$this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
+		}
78
+		else {
79
+			$this->assignCSRFToken();
80
+			$this->assign('comment', $comment);
81
+			$this->assign('request', $request);
82
+			$this->assign('user', User::getById($comment->getUser(), $database));
83
+			$this->setTemplate('edit-comment.tpl');
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
includes/Pages/PageOAuth.php 1 patch
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.
includes/Pages/PageLogout.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 block discarded – undo
13 13
 
14 14
 class PageLogout extends InternalPageBase
15 15
 {
16
-    /**
17
-     * Main function for this page, when no specific actions are called.
18
-     */
19
-    protected function main()
20
-    {
21
-        Session::destroy();
22
-        $this->redirect("login");
23
-    }
16
+	/**
17
+	 * Main function for this page, when no specific actions are called.
18
+	 */
19
+	protected function main()
20
+	{
21
+		Session::destroy();
22
+		$this->redirect("login");
23
+	}
24 24
 
25
-    protected function isProtectedPage()
26
-    {
27
-        return false;
28
-    }
25
+	protected function isProtectedPage()
26
+	{
27
+		return false;
28
+	}
29 29
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterOption.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@
 block discarded – undo
12 12
 
13 13
 class PageRegisterOption 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
-        $this->setTemplate('registration/option.tpl');
22
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->setTemplate('registration/option.tpl');
22
+	}
23 23
 
24
-    protected function isProtectedPage()
25
-    {
26
-        return false;
27
-    }
24
+	protected function isProtectedPage()
25
+	{
26
+		return false;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterStandard.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
 
11 11
 class PageRegisterStandard extends PageRegisterBase
12 12
 {
13
-    /**
14
-     * @return string
15
-     */
16
-    protected function getRegistrationTemplate()
17
-    {
18
-        return "registration/register.tpl";
19
-    }
13
+	/**
14
+	 * @return string
15
+	 */
16
+	protected function getRegistrationTemplate()
17
+	{
18
+		return "registration/register.tpl";
19
+	}
20 20
 
21
-    /**
22
-     * @return string
23
-     */
24
-    protected function getDefaultRole()
25
-    {
26
-        return 'user';
27
-    }
21
+	/**
22
+	 * @return string
23
+	 */
24
+	protected function getDefaultRole()
25
+	{
26
+		return 'user';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/PageSiteNotice.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 
16 16
 class PageSiteNotice extends InternalPageBase
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->setHtmlTitle('Site Notice');
25
-
26
-        $database = $this->getDatabase();
27
-
28
-        /** @var SiteNotice $siteNoticeMessage */
29
-        $siteNoticeMessage = SiteNotice::getById(1, $database);
30
-
31
-        // Dual-mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-
35
-            $siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
-            $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
-            $siteNoticeMessage->save();
38
-
39
-            Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
-            $this->getNotificationHelper()->siteNoticeEdited();
41
-
42
-            $this->redirect();
43
-        }
44
-        else {
45
-            $this->assignCSRFToken();
46
-
47
-            $this->setTemplate('site-notice/edit-form.tpl');
48
-            $this->assign('message', $siteNoticeMessage);
49
-        }
50
-    }
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->setHtmlTitle('Site Notice');
25
+
26
+		$database = $this->getDatabase();
27
+
28
+		/** @var SiteNotice $siteNoticeMessage */
29
+		$siteNoticeMessage = SiteNotice::getById(1, $database);
30
+
31
+		// Dual-mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+
35
+			$siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
+			$siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
+			$siteNoticeMessage->save();
38
+
39
+			Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
+			$this->getNotificationHelper()->siteNoticeEdited();
41
+
42
+			$this->redirect();
43
+		}
44
+		else {
45
+			$this->assignCSRFToken();
46
+
47
+			$this->setTemplate('site-notice/edit-form.tpl');
48
+			$this->assign('message', $siteNoticeMessage);
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -18,113 +18,113 @@
 block discarded – undo
18 18
 
19 19
 class PageLog extends InternalPageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Logs');
27
-
28
-        $filterUser = WebRequest::getString('filterUser');
29
-        $filterAction = WebRequest::getString('filterAction');
30
-
31
-        $database = $this->getDatabase();
32
-
33
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
34
-            return UserSearchHelper::get($database)->fetchColumn('username');
35
-        });
36
-
37
-        $limit = WebRequest::getInt('limit');
38
-        if ($limit === null) {
39
-            $limit = 100;
40
-        }
41
-
42
-        $page = WebRequest::getInt('page');
43
-        if ($page === null) {
44
-            $page = 1;
45
-        }
46
-
47
-        $offset = ($page - 1) * $limit;
48
-
49
-        $logSearch = LogSearchHelper::get($database)->limit($limit, $offset);
50
-        if ($filterUser !== null) {
51
-            $logSearch->byUser(User::getByUsername($filterUser, $database)->getId());
52
-        }
53
-
54
-        if ($filterAction !== null) {
55
-            $logSearch->byAction($filterAction);
56
-        }
57
-
58
-        /** @var Log[] $logs */
59
-        $logs = $logSearch->getRecordCount($count)->fetch();
60
-
61
-        if ($count === 0) {
62
-            $this->assign('logs', array());
63
-            $this->setTemplate('logs/main.tpl');
64
-
65
-            return;
66
-        }
67
-
68
-        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
69
-
70
-        $this->setupPageData($page, $limit, $count);
71
-
72
-        $this->assign("logs", $logData);
73
-        $this->assign("users", $users);
74
-
75
-        $this->assign("filterUser", $filterUser);
76
-        $this->assign("filterAction", $filterAction);
77
-
78
-        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
79
-
80
-        $this->setTemplate("logs/main.tpl");
81
-    }
82
-
83
-    /**
84
-     * @param int $page
85
-     * @param int $limit
86
-     * @param int $count
87
-     */
88
-    protected function setupPageData($page, $limit, $count)
89
-    {
90
-        // The number of pages on the pager to show. Must be odd
91
-        $pageLimit = 9;
92
-
93
-        $pageData = array(
94
-            // Can the user go to the previous page?
95
-            'canprev'   => $page != 1,
96
-            // Can the user go to the next page?
97
-            'cannext'   => ($page * $limit) < $count,
98
-            // Maximum page number
99
-            'maxpage'   => ceil($count / $limit),
100
-            // Limit to the number of pages to display
101
-            'pagelimit' => $pageLimit,
102
-        );
103
-
104
-        // number of pages either side of the current to show
105
-        $pageMargin = (($pageLimit - 1) / 2);
106
-
107
-        // Calculate the number of pages either side to show - this is for situations like:
108
-        //  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
109
-        $pageData['lowpage'] = max(1, $page - $pageMargin);
110
-        $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
111
-        $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
112
-
113
-        if ($pageCount < $pageLimit) {
114
-            if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
115
-                $pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
116
-            }
117
-            elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
118
-                $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
119
-            }
120
-        }
121
-
122
-        // Put the range of pages into the page data
123
-        $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
124
-
125
-        $this->assign("pagedata", $pageData);
126
-
127
-        $this->assign("limit", $limit);
128
-        $this->assign("page", $page);
129
-    }
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Logs');
27
+
28
+		$filterUser = WebRequest::getString('filterUser');
29
+		$filterAction = WebRequest::getString('filterAction');
30
+
31
+		$database = $this->getDatabase();
32
+
33
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
34
+			return UserSearchHelper::get($database)->fetchColumn('username');
35
+		});
36
+
37
+		$limit = WebRequest::getInt('limit');
38
+		if ($limit === null) {
39
+			$limit = 100;
40
+		}
41
+
42
+		$page = WebRequest::getInt('page');
43
+		if ($page === null) {
44
+			$page = 1;
45
+		}
46
+
47
+		$offset = ($page - 1) * $limit;
48
+
49
+		$logSearch = LogSearchHelper::get($database)->limit($limit, $offset);
50
+		if ($filterUser !== null) {
51
+			$logSearch->byUser(User::getByUsername($filterUser, $database)->getId());
52
+		}
53
+
54
+		if ($filterAction !== null) {
55
+			$logSearch->byAction($filterAction);
56
+		}
57
+
58
+		/** @var Log[] $logs */
59
+		$logs = $logSearch->getRecordCount($count)->fetch();
60
+
61
+		if ($count === 0) {
62
+			$this->assign('logs', array());
63
+			$this->setTemplate('logs/main.tpl');
64
+
65
+			return;
66
+		}
67
+
68
+		list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
69
+
70
+		$this->setupPageData($page, $limit, $count);
71
+
72
+		$this->assign("logs", $logData);
73
+		$this->assign("users", $users);
74
+
75
+		$this->assign("filterUser", $filterUser);
76
+		$this->assign("filterAction", $filterAction);
77
+
78
+		$this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
79
+
80
+		$this->setTemplate("logs/main.tpl");
81
+	}
82
+
83
+	/**
84
+	 * @param int $page
85
+	 * @param int $limit
86
+	 * @param int $count
87
+	 */
88
+	protected function setupPageData($page, $limit, $count)
89
+	{
90
+		// The number of pages on the pager to show. Must be odd
91
+		$pageLimit = 9;
92
+
93
+		$pageData = array(
94
+			// Can the user go to the previous page?
95
+			'canprev'   => $page != 1,
96
+			// Can the user go to the next page?
97
+			'cannext'   => ($page * $limit) < $count,
98
+			// Maximum page number
99
+			'maxpage'   => ceil($count / $limit),
100
+			// Limit to the number of pages to display
101
+			'pagelimit' => $pageLimit,
102
+		);
103
+
104
+		// number of pages either side of the current to show
105
+		$pageMargin = (($pageLimit - 1) / 2);
106
+
107
+		// Calculate the number of pages either side to show - this is for situations like:
108
+		//  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
109
+		$pageData['lowpage'] = max(1, $page - $pageMargin);
110
+		$pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
111
+		$pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
112
+
113
+		if ($pageCount < $pageLimit) {
114
+			if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
115
+				$pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
116
+			}
117
+			elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
118
+				$pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
119
+			}
120
+		}
121
+
122
+		// Put the range of pages into the page data
123
+		$pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
124
+
125
+		$this->assign("pagedata", $pageData);
126
+
127
+		$this->assign("limit", $limit);
128
+		$this->assign("page", $page);
129
+	}
130 130
 }
Please login to merge, or discard this patch.