Completed
Pull Request — newinternal (#418)
by Matthew
04:57
created
includes/Pages/PageWelcomeTemplateManagement.php 1 patch
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -20,245 +20,245 @@
 block discarded – undo
20 20
 
21 21
 class PageWelcomeTemplateManagement extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     * @return void
26
-     */
27
-    protected function main()
28
-    {
29
-        $templateList = WelcomeTemplate::getAll($this->getDatabase());
30
-
31
-        $this->assignCSRFToken();
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 * @return void
26
+	 */
27
+	protected function main()
28
+	{
29
+		$templateList = WelcomeTemplate::getAll($this->getDatabase());
30
+
31
+		$this->assignCSRFToken();
32 32
 
33
-        $this->assign('templateList', $templateList);
34
-        $this->setTemplate('welcome-template/list.tpl');
35
-    }
33
+		$this->assign('templateList', $templateList);
34
+		$this->setTemplate('welcome-template/list.tpl');
35
+	}
36 36
 
37
-    /**
38
-     * Handles the requests for selecting a template to use.
39
-     *
40
-     * @throws ApplicationLogicException
41
-     */
42
-    protected function select()
43
-    {
44
-        // get rid of GETs
45
-        if (!WebRequest::wasPosted()) {
46
-            $this->redirect('welcomeTemplates');
47
-        }
48
-
49
-        $this->validateCSRFToken();
50
-
51
-        $user = User::getCurrent($this->getDatabase());
52
-
53
-        if (WebRequest::postBoolean('disable')) {
54
-            $user->setWelcomeTemplate(null);
55
-            $user->save();
56
-
57
-            SessionAlert::success('Disabled automatic user welcoming.');
58
-            $this->redirect('welcomeTemplates');
59
-
60
-            return;
61
-        }
62
-
63
-        $database = $this->getDatabase();
37
+	/**
38
+	 * Handles the requests for selecting a template to use.
39
+	 *
40
+	 * @throws ApplicationLogicException
41
+	 */
42
+	protected function select()
43
+	{
44
+		// get rid of GETs
45
+		if (!WebRequest::wasPosted()) {
46
+			$this->redirect('welcomeTemplates');
47
+		}
48
+
49
+		$this->validateCSRFToken();
50
+
51
+		$user = User::getCurrent($this->getDatabase());
52
+
53
+		if (WebRequest::postBoolean('disable')) {
54
+			$user->setWelcomeTemplate(null);
55
+			$user->save();
56
+
57
+			SessionAlert::success('Disabled automatic user welcoming.');
58
+			$this->redirect('welcomeTemplates');
59
+
60
+			return;
61
+		}
62
+
63
+		$database = $this->getDatabase();
64 64
 
65
-        $templateId = WebRequest::postInt('template');
66
-        /** @var false|WelcomeTemplate $template */
67
-        $template = WelcomeTemplate::getById($templateId, $database);
65
+		$templateId = WebRequest::postInt('template');
66
+		/** @var false|WelcomeTemplate $template */
67
+		$template = WelcomeTemplate::getById($templateId, $database);
68 68
 
69
-        if ($template === false || $template->isDeleted()) {
70
-            throw new ApplicationLogicException('Unknown template');
71
-        }
69
+		if ($template === false || $template->isDeleted()) {
70
+			throw new ApplicationLogicException('Unknown template');
71
+		}
72 72
 
73
-        $user->setWelcomeTemplate($template->getId());
74
-        $user->save();
73
+		$user->setWelcomeTemplate($template->getId());
74
+		$user->save();
75 75
 
76
-        SessionAlert::success("Updated selected welcome template for automatic welcoming.");
76
+		SessionAlert::success("Updated selected welcome template for automatic welcoming.");
77 77
 
78
-        $this->redirect('welcomeTemplates');
79
-    }
78
+		$this->redirect('welcomeTemplates');
79
+	}
80 80
 
81
-    /**
82
-     * Handles the requests for viewing a template.
83
-     *
84
-     * @throws ApplicationLogicException
85
-     */
86
-    protected function view()
87
-    {
88
-        $database = $this->getDatabase();
81
+	/**
82
+	 * Handles the requests for viewing a template.
83
+	 *
84
+	 * @throws ApplicationLogicException
85
+	 */
86
+	protected function view()
87
+	{
88
+		$database = $this->getDatabase();
89 89
 
90
-        $templateId = WebRequest::getInt('template');
90
+		$templateId = WebRequest::getInt('template');
91 91
 
92
-        /** @var WelcomeTemplate $template */
93
-        $template = WelcomeTemplate::getById($templateId, $database);
92
+		/** @var WelcomeTemplate $template */
93
+		$template = WelcomeTemplate::getById($templateId, $database);
94 94
 
95
-        if ($template === false) {
96
-            throw new ApplicationLogicException('Cannot find requested template');
97
-        }
95
+		if ($template === false) {
96
+			throw new ApplicationLogicException('Cannot find requested template');
97
+		}
98 98
 
99
-        $templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
99
+		$templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
100 100
 
101
-        $this->assign('templateHtml', $templateHtml);
102
-        $this->assign('template', $template);
103
-        $this->setTemplate('welcome-template/view.tpl');
104
-    }
101
+		$this->assign('templateHtml', $templateHtml);
102
+		$this->assign('template', $template);
103
+		$this->setTemplate('welcome-template/view.tpl');
104
+	}
105 105
 
106
-    /**
107
-     * Handler for the add action to create a new welcome template
108
-     *
109
-     * @throws Exception
110
-     */
111
-    protected function add()
112
-    {
113
-        if (WebRequest::wasPosted()) {
114
-            $this->validateCSRFToken();
115
-            $database = $this->getDatabase();
106
+	/**
107
+	 * Handler for the add action to create a new welcome template
108
+	 *
109
+	 * @throws Exception
110
+	 */
111
+	protected function add()
112
+	{
113
+		if (WebRequest::wasPosted()) {
114
+			$this->validateCSRFToken();
115
+			$database = $this->getDatabase();
116 116
 
117
-            $userCode = WebRequest::postString('usercode');
118
-            $botCode = WebRequest::postString('botcode');
117
+			$userCode = WebRequest::postString('usercode');
118
+			$botCode = WebRequest::postString('botcode');
119 119
 
120
-            $this->validate($userCode, $botCode);
120
+			$this->validate($userCode, $botCode);
121 121
 
122
-            $template = new WelcomeTemplate();
123
-            $template->setDatabase($database);
124
-            $template->setUserCode($userCode);
125
-            $template->setBotCode($botCode);
126
-            $template->save();
122
+			$template = new WelcomeTemplate();
123
+			$template->setDatabase($database);
124
+			$template->setUserCode($userCode);
125
+			$template->setBotCode($botCode);
126
+			$template->save();
127 127
 
128
-            Logger::welcomeTemplateCreated($database, $template);
128
+			Logger::welcomeTemplateCreated($database, $template);
129 129
 
130
-            $this->getNotificationHelper()->welcomeTemplateCreated($template);
130
+			$this->getNotificationHelper()->welcomeTemplateCreated($template);
131 131
 
132
-            SessionAlert::success("Template successfully created.");
132
+			SessionAlert::success("Template successfully created.");
133 133
 
134
-            $this->redirect('welcomeTemplates');
135
-        }
136
-        else {
137
-            $this->assignCSRFToken();
138
-            $this->setTemplate("welcome-template/add.tpl");
139
-        }
140
-    }
134
+			$this->redirect('welcomeTemplates');
135
+		}
136
+		else {
137
+			$this->assignCSRFToken();
138
+			$this->setTemplate("welcome-template/add.tpl");
139
+		}
140
+	}
141 141
 
142
-    /**
143
-     * Hander for editing templates
144
-     */
145
-    protected function edit()
146
-    {
147
-        $database = $this->getDatabase();
142
+	/**
143
+	 * Hander for editing templates
144
+	 */
145
+	protected function edit()
146
+	{
147
+		$database = $this->getDatabase();
148 148
 
149
-        $templateId = WebRequest::getInt('template');
149
+		$templateId = WebRequest::getInt('template');
150 150
 
151
-        /** @var WelcomeTemplate $template */
152
-        $template = WelcomeTemplate::getById($templateId, $database);
153
-
154
-        if ($template === false) {
155
-            throw new ApplicationLogicException('Cannot find requested template');
156
-        }
157
-
158
-        if ($template->isDeleted()) {
159
-            throw new ApplicationLogicException('The specified template has been deleted');
160
-        }
161
-
162
-        if (WebRequest::wasPosted()) {
163
-            $this->validateCSRFToken();
164
-
165
-            $userCode = WebRequest::postString('usercode');
166
-            $botCode = WebRequest::postString('botcode');
167
-
168
-            $this->validate($userCode, $botCode);
169
-
170
-            $template->setUserCode($userCode);
171
-            $template->setBotCode($botCode);
172
-            $template->setUpdateVersion(WebRequest::postInt('updateversion'));
173
-            $template->save();
174
-
175
-            Logger::welcomeTemplateEdited($database, $template);
176
-
177
-            SessionAlert::success("Template updated.");
178
-
179
-            $this->getNotificationHelper()->welcomeTemplateEdited($template);
180
-
181
-            $this->redirect('welcomeTemplates');
182
-        }
183
-        else {
184
-            $this->assignCSRFToken();
185
-            $this->assign('template', $template);
186
-            $this->setTemplate('welcome-template/edit.tpl');
187
-        }
188
-    }
189
-
190
-    protected function delete()
191
-    {
192
-        $this->redirect('welcomeTemplates');
193
-
194
-        if (!WebRequest::wasPosted()) {
195
-            return;
196
-        }
197
-
198
-        $this->validateCSRFToken();
199
-
200
-        $database = $this->getDatabase();
201
-
202
-        $templateId = WebRequest::postInt('template');
203
-        $updateVersion = WebRequest::postInt('updateversion');
204
-
205
-        /** @var WelcomeTemplate $template */
206
-        $template = WelcomeTemplate::getById($templateId, $database);
207
-
208
-        if ($template === false || $template->isDeleted()) {
209
-            throw new ApplicationLogicException('Cannot find requested template');
210
-        }
211
-
212
-        // set the update version to the version sent by the client (optimisticly lock from initial page load)
213
-        $template->setUpdateVersion($updateVersion);
214
-
215
-        $database
216
-            ->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
217
-            ->execute(array(":id" => $templateId));
218
-
219
-        Logger::welcomeTemplateDeleted($database, $template);
220
-
221
-        $template->delete();
222
-
223
-        SessionAlert::success(
224
-            "Template deleted. Any users who were using this template have had automatic welcoming disabled.");
225
-        $this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
226
-    }
227
-
228
-    /**
229
-     * Sets up the security for this page. If certain actions have different permissions, this should be reflected in
230
-     * the return value from this function.
231
-     *
232
-     * If this page even supports actions, you will need to check the route
233
-     *
234
-     * @return SecurityConfiguration
235
-     * @category Security-Critical
236
-     */
237
-    protected function getSecurityConfiguration()
238
-    {
239
-        switch ($this->getRouteName()) {
240
-            case 'edit':
241
-            case 'add':
242
-            case 'delete':
243
-                // WARNING: if you want to unlink edit/add/delete, you'll want to change the barrier tests in the
244
-                // template
245
-                return $this->getSecurityManager()->configure()->asAdminPage();
246
-            case 'view':
247
-            case 'select':
248
-                return $this->getSecurityManager()->configure()->asInternalPage();
249
-            default:
250
-                return $this->getSecurityManager()->configure()->asInternalPage();
251
-        }
252
-    }
253
-
254
-    private function validate($userCode, $botCode)
255
-    {
256
-        if ($userCode === null) {
257
-            throw new ApplicationLogicException('User code cannot be null');
258
-        }
259
-
260
-        if ($botCode === null) {
261
-            throw new ApplicationLogicException('Bot code cannot be null');
262
-        }
263
-    }
151
+		/** @var WelcomeTemplate $template */
152
+		$template = WelcomeTemplate::getById($templateId, $database);
153
+
154
+		if ($template === false) {
155
+			throw new ApplicationLogicException('Cannot find requested template');
156
+		}
157
+
158
+		if ($template->isDeleted()) {
159
+			throw new ApplicationLogicException('The specified template has been deleted');
160
+		}
161
+
162
+		if (WebRequest::wasPosted()) {
163
+			$this->validateCSRFToken();
164
+
165
+			$userCode = WebRequest::postString('usercode');
166
+			$botCode = WebRequest::postString('botcode');
167
+
168
+			$this->validate($userCode, $botCode);
169
+
170
+			$template->setUserCode($userCode);
171
+			$template->setBotCode($botCode);
172
+			$template->setUpdateVersion(WebRequest::postInt('updateversion'));
173
+			$template->save();
174
+
175
+			Logger::welcomeTemplateEdited($database, $template);
176
+
177
+			SessionAlert::success("Template updated.");
178
+
179
+			$this->getNotificationHelper()->welcomeTemplateEdited($template);
180
+
181
+			$this->redirect('welcomeTemplates');
182
+		}
183
+		else {
184
+			$this->assignCSRFToken();
185
+			$this->assign('template', $template);
186
+			$this->setTemplate('welcome-template/edit.tpl');
187
+		}
188
+	}
189
+
190
+	protected function delete()
191
+	{
192
+		$this->redirect('welcomeTemplates');
193
+
194
+		if (!WebRequest::wasPosted()) {
195
+			return;
196
+		}
197
+
198
+		$this->validateCSRFToken();
199
+
200
+		$database = $this->getDatabase();
201
+
202
+		$templateId = WebRequest::postInt('template');
203
+		$updateVersion = WebRequest::postInt('updateversion');
204
+
205
+		/** @var WelcomeTemplate $template */
206
+		$template = WelcomeTemplate::getById($templateId, $database);
207
+
208
+		if ($template === false || $template->isDeleted()) {
209
+			throw new ApplicationLogicException('Cannot find requested template');
210
+		}
211
+
212
+		// set the update version to the version sent by the client (optimisticly lock from initial page load)
213
+		$template->setUpdateVersion($updateVersion);
214
+
215
+		$database
216
+			->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
217
+			->execute(array(":id" => $templateId));
218
+
219
+		Logger::welcomeTemplateDeleted($database, $template);
220
+
221
+		$template->delete();
222
+
223
+		SessionAlert::success(
224
+			"Template deleted. Any users who were using this template have had automatic welcoming disabled.");
225
+		$this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
226
+	}
227
+
228
+	/**
229
+	 * Sets up the security for this page. If certain actions have different permissions, this should be reflected in
230
+	 * the return value from this function.
231
+	 *
232
+	 * If this page even supports actions, you will need to check the route
233
+	 *
234
+	 * @return SecurityConfiguration
235
+	 * @category Security-Critical
236
+	 */
237
+	protected function getSecurityConfiguration()
238
+	{
239
+		switch ($this->getRouteName()) {
240
+			case 'edit':
241
+			case 'add':
242
+			case 'delete':
243
+				// WARNING: if you want to unlink edit/add/delete, you'll want to change the barrier tests in the
244
+				// template
245
+				return $this->getSecurityManager()->configure()->asAdminPage();
246
+			case 'view':
247
+			case 'select':
248
+				return $this->getSecurityManager()->configure()->asInternalPage();
249
+			default:
250
+				return $this->getSecurityManager()->configure()->asInternalPage();
251
+		}
252
+	}
253
+
254
+	private function validate($userCode, $botCode)
255
+	{
256
+		if ($userCode === null) {
257
+			throw new ApplicationLogicException('User code cannot be null');
258
+		}
259
+
260
+		if ($botCode === null) {
261
+			throw new ApplicationLogicException('Bot code cannot be null');
262
+		}
263
+	}
264 264
 }
