Completed
Pull Request — newinternal (#285)
by Simon
07:17 queued 04:17
created
includes/Helpers/SearchHelpers/RequestSearchHelper.php 2 patches
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.
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -14,117 +14,117 @@
 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', Request::class);
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
-     * Filters the results by IP address
43
-     *
44
-     * @param string $ipAddress
45
-     *
46
-     * @return $this
47
-     */
48
-    public function byIp($ipAddress)
49
-    {
50
-        $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
51
-        $this->parameterList[] = $ipAddress;
52
-        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
53
-
54
-        return $this;
55
-    }
56
-
57
-    /**
58
-     * Filters the results by email address
59
-     *
60
-     * @param string $emailAddress
61
-     *
62
-     * @return $this
63
-     */
64
-    public function byEmailAddress($emailAddress)
65
-    {
66
-        $this->whereClause .= ' AND email LIKE ?';
67
-        $this->parameterList[] = $emailAddress;
68
-
69
-        return $this;
70
-    }
71
-
72
-    /**
73
-     * Filters the results by name
74
-     *
75
-     * @param string $name
76
-     *
77
-     * @return $this
78
-     */
79
-    public function byName($name)
80
-    {
81
-        $this->whereClause .= ' AND name LIKE ?';
82
-        $this->parameterList[] = $name;
83
-
84
-        return $this;
85
-    }
86
-
87
-    /**
88
-     * Excludes a request from the results
89
-     *
90
-     * @param int $requestId
91
-     *
92
-     * @return $this
93
-     */
94
-    public function excludingRequest($requestId)
95
-    {
96
-        $this->whereClause .= ' AND id <> ?';
97
-        $this->parameterList[] = $requestId;
98
-
99
-        return $this;
100
-    }
101
-
102
-    /**
103
-     * Filters the results to only those with a confirmed email address
104
-     *
105
-     * @return $this
106
-     */
107
-    public function withConfirmedEmail()
108
-    {
109
-        $this->whereClause .= ' AND emailconfirm = ?';
110
-        $this->parameterList[] = 'Confirmed';
111
-
112
-        return $this;
113
-    }
114
-
115
-    /**
116
-     * Filters the results to exclude purged data
117
-     *
118
-     * @param SiteConfiguration $configuration
119
-     *
120
-     * @return $this
121
-     */
122
-    public function excludingPurgedData(SiteConfiguration $configuration)
123
-    {
124
-        $this->whereClause .= ' AND ip <> ? AND email <> ?';
125
-        $this->parameterList[] = $configuration->getDataClearIp();
126
-        $this->parameterList[] = $configuration->getDataClearEmail();
127
-
128
-        return $this;
129
-    }
17
+	/**
18
+	 * RequestSearchHelper constructor.
19
+	 *
20
+	 * @param PdoDatabase $database
21
+	 */
22
+	protected function __construct(PdoDatabase $database)
23
+	{
24
+		parent::__construct($database, 'request', Request::class);
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
+	 * Filters the results by IP address
43
+	 *
44
+	 * @param string $ipAddress
45
+	 *
46
+	 * @return $this
47
+	 */
48
+	public function byIp($ipAddress)
49
+	{
50
+		$this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
51
+		$this->parameterList[] = $ipAddress;
52
+		$this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
53
+
54
+		return $this;
55
+	}
56
+
57
+	/**
58
+	 * Filters the results by email address
59
+	 *
60
+	 * @param string $emailAddress
61
+	 *
62
+	 * @return $this
63
+	 */
64
+	public function byEmailAddress($emailAddress)
65
+	{
66
+		$this->whereClause .= ' AND email LIKE ?';
67
+		$this->parameterList[] = $emailAddress;
68
+
69
+		return $this;
70
+	}
71
+
72
+	/**
73
+	 * Filters the results by name
74
+	 *
75
+	 * @param string $name
76
+	 *
77
+	 * @return $this
78
+	 */
79
+	public function byName($name)
80
+	{
81
+		$this->whereClause .= ' AND name LIKE ?';
82
+		$this->parameterList[] = $name;
83
+
84
+		return $this;
85
+	}
86
+
87
+	/**
88
+	 * Excludes a request from the results
89
+	 *
90
+	 * @param int $requestId
91
+	 *
92
+	 * @return $this
93
+	 */
94
+	public function excludingRequest($requestId)
95
+	{
96
+		$this->whereClause .= ' AND id <> ?';
97
+		$this->parameterList[] = $requestId;
98
+
99
+		return $this;
100
+	}
101
+
102
+	/**
103
+	 * Filters the results to only those with a confirmed email address
104
+	 *
105
+	 * @return $this
106
+	 */
107
+	public function withConfirmedEmail()
108
+	{
109
+		$this->whereClause .= ' AND emailconfirm = ?';
110
+		$this->parameterList[] = 'Confirmed';
111
+
112
+		return $this;
113
+	}
114
+
115
+	/**
116
+	 * Filters the results to exclude purged data
117
+	 *
118
+	 * @param SiteConfiguration $configuration
119
+	 *
120
+	 * @return $this
121
+	 */
122
+	public function excludingPurgedData(SiteConfiguration $configuration)
123
+	{
124
+		$this->whereClause .= ' AND ip <> ? AND email <> ?';
125
+		$this->parameterList[] = $configuration->getDataClearIp();
126
+		$this->parameterList[] = $configuration->getDataClearEmail();
127
+
128
+		return $this;
129
+	}
130 130
 }
131 131
\ No newline at end of file
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.
includes/Helpers/BanHelper.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,49 +14,49 @@
 block discarded – undo
14 14
 
15 15
 class BanHelper implements IBanHelper
16 16
 {
17
-    /**
18
-     * @var PdoDatabase
19
-     */
20
-    private $database;
17
+	/**
18
+	 * @var PdoDatabase
19
+	 */
20
+	private $database;
21 21
 
22
-    public function __construct(PdoDatabase $database)
23
-    {
24
-        $this->database = $database;
25
-    }
22
+	public function __construct(PdoDatabase $database)
23
+	{
24
+		$this->database = $database;
25
+	}
26 26
 
27
-    /**
28
-     * Summary of nameIsBanned
29
-     *
30
-     * @param string $name The name to test if is banned.
31
-     *
32
-     * @return Ban
33
-     */
34
-    public function nameIsBanned($name)
35
-    {
36
-        return Ban::getBanByTarget($name, "Name", $this->database);
37
-    }
27
+	/**
28
+	 * Summary of nameIsBanned
29
+	 *
30
+	 * @param string $name The name to test if is banned.
31
+	 *
32
+	 * @return Ban
33
+	 */
34
+	public function nameIsBanned($name)
35
+	{
36
+		return Ban::getBanByTarget($name, "Name", $this->database);
37
+	}
38 38
 
39
-    /**
40
-     * Summary of emailIsBanned
41
-     *
42
-     * @param string $email
43
-     *
44
-     * @return Ban
45
-     */
46
-    public function emailIsBanned($email)
47
-    {
48
-        return Ban::getBanByTarget($email, "EMail", $this->database);
49
-    }
39
+	/**
40
+	 * Summary of emailIsBanned
41
+	 *
42
+	 * @param string $email
43
+	 *
44
+	 * @return Ban
45
+	 */
46
+	public function emailIsBanned($email)
47
+	{
48
+		return Ban::getBanByTarget($email, "EMail", $this->database);
49
+	}
50 50
 
51
-    /**
52
-     * Summary of ipIsBanned
53
-     *
54
-     * @param string $ip
55
-     *
56
-     * @return Ban
57
-     */
58
-    public function ipIsBanned($ip)
59
-    {
60
-        return Ban::getBanByTarget($ip, "IP", $this->database);
61
-    }
51
+	/**
52
+	 * Summary of ipIsBanned
53
+	 *
54
+	 * @param string $ip
55
+	 *
56
+	 * @return Ban
57
+	 */
58
+	public function ipIsBanned($ip)
59
+	{
60
+		return Ban::getBanByTarget($ip, "IP", $this->database);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
includes/Helpers/LogHelper.php 2 patches
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -24,321 +24,321 @@
 block discarded – undo
24 24
 
25 25
 class LogHelper
26 26
 {
27
-    /**
28
-     * Summary of getRequestLogsWithComments
29
-     *
30
-     * @param int         $requestId
31
-     * @param PdoDatabase $db
32
-     *
33
-     * @return DataObject[]
34
-     */
35
-    public static function getRequestLogsWithComments($requestId, PdoDatabase $db)
36
-    {
37
-        $logs = LogSearchHelper::get($db)->byObjectType('Request')->byObjectId($requestId)->fetch();
38
-        $comments = Comment::getForRequest($requestId, $db);
39
-
40
-        $items = array_merge($logs, $comments);
41
-
42
-        /**
43
-         * @param DataObject $item
44
-         *
45
-         * @return int
46
-         */
47
-        $sortKey = function(DataObject $item) {
48
-            if ($item instanceof Log) {
49
-                return $item->getTimestamp()->getTimestamp();
50
-            }
51
-
52
-            if ($item instanceof Comment) {
53
-                return $item->getTime()->getTimestamp();
54
-            }
55
-
56
-            return 0;
57
-        };
58
-
59
-        do {
60
-            $flag = false;
61
-
62
-            $loopLimit = (count($items) - 1);
63
-            for ($i = 0; $i < $loopLimit; $i++) {
64
-                // are these two items out of order?
65
-                if ($sortKey($items[$i]) > $sortKey($items[$i + 1])) {
66
-                    // swap them
67
-                    $swap = $items[$i];
68
-                    $items[$i] = $items[$i + 1];
69
-                    $items[$i + 1] = $swap;
70
-
71
-                    // set a flag to say we've modified the array this time around
72
-                    $flag = true;
73
-                }
74
-            }
75
-        }
76
-        while ($flag);
77
-
78
-        return $items;
79
-    }
80
-
81
-    /**
82
-     * Summary of getLogDescription
83
-     *
84
-     * @param Log $entry
85
-     *
86
-     * @return string
87
-     */
88
-    public static function getLogDescription(Log $entry)
89
-    {
90
-        $text = "Deferred to ";
91
-        if (substr($entry->getAction(), 0, strlen($text)) == $text) {
92
-            // Deferred to a different queue
93
-            // This is exactly what we want to display.
94
-            return $entry->getAction();
95
-        }
96
-
97
-        $text = "Closed custom-n";
98
-        if ($entry->getAction() == $text) {
99
-            // Custom-closed
100
-            return "closed (custom reason - account not created)";
101
-        }
102
-
103
-        $text = "Closed custom-y";
104
-        if ($entry->getAction() == $text) {
105
-            // Custom-closed
106
-            return "closed (custom reason - account created)";
107
-        }
108
-
109
-        $text = "Closed 0";
110
-        if ($entry->getAction() == $text) {
111
-            // Dropped the request - short-circuit the lookup
112
-            return "dropped request";
113
-        }
114
-
115
-        $text = "Closed ";
116
-        if (substr($entry->getAction(), 0, strlen($text)) == $text) {
117
-            // Closed with a reason - do a lookup here.
118
-            $id = substr($entry->getAction(), strlen($text));
119
-            /** @var EmailTemplate $template */
120
-            $template = EmailTemplate::getById((int)$id, $entry->getDatabase());
121
-
122
-            if ($template != false) {
123
-                return "closed (" . $template->getName() . ")";
124
-            }
125
-        }
126
-
127
-        // Fall back to the basic stuff
128
-        $lookup = array(
129
-            'Reserved'        => 'reserved',
130
-            'Email Confirmed' => 'email-confirmed',
131
-            'Unreserved'      => 'unreserved',
132
-            'Approved'        => 'approved',
133
-            'Suspended'       => 'suspended',
134
-            'Banned'          => 'banned',
135
-            'Edited'          => 'edited interface message',
136
-            'Declined'        => 'declined',
137
-            'EditComment-c'   => 'edited a comment',
138
-            'EditComment-r'   => 'edited a comment',
139
-            'Unbanned'        => 'unbanned',
140
-            'Promoted'        => 'promoted to tool admin',
141
-            'BreakReserve'    => 'forcibly broke the reservation',
142
-            'Prefchange'      => 'changed user preferences',
143
-            'Renamed'         => 'renamed',
144
-            'Demoted'         => 'demoted from tool admin',
145
-            'ReceiveReserved' => 'received the reservation',
146
-            'SendReserved'    => 'sent the reservation',
147
-            'EditedEmail'     => 'edited email',
148
-            'DeletedTemplate' => 'deleted template',
149
-            'EditedTemplate'  => 'edited template',
150
-            'CreatedEmail'    => 'created email',
151
-            'CreatedTemplate' => 'created template',
152
-            'SentMail'        => 'sent an email to the requestor',
153
-            'Registered'      => 'registered a tool account',
154
-        );
155
-
156
-        if (array_key_exists($entry->getAction(), $lookup)) {
157
-            return $lookup[$entry->getAction()];
158
-        }
159
-
160
-        // OK, I don't know what this is. Fall back to something sane.
161
-        return "performed an unknown action ({$entry->getAction()})";
162
-    }
163
-
164
-    /**
165
-     * @param PdoDatabase $database
166
-     *
167
-     * @return array
168
-     */
169
-    public static function getLogActions(PdoDatabase $database)
170
-    {
171
-        $lookup = array(
172
-            'Reserved'        => 'reserved',
173
-            'Email Confirmed' => 'email-confirmed',
174
-            'Unreserved'      => 'unreserved',
175
-            'Approved'        => 'approved',
176
-            'Suspended'       => 'suspended',
177
-            'Banned'          => 'banned',
178
-            'Edited'          => 'edited interface message',
179
-            'Declined'        => 'declined',
180
-            'EditComment-c'   => 'edited a comment (by comment ID)',
181
-            'EditComment-r'   => 'edited a comment (by request)',
182
-            'Unbanned'        => 'unbanned',
183
-            'Promoted'        => 'promoted to tool admin',
184
-            'BreakReserve'    => 'forcibly broke the reservation',
185
-            'Prefchange'      => 'changed user preferences',
186
-            'Renamed'         => 'renamed',
187
-            'Demoted'         => 'demoted from tool admin',
188
-            'ReceiveReserved' => 'received the reservation',
189
-            'SendReserved'    => 'sent the reservation',
190
-            'EditedEmail'     => 'edited email',
191
-            'DeletedTemplate' => 'deleted template',
192
-            'EditedTemplate'  => 'edited template',
193
-            'CreatedEmail'    => 'created email',
194
-            'CreatedTemplate' => 'created template',
195
-            'SentMail'        => 'sent an email to the requestor',
196
-            'Registered'      => 'registered a tool account',
197
-            'Closed 0'        => 'dropped request',
198
-        );
199
-
200
-        $statement = $database->query(<<<SQL
27
+	/**
28
+	 * Summary of getRequestLogsWithComments
29
+	 *
30
+	 * @param int         $requestId
31
+	 * @param PdoDatabase $db
32
+	 *
33
+	 * @return DataObject[]
34
+	 */
35
+	public static function getRequestLogsWithComments($requestId, PdoDatabase $db)
36
+	{
37
+		$logs = LogSearchHelper::get($db)->byObjectType('Request')->byObjectId($requestId)->fetch();
38
+		$comments = Comment::getForRequest($requestId, $db);
39
+
40
+		$items = array_merge($logs, $comments);
41
+
42
+		/**
43
+		 * @param DataObject $item
44
+		 *
45
+		 * @return int
46
+		 */
47
+		$sortKey = function(DataObject $item) {
48
+			if ($item instanceof Log) {
49
+				return $item->getTimestamp()->getTimestamp();
50
+			}
51
+
52
+			if ($item instanceof Comment) {
53
+				return $item->getTime()->getTimestamp();
54
+			}
55
+
56
+			return 0;
57
+		};
58
+
59
+		do {
60
+			$flag = false;
61
+
62
+			$loopLimit = (count($items) - 1);
63
+			for ($i = 0; $i < $loopLimit; $i++) {
64
+				// are these two items out of order?
65
+				if ($sortKey($items[$i]) > $sortKey($items[$i + 1])) {
66
+					// swap them
67
+					$swap = $items[$i];
68
+					$items[$i] = $items[$i + 1];
69
+					$items[$i + 1] = $swap;
70
+
71
+					// set a flag to say we've modified the array this time around
72
+					$flag = true;
73
+				}
74
+			}
75
+		}
76
+		while ($flag);
77
+
78
+		return $items;
79
+	}
80
+
81
+	/**
82
+	 * Summary of getLogDescription
83
+	 *
84
+	 * @param Log $entry
85
+	 *
86
+	 * @return string
87
+	 */
88
+	public static function getLogDescription(Log $entry)
89
+	{
90
+		$text = "Deferred to ";
91
+		if (substr($entry->getAction(), 0, strlen($text)) == $text) {
92
+			// Deferred to a different queue
93
+			// This is exactly what we want to display.
94
+			return $entry->getAction();
95
+		}
96
+
97
+		$text = "Closed custom-n";
98
+		if ($entry->getAction() == $text) {
99
+			// Custom-closed
100
+			return "closed (custom reason - account not created)";
101
+		}
102
+
103
+		$text = "Closed custom-y";
104
+		if ($entry->getAction() == $text) {
105
+			// Custom-closed
106
+			return "closed (custom reason - account created)";
107
+		}
108
+
109
+		$text = "Closed 0";
110
+		if ($entry->getAction() == $text) {
111
+			// Dropped the request - short-circuit the lookup
112
+			return "dropped request";
113
+		}
114
+
115
+		$text = "Closed ";
116
+		if (substr($entry->getAction(), 0, strlen($text)) == $text) {
117
+			// Closed with a reason - do a lookup here.
118
+			$id = substr($entry->getAction(), strlen($text));
119
+			/** @var EmailTemplate $template */
120
+			$template = EmailTemplate::getById((int)$id, $entry->getDatabase());
121
+
122
+			if ($template != false) {
123
+				return "closed (" . $template->getName() . ")";
124
+			}
125
+		}
126
+
127
+		// Fall back to the basic stuff
128
+		$lookup = array(
129
+			'Reserved'        => 'reserved',
130
+			'Email Confirmed' => 'email-confirmed',
131
+			'Unreserved'      => 'unreserved',
132
+			'Approved'        => 'approved',
133
+			'Suspended'       => 'suspended',
134
+			'Banned'          => 'banned',
135
+			'Edited'          => 'edited interface message',
136
+			'Declined'        => 'declined',
137
+			'EditComment-c'   => 'edited a comment',
138
+			'EditComment-r'   => 'edited a comment',
139
+			'Unbanned'        => 'unbanned',
140
+			'Promoted'        => 'promoted to tool admin',
141
+			'BreakReserve'    => 'forcibly broke the reservation',
142
+			'Prefchange'      => 'changed user preferences',
143
+			'Renamed'         => 'renamed',
144
+			'Demoted'         => 'demoted from tool admin',
145
+			'ReceiveReserved' => 'received the reservation',
146
+			'SendReserved'    => 'sent the reservation',
147
+			'EditedEmail'     => 'edited email',
148
+			'DeletedTemplate' => 'deleted template',
149
+			'EditedTemplate'  => 'edited template',
150
+			'CreatedEmail'    => 'created email',
151
+			'CreatedTemplate' => 'created template',
152
+			'SentMail'        => 'sent an email to the requestor',
153
+			'Registered'      => 'registered a tool account',
154
+		);
155
+
156
+		if (array_key_exists($entry->getAction(), $lookup)) {
157
+			return $lookup[$entry->getAction()];
158
+		}
159
+
160
+		// OK, I don't know what this is. Fall back to something sane.
161
+		return "performed an unknown action ({$entry->getAction()})";
162
+	}
163
+
164
+	/**
165
+	 * @param PdoDatabase $database
166
+	 *
167
+	 * @return array
168
+	 */
169
+	public static function getLogActions(PdoDatabase $database)
170
+	{
171
+		$lookup = array(
172
+			'Reserved'        => 'reserved',
173
+			'Email Confirmed' => 'email-confirmed',
174
+			'Unreserved'      => 'unreserved',
175
+			'Approved'        => 'approved',
176
+			'Suspended'       => 'suspended',
177
+			'Banned'          => 'banned',
178
+			'Edited'          => 'edited interface message',
179
+			'Declined'        => 'declined',
180
+			'EditComment-c'   => 'edited a comment (by comment ID)',
181
+			'EditComment-r'   => 'edited a comment (by request)',
182
+			'Unbanned'        => 'unbanned',
183
+			'Promoted'        => 'promoted to tool admin',
184
+			'BreakReserve'    => 'forcibly broke the reservation',
185
+			'Prefchange'      => 'changed user preferences',
186
+			'Renamed'         => 'renamed',
187
+			'Demoted'         => 'demoted from tool admin',
188
+			'ReceiveReserved' => 'received the reservation',
189
+			'SendReserved'    => 'sent the reservation',
190
+			'EditedEmail'     => 'edited email',
191
+			'DeletedTemplate' => 'deleted template',
192
+			'EditedTemplate'  => 'edited template',
193
+			'CreatedEmail'    => 'created email',
194
+			'CreatedTemplate' => 'created template',
195
+			'SentMail'        => 'sent an email to the requestor',
196
+			'Registered'      => 'registered a tool account',
197
+			'Closed 0'        => 'dropped request',
198
+		);
199
+
200
+		$statement = $database->query(<<<SQL
201 201
 SELECT CONCAT('Closed ', id) AS k, CONCAT('closed (',name,')') AS v
202 202
 FROM emailtemplate;
203 203
 SQL
204
-        );
205
-        foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
206
-            $lookup[$row['k']] = $row['v'];
207
-        }
208
-
209
-        return $lookup;
210
-    }
211
-
212
-    /**
213
-     * This returns a HTML
214
-     *
215
-     * @param string            $objectId
216
-     * @param string            $objectType
217
-     * @param PdoDatabase       $database
218
-     * @param SiteConfiguration $configuration
219
-     *
220
-     * @return null|string
221
-     * @category Security-Critical
222
-     */
223
-    private static function getObjectDescription(
224
-        $objectId,
225
-        $objectType,
226
-        PdoDatabase $database,
227
-        SiteConfiguration $configuration
228
-    ) {
229
-        if ($objectType == '') {
230
-            return null;
231
-        }
232
-
233
-        $baseurl = $configuration->getBaseUrl();
234
-
235
-        switch ($objectType) {
236
-            case 'Ban':
237
-                /** @var Ban $ban */
238
-                $ban = Ban::getById($objectId, $database);
239
-
240
-                return 'Ban #' . $objectId . " (" . htmlentities($ban->getTarget()) . ")</a>";
241
-            case 'EmailTemplate':
242
-                /** @var EmailTemplate $emailTemplate */
243
-                $emailTemplate = EmailTemplate::getById($objectId, $database);
244
-                $name = htmlentities($emailTemplate->getName(), ENT_COMPAT, 'UTF-8');
245
-
246
-                return <<<HTML
204
+		);
205
+		foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
206
+			$lookup[$row['k']] = $row['v'];
207
+		}
208
+
209
+		return $lookup;
210
+	}
211
+
212
+	/**
213
+	 * This returns a HTML
214
+	 *
215
+	 * @param string            $objectId
216
+	 * @param string            $objectType
217
+	 * @param PdoDatabase       $database
218
+	 * @param SiteConfiguration $configuration
219
+	 *
220
+	 * @return null|string
221
+	 * @category Security-Critical
222
+	 */
223
+	private static function getObjectDescription(
224
+		$objectId,
225
+		$objectType,
226
+		PdoDatabase $database,
227
+		SiteConfiguration $configuration
228
+	) {
229
+		if ($objectType == '') {
230
+			return null;
231
+		}
232
+
233
+		$baseurl = $configuration->getBaseUrl();
234
+
235
+		switch ($objectType) {
236
+			case 'Ban':
237
+				/** @var Ban $ban */
238
+				$ban = Ban::getById($objectId, $database);
239
+
240
+				return 'Ban #' . $objectId . " (" . htmlentities($ban->getTarget()) . ")</a>";
241
+			case 'EmailTemplate':
242
+				/** @var EmailTemplate $emailTemplate */
243
+				$emailTemplate = EmailTemplate::getById($objectId, $database);
244
+				$name = htmlentities($emailTemplate->getName(), ENT_COMPAT, 'UTF-8');
245
+
246
+				return <<<HTML
247 247
 <a href="{$baseurl}/internal.php/emailManagement/view?id={$objectId}">Email Template #{$objectId} ({$name})</a>
248 248
 HTML;
249
-            case 'SiteNotice':
250
-                return "<a href=\"{$baseurl}/internal.php/siteNotice\">the site notice</a>";
251
-            case 'Request':
252
-                /** @var Request $request */
253
-                $request = Request::getById($objectId, $database);
254
-                $name = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
255
-
256
-                return <<<HTML
249
+			case 'SiteNotice':
250
+				return "<a href=\"{$baseurl}/internal.php/siteNotice\">the site notice</a>";
251
+			case 'Request':
252
+				/** @var Request $request */
253
+				$request = Request::getById($objectId, $database);
254
+				$name = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
255
+
256
+				return <<<HTML
257 257
 <a href="{$baseurl}/internal.php/viewRequest?id={$objectId}">Request #{$objectId} ({$name})</a>
258 258
 HTML;
259
-            case 'User':
260
-                /** @var User $user */
261
-                $user = User::getById($objectId, $database);
262
-                $username = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8');
263
-
264
-                return "<a href=\"{$baseurl}/internal.php/statistics/users/detail?user={$objectId}\">{$username}</a>";
265
-            case 'WelcomeTemplate':
266
-                /** @var WelcomeTemplate $welcomeTemplate */
267
-                $welcomeTemplate = WelcomeTemplate::getById($objectId, $database);
268
-
269
-                // some old templates have been completely deleted and lost to the depths of time.
270
-                if ($welcomeTemplate === false) {
271
-                    return "Welcome template #{$objectId}";
272
-                }
273
-                else {
274
-                    $userCode = htmlentities($welcomeTemplate->getUserCode(), ENT_COMPAT, 'UTF-8');
275
-
276
-                    return "<a href=\"{$baseurl}/internal.php/welcomeTemplates/view?template={$objectId}\">{$userCode}</a>";
277
-                }
278
-            default:
279
-                return '[' . $objectType . " " . $objectId . ']';
280
-        }
281
-    }
282
-
283
-    /**
284
-     * @param    Log[]          $logs
285
-     * @param     PdoDatabase   $database
286
-     * @param SiteConfiguration $configuration
287
-     *
288
-     * @return array
289
-     * @throws Exception
290
-     */
291
-    public static function prepareLogsForTemplate($logs, PdoDatabase $database, SiteConfiguration $configuration)
292
-    {
293
-        $userIds = array();
294
-
295
-        /** @var Log $logEntry */
296
-        foreach ($logs as $logEntry) {
297
-            if (!$logEntry instanceof Log) {
298
-                // if this happens, we've done something wrong with passing back the log data.
299
-                throw new Exception('Log entry is not an instance of a Log, this should never happen.');
300
-            }
301
-
302
-            $user = $logEntry->getUser();
303
-            if ($user === -1) {
304
-                continue;
305
-            }
306
-
307
-            if (!array_search($user, $userIds)) {
308
-                $userIds[] = $user;
309
-            }
310
-        }
311
-
312
-        $users = User::getUsernames($userIds, $database);
313
-        $users[-1] = User::getCommunity()->getUsername();
314
-
315
-        $logData = array();
316
-
317
-        /** @var Log $logEntry */
318
-        foreach ($logs as $logEntry) {
319
-            $objectDescription = self::getObjectDescription($logEntry->getObjectId(), $logEntry->getObjectType(),
320
-                $database, $configuration);
321
-
322
-            if ($logEntry->getAction() === 'Renamed') {
323
-                $renameData = unserialize($logEntry->getComment());
324
-                $oldName = htmlentities($renameData['old'], ENT_COMPAT, 'UTF-8');
325
-                $newName = htmlentities($renameData['new'], ENT_COMPAT, 'UTF-8');
326
-                $comment = 'Renamed \'' . $oldName . '\' to \'' . $newName . '\'.';
327
-            }
328
-            else {
329
-                $comment = $logEntry->getComment();
330
-            }
331
-
332
-            $logData[] = array(
333
-                'timestamp'         => $logEntry->getTimestamp(),
334
-                'userid'            => $logEntry->getUser(),
335
-                'username'          => $users[$logEntry->getUser()],
336
-                'description'       => self::getLogDescription($logEntry),
337
-                'objectdescription' => $objectDescription,
338
-                'comment'           => $comment,
339
-            );
340
-        }
341
-
342
-        return array($users, $logData);
343
-    }
259
+			case 'User':
260
+				/** @var User $user */
261
+				$user = User::getById($objectId, $database);
262
+				$username = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8');
263
+
264
+				return "<a href=\"{$baseurl}/internal.php/statistics/users/detail?user={$objectId}\">{$username}</a>";
265
+			case 'WelcomeTemplate':
266
+				/** @var WelcomeTemplate $welcomeTemplate */
267
+				$welcomeTemplate = WelcomeTemplate::getById($objectId, $database);
268
+
269
+				// some old templates have been completely deleted and lost to the depths of time.
270
+				if ($welcomeTemplate === false) {
271
+					return "Welcome template #{$objectId}";
272
+				}
273
+				else {
274
+					$userCode = htmlentities($welcomeTemplate->getUserCode(), ENT_COMPAT, 'UTF-8');
275
+
276
+					return "<a href=\"{$baseurl}/internal.php/welcomeTemplates/view?template={$objectId}\">{$userCode}</a>";
277
+				}
278
+			default:
279
+				return '[' . $objectType . " " . $objectId . ']';
280
+		}
281
+	}
282
+
283
+	/**
284
+	 * @param    Log[]          $logs
285
+	 * @param     PdoDatabase   $database
286
+	 * @param SiteConfiguration $configuration
287
+	 *
288
+	 * @return array
289
+	 * @throws Exception
290
+	 */
291
+	public static function prepareLogsForTemplate($logs, PdoDatabase $database, SiteConfiguration $configuration)
292
+	{
293
+		$userIds = array();
294
+
295
+		/** @var Log $logEntry */
296
+		foreach ($logs as $logEntry) {
297
+			if (!$logEntry instanceof Log) {
298
+				// if this happens, we've done something wrong with passing back the log data.
299
+				throw new Exception('Log entry is not an instance of a Log, this should never happen.');
300
+			}
301
+
302
+			$user = $logEntry->getUser();
303
+			if ($user === -1) {
304
+				continue;
305
+			}
306
+
307
+			if (!array_search($user, $userIds)) {
308
+				$userIds[] = $user;
309
+			}
310
+		}
311
+
312
+		$users = User::getUsernames($userIds, $database);
313
+		$users[-1] = User::getCommunity()->getUsername();
314
+
315
+		$logData = array();
316
+
317
+		/** @var Log $logEntry */
318
+		foreach ($logs as $logEntry) {
319
+			$objectDescription = self::getObjectDescription($logEntry->getObjectId(), $logEntry->getObjectType(),
320
+				$database, $configuration);
321
+
322
+			if ($logEntry->getAction() === 'Renamed') {
323
+				$renameData = unserialize($logEntry->getComment());
324
+				$oldName = htmlentities($renameData['old'], ENT_COMPAT, 'UTF-8');
325
+				$newName = htmlentities($renameData['new'], ENT_COMPAT, 'UTF-8');
326
+				$comment = 'Renamed \'' . $oldName . '\' to \'' . $newName . '\'.';
327
+			}
328
+			else {
329
+				$comment = $logEntry->getComment();
330
+			}
331
+
332
+			$logData[] = array(
333
+				'timestamp'         => $logEntry->getTimestamp(),
334
+				'userid'            => $logEntry->getUser(),
335
+				'username'          => $users[$logEntry->getUser()],
336
+				'description'       => self::getLogDescription($logEntry),
337
+				'objectdescription' => $objectDescription,
338
+				'comment'           => $comment,
339
+			);
340
+		}
341
+
342
+		return array($users, $logData);
343
+	}
344 344
 }
345 345
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             $template = EmailTemplate::getById((int)$id, $entry->getDatabase());
121 121
 
122 122
             if ($template != false) {
123
-                return "closed (" . $template->getName() . ")";
123
+                return "closed (".$template->getName().")";
124 124
             }
125 125
         }
