Passed
Push — newinternal-releasecandidate ( fe35c3...e02730 )
by Simon
09:46
created
includes/Fragments/RequestData.php 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -24,324 +24,324 @@
 block discarded – undo
24 24
 
25 25
 trait RequestData
26 26
 {
27
-    /**
28
-     * @var array Array of IP address classed as 'private' by RFC1918.
29
-     */
30
-    protected static $rfc1918ips = array(
31
-        "10.0.0.0"    => "10.255.255.255",
32
-        "172.16.0.0"  => "172.31.255.255",
33
-        "192.168.0.0" => "192.168.255.255",
34
-        "169.254.0.0" => "169.254.255.255",
35
-        "127.0.0.0"   => "127.255.255.255",
36
-    );
37
-
38
-    /**
39
-     * Gets a request object
40
-     *
41
-     * @param PdoDatabase $database  The database connection
42
-     * @param int         $requestId The ID of the request to retrieve
43
-     *
44
-     * @return Request
45
-     * @throws ApplicationLogicException
46
-     */
47
-    protected function getRequest(PdoDatabase $database, $requestId)
48
-    {
49
-        if ($requestId === null) {
50
-            throw new ApplicationLogicException("No request specified");
51
-        }
52
-
53
-        $request = Request::getById($requestId, $database);
54
-        if ($request === false || !is_a($request, Request::class)) {
55
-            throw new ApplicationLogicException('Could not load the requested request!');
56
-        }
57
-
58
-        return $request;
59
-    }
60
-
61
-    /**
62
-     * Returns a value stating whether the user is allowed to see private data or not
63
-     *
64
-     * @param Request $request
65
-     * @param User    $currentUser
66
-     *
67
-     * @return bool
68
-     * @category Security-Critical
69
-     */
70
-    protected function isAllowedPrivateData(Request $request, User $currentUser)
71
-    {
72
-        // Test the main security barrier for private data access using SecurityManager
73
-        if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) {
74
-            // Tool admins/check-users can always see private data
75
-            return true;
76
-        }
77
-
78
-        // reserving user is allowed to see the data
79
-        if ($currentUser->getId() === $request->getReserved()
80
-            && $request->getReserved() !== null
81
-            && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData')
82
-        ) {
83
-            return true;
84
-        }
85
-
86
-        // user has the reveal hash
87
-        if (WebRequest::getString('hash') === $request->getRevealHash()
88
-            && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData')
89
-        ) {
90
-            return true;
91
-        }
92
-
93
-        // nope. Not allowed.
94
-        return false;
95
-    }
96
-
97
-    /**
98
-     * Tests the security barrier for a specified action.
99
-     *
100
-     * Don't use within templates
101
-     *
102
-     * @param string      $action
103
-     *
104
-     * @param User        $user
105
-     * @param null|string $pageName
106
-     *
107
-     * @return bool
108
-     * @category Security-Critical
109
-     */
110
-    abstract protected function barrierTest($action, User $user, $pageName = null);
111
-
112
-    /**
113
-     * Gets the name of the route that has been passed from the request router.
114
-     * @return string
115
-     */
116
-    abstract protected function getRouteName();
117
-
118
-    /** @return SecurityManager */
119
-    abstract protected function getSecurityManager();
120
-
121
-    /**
122
-     * Sets the name of the template this page should display.
123
-     *
124
-     * @param string $name
125
-     */
126
-    abstract protected function setTemplate($name);
127
-
128
-    /** @return IXffTrustProvider */
129
-    abstract protected function getXffTrustProvider();
130
-
131
-    /** @return ILocationProvider */
132
-    abstract protected function getLocationProvider();
133
-
134
-    /** @return IRDnsProvider */
135
-    abstract protected function getRdnsProvider();
136
-
137
-    /**
138
-     * Assigns a Smarty variable
139
-     *
140
-     * @param  array|string $name  the template variable name(s)
141
-     * @param  mixed        $value the value to assign
142
-     */
143
-    abstract protected function assign($name, $value);
144
-
145
-    /**
146
-     * @param int         $requestReservationId
147
-     * @param PdoDatabase $database
148
-     * @param User        $currentUser
149
-     */
150
-    protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)
151
-    {
152
-        $requestIsReserved = $requestReservationId !== null;
153
-        $this->assign('requestIsReserved', $requestIsReserved);
154
-        $this->assign('requestIsReservedByMe', false);
155
-
156
-        if ($requestIsReserved) {
157
-            $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername());
158
-            $this->assign('requestReservedById', $requestReservationId);
159
-
160
-            if ($requestReservationId === $currentUser->getId()) {
161
-                $this->assign('requestIsReservedByMe', true);
162
-            }
163
-        }
164
-
165
-        $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
166
-    }
167
-
168
-    /**
169
-     * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
170
-     *
171
-     * @param Request           $request
172
-     * @param User              $currentUser
173
-     * @param SiteConfiguration $configuration
174
-     *
175
-     * @param PdoDatabase       $database
176
-     */
177
-    protected function setupPrivateData(
178
-        $request,
179
-        User $currentUser,
180
-        SiteConfiguration $configuration,
181
-        PdoDatabase $database
182
-    ) {
183
-        $xffProvider = $this->getXffTrustProvider();
184
-
185
-        $relatedEmailRequests = RequestSearchHelper::get($database)
186
-            ->byEmailAddress($request->getEmail())
187
-            ->withConfirmedEmail()
188
-            ->excludingPurgedData($configuration)
189
-            ->excludingRequest($request->getId())
190
-            ->fetch();
191
-
192
-        $this->assign('requestEmail', $request->getEmail());
193
-        $emailDomain = explode("@", $request->getEmail())[1];
194
-        $this->assign("emailurl", $emailDomain);
195
-        $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests));
196
-        $this->assign('requestRelatedEmailRequests', $relatedEmailRequests);
197
-
198
-        $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
199
-        $this->assign('requestTrustedIp', $trustedIp);
200
-        $this->assign('requestRealIp', $request->getIp());
201
-        $this->assign('requestForwardedIp', $request->getForwardedIp());
202
-
203
-        $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);
204
-        $this->assign('requestTrustedIpLocation', $trustedIpLocation);
205
-
206
-        $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null);
207
-
208
-        $relatedIpRequests = RequestSearchHelper::get($database)
209
-            ->byIp($trustedIp)
210
-            ->withConfirmedEmail()
211
-            ->excludingPurgedData($configuration)
212
-            ->excludingRequest($request->getId())
213
-            ->fetch();
214
-
215
-        $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests));
216
-        $this->assign('requestRelatedIpRequests', $relatedIpRequests);
217
-
218
-        $this->assign('showRevealLink', false);
219
-        if ($request->getReserved() === $currentUser->getId() ||
220
-            $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
221
-        ) {
222
-            $this->assign('showRevealLink', true);
223
-            $this->assign('revealHash', $request->getRevealHash());
224
-        }
225
-
226
-        $this->setupForwardedIpData($request);
227
-    }
228
-
229
-    /**
230
-     * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
231
-     *
232
-     * @param Request $request
233
-     */
234
-    protected function setupCheckUserData(Request $request)
235
-    {
236
-        $this->assign('requestUserAgent', $request->getUserAgent());
237
-    }
238
-
239
-    /**
240
-     * Sets up the basic data for this request, and adds it to Smarty
241
-     *
242
-     * @param Request           $request
243
-     * @param SiteConfiguration $config
244
-     */
245
-    protected function setupBasicData(Request $request, SiteConfiguration $config)
246
-    {
247
-        $this->assign('requestId', $request->getId());
248
-        $this->assign('updateVersion', $request->getUpdateVersion());
249
-        $this->assign('requestName', $request->getName());
250
-        $this->assign('requestDate', $request->getDate());
251
-        $this->assign('requestStatus', $request->getStatus());
252
-
253
-        $isClosed = !array_key_exists($request->getStatus(), $config->getRequestStates())
254
-            && $request->getStatus() !== RequestStatus::HOSPITAL;
255
-        $this->assign('requestIsClosed', $isClosed);
256
-    }
257
-
258
-    /**
259
-     * Sets up the forwarded IP data for this request and adds it to Smarty
260
-     *
261
-     * @param Request $request
262
-     */
263
-    protected function setupForwardedIpData(Request $request)
264
-    {
265
-        if ($request->getForwardedIp() !== null) {
266
-            $requestProxyData = array(); // Initialize array to store data to be output in Smarty template.
267
-            $proxyIndex = 0;
268
-
269
-            // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],
270
-            // [proxy1], [proxy2], and our actual IP will be [proxy3]
271
-            $proxies = explode(",", $request->getForwardedIp());
272
-            $proxies[] = $request->getIp();
273
-
274
-            // Origin is the supposed "client" IP.
275
-            $origin = $proxies[0];
276
-            $this->assign("forwardedOrigin", $origin);
277
-
278
-            // We step through the servers in reverse order, from closest to furthest
279
-            $proxies = array_reverse($proxies);
280
-
281
-            // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.
282
-            $trust = true;
283
-
284
-            /**
285
-             * @var int    $index     The zero-based index of the proxy.
286
-             * @var string $proxyData The proxy IP address (although possibly not!)
287
-             */
288
-            foreach ($proxies as $index => $proxyData) {
289
-                $proxyAddress = trim($proxyData);
290
-                $requestProxyData[$proxyIndex]['ip'] = $proxyAddress;
291
-
292
-                // get data on this IP.
293
-                $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);
294
-
295
-                $proxyIsInPrivateRange = $this->getXffTrustProvider()
296
-                    ->ipInRange(self::$rfc1918ips, $proxyAddress);
297
-
298
-                if (!$proxyIsInPrivateRange) {
299
-                    $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);
300
-                    $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);
301
-                }
302
-                else {
303
-                    // this is going to fail, so why bother trying?
304
-                    $proxyReverseDns = false;
305
-                    $proxyLocation = false;
306
-                }
307
-
308
-                // current trust chain status BEFORE this link
309
-                $preLinkTrust = $trust;
310
-
311
-                // is *this* link trusted? Note, this will be true even if there is an untrusted link before this!
312
-                $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;
313
-
314
-                // set the trust status of the chain to this point
315
-                $trust = $trust & $thisProxyIsTrusted;
316
-
317
-                // If this is the origin address, and the chain was trusted before this point, then we can trust
318
-                // the origin.
319
-                if ($preLinkTrust && $proxyAddress == $origin) {
320
-                    // if this is the origin, then we are at the last point in the chain.
321
-                    // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check
322
-                    // to see if this is *really* the last in the chain, rather than just the same IP as it.
323
-                    $trust = true;
324
-                }
325
-
326
-                $requestProxyData[$proxyIndex]['trust'] = $trust;
327
-
328
-                $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;
329
-                $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;
330
-                $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;
331
-
332
-                $requestProxyData[$proxyIndex]['location'] = $proxyLocation;
333
-
334
-                if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) {
335
-                    $requestProxyData[$proxyIndex]['rdns'] = null;
336
-                }
337
-
338
-                $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;
339
-                $requestProxyData[$proxyIndex]['showlinks'] = $showLinks;
340
-
341
-                $proxyIndex++;
342
-            }
343
-
344
-            $this->assign("requestProxyData", $requestProxyData);
345
-        }
346
-    }
27
+	/**
28
+	 * @var array Array of IP address classed as 'private' by RFC1918.
29
+	 */
30
+	protected static $rfc1918ips = array(
31
+		"10.0.0.0"    => "10.255.255.255",
32
+		"172.16.0.0"  => "172.31.255.255",
33
+		"192.168.0.0" => "192.168.255.255",
34
+		"169.254.0.0" => "169.254.255.255",
35
+		"127.0.0.0"   => "127.255.255.255",
36
+	);
37
+
38
+	/**
39
+	 * Gets a request object
40
+	 *
41
+	 * @param PdoDatabase $database  The database connection
42
+	 * @param int         $requestId The ID of the request to retrieve
43
+	 *
44
+	 * @return Request
45
+	 * @throws ApplicationLogicException
46
+	 */
47
+	protected function getRequest(PdoDatabase $database, $requestId)
48
+	{
49
+		if ($requestId === null) {
50
+			throw new ApplicationLogicException("No request specified");
51
+		}
52
+
53
+		$request = Request::getById($requestId, $database);
54
+		if ($request === false || !is_a($request, Request::class)) {
55
+			throw new ApplicationLogicException('Could not load the requested request!');
56
+		}
57
+
58
+		return $request;
59
+	}
60
+
61
+	/**
62
+	 * Returns a value stating whether the user is allowed to see private data or not
63
+	 *
64
+	 * @param Request $request
65
+	 * @param User    $currentUser
66
+	 *
67
+	 * @return bool
68
+	 * @category Security-Critical
69
+	 */
70
+	protected function isAllowedPrivateData(Request $request, User $currentUser)
71
+	{
72
+		// Test the main security barrier for private data access using SecurityManager
73
+		if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) {
74
+			// Tool admins/check-users can always see private data
75
+			return true;
76
+		}
77
+
78
+		// reserving user is allowed to see the data
79
+		if ($currentUser->getId() === $request->getReserved()
80
+			&& $request->getReserved() !== null
81
+			&& $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData')
82
+		) {
83
+			return true;
84
+		}
85
+
86
+		// user has the reveal hash
87
+		if (WebRequest::getString('hash') === $request->getRevealHash()
88
+			&& $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData')
89
+		) {
90
+			return true;
91
+		}
92
+
93
+		// nope. Not allowed.
94
+		return false;
95
+	}
96
+
97
+	/**
98
+	 * Tests the security barrier for a specified action.
99
+	 *
100
+	 * Don't use within templates
101
+	 *
102
+	 * @param string      $action
103
+	 *
104
+	 * @param User        $user
105
+	 * @param null|string $pageName
106
+	 *
107
+	 * @return bool
108
+	 * @category Security-Critical
109
+	 */
110
+	abstract protected function barrierTest($action, User $user, $pageName = null);
111
+
112
+	/**
113
+	 * Gets the name of the route that has been passed from the request router.
114
+	 * @return string
115
+	 */
116
+	abstract protected function getRouteName();
117
+
118
+	/** @return SecurityManager */
119
+	abstract protected function getSecurityManager();
120
+
121
+	/**
122
+	 * Sets the name of the template this page should display.
123
+	 *
124
+	 * @param string $name
125
+	 */
126
+	abstract protected function setTemplate($name);
127
+
128
+	/** @return IXffTrustProvider */
129
+	abstract protected function getXffTrustProvider();
130
+
131
+	/** @return ILocationProvider */
132
+	abstract protected function getLocationProvider();
133
+
134
+	/** @return IRDnsProvider */
135
+	abstract protected function getRdnsProvider();
136
+
137
+	/**
138
+	 * Assigns a Smarty variable
139
+	 *
140
+	 * @param  array|string $name  the template variable name(s)
141
+	 * @param  mixed        $value the value to assign
142
+	 */
143
+	abstract protected function assign($name, $value);
144
+
145
+	/**
146
+	 * @param int         $requestReservationId
147
+	 * @param PdoDatabase $database
148
+	 * @param User        $currentUser
149
+	 */
150
+	protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)
151
+	{
152
+		$requestIsReserved = $requestReservationId !== null;
153
+		$this->assign('requestIsReserved', $requestIsReserved);
154
+		$this->assign('requestIsReservedByMe', false);
155
+
156
+		if ($requestIsReserved) {
157
+			$this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername());
158
+			$this->assign('requestReservedById', $requestReservationId);
159
+
160
+			if ($requestReservationId === $currentUser->getId()) {
161
+				$this->assign('requestIsReservedByMe', true);
162
+			}
163
+		}
164
+
165
+		$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
166
+	}
167
+
168
+	/**
169
+	 * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
170
+	 *
171
+	 * @param Request           $request
172
+	 * @param User              $currentUser
173
+	 * @param SiteConfiguration $configuration
174
+	 *
175
+	 * @param PdoDatabase       $database
176
+	 */
177
+	protected function setupPrivateData(
178
+		$request,
179
+		User $currentUser,
180
+		SiteConfiguration $configuration,
181
+		PdoDatabase $database
182
+	) {
183
+		$xffProvider = $this->getXffTrustProvider();
184
+
185
+		$relatedEmailRequests = RequestSearchHelper::get($database)
186
+			->byEmailAddress($request->getEmail())
187
+			->withConfirmedEmail()
188
+			->excludingPurgedData($configuration)
189
+			->excludingRequest($request->getId())
190
+			->fetch();
191
+
192
+		$this->assign('requestEmail', $request->getEmail());
193
+		$emailDomain = explode("@", $request->getEmail())[1];
194
+		$this->assign("emailurl", $emailDomain);
195
+		$this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests));
196
+		$this->assign('requestRelatedEmailRequests', $relatedEmailRequests);
197
+
198
+		$trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
199
+		$this->assign('requestTrustedIp', $trustedIp);
200
+		$this->assign('requestRealIp', $request->getIp());
201
+		$this->assign('requestForwardedIp', $request->getForwardedIp());
202
+
203
+		$trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);
204
+		$this->assign('requestTrustedIpLocation', $trustedIpLocation);
205
+
206
+		$this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null);
207
+
208
+		$relatedIpRequests = RequestSearchHelper::get($database)
209
+			->byIp($trustedIp)
210
+			->withConfirmedEmail()
211
+			->excludingPurgedData($configuration)
212
+			->excludingRequest($request->getId())
213
+			->fetch();
214
+
215
+		$this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests));
216
+		$this->assign('requestRelatedIpRequests', $relatedIpRequests);
217
+
218
+		$this->assign('showRevealLink', false);
219
+		if ($request->getReserved() === $currentUser->getId() ||
220
+			$this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData')
221
+		) {
222
+			$this->assign('showRevealLink', true);
223
+			$this->assign('revealHash', $request->getRevealHash());
224
+		}
225
+
226
+		$this->setupForwardedIpData($request);
227
+	}
228
+
229
+	/**
230
+	 * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
231
+	 *
232
+	 * @param Request $request
233
+	 */
234
+	protected function setupCheckUserData(Request $request)
235
+	{
236
+		$this->assign('requestUserAgent', $request->getUserAgent());
237
+	}
238
+
239
+	/**
240
+	 * Sets up the basic data for this request, and adds it to Smarty
241
+	 *
242
+	 * @param Request           $request
243
+	 * @param SiteConfiguration $config
244
+	 */
245
+	protected function setupBasicData(Request $request, SiteConfiguration $config)
246
+	{
247
+		$this->assign('requestId', $request->getId());
248
+		$this->assign('updateVersion', $request->getUpdateVersion());
249
+		$this->assign('requestName', $request->getName());
250
+		$this->assign('requestDate', $request->getDate());
251
+		$this->assign('requestStatus', $request->getStatus());
252
+
253
+		$isClosed = !array_key_exists($request->getStatus(), $config->getRequestStates())
254
+			&& $request->getStatus() !== RequestStatus::HOSPITAL;
255
+		$this->assign('requestIsClosed', $isClosed);
256
+	}
257
+
258
+	/**
259
+	 * Sets up the forwarded IP data for this request and adds it to Smarty
260
+	 *
261
+	 * @param Request $request
262
+	 */
263
+	protected function setupForwardedIpData(Request $request)
264
+	{
265
+		if ($request->getForwardedIp() !== null) {
266
+			$requestProxyData = array(); // Initialize array to store data to be output in Smarty template.
267
+			$proxyIndex = 0;
268
+
269
+			// Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],
270
+			// [proxy1], [proxy2], and our actual IP will be [proxy3]
271
+			$proxies = explode(",", $request->getForwardedIp());
272
+			$proxies[] = $request->getIp();
273
+
274
+			// Origin is the supposed "client" IP.
275
+			$origin = $proxies[0];
276
+			$this->assign("forwardedOrigin", $origin);
277
+
278
+			// We step through the servers in reverse order, from closest to furthest
279
+			$proxies = array_reverse($proxies);
280
+
281
+			// By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.
282
+			$trust = true;
283
+
284
+			/**
285
+			 * @var int    $index     The zero-based index of the proxy.
286
+			 * @var string $proxyData The proxy IP address (although possibly not!)
287
+			 */
288
+			foreach ($proxies as $index => $proxyData) {
289
+				$proxyAddress = trim($proxyData);
290
+				$requestProxyData[$proxyIndex]['ip'] = $proxyAddress;
291
+
292
+				// get data on this IP.
293
+				$thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);
294
+
295
+				$proxyIsInPrivateRange = $this->getXffTrustProvider()
296
+					->ipInRange(self::$rfc1918ips, $proxyAddress);
297
+
298
+				if (!$proxyIsInPrivateRange) {
299
+					$proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);
300
+					$proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);
301
+				}
302
+				else {
303
+					// this is going to fail, so why bother trying?
304
+					$proxyReverseDns = false;
305
+					$proxyLocation = false;
306
+				}
307
+
308
+				// current trust chain status BEFORE this link
309
+				$preLinkTrust = $trust;
310
+
311
+				// is *this* link trusted? Note, this will be true even if there is an untrusted link before this!
312
+				$requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;
313
+
314
+				// set the trust status of the chain to this point
315
+				$trust = $trust & $thisProxyIsTrusted;
316
+
317
+				// If this is the origin address, and the chain was trusted before this point, then we can trust
318
+				// the origin.
319
+				if ($preLinkTrust && $proxyAddress == $origin) {
320
+					// if this is the origin, then we are at the last point in the chain.
321
+					// @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check
322
+					// to see if this is *really* the last in the chain, rather than just the same IP as it.
323
+					$trust = true;
324
+				}
325
+
326
+				$requestProxyData[$proxyIndex]['trust'] = $trust;
327
+
328
+				$requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;
329
+				$requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;
330
+				$requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;
331
+
332
+				$requestProxyData[$proxyIndex]['location'] = $proxyLocation;
333
+
334
+				if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) {
335
+					$requestProxyData[$proxyIndex]['rdns'] = null;
336
+				}
337
+
338
+				$showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;
339
+				$requestProxyData[$proxyIndex]['showlinks'] = $showLinks;
340
+
341
+				$proxyIndex++;
342
+			}
343
+
344
+			$this->assign("requestProxyData", $requestProxyData);
345
+		}
346
+	}
347 347
 }