265 265
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageViewRequest.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -23,229 +23,229 @@
 block discarded – undo
23 23
 
24 24
 class PageViewRequest extends InternalPageBase
25 25
 {
26
-    use RequestData;
27
-    const PRIVATE_DATA_BARRIER = 'privateData';
28
-    const SET_BAN_BARRIER = 'setBan';
29
-    const STATUS_SYMBOL_OPEN = '&#x2610';
30
-    const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
-    const STATUS_SYMBOL_REJECTED = '&#x2612';
32
-
33
-    /**
34
-     * Main function for this page, when no specific actions are called.
35
-     * @throws ApplicationLogicException
36
-     */
37
-    protected function main()
38
-    {
39
-        // set up csrf protection
40
-        $this->assignCSRFToken();
41
-
42
-        // get some useful objects
43
-        $database = $this->getDatabase();
44
-        $request = $this->getRequest($database, WebRequest::getInt('id'));
45
-        $config = $this->getSiteConfiguration();
46
-        $currentUser = User::getCurrent($database);
47
-
48
-        // Test we should be able to look at this request
49
-        if ($config->getEmailConfirmationEnabled()) {
50
-            if ($request->getEmailConfirm() !== 'Confirmed') {
51
-                // Not allowed to look at this yet.
52
-                throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
-            }
54
-        }
55
-
56
-        $this->setupBasicData($request, $config);
57
-
58
-        $this->setupUsernameData($request);
59
-
60
-        $this->setupTitle($request);
61
-
62
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
-        $this->setupGeneralData($database);
64
-
65
-        $this->assign('requestDataCleared', false);
66
-        if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
-            $this->assign('requestDataCleared', true);
68
-        }
69
-
70
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
-
72
-        $this->setupLogData($request, $database);
73
-
74
-        if ($allowedPrivateData) {
75
-            $this->setTemplate('view-request/main-with-data.tpl');
76
-            $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
77
-
78
-            if ($currentUser->isCheckuser()) {
79
-                $this->setTemplate('view-request/main-with-checkuser-data.tpl');
80
-                $this->setupCheckUserData($request);
81
-            }
82
-        }
83
-        else {
84
-            $this->setTemplate('view-request/main.tpl');
85
-        }
86
-    }
87
-
88
-    /**
89
-     * @param Request $request
90
-     */
91
-    protected function setupTitle(Request $request)
92
-    {
93
-        $statusSymbol = self::STATUS_SYMBOL_OPEN;
94
-        if ($request->getStatus() === 'Closed') {
95
-            if ($request->getWasCreated()) {
96
-                $statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
97
-            }
98
-            else {
99
-                $statusSymbol = self::STATUS_SYMBOL_REJECTED;
100
-            }
101
-        }
102
-
103
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
104
-    }
105
-
106
-    /**
107
-     * Sets up data unrelated to the request, such as the email template information
108
-     *
109
-     * @param PdoDatabase $database
110
-     */
111
-    protected function setupGeneralData(PdoDatabase $database)
112
-    {
113
-        $config = $this->getSiteConfiguration();
114
-
115
-        $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
116
-
117
-        $this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
118
-
119
-        $this->assign('requestStates', $config->getRequestStates());
120
-
121
-        /** @var EmailTemplate $createdTemplate */
122
-        $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
123
-
124
-        $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
125
-        $this->assign('createdJsQuestion', $createdTemplate->getJsquestion());
126
-        $this->assign('createdId', $createdTemplate->getId());
127
-        $this->assign('createdName', $createdTemplate->getName());
128
-
129
-        $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
130
-        $this->assign("createReasons", $createReasons);
131
-        $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
132
-        $this->assign("declineReasons", $declineReasons);
133
-
134
-        $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
135
-        $this->assign("allCreateReasons", $allCreateReasons);
136
-        $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
137
-        $this->assign("allDeclineReasons", $allDeclineReasons);
138
-        $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
139
-        $this->assign("allOtherReasons", $allOtherReasons);
140
-
141
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
142
-            return User::getAllUsernames($database, true);
143
-        });
144
-    }
145
-
146
-    private function setupLogData(Request $request, PdoDatabase $database)
147
-    {
148
-        $currentUser = User::getCurrent($database);
149
-
150
-        $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database);
151
-        $requestLogs = array();
152
-
153
-        if (trim($request->getComment()) !== "") {
154
-            $requestLogs[] = array(
155
-                'type'     => 'comment',
156
-                'security' => 'user',
157
-                'userid'   => null,
158
-                'user'     => $request->getName(),
159
-                'entry'    => null,
160
-                'time'     => $request->getDate(),
161
-                'canedit'  => false,
162
-                'id'       => $request->getId(),
163
-                'comment'  => $request->getComment(),
164
-            );
165
-        }
166
-
167
-        /** @var User[] $nameCache */
168
-        $nameCache = array();
169
-
170
-        $editableComments = $this->allowEditingComments($currentUser);
171
-
172
-        /** @var Log|Comment $entry */
173
-        foreach ($logs as $entry) {
174
-            // both log and comment have a 'user' field
175
-            if (!array_key_exists($entry->getUser(), $nameCache)) {
176
-                $entryUser = User::getById($entry->getUser(), $database);
177
-                $nameCache[$entry->getUser()] = $entryUser;
178
-            }
179
-
180
-            if ($entry instanceof Comment) {
181
-                $requestLogs[] = array(
182
-                    'type'     => 'comment',
183
-                    'security' => $entry->getVisibility(),
184
-                    'user'     => $nameCache[$entry->getUser()]->getUsername(),
185
-                    'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
186
-                    'entry'    => null,
187
-                    'time'     => $entry->getTime(),
188
-                    'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
189
-                    'id'       => $entry->getId(),
190
-                    'comment'  => $entry->getComment(),
191
-                );
192
-            }
193
-
194
-            if ($entry instanceof Log) {
195
-                $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
196
-                $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
197
-
198
-                $requestLogs[] = array(
199
-                    'type'     => 'log',
200
-                    'security' => 'user',
201
-                    'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
202
-                    'user'     => $entryUser->getUsername(),
203
-                    'entry'    => LogHelper::getLogDescription($entry),
204
-                    'time'     => $entry->getTimestamp(),
205
-                    'canedit'  => false,
206
-                    'id'       => $entry->getId(),
207
-                    'comment'  => $entry->getComment(),
208
-                );
209
-            }
210
-        }
211
-
212
-        $this->assign("requestLogs", $requestLogs);
213
-    }
214
-
215
-    /**
216
-     * @param Request $request
217
-     */
218
-    protected function setupUsernameData(Request $request)
219
-    {
220
-        $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
221
-
222
-        $this->assign('requestIsBlacklisted', $blacklistData !== false);
223
-        $this->assign('requestBlacklist', $blacklistData);
224
-
225
-        try {
226
-            $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
227
-        }
228
-        catch (Exception $ex) {
229
-            $spoofs = $ex->getMessage();
230
-        }
231
-
232
-        $this->assign("spoofs", $spoofs);
233
-    }
234
-
235
-    /**
236
-     * @param User $currentUser
237
-     *
238
-     * @return bool
239
-     */
240
-    private function allowEditingComments(User $currentUser)
241
-    {
242
-        $editableComments = false;
243
-        if ($currentUser->isAdmin() || $currentUser->isCheckuser()) {
244
-            $editableComments = true;
245
-
246
-            return $editableComments;
247
-        }
248
-
249
-        return $editableComments;
250
-    }
26
+	use RequestData;
27
+	const PRIVATE_DATA_BARRIER = 'privateData';
28
+	const SET_BAN_BARRIER = 'setBan';
29
+	const STATUS_SYMBOL_OPEN = '&#x2610';
30
+	const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
+	const STATUS_SYMBOL_REJECTED = '&#x2612';
32
+
33
+	/**
34
+	 * Main function for this page, when no specific actions are called.
35
+	 * @throws ApplicationLogicException
36
+	 */
37
+	protected function main()
38
+	{
39
+		// set up csrf protection
40
+		$this->assignCSRFToken();
41
+
42
+		// get some useful objects
43
+		$database = $this->getDatabase();
44
+		$request = $this->getRequest($database, WebRequest::getInt('id'));
45
+		$config = $this->getSiteConfiguration();
46
+		$currentUser = User::getCurrent($database);
47
+
48
+		// Test we should be able to look at this request
49
+		if ($config->getEmailConfirmationEnabled()) {
50
+			if ($request->getEmailConfirm() !== 'Confirmed') {
51
+				// Not allowed to look at this yet.
52
+				throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
+			}
54
+		}
55
+
56
+		$this->setupBasicData($request, $config);
57
+
58
+		$this->setupUsernameData($request);
59
+
60
+		$this->setupTitle($request);
61
+
62
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
+		$this->setupGeneralData($database);
64
+
65
+		$this->assign('requestDataCleared', false);
66
+		if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
+			$this->assign('requestDataCleared', true);
68
+		}
69
+
70
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
+
72
+		$this->setupLogData($request, $database);
73
+
74
+		if ($allowedPrivateData) {
75
+			$this->setTemplate('view-request/main-with-data.tpl');
76
+			$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
77
+
78
+			if ($currentUser->isCheckuser()) {
79
+				$this->setTemplate('view-request/main-with-checkuser-data.tpl');
80
+				$this->setupCheckUserData($request);
81
+			}
82
+		}
83
+		else {
84
+			$this->setTemplate('view-request/main.tpl');
85
+		}
86
+	}
87
+
88
+	/**
89
+	 * @param Request $request
90
+	 */
91
+	protected function setupTitle(Request $request)
92
+	{
93
+		$statusSymbol = self::STATUS_SYMBOL_OPEN;
94
+		if ($request->getStatus() === 'Closed') {
95
+			if ($request->getWasCreated()) {
96
+				$statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
97
+			}
98
+			else {
99
+				$statusSymbol = self::STATUS_SYMBOL_REJECTED;
100
+			}
101
+		}
102
+
103
+		$this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
104
+	}
105
+
106
+	/**
107
+	 * Sets up data unrelated to the request, such as the email template information
108
+	 *
109
+	 * @param PdoDatabase $database
110
+	 */
111
+	protected function setupGeneralData(PdoDatabase $database)
112
+	{
113
+		$config = $this->getSiteConfiguration();
114
+
115
+		$this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
116
+
117
+		$this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
118
+
119
+		$this->assign('requestStates', $config->getRequestStates());
120
+
121
+		/** @var EmailTemplate $createdTemplate */
122
+		$createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
123
+
124
+		$this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
125
+		$this->assign('createdJsQuestion', $createdTemplate->getJsquestion());
126
+		$this->assign('createdId', $createdTemplate->getId());
127
+		$this->assign('createdName', $createdTemplate->getName());
128
+
129
+		$createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
130
+		$this->assign("createReasons", $createReasons);
131
+		$declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
132
+		$this->assign("declineReasons", $declineReasons);
133
+
134
+		$allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
135
+		$this->assign("allCreateReasons", $allCreateReasons);
136
+		$allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
137
+		$this->assign("allDeclineReasons", $allDeclineReasons);
138
+		$allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
139
+		$this->assign("allOtherReasons", $allOtherReasons);
140
+
141
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
142
+			return User::getAllUsernames($database, true);
143
+		});
144
+	}
145
+
146
+	private function setupLogData(Request $request, PdoDatabase $database)
147
+	{
148
+		$currentUser = User::getCurrent($database);
149
+
150
+		$logs = LogHelper::getRequestLogsWithComments($request->getId(), $database);
151
+		$requestLogs = array();
152
+
153
+		if (trim($request->getComment()) !== "") {
154
+			$requestLogs[] = array(
155
+				'type'     => 'comment',
156
+				'security' => 'user',
157
+				'userid'   => null,
158
+				'user'     => $request->getName(),
159
+				'entry'    => null,
160
+				'time'     => $request->getDate(),
161
+				'canedit'  => false,
162
+				'id'       => $request->getId(),
163
+				'comment'  => $request->getComment(),
164
+			);
165
+		}
166
+
167
+		/** @var User[] $nameCache */
168
+		$nameCache = array();
169
+
170
+		$editableComments = $this->allowEditingComments($currentUser);
171
+
172
+		/** @var Log|Comment $entry */
173
+		foreach ($logs as $entry) {
174
+			// both log and comment have a 'user' field
175
+			if (!array_key_exists($entry->getUser(), $nameCache)) {
176
+				$entryUser = User::getById($entry->getUser(), $database);
177
+				$nameCache[$entry->getUser()] = $entryUser;
178
+			}
179
+
180
+			if ($entry instanceof Comment) {
181
+				$requestLogs[] = array(
182
+					'type'     => 'comment',
183
+					'security' => $entry->getVisibility(),
184
+					'user'     => $nameCache[$entry->getUser()]->getUsername(),
185
+					'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
186
+					'entry'    => null,
187
+					'time'     => $entry->getTime(),
188
+					'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
189
+					'id'       => $entry->getId(),
190
+					'comment'  => $entry->getComment(),
191
+				);
192
+			}
193
+
194
+			if ($entry instanceof Log) {
195
+				$invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
196
+				$entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
197
+
198
+				$requestLogs[] = array(
199
+					'type'     => 'log',
200
+					'security' => 'user',
201
+					'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
202
+					'user'     => $entryUser->getUsername(),
203
+					'entry'    => LogHelper::getLogDescription($entry),
204
+					'time'     => $entry->getTimestamp(),
205
+					'canedit'  => false,
206
+					'id'       => $entry->getId(),
207
+					'comment'  => $entry->getComment(),
208
+				);
209
+			}
210
+		}
211
+
212
+		$this->assign("requestLogs", $requestLogs);
213
+	}
214
+
215
+	/**
216
+	 * @param Request $request
217
+	 */
218
+	protected function setupUsernameData(Request $request)
219
+	{
220
+		$blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
221
+
222
+		$this->assign('requestIsBlacklisted', $blacklistData !== false);
223
+		$this->assign('requestBlacklist', $blacklistData);
224
+
225
+		try {
226
+			$spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
227
+		}
228
+		catch (Exception $ex) {
229
+			$spoofs = $ex->getMessage();
230
+		}
231
+
232
+		$this->assign("spoofs", $spoofs);
233
+	}
234
+
235
+	/**
236
+	 * @param User $currentUser
237
+	 *
238
+	 * @return bool
239
+	 */
240
+	private function allowEditingComments(User $currentUser)
241
+	{
242
+		$editableComments = false;
243
+		if ($currentUser->isAdmin() || $currentUser->isCheckuser()) {
244
+			$editableComments = true;
245
+
246
+			return $editableComments;
247
+		}
248
+
249
+		return $editableComments;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@
 block discarded – undo
100 100
             }