126 126
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                 /** @var Ban $ban */
238 238
                 $ban = Ban::getById($objectId, $database);
239 239
 
240
-                return 'Ban #' . $objectId . " (" . htmlentities($ban->getTarget()) . ")</a>";
240
+                return 'Ban #'.$objectId." (".htmlentities($ban->getTarget()).")</a>";
241 241
             case 'EmailTemplate':
242 242
                 /** @var EmailTemplate $emailTemplate */
243 243
                 $emailTemplate = EmailTemplate::getById($objectId, $database);
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
                     return "<a href=\"{$baseurl}/internal.php/welcomeTemplates/view?template={$objectId}\">{$userCode}</a>";
277 277
                 }
278 278
             default:
279
-                return '[' . $objectType . " " . $objectId . ']';
279
+                return '['.$objectType." ".$objectId.']';
280 280
         }
281 281
     }
282 282
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                 $renameData = unserialize($logEntry->getComment());
324 324
                 $oldName = htmlentities($renameData['old'], ENT_COMPAT, 'UTF-8');
325 325
                 $newName = htmlentities($renameData['new'], ENT_COMPAT, 'UTF-8');
326
-                $comment = 'Renamed \'' . $oldName . '\' to \'' . $newName . '\'.';
326
+                $comment = 'Renamed \''.$oldName.'\' to \''.$newName.'\'.';
327 327
             }