Please login to merge, or discard this patch.
includes/Router/OAuthRequestRouter.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
17 17
  */
18 18
 class OAuthRequestRouter extends RequestRouter
19 19
 {
20
-    protected function getRouteFromPath($pathInfo)
21
-    {
22
-        // Hardcode the route for this entry point
23
-        return array(PageOAuthCallback::class, 'authorise');
24
-    }
20
+	protected function getRouteFromPath($pathInfo)
21
+	{
22
+		// Hardcode the route for this entry point
23
+		return array(PageOAuthCallback::class, 'authorise');
24
+	}
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Tasks/PagedInternalPageBase.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
         $formParameters['limit'] = $this->limit;
103 103
         $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&amp;'));
104 104
 
105
-        foreach ($formParameters as $key => $value)  {
105
+        foreach ($formParameters as $key => $value) {
106 106
             $this->assign($key, $value);
107 107
         }
108 108
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
         $formParameters['limit'] = $this->limit;
103 103
         $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&amp;'));
104 104
 
105
-        foreach ($formParameters as $key => $value)  {
105
+        foreach ($formParameters as $key => $value) {
106 106
             $this->assign($key, $value);
107 107
         }
108 108
     }
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -13,97 +13,97 @@
 block discarded – undo
13 13
 
14 14
 abstract class PagedInternalPageBase extends InternalPageBase
15 15
 {
16
-    /** @var SearchHelperBase */
17
-    private $searchHelper;
18
-    private $page;
19
-    private $limit;
20
-
21
-    /**
22
-     * Sets up the pager with the current page, current limit, and total number of records.
23
-     *
24
-     * @param int   $count
25
-     * @param array $formParameters
26
-     */
27
-    protected function setupPageData($count, $formParameters)
28
-    {
29
-        $page = $this->page;
30
-        $limit = $this->limit;
31
-
32
-        // The number of pages on the pager to show. Must be odd
33
-        $pageLimit = 9;
34
-
35
-        $pageData = array(
36
-            // Can the user go to the previous page?
37
-            'canprev'   => $page != 1,
38
-            // Can the user go to the next page?
39
-            'cannext'   => ($page * $limit) < $count,
40
-            // Maximum page number
41
-            'maxpage'   => max(1, ceil($count / $limit)),
42
-            // Limit to the number of pages to display
43
-            'pagelimit' => $pageLimit,
44
-        );
45
-
46
-        // number of pages either side of the current to show
47
-        $pageMargin = (($pageLimit - 1) / 2);
48
-
49
-        // Calculate the number of pages either side to show - this is for situations like:
50
-        //  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
51
-        $pageData['lowpage'] = max(1, $page - $pageMargin);
52
-        $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
53
-        $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
54
-
55
-        if ($pageCount < $pageLimit) {
56
-            if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
57
-                $pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
58
-            }
59
-            elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
60
-                $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
61
-            }
62
-        }
63
-
64
-        // Put the range of pages into the page data
65
-        $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
66
-
67
-        $this->assign("pagedata", $pageData);
68
-
69
-        $this->assign("limit", $limit);
70
-        $this->assign("page", $page);
71
-
72
-        $this->setupFormParameters($formParameters);
73
-    }
74
-
75
-    protected function setSearchHelper(SearchHelperBase $searchHelper)
76
-    {
77
-        $this->searchHelper = $searchHelper;
78
-    }
79
-
80
-    protected function setupLimits()
81
-    {
82
-        $limit = WebRequest::getInt('limit');
83
-        if ($limit === null) {
84
-            $limit = 100;
85
-        }
86
-
87
-        $page = WebRequest::getInt('page');
88
-        if ($page === null) {
89
-            $page = 1;
90
-        }
91
-
92
-        $offset = ($page - 1) * $limit;
93
-
94
-        $this->searchHelper->limit($limit, $offset);
95
-
96
-        $this->page = $page;
97
-        $this->limit = $limit;
98
-    }
99
-
100
-    private function setupFormParameters($formParameters)
101
-    {
102
-        $formParameters['limit'] = $this->limit;
103
-        $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&amp;'));
104
-
105
-        foreach ($formParameters as $key => $value)  {
106
-            $this->assign($key, $value);
107
-        }
108
-    }
16
+	/** @var SearchHelperBase */
17
+	private $searchHelper;
18
+	private $page;
19
+	private $limit;
20
+
21
+	/**
22
+	 * Sets up the pager with the current page, current limit, and total number of records.
23
+	 *
24
+	 * @param int   $count
25
+	 * @param array $formParameters
26
+	 */
27
+	protected function setupPageData($count, $formParameters)
28
+	{
29
+		$page = $this->page;
30
+		$limit = $this->limit;
31
+
32
+		// The number of pages on the pager to show. Must be odd
33
+		$pageLimit = 9;
34
+
35
+		$pageData = array(
36
+			// Can the user go to the previous page?
37
+			'canprev'   => $page != 1,
38
+			// Can the user go to the next page?
39
+			'cannext'   => ($page * $limit) < $count,
40
+			// Maximum page number
41
+			'maxpage'   => max(1, ceil($count / $limit)),
42
+			// Limit to the number of pages to display
43
+			'pagelimit' => $pageLimit,
44
+		);
45
+
46
+		// number of pages either side of the current to show
47
+		$pageMargin = (($pageLimit - 1) / 2);
48
+
49
+		// Calculate the number of pages either side to show - this is for situations like:
50
+		//  [1]  [2] [[3]] [4]  [5]  [6]  [7]  [8]  [9] - where you can't just use the page margin calculated
51
+		$pageData['lowpage'] = max(1, $page - $pageMargin);
52
+		$pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin);
53
+		$pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1;
54
+
55
+		if ($pageCount < $pageLimit) {
56
+			if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) {
57
+				$pageData['hipage'] = min($pageLimit, $pageData['maxpage']);
58
+			}
59
+			elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) {
60
+				$pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1);
61
+			}
62
+		}
63
+
64
+		// Put the range of pages into the page data
65
+		$pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']);
66
+
67
+		$this->assign("pagedata", $pageData);
68
+
69
+		$this->assign("limit", $limit);
70
+		$this->assign("page", $page);
71
+
72
+		$this->setupFormParameters($formParameters);
73
+	}
74
+
75
+	protected function setSearchHelper(SearchHelperBase $searchHelper)
76
+	{
77
+		$this->searchHelper = $searchHelper;
78
+	}
79
+
80
+	protected function setupLimits()
81
+	{
82
+		$limit = WebRequest::getInt('limit');
83
+		if ($limit === null) {
84
+			$limit = 100;
85
+		}
86
+
87
+		$page = WebRequest::getInt('page');
88
+		if ($page === null) {
89
+			$page = 1;
90
+		}
91
+
92
+		$offset = ($page - 1) * $limit;
93
+
94
+		$this->searchHelper->limit($limit, $offset);
95
+
96
+		$this->page = $page;
97
+		$this->limit = $limit;
98
+	}
99
+
100
+	private function setupFormParameters($formParameters)
101
+	{
102
+		$formParameters['limit'] = $this->limit;
103
+		$this->assign('searchParamsUrl', http_build_query($formParameters, '', '&amp;'));
104
+
105
+		foreach ($formParameters as $key => $value)  {
106
+			$this->assign($key, $value);
107
+		}
108
+	}
109 109
 }