101 101
         }
102 102
 
103
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
103
+        $this->setHtmlTitle($statusSymbol.' #'.$request->getId());
104 104
     }
105 105
 
106 106
     /**
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -18,127 +18,127 @@
 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 User::getAllUsernames($database);
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
-     * Sets up the security for this page. If certain actions have different permissions, this should be reflected in
85
-     * the return value from this function.
86
-     *
87
-     * If this page even supports actions, you will need to check the route
88
-     *
89
-     * @return SecurityConfiguration
90
-     * @category Security-Critical
91
-     */
92
-    protected function getSecurityConfiguration()
93
-    {
94
-        return $this->getSecurityManager()->configure()->asInternalPage();
95
-    }
96
-
97
-    /**
98
-     * @param int $page
99
-     * @param int $limit
100
-     * @param int $count
101
-     */
102
-    protected function setupPageData($page, $limit, $count)
103
-    {
104
-        // The number of pages on the pager to show. Must be odd
105
-        $pageLimit = 9;
106
-
107
-        $pageData = array(
108
-            // Can the user go to the previous page?
109
-            'canprev'   => $page != 1,
110
-            // Can the user go to the next page?
111
-            'cannext'   => ($page * $limit) < $count,
112
-            // Maximum page number
113
-            'maxpage'   => ceil($count / $limit),
114
-            // Limit to the number of pages to display
115
-            'pagelimit' => $pageLimit,
116
-        );
117
-
118
-        // number of pages either side of the current to show
119
-        $pageMargin = (($pageLimit - 1) / 2);
120
-
121
-        // Calculate the number of pages either side to show - this is for situations like:
122
-        //  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
123
-        $pageData['lowpage'] = max(1, $page - $pageMargin);
124
-        $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
125
-        $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
126
-
127
-        if ($pageCount < $pageLimit) {
128
-            if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
129
-                $pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
130
-            }
131
-            elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
132
-                $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
133
-            }
134
-        }
135
-
136
-        // Put the range of pages into the page data
137
-        $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
138
-
139
-        $this->assign("pagedata", $pageData);
140
-
141
-        $this->assign("limit", $limit);
142
-        $this->assign("page", $page);
143
-    }
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 User::getAllUsernames($database);
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
+	 * Sets up the security for this page. If certain actions have different permissions, this should be reflected in
85
+	 * the return value from this function.
86
+	 *
87
+	 * If this page even supports actions, you will need to check the route
88
+	 *
89
+	 * @return SecurityConfiguration
90
+	 * @category Security-Critical
91
+	 */
92
+	protected function getSecurityConfiguration()
93
+	{
94
+		return $this->getSecurityManager()->configure()->asInternalPage();
95
+	}
96
+
97
+	/**
98
+	 * @param int $page
99
+	 * @param int $limit
100
+	 * @param int $count
101
+	 */
102
+	protected function setupPageData($page, $limit, $count)
103
+	{
104
+		// The number of pages on the pager to show. Must be odd
105
+		$pageLimit = 9;
106
+
107
+		$pageData = array(
108
+			// Can the user go to the previous page?
109
+			'canprev'   => $page != 1,
110
+			// Can the user go to the next page?
111
+			'cannext'   => ($page * $limit) < $count,
112
+			// Maximum page number
113
+			'maxpage'   => ceil($count / $limit),
114
+			// Limit to the number of pages to display
115
+			'pagelimit' => $pageLimit,
116
+		);
117
+
118
+		// number of pages either side of the current to show
119
+		$pageMargin = (($pageLimit - 1) / 2);
120
+
121
+		// Calculate the number of pages either side to show - this is for situations like:
122
+		//  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
123
+		$pageData['lowpage'] = max(1, $page - $pageMargin);
124
+		$pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
125
+		$pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
126
+
127
+		if ($pageCount < $pageLimit) {
128
+			if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
129
+				$pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
130
+			}
131
+			elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
132
+				$pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
133
+			}
134
+		}
135
+
136
+		// Put the range of pages into the page data
137
+		$pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
138
+
139
+		$this->assign("pagedata", $pageData);
140
+
141
+		$this->assign("limit", $limit);
142
+		$this->assign("page", $page);
143
+	}
144 144
 }