328 328
             else {
329 329
                 $comment = $logEntry->getComment();
Please login to merge, or discard this patch.
includes/Helpers/TypeAheadHelper.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -12,51 +12,51 @@
 block discarded – undo
12 12
 
13 13
 class TypeAheadHelper implements ITypeAheadHelper
14 14
 {
15
-    private $definedClasses = array();
16
-
17
-    /**
18
-     * @param string   $class     CSS class to apply this typeahead to.
19
-     * @param callable $generator Generator function taking no arguments to return an array of strings.
20
-     */
21
-    public function defineTypeAheadSource($class, callable $generator)
22
-    {
23
-        $dataList = '';
24
-        foreach ($generator() as $dataItem) {
25
-            $dataList .= '"' . htmlentities($dataItem) . '", ';
26
-        }
27
-        $dataList = "[" . rtrim($dataList, ", ") . "]";
28
-
29
-        $script = <<<JS
15
+	private $definedClasses = array();
16
+
17
+	/**
18
+	 * @param string   $class     CSS class to apply this typeahead to.
19
+	 * @param callable $generator Generator function taking no arguments to return an array of strings.
20
+	 */
21
+	public function defineTypeAheadSource($class, callable $generator)
22
+	{
23
+		$dataList = '';
24
+		foreach ($generator() as $dataItem) {
25
+			$dataList .= '"' . htmlentities($dataItem) . '", ';
26
+		}
27
+		$dataList = "[" . rtrim($dataList, ", ") . "]";
28
+
29
+		$script = <<<JS
30 30
 $('.{$class}').typeahead({
31 31
 	source: {$dataList}
32 32
 });
33 33
 JS;
34
-        $this->definedClasses[$class] = $script;
35
-    }
34
+		$this->definedClasses[$class] = $script;
35
+	}
36 36
 
37
-    /**
38
-     * @return string HTML fragment containing a JS block for typeaheads.
39
-     */
40
-    public function getTypeAheadScriptBlock()
41
-    {
42
-        $jsBlocks = '';
37
+	/**
38
+	 * @return string HTML fragment containing a JS block for typeaheads.
39
+	 */
40
+	public function getTypeAheadScriptBlock()
41
+	{
42
+		$jsBlocks = '';
43 43
 
44
-        if (count($this->definedClasses) === 0) {
45
-            return '';
46
-        }
44
+		if (count($this->definedClasses) === 0) {
45
+			return '';
46
+		}
47 47
 
48
-        foreach ($this->definedClasses as $class => $js) {
49
-            $jsBlocks = $js . "\r\n\r\n";
50
-        }
48
+		foreach ($this->definedClasses as $class => $js) {
49
+			$jsBlocks = $js . "\r\n\r\n";
50
+		}
51 51
 
52
-        $data = <<<HTML
52
+		$data = <<<HTML
53 53
 <script type="text/javascript">
54 54
 	{$jsBlocks}
55 55
 </script>
56 56
 HTML;
57 57
 
58
-        $this->definedClasses = array();
58
+		$this->definedClasses = array();
59 59
 
60
-        return $data;
61
-    }
60
+		return $data;
61
+	}
62 62
 }
63 63
\ 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
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
     {
23 23
         $dataList = '';
24 24
         foreach ($generator() as $dataItem) {
25
-            $dataList .= '"' . htmlentities($dataItem) . '", ';
25
+            $dataList .= '"'.htmlentities($dataItem).'", ';
26 26
         }
27
-        $dataList = "[" . rtrim($dataList, ", ") . "]";
27
+        $dataList = "[".rtrim($dataList, ", ")."]";
28 28
 
29 29
         $script = <<<JS
30 30
 $('.{$class}').typeahead({
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         }
47 47
 
48 48
         foreach ($this->definedClasses as $class => $js) {
49
-            $jsBlocks = $js . "\r\n\r\n";
49
+            $jsBlocks = $js."\r\n\r\n";
50 50
         }
51 51
 
52 52
         $data = <<<HTML
Please login to merge, or discard this patch.
includes/Helpers/DebugHelper.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -13,53 +13,53 @@
 block discarded – undo
13 13
  */
14 14
 class DebugHelper
15 15
 {
16
-    /**
17
-     * Internal mockable method wrapper for debug_backtrace.
18
-     *
19
-     * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive
20
-     * cascade until the runtime explodes.
21
-     *
22
-     * Instead, we mock this method, which allows debug_backtrace to still be called correctly.
23
-     *
24
-     * @return array
25
-     */
26
-    public function get_debug_backtrace()
27
-    {
28
-        return debug_backtrace();
29
-    }
16
+	/**
17
+	 * Internal mockable method wrapper for debug_backtrace.
18
+	 *
19
+	 * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive
20
+	 * cascade until the runtime explodes.
21
+	 *
22
+	 * Instead, we mock this method, which allows debug_backtrace to still be called correctly.
23
+	 *
24
+	 * @return array
25
+	 */
26
+	public function get_debug_backtrace()
27
+	{
28
+		return debug_backtrace();
29
+	}
30 30
 
31
-    /**
32
-     * Returns a string representation of the current backtrace for display.
33
-     *
34
-     * Note that this explicitly excludes the top two frames, which will be methods from this class.
35
-     *
36
-     * @return string
37
-     */
38
-    public function getBacktrace()
39
-    {
40
-        $backtrace = $this->get_debug_backtrace();
31
+	/**
32
+	 * Returns a string representation of the current backtrace for display.
33
+	 *
34
+	 * Note that this explicitly excludes the top two frames, which will be methods from this class.
35
+	 *
36
+	 * @return string
37
+	 */
38
+	public function getBacktrace()
39
+	{
40
+		$backtrace = $this->get_debug_backtrace();
41 41
 
42
-        $output = "";
42
+		$output = "";
43 43
 
44
-        $count = 0;
45
-        foreach ($backtrace as $line) {
46
-            if ($count <= 1) {
47
-                $count++;
48
-                continue;
49
-            }
44
+		$count = 0;
45
+		foreach ($backtrace as $line) {
46
+			if ($count <= 1) {
47
+				$count++;
48
+				continue;
49
+			}
50 50
 
51
-            $output .= "#{$count}: ";
51
+			$output .= "#{$count}: ";
52 52
 
53
-            if (isset($line['type']) && $line['type'] != "") {
54
-                $output .= $line['class'] . $line['type'];
55
-            }
53
+			if (isset($line['type']) && $line['type'] != "") {
54
+				$output .= $line['class'] . $line['type'];
55
+			}
56 56
 
57
-            $output .= $line['function'] . "(...)";
58
-            $output .= " [{$line['file']}#{$line['line']}\r\n";
57
+			$output .= $line['function'] . "(...)";
58
+			$output .= " [{$line['file']}#{$line['line']}\r\n";
59 59
 
60
-            $count++;
61
-        }
60
+			$count++;
61
+		}
62 62
 
63
-        return $output;
64
-    }
63
+		return $output;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@
 block discarded – undo
51 51
             $output .= "#{$count}: ";
52 52
 
53 53
             if (isset($line['type']) && $line['type'] != "") {
54
-                $output .= $line['class'] . $line['type'];
54
+                $output .= $line['class'].$line['type'];
55 55
             }
56 56
 
57
-            $output .= $line['function'] . "(...)";
57
+            $output .= $line['function']."(...)";
58 58
             $output .= " [{$line['file']}#{$line['line']}\r\n";
59 59
 
60 60
             $count++;
Please login to merge, or discard this patch.
includes/Helpers/BlacklistHelper.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,91 +13,91 @@
 block discarded – undo
13 13
 
14 14
 class BlacklistHelper implements IBlacklistHelper
15 15
 {
16
-    /** @var HttpHelper */
17
-    private $httpHelper;
18
-    /**
19
-     * Cache of previously requested usernames
20
-     * @var array
21
-     */
22
-    private $cache = array();
23
-    /** @var string */
24
-    private $mediawikiWebServiceEndpoint;
16
+	/** @var HttpHelper */
17
+	private $httpHelper;
18
+	/**
19
+	 * Cache of previously requested usernames
20
+	 * @var array
21
+	 */
22
+	private $cache = array();
23
+	/** @var string */
24
+	private $mediawikiWebServiceEndpoint;
25 25
 
26
-    /**
27
-     * BlacklistHelper constructor.
28
-     *
29
-     * @param HttpHelper $httpHelper
30
-     * @param string     $mediawikiWebServiceEndpoint
31
-     */
32
-    public function __construct(HttpHelper $httpHelper, $mediawikiWebServiceEndpoint)
33
-    {
34
-        $this->httpHelper = $httpHelper;
35
-        $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
36
-    }
26
+	/**
27
+	 * BlacklistHelper constructor.
28
+	 *
29
+	 * @param HttpHelper $httpHelper
30
+	 * @param string     $mediawikiWebServiceEndpoint
31
+	 */
32
+	public function __construct(HttpHelper $httpHelper, $mediawikiWebServiceEndpoint)
33
+	{
34
+		$this->httpHelper = $httpHelper;
35
+		$this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
36
+	}
37 37
 
38
-    /**
39
-     * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
40
-     *
41
-     * @param string $username
42
-     *
43
-     * @return false|string False if the username is not blacklisted, else the blacklist entry.
44
-     */
45
-    public function isBlacklisted($username)
46
-    {
47
-        if (isset($this->cache[$username])) {
48
-            $result = $this->cache[$username];
49
-            if ($result === false) {
50
-                return false;
51
-            }
38
+	/**
39
+	 * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
40
+	 *
41
+	 * @param string $username
42
+	 *
43
+	 * @return false|string False if the username is not blacklisted, else the blacklist entry.
44
+	 */
45
+	public function isBlacklisted($username)
46
+	{
47
+		if (isset($this->cache[$username])) {
48
+			$result = $this->cache[$username];
49
+			if ($result === false) {
50
+				return false;
51
+			}
52 52
 
53
-            return $result['line'];
54
-        }
53
+			return $result['line'];
54
+		}
55 55
 
56
-        try {
57
-            $result = $this->performWikiLookup($username);
58
-        }
59
-        catch (CurlException $ex) {
60
-            // LOGME log this, but fail gracefully.
61
-            return false;
62
-        }
56
+		try {
57
+			$result = $this->performWikiLookup($username);
58
+		}
59
+		catch (CurlException $ex) {
60
+			// LOGME log this, but fail gracefully.
61
+			return false;
62
+		}
63 63
 
64
-        if ($result['result'] === 'ok') {
65
-            // not blacklisted
66
-            $this->cache[$username] = false;
64
+		if ($result['result'] === 'ok') {
65
+			// not blacklisted
66
+			$this->cache[$username] = false;
67 67
 
68
-            return false;
69
-        }
70
-        else {
71
-            $this->cache[$username] = $result;
68
+			return false;
69
+		}
70
+		else {
71
+			$this->cache[$username] = $result;
72 72
 
73
-            return $result['line'];
74
-        }
75
-    }
73
+			return $result['line'];
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * Performs a fetch to MediaWiki for the relevant title blacklist entry
79
-     *
80
-     * @param string $username The username to look up
81
-     *
82
-     * @return array
83
-     * @throws CurlException
84
-     */
85
-    private function performWikiLookup($username)
86
-    {
87
-        $endpoint = $this->mediawikiWebServiceEndpoint;
77
+	/**
78
+	 * Performs a fetch to MediaWiki for the relevant title blacklist entry
79
+	 *
80
+	 * @param string $username The username to look up
81
+	 *
82
+	 * @return array
83
+	 * @throws CurlException
84
+	 */
85
+	private function performWikiLookup($username)
86
+	{
87
+		$endpoint = $this->mediawikiWebServiceEndpoint;
88 88
 
89
-        $parameters = array(
90
-            'action'       => 'titleblacklist',
91
-            'format'       => 'php',
92
-            'tbtitle'      => $username,
93
-            'tbaction'     => 'new-account',
94
-            'tbnooverride' => true,
95
-        );
89
+		$parameters = array(
90
+			'action'       => 'titleblacklist',
91
+			'format'       => 'php',
92
+			'tbtitle'      => $username,
93
+			'tbaction'     => 'new-account',
94
+			'tbnooverride' => true,
95
+		);
96 96
 
97
-        $apiResult = $this->httpHelper->get($endpoint, $parameters);
97
+		$apiResult = $this->httpHelper->get($endpoint, $parameters);
98 98
 
99
-        $data = unserialize($apiResult);
99
+		$data = unserialize($apiResult);
100 100
 
101
-        return $data['titleblacklist'];
102
-    }
101
+		return $data['titleblacklist'];
102
+	}
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.