Please login to merge, or discard this patch.
includes/Tasks/ITask.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -23,149 +23,149 @@
 block discarded – undo
23 23
 
24 24
 interface ITask
25 25
 {
26
-    /**
27
-     * @return IEmailHelper
28
-     */
29
-    public function getEmailHelper();
30
-
31
-    /**
32
-     * @param IEmailHelper $emailHelper
33
-     *
34
-     * @return void
35
-     */
36
-    public function setEmailHelper($emailHelper);
37
-
38
-    /**
39
-     * @return HttpHelper
40
-     */
41
-    public function getHttpHelper();
42
-
43
-    /**
44
-     * @param HttpHelper $httpHelper
45
-     *
46
-     * @return void
47
-     */
48
-    public function setHttpHelper($httpHelper);
49
-
50
-    /**
51
-     * @return WikiTextHelper
52
-     */
53
-    public function getWikiTextHelper();
54
-
55
-    /**
56
-     * @param WikiTextHelper $wikiTextHelper
57
-     *
58
-     * @return void
59
-     */
60
-    public function setWikiTextHelper($wikiTextHelper);
61
-
62
-    /**
63
-     * @return ILocationProvider
64
-     */
65
-    public function getLocationProvider();
66
-
67
-    /**
68
-     * @param ILocationProvider $locationProvider
69
-     *
70
-     * @return void
71
-     */
72
-    public function setLocationProvider(ILocationProvider $locationProvider);
73
-
74
-    /**
75
-     * @return IXffTrustProvider
76
-     */
77
-    public function getXffTrustProvider();
78
-
79
-    /**
80
-     * @param IXffTrustProvider $xffTrustProvider
81
-     *
82
-     * @return void
83
-     */
84
-    public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider);
85
-
86
-    /**
87
-     * @return IRDnsProvider
88
-     */
89
-    public function getRdnsProvider();
90
-
91
-    /**
92
-     * @param IRDnsProvider $rdnsProvider
93
-     *
94
-     * @return void
95
-     */
96
-    public function setRdnsProvider($rdnsProvider);
97
-
98
-    /**
99
-     * @return IAntiSpoofProvider
100
-     */
101
-    public function getAntiSpoofProvider();
102
-
103
-    /**
104
-     * @param IAntiSpoofProvider $antiSpoofProvider
105
-     *
106
-     * @return void
107
-     */
108
-    public function setAntiSpoofProvider($antiSpoofProvider);
109
-
110
-    /**
111
-     * @return PdoDatabase
112
-     */
113
-    public function getDatabase();
114
-
115
-    /**
116
-     * @param PdoDatabase $database
117
-     *
118
-     * @return void
119
-     */
120
-    public function setDatabase($database);
121
-
122
-    /**
123
-     * @return IOAuthProtocolHelper
124
-     */
125
-    public function getOAuthProtocolHelper();
126
-
127
-    /**
128
-     * @param IOAuthProtocolHelper $oauthProtocolHelper
129
-     *
130
-     * @return void
131
-     */
132
-    public function setOAuthProtocolHelper($oauthProtocolHelper);
133
-
134
-    /**
135
-     * @return void
136
-     */
137
-    public function execute();
138
-
139
-    /**
140
-     * Sets the site configuration object for this page
141
-     *
142
-     * @param SiteConfiguration $configuration
143
-     *
144
-     * @return void
145
-     */
146
-    public function setSiteConfiguration($configuration);
147
-
148
-    /**
149
-     * @return IrcNotificationHelper
150
-     */
151
-    public function getNotificationHelper();
152
-
153
-    /**
154
-     * @param IrcNotificationHelper $notificationHelper
155
-     *
156
-     * @return void
157
-     */
158
-    public function setNotificationHelper($notificationHelper);
159
-
160
-    /**
161
-     * @return TorExitProvider
162
-     */
163
-    public function getTorExitProvider();
164
-
165
-    /**
166
-     * @param TorExitProvider $torExitProvider
167
-     *
168
-     * @return void
169
-     */
170
-    public function setTorExitProvider($torExitProvider);
26
+	/**
27
+	 * @return IEmailHelper
28
+	 */
29
+	public function getEmailHelper();
30
+
31
+	/**
32
+	 * @param IEmailHelper $emailHelper
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function setEmailHelper($emailHelper);
37
+
38
+	/**
39
+	 * @return HttpHelper
40
+	 */
41
+	public function getHttpHelper();
42
+
43
+	/**
44
+	 * @param HttpHelper $httpHelper
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function setHttpHelper($httpHelper);
49
+
50
+	/**
51
+	 * @return WikiTextHelper
52
+	 */
53
+	public function getWikiTextHelper();
54
+
55
+	/**
56
+	 * @param WikiTextHelper $wikiTextHelper
57
+	 *
58
+	 * @return void
59
+	 */
60
+	public function setWikiTextHelper($wikiTextHelper);
61
+
62
+	/**
63
+	 * @return ILocationProvider
64
+	 */
65
+	public function getLocationProvider();
66
+
67
+	/**
68
+	 * @param ILocationProvider $locationProvider
69
+	 *
70
+	 * @return void
71
+	 */
72
+	public function setLocationProvider(ILocationProvider $locationProvider);
73
+
74
+	/**
75
+	 * @return IXffTrustProvider
76
+	 */
77
+	public function getXffTrustProvider();
78
+
79
+	/**
80
+	 * @param IXffTrustProvider $xffTrustProvider
81
+	 *
82
+	 * @return void
83
+	 */
84
+	public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider);
85
+
86
+	/**
87
+	 * @return IRDnsProvider
88
+	 */
89
+	public function getRdnsProvider();
90
+
91
+	/**
92
+	 * @param IRDnsProvider $rdnsProvider
93
+	 *
94
+	 * @return void
95
+	 */
96
+	public function setRdnsProvider($rdnsProvider);
97
+
98
+	/**
99
+	 * @return IAntiSpoofProvider
100
+	 */
101
+	public function getAntiSpoofProvider();
102
+
103
+	/**
104
+	 * @param IAntiSpoofProvider $antiSpoofProvider
105
+	 *
106
+	 * @return void
107
+	 */
108
+	public function setAntiSpoofProvider($antiSpoofProvider);
109
+
110
+	/**
111
+	 * @return PdoDatabase
112
+	 */
113
+	public function getDatabase();
114
+
115
+	/**
116
+	 * @param PdoDatabase $database
117
+	 *
118
+	 * @return void
119
+	 */
120
+	public function setDatabase($database);
121
+
122
+	/**
123
+	 * @return IOAuthProtocolHelper
124
+	 */
125
+	public function getOAuthProtocolHelper();
126
+
127
+	/**
128
+	 * @param IOAuthProtocolHelper $oauthProtocolHelper
129
+	 *
130
+	 * @return void
131
+	 */
132
+	public function setOAuthProtocolHelper($oauthProtocolHelper);
133
+
134
+	/**
135
+	 * @return void
136
+	 */
137
+	public function execute();
138
+
139
+	/**
140
+	 * Sets the site configuration object for this page
141
+	 *
142
+	 * @param SiteConfiguration $configuration
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function setSiteConfiguration($configuration);
147
+
148
+	/**
149
+	 * @return IrcNotificationHelper
150
+	 */
151
+	public function getNotificationHelper();
152
+
153
+	/**
154
+	 * @param IrcNotificationHelper $notificationHelper
155
+	 *
156
+	 * @return void
157
+	 */
158
+	public function setNotificationHelper($notificationHelper);
159
+
160
+	/**
161
+	 * @return TorExitProvider
162
+	 */
163
+	public function getTorExitProvider();
164
+
165
+	/**
166
+	 * @param TorExitProvider $torExitProvider
167
+	 *
168
+	 * @return void
169
+	 */
170
+	public function setTorExitProvider($torExitProvider);
171 171
 }
