Completed
Pull Request — newinternal (#418)
by Matthew
04:57
created
includes/RegexConstants.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class RegexConstants
12 12
 {
13
-    const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?';
14
-    const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?';
15
-    const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
16
-    const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
13
+	const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?';
14
+	const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?';
15
+	const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
16
+	const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/IrcNotificationHelper.php 2 patches
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -26,445 +26,445 @@
 block discarded – undo
26 26
  */
27 27
 class IrcNotificationHelper
28 28
 {
29
-    /** @var PdoDatabase $notificationsDatabase */
30
-    private $notificationsDatabase;
31
-    /** @var PdoDatabase $primaryDatabase */
32
-    private $primaryDatabase;
33
-    /** @var bool $notificationsEnabled */
34
-    private $notificationsEnabled;
35
-    /** @var int $notificationType */
36
-    private $notificationType;
37
-    /** @var User $currentUser */
38
-    private $currentUser;
39
-    /** @var string $instanceName */
40
-    private $instanceName;
41
-    /** @var string */
42
-    private $baseUrl;
43
-    /** @var array */
44
-    private $requestStates;
45
-
46
-    /**
47
-     * IrcNotificationHelper constructor.
48
-     *
49
-     * @param SiteConfiguration $siteConfiguration
50
-     * @param PdoDatabase       $primaryDatabase
51
-     * @param PdoDatabase       $notificationsDatabase
52
-     */
53
-    public function __construct(
54
-        SiteConfiguration $siteConfiguration,
55
-        PdoDatabase $primaryDatabase,
56
-        PdoDatabase $notificationsDatabase = null
57
-    ) {
58
-        $this->primaryDatabase = $primaryDatabase;
59
-
60
-        if ($this->notificationsDatabase !== null) {
61
-            $this->notificationsDatabase = $notificationsDatabase;
62
-            $this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
-        }
64
-        else {
65
-            $this->notificationsEnabled = false;
66
-        }
67
-
68
-        $this->notificationType = $siteConfiguration->getIrcNotificationType();
69
-        $this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
-        $this->baseUrl = $siteConfiguration->getBaseUrl();
71
-        $this->requestStates = $siteConfiguration->getRequestStates();
72
-
73
-        $this->currentUser = User::getCurrent($primaryDatabase);
74
-    }
75
-
76
-    /**
77
-     * Send a notification
78
-     *
79
-     * @param string $message The text to send
80
-     */
81
-    protected function send($message)
82
-    {
83
-        $instanceName = $this->instanceName;
84
-
85
-        if (!$this->notificationsEnabled) {
86
-            return;
87
-        }
88
-
89
-        $blacklist = array("DCC", "CCTP", "PRIVMSG");
90
-        $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
-
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
-
94
-        try {
95
-            $notification = new Notification();
96
-            $notification->setDatabase($this->notificationsDatabase);
97
-            $notification->setType($this->notificationType);
98
-            $notification->setText($msg);
99
-
100
-            $notification->save();
101
-        }
102
-        catch (Exception $ex) {
103
-            // OK, so we failed to send the notification - that db might be down?
104
-            // This is non-critical, so silently fail.
105
-
106
-            // Disable notifications for remainder of request.
107
-            $this->notificationsEnabled = false;
108
-        }
109
-    }
110
-
111
-    #region user management
112
-
113
-    /**
114
-     * send a new user notification
115
-     *
116
-     * @param User $user
117
-     */
118
-    public function userNew(User $user)
119
-    {
120
-        $this->send("New user: {$user->getUsername()}");
121
-    }
122
-
123
-    /**
124
-     * send an approved notification
125
-     *
126
-     * @param User $user
127
-     */
128
-    public function userApproved(User $user)
129
-    {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
-    }
132
-
133
-    /**
134
-     * send a promoted notification
135
-     *
136
-     * @param User $user
137
-     */
138
-    public function userPromoted(User $user)
139
-    {
140
-        $this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
141
-    }
142
-
143
-    /**
144
-     * send a declined notification
145
-     *
146
-     * @param User   $user
147
-     * @param string $reason the reason the user was declined
148
-     */
149
-    public function userDeclined(User $user, $reason)
150
-    {
151
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
152
-    }
153
-
154
-    /**
155
-     * send a demotion notification
156
-     *
157
-     * @param User   $user
158
-     * @param string $reason the reason the user was demoted
159
-     */
160
-    public function userDemoted(User $user, $reason)
161
-    {
162
-        $this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
163
-    }
164
-
165
-    /**
166
-     * send a suspended notification
167
-     *
168
-     * @param User   $user
169
-     * @param string $reason The reason the user has been suspended
170
-     */
171
-    public function userSuspended(User $user, $reason)
172
-    {
173
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
174
-    }
175
-
176
-    /**
177
-     * Send a preference change notification
178
-     *
179
-     * @param User $user
180
-     */
181
-    public function userPrefChange(User $user)
182
-    {
183
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
184
-    }
185
-
186
-    /**
187
-     * Send a user renamed notification
188
-     *
189
-     * @param User   $user
190
-     * @param string $old
191
-     */
192
-    public function userRenamed(User $user, $old)
193
-    {
194
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
195
-    }
196
-
197
-    #endregion
198
-
199
-    #region Site Notice
200
-
201
-    /**
202
-     * Summary of siteNoticeEdited
203
-     */
204
-    public function siteNoticeEdited()
205
-    {
206
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
207
-    }
208
-    #endregion
209
-
210
-    #region Welcome Templates
211
-    /**
212
-     * Summary of welcomeTemplateCreated
213
-     *
214
-     * @param WelcomeTemplate $template
215
-     */
216
-    public function welcomeTemplateCreated(WelcomeTemplate $template)
217
-    {
218
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
219
-    }
220
-
221
-    /**
222
-     * Summary of welcomeTemplateDeleted
223
-     *
224
-     * @param int $templateid
225
-     */
226
-    public function welcomeTemplateDeleted($templateid)
227
-    {
228
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
229
-    }
230
-
231
-    /**
232
-     * Summary of welcomeTemplateEdited
233
-     *
234
-     * @param WelcomeTemplate $template
235
-     */
236
-    public function welcomeTemplateEdited(WelcomeTemplate $template)
237
-    {
238
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
239
-    }
240
-
241
-    #endregion
242
-
243
-    #region bans
244
-    /**
245
-     * Summary of banned
246
-     *
247
-     * @param Ban $ban
248
-     */
249
-    public function banned(Ban $ban)
250
-    {
251
-        if ($ban->getDuration() == -1) {
252
-            $duration = "indefinitely";
253
-        }
254
-        else {
255
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
256
-        }
257
-
258
-        $username = $this->currentUser->getUsername();
259
-
260
-        $this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
261
-    }
262
-
263
-    /**
264
-     * Summary of unbanned
265
-     *
266
-     * @param Ban    $ban
267
-     * @param string $unbanreason
268
-     */
269
-    public function unbanned(Ban $ban, $unbanreason)
270
-    {
271
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
272
-                ->getUsername() . " (" . $unbanreason . ")");
273
-    }
274
-
275
-    #endregion
276
-
277
-    #region request management
278
-
279
-    /**
280
-     * Summary of requestReceived
281
-     *
282
-     * @param Request $request
283
-     */
284
-    public function requestReceived(Request $request)
285
-    {
286
-        $this->send(
287
-            IrcColourCode::DARK_GREY . "[["
288
-            . IrcColourCode::DARK_GREEN . "acc:"
289
-            . IrcColourCode::ORANGE . $request->getId()
290
-            . IrcColourCode::DARK_GREY . "]]"
291
-            . IrcColourCode::RED . " N "
292
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
293
-            . IrcColourCode::DARK_RED . "* "
294
-            . IrcColourCode::DARK_GREEN . $request->getName()
295
-            . IrcColourCode::DARK_RED . " * "
296
-            . IrcColourCode::RESET
297
-        );
298
-    }
299
-
300
-    /**
301
-     * Summary of requestDeferred
302
-     *
303
-     * @param Request $request
304
-     */
305
-    public function requestDeferred(Request $request)
306
-    {
307
-        $availableRequestStates = $this->requestStates;
308
-
309
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
310
-        $username = $this->currentUser->getUsername();
311
-
312
-        $this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
313
-    }
314
-
315
-    /**
316
-     *
317
-     * Summary of requestDeferredWithMail
318
-     *
319
-     * @param Request $request
320
-     */
321
-    public function requestDeferredWithMail(Request $request)
322
-    {
323
-        $availableRequestStates = $this->requestStates;
324
-
325
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
326
-        $username = $this->currentUser->getUsername();
327
-        $id = $request->getId();
328
-        $name = $request->getName();
329
-
330
-        $this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
331
-    }
332
-
333
-    /**
334
-     * Summary of requestClosed
335
-     *
336
-     * @param Request $request
337
-     * @param string  $closetype
338
-     */
339
-    public function requestClosed(Request $request, $closetype)
340
-    {
341
-        $username = $this->currentUser->getUsername();
342
-
343
-        $this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
344
-    }
345
-
346
-    /**
347
-     * Summary of sentMail
348
-     *
349
-     * @param Request $request
350
-     */
351
-    public function sentMail(Request $request)
352
-    {
353
-        $this->send($this->currentUser->getUsername()
354
-            . " sent an email related to Request {$request->getId()} ({$request->getName()})");
355
-    }
356
-
357
-    #endregion
358
-
359
-    #region reservations
360
-
361
-    /**
362
-     * Summary of requestReserved
363
-     *
364
-     * @param Request $request
365
-     */
366
-    public function requestReserved(Request $request)
367
-    {
368
-        $username = $this->currentUser->getUsername();
369
-
370
-        $this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
371
-    }
372
-
373
-    /**
374
-     * Summary of requestReserveBroken
375
-     *
376
-     * @param Request $request
377
-     */
378
-    public function requestReserveBroken(Request $request)
379
-    {
380
-        $username = $this->currentUser->getUsername();
381
-
382
-        $this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
383
-    }
384
-
385
-    /**
386
-     * Summary of requestUnreserved
387
-     *
388
-     * @param Request $request
389
-     */
390
-    public function requestUnreserved(Request $request)
391
-    {
392
-        $this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
393
-    }
394
-
395
-    /**
396
-     * Summary of requestReservationSent
397
-     *
398
-     * @param Request $request
399
-     * @param User    $target
400
-     */
401
-    public function requestReservationSent(Request $request, User $target)
402
-    {
403
-        $username = $this->currentUser->getUsername();
404
-
405
-        $this->send(
406
-            "Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
407
-            . $username);
408
-    }
409
-
410
-    #endregion
411
-
412
-    #region comments
413
-
414
-    /**
415
-     * Summary of commentCreated
416
-     *
417
-     * @param Comment $comment
418
-     * @param Request $request
419
-     */
420
-    public function commentCreated(Comment $comment, Request $request)
421
-    {
422
-        $username = $this->currentUser->getUsername();
423
-        $visibility = ($comment->getVisibility() == "admin" ? "private " : "");
424
-
425
-        $this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
426
-    }
427
-
428
-    /**
429
-     * Summary of commentEdited
430
-     *
431
-     * @param Comment $comment
432
-     * @param Request $request
433
-     */
434
-    public function commentEdited(Comment $comment, Request $request)
435
-    {
436
-        $username = $this->currentUser->getUsername();
437
-
438
-        $this->send(<<<TAG
29
+	/** @var PdoDatabase $notificationsDatabase */
30
+	private $notificationsDatabase;
31
+	/** @var PdoDatabase $primaryDatabase */
32
+	private $primaryDatabase;
33
+	/** @var bool $notificationsEnabled */
34
+	private $notificationsEnabled;
35
+	/** @var int $notificationType */
36
+	private $notificationType;
37
+	/** @var User $currentUser */
38
+	private $currentUser;
39
+	/** @var string $instanceName */
40
+	private $instanceName;
41
+	/** @var string */
42
+	private $baseUrl;
43
+	/** @var array */
44
+	private $requestStates;
45
+
46
+	/**
47
+	 * IrcNotificationHelper constructor.
48
+	 *
49
+	 * @param SiteConfiguration $siteConfiguration
50
+	 * @param PdoDatabase       $primaryDatabase
51
+	 * @param PdoDatabase       $notificationsDatabase
52
+	 */
53
+	public function __construct(
54
+		SiteConfiguration $siteConfiguration,
55
+		PdoDatabase $primaryDatabase,
56
+		PdoDatabase $notificationsDatabase = null
57
+	) {
58
+		$this->primaryDatabase = $primaryDatabase;
59
+
60
+		if ($this->notificationsDatabase !== null) {
61
+			$this->notificationsDatabase = $notificationsDatabase;
62
+			$this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
+		}
64
+		else {
65
+			$this->notificationsEnabled = false;
66
+		}
67
+
68
+		$this->notificationType = $siteConfiguration->getIrcNotificationType();
69
+		$this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
+		$this->baseUrl = $siteConfiguration->getBaseUrl();
71
+		$this->requestStates = $siteConfiguration->getRequestStates();
72
+
73
+		$this->currentUser = User::getCurrent($primaryDatabase);
74
+	}
75
+
76
+	/**
77
+	 * Send a notification
78
+	 *
79
+	 * @param string $message The text to send
80
+	 */
81
+	protected function send($message)
82
+	{
83
+		$instanceName = $this->instanceName;
84
+
85
+		if (!$this->notificationsEnabled) {
86
+			return;
87
+		}
88
+
89
+		$blacklist = array("DCC", "CCTP", "PRIVMSG");
90
+		$message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
+
92
+		$msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
+
94
+		try {
95
+			$notification = new Notification();
96
+			$notification->setDatabase($this->notificationsDatabase);
97
+			$notification->setType($this->notificationType);
98
+			$notification->setText($msg);
99
+
100
+			$notification->save();
101
+		}
102
+		catch (Exception $ex) {
103
+			// OK, so we failed to send the notification - that db might be down?
104
+			// This is non-critical, so silently fail.
105
+
106
+			// Disable notifications for remainder of request.
107
+			$this->notificationsEnabled = false;
108
+		}
109
+	}
110
+
111
+	#region user management
112
+
113
+	/**
114
+	 * send a new user notification
115
+	 *
116
+	 * @param User $user
117
+	 */
118
+	public function userNew(User $user)
119
+	{
120
+		$this->send("New user: {$user->getUsername()}");
121
+	}
122
+
123
+	/**
124
+	 * send an approved notification
125
+	 *
126
+	 * @param User $user
127
+	 */
128
+	public function userApproved(User $user)
129
+	{
130
+		$this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
+	}
132
+
133
+	/**
134
+	 * send a promoted notification
135
+	 *
136
+	 * @param User $user
137
+	 */
138
+	public function userPromoted(User $user)
139
+	{
140
+		$this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
141
+	}
142
+
143
+	/**
144
+	 * send a declined notification
145
+	 *
146
+	 * @param User   $user
147
+	 * @param string $reason the reason the user was declined
148
+	 */
149
+	public function userDeclined(User $user, $reason)
150
+	{
151
+		$this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
152
+	}
153
+
154
+	/**
155
+	 * send a demotion notification
156
+	 *
157
+	 * @param User   $user
158
+	 * @param string $reason the reason the user was demoted
159
+	 */
160
+	public function userDemoted(User $user, $reason)
161
+	{
162
+		$this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
163
+	}
164
+
165
+	/**
166
+	 * send a suspended notification
167
+	 *
168
+	 * @param User   $user
169
+	 * @param string $reason The reason the user has been suspended
170
+	 */
171
+	public function userSuspended(User $user, $reason)
172
+	{
173
+		$this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
174
+	}
175
+
176
+	/**
177
+	 * Send a preference change notification
178
+	 *
179
+	 * @param User $user
180
+	 */
181
+	public function userPrefChange(User $user)
182
+	{
183
+		$this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
184
+	}
185
+
186
+	/**
187
+	 * Send a user renamed notification
188
+	 *
189
+	 * @param User   $user
190
+	 * @param string $old
191
+	 */
192
+	public function userRenamed(User $user, $old)
193
+	{
194
+		$this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
195
+	}
196
+
197
+	#endregion
198
+
199
+	#region Site Notice
200
+
201
+	/**
202
+	 * Summary of siteNoticeEdited
203
+	 */
204
+	public function siteNoticeEdited()
205
+	{
206
+		$this->send("Site notice edited by " . $this->currentUser->getUsername());
207
+	}
208
+	#endregion
209
+
210
+	#region Welcome Templates
211
+	/**
212
+	 * Summary of welcomeTemplateCreated
213
+	 *
214
+	 * @param WelcomeTemplate $template
215
+	 */
216
+	public function welcomeTemplateCreated(WelcomeTemplate $template)
217
+	{
218
+		$this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
219
+	}
220
+
221
+	/**
222
+	 * Summary of welcomeTemplateDeleted
223
+	 *
224
+	 * @param int $templateid
225
+	 */
226
+	public function welcomeTemplateDeleted($templateid)
227
+	{
228
+		$this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
229
+	}
230
+
231
+	/**
232
+	 * Summary of welcomeTemplateEdited
233
+	 *
234
+	 * @param WelcomeTemplate $template
235
+	 */
236
+	public function welcomeTemplateEdited(WelcomeTemplate $template)
237
+	{
238
+		$this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
239
+	}
240
+
241
+	#endregion
242
+
243
+	#region bans
244
+	/**
245
+	 * Summary of banned
246
+	 *
247
+	 * @param Ban $ban
248
+	 */
249
+	public function banned(Ban $ban)
250
+	{
251
+		if ($ban->getDuration() == -1) {
252
+			$duration = "indefinitely";
253
+		}
254
+		else {
255
+			$duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
256
+		}
257
+
258
+		$username = $this->currentUser->getUsername();
259
+
260
+		$this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
261
+	}
262
+
263
+	/**
264
+	 * Summary of unbanned
265
+	 *
266
+	 * @param Ban    $ban
267
+	 * @param string $unbanreason
268
+	 */
269
+	public function unbanned(Ban $ban, $unbanreason)
270
+	{
271
+		$this->send($ban->getTarget() . " unbanned by " . $this->currentUser
272
+				->getUsername() . " (" . $unbanreason . ")");
273
+	}
274
+
275
+	#endregion
276
+
277
+	#region request management
278
+
279
+	/**
280
+	 * Summary of requestReceived
281
+	 *
282
+	 * @param Request $request
283
+	 */
284
+	public function requestReceived(Request $request)
285
+	{
286
+		$this->send(
287
+			IrcColourCode::DARK_GREY . "[["
288
+			. IrcColourCode::DARK_GREEN . "acc:"
289
+			. IrcColourCode::ORANGE . $request->getId()
290
+			. IrcColourCode::DARK_GREY . "]]"
291
+			. IrcColourCode::RED . " N "
292
+			. IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
293
+			. IrcColourCode::DARK_RED . "* "
294
+			. IrcColourCode::DARK_GREEN . $request->getName()
295
+			. IrcColourCode::DARK_RED . " * "
296
+			. IrcColourCode::RESET
297
+		);
298
+	}
299
+
300
+	/**
301
+	 * Summary of requestDeferred
302
+	 *
303
+	 * @param Request $request
304
+	 */
305
+	public function requestDeferred(Request $request)
306
+	{
307
+		$availableRequestStates = $this->requestStates;
308
+
309
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
310
+		$username = $this->currentUser->getUsername();
311
+
312
+		$this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
313
+	}
314
+
315
+	/**
316
+	 *
317
+	 * Summary of requestDeferredWithMail
318
+	 *
319
+	 * @param Request $request
320
+	 */
321
+	public function requestDeferredWithMail(Request $request)
322
+	{
323
+		$availableRequestStates = $this->requestStates;
324
+
325
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
326
+		$username = $this->currentUser->getUsername();
327
+		$id = $request->getId();
328
+		$name = $request->getName();
329
+
330
+		$this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
331
+	}
332
+
333
+	/**
334
+	 * Summary of requestClosed
335
+	 *
336
+	 * @param Request $request
337
+	 * @param string  $closetype
338
+	 */
339
+	public function requestClosed(Request $request, $closetype)
340
+	{
341
+		$username = $this->currentUser->getUsername();
342
+
343
+		$this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
344
+	}
345
+
346
+	/**
347
+	 * Summary of sentMail
348
+	 *
349
+	 * @param Request $request
350
+	 */
351
+	public function sentMail(Request $request)
352
+	{
353
+		$this->send($this->currentUser->getUsername()
354
+			. " sent an email related to Request {$request->getId()} ({$request->getName()})");
355
+	}
356
+
357
+	#endregion
358
+
359
+	#region reservations
360
+
361
+	/**
362
+	 * Summary of requestReserved
363
+	 *
364
+	 * @param Request $request
365
+	 */
366
+	public function requestReserved(Request $request)
367
+	{
368
+		$username = $this->currentUser->getUsername();
369
+
370
+		$this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
371
+	}
372
+
373
+	/**
374
+	 * Summary of requestReserveBroken
375
+	 *
376
+	 * @param Request $request
377
+	 */
378
+	public function requestReserveBroken(Request $request)
379
+	{
380
+		$username = $this->currentUser->getUsername();
381
+
382
+		$this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
383
+	}
384
+
385
+	/**
386
+	 * Summary of requestUnreserved
387
+	 *
388
+	 * @param Request $request
389
+	 */
390
+	public function requestUnreserved(Request $request)
391
+	{
392
+		$this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
393
+	}
394
+
395
+	/**
396
+	 * Summary of requestReservationSent
397
+	 *
398
+	 * @param Request $request
399
+	 * @param User    $target
400
+	 */
401
+	public function requestReservationSent(Request $request, User $target)
402
+	{
403
+		$username = $this->currentUser->getUsername();
404
+
405
+		$this->send(
406
+			"Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
407
+			. $username);
408
+	}
409
+
410
+	#endregion
411
+
412
+	#region comments
413
+
414
+	/**
415
+	 * Summary of commentCreated
416
+	 *
417
+	 * @param Comment $comment
418
+	 * @param Request $request
419
+	 */
420
+	public function commentCreated(Comment $comment, Request $request)
421
+	{
422
+		$username = $this->currentUser->getUsername();
423
+		$visibility = ($comment->getVisibility() == "admin" ? "private " : "");
424
+
425
+		$this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
426
+	}
427
+
428
+	/**
429
+	 * Summary of commentEdited
430
+	 *
431
+	 * @param Comment $comment
432
+	 * @param Request $request
433
+	 */
434
+	public function commentEdited(Comment $comment, Request $request)
435
+	{
436
+		$username = $this->currentUser->getUsername();
437
+
438
+		$this->send(<<<TAG
439 439
 Comment {$comment->getId()} on request {$request->getId()} ({$request->getName()}) edited by {$username}
440 440
 TAG
441
-        );
442
-    }
443
-
444
-    #endregion
445
-
446
-    #region email management (close reasons)
447
-
448
-    /**
449
-     * Summary of emailCreated
450
-     *
451
-     * @param EmailTemplate $template
452
-     */
453
-    public function emailCreated(EmailTemplate $template)
454
-    {
455
-        $username = $this->currentUser->getUsername();
456
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
457
-    }
458
-
459
-    /**
460
-     * Summary of emailEdited
461
-     *
462
-     * @param EmailTemplate $template
463
-     */
464
-    public function emailEdited(EmailTemplate $template)
465
-    {
466
-        $username = $this->currentUser->getUsername();
467
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
468
-    }
469
-    #endregion
441
+		);
442
+	}
443
+
444
+	#endregion
445
+
446
+	#region email management (close reasons)
447
+
448
+	/**
449
+	 * Summary of emailCreated
450
+	 *
451
+	 * @param EmailTemplate $template
452
+	 */
453
+	public function emailCreated(EmailTemplate $template)
454
+	{
455
+		$username = $this->currentUser->getUsername();
456
+		$this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
457
+	}
458
+
459
+	/**
460
+	 * Summary of emailEdited
461
+	 *
462
+	 * @param EmailTemplate $template
463
+	 */
464
+	public function emailEdited(EmailTemplate $template)
465
+	{
466
+		$username = $this->currentUser->getUsername();
467
+		$this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
468
+	}
469
+	#endregion
470 470
 }
471 471
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $blacklist = array("DCC", "CCTP", "PRIVMSG");
90 90
         $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91 91
 
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
92
+        $msg = IrcColourCode::RESET.IrcColourCode::BOLD."[$instanceName]".IrcColourCode::RESET.": $message";
93 93
 
94 94
         try {
95 95
             $notification = new Notification();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function userApproved(User $user)
129 129
     {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
130
+        $this->send("{$user->getUsername()} approved by ".$this->currentUser->getUsername());
131 131
     }
132 132
 
133 133
     /**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function userPromoted(User $user)
139 139
     {
140
-        $this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
140
+        $this->send("{$user->getUsername()} promoted to tool admin by ".$this->currentUser->getUsername());
141 141
     }
142 142
 
143 143
     /**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function userDeclined(User $user, $reason)
150 150
     {
151
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
151
+        $this->send("{$user->getUsername()} declined by ".$this->currentUser->getUsername()." ($reason)");
152 152
     }
153 153
 
154 154
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function userDemoted(User $user, $reason)
161 161
     {
162
-        $this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
162
+        $this->send("{$user->getUsername()} demoted by ".$this->currentUser->getUsername()." ($reason)");
163 163
     }
164 164
 
165 165
     /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function userSuspended(User $user, $reason)
172 172
     {
173
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
173
+        $this->send("{$user->getUsername()} suspended by ".$this->currentUser->getUsername()." ($reason)");
174 174
     }
175 175
 
176 176
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function userPrefChange(User $user)
182 182
     {
183
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
183
+        $this->send("{$user->getUsername()}'s preferences were changed by ".$this->currentUser->getUsername());
184 184
     }
185 185
 
186 186
     /**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function userRenamed(User $user, $old)
193 193
     {
194
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
194
+        $this->send($this->currentUser->getUsername()." renamed $old to {$user->getUsername()}");
195 195
     }
196 196
 
197 197
     #endregion
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public function siteNoticeEdited()
205 205
     {
206
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
206
+        $this->send("Site notice edited by ".$this->currentUser->getUsername());
207 207
     }
208 208
     #endregion
209 209
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      */
216 216
     public function welcomeTemplateCreated(WelcomeTemplate $template)
217 217
     {
218
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
218
+        $this->send("Welcome template {$template->getId()} created by ".$this->currentUser->getUsername());
219 219
     }
220 220
 
221 221
     /**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      */
226 226
     public function welcomeTemplateDeleted($templateid)
227 227
     {
228
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
228
+        $this->send("Welcome template {$templateid} deleted by ".$this->currentUser->getUsername());
229 229
     }
230 230
 
231 231
     /**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function welcomeTemplateEdited(WelcomeTemplate $template)
237 237
     {
238
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
238
+        $this->send("Welcome template {$template->getId()} edited by ".$this->currentUser->getUsername());
239 239
     }
240 240
 
241 241
     #endregion
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             $duration = "indefinitely";
253 253
         }
254 254
         else {
255
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
255
+            $duration = "until ".date("F j, Y, g:i a", $ban->getDuration());
256 256
         }
257 257
 
258 258
         $username = $this->currentUser->getUsername();
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
      */
269 269
     public function unbanned(Ban $ban, $unbanreason)
270 270
     {
271
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
272
-                ->getUsername() . " (" . $unbanreason . ")");
271
+        $this->send($ban->getTarget()." unbanned by ".$this->currentUser
272
+                ->getUsername()." (".$unbanreason.")");
273 273
     }
274 274
 
275 275
     #endregion
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
     public function requestReceived(Request $request)
285 285
     {
286 286
         $this->send(
287
-            IrcColourCode::DARK_GREY . "[["
288
-            . IrcColourCode::DARK_GREEN . "acc:"
289
-            . IrcColourCode::ORANGE . $request->getId()
290
-            . IrcColourCode::DARK_GREY . "]]"
291
-            . IrcColourCode::RED . " N "
292
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
293
-            . IrcColourCode::DARK_RED . "* "
294
-            . IrcColourCode::DARK_GREEN . $request->getName()
295
-            . IrcColourCode::DARK_RED . " * "
287
+            IrcColourCode::DARK_GREY."[["
288
+            . IrcColourCode::DARK_GREEN."acc:"
289
+            . IrcColourCode::ORANGE.$request->getId()
290
+            . IrcColourCode::DARK_GREY."]]"
291
+            . IrcColourCode::RED." N "
292
+            . IrcColourCode::DARK_BLUE.$this->baseUrl."/internal.php/viewRequest?id={$request->getId()} "
293
+            . IrcColourCode::DARK_RED."* "
294
+            . IrcColourCode::DARK_GREEN.$request->getName()
295
+            . IrcColourCode::DARK_RED." * "
296 296
             . IrcColourCode::RESET
297 297
         );
298 298
     }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function emailCreated(EmailTemplate $template)
454 454
     {
455 455
         $username = $this->currentUser->getUsername();
456
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
456
+        $this->send("Email {$template->getId()} ({$template->getName()}) created by ".$username);
457 457
     }
458 458
 
459 459
     /**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
     public function emailEdited(EmailTemplate $template)
465 465
     {
466 466
         $username = $this->currentUser->getUsername();
467
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
467
+        $this->send("Email {$template->getId()} ({$template->getName()}) edited by ".$username);
468 468
     }
469 469
     #endregion
470 470
 }
471 471
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/HttpHelper.php 2 patches
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -12,103 +12,103 @@
 block discarded – undo
12 12
 
13 13
 class HttpHelper
14 14
 {
15
-    private $curlHandle;
16
-
17
-    /**
18
-     * HttpHelper constructor.
19
-     *
20
-     * @param string  $userAgent
21
-     * @param boolean $disableVerifyPeer
22
-     */
23
-    public function __construct($userAgent, $disableVerifyPeer)
24
-    {
25
-        $this->curlHandle = curl_init();
26
-
27
-        curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
28
-        curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent);
29
-        curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true);
30
-
31
-        if ($disableVerifyPeer) {
32
-            curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
33
-        }
34
-    }
35
-
36
-    public function __destruct()
37
-    {
38
-        curl_close($this->curlHandle);
39
-    }
40
-
41
-    /**
42
-     * Fetches the content of a URL, with an optional parameter set.
43
-     *
44
-     * @param string     $url        The URL to fetch.
45
-     * @param null|array $parameters Key/value pair of GET parameters to add to the request.
46
-     *                               Null lets you handle it yourself.
47
-     *
48
-     * @param array      $headers
49
-     *
50
-     * @return string
51
-     * @throws CurlException
52
-     */
53
-    public function get($url, $parameters = null, $headers = array())
54
-    {
55
-        if ($parameters !== null && is_array($parameters)) {
56
-            $getString = '?' . http_build_query($parameters);
57
-            $url .= $getString;
58
-        }
59
-
60
-        curl_setopt($this->curlHandle, CURLOPT_URL, $url);
61
-
62
-        // Make sure we're doing a GET
63
-        curl_setopt($this->curlHandle, CURLOPT_POST, false);
64
-
65
-        curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
66
-
67
-        $result = curl_exec($this->curlHandle);
68
-
69
-        if ($result === false) {
70
-            $error = curl_error($this->curlHandle);
71
-            throw new CurlException('Remote request failed with error ' . $error);
72
-        }
73
-
74
-        return $result;
75
-    }
76
-
77
-    /**
78
-     * Posts data to a URL
79
-     *
80
-     * @param string $url        The URL to fetch.
81
-     * @param array  $parameters Key/value pair of POST parameters to add to the request.
82
-     * @param array  $headers
83
-     *
84
-     * @return string
85
-     * @throws CurlException
86
-     */
87
-    public function post($url, $parameters, $headers = array())
88
-    {
89
-        curl_setopt($this->curlHandle, CURLOPT_URL, $url);
90
-
91
-        // Make sure we're doing a POST
92
-        curl_setopt($this->curlHandle, CURLOPT_POST, true);
93
-        curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters));
94
-
95
-        curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
96
-
97
-        $result = curl_exec($this->curlHandle);
98
-
99
-        if ($result === false) {
100
-            $error = curl_error($this->curlHandle);
101
-            throw new CurlException('Remote request failed with error ' . $error);
102
-        }
103
-
104
-        return $result;
105
-    }
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function getError()
111
-    {
112
-        return curl_error($this->curlHandle);
113
-    }
15
+	private $curlHandle;
16
+
17
+	/**
18
+	 * HttpHelper constructor.
19
+	 *
20
+	 * @param string  $userAgent
21
+	 * @param boolean $disableVerifyPeer
22
+	 */
23
+	public function __construct($userAgent, $disableVerifyPeer)
24
+	{
25
+		$this->curlHandle = curl_init();
26
+
27
+		curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
28
+		curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent);
29
+		curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true);
30
+
31
+		if ($disableVerifyPeer) {
32
+			curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
33
+		}
34
+	}
35
+
36
+	public function __destruct()
37
+	{
38
+		curl_close($this->curlHandle);
39
+	}
40
+
41
+	/**
42
+	 * Fetches the content of a URL, with an optional parameter set.
43
+	 *
44
+	 * @param string     $url        The URL to fetch.
45
+	 * @param null|array $parameters Key/value pair of GET parameters to add to the request.
46
+	 *                               Null lets you handle it yourself.
47
+	 *
48
+	 * @param array      $headers
49
+	 *
50
+	 * @return string
51
+	 * @throws CurlException
52
+	 */
53
+	public function get($url, $parameters = null, $headers = array())
54
+	{
55
+		if ($parameters !== null && is_array($parameters)) {
56
+			$getString = '?' . http_build_query($parameters);
57
+			$url .= $getString;
58
+		}
59
+
60
+		curl_setopt($this->curlHandle, CURLOPT_URL, $url);
61
+
62
+		// Make sure we're doing a GET
63
+		curl_setopt($this->curlHandle, CURLOPT_POST, false);
64
+
65
+		curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
66
+
67
+		$result = curl_exec($this->curlHandle);
68
+
69
+		if ($result === false) {
70
+			$error = curl_error($this->curlHandle);
71
+			throw new CurlException('Remote request failed with error ' . $error);
72
+		}
73
+
74
+		return $result;
75
+	}
76
+
77
+	/**
78
+	 * Posts data to a URL
79
+	 *
80
+	 * @param string $url        The URL to fetch.
81
+	 * @param array  $parameters Key/value pair of POST parameters to add to the request.
82
+	 * @param array  $headers
83
+	 *
84
+	 * @return string
85
+	 * @throws CurlException
86
+	 */
87
+	public function post($url, $parameters, $headers = array())
88
+	{
89
+		curl_setopt($this->curlHandle, CURLOPT_URL, $url);
90
+
91
+		// Make sure we're doing a POST
92
+		curl_setopt($this->curlHandle, CURLOPT_POST, true);
93
+		curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters));
94
+
95
+		curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
96
+
97
+		$result = curl_exec($this->curlHandle);
98
+
99
+		if ($result === false) {
100
+			$error = curl_error($this->curlHandle);
101
+			throw new CurlException('Remote request failed with error ' . $error);
102
+		}
103
+
104
+		return $result;
105
+	}
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function getError()
111
+	{
112
+		return curl_error($this->curlHandle);
113
+	}
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public function get($url, $parameters = null, $headers = array())
54 54
     {
55 55
         if ($parameters !== null && is_array($parameters)) {
56
-            $getString = '?' . http_build_query($parameters);
56
+            $getString = '?'.http_build_query($parameters);
57 57
             $url .= $getString;
58 58
         }
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
         if ($result === false) {
70 70
             $error = curl_error($this->curlHandle);
71
-            throw new CurlException('Remote request failed with error ' . $error);
71
+            throw new CurlException('Remote request failed with error '.$error);
72 72
         }
73 73
 
74 74
         return $result;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
         if ($result === false) {
100 100
             $error = curl_error($this->curlHandle);
101
-            throw new CurlException('Remote request failed with error ' . $error);
101
+            throw new CurlException('Remote request failed with error '.$error);
102 102
         }
103 103
 
104 104
         return $result;
Please login to merge, or discard this patch.
includes/Helpers/SearchHelpers/LogSearchHelper.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -13,102 +13,102 @@
 block discarded – undo
13 13
 
14 14
 class LogSearchHelper extends SearchHelperBase
15 15
 {
16
-    /**
17
-     * LogSearchHelper constructor.
18
-     *
19
-     * @param PdoDatabase $database
20
-     */
21
-    protected function __construct(PdoDatabase $database)
22
-    {
23
-        parent::__construct($database, 'log', 'timestamp DESC');
24
-    }
25
-
26
-    /**
27
-     * Initiates a search for requests
28
-     *
29
-     * @param PdoDatabase $database
30
-     *
31
-     * @return LogSearchHelper
32
-     */
33
-    public static function get(PdoDatabase $database)
34
-    {
35
-        $helper = new LogSearchHelper($database);
36
-
37
-        return $helper;
38
-    }
39
-
40
-    /**
41
-     * Returns the requested requests
42
-     *
43
-     * @return Log[]
44
-     */
45
-    public function fetch()
46
-    {
47
-        $targetClass = Log::class;
48
-
49
-        /** @var Log[] $returnedObjects */
50
-        $returnedObjects = $this->fetchObjects($targetClass);
51
-
52
-        return $returnedObjects;
53
-    }
54
-
55
-    /**
56
-     * Filters the results by user
57
-     *
58
-     * @param int $userId
59
-     *
60
-     * @return $this
61
-     */
62
-    public function byUser($userId)
63
-    {
64
-        $this->whereClause .= ' AND user = ?';
65
-        $this->parameterList[] = $userId;
66
-
67
-        return $this;
68
-    }
69
-
70
-    /**
71
-     * Filters the results by log action
72
-     *
73
-     * @param string $action
74
-     *
75
-     * @return $this
76
-     */
77
-    public function byAction($action)
78
-    {
79
-        $this->whereClause .= ' AND action = ?';
80
-        $this->parameterList[] = $action;
81
-
82
-        return $this;
83
-    }
84
-
85
-    /**
86
-     * Filters the results by object type
87
-     *
88
-     * @param string $objectType
89
-     *
90
-     * @return $this
91
-     */
92
-    public function byObjectType($objectType)
93
-    {
94
-        $this->whereClause .= ' AND objecttype = ?';
95
-        $this->parameterList[] = $objectType;
96
-
97
-        return $this;
98
-    }
99
-
100
-    /**
101
-     * Filters the results by object type
102
-     *
103
-     * @param integer $objectId
104
-     *
105
-     * @return $this
106
-     */
107
-    public function byObjectId($objectId)
108
-    {
109
-        $this->whereClause .= ' AND objectid = ?';
110
-        $this->parameterList[] = $objectId;
111
-
112
-        return $this;
113
-    }
16
+	/**
17
+	 * LogSearchHelper constructor.
18
+	 *
19
+	 * @param PdoDatabase $database
20
+	 */
21
+	protected function __construct(PdoDatabase $database)
22
+	{
23
+		parent::__construct($database, 'log', 'timestamp DESC');
24
+	}
25
+
26
+	/**
27
+	 * Initiates a search for requests
28
+	 *
29
+	 * @param PdoDatabase $database
30
+	 *
31
+	 * @return LogSearchHelper
32
+	 */
33
+	public static function get(PdoDatabase $database)
34
+	{
35
+		$helper = new LogSearchHelper($database);
36
+
37
+		return $helper;
38
+	}
39
+
40
+	/**
41
+	 * Returns the requested requests
42
+	 *
43
+	 * @return Log[]
44
+	 */
45
+	public function fetch()
46
+	{
47
+		$targetClass = Log::class;
48
+
49
+		/** @var Log[] $returnedObjects */
50
+		$returnedObjects = $this->fetchObjects($targetClass);
51
+
52
+		return $returnedObjects;
53
+	}
54
+
55
+	/**
56
+	 * Filters the results by user
57
+	 *
58
+	 * @param int $userId
59
+	 *
60
+	 * @return $this
61
+	 */
62
+	public function byUser($userId)
63
+	{
64
+		$this->whereClause .= ' AND user = ?';
65
+		$this->parameterList[] = $userId;
66
+
67
+		return $this;
68
+	}
69
+
70
+	/**
71
+	 * Filters the results by log action
72
+	 *
73
+	 * @param string $action
74
+	 *
75
+	 * @return $this
76
+	 */
77
+	public function byAction($action)
78
+	{
79
+		$this->whereClause .= ' AND action = ?';
80
+		$this->parameterList[] = $action;
81
+
82
+		return $this;
83
+	}
84
+
85
+	/**
86
+	 * Filters the results by object type
87
+	 *
88
+	 * @param string $objectType
89
+	 *
90
+	 * @return $this
91
+	 */
92
+	public function byObjectType($objectType)
93
+	{
94
+		$this->whereClause .= ' AND objecttype = ?';
95
+		$this->parameterList[] = $objectType;
96
+
97
+		return $this;
98
+	}
99
+
100
+	/**
101
+	 * Filters the results by object type
102
+	 *
103
+	 * @param integer $objectId
104
+	 *
105
+	 * @return $this
106
+	 */
107
+	public function byObjectId($objectId)
108
+	{
109
+		$this->whereClause .= ' AND objectid = ?';
110
+		$this->parameterList[] = $objectId;
111
+
112
+		return $this;
113
+	}
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/SearchHelpers/SearchHelperBase.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -14,119 +14,119 @@
 block discarded – undo
14 14
 
15 15
 abstract class SearchHelperBase
16 16
 {
17
-    /** @var PdoDatabase */
18
-    protected $database;
19
-    /** @var array */
20
-    protected $parameterList = array();
21
-    /** @var null|int */
22
-    private $limit = null;
23
-    /** @var null|int */
24
-    private $offset = null;
25
-    private $orderBy = null;
26
-    /**
27
-     * @var string The where clause.
28
-     *
29
-     * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note
30
-     * that we use positional parameters instead of named parameters because we don't know many times different options
31
-     * will be called (looking at excluding() here, but there's the option for others).
32
-     */
33
-    protected $whereClause = 'WHERE 1 = 1';
34
-    /** @var string */
35
-    private $table;
36
-
37
-    /**
38
-     * SearchHelperBase constructor.
39
-     *
40
-     * @param PdoDatabase $database
41
-     * @param string      $table
42
-     * @param null|string $order Order by clause, excluding ORDER BY.
43
-     */
44
-    protected function __construct(PdoDatabase $database, $table, $order = null)
45
-    {
46
-        $this->database = $database;
47
-        $this->table = $table;
48
-        $this->orderBy = $order;
49
-    }
50
-
51
-    /**
52
-     * @param $targetClass
53
-     *
54
-     * @return DataObject[]
55
-     */
56
-    protected function fetchObjects($targetClass)
57
-    {
58
-        $query = 'SELECT * FROM ' . $this->table . ' ' . $this->whereClause;
59
-        $query .= $this->applyOrder();
60
-        $query .= $this->applyLimit();
61
-
62
-        $statement = $this->database->prepare($query);
63
-        $statement->execute($this->parameterList);
64
-
65
-        /** @var DataObject[] $returnedObjects */
66
-        $returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $targetClass);
67
-        foreach ($returnedObjects as $req) {
68
-            $req->setDatabase($this->database);
69
-        }
70
-
71
-        return $returnedObjects;
72
-    }
73
-
74
-    /**
75
-     * @param int $count Returns the record count of the result set
76
-     *
77
-     * @return $this
78
-     */
79
-    public function getRecordCount(&$count)
80
-    {
81
-        $query = 'SELECT COUNT(1) FROM ' . $this->table . ' ' . $this->whereClause;
82
-        $statement = $this->database->prepare($query);
83
-        $statement->execute($this->parameterList);
84
-
85
-        $count = $statement->fetchColumn(0);
86
-        $statement->closeCursor();
87
-
88
-        return $this;
89
-    }
90
-
91
-    /**
92
-     * Limits the results
93
-     *
94
-     * @param integer      $limit
95
-     * @param integer|null $offset
96
-     *
97
-     * @return $this
98
-     *
99
-     */
100
-    public function limit($limit, $offset = null)
101
-    {
102
-        $this->limit = $limit;
103
-        $this->offset = $offset;
104
-
105
-        return $this;
106
-    }
107
-
108
-    private function applyLimit()
109
-    {
110
-        $clause = '';
111
-        if ($this->limit !== null) {
112
-            $clause = ' LIMIT ?';
113
-            $this->parameterList[] = $this->limit;
114
-
115
-            if ($this->offset !== null) {
116
-                $clause .= ' OFFSET ?';
117
-                $this->parameterList[] = $this->offset;
118
-            }
119
-        }
120
-
121
-        return $clause;
122
-    }
123
-
124
-    private function applyOrder()
125
-    {
126
-        if ($this->orderBy !== null) {
127
-            return ' ORDER BY ' . $this->orderBy;
128
-        }
129
-
130
-        return '';
131
-    }
17
+	/** @var PdoDatabase */
18
+	protected $database;
19
+	/** @var array */
20
+	protected $parameterList = array();
21
+	/** @var null|int */
22
+	private $limit = null;
23
+	/** @var null|int */
24
+	private $offset = null;
25
+	private $orderBy = null;
26
+	/**
27
+	 * @var string The where clause.
28
+	 *
29
+	 * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note
30
+	 * that we use positional parameters instead of named parameters because we don't know many times different options
31
+	 * will be called (looking at excluding() here, but there's the option for others).
32
+	 */
33
+	protected $whereClause = 'WHERE 1 = 1';
34
+	/** @var string */
35
+	private $table;
36
+
37
+	/**
38
+	 * SearchHelperBase constructor.
39
+	 *
40
+	 * @param PdoDatabase $database
41
+	 * @param string      $table
42
+	 * @param null|string $order Order by clause, excluding ORDER BY.
43
+	 */
44
+	protected function __construct(PdoDatabase $database, $table, $order = null)
45
+	{
46
+		$this->database = $database;
47
+		$this->table = $table;
48
+		$this->orderBy = $order;
49
+	}
50
+
51
+	/**
52
+	 * @param $targetClass
53
+	 *
54
+	 * @return DataObject[]
55
+	 */
56
+	protected function fetchObjects($targetClass)
57
+	{
58
+		$query = 'SELECT * FROM ' . $this->table . ' ' . $this->whereClause;
59
+		$query .= $this->applyOrder();
60
+		$query .= $this->applyLimit();
61
+
62
+		$statement = $this->database->prepare($query);
63
+		$statement->execute($this->parameterList);
64
+
65
+		/** @var DataObject[] $returnedObjects */
66
+		$returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $targetClass);
67
+		foreach ($returnedObjects as $req) {
68
+			$req->setDatabase($this->database);
69
+		}
70
+
71
+		return $returnedObjects;
72
+	}
73
+
74
+	/**
75
+	 * @param int $count Returns the record count of the result set
76
+	 *
77
+	 * @return $this
78
+	 */
79
+	public function getRecordCount(&$count)
80
+	{
81
+		$query = 'SELECT COUNT(1) FROM ' . $this->table . ' ' . $this->whereClause;
82
+		$statement = $this->database->prepare($query);
83
+		$statement->execute($this->parameterList);
84
+
85
+		$count = $statement->fetchColumn(0);
86
+		$statement->closeCursor();
87
+
88
+		return $this;
89
+	}
90
+
91
+	/**
92
+	 * Limits the results
93
+	 *
94
+	 * @param integer      $limit
95
+	 * @param integer|null $offset
96
+	 *
97
+	 * @return $this
98
+	 *
99
+	 */
100
+	public function limit($limit, $offset = null)
101
+	{
102
+		$this->limit = $limit;
103
+		$this->offset = $offset;
104
+
105
+		return $this;
106
+	}
107
+
108
+	private function applyLimit()
109
+	{
110
+		$clause = '';
111
+		if ($this->limit !== null) {
112
+			$clause = ' LIMIT ?';
113
+			$this->parameterList[] = $this->limit;
114
+
115
+			if ($this->offset !== null) {
116
+				$clause .= ' OFFSET ?';
117
+				$this->parameterList[] = $this->offset;
118
+			}
119
+		}
120
+
121
+		return $clause;
122
+	}
123
+
124
+	private function applyOrder()
125
+	{
126
+		if ($this->orderBy !== null) {
127
+			return ' ORDER BY ' . $this->orderBy;
128
+		}
129
+
130
+		return '';
131
+	}
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     protected function fetchObjects($targetClass)
57 57
     {
58
-        $query = 'SELECT * FROM ' . $this->table . ' ' . $this->whereClause;
58
+        $query = 'SELECT * FROM '.$this->table.' '.$this->whereClause;
59 59
         $query .= $this->applyOrder();
60 60
         $query .= $this->applyLimit();
61 61
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function getRecordCount(&$count)
80 80
     {
81
-        $query = 'SELECT COUNT(1) FROM ' . $this->table . ' ' . $this->whereClause;
81
+        $query = 'SELECT COUNT(1) FROM '.$this->table.' '.$this->whereClause;
82 82
         $statement = $this->database->prepare($query);
83 83
         $statement->execute($this->parameterList);
84 84
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     private function applyOrder()
125 125
     {
126 126
         if ($this->orderBy !== null) {
127
-            return ' ORDER BY ' . $this->orderBy;
127
+            return ' ORDER BY '.$this->orderBy;
128 128
         }
129 129
 
130 130
         return '';
Please login to merge, or discard this patch.
includes/Helpers/SearchHelpers/RequestSearchHelper.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -14,131 +14,131 @@
 block discarded – undo
14 14
 
15 15
 class RequestSearchHelper extends SearchHelperBase
16 16
 {
17
-    /**
18
-     * RequestSearchHelper constructor.
19
-     *
20
-     * @param PdoDatabase $database
21
-     */
22
-    protected function __construct(PdoDatabase $database)
23
-    {
24
-        parent::__construct($database, 'request');
25
-    }
26
-
27
-    /**
28
-     * Initiates a search for requests
29
-     *
30
-     * @param PdoDatabase $database
31
-     *
32
-     * @return RequestSearchHelper
33
-     */
34
-    public static function get(PdoDatabase $database)
35
-    {
36
-        $helper = new RequestSearchHelper($database);
37
-
38
-        return $helper;
39
-    }
40
-
41
-    /**
42
-     * Returns the requested requests
43
-     *
44
-     * @return Request[]
45
-     */
46
-    public function fetch()
47
-    {
48
-        $targetClass = Request::class;
49
-        /** @var Request[] $returnedObjects */
50
-        $returnedObjects = $this->fetchObjects($targetClass);
51
-
52
-        return $returnedObjects;
53
-    }
54
-
55
-    /**
56
-     * Filters the results by IP address
57
-     *
58
-     * @param string $ipAddress
59
-     *
60
-     * @return $this
61
-     */
62
-    public function byIp($ipAddress)
63
-    {
64
-        $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
65
-        $this->parameterList[] = $ipAddress;
66
-        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
67
-
68
-        return $this;
69
-    }
70
-
71
-    /**
72
-     * Filters the results by email address
73
-     *
74
-     * @param string $emailAddress
75
-     *
76
-     * @return $this
77
-     */
78
-    public function byEmailAddress($emailAddress)
79
-    {
80
-        $this->whereClause .= ' AND email LIKE ?';
81
-        $this->parameterList[] = $emailAddress;
82
-
83
-        return $this;
84
-    }
85
-
86
-    /**
87
-     * Filters the results by name
88
-     *
89
-     * @param string $name
90
-     *
91
-     * @return $this
92
-     */
93
-    public function byName($name)
94
-    {
95
-        $this->whereClause .= ' AND name LIKE ?';
96
-        $this->parameterList[] = $name;
97
-
98
-        return $this;
99
-    }
100
-
101
-    /**
102
-     * Excludes a request from the results
103
-     *
104
-     * @param int $requestId
105
-     *
106
-     * @return $this
107
-     */
108
-    public function excludingRequest($requestId)
109
-    {
110
-        $this->whereClause .= ' AND id <> ?';
111
-        $this->parameterList[] = $requestId;
112
-
113
-        return $this;
114
-    }
115
-
116
-    /**
117
-     * Filters the results to only those with a confirmed email address
118
-     *
119
-     * @return $this
120
-     */
121
-    public function withConfirmedEmail()
122
-    {
123
-        $this->whereClause .= ' AND emailconfirm = ?';
124
-        $this->parameterList[] = 'Confirmed';
125
-
126
-        return $this;
127
-    }
128
-
129
-    /**
130
-     * Filters the results to exclude purged data
131
-     *
132
-     * @param SiteConfiguration $configuration
133
-     *
134
-     * @return $this
135
-     */
136
-    public function excludingPurgedData(SiteConfiguration $configuration)
137
-    {
138
-        $this->whereClause .= ' AND ip <> ? AND email <> ?';
139
-        $this->parameterList[] = $configuration->getDataClearIp();
140
-        $this->parameterList[] = $configuration->getDataClearEmail();
141
-
142
-        return $this;
143
-    }
17
+	/**
18
+	 * RequestSearchHelper constructor.
19
+	 *
20
+	 * @param PdoDatabase $database
21
+	 */
22
+	protected function __construct(PdoDatabase $database)
23
+	{
24
+		parent::__construct($database, 'request');
25
+	}
26
+
27
+	/**
28
+	 * Initiates a search for requests
29
+	 *
30
+	 * @param PdoDatabase $database
31
+	 *
32
+	 * @return RequestSearchHelper
33
+	 */
34
+	public static function get(PdoDatabase $database)
35
+	{
36
+		$helper = new RequestSearchHelper($database);
37
+
38
+		return $helper;
39
+	}
40
+
41
+	/**
42
+	 * Returns the requested requests
43
+	 *
44
+	 * @return Request[]
45
+	 */
46
+	public function fetch()
47
+	{
48
+		$targetClass = Request::class;
49
+		/** @var Request[] $returnedObjects */
50
+		$returnedObjects = $this->fetchObjects($targetClass);
51
+
52
+		return $returnedObjects;
53
+	}
54
+
55
+	/**
56
+	 * Filters the results by IP address
57
+	 *
58
+	 * @param string $ipAddress
59
+	 *
60
+	 * @return $this
61
+	 */
62
+	public function byIp($ipAddress)
63
+	{
64
+		$this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
65
+		$this->parameterList[] = $ipAddress;
66
+		$this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
67
+
68
+		return $this;
69
+	}
70
+
71
+	/**
72
+	 * Filters the results by email address
73
+	 *
74
+	 * @param string $emailAddress
75
+	 *
76
+	 * @return $this
77
+	 */
78
+	public function byEmailAddress($emailAddress)
79
+	{
80
+		$this->whereClause .= ' AND email LIKE ?';
81
+		$this->parameterList[] = $emailAddress;
82
+
83
+		return $this;
84
+	}
85
+
86
+	/**
87
+	 * Filters the results by name
88
+	 *
89
+	 * @param string $name
90
+	 *
91
+	 * @return $this
92
+	 */
93
+	public function byName($name)
94
+	{
95
+		$this->whereClause .= ' AND name LIKE ?';
96
+		$this->parameterList[] = $name;
97
+
98
+		return $this;
99
+	}
100
+
101
+	/**
102
+	 * Excludes a request from the results
103
+	 *
104
+	 * @param int $requestId
105
+	 *
106
+	 * @return $this
107
+	 */
108
+	public function excludingRequest($requestId)
109
+	{
110
+		$this->whereClause .= ' AND id <> ?';
111
+		$this->parameterList[] = $requestId;
112
+
113
+		return $this;
114
+	}
115
+
116
+	/**
117
+	 * Filters the results to only those with a confirmed email address
118
+	 *
119
+	 * @return $this
120
+	 */
121
+	public function withConfirmedEmail()
122
+	{
123
+		$this->whereClause .= ' AND emailconfirm = ?';
124
+		$this->parameterList[] = 'Confirmed';
125
+
126
+		return $this;
127
+	}
128
+
129
+	/**
130
+	 * Filters the results to exclude purged data
131
+	 *
132
+	 * @param SiteConfiguration $configuration
133
+	 *
134
+	 * @return $this
135
+	 */
136
+	public function excludingPurgedData(SiteConfiguration $configuration)
137
+	{
138
+		$this->whereClause .= ' AND ip <> ? AND email <> ?';
139
+		$this->parameterList[] = $configuration->getDataClearIp();
140
+		$this->parameterList[] = $configuration->getDataClearEmail();
141
+
142
+		return $this;
143
+	}
144 144
 }
145 145
\ 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
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
     {
64 64
         $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
65 65
         $this->parameterList[] = $ipAddress;
66
-        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
66
+        $this->parameterList[] = '%'.trim($ipAddress, '%').'%';
67 67
 
68 68
         return $this;
69 69
     }
Please login to merge, or discard this patch.
includes/Helpers/WikiTextHelper.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -12,52 +12,52 @@
 block discarded – undo
12 12
 
13 13
 class WikiTextHelper
14 14
 {
15
-    /**
16
-     * @var SiteConfiguration
17
-     */
18
-    private $configuration;
19
-    /**
20
-     * @var HttpHelper
21
-     */
22
-    private $http;
23
-
24
-    /**
25
-     * WikiTextHelper constructor.
26
-     *
27
-     * @param SiteConfiguration $configuration
28
-     * @param HttpHelper        $http
29
-     */
30
-    public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
-    {
32
-        $this->configuration = $configuration;
33
-        $this->http = $http;
34
-    }
35
-
36
-    /**
37
-     * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
-     *
39
-     * @param string $wikiText
40
-     *
41
-     * @return string
42
-     */
43
-    public function getHtmlForWikiText($wikiText)
44
-    {
45
-        $endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
-
47
-        $parameters = array(
48
-            'action'             => 'parse',
49
-            'pst'                => true,
50
-            'contentmodel'       => 'wikitext',
51
-            'disablelimitreport' => true,
52
-            'disabletoc'         => true,
53
-            'disableeditsection' => true,
54
-            'format'             => 'php',
55
-            'text'               => $wikiText,
56
-        );
57
-
58
-        $apiResult = $this->http->get($endpoint, $parameters);
59
-        $parseResult = unserialize($apiResult);
60
-
61
-        return $parseResult['parse']['text']['*'];
62
-    }
15
+	/**
16
+	 * @var SiteConfiguration
17
+	 */
18
+	private $configuration;
19
+	/**
20
+	 * @var HttpHelper
21
+	 */
22
+	private $http;
23
+
24
+	/**
25
+	 * WikiTextHelper constructor.
26
+	 *
27
+	 * @param SiteConfiguration $configuration
28
+	 * @param HttpHelper        $http
29
+	 */
30
+	public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
+	{
32
+		$this->configuration = $configuration;
33
+		$this->http = $http;
34
+	}
35
+
36
+	/**
37
+	 * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
+	 *
39
+	 * @param string $wikiText
40
+	 *
41
+	 * @return string
42
+	 */
43
+	public function getHtmlForWikiText($wikiText)
44
+	{
45
+		$endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
+
47
+		$parameters = array(
48
+			'action'             => 'parse',
49
+			'pst'                => true,
50
+			'contentmodel'       => 'wikitext',
51
+			'disablelimitreport' => true,
52
+			'disabletoc'         => true,
53
+			'disableeditsection' => true,
54
+			'format'             => 'php',
55
+			'text'               => $wikiText,
56
+		);
57
+
58
+		$apiResult = $this->http->get($endpoint, $parameters);
59
+		$parseResult = unserialize($apiResult);
60
+
61
+		return $parseResult['parse']['text']['*'];
62
+	}
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Logger.php 1 patch
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -30,300 +30,300 @@
 block discarded – undo
30 30
  */
31 31
 class Logger
32 32
 {
33
-    /**
34
-     * @param PdoDatabase $database
35
-     * @param Request     $object
36
-     */
37
-    public static function emailConfirmed(PdoDatabase $database, Request $object)
38
-    {
39
-        self::createLogEntry($database, $object, "Email Confirmed", null, User::getCommunity());
40
-    }
41
-
42
-    /**
43
-     * @param PdoDatabase $database
44
-     * @param DataObject  $object
45
-     * @param string      $logAction
46
-     * @param null|string $comment
47
-     * @param User        $user
48
-     *
49
-     * @throws Exception
50
-     */
51
-    private static function createLogEntry(
52
-        PdoDatabase $database,
53
-        DataObject $object,
54
-        $logAction,
55
-        $comment = null,
56
-        $user = null
57
-    ) {
58
-        if ($user == null) {
59
-            $user = User::getCurrent($database);
60
-        }
61
-
62
-        $objectType = get_class($object);
63
-        if (strpos($objectType, 'Waca\\DataObjects\\') !== false) {
64
-            $objectType = str_replace('Waca\\DataObjects\\', '', $objectType);
65
-        }
66
-
67
-        $log = new Log();
68
-        $log->setDatabase($database);
69
-        $log->setAction($logAction);
70
-        $log->setObjectId($object->getId());
71
-        $log->setObjectType($objectType);
72
-        $log->setUser($user);
73
-        $log->setComment($comment);
74
-        $log->save();
75
-    }
76
-
77
-    #region Users
78
-
79
-    /**
80
-     * @param PdoDatabase $database
81
-     * @param User        $user
82
-     */
83
-    public static function newUser(PdoDatabase $database, User $user)
84
-    {
85
-        self::createLogEntry($database, $user, 'Registered', null, User::getCommunity());
86
-    }
87
-
88
-    /**
89
-     * @param PdoDatabase $database
90
-     * @param User        $object
91
-     */
92
-    public static function approvedUser(PdoDatabase $database, User $object)
93
-    {
94
-        self::createLogEntry($database, $object, "Approved");
95
-    }
96
-
97
-    /**
98
-     * @param PdoDatabase $database
99
-     * @param User        $object
100
-     * @param string      $comment
101
-     */
102
-    public static function declinedUser(PdoDatabase $database, User $object, $comment)
103
-    {
104
-        self::createLogEntry($database, $object, "Declined", $comment);
105
-    }
106
-
107
-    /**
108
-     * @param PdoDatabase $database
109
-     * @param User        $object
110
-     * @param string      $comment
111
-     */
112
-    public static function suspendedUser(PdoDatabase $database, User $object, $comment)
113
-    {
114
-        self::createLogEntry($database, $object, "Suspended", $comment);
115
-    }
116
-
117
-    /**
118
-     * @param PdoDatabase $database
119
-     * @param User        $object
120
-     * @param string      $comment
121
-     */
122
-    public static function demotedUser(PdoDatabase $database, User $object, $comment)
123
-    {
124
-        self::createLogEntry($database, $object, "Demoted", $comment);
125
-    }
126
-
127
-    /**
128
-     * @param PdoDatabase $database
129
-     * @param User        $object
130
-     */
131
-    public static function promotedUser(PdoDatabase $database, User $object)
132
-    {
133
-        self::createLogEntry($database, $object, "Promoted");
134
-    }
135
-
136
-    /**
137
-     * @param PdoDatabase $database
138
-     * @param User        $object
139
-     * @param string      $comment
140
-     */
141
-    public static function renamedUser(PdoDatabase $database, User $object, $comment)
142
-    {
143
-        self::createLogEntry($database, $object, "Renamed", $comment);
144
-    }
145
-
146
-    /**
147
-     * @param PdoDatabase $database
148
-     * @param User        $object
149
-     */
150
-    public static function userPreferencesChange(PdoDatabase $database, User $object)
151
-    {
152
-        self::createLogEntry($database, $object, "Prefchange");
153
-    }
154
-
155
-    #endregion
156
-
157
-    /**
158
-     * @param PdoDatabase $database
159
-     * @param SiteNotice  $object
160
-     */
161
-    public static function siteNoticeEdited(PdoDatabase $database, SiteNotice $object)
162
-    {
163
-        self::createLogEntry($database, $object, "Edited");
164
-    }
165
-
166
-    #region Welcome Templates
167
-
168
-    /**
169
-     * @param PdoDatabase     $database
170
-     * @param WelcomeTemplate $object
171
-     */
172
-    public static function welcomeTemplateCreated(PdoDatabase $database, WelcomeTemplate $object)
173
-    {
174
-        self::createLogEntry($database, $object, "CreatedTemplate");
175
-    }
176
-
177
-    /**
178
-     * @param PdoDatabase     $database
179
-     * @param WelcomeTemplate $object
180
-     */
181
-    public static function welcomeTemplateEdited(PdoDatabase $database, WelcomeTemplate $object)
182
-    {
183
-        self::createLogEntry($database, $object, "EditedTemplate");
184
-    }
185
-
186
-    /**
187
-     * @param PdoDatabase     $database
188
-     * @param WelcomeTemplate $object
189
-     */
190
-    public static function welcomeTemplateDeleted(PdoDatabase $database, WelcomeTemplate $object)
191
-    {
192
-        self::createLogEntry($database, $object, "DeletedTemplate");
193
-    }
194
-
195
-    #endregion
196
-
197
-    #region Bans
198
-
199
-    /**
200
-     * @param PdoDatabase $database
201
-     * @param Ban         $object
202
-     * @param string      $reason
203
-     */
204
-    public static function banned(PdoDatabase $database, Ban $object, $reason)
205
-    {
206
-        self::createLogEntry($database, $object, "Banned", $reason);
207
-    }
208
-
209
-    /**
210
-     * @param PdoDatabase $database
211
-     * @param Ban         $object
212
-     * @param string      $reason
213
-     */
214
-    public static function unbanned(PdoDatabase $database, Ban $object, $reason)
215
-    {
216
-        self::createLogEntry($database, $object, "Unbanned", $reason);
217
-    }
218
-
219
-    #endregion
220
-
221
-    #region Requests
222
-
223
-    /**
224
-     * @param PdoDatabase $database
225
-     * @param Request     $object
226
-     * @param string      $target
227
-     */
228
-    public static function deferRequest(PdoDatabase $database, Request $object, $target)
229
-    {
230
-        self::createLogEntry($database, $object, "Deferred to $target");
231
-    }
232
-
233
-    /**
234
-     * @param PdoDatabase $database
235
-     * @param Request     $object
236
-     * @param integer     $target
237
-     * @param string      $comment
238
-     */
239
-    public static function closeRequest(PdoDatabase $database, Request $object, $target, $comment)
240
-    {
241
-        self::createLogEntry($database, $object, "Closed $target", $comment);
242
-    }
243
-
244
-    /**
245
-     * @param PdoDatabase $database
246
-     * @param Request     $object
247
-     */
248
-    public static function reserve(PdoDatabase $database, Request $object)
249
-    {
250
-        self::createLogEntry($database, $object, "Reserved");
251
-    }
252
-
253
-    /**
254
-     * @param PdoDatabase $database
255
-     * @param Request     $object
256
-     */
257
-    public static function breakReserve(PdoDatabase $database, Request $object)
258
-    {
259
-        self::createLogEntry($database, $object, "BreakReserve");
260
-    }
261
-
262
-    /**
263
-     * @param PdoDatabase $database
264
-     * @param Request     $object
265
-     */
266
-    public static function unreserve(PdoDatabase $database, Request $object)
267
-    {
268
-        self::createLogEntry($database, $object, "Unreserved");
269
-    }
270
-
271
-    /**
272
-     * @param PdoDatabase $database
273
-     * @param Comment     $object
274
-     * @param Request     $request
275
-     */
276
-    public static function editComment(PdoDatabase $database, Comment $object, Request $request)
277
-    {
278
-        self::createLogEntry($database, $request, "EditComment-r");
279
-        self::createLogEntry($database, $object, "EditComment-c");
280
-    }
281
-
282
-    /**
283
-     * @param PdoDatabase $database
284
-     * @param Request     $object
285
-     * @param User        $target
286
-     */
287
-    public static function sendReservation(PdoDatabase $database, Request $object, User $target)
288
-    {
289
-        self::createLogEntry($database, $object, "SendReserved");
290
-        self::createLogEntry($database, $object, "ReceiveReserved", null, $target);
291
-    }
292
-
293
-    /**
294
-     * @param PdoDatabase $database
295
-     * @param Request     $object
296
-     * @param string      $comment
297
-     */
298
-    public static function sentMail(PdoDatabase $database, Request $object, $comment)
299
-    {
300
-        self::createLogEntry($database, $object, "SentMail", $comment);
301
-    }
302
-    #endregion
303
-
304
-    #region Email templates
305
-
306
-    /**
307
-     * @param PdoDatabase   $database
308
-     * @param EmailTemplate $object
309
-     */
310
-    public static function createEmail(PdoDatabase $database, EmailTemplate $object)
311
-    {
312
-        self::createLogEntry($database, $object, "CreatedEmail");
313
-    }
314
-
315
-    /**
316
-     * @param PdoDatabase   $database
317
-     * @param EmailTemplate $object
318
-     */
319
-    public static function editedEmail(PdoDatabase $database, EmailTemplate $object)
320
-    {
321
-        self::createLogEntry($database, $object, "EditedEmail");
322
-    }
323
-
324
-    #endregion
325
-
326
-    #region Display
327
-
328
-    #endregion
33
+	/**
34
+	 * @param PdoDatabase $database
35
+	 * @param Request     $object
36
+	 */
37
+	public static function emailConfirmed(PdoDatabase $database, Request $object)
38
+	{
39
+		self::createLogEntry($database, $object, "Email Confirmed", null, User::getCommunity());
40
+	}
41
+
42
+	/**
43
+	 * @param PdoDatabase $database
44
+	 * @param DataObject  $object
45
+	 * @param string      $logAction
46
+	 * @param null|string $comment
47
+	 * @param User        $user
48
+	 *
49
+	 * @throws Exception
50
+	 */
51
+	private static function createLogEntry(
52
+		PdoDatabase $database,
53
+		DataObject $object,
54
+		$logAction,
55
+		$comment = null,
56
+		$user = null
57
+	) {
58
+		if ($user == null) {
59
+			$user = User::getCurrent($database);
60
+		}
61
+
62
+		$objectType = get_class($object);
63
+		if (strpos($objectType, 'Waca\\DataObjects\\') !== false) {
64
+			$objectType = str_replace('Waca\\DataObjects\\', '', $objectType);
65
+		}
66
+
67
+		$log = new Log();
68
+		$log->setDatabase($database);
69
+		$log->setAction($logAction);
70
+		$log->setObjectId($object->getId());
71
+		$log->setObjectType($objectType);
72
+		$log->setUser($user);
73
+		$log->setComment($comment);
74
+		$log->save();
75
+	}
76
+
77
+	#region Users
78
+
79
+	/**
80
+	 * @param PdoDatabase $database
81
+	 * @param User        $user
82
+	 */
83
+	public static function newUser(PdoDatabase $database, User $user)
84
+	{
85
+		self::createLogEntry($database, $user, 'Registered', null, User::getCommunity());
86
+	}
87
+
88
+	/**
89
+	 * @param PdoDatabase $database
90
+	 * @param User        $object
91
+	 */
92
+	public static function approvedUser(PdoDatabase $database, User $object)
93
+	{
94
+		self::createLogEntry($database, $object, "Approved");
95
+	}
96
+
97
+	/**
98
+	 * @param PdoDatabase $database
99
+	 * @param User        $object
100
+	 * @param string      $comment
101
+	 */
102
+	public static function declinedUser(PdoDatabase $database, User $object, $comment)
103
+	{
104
+		self::createLogEntry($database, $object, "Declined", $comment);
105
+	}
106
+
107
+	/**
108
+	 * @param PdoDatabase $database
109
+	 * @param User        $object
110
+	 * @param string      $comment
111
+	 */
112
+	public static function suspendedUser(PdoDatabase $database, User $object, $comment)
113
+	{
114
+		self::createLogEntry($database, $object, "Suspended", $comment);
115
+	}
116
+
117
+	/**
118
+	 * @param PdoDatabase $database
119
+	 * @param User        $object
120
+	 * @param string      $comment
121
+	 */
122
+	public static function demotedUser(PdoDatabase $database, User $object, $comment)
123
+	{
124
+		self::createLogEntry($database, $object, "Demoted", $comment);
125
+	}
126
+
127
+	/**
128
+	 * @param PdoDatabase $database
129
+	 * @param User        $object
130
+	 */
131
+	public static function promotedUser(PdoDatabase $database, User $object)
132
+	{
133
+		self::createLogEntry($database, $object, "Promoted");
134
+	}
135
+
136
+	/**
137
+	 * @param PdoDatabase $database
138
+	 * @param User        $object
139
+	 * @param string      $comment
140
+	 */
141
+	public static function renamedUser(PdoDatabase $database, User $object, $comment)
142
+	{
143
+		self::createLogEntry($database, $object, "Renamed", $comment);
144
+	}
145
+
146
+	/**
147
+	 * @param PdoDatabase $database
148
+	 * @param User        $object
149
+	 */
150
+	public static function userPreferencesChange(PdoDatabase $database, User $object)
151
+	{
152
+		self::createLogEntry($database, $object, "Prefchange");
153
+	}
154
+
155
+	#endregion
156
+
157
+	/**
158
+	 * @param PdoDatabase $database
159
+	 * @param SiteNotice  $object
160
+	 */
161
+	public static function siteNoticeEdited(PdoDatabase $database, SiteNotice $object)
162
+	{
163
+		self::createLogEntry($database, $object, "Edited");
164
+	}
165
+
166
+	#region Welcome Templates
167
+
168
+	/**
169
+	 * @param PdoDatabase     $database
170
+	 * @param WelcomeTemplate $object
171
+	 */
172
+	public static function welcomeTemplateCreated(PdoDatabase $database, WelcomeTemplate $object)
173
+	{
174
+		self::createLogEntry($database, $object, "CreatedTemplate");
175
+	}
176
+
177
+	/**
178
+	 * @param PdoDatabase     $database
179
+	 * @param WelcomeTemplate $object
180
+	 */
181
+	public static function welcomeTemplateEdited(PdoDatabase $database, WelcomeTemplate $object)
182
+	{
183
+		self::createLogEntry($database, $object, "EditedTemplate");
184
+	}
185
+
186
+	/**
187
+	 * @param PdoDatabase     $database
188
+	 * @param WelcomeTemplate $object
189
+	 */
190
+	public static function welcomeTemplateDeleted(PdoDatabase $database, WelcomeTemplate $object)
191
+	{
192
+		self::createLogEntry($database, $object, "DeletedTemplate");
193
+	}
194
+
195
+	#endregion
196
+
197
+	#region Bans
198
+
199
+	/**
200
+	 * @param PdoDatabase $database
201
+	 * @param Ban         $object
202
+	 * @param string      $reason
203
+	 */
204
+	public static function banned(PdoDatabase $database, Ban $object, $reason)
205
+	{
206
+		self::createLogEntry($database, $object, "Banned", $reason);
207
+	}
208
+
209
+	/**
210
+	 * @param PdoDatabase $database
211
+	 * @param Ban         $object
212
+	 * @param string      $reason
213
+	 */
214
+	public static function unbanned(PdoDatabase $database, Ban $object, $reason)
215
+	{
216
+		self::createLogEntry($database, $object, "Unbanned", $reason);
217
+	}
218
+
219
+	#endregion
220
+
221
+	#region Requests
222
+
223
+	/**
224
+	 * @param PdoDatabase $database
225
+	 * @param Request     $object
226
+	 * @param string      $target
227
+	 */
228
+	public static function deferRequest(PdoDatabase $database, Request $object, $target)
229
+	{
230
+		self::createLogEntry($database, $object, "Deferred to $target");
231
+	}
232
+
233
+	/**
234
+	 * @param PdoDatabase $database
235
+	 * @param Request     $object
236
+	 * @param integer     $target
237
+	 * @param string      $comment
238
+	 */
239
+	public static function closeRequest(PdoDatabase $database, Request $object, $target, $comment)
240
+	{
241
+		self::createLogEntry($database, $object, "Closed $target", $comment);
242
+	}
243
+
244
+	/**
245
+	 * @param PdoDatabase $database
246
+	 * @param Request     $object
247
+	 */
248
+	public static function reserve(PdoDatabase $database, Request $object)
249
+	{
250
+		self::createLogEntry($database, $object, "Reserved");
251
+	}
252
+
253
+	/**
254
+	 * @param PdoDatabase $database
255
+	 * @param Request     $object
256
+	 */
257
+	public static function breakReserve(PdoDatabase $database, Request $object)
258
+	{
259
+		self::createLogEntry($database, $object, "BreakReserve");
260
+	}
261
+
262
+	/**
263
+	 * @param PdoDatabase $database
264
+	 * @param Request     $object
265
+	 */
266
+	public static function unreserve(PdoDatabase $database, Request $object)
267
+	{
268
+		self::createLogEntry($database, $object, "Unreserved");
269
+	}
270
+
271
+	/**
272
+	 * @param PdoDatabase $database
273
+	 * @param Comment     $object
274
+	 * @param Request     $request
275
+	 */
276
+	public static function editComment(PdoDatabase $database, Comment $object, Request $request)
277
+	{
278
+		self::createLogEntry($database, $request, "EditComment-r");
279
+		self::createLogEntry($database, $object, "EditComment-c");
280
+	}
281
+
282
+	/**
283
+	 * @param PdoDatabase $database
284
+	 * @param Request     $object
285
+	 * @param User        $target
286
+	 */
287
+	public static function sendReservation(PdoDatabase $database, Request $object, User $target)
288
+	{
289
+		self::createLogEntry($database, $object, "SendReserved");
290
+		self::createLogEntry($database, $object, "ReceiveReserved", null, $target);
291
+	}
292
+
293
+	/**
294
+	 * @param PdoDatabase $database
295
+	 * @param Request     $object
296
+	 * @param string      $comment
297
+	 */
298
+	public static function sentMail(PdoDatabase $database, Request $object, $comment)
299
+	{
300
+		self::createLogEntry($database, $object, "SentMail", $comment);
301
+	}
302
+	#endregion
303
+
304
+	#region Email templates
305
+
306
+	/**
307
+	 * @param PdoDatabase   $database
308
+	 * @param EmailTemplate $object
309
+	 */
310
+	public static function createEmail(PdoDatabase $database, EmailTemplate $object)
311
+	{
312
+		self::createLogEntry($database, $object, "CreatedEmail");
313
+	}
314
+
315
+	/**
316
+	 * @param PdoDatabase   $database
317
+	 * @param EmailTemplate $object
318
+	 */
319
+	public static function editedEmail(PdoDatabase $database, EmailTemplate $object)
320
+	{
321
+		self::createLogEntry($database, $object, "EditedEmail");
322
+	}
323
+
324
+	#endregion
325
+
326
+	#region Display
327
+
328
+	#endregion
329 329
 }
Please login to merge, or discard this patch.
includes/Helpers/OAuthHelper.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -21,231 +21,231 @@
 block discarded – undo
21 21
 
22 22
 class OAuthHelper implements IOAuthHelper
23 23
 {
24
-    private $oauthConsumer;
25
-    /**
26
-     * @var string
27
-     */
28
-    private $oauthEndpoint;
29
-    /**
30
-     * @var string
31
-     */
32
-    private $consumerToken;
33
-    /**
34
-     * @var string
35
-     */
36
-    private $consumerSecret;
37
-    /**
38
-     * @var HttpHelper
39
-     */
40
-    private $httpHelper;
41
-    /**
42
-     * @var string
43
-     */
44
-    private $mediawikiWebServiceEndpoint;
45
-
46
-    /**
47
-     * OAuthHelper constructor.
48
-     *
49
-     * @param string     $oauthEndpoint
50
-     * @param string     $consumerKey
51
-     * @param string     $consumerSecret
52
-     * @param HttpHelper $httpHelper
53
-     * @param string     $mediawikiWebServiceEndpoint
54
-     */
55
-    public function __construct(
56
-        $oauthEndpoint,
57
-        $consumerKey,
58
-        $consumerSecret,
59
-        HttpHelper $httpHelper,
60
-        $mediawikiWebServiceEndpoint
61
-    ) {
62
-        $this->oauthEndpoint = $oauthEndpoint;
63
-        $this->consumerToken = $consumerKey;
64
-        $this->consumerSecret = $consumerSecret;
65
-        $this->httpHelper = $httpHelper;
66
-
67
-        $this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret);
68
-        $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
69
-    }
70
-
71
-    /**
72
-     * @return stdClass
73
-     *
74
-     * @throws Exception
75
-     * @throws CurlException
76
-     */
77
-    public function getRequestToken()
78
-    {
79
-        $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
80
-
81
-        $parsedUrl = parse_url($endpoint);
82
-        $urlParameters = array();
83
-        parse_str($parsedUrl['query'], $urlParameters);
84
-
85
-        $req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters);
86
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
87
-        $req_req->sign_request($hmac_method, $this->oauthConsumer, null);
88
-
89
-        $targetUrl = (string)$req_req;
90
-
91
-        $data = $this->httpHelper->get($targetUrl, null);
92
-
93
-        if ($data === false) {
94
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
95
-        }
96
-
97
-        $token = json_decode($data);
98
-
99
-        if (!isset($token)) {
100
-            throw new Exception('Unknown error encountered getting request token while decoding json data.');
101
-        }
102
-
103
-        if (isset($token->error)) {
104
-            throw new Exception('Error encountered while getting request token: ' . $token->error);
105
-        }
106
-
107
-        return $token;
108
-    }
109
-
110
-    /**
111
-     * @param string $requestToken
112
-     *
113
-     * @return string
114
-     */
115
-    public function getAuthoriseUrl($requestToken)
116
-    {
117
-        return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}";
118
-    }
119
-
120
-    /**
121
-     * @param string $oauthRequestToken
122
-     * @param string $oauthRequestSecret
123
-     * @param string $oauthVerifier
124
-     *
125
-     * @return stdClass
126
-     * @throws CurlException
127
-     * @throws Exception
128
-     */
129
-    public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130
-    {
131
-        $endpoint = $this->oauthEndpoint . '/token&format=json';
132
-
133
-        $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134
-
135
-        $parsedUrl = parse_url($endpoint);
136
-        parse_str($parsedUrl['query'], $urlParameters);
137
-        $urlParameters['oauth_verifier'] = trim($oauthVerifier);
138
-
139
-        $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint,
140
-            $urlParameters);
141
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
142
-        $acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer);
143
-
144
-        $targetUrl = (string)$acc_req;
145
-
146
-        $data = $this->httpHelper->get($targetUrl, null);
147
-
148
-        if ($data === false) {
149
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
150
-        }
151
-
152
-        $token = json_decode($data);
153
-
154
-        if (!isset($token)) {
155
-            throw new Exception('Unknown error encountered getting access token while decoding json data.');
156
-        }
157
-
158
-        if (isset($token->error)) {
159
-            throw new Exception('Error encountered while getting access token: ' . $token->error);
160
-        }
161
-
162
-        return $token;
163
-    }
164
-
165
-    /**
166
-     * @param string $oauthAccessToken
167
-     * @param string $oauthAccessSecret
168
-     *
169
-     * @return JWT
170
-     * @throws CurlException
171
-     * @throws Exception
172
-     */
173
-    public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174
-    {
175
-        $endpoint = $this->oauthEndpoint . '/identify&format=json';
176
-
177
-        $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178
-
179
-        $parsedUrl = parse_url($endpoint);
180
-        parse_str($parsedUrl['query'], $urlParameters);
181
-
182
-        $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint,
183
-            $urlParameters);
184
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
185
-        $acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken);
186
-
187
-        $targetUrl = (string)$acc_req;
188
-
189
-        $data = $this->httpHelper->get($targetUrl, null);
190
-
191
-        if ($data === false) {
192
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
193
-        }
194
-
195
-        $decodedData = json_decode($data);
196
-
197
-        if (isset($decodedData->error)) {
198
-            throw new Exception($decodedData->error);
199
-        }
200
-
201
-        $identity = JWT::decode($data, $this->consumerSecret);
202
-
203
-        return $identity;
204
-    }
205
-
206
-    /**
207
-     * @param array  $apiParams    array of parameters to send to the API
208
-     * @param string $accessToken  user's access token
209
-     * @param string $accessSecret user's secret
210
-     * @param string $method       HTTP method
211
-     *
212
-     * @return stdClass
213
-     * @throws ApplicationLogicException
214
-     * @throws CurlException
215
-     * @throws Exception
216
-     */
217
-    public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET')
218
-    {
219
-        $userToken = new OAuthToken($accessToken, $accessSecret);
220
-
221
-        $apiParams['format'] = 'json';
222
-
223
-        $api_req = OAuthRequest::from_consumer_and_token(
224
-            $this->oauthConsumer, // Consumer
225
-            $userToken, // User Access Token
226
-            $method, // HTTP Method
227
-            $this->mediawikiWebServiceEndpoint, // Endpoint url
228
-            $apiParams    // Extra signed parameters
229
-        );
230
-
231
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
24
+	private $oauthConsumer;
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $oauthEndpoint;
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private $consumerToken;
33
+	/**
34
+	 * @var string
35
+	 */
36
+	private $consumerSecret;
37
+	/**
38
+	 * @var HttpHelper
39
+	 */
40
+	private $httpHelper;
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private $mediawikiWebServiceEndpoint;
45
+
46
+	/**
47
+	 * OAuthHelper constructor.
48
+	 *
49
+	 * @param string     $oauthEndpoint
50
+	 * @param string     $consumerKey
51
+	 * @param string     $consumerSecret
52
+	 * @param HttpHelper $httpHelper
53
+	 * @param string     $mediawikiWebServiceEndpoint
54
+	 */
55
+	public function __construct(
56
+		$oauthEndpoint,
57
+		$consumerKey,
58
+		$consumerSecret,
59
+		HttpHelper $httpHelper,
60
+		$mediawikiWebServiceEndpoint
61
+	) {
62
+		$this->oauthEndpoint = $oauthEndpoint;
63
+		$this->consumerToken = $consumerKey;
64
+		$this->consumerSecret = $consumerSecret;
65
+		$this->httpHelper = $httpHelper;
66
+
67
+		$this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret);
68
+		$this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
69
+	}
70
+
71
+	/**
72
+	 * @return stdClass
73
+	 *
74
+	 * @throws Exception
75
+	 * @throws CurlException
76
+	 */
77
+	public function getRequestToken()
78
+	{
79
+		$endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
80
+
81
+		$parsedUrl = parse_url($endpoint);
82
+		$urlParameters = array();
83
+		parse_str($parsedUrl['query'], $urlParameters);
84
+
85
+		$req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters);
86
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
87
+		$req_req->sign_request($hmac_method, $this->oauthConsumer, null);
88
+
89
+		$targetUrl = (string)$req_req;
90
+
91
+		$data = $this->httpHelper->get($targetUrl, null);
92
+
93
+		if ($data === false) {
94
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
95
+		}
96
+
97
+		$token = json_decode($data);
98
+
99
+		if (!isset($token)) {
100
+			throw new Exception('Unknown error encountered getting request token while decoding json data.');
101
+		}
102
+
103
+		if (isset($token->error)) {
104
+			throw new Exception('Error encountered while getting request token: ' . $token->error);
105
+		}
106
+
107
+		return $token;
108
+	}
109
+
110
+	/**
111
+	 * @param string $requestToken
112
+	 *
113
+	 * @return string
114
+	 */
115
+	public function getAuthoriseUrl($requestToken)
116
+	{
117
+		return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}";
118
+	}
119
+
120
+	/**
121
+	 * @param string $oauthRequestToken
122
+	 * @param string $oauthRequestSecret
123
+	 * @param string $oauthVerifier
124
+	 *
125
+	 * @return stdClass
126
+	 * @throws CurlException
127
+	 * @throws Exception
128
+	 */
129
+	public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130
+	{
131
+		$endpoint = $this->oauthEndpoint . '/token&format=json';
132
+
133
+		$requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134
+
135
+		$parsedUrl = parse_url($endpoint);
136
+		parse_str($parsedUrl['query'], $urlParameters);
137
+		$urlParameters['oauth_verifier'] = trim($oauthVerifier);
138
+
139
+		$acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint,
140
+			$urlParameters);
141
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
142
+		$acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer);
143
+
144
+		$targetUrl = (string)$acc_req;
145
+
146
+		$data = $this->httpHelper->get($targetUrl, null);
147
+
148
+		if ($data === false) {
149
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
150
+		}
151
+
152
+		$token = json_decode($data);
153
+
154
+		if (!isset($token)) {
155
+			throw new Exception('Unknown error encountered getting access token while decoding json data.');
156
+		}
157
+
158
+		if (isset($token->error)) {
159
+			throw new Exception('Error encountered while getting access token: ' . $token->error);
160
+		}
161
+
162
+		return $token;
163
+	}
164
+
165
+	/**
166
+	 * @param string $oauthAccessToken
167
+	 * @param string $oauthAccessSecret
168
+	 *
169
+	 * @return JWT
170
+	 * @throws CurlException
171
+	 * @throws Exception
172
+	 */
173
+	public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174
+	{
175
+		$endpoint = $this->oauthEndpoint . '/identify&format=json';
176
+
177
+		$oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178
+
179
+		$parsedUrl = parse_url($endpoint);
180
+		parse_str($parsedUrl['query'], $urlParameters);
181
+
182
+		$acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint,
183
+			$urlParameters);
184
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
185
+		$acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken);
186
+
187
+		$targetUrl = (string)$acc_req;
188
+
189
+		$data = $this->httpHelper->get($targetUrl, null);
190
+
191
+		if ($data === false) {
192
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
193
+		}
194
+
195
+		$decodedData = json_decode($data);
196
+
197
+		if (isset($decodedData->error)) {
198
+			throw new Exception($decodedData->error);
199
+		}
200
+
201
+		$identity = JWT::decode($data, $this->consumerSecret);
202
+
203
+		return $identity;
204
+	}
205
+
206
+	/**
207
+	 * @param array  $apiParams    array of parameters to send to the API
208
+	 * @param string $accessToken  user's access token
209
+	 * @param string $accessSecret user's secret
210
+	 * @param string $method       HTTP method
211
+	 *
212
+	 * @return stdClass
213
+	 * @throws ApplicationLogicException
214
+	 * @throws CurlException
215
+	 * @throws Exception
216
+	 */
217
+	public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET')
218
+	{
219
+		$userToken = new OAuthToken($accessToken, $accessSecret);
220
+
221
+		$apiParams['format'] = 'json';
222
+
223
+		$api_req = OAuthRequest::from_consumer_and_token(
224
+			$this->oauthConsumer, // Consumer
225
+			$userToken, // User Access Token
226
+			$method, // HTTP Method
227
+			$this->mediawikiWebServiceEndpoint, // Endpoint url
228
+			$apiParams    // Extra signed parameters
229
+		);
230
+
231
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
232 232
 
233
-        $api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken);
234
-
235
-        if ($method == 'GET') {
236
-            $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams);
237
-        }
238
-        elseif ($method == 'POST') {
239
-            $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams);
240
-        }
241
-        else {
242
-            throw new ApplicationLogicException('Unsupported HTTP Method');
243
-        }
244
-
245
-        if ($data === false) {
246
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
247
-        }
248
-
249
-        return json_decode($data);
250
-    }
233
+		$api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken);
234
+
235
+		if ($method == 'GET') {
236
+			$data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams);
237
+		}
238
+		elseif ($method == 'POST') {
239
+			$data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams);
240
+		}
241
+		else {
242
+			throw new ApplicationLogicException('Unsupported HTTP Method');
243
+		}
244
+
245
+		if ($data === false) {
246
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
247
+		}
248
+
249
+		return json_decode($data);
250
+	}
251 251
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function getRequestToken()
78 78
     {
79
-        $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
79
+        $endpoint = $this->oauthEndpoint.'/initiate&format=json&oauth_callback=oob';
80 80
 
81 81
         $parsedUrl = parse_url($endpoint);
82 82
         $urlParameters = array();
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $data = $this->httpHelper->get($targetUrl, null);
92 92
 
93 93
         if ($data === false) {
94
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
94
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
95 95
         }
96 96
 
97 97
         $token = json_decode($data);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         }
