Completed
Pull Request — newinternal (#285)
by Simon
07:17 queued 04:17
created
includes/Helpers/OAuthHelper.php 1 patch
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.
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 1 patch
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.
includes/Helpers/TypeAheadHelper.php 1 patch
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.
includes/Helpers/DebugHelper.php 1 patch
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.
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.
includes/Helpers/FakeBlacklistHelper.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -12,16 +12,16 @@
 block discarded – undo
12 12
 
13 13
 class FakeBlacklistHelper implements IBlacklistHelper
14 14
 {
15
-    /**
16
-     * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
17
-     *
18
-     * @param string $username
19
-     *
20
-     * @return bool
21
-     */
22
-    public function isBlacklisted($username)
23
-    {
24
-        // Short-circuit
25
-        return false;
26
-    }
15
+	/**
16
+	 * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
17
+	 *
18
+	 * @param string $username
19
+	 *
20
+	 * @return bool
21
+	 */
22
+	public function isBlacklisted($username)
23
+	{
24
+		// Short-circuit
25
+		return false;
26
+	}
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/EmailHelper.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@
 block discarded – undo
12 12
 
13 13
 class EmailHelper implements IEmailHelper
14 14
 {
15
-    /**
16
-     * @param string $to
17
-     * @param string $subject
18
-     * @param string $content
19
-     * @param array  $headers Extra headers to include
20
-     */
21
-    public function sendMail($to, $subject, $content, $headers = array())
22
-    {
23
-        $headers['From'] = '[email protected]';
24
-        $headerString = '';
15
+	/**
16
+	 * @param string $to
17
+	 * @param string $subject
18
+	 * @param string $content
19
+	 * @param array  $headers Extra headers to include
20
+	 */
21
+	public function sendMail($to, $subject, $content, $headers = array())
22
+	{
23
+		$headers['From'] = '[email protected]';
24
+		$headerString = '';
25 25
 
26
-        foreach ($headers as $header => $headerValue) {
27
-            $headerString .= $header . ': ' . $headerValue . "\r\n";
28
-        }
26
+		foreach ($headers as $header => $headerValue) {
27
+			$headerString .= $header . ': ' . $headerValue . "\r\n";
28
+		}
29 29
 
30
-        mail($to, $subject, $content, $headerString);
31
-    }
30
+		mail($to, $subject, $content, $headerString);
31
+	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IBanHelper.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -12,30 +12,30 @@
 block discarded – undo
12 12
 
13 13
 interface IBanHelper
14 14
 {
15
-    /**
16
-     * Summary of nameIsBanned
17
-     *
18
-     * @param string $name The name to test if is banned.
19
-     *
20
-     * @return Ban
21
-     */
22
-    public function nameIsBanned($name);
15
+	/**
16
+	 * Summary of nameIsBanned
17
+	 *
18
+	 * @param string $name The name to test if is banned.
19
+	 *
20
+	 * @return Ban
21
+	 */
22
+	public function nameIsBanned($name);
23 23
 
24
-    /**
25
-     * Summary of emailIsBanned
26
-     *
27
-     * @param string $email
28
-     *
29
-     * @return Ban
30
-     */
31
-    public function emailIsBanned($email);
24
+	/**
25
+	 * Summary of emailIsBanned
26
+	 *
27
+	 * @param string $email
28
+	 *
29
+	 * @return Ban
30
+	 */
31
+	public function emailIsBanned($email);
32 32
 
33
-    /**
34
-     * Summary of ipIsBanned
35
-     *
36
-     * @param string $ip
37
-     *
38
-     * @return Ban
39
-     */
40
-    public function ipIsBanned($ip);
33
+	/**
34
+	 * Summary of ipIsBanned
35
+	 *
36
+	 * @param string $ip
37
+	 *
38
+	 * @return Ban
39
+	 */
40
+	public function ipIsBanned($ip);
41 41
 }
Please login to merge, or discard this patch.