172 172
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Tasks/TaskBase.php 1 patch
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -23,229 +23,229 @@
 block discarded – undo
23 23
 
24 24
 abstract class TaskBase implements ITask
25 25
 {
26
-    /** @var SiteConfiguration */
27
-    private $siteConfiguration;
28
-    /** @var IEmailHelper */
29
-    private $emailHelper;
30
-    /** @var HttpHelper */
31
-    private $httpHelper;
32
-    /** @var WikiTextHelper */
33
-    private $wikiTextHelper;
34
-    /** @var ILocationProvider */
35
-    private $locationProvider;
36
-    /** @var IXffTrustProvider */
37
-    private $xffTrustProvider;
38
-    /** @var IRDnsProvider */
39
-    private $rdnsProvider;
40
-    /** @var IAntiSpoofProvider */
41
-    private $antiSpoofProvider;
42
-    /** @var IOAuthProtocolHelper */
43
-    private $oauthHelper;
44
-    /** @var PdoDatabase */
45
-    private $database;
46
-    /** @var IrcNotificationHelper */
47
-    private $notificationHelper;
48
-    /** @var TorExitProvider */
49
-    private $torExitProvider;
50
-
51
-    /**
52
-     * @return IEmailHelper
53
-     */
54
-    final public function getEmailHelper()
55
-    {
56
-        return $this->emailHelper;
57
-    }
58
-
59
-    /**
60
-     * @param IEmailHelper $emailHelper
61
-     */
62
-    final public function setEmailHelper($emailHelper)
63
-    {
64
-        $this->emailHelper = $emailHelper;
65
-    }
66
-
67
-    /**
68
-     * @return HttpHelper
69
-     */
70
-    final public function getHttpHelper()
71
-    {
72
-        return $this->httpHelper;
73
-    }
74
-
75
-    /**
76
-     * @param HttpHelper $httpHelper
77
-     */
78
-    final public function setHttpHelper($httpHelper)
79
-    {
80
-        $this->httpHelper = $httpHelper;
81
-    }
82
-
83
-    /**
84
-     * @return WikiTextHelper
85
-     */
86
-    final public function getWikiTextHelper()
87
-    {
88
-        return $this->wikiTextHelper;
89
-    }
90
-
91
-    /**
92
-     * @param WikiTextHelper $wikiTextHelper
93
-     */
94
-    final public function setWikiTextHelper($wikiTextHelper)
95
-    {
96
-        $this->wikiTextHelper = $wikiTextHelper;
97
-    }
98
-
99
-    /**
100
-     * @return ILocationProvider
101
-     */
102
-    final public function getLocationProvider()
103
-    {
104
-        return $this->locationProvider;
105
-    }
106
-
107
-    /**
108
-     * @param ILocationProvider $locationProvider
109
-     */
110
-    final public function setLocationProvider(ILocationProvider $locationProvider)
111
-    {
112
-        $this->locationProvider = $locationProvider;
113
-    }
114
-
115
-    /**
116
-     * @return IXffTrustProvider
117
-     */
118
-    final public function getXffTrustProvider()
119
-    {
120
-        return $this->xffTrustProvider;
121
-    }
122
-
123
-    /**
124
-     * @param IXffTrustProvider $xffTrustProvider
125
-     */
126
-    final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider)
127
-    {
128
-        $this->xffTrustProvider = $xffTrustProvider;
129
-    }
130
-
131
-    /**
132
-     * @return IRDnsProvider
133
-     */
134
-    final public function getRdnsProvider()
135
-    {
136
-        return $this->rdnsProvider;
137
-    }
138
-
139
-    /**
140
-     * @param IRDnsProvider $rdnsProvider
141
-     */
142
-    public function setRdnsProvider($rdnsProvider)
143
-    {
144
-        $this->rdnsProvider = $rdnsProvider;
145
-    }
146
-
147
-    /**
148
-     * @return IAntiSpoofProvider
149
-     */
150
-    public function getAntiSpoofProvider()
151
-    {
152
-        return $this->antiSpoofProvider;
153
-    }
154
-
155
-    /**
156
-     * @param IAntiSpoofProvider $antiSpoofProvider
157
-     */
158
-    public function setAntiSpoofProvider($antiSpoofProvider)
159
-    {
160
-        $this->antiSpoofProvider = $antiSpoofProvider;
161
-    }
162
-
163
-    /**
164
-     * @return PdoDatabase
165
-     */
166
-    final public function getDatabase()
167
-    {
168
-        return $this->database;
169
-    }
170
-
171
-    /**
172
-     * @param PdoDatabase $database
173
-     */
174
-    final public function setDatabase($database)
175
-    {
176
-        $this->database = $database;
177
-    }
178
-
179
-    /**
180
-     * @return IOAuthProtocolHelper
181
-     */
182
-    public function getOAuthProtocolHelper()
183
-    {
184
-        return $this->oauthHelper;
185
-    }
186
-
187
-    /**
188
-     * @param IOAuthProtocolHelper $oauthProtocolHelper
189
-     */
190
-    public function setOAuthProtocolHelper($oauthProtocolHelper)
191
-    {
192
-        $this->oauthHelper = $oauthProtocolHelper;
193
-    }
194
-
195
-    /**
196
-     * @return void
197
-     */
198
-    abstract public function execute();
199
-
200
-    /**
201
-     * @return IrcNotificationHelper
202
-     */
203
-    public function getNotificationHelper()
204
-    {
205
-        return $this->notificationHelper;
206
-    }
207
-
208
-    /**
209
-     * @param IrcNotificationHelper $notificationHelper
210
-     */
211
-    public function setNotificationHelper($notificationHelper)
212
-    {
213
-        $this->notificationHelper = $notificationHelper;
214
-    }
215
-
216
-    /**
217
-     * @return TorExitProvider
218
-     */
219
-    public function getTorExitProvider()
220
-    {
221
-        return $this->torExitProvider;
222
-    }
223
-
224
-    /**
225
-     * @param TorExitProvider $torExitProvider
226
-     */
227
-    public function setTorExitProvider($torExitProvider)
228
-    {
229
-        $this->torExitProvider = $torExitProvider;
230
-    }
231
-
232
-    /**
233
-     * Gets the site configuration object
234
-     *
235
-     * @return SiteConfiguration
236
-     */
237
-    final protected function getSiteConfiguration()
238
-    {
239
-        return $this->siteConfiguration;
240
-    }
241
-
242
-    /**
243
-     * Sets the site configuration object for this page
244
-     *
245
-     * @param SiteConfiguration $configuration
246
-     */
247
-    final public function setSiteConfiguration($configuration)
248
-    {
249
-        $this->siteConfiguration = $configuration;
250
-    }
26
+	/** @var SiteConfiguration */
27
+	private $siteConfiguration;
28
+	/** @var IEmailHelper */
29
+	private $emailHelper;
30
+	/** @var HttpHelper */
31
+	private $httpHelper;
32
+	/** @var WikiTextHelper */
33
+	private $wikiTextHelper;
34
+	/** @var ILocationProvider */
35
+	private $locationProvider;
36
+	/** @var IXffTrustProvider */
37
+	private $xffTrustProvider;
38
+	/** @var IRDnsProvider */
39
+	private $rdnsProvider;
40
+	/** @var IAntiSpoofProvider */
41
+	private $antiSpoofProvider;
42
+	/** @var IOAuthProtocolHelper */
43
+	private $oauthHelper;
44
+	/** @var PdoDatabase */
45
+	private $database;
46
+	/** @var IrcNotificationHelper */
47
+	private $notificationHelper;
48
+	/** @var TorExitProvider */
49
+	private $torExitProvider;
50
+
51
+	/**
52
+	 * @return IEmailHelper
53
+	 */
54
+	final public function getEmailHelper()
55
+	{
56
+		return $this->emailHelper;
57
+	}
58
+
59
+	/**
60
+	 * @param IEmailHelper $emailHelper
61
+	 */
62
+	final public function setEmailHelper($emailHelper)
63
+	{
64
+		$this->emailHelper = $emailHelper;
65
+	}
66
+
67
+	/**
68
+	 * @return HttpHelper
69
+	 */
70
+	final public function getHttpHelper()
71
+	{
72
+		return $this->httpHelper;
73
+	}
74
+
75
+	/**
76
+	 * @param HttpHelper $httpHelper
77
+	 */
78
+	final public function setHttpHelper($httpHelper)
79
+	{
80
+		$this->httpHelper = $httpHelper;
81
+	}
82
+
83
+	/**
84
+	 * @return WikiTextHelper
85
+	 */
86
+	final public function getWikiTextHelper()
87
+	{
88
+		return $this->wikiTextHelper;
89
+	}
90
+
91
+	/**
92
+	 * @param WikiTextHelper $wikiTextHelper
93
+	 */
94
+	final public function setWikiTextHelper($wikiTextHelper)
95
+	{
96
+		$this->wikiTextHelper = $wikiTextHelper;
97
+	}
98
+
99
+	/**
100
+	 * @return ILocationProvider
101
+	 */
102
+	final public function getLocationProvider()
103
+	{
104
+		return $this->locationProvider;
105
+	}
106
+
107
+	/**
108
+	 * @param ILocationProvider $locationProvider
109
+	 */
110
+	final public function setLocationProvider(ILocationProvider $locationProvider)
111
+	{
112
+		$this->locationProvider = $locationProvider;
113
+	}
114
+
115
+	/**
116
+	 * @return IXffTrustProvider
117
+	 */
118
+	final public function getXffTrustProvider()
119
+	{
120
+		return $this->xffTrustProvider;
121
+	}
122
+
123
+	/**
124
+	 * @param IXffTrustProvider $xffTrustProvider
125
+	 */
126
+	final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider)
127
+	{
128
+		$this->xffTrustProvider = $xffTrustProvider;
129
+	}
130
+
131
+	/**
132
+	 * @return IRDnsProvider
133
+	 */
134
+	final public function getRdnsProvider()
135
+	{
136
+		return $this->rdnsProvider;
137
+	}
138
+
139
+	/**
140
+	 * @param IRDnsProvider $rdnsProvider
141
+	 */
142
+	public function setRdnsProvider($rdnsProvider)
143
+	{
144
+		$this->rdnsProvider = $rdnsProvider;
145
+	}
146
+
147
+	/**
148
+	 * @return IAntiSpoofProvider
149
+	 */
150
+	public function getAntiSpoofProvider()
151
+	{
152
+		return $this->antiSpoofProvider;
153
+	}
154
+
155
+	/**
156
+	 * @param IAntiSpoofProvider $antiSpoofProvider
157
+	 */
158
+	public function setAntiSpoofProvider($antiSpoofProvider)
159
+	{
160
+		$this->antiSpoofProvider = $antiSpoofProvider;
161
+	}
162
+
163
+	/**
164
+	 * @return PdoDatabase
165
+	 */
166
+	final public function getDatabase()
167
+	{
168
+		return $this->database;
169
+	}
170
+
171
+	/**
172
+	 * @param PdoDatabase $database
173
+	 */
174
+	final public function setDatabase($database)
175
+	{
176
+		$this->database = $database;
177
+	}
178
+
179
+	/**
180
+	 * @return IOAuthProtocolHelper
181
+	 */
182
+	public function getOAuthProtocolHelper()
183
+	{
184
+		return $this->oauthHelper;
185
+	}
186
+
187
+	/**
188
+	 * @param IOAuthProtocolHelper $oauthProtocolHelper
189
+	 */
190
+	public function setOAuthProtocolHelper($oauthProtocolHelper)
191
+	{
192
+		$this->oauthHelper = $oauthProtocolHelper;
193
+	}
194
+
195
+	/**
196
+	 * @return void
197
+	 */
198
+	abstract public function execute();
199
+
200
+	/**
201
+	 * @return IrcNotificationHelper
202
+	 */
203
+	public function getNotificationHelper()
204
+	{
205
+		return $this->notificationHelper;
206
+	}
207
+
208
+	/**
209
+	 * @param IrcNotificationHelper $notificationHelper
210
+	 */
211
+	public function setNotificationHelper($notificationHelper)
212
+	{
213
+		$this->notificationHelper = $notificationHelper;
214
+	}
215
+
216
+	/**
217
+	 * @return TorExitProvider
218
+	 */
219
+	public function getTorExitProvider()
220
+	{
221
+		return $this->torExitProvider;
222
+	}
223
+
224
+	/**
225
+	 * @param TorExitProvider $torExitProvider
226
+	 */
227
+	public function setTorExitProvider($torExitProvider)
228
+	{
229
+		$this->torExitProvider = $torExitProvider;
230
+	}
231
+
232
+	/**
233
+	 * Gets the site configuration object
234
+	 *
235
+	 * @return SiteConfiguration
236
+	 */
237
+	final protected function getSiteConfiguration()
238
+	{
239
+		return $this->siteConfiguration;
240
+	}
241
+
242
+	/**
243
+	 * Sets the site configuration object for this page
244
+	 *
245
+	 * @param SiteConfiguration $configuration
246
+	 */
247
+	final public function setSiteConfiguration($configuration)
248
+	{
249
+		$this->siteConfiguration = $configuration;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
includes/DataObjects/OAuthToken.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,42 +14,42 @@  discard block
 block discarded – undo
14 14
 
15 15
 class OAuthToken extends DataObject
16 16
 {
17
-    /** @var int */
18
-    private $user;
19
-    /** @var string */
20
-    private $token;
21
-    /** @var string */
22
-    private $secret;
23
-    /** @var string */
24
-    private $type;
25
-    /** @var string */
26
-    private $expiry;
27
-
28
-    public function save()
29
-    {
30
-        if ($this->isNew()) {
31
-            // insert
32
-            $statement = $this->dbObject->prepare(<<<SQL
17
+	/** @var int */
18
+	private $user;
19
+	/** @var string */
20
+	private $token;
21
+	/** @var string */
22
+	private $secret;
23
+	/** @var string */
24
+	private $type;
25
+	/** @var string */
26
+	private $expiry;
27
+
28
+	public function save()
29
+	{
30
+		if ($this->isNew()) {
31
+			// insert
32
+			$statement = $this->dbObject->prepare(<<<SQL
33 33
                 INSERT INTO oauthtoken ( user, token, secret, type, expiry )
34 34
                 VALUES ( :user, :token, :secret, :type, :expiry );
35 35
 SQL
36
-            );
37
-            $statement->bindValue(":user", $this->user);
38
-            $statement->bindValue(":token", $this->token);
39
-            $statement->bindValue(":secret", $this->secret);
40
-            $statement->bindValue(":type", $this->type);
41
-            $statement->bindValue(":expiry", $this->expiry);
42
-
43
-            if ($statement->execute()) {
44
-                $this->id = (int)$this->dbObject->lastInsertId();
45
-            }
46
-            else {
47
-                throw new Exception($statement->errorInfo());
48
-            }
49
-        }
50
-        else {
51
-            // update
52
-            $statement = $this->dbObject->prepare(<<<SQL
36
+			);
37
+			$statement->bindValue(":user", $this->user);
38
+			$statement->bindValue(":token", $this->token);
39
+			$statement->bindValue(":secret", $this->secret);
40
+			$statement->bindValue(":type", $this->type);
41
+			$statement->bindValue(":expiry", $this->expiry);
42
+
43
+			if ($statement->execute()) {
44
+				$this->id = (int)$this->dbObject->lastInsertId();
45
+			}
46
+			else {
47
+				throw new Exception($statement->errorInfo());
48
+			}
49
+		}
50
+		else {
51
+			// update
52
+			$statement = $this->dbObject->prepare(<<<SQL
53 53
                 UPDATE oauthtoken
54 54
                 SET   token = :token
55 55
                     , secret = :secret
@@ -58,109 +58,109 @@  discard block
 block discarded – undo
58 58
                     , updateversion = updateversion + 1
59 59
                 WHERE id = :id AND updateversion = :updateversion;
60 60
 SQL
61
-            );
62
-
63
-            $statement->bindValue(':id', $this->id);
64
-            $statement->bindValue(':updateversion', $this->updateversion);
65
-
66
-            $statement->bindValue(":token", $this->token);
67
-            $statement->bindValue(":secret", $this->secret);
68
-            $statement->bindValue(":type", $this->type);
69
-            $statement->bindValue(":expiry", $this->expiry);
70
-
71
-            if (!$statement->execute()) {
72
-                throw new Exception($statement->errorInfo());
73
-            }
74
-
75
-            if ($statement->rowCount() !== 1) {
76
-                throw new OptimisticLockFailedException();
77
-            }
78
-
79
-            $this->updateversion++;
80
-        }
81
-    }
82
-
83
-    #region properties
84
-
85
-    /**
86
-     * @return mixed
87
-     */
88
-    public function getUserId()
89
-    {
90
-        return $this->user;
91
-    }
92
-
93
-    /**
94
-     * @param mixed $user
95
-     */
96
-    public function setUserId($user)
97
-    {
98
-        $this->user = $user;
99
-    }
100
-
101
-    /**
102
-     * @return mixed
103
-     */
104
-    public function getToken()
105
-    {
106
-        return $this->token;
107
-    }
108
-
109
-    /**
110
-     * @param mixed $token
111
-     */
112
-    public function setToken($token)
113
-    {
114
-        $this->token = $token;
115
-    }
116
-
117
-    /**
118
-     * @return mixed
119
-     */
120
-    public function getSecret()
121
-    {
122
-        return $this->secret;
123
-    }
124
-
125
-    /**
126
-     * @param mixed $secret
127
-     */
128
-    public function setSecret($secret)
129
-    {
130
-        $this->secret = $secret;
131
-    }
132
-
133
-    /**
134
-     * @return mixed
135
-     */
136
-    public function getType()
137
-    {
138
-        return $this->type;
139
-    }
140
-
141
-    /**
142
-     * @param mixed $type
143
-     */
144
-    public function setType($type)
145
-    {
146
-        $this->type = $type;
147
-    }
148
-
149
-    /**
150
-     * @return string
151
-     */
152
-    public function getExpiry()
153
-    {
154
-        return $this->expiry;
155
-    }
156
-
157
-    /**
158
-     * @param string $expiry
159
-     */
160
-    public function setExpiry($expiry)
161
-    {
162
-        $this->expiry = $expiry;
163
-    }
164
-    #endregion
61
+			);
62
+
63
+			$statement->bindValue(':id', $this->id);
64
+			$statement->bindValue(':updateversion', $this->updateversion);
65
+
66
+			$statement->bindValue(":token", $this->token);
67
+			$statement->bindValue(":secret", $this->secret);
68
+			$statement->bindValue(":type", $this->type);
69
+			$statement->bindValue(":expiry", $this->expiry);
70
+
71
+			if (!$statement->execute()) {
72
+				throw new Exception($statement->errorInfo());
73
+			}
74
+
75
+			if ($statement->rowCount() !== 1) {
76
+				throw new OptimisticLockFailedException();
77
+			}
78
+
79
+			$this->updateversion++;
80
+		}
81
+	}
82
+
83
+	#region properties
84
+
85
+	/**
86
+	 * @return mixed
87
+	 */
88
+	public function getUserId()
89
+	{
90
+		return $this->user;
91
+	}
92
+
93
+	/**
94
+	 * @param mixed $user
95
+	 */
96
+	public function setUserId($user)
97
+	{
98
+		$this->user = $user;
99
+	}
100
+
101
+	/**
102
+	 * @return mixed
103
+	 */
104
+	public function getToken()
105
+	{
106
+		return $this->token;
107
+	}
108
+
109
+	/**
110
+	 * @param mixed $token
111
+	 */
112
+	public function setToken($token)
113
+	{
114
+		$this->token = $token;
115
+	}
116
+
117
+	/**
118
+	 * @return mixed
119
+	 */
120
+	public function getSecret()
121
+	{
122
+		return $this->secret;
123
+	}
124
+
125
+	/**
126
+	 * @param mixed $secret
127
+	 */
128
+	public function setSecret($secret)
129
+	{
130
+		$this->secret = $secret;
131
+	}
132
+
133
+	/**
134
+	 * @return mixed
135
+	 */
136
+	public function getType()
137
+	{
138
+		return $this->type;
139
+	}
140
+
141
+	/**
142
+	 * @param mixed $type
143
+	 */
144
+	public function setType($type)
145
+	{
146
+		$this->type = $type;
147
+	}
148
+
149
+	/**
150
+	 * @return string
151
+	 */
152
+	public function getExpiry()
153
+	{
154
+		return $this->expiry;
155
+	}
156
+
157
+	/**
158
+	 * @param string $expiry
159
+	 */
160
+	public function setExpiry($expiry)
161
+	{
162
+		$this->expiry = $expiry;
163
+	}
164
+	#endregion
165 165
 
166 166
 }
167 167
\ No newline at end of file
Please login to merge, or discard this patch.
includes/DataObjects/JobQueue.php 2 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
 class JobQueue extends DataObject
19 19
 {
20
-    /*
20
+	/*
21 21
      * Status workflow is this:
22 22
      *
23 23
      * 1) Ready. The job has been added to the queue
@@ -26,78 +26,78 @@  discard block
 block discarded – undo
26 26
      * 3) Complete / Failed. The job has been processed
27 27
      *
28 28
      */
29
-    const STATUS_READY = 'ready';
30
-    const STATUS_WAITING = 'waiting';
31
-    const STATUS_RUNNING = 'running';
32
-    const STATUS_COMPLETE = 'complete';
33
-    const STATUS_CANCELLED = 'cancelled';
34
-    const STATUS_FAILED = 'failed';
35
-    const STATUS_HELD = 'held';
36
-
37
-    /** @var string */
38
-    private $task;
39
-    /** @var int */
40
-    private $user;
41
-    /** @var int */
42
-    private $request;
43
-    /** @var int */
44
-    private $emailtemplate;
45
-    /** @var string */
46
-    private $status;
47
-    /** @var string */
48
-    private $enqueue;
49
-    /** @var string */
50
-    private $parameters;
51
-    /** @var string */
52
-    private $error;
53
-    /** @var int */
54
-    private $acknowledged;
55
-    /** @var int */
56
-    private $parent;
57
-
58
-    /**
59
-     * This feels like the least bad place to put this method.
60
-     */
61
-    public static function getTaskDescriptions() {
62
-        return array(
63
-            BotCreationTask::class  => 'Create account (via bot)',
64
-            UserCreationTask::class => 'Create account (via OAuth)',
65
-            WelcomeUserTask::class  => 'Welcome user',
66
-        );
67
-    }
68
-
69
-    /**
70
-     * Saves a data object to the database, either updating or inserting a record.
71
-     * @return void
72
-     * @throws Exception
73
-     * @throws OptimisticLockFailedException
74
-     */
75
-    public function save()
76
-    {
77
-        if ($this->isNew()) {
78
-            // insert
79
-            $statement = $this->dbObject->prepare(<<<SQL
29
+	const STATUS_READY = 'ready';
30
+	const STATUS_WAITING = 'waiting';
31
+	const STATUS_RUNNING = 'running';
32
+	const STATUS_COMPLETE = 'complete';
33
+	const STATUS_CANCELLED = 'cancelled';
34
+	const STATUS_FAILED = 'failed';
35
+	const STATUS_HELD = 'held';
36
+
37
+	/** @var string */
38
+	private $task;
39
+	/** @var int */
40
+	private $user;
41
+	/** @var int */
42
+	private $request;
43
+	/** @var int */
44
+	private $emailtemplate;
45
+	/** @var string */
46
+	private $status;
47
+	/** @var string */
48
+	private $enqueue;
49
+	/** @var string */
50
+	private $parameters;
51
+	/** @var string */
52
+	private $error;
53
+	/** @var int */
54
+	private $acknowledged;
55
+	/** @var int */
56
+	private $parent;
57
+
58
+	/**
59
+	 * This feels like the least bad place to put this method.
60
+	 */
61
+	public static function getTaskDescriptions() {
62
+		return array(
63
+			BotCreationTask::class  => 'Create account (via bot)',
64
+			UserCreationTask::class => 'Create account (via OAuth)',
65
+			WelcomeUserTask::class  => 'Welcome user',
66
+		);
67
+	}
68
+
69
+	/**
70
+	 * Saves a data object to the database, either updating or inserting a record.
71
+	 * @return void
72
+	 * @throws Exception
73
+	 * @throws OptimisticLockFailedException
74
+	 */
75
+	public function save()
76
+	{
77
+		if ($this->isNew()) {
78
+			// insert
79
+			$statement = $this->dbObject->prepare(<<<SQL
80 80
                 INSERT INTO jobqueue (task, user, request, emailtemplate, parameters, parent) 
81 81
                 VALUES (:task, :user, :request, :emailtemplate, :parameters, :parent)
82 82
 SQL
83
-            );
84
-            $statement->bindValue(":task", $this->task);
85
-            $statement->bindValue(":user", $this->user);
86
-            $statement->bindValue(":request", $this->request);
87
-            $statement->bindValue(":emailtemplate", $this->emailtemplate);
88
-            $statement->bindValue(":parameters", $this->parameters);
89
-            $statement->bindValue(":parent", $this->parent);
90
-
91
-            if ($statement->execute()) {
92
-                $this->id = (int)$this->dbObject->lastInsertId();
93
-            }
94
-            else {
95
-                throw new Exception($statement->errorInfo());
96
-            }
97
-        }
98
-        else {
99
-            // update
100
-            $statement = $this->dbObject->prepare(<<<SQL
83
+			);
84
+			$statement->bindValue(":task", $this->task);
85
+			$statement->bindValue(":user", $this->user);
86
+			$statement->bindValue(":request", $this->request);
87
+			$statement->bindValue(":emailtemplate", $this->emailtemplate);
88
+			$statement->bindValue(":parameters", $this->parameters);
89
+			$statement->bindValue(":parent", $this->parent);
90
+
91
+			if ($statement->execute()) {
92
+				$this->id = (int)$this->dbObject->lastInsertId();
93
+			}
94
+			else {
95
+				throw new Exception($statement->errorInfo());
96
+			}
97
+		}
98
+		else {
99
+			// update
100
+			$statement = $this->dbObject->prepare(<<<SQL
101 101
                 UPDATE jobqueue SET 
102 102
                       status = :status
103 103
                     , error = :error
@@ -105,187 +105,187 @@  discard block
 block discarded – undo
105 105
                     , updateversion = updateversion + 1
106 106
                 WHERE id = :id AND updateversion = :updateversion;
107 107
 SQL
108
-            );
109
-
110
-            $statement->bindValue(":id", $this->id);
111
-            $statement->bindValue(":updateversion", $this->updateversion);
112
-
113
-            $statement->bindValue(":status", $this->status);
114
-            $statement->bindValue(":error", $this->error);
115
-            $statement->bindValue(":ack", $this->acknowledged);
116
-
117
-            if (!$statement->execute()) {
118
-                throw new Exception($statement->errorInfo());
119
-            }
120
-
121
-            if ($statement->rowCount() !== 1) {
122
-                throw new OptimisticLockFailedException();
123
-            }
124
-
125
-            $this->updateversion++;
126
-        }
127
-    }
128
-
129
-    #region Properties
130
-
131
-    /**
132
-     * @return string
133
-     */
134
-    public function getTask()
135
-    {
136
-        return $this->task;
137
-    }
138
-
139
-    /**
140
-     * @param string $task
141
-     */
142
-    public function setTask($task)
143
-    {
144
-        $this->task = $task;
145
-    }
146
-
147
-    /**
148
-     * @return int
149
-     */
150
-    public function getTriggerUserId()
151
-    {
152
-        return $this->user;
153
-    }
154
-
155
-    /**
156
-     * @param int $user
157
-     */
158
-    public function setTriggerUserId($user)
159
-    {
160
-        $this->user = $user;
161
-    }
162
-
163
-    /**
164
-     * @return int
165
-     */
166
-    public function getRequest()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-    /**
172
-     * @param int $request
173
-     */
174
-    public function setRequest($request)
175
-    {
176
-        $this->request = $request;
177
-    }
178
-
179
-    /**
180
-     * @return string
181
-     */
182
-    public function getStatus()
183
-    {
184
-        return $this->status;
185
-    }
186
-
187
-    /**
188
-     * @param string $status
189
-     */
190
-    public function setStatus($status)
191
-    {
192
-        $this->status = $status;
193
-    }
194
-
195
-    /**
196
-     * @return string
197
-     */
198
-    public function getEnqueue()
199
-    {
200
-        return $this->enqueue;
201
-    }
202
-
203
-    /**
204
-     * @param string $enqueue
205
-     */
206
-    public function setEnqueue($enqueue)
207
-    {
208
-        $this->enqueue = $enqueue;
209
-    }
210
-
211
-    /**
212
-     * @return string
213
-     */
214
-    public function getParameters()
215
-    {
216
-        return $this->parameters;
217
-    }
218
-
219
-    /**
220
-     * @param string $parameters
221
-     */
222
-    public function setParameters($parameters)
223
-    {
224
-        $this->parameters = $parameters;
225
-    }
226
-
227
-    /**
228
-     * @return mixed
229
-     */
230
-    public function getError()
231
-    {
232
-        return $this->error;
233
-    }
234
-
235
-    /**
236
-     * @param mixed $error
237
-     */
238
-    public function setError($error)
239
-    {
240
-        $this->error = $error;
241
-    }
242
-
243
-    /**
244
-     * @return int
245
-     */
246
-    public function getAcknowledged()
247
-    {
248
-        return $this->acknowledged;
249
-    }
250
-
251
-    /**
252
-     * @param int $acknowledged
253
-     */
254
-    public function setAcknowledged($acknowledged)
255
-    {
256
-        $this->acknowledged = $acknowledged;
257
-    }
258
-
259
-    /**
260
-     * @return int
261
-     */
262
-    public function getParent()
263
-    {
264
-        return $this->parent;
265
-    }
266
-
267
-    /**
268
-     * @param int $parent
269
-     */
270
-    public function setParent($parent)
271
-    {
272
-        $this->parent = $parent;
273
-    }
274
-
275
-    /**
276
-     * @return int
277
-     */
278
-    public function getEmailTemplate()
279
-    {
280
-        return $this->emailtemplate;
281
-    }
282
-
283
-    /**
284
-     * @param int $emailTemplate
285
-     */
286
-    public function setEmailTemplate($emailTemplate)
287
-    {
288
-        $this->emailtemplate = $emailTemplate;
289
-    }
290
-    #endregion
108
+			);
109
+
110
+			$statement->bindValue(":id", $this->id);
111
+			$statement->bindValue(":updateversion", $this->updateversion);
112
+
113
+			$statement->bindValue(":status", $this->status);
114
+			$statement->bindValue(":error", $this->error);
115
+			$statement->bindValue(":ack", $this->acknowledged);
116
+
117
+			if (!$statement->execute()) {
118
+				throw new Exception($statement->errorInfo());
119
+			}
120
+
121
+			if ($statement->rowCount() !== 1) {
122
+				throw new OptimisticLockFailedException();
123
+			}
124
+
125
+			$this->updateversion++;
126
+		}
127
+	}
128
+
129
+	#region Properties
130
+
131
+	/**
132
+	 * @return string
133
+	 */
134
+	public function getTask()
135
+	{
136
+		return $this->task;
137
+	}
138
+
139
+	/**
140
+	 * @param string $task
141
+	 */
142
+	public function setTask($task)
143
+	{
144
+		$this->task = $task;
145
+	}
146
+
147
+	/**
148
+	 * @return int
149
+	 */
150
+	public function getTriggerUserId()
151
+	{
152
+		return $this->user;
153
+	}
154
+
155
+	/**
156
+	 * @param int $user
157
+	 */
158
+	public function setTriggerUserId($user)
159
+	{
160
+		$this->user = $user;
161
+	}
162
+
163
+	/**
164
+	 * @return int
165
+	 */
166
+	public function getRequest()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+	/**
172
+	 * @param int $request
173
+	 */
174
+	public function setRequest($request)
175
+	{
176
+		$this->request = $request;
177
+	}
178
+
179
+	/**
180
+	 * @return string
181
+	 */
182
+	public function getStatus()
183
+	{
184
+		return $this->status;
185
+	}
186
+
187
+	/**
188
+	 * @param string $status
189
+	 */
190
+	public function setStatus($status)
191
+	{
192
+		$this->status = $status;
193
+	}
194
+
195
+	/**
196
+	 * @return string
197
+	 */
198
+	public function getEnqueue()
199
+	{
200
+		return $this->enqueue;
201
+	}
202
+
203
+	/**
204
+	 * @param string $enqueue
205
+	 */
206
+	public function setEnqueue($enqueue)
207
+	{
208
+		$this->enqueue = $enqueue;
209
+	}
210
+
211
+	/**
212
+	 * @return string
213
+	 */
214
+	public function getParameters()
215
+	{
216
+		return $this->parameters;
217
+	}
218
+
219
+	/**
220
+	 * @param string $parameters
221
+	 */
222
+	public function setParameters($parameters)
223
+	{
224
+		$this->parameters = $parameters;
225
+	}
226
+
227
+	/**
228
+	 * @return mixed
229
+	 */
230
+	public function getError()
231
+	{
232
+		return $this->error;
233
+	}
234
+
235
+	/**
236
+	 * @param mixed $error
237
+	 */
238
+	public function setError($error)
239
+	{
240
+		$this->error = $error;
241
+	}
242
+
243
+	/**
244
+	 * @return int
245
+	 */
246
+	public function getAcknowledged()
247
+	{
248
+		return $this->acknowledged;
249
+	}
250
+
251
+	/**
252
+	 * @param int $acknowledged
253
+	 */
254
+	public function setAcknowledged($acknowledged)
255
+	{
256
+		$this->acknowledged = $acknowledged;
257
+	}
258
+
259
+	/**
260
+	 * @return int
261
+	 */
262
+	public function getParent()
263
+	{
264
+		return $this->parent;
265
+	}
266
+
267
+	/**
268
+	 * @param int $parent
269
+	 */
270
+	public function setParent($parent)
271
+	{
272
+		$this->parent = $parent;
273
+	}
274
+
275
+	/**
276
+	 * @return int
277
+	 */
278
+	public function getEmailTemplate()
279
+	{
280
+		return $this->emailtemplate;
281
+	}
282
+
283
+	/**
284
+	 * @param int $emailTemplate
285
+	 */
286
+	public function setEmailTemplate($emailTemplate)
287
+	{
288
+		$this->emailtemplate = $emailTemplate;
289
+	}
290
+	#endregion
291 291
 }
292 292
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,8 @@
 block discarded – undo
58 58
     /**
59 59
      * This feels like the least bad place to put this method.
60 60
      */
61
-    public static function getTaskDescriptions() {
61
+    public static function getTaskDescriptions()
62
+    {
62 63
         return array(
63 64
             BotCreationTask::class  => 'Create account (via bot)',
64 65
             UserCreationTask::class => 'Create account (via OAuth)',
Please login to merge, or discard this patch.
includes/ApplicationBase.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -25,155 +25,155 @@
 block discarded – undo
25 25
 
26 26
 abstract class ApplicationBase
27 27
 {
28
-    private $configuration;
29
-
30
-    public function __construct(SiteConfiguration $configuration)
31
-    {
32
-        $this->configuration = $configuration;
33
-    }
34
-
35
-    /**
36
-     * Application entry point.
37
-     *
38
-     * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
-     */
40
-    public function run()
41
-    {
42
-        try {
43
-            if ($this->setupEnvironment()) {
44
-                $this->main();
45
-            }
46
-        }
47
-        catch (Exception $ex) {
48
-            print $ex->getMessage();
49
-        }
50
-        finally {
51
-            $this->cleanupEnvironment();
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Environment setup
57
-     *
58
-     * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
-     * and shut down prematurely.
60
-     *
61
-     * @return bool
62
-     * @throws EnvironmentException
63
-     */
64
-    protected function setupEnvironment()
65
-    {
66
-        $this->setupDatabase();
67
-
68
-        return true;
69
-    }
70
-
71
-    /**
72
-     * @return PdoDatabase
73
-     * @throws EnvironmentException
74
-     * @throws Exception
75
-     */
76
-    protected function setupDatabase()
77
-    {
78
-        // check the schema version
79
-        $database = PdoDatabase::getDatabaseConnection('acc');
80
-
81
-        /** @var int $actualVersion */
82
-        $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
-        if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
-            throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
-        }
86
-
87
-        return $database;
88
-    }
89
-
90
-    /**
91
-     * @return SiteConfiguration
92
-     */
93
-    public function getConfiguration()
94
-    {
95
-        return $this->configuration;
96
-    }
97
-
98
-    /**
99
-     * Main application logic
100
-     * @return void
101
-     */
102
-    abstract protected function main();
103
-
104
-    /**
105
-     * Any cleanup tasks should go here
106
-     *
107
-     * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
-     * This should *only* be for cleaning up, no logic should go here.
109
-     *
110
-     * @return void
111
-     */
112
-    abstract protected function cleanupEnvironment();
113
-
114
-    /**
115
-     * @param ITask             $page
116
-     * @param SiteConfiguration $siteConfiguration
117
-     * @param PdoDatabase       $database
118
-     * @param PdoDatabase       $notificationsDatabase
119
-     *
120
-     * @return void
121
-     */
122
-    protected function setupHelpers(
123
-        ITask $page,
124
-        SiteConfiguration $siteConfiguration,
125
-        PdoDatabase $database,
126
-        PdoDatabase $notificationsDatabase = null
127
-    ) {
128
-        $page->setSiteConfiguration($siteConfiguration);
129
-
130
-        // setup the global database object
131
-        $page->setDatabase($database);
132
-
133
-        // set up helpers and inject them into the page.
134
-        $httpHelper = new HttpHelper(
135
-            $siteConfiguration->getUserAgent(),
136
-            $siteConfiguration->getCurlDisableVerifyPeer()
137
-        );
138
-
139
-        $page->setEmailHelper(new EmailHelper());
140
-        $page->setHttpHelper($httpHelper);
141
-        $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
-
143
-        if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
-            $page->setLocationProvider(new FakeLocationProvider());
145
-        }
146
-        else {
147
-            $page->setLocationProvider(
148
-                new IpLocationProvider(
149
-                    $database,
150
-                    $siteConfiguration->getLocationProviderApiKey(),
151
-                    $httpHelper
152
-                ));
153
-        }
154
-
155
-        $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
-
157
-        $page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
-
159
-        $page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
-            $database,
161
-            $this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
-            $httpHelper));
163
-
164
-        $page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
-            $siteConfiguration->getOAuthBaseUrl(),
166
-            $siteConfiguration->getOAuthConsumerToken(),
167
-            $siteConfiguration->getOAuthConsumerSecret(),
168
-            $httpHelper,
169
-            $siteConfiguration->getMediawikiWebServiceEndpoint()
170
-        ));
171
-
172
-        $page->setNotificationHelper(new IrcNotificationHelper(
173
-            $siteConfiguration,
174
-            $database,
175
-            $notificationsDatabase));
176
-
177
-        $page->setTorExitProvider(new TorExitProvider($database));
178
-    }
28
+	private $configuration;
29
+
30
+	public function __construct(SiteConfiguration $configuration)
31
+	{
32
+		$this->configuration = $configuration;
33
+	}
34
+
35
+	/**
36
+	 * Application entry point.
37
+	 *
38
+	 * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
+	 */
40
+	public function run()
41
+	{
42
+		try {
43
+			if ($this->setupEnvironment()) {
44
+				$this->main();
45
+			}
46
+		}
47
+		catch (Exception $ex) {
48
+			print $ex->getMessage();
49
+		}
50
+		finally {
51
+			$this->cleanupEnvironment();
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Environment setup
57
+	 *
58
+	 * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
+	 * and shut down prematurely.
60
+	 *
61
+	 * @return bool
62
+	 * @throws EnvironmentException
63
+	 */
64
+	protected function setupEnvironment()
65
+	{
66
+		$this->setupDatabase();
67
+
68
+		return true;
69
+	}
70
+
71
+	/**
72
+	 * @return PdoDatabase
73
+	 * @throws EnvironmentException
74
+	 * @throws Exception
75
+	 */
76
+	protected function setupDatabase()
77
+	{
78
+		// check the schema version
79
+		$database = PdoDatabase::getDatabaseConnection('acc');
80
+
81
+		/** @var int $actualVersion */
82
+		$actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
+		if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
+			throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
+		}
86
+
87
+		return $database;
88
+	}
89
+
90
+	/**
91
+	 * @return SiteConfiguration
92
+	 */
93
+	public function getConfiguration()
94
+	{
95
+		return $this->configuration;
96
+	}
97
+
98
+	/**
99
+	 * Main application logic
100
+	 * @return void
101
+	 */
102
+	abstract protected function main();
103
+
104
+	/**
105
+	 * Any cleanup tasks should go here
106
+	 *
107
+	 * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
+	 * This should *only* be for cleaning up, no logic should go here.
109
+	 *
110
+	 * @return void
111
+	 */
112
+	abstract protected function cleanupEnvironment();
113
+
114
+	/**
115
+	 * @param ITask             $page
116
+	 * @param SiteConfiguration $siteConfiguration
117
+	 * @param PdoDatabase       $database
118
+	 * @param PdoDatabase       $notificationsDatabase
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function setupHelpers(
123
+		ITask $page,
124
+		SiteConfiguration $siteConfiguration,
125
+		PdoDatabase $database,
126
+		PdoDatabase $notificationsDatabase = null
127
+	) {
128
+		$page->setSiteConfiguration($siteConfiguration);
129
+
130
+		// setup the global database object
131
+		$page->setDatabase($database);
132
+
133
+		// set up helpers and inject them into the page.
134
+		$httpHelper = new HttpHelper(
135
+			$siteConfiguration->getUserAgent(),
136
+			$siteConfiguration->getCurlDisableVerifyPeer()
137
+		);
138
+
139
+		$page->setEmailHelper(new EmailHelper());
140
+		$page->setHttpHelper($httpHelper);
141
+		$page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
+
143
+		if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
+			$page->setLocationProvider(new FakeLocationProvider());
145
+		}
146
+		else {
147
+			$page->setLocationProvider(
148
+				new IpLocationProvider(
149
+					$database,
150
+					$siteConfiguration->getLocationProviderApiKey(),
151
+					$httpHelper
152
+				));
153
+		}
154
+
155
+		$page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
+
157
+		$page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
+
159
+		$page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
+			$database,
161
+			$this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
+			$httpHelper));
163
+
164
+		$page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
+			$siteConfiguration->getOAuthBaseUrl(),
166
+			$siteConfiguration->getOAuthConsumerToken(),
167
+			$siteConfiguration->getOAuthConsumerSecret(),
168
+			$httpHelper,
169
+			$siteConfiguration->getMediawikiWebServiceEndpoint()
170
+		));
171
+
172
+		$page->setNotificationHelper(new IrcNotificationHelper(
173
+			$siteConfiguration,
174
+			$database,
175
+			$notificationsDatabase));
176
+
177
+		$page->setTorExitProvider(new TorExitProvider($database));
178
+	}
179 179
 }
180 180
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleStart.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 
16 16
 class ConsoleStart extends ApplicationBase
17 17
 {
18
-    /**
19
-     * @var ConsoleTaskBase
20
-     */
21
-    private $consoleTask;
18
+	/**
19
+	 * @var ConsoleTaskBase
20
+	 */
21
+	private $consoleTask;
22 22
 
23
-    /**
24
-     * ConsoleStart constructor.
25
-     *
26
-     * @param SiteConfiguration $configuration
27
-     * @param ConsoleTaskBase   $consoleTask
28
-     */
29
-    public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
-    {
31
-        parent::__construct($configuration);
32
-        $this->consoleTask = $consoleTask;
33
-    }
23
+	/**
24
+	 * ConsoleStart constructor.
25
+	 *
26
+	 * @param SiteConfiguration $configuration
27
+	 * @param ConsoleTaskBase   $consoleTask
28
+	 */
29
+	public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
+	{
31
+		parent::__construct($configuration);
32
+		$this->consoleTask = $consoleTask;
33
+	}
34 34
 
35
-    protected function setupEnvironment()
36
-    {
37
-        // initialise super-global providers
38
-        WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
35
+	protected function setupEnvironment()
36
+	{
37
+		// initialise super-global providers
38
+		WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
39 39
 
40
-        if (WebRequest::method() !== null) {
41
-            throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
-        }
40
+		if (WebRequest::method() !== null) {
41
+			throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
+		}
43 43
 
44
-        return parent::setupEnvironment();
45
-    }
44
+		return parent::setupEnvironment();
45
+	}
46 46
 
47
-    protected function cleanupEnvironment()
48
-    {
49
-    }
47
+	protected function cleanupEnvironment()
48
+	{
49
+	}
50 50
 
51
-    /**
52
-     * Main application logic
53
-     */
54
-    protected function main()
55
-    {
56
-        $database = PdoDatabase::getDatabaseConnection('acc');
51
+	/**
52
+	 * Main application logic
53
+	 */
54
+	protected function main()
55
+	{
56
+		$database = PdoDatabase::getDatabaseConnection('acc');
57 57
 
58
-        if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
-            $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
-        }
61
-        else {
62
-            // pass through null
63
-            $notificationsDatabase = null;
64
-        }
58
+		if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
+			$notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
+		}
61
+		else {
62
+			// pass through null
63
+			$notificationsDatabase = null;
64
+		}
65 65
 
66
-        $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
66
+		$this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
67 67
 
68
-        // initialise a database transaction
69
-        if (!$database->beginTransaction()) {
70
-            throw new Exception('Failed to start transaction on primary database.');
71
-        }
68
+		// initialise a database transaction
69
+		if (!$database->beginTransaction()) {
70
+			throw new Exception('Failed to start transaction on primary database.');
71
+		}
72 72
 
73
-        try {
74
-            // run the task
75
-            $this->consoleTask->execute();
73
+		try {
74
+			// run the task
75
+			$this->consoleTask->execute();
76 76
 
77
-            if ($database->hasActiveTransaction()) {
78
-                $database->commit();
79
-            }
80
-        }
81
-        finally {
82
-            // Catch any hanging on transactions
83
-            if ($database->hasActiveTransaction()) {
84
-                $database->rollBack();
85
-            }
86
-        }
87
-    }
77
+			if ($database->hasActiveTransaction()) {
78
+				$database->commit();
79
+			}
80
+		}
81
+		finally {
82
+			// Catch any hanging on transactions
83
+			if ($database->hasActiveTransaction()) {
84
+				$database->rollBack();
85
+			}
86
+		}
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.