145 145
\ No newline at end of file
Please login to merge, or discard this patch.
includes/IdentificationVerifier.php 2 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -24,131 +24,131 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class IdentificationVerifier
26 26
 {
27
-    /**
28
-     * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia
29
-     * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard.  Note that URL encoding
30
-     * of these values is *not* necessary; this is done automatically.
31
-     *
32
-     * @var string[]
33
-     * @category Security-Critical
34
-     */
35
-    private static $apiQueryParameters = array(
36
-        'action'   => 'query',
37
-        'format'   => 'json',
38
-        'prop'     => 'links',
39
-        'titles'   => 'Access to nonpublic information policy/Noticeboard',
40
-        // Username of the user to be checked, with User: prefix, goes here!  Set in isIdentifiedOnWiki()
41
-        'pltitles' => '',
42
-    );
43
-    /** @var HttpHelper */
44
-    private $httpHelper;
45
-    /** @var SiteConfiguration */
46
-    private $siteConfiguration;
47
-    /** @var PdoDatabase */
48
-    private $dbObject;
49
-
50
-    /**
51
-     * IdentificationVerifier constructor.
52
-     *
53
-     * @param HttpHelper        $httpHelper
54
-     * @param SiteConfiguration $siteConfiguration
55
-     * @param PdoDatabase       $dbObject
56
-     */
57
-    public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
58
-    {
59
-        $this->httpHelper = $httpHelper;
60
-        $this->siteConfiguration = $siteConfiguration;
61
-        $this->dbObject = $dbObject;
62
-    }
63
-
64
-    /**
65
-     * Checks if the given user is identified to the Wikimedia Foundation.
66
-     *
67
-     * @param string $onWikiName The Wikipedia username of the user
68
-     *
69
-     * @return bool
70
-     * @category Security-Critical
71
-     */
72
-    public function isUserIdentified($onWikiName)
73
-    {
74
-        if ($this->checkIdentificationCache($onWikiName)) {
75
-            return true;
76
-        }
77
-        else {
78
-            if ($this->isIdentifiedOnWiki($onWikiName)) {
79
-                $this->cacheIdentificationStatus($onWikiName);
80
-
81
-                return true;
82
-            }
83
-            else {
84
-                return false;
85
-            }
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Checks if the given user has a valid entry in the idcache table.
91
-     *
92
-     * @param string $onWikiName The Wikipedia username of the user
93
-     *
94
-     * @return bool
95
-     * @category Security-Critical
96
-     */
97
-    private function checkIdentificationCache($onWikiName)
98
-    {
99
-        $interval = $this->siteConfiguration->getIdentificationCacheExpiry();
100
-
101
-        $query = <<<SQL
27
+	/**
28
+	 * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia
29
+	 * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard.  Note that URL encoding
30
+	 * of these values is *not* necessary; this is done automatically.
31
+	 *
32
+	 * @var string[]
33
+	 * @category Security-Critical
34
+	 */
35
+	private static $apiQueryParameters = array(
36
+		'action'   => 'query',
37
+		'format'   => 'json',
38
+		'prop'     => 'links',
39
+		'titles'   => 'Access to nonpublic information policy/Noticeboard',
40
+		// Username of the user to be checked, with User: prefix, goes here!  Set in isIdentifiedOnWiki()
41
+		'pltitles' => '',
42
+	);
43
+	/** @var HttpHelper */
44
+	private $httpHelper;
45
+	/** @var SiteConfiguration */
46
+	private $siteConfiguration;
47
+	/** @var PdoDatabase */
48
+	private $dbObject;
49
+
50
+	/**
51
+	 * IdentificationVerifier constructor.
52
+	 *
53
+	 * @param HttpHelper        $httpHelper
54
+	 * @param SiteConfiguration $siteConfiguration
55
+	 * @param PdoDatabase       $dbObject
56
+	 */
57
+	public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
58
+	{
59
+		$this->httpHelper = $httpHelper;
60
+		$this->siteConfiguration = $siteConfiguration;
61
+		$this->dbObject = $dbObject;
62
+	}
63
+
64
+	/**
65
+	 * Checks if the given user is identified to the Wikimedia Foundation.
66
+	 *
67
+	 * @param string $onWikiName The Wikipedia username of the user
68
+	 *
69
+	 * @return bool
70
+	 * @category Security-Critical
71
+	 */
72
+	public function isUserIdentified($onWikiName)
73
+	{
74
+		if ($this->checkIdentificationCache($onWikiName)) {
75
+			return true;
76
+		}
77
+		else {
78
+			if ($this->isIdentifiedOnWiki($onWikiName)) {
79
+				$this->cacheIdentificationStatus($onWikiName);
80
+
81
+				return true;
82
+			}
83
+			else {
84
+				return false;
85
+			}
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Checks if the given user has a valid entry in the idcache table.
91
+	 *
92
+	 * @param string $onWikiName The Wikipedia username of the user
93
+	 *
94
+	 * @return bool
95
+	 * @category Security-Critical
96
+	 */
97
+	private function checkIdentificationCache($onWikiName)
98
+	{
99
+		$interval = $this->siteConfiguration->getIdentificationCacheExpiry();
100
+
101
+		$query = <<<SQL
102 102
 			SELECT COUNT(`id`)
103 103
 			FROM `idcache`
104 104
 			WHERE `onwikiusername` = :onwikiname
105 105
 				AND DATE_ADD(`checktime`, INTERVAL {$interval}) >= NOW();
106 106
 SQL;
107
-        $stmt = $this->dbObject->prepare($query);
108
-        $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
109
-        $stmt->execute();
110
-
111
-        // Guaranteed by the query to only return a single row with a single column
112
-        $results = $stmt->fetch(PDO::FETCH_NUM);
113
-
114
-        // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a
115
-        // unique key - but meh.
116
-        return $results[0] != 0;
117
-    }
118
-
119
-    /**
120
-     * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the
121
-     * idcache table.  Meant to be called periodically by a maintenance script.
122
-     *
123
-     * @param SiteConfiguration $siteConfiguration
124
-     * @param PdoDatabase       $dbObject
125
-     *
126
-     * @return void
127
-     */
128
-    public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
129
-    {
130
-        $interval = $siteConfiguration->getIdentificationCacheExpiry();
131
-
132
-        $query = <<<SQL
107
+		$stmt = $this->dbObject->prepare($query);
108
+		$stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
109
+		$stmt->execute();
110
+
111
+		// Guaranteed by the query to only return a single row with a single column
112
+		$results = $stmt->fetch(PDO::FETCH_NUM);
113
+
114
+		// I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a
115
+		// unique key - but meh.
116
+		return $results[0] != 0;
117
+	}
118
+
119
+	/**
120
+	 * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the
121
+	 * idcache table.  Meant to be called periodically by a maintenance script.
122
+	 *
123
+	 * @param SiteConfiguration $siteConfiguration
124
+	 * @param PdoDatabase       $dbObject
125
+	 *
126
+	 * @return void
127
+	 */
128
+	public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
129
+	{
130
+		$interval = $siteConfiguration->getIdentificationCacheExpiry();
131
+
132
+		$query = <<<SQL
133 133
 			DELETE FROM `idcache`
134 134
 			WHERE DATE_ADD(`checktime`, INTERVAL {$interval}) < NOW();
135 135
 SQL;
136
-        $dbObject->prepare($query)->execute();
137
-    }
138
-
139
-    /**
140
-     * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified.  This
141
-     * is so we don't have to hit the API every single time we check.  The cache entry is valid for as long as specified
142
-     * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()).
143
-     *
144
-     * @param string $onWikiName The Wikipedia username of the user
145
-     *
146
-     * @return void
147
-     * @category Security-Critical
148
-     */
149
-    private function cacheIdentificationStatus($onWikiName)
150
-    {
151
-        $query = <<<SQL
136
+		$dbObject->prepare($query)->execute();
137
+	}
138
+
139
+	/**
140
+	 * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified.  This
141
+	 * is so we don't have to hit the API every single time we check.  The cache entry is valid for as long as specified
142
+	 * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()).
143
+	 *
144
+	 * @param string $onWikiName The Wikipedia username of the user
145
+	 *
146
+	 * @return void
147
+	 * @category Security-Critical
148
+	 */
149
+	private function cacheIdentificationStatus($onWikiName)
150
+	{
151
+		$query = <<<SQL
152 152
 			INSERT INTO `idcache`
153 153
 				(`onwikiusername`)
154 154
 			VALUES
@@ -157,33 +157,33 @@  discard block
 block discarded – undo
157 157
 				`onwikiusername` = VALUES(`onwikiusername`),
158 158
 				`checktime` = CURRENT_TIMESTAMP;
159 159
 SQL;
160
-        $stmt = $this->dbObject->prepare($query);
161
-        $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
162
-        $stmt->execute();
163
-    }
164
-
165
-    /**
166
-     * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard.
167
-     *
168
-     * @param string $onWikiName The Wikipedia username of the user
169
-     *
170
-     * @return bool
171
-     * @category Security-Critical
172
-     */
173
-    private function isIdentifiedOnWiki($onWikiName)
174
-    {
175
-        $strings = new StringFunctions();
176
-
177
-        // First character of Wikipedia usernames is always capitalized.
178
-        $onWikiName = $strings->ucfirst($onWikiName);
179
-
180
-        $parameters = self::$apiQueryParameters;
181
-        $parameters['pltitles'] = "User:" . $onWikiName;
182
-        $response = $this->httpHelper->get($this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(), $parameters);
183
-        $response = json_decode($response, true);
184
-
185
-        $page = @array_pop($response['query']['pages']);
186
-
187
-        return @$page['links'][0]['title'] === "User:" . $onWikiName;
188
-    }
160
+		$stmt = $this->dbObject->prepare($query);
161
+		$stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
162
+		$stmt->execute();
163
+	}
164
+
165
+	/**
166
+	 * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard.
167
+	 *
168
+	 * @param string $onWikiName The Wikipedia username of the user
169
+	 *
170
+	 * @return bool
171
+	 * @category Security-Critical
172
+	 */
173
+	private function isIdentifiedOnWiki($onWikiName)
174
+	{
175
+		$strings = new StringFunctions();
176
+
177
+		// First character of Wikipedia usernames is always capitalized.
178
+		$onWikiName = $strings->ucfirst($onWikiName);
179
+
180
+		$parameters = self::$apiQueryParameters;
181
+		$parameters['pltitles'] = "User:" . $onWikiName;
182
+		$response = $this->httpHelper->get($this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(), $parameters);
183
+		$response = json_decode($response, true);
184
+
185
+		$page = @array_pop($response['query']['pages']);
186
+
187
+		return @$page['links'][0]['title'] === "User:" . $onWikiName;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -178,12 +178,12 @@
 block discarded – undo
178 178
         $onWikiName = $strings->ucfirst($onWikiName);
179 179
 
180 180
         $parameters = self::$apiQueryParameters;
181
-        $parameters['pltitles'] = "User:" . $onWikiName;
181
+        $parameters['pltitles'] = "User:".$onWikiName;
182 182
         $response = $this->httpHelper->get($this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(), $parameters);
183 183
         $response = json_decode($response, true);
184 184
 
185 185
         $page = @array_pop($response['query']['pages']);
186 186
 
187
-        return @$page['links'][0]['title'] === "User:" . $onWikiName;
187
+        return @$page['links'][0]['title'] === "User:".$onWikiName;
188 188
     }
189 189
 }
Please login to merge, or discard this patch.
includes/IrcColourCode.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -10,27 +10,27 @@
 block discarded – undo
10 10
 
11 11
 class IrcColourCode
12 12
 {
13
-    const BOLD = "\x02";
14
-    const ITALIC = "\x09";
15
-    const STRIKE = "\x13";
16
-    const UNDERLINE = "\x15";
17
-    const UNDERLINE2 = "\x1f";
18
-    const REVERSE = "\x16";
19
-    const RESET = "\x0f";
20
-    const WHITE = "\x0300";
21
-    const BLACK = "\x0301";
22
-    const DARK_BLUE = "\x0302";
23
-    const DARK_GREEN = "\x0303";
24
-    const RED = "\x0304";
25
-    const DARK_RED = "\x0305";
26
-    const DARK_VIOLET = "\x0306";
27
-    const ORANGE = "\x0307";
28
-    const YELLOW = "\x0308";
29
-    const LIGHT_GREEN = "\x0309";
30
-    const CYAN = "\x0310";
31
-    const LIGHT_CYAN = "\x0311";
32
-    const BLUE = "\x0312";
33
-    const VIOLET = "\x0313";
34
-    const DARK_GREY = "\x0314";
35
-    const LIGHT_GREY = "\x0315";
13
+	const BOLD = "\x02";
14
+	const ITALIC = "\x09";
15
+	const STRIKE = "\x13";
16
+	const UNDERLINE = "\x15";
17
+	const UNDERLINE2 = "\x1f";
18
+	const REVERSE = "\x16";
19
+	const RESET = "\x0f";
20
+	const WHITE = "\x0300";
21
+	const BLACK = "\x0301";
22
+	const DARK_BLUE = "\x0302";
23
+	const DARK_GREEN = "\x0303";
24
+	const RED = "\x0304";
25
+	const DARK_RED = "\x0305";
26
+	const DARK_VIOLET = "\x0306";
27
+	const ORANGE = "\x0307";
28
+	const YELLOW = "\x0308";
29
+	const LIGHT_GREEN = "\x0309";
30
+	const CYAN = "\x0310";
31
+	const LIGHT_CYAN = "\x0311";
32
+	const BLUE = "\x0312";
33
+	const VIOLET = "\x0313";
34
+	const DARK_GREY = "\x0314";
35
+	const LIGHT_GREY = "\x0315";
36 36
 }
Please login to merge, or discard this patch.
includes/Exceptions/NotIdentifiedException.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -13,24 +13,24 @@
 block discarded – undo
13 13
 
14 14
 class NotIdentifiedException extends ReadableException
15 15
 {
16
-    /**
17
-     * Returns a readable HTML error message that's displayable to the user using templates.
18
-     * @return string
19
-     */
20
-    public function getReadableError()
21
-    {
22
-        if (!headers_sent()) {
23
-            header("HTTP/1.1 403 Forbidden");
24
-        }
16
+	/**
17
+	 * Returns a readable HTML error message that's displayable to the user using templates.
18
+	 * @return string
19
+	 */
20
+	public function getReadableError()
21
+	{
22
+		if (!headers_sent()) {
23
+			header("HTTP/1.1 403 Forbidden");
24
+		}
25 25
 
26
-        $this->setUpSmarty();
26
+		$this->setUpSmarty();
27 27
 
28
-        // uck. We should still be able to access the database in this situation though.
29
-        $database = PdoDatabase::getDatabaseConnection('acc');
30
-        $currentUser = User::getCurrent($database);
31
-        $this->assign('currentUser', $currentUser);
32
-        $this->assign("loggedIn", (!$currentUser->isCommunityUser()));
28
+		// uck. We should still be able to access the database in this situation though.
29
+		$database = PdoDatabase::getDatabaseConnection('acc');
30
+		$currentUser = User::getCurrent($database);
31
+		$this->assign('currentUser', $currentUser);
32
+		$this->assign("loggedIn", (!$currentUser->isCommunityUser()));
33 33
 
34
-        return $this->fetchTemplate("exception/not-identified.tpl");
35
-    }
34
+		return $this->fetchTemplate("exception/not-identified.tpl");
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Exceptions/ReadableException.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -21,22 +21,22 @@
 block discarded – undo
21 21
  */
22 22
 abstract class ReadableException extends Exception
23 23
 {
24
-    use TemplateOutput;
24
+	use TemplateOutput;
25 25
 
26
-    /**
27
-     * Returns a readable HTML error message that's displayable to the user using templates.
28
-     * @return string
29
-     */
30
-    abstract public function getReadableError();
26
+	/**
27
+	 * Returns a readable HTML error message that's displayable to the user using templates.
28
+	 * @return string
29
+	 */
30
+	abstract public function getReadableError();
31 31
 
32
-    /**
33
-     * @return SiteConfiguration
34
-     */
35
-    protected function getSiteConfiguration()
36
-    {
37
-        // Uck. However, we have encountered an exception.
38
-        global $siteConfiguration;
32
+	/**
33
+	 * @return SiteConfiguration
34
+	 */
35
+	protected function getSiteConfiguration()
36
+	{
37
+		// Uck. However, we have encountered an exception.
38
+		global $siteConfiguration;
39 39
 
40
-        return $siteConfiguration;
41
-    }
40
+		return $siteConfiguration;
41
+	}
42 42
 }
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Exceptions/EnvironmentException.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@
 block discarded – undo
21 21
  */
22 22
 class EnvironmentException extends Exception
23 23
 {
24
-    /**
25
-     * EnvironmentException constructor.
26
-     *
27
-     * @param string $friendlyMessage
28
-     */
29
-    public function __construct($friendlyMessage)
30
-    {
31
-        parent::__construct($friendlyMessage);
32
-    }
24
+	/**
25
+	 * EnvironmentException constructor.
26
+	 *
27
+	 * @param string $friendlyMessage
28
+	 */
29
+	public function __construct($friendlyMessage)
30
+	{
31
+		parent::__construct($friendlyMessage);
32
+	}
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Exceptions/AccessDeniedException.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -22,60 +22,60 @@
 block discarded – undo
22 22
  */
23 23
 class AccessDeniedException extends ReadableException
24 24
 {
25
-    public function getReadableError()
26
-    {
27
-        if (!headers_sent()) {
28
-            header("HTTP/1.1 403 Forbidden");
29
-        }
25
+	public function getReadableError()
26
+	{
27
+		if (!headers_sent()) {
28
+			header("HTTP/1.1 403 Forbidden");
29
+		}
30 30
 
31
-        $this->setUpSmarty();
31
+		$this->setUpSmarty();
32 32
 
33
-        // uck. We should still be able to access the database in this situation though.
34
-        $database = PdoDatabase::getDatabaseConnection('acc');
35
-        $currentUser = User::getCurrent($database);
36
-        $this->assign('currentUser', $currentUser);
37
-        $this->assign("loggedIn", (!$currentUser->isCommunityUser()));
33
+		// uck. We should still be able to access the database in this situation though.
34
+		$database = PdoDatabase::getDatabaseConnection('acc');
35
+		$currentUser = User::getCurrent($database);
36
+		$this->assign('currentUser', $currentUser);
37
+		$this->assign("loggedIn", (!$currentUser->isCommunityUser()));
38 38
 
39
-        if ($currentUser->isDeclined()) {
40
-            $this->assign('htmlTitle', 'Account Declined');
41
-            $this->assign('declineReason', $this->getLogEntry('Declined', $currentUser, $database));
39
+		if ($currentUser->isDeclined()) {
40
+			$this->assign('htmlTitle', 'Account Declined');
41
+			$this->assign('declineReason', $this->getLogEntry('Declined', $currentUser, $database));
42 42
 
43
-            return $this->fetchTemplate("exception/account-declined.tpl");
44
-        }
43
+			return $this->fetchTemplate("exception/account-declined.tpl");
44
+		}
45 45
 
46
-        if ($currentUser->isSuspended()) {
47
-            $this->assign('htmlTitle', 'Account Suspended');
48
-            $this->assign('suspendReason', $this->getLogEntry('Suspended', $currentUser, $database));
46
+		if ($currentUser->isSuspended()) {
47
+			$this->assign('htmlTitle', 'Account Suspended');
48
+			$this->assign('suspendReason', $this->getLogEntry('Suspended', $currentUser, $database));
49 49
 
50
-            return $this->fetchTemplate("exception/account-suspended.tpl");
51
-        }
50
+			return $this->fetchTemplate("exception/account-suspended.tpl");
51
+		}
52 52
 
53
-        if ($currentUser->isNewUser()) {
54
-            $this->assign('htmlTitle', 'Account Pending');
53
+		if ($currentUser->isNewUser()) {
54
+			$this->assign('htmlTitle', 'Account Pending');
55 55
 
56
-            return $this->fetchTemplate("exception/account-new.tpl");
57
-        }
56
+			return $this->fetchTemplate("exception/account-new.tpl");
57
+		}
58 58
 
59
-        return $this->fetchTemplate("exception/access-denied.tpl");
60
-    }
59
+		return $this->fetchTemplate("exception/access-denied.tpl");
60
+	}
61 61
 
62
-    /**
63
-     * @param string      $action
64
-     * @param User        $user
65
-     * @param PdoDatabase $database
66
-     *
67
-     * @return null|string
68
-     */
69
-    private function getLogEntry($action, User $user, PdoDatabase $database)
70
-    {
71
-        /** @var Log[] $logs */
72
-        $logs = LogSearchHelper::get($database)
73
-            ->byAction($action)
74
-            ->byObjectType('User')
75
-            ->byObjectId($user->getId())
76
-            ->limit(1)
77
-            ->fetch();
62
+	/**
63
+	 * @param string      $action
64
+	 * @param User        $user
65
+	 * @param PdoDatabase $database
66
+	 *
67
+	 * @return null|string
68
+	 */
69
+	private function getLogEntry($action, User $user, PdoDatabase $database)
70
+	{
71
+		/** @var Log[] $logs */
72
+		$logs = LogSearchHelper::get($database)
73
+			->byAction($action)
74
+			->byObjectType('User')
75
+			->byObjectId($user->getId())
76
+			->limit(1)
77
+			->fetch();
78 78
 
79
-        return $logs[0]->getComment();
80
-    }
79
+		return $logs[0]->getComment();
80
+	}
81 81
 }
82 82
\ No newline at end of file
Please login to merge, or discard this patch.