102 102
 
103 103
         if (isset($token->error)) {
104
-            throw new Exception('Error encountered while getting request token: ' . $token->error);
104
+            throw new Exception('Error encountered while getting request token: '.$token->error);
105 105
         }
106 106
 
107 107
         return $token;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130 130
     {
131
-        $endpoint = $this->oauthEndpoint . '/token&format=json';
131
+        $endpoint = $this->oauthEndpoint.'/token&format=json';
132 132
 
133 133
         $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134 134
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         $data = $this->httpHelper->get($targetUrl, null);
147 147
 
148 148
         if ($data === false) {
149
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
149
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
150 150
         }
151 151
 
152 152
         $token = json_decode($data);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         if (isset($token->error)) {
159
-            throw new Exception('Error encountered while getting access token: ' . $token->error);
159
+            throw new Exception('Error encountered while getting access token: '.$token->error);
160 160
         }
161 161
 
162 162
         return $token;
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174 174
     {
175
-        $endpoint = $this->oauthEndpoint . '/identify&format=json';
175
+        $endpoint = $this->oauthEndpoint.'/identify&format=json';
176 176
 
177 177
         $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178 178
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $data = $this->httpHelper->get($targetUrl, null);
190 190
 
191 191
         if ($data === false) {
192
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
192
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
193 193
         }
194 194
 
195 195
         $decodedData = json_decode($data);
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         }
244 244
 
245 245
         if ($data === false) {
246
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
246
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
247 247
         }
248 248
 
249 249
         return json_decode($data);
Please login to merge, or discard this patch.