Passed
Push — dependabot/composer/php8/forta... ( 9a9f56...0ecb64 )
by
unknown
17:53 queued 14:02
created
includes/Helpers/SearchHelpers/UserSearchHelper.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -15,73 +15,73 @@  discard block
 block discarded – undo
15 15
 
16 16
 class UserSearchHelper extends SearchHelperBase
17 17
 {
18
-    /**
19
-     * UserSearchHelper constructor.
20
-     *
21
-     * @param PdoDatabase $database
22
-     */
23
-    public function __construct(PdoDatabase $database)
24
-    {
25
-        parent::__construct($database, 'user', User::class);
26
-    }
27
-
28
-    /**
29
-     * Initiates a search for requests
30
-     *
31
-     * @param PdoDatabase $database
32
-     *
33
-     * @return UserSearchHelper
34
-     */
35
-    public static function get(PdoDatabase $database)
36
-    {
37
-        $helper = new UserSearchHelper($database);
38
-
39
-        return $helper;
40
-    }
41
-
42
-    /**
43
-     * @param string $status
44
-     *
45
-     * @return $this
46
-     */
47
-    public function byStatus($status)
48
-    {
49
-        $this->whereClause .= ' AND status = ?';
50
-        $this->parameterList[] = $status;
51
-
52
-        return $this;
53
-    }
54
-
55
-    public function statusIn($statuses)
56
-    {
57
-        $this->inClause('status', $statuses);
58
-
59
-        return $this;
60
-    }
61
-
62
-    /**
63
-     * @param string $role
64
-     *
65
-     * @return $this
66
-     */
67
-    public function byRole($role)
68
-    {
69
-        $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user';
70
-        $this->whereClause .= ' AND r.role = ?';
71
-        $this->parameterList[] = $role;
72
-
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * @param DateTime $instant
78
-     *
79
-     * @return $this
80
-     */
81
-    public function lastActiveBefore(DateTime $instant)
82
-    {
83
-        $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?';
84
-        $this->joinClause .= <<<'SQLFRAG'
18
+	/**
19
+	 * UserSearchHelper constructor.
20
+	 *
21
+	 * @param PdoDatabase $database
22
+	 */
23
+	public function __construct(PdoDatabase $database)
24
+	{
25
+		parent::__construct($database, 'user', User::class);
26
+	}
27
+
28
+	/**
29
+	 * Initiates a search for requests
30
+	 *
31
+	 * @param PdoDatabase $database
32
+	 *
33
+	 * @return UserSearchHelper
34
+	 */
35
+	public static function get(PdoDatabase $database)
36
+	{
37
+		$helper = new UserSearchHelper($database);
38
+
39
+		return $helper;
40
+	}
41
+
42
+	/**
43
+	 * @param string $status
44
+	 *
45
+	 * @return $this
46
+	 */
47
+	public function byStatus($status)
48
+	{
49
+		$this->whereClause .= ' AND status = ?';
50
+		$this->parameterList[] = $status;
51
+
52
+		return $this;
53
+	}
54
+
55
+	public function statusIn($statuses)
56
+	{
57
+		$this->inClause('status', $statuses);
58
+
59
+		return $this;
60
+	}
61
+
62
+	/**
63
+	 * @param string $role
64
+	 *
65
+	 * @return $this
66
+	 */
67
+	public function byRole($role)
68
+	{
69
+		$this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user';
70
+		$this->whereClause .= ' AND r.role = ?';
71
+		$this->parameterList[] = $role;
72
+
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * @param DateTime $instant
78
+	 *
79
+	 * @return $this
80
+	 */
81
+	public function lastActiveBefore(DateTime $instant)
82
+	{
83
+		$this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?';
84
+		$this->joinClause .= <<<'SQLFRAG'
85 85
  LEFT JOIN (
86 86
     SELECT objectid, MAX(timestamp) timestamp 
87 87
     FROM log
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
     GROUP BY objectid
90 90
     ) approvaldate ON approvaldate.objectid = origin.id
91 91
 SQLFRAG;
92
-        $formattedDate = $instant->format("Y-m-d H:i:s");
93
-        $this->parameterList[] = $formattedDate;
94
-        $this->parameterList[] = $formattedDate;
92
+		$formattedDate = $instant->format("Y-m-d H:i:s");
93
+		$this->parameterList[] = $formattedDate;
94
+		$this->parameterList[] = $formattedDate;
95 95
 
96
-        return $this;
97
-    }
96
+		return $this;
97
+	}
98 98
 
99
-    public function getRoleMap(&$roleMap)
100
-    {
101
-        $query = <<<SQL
99
+	public function getRoleMap(&$roleMap)
100
+	{
101
+		$query = <<<SQL
102 102
             SELECT /* UserSearchHelper/roleMap */ 
103 103
                   r.user user
104 104
                 , group_concat(r.role SEPARATOR ', ') roles 
@@ -107,22 +107,22 @@  discard block
 block discarded – undo
107 107
             GROUP BY r.user
108 108
 SQL;
109 109
 
110
-        $statement = $this->database->prepare($query);
111
-        $statement->execute($this->parameterList);
110
+		$statement = $this->database->prepare($query);
111
+		$statement->execute($this->parameterList);
112 112
 
113
-        $roleMap = array();
114
-        foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
115
-            $roleMap[$row['user']] = $row['roles'];
116
-        }
113
+		$roleMap = array();
114
+		foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
115
+			$roleMap[$row['user']] = $row['roles'];
116
+		}
117 117
 
118
-        return $this;
119
-    }
118
+		return $this;
119
+	}
120 120
 
121
-    public function withReservedRequest()
122
-    {
123
-        $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id';
124
-        $this->groupByClause = ' GROUP BY origin.id, origin.username';
121
+	public function withReservedRequest()
122
+	{
123
+		$this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id';
124
+		$this->groupByClause = ' GROUP BY origin.id, origin.username';
125 125
 
126
-        return $this->fetchMap('username');
127
-    }
126
+		return $this->fetchMap('username');
127
+	}
128 128
 }
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IMediaWikiClient.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
 
11 11
 interface IMediaWikiClient
12 12
 {
13
-    function doApiCall($params, $method);
13
+	function doApiCall($params, $method);
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Tasks/ApiPageBase.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
 
13 13
 abstract class ApiPageBase extends TaskBase implements IRoutedTask, IApiAction
14 14
 {
15
-    final public function execute()
16
-    {
17
-        $this->main();
18
-    }
15
+	final public function execute()
16
+	{
17
+		$this->main();
18
+	}
19 19
 
20
-    /**
21
-     * @param string $routeName
22
-     */
23
-    public function setRoute($routeName)
24
-    {
25
-        // no-op
26
-    }
20
+	/**
21
+	 * @param string $routeName
22
+	 */
23
+	public function setRoute($routeName)
24
+	{
25
+		// no-op
26
+	}
27 27
 
28
-    /**
29
-     * @return string
30
-     */
31
-    public function getRouteName()
32
-    {
33
-        return 'main';
34
-    }
28
+	/**
29
+	 * @return string
30
+	 */
31
+	public function getRouteName()
32
+	{
33
+		return 'main';
34
+	}
35 35
 }
Please login to merge, or discard this patch.
includes/Tasks/XmlApiPageBase.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 
18 18
 abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction
19 19
 {
20
-    /**
21
-     * API result document
22
-     * @var DOMDocument
23
-     */
24
-    protected $document;
25
-
26
-    public function __construct()
27
-    {
28
-        $this->document = new DOMDocument('1.0');
29
-    }
30
-
31
-    /**
32
-     * Main function for this page, when no specific actions are called.
33
-     *
34
-     * @throws ApiException
35
-     * @return void
36
-     */
37
-    final protected function main()
38
-    {
39
-        if (headers_sent()) {
40
-            throw new ApiException('Headers have already been sent - this indicates a bug in the application!');
41
-        }
42
-
43
-        header("Content-Type: text/xml");
44
-
45
-        // javascript access control
46
-        $httpOrigin = WebRequest::origin();
47
-
48
-        if ($httpOrigin !== null) {
49
-            $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts();
50
-
51
-            if (in_array($httpOrigin, $CORSallowed)) {
52
-                header("Access-Control-Allow-Origin: " . $httpOrigin);
53
-            }
54
-        }
55
-
56
-        $responseData = $this->runApiPage();
57
-
58
-        ob_end_clean();
59
-        print($responseData);
60
-        ob_start();
61
-    }
62
-
63
-    /**
64
-     * Method that runs API action
65
-     *
66
-     * @param DOMElement $apiDocument
67
-     *
68
-     * @return DOMElement
69
-     */
70
-    abstract public function executeApiAction(DOMElement $apiDocument);
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    final public function runApiPage()
76
-    {
77
-        $apiDocument = $this->document->createElement("api");
78
-
79
-        try {
80
-            $apiDocument = $this->executeApiAction($apiDocument);
81
-        }
82
-            /** @noinspection PhpRedundantCatchClauseInspection */
83
-        catch (ApiException $ex) {
84
-            $exception = $this->document->createElement("error");
85
-            $exception->setAttribute("message", $ex->getMessage());
86
-            $apiDocument->appendChild($exception);
87
-        }
88
-
89
-        $this->document->appendChild($apiDocument);
90
-
91
-        return $this->document->saveXML();
92
-    }
20
+	/**
21
+	 * API result document
22
+	 * @var DOMDocument
23
+	 */
24
+	protected $document;
25
+
26
+	public function __construct()
27
+	{
28
+		$this->document = new DOMDocument('1.0');
29
+	}
30
+
31
+	/**
32
+	 * Main function for this page, when no specific actions are called.
33
+	 *
34
+	 * @throws ApiException
35
+	 * @return void
36
+	 */
37
+	final protected function main()
38
+	{
39
+		if (headers_sent()) {
40
+			throw new ApiException('Headers have already been sent - this indicates a bug in the application!');
41
+		}
42
+
43
+		header("Content-Type: text/xml");
44
+
45
+		// javascript access control
46
+		$httpOrigin = WebRequest::origin();
47
+
48
+		if ($httpOrigin !== null) {
49
+			$CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts();
50
+
51
+			if (in_array($httpOrigin, $CORSallowed)) {
52
+				header("Access-Control-Allow-Origin: " . $httpOrigin);
53
+			}
54
+		}
55
+
56
+		$responseData = $this->runApiPage();
57
+
58
+		ob_end_clean();
59
+		print($responseData);
60
+		ob_start();
61
+	}
62
+
63
+	/**
64
+	 * Method that runs API action
65
+	 *
66
+	 * @param DOMElement $apiDocument
67
+	 *
68
+	 * @return DOMElement
69
+	 */
70
+	abstract public function executeApiAction(DOMElement $apiDocument);
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	final public function runApiPage()
76
+	{
77
+		$apiDocument = $this->document->createElement("api");
78
+
79
+		try {
80
+			$apiDocument = $this->executeApiAction($apiDocument);
81
+		}
82
+			/** @noinspection PhpRedundantCatchClauseInspection */
83
+		catch (ApiException $ex) {
84
+			$exception = $this->document->createElement("error");
85
+			$exception->setAttribute("message", $ex->getMessage());
86
+			$apiDocument->appendChild($exception);
87
+		}
88
+
89
+		$this->document->appendChild($apiDocument);
90
+
91
+		return $this->document->saveXML();
92
+	}
93 93
 }
Please login to merge, or discard this patch.
includes/ConsoleTasks/PrecacheGeolocationTask.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 
15 15
 class PrecacheGeolocationTask extends ConsoleTaskBase
16 16
 {
17
-    public function execute()
18
-    {
19
-        $database = $this->getDatabase();
20
-        $locationProvider = $this->getLocationProvider();
17
+	public function execute()
18
+	{
19
+		$database = $this->getDatabase();
20
+		$locationProvider = $this->getLocationProvider();
21 21
 
22
-        while (true) {
23
-            echo "Beginning txn\n";
24
-            $database->beginTransaction();
22
+		while (true) {
23
+			echo "Beginning txn\n";
24
+			$database->beginTransaction();
25 25
 
26
-            try {
27
-                echo ". Fetching data...\n";
26
+			try {
27
+				echo ". Fetching data...\n";
28 28
 
29
-                // fetch a bunch of un-geolocated IPs from the database.
30
-                // Note we have to parse the forwardedip field in the database so we can test against the geolocation
31
-                // table.
32
-                //
33
-                // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
34
-                //
35
-                // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an
36
-                // IN() clause dynamically, sending that back to the database to check if there are geolocation entries,
37
-                // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all
38
-                // IPs from the database before we find any at all. This way keeps all of that legwork in the database,
39
-                // at the cost of a more complex query.
40
-                $statement = $database->query(<<<SQL
29
+				// fetch a bunch of un-geolocated IPs from the database.
30
+				// Note we have to parse the forwardedip field in the database so we can test against the geolocation
31
+				// table.
32
+				//
33
+				// This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
34
+				//
35
+				// Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an
36
+				// IN() clause dynamically, sending that back to the database to check if there are geolocation entries,
37
+				// then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all
38
+				// IPs from the database before we find any at all. This way keeps all of that legwork in the database,
39
+				// at the cost of a more complex query.
40
+				$statement = $database->query(<<<SQL
41 41
                     SELECT /* PrecacheGeolocationTask */ p.prox
42 42
                     FROM (
43 43
                       SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox
@@ -54,42 +54,42 @@  discard block
 block discarded – undo
54 54
                     WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox FOR UPDATE)
55 55
                     LIMIT 10;
56 56
 SQL
57
-                );
57
+				);
58 58
 
59
-                $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
59
+				$missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
60 60
 
61
-                $count = count($missingIps);
62
-                if ($count === 0) {
63
-                    echo ". Found nothing to do.\n";
64
-                    break;
65
-                }
61
+				$count = count($missingIps);
62
+				if ($count === 0) {
63
+					echo ". Found nothing to do.\n";
64
+					break;
65
+				}
66 66
 
67
-                echo ". Picked {$count} IP addresses\n";
67
+				echo ". Picked {$count} IP addresses\n";
68 68
 
69
-                foreach ($missingIps as $ip) {
70
-                    echo ". . Getting location for {$ip}...\n";
71
-                    $data = json_encode($locationProvider->getIpLocation($ip));
72
-                    echo ". . . {$data}\n";
73
-                }
69
+				foreach ($missingIps as $ip) {
70
+					echo ". . Getting location for {$ip}...\n";
71
+					$data = json_encode($locationProvider->getIpLocation($ip));
72
+					echo ". . . {$data}\n";
73
+				}
74 74
 
75
-                echo ". IP location fetch complete.\n";
76
-                $database->commit();
77
-                echo ". Committed txn.\n";
78
-            }
79
-            catch (Exception $ex) {
80
-                echo ". Encountered exception: " . $ex->getMessage() . "\n";
81
-                $database->rollBack();
82
-                echo ". Rolled back txn\n";
83
-                throw $ex;
84
-            }
85
-            finally {
86
-                if ($database->hasActiveTransaction()) {
87
-                    $database->rollBack();
88
-                    echo ". Rolled back txn\n";
89
-                }
90
-            }
91
-        }
75
+				echo ". IP location fetch complete.\n";
76
+				$database->commit();
77
+				echo ". Committed txn.\n";
78
+			}
79
+			catch (Exception $ex) {
80
+				echo ". Encountered exception: " . $ex->getMessage() . "\n";
81
+				$database->rollBack();
82
+				echo ". Rolled back txn\n";
83
+				throw $ex;
84
+			}
85
+			finally {
86
+				if ($database->hasActiveTransaction()) {
87
+					$database->rollBack();
88
+					echo ". Rolled back txn\n";
89
+				}
90
+			}
91
+		}
92 92
 
93
-        echo "Done.\n";
94
-    }
93
+		echo "Done.\n";
94
+	}
95 95
 }
96 96
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IOAuthProtocolHelper.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -15,53 +15,53 @@
 block discarded – undo
15 15
 
16 16
 interface IOAuthProtocolHelper
17 17
 {
18
-    /**
19
-     * @return stdClass
20
-     *
21
-     * @throws Exception
22
-     * @throws CurlException
23
-     */
24
-    public function getRequestToken();
18
+	/**
19
+	 * @return stdClass
20
+	 *
21
+	 * @throws Exception
22
+	 * @throws CurlException
23
+	 */
24
+	public function getRequestToken();
25 25
 
26
-    /**
27
-     * @param string $requestToken
28
-     *
29
-     * @return string
30
-     */
31
-    public function getAuthoriseUrl($requestToken);
26
+	/**
27
+	 * @param string $requestToken
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function getAuthoriseUrl($requestToken);
32 32
 
33
-    /**
34
-     * @param string $oauthRequestToken
35
-     * @param string $oauthRequestSecret
36
-     * @param string $oauthVerifier
37
-     *
38
-     * @return stdClass
39
-     * @throws CurlException
40
-     * @throws Exception
41
-     */
42
-    public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier);
33
+	/**
34
+	 * @param string $oauthRequestToken
35
+	 * @param string $oauthRequestSecret
36
+	 * @param string $oauthVerifier
37
+	 *
38
+	 * @return stdClass
39
+	 * @throws CurlException
40
+	 * @throws Exception
41
+	 */
42
+	public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier);
43 43
 
44
-    /**
45
-     * @param string $oauthAccessToken
46
-     * @param string $oauthAccessSecret
47
-     *
48
-     * @return stdClass
49
-     * @throws CurlException
50
-     * @throws Exception
51
-     * @throws \MediaWiki\OAuthClient\Exception
52
-     */
53
-    public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret);
44
+	/**
45
+	 * @param string $oauthAccessToken
46
+	 * @param string $oauthAccessSecret
47
+	 *
48
+	 * @return stdClass
49
+	 * @throws CurlException
50
+	 * @throws Exception
51
+	 * @throws \MediaWiki\OAuthClient\Exception
52
+	 */
53
+	public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret);
54 54
 
55
-    /**
56
-     * @param array  $apiParams    array of parameters to send to the API
57
-     * @param string $accessToken  user's access token
58
-     * @param string $accessSecret user's secret
59
-     * @param string $method       HTTP method
60
-     *
61
-     * @return stdClass
62
-     * @throws ApplicationLogicException
63
-     * @throws CurlException
64
-     * @throws Exception
65
-     */
66
-    public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET');
55
+	/**
56
+	 * @param array  $apiParams    array of parameters to send to the API
57
+	 * @param string $accessToken  user's access token
58
+	 * @param string $accessSecret user's secret
59
+	 * @param string $method       HTTP method
60
+	 *
61
+	 * @return stdClass
62
+	 * @throws ApplicationLogicException
63
+	 * @throws CurlException
64
+	 * @throws Exception
65
+	 */
66
+	public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET');
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Providers/XffTrustProvider.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -22,156 +22,156 @@
 block discarded – undo
22 22
  */
23 23
 class XffTrustProvider implements IXffTrustProvider
24 24
 {
25
-    /**
26
-     * Array of IP addresses which are TRUSTED proxies
27
-     * @var string[]
28
-     */
29
-    private $trustedCache;
30
-    /**
31
-     * Array of IP addresses which are UNTRUSTED proxies
32
-     * @var string[]
33
-     */
34
-    private $untrustedCache = array();
35
-    /** @var PDOStatement */
36
-    private $trustedQuery;
37
-    /**
38
-     * @var PdoDatabase
39
-     */
40
-    private $database;
41
-
42
-    /**
43
-     * Creates a new instance of the trust provider
44
-     *
45
-     * @param string[]    $squidIpList List of IP addresses to pre-approve
46
-     * @param PdoDatabase $database
47
-     */
48
-    public function __construct($squidIpList, PdoDatabase $database)
49
-    {
50
-        $this->trustedCache = $squidIpList;
51
-        $this->database = $database;
52
-    }
53
-
54
-    /**
55
-     * Returns a value if the IP address is a trusted proxy
56
-     *
57
-     * @param string $ip
58
-     *
59
-     * @return bool
60
-     */
61
-    public function isTrusted($ip)
62
-    {
63
-        if (in_array($ip, $this->trustedCache)) {
64
-            return true;
65
-        }
66
-
67
-        if (in_array($ip, $this->untrustedCache)) {
68
-            return false;
69
-        }
70
-
71
-        if ($this->trustedQuery === null) {
72
-            $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;";
73
-            $this->trustedQuery = $this->database->prepare($query);
74
-        }
75
-
76
-        $this->trustedQuery->execute(array(":ip" => $ip));
77
-        $result = $this->trustedQuery->fetchColumn();
78
-        $this->trustedQuery->closeCursor();
79
-
80
-        if ($result == 0) {
81
-            $this->untrustedCache[] = $ip;
82
-
83
-            return false;
84
-        }
85
-
86
-        if ($result >= 1) {
87
-            $this->trustedCache[] = $ip;
88
-
89
-            return true;
90
-        }
91
-
92
-        // something weird has happened if we've got here.
93
-        // default to untrusted.
94
-        return false;
95
-    }
96
-
97
-    /**
98
-     * Gets the last trusted IP in the proxy chain.
99
-     *
100
-     * @param string $ip      The IP address from REMOTE_ADDR
101
-     * @param string $proxyIp The contents of the XFF header.
102
-     *
103
-     * @return string Trusted source IP address
104
-     */
105
-    public function getTrustedClientIp($ip, $proxyIp)
106
-    {
107
-        $clientIpAddress = $ip;
108
-        if ($proxyIp) {
109
-            $ipList = explode(",", $proxyIp);
110
-            $ipList[] = $clientIpAddress;
111
-            $ipList = array_reverse($ipList);
112
-
113
-            foreach ($ipList as $ipNumber => $ipAddress) {
114
-                if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) {
115
-                    continue;
116
-                }
117
-
118
-                $clientIpAddress = $ipAddress;
119
-                break;
120
-            }
121
-        }
122
-
123
-        return trim($clientIpAddress);
124
-    }
125
-
126
-    /**
127
-     * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them.
128
-     *
129
-     * @param array  $haystack
130
-     * @param string $ip
131
-     *
132
-     * @return bool
133
-     */
134
-    public function ipInRange($haystack, $ip)
135
-    {
136
-        $needle = ip2long($ip);
137
-
138
-        foreach ($haystack as $low => $high) {
139
-            if (ip2long($low) <= $needle && ip2long($high) >= $needle) {
140
-                return true;
141
-            }
142
-        }
143
-
144
-        return false;
145
-    }
146
-
147
-    /**
148
-     * Explodes a CIDR range into an array of addresses
149
-     *
150
-     * @param string $range A CIDR-format range
151
-     *
152
-     * @return array An array containing every IP address in the range
153
-     */
154
-    public function explodeCidr($range)
155
-    {
156
-        $cidrData = explode('/', $range);
157
-
158
-        if (!isset($cidrData[1])) {
159
-            return array($range);
160
-        }
161
-
162
-        $blow = (
163
-            str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) &
164
-            str_pad(str_pad("", $cidrData[1], "1"), 32, "0")
165
-        );
166
-        $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1"));
167
-
168
-        $list = array();
169
-
170
-        $bindecBHigh = bindec($bhigh);
171
-        for ($x = bindec($blow); $x <= $bindecBHigh; $x++) {
172
-            $list[] = long2ip($x);
173
-        }
174
-
175
-        return $list;
176
-    }
25
+	/**
26
+	 * Array of IP addresses which are TRUSTED proxies
27
+	 * @var string[]
28
+	 */
29
+	private $trustedCache;
30
+	/**
31
+	 * Array of IP addresses which are UNTRUSTED proxies
32
+	 * @var string[]
33
+	 */
34
+	private $untrustedCache = array();
35
+	/** @var PDOStatement */
36
+	private $trustedQuery;
37
+	/**
38
+	 * @var PdoDatabase
39
+	 */
40
+	private $database;
41
+
42
+	/**
43
+	 * Creates a new instance of the trust provider
44
+	 *
45
+	 * @param string[]    $squidIpList List of IP addresses to pre-approve
46
+	 * @param PdoDatabase $database
47
+	 */
48
+	public function __construct($squidIpList, PdoDatabase $database)
49
+	{
50
+		$this->trustedCache = $squidIpList;
51
+		$this->database = $database;
52
+	}
53
+
54
+	/**
55
+	 * Returns a value if the IP address is a trusted proxy
56
+	 *
57
+	 * @param string $ip
58
+	 *
59
+	 * @return bool
60
+	 */
61
+	public function isTrusted($ip)
62
+	{
63
+		if (in_array($ip, $this->trustedCache)) {
64
+			return true;
65
+		}
66
+
67
+		if (in_array($ip, $this->untrustedCache)) {
68
+			return false;
69
+		}
70
+
71
+		if ($this->trustedQuery === null) {
72
+			$query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;";
73
+			$this->trustedQuery = $this->database->prepare($query);
74
+		}
75
+
76
+		$this->trustedQuery->execute(array(":ip" => $ip));
77
+		$result = $this->trustedQuery->fetchColumn();
78
+		$this->trustedQuery->closeCursor();
79
+
80
+		if ($result == 0) {
81
+			$this->untrustedCache[] = $ip;
82
+
83
+			return false;
84
+		}
85
+
86
+		if ($result >= 1) {
87
+			$this->trustedCache[] = $ip;
88
+
89
+			return true;
90
+		}
91
+
92
+		// something weird has happened if we've got here.
93
+		// default to untrusted.
94
+		return false;
95
+	}
96
+
97
+	/**
98
+	 * Gets the last trusted IP in the proxy chain.
99
+	 *
100
+	 * @param string $ip      The IP address from REMOTE_ADDR
101
+	 * @param string $proxyIp The contents of the XFF header.
102
+	 *
103
+	 * @return string Trusted source IP address
104
+	 */
105
+	public function getTrustedClientIp($ip, $proxyIp)
106
+	{
107
+		$clientIpAddress = $ip;
108
+		if ($proxyIp) {
109
+			$ipList = explode(",", $proxyIp);
110
+			$ipList[] = $clientIpAddress;
111
+			$ipList = array_reverse($ipList);
112
+
113
+			foreach ($ipList as $ipNumber => $ipAddress) {
114
+				if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) {
115
+					continue;
116
+				}
117
+
118
+				$clientIpAddress = $ipAddress;
119
+				break;
120
+			}
121
+		}
122
+
123
+		return trim($clientIpAddress);
124
+	}
125
+
126
+	/**
127
+	 * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them.
128
+	 *
129
+	 * @param array  $haystack
130
+	 * @param string $ip
131
+	 *
132
+	 * @return bool
133
+	 */
134
+	public function ipInRange($haystack, $ip)
135
+	{
136
+		$needle = ip2long($ip);
137
+
138
+		foreach ($haystack as $low => $high) {
139
+			if (ip2long($low) <= $needle && ip2long($high) >= $needle) {
140
+				return true;
141
+			}
142
+		}
143
+
144
+		return false;
145
+	}
146
+
147
+	/**
148
+	 * Explodes a CIDR range into an array of addresses
149
+	 *
150
+	 * @param string $range A CIDR-format range
151
+	 *
152
+	 * @return array An array containing every IP address in the range
153
+	 */
154
+	public function explodeCidr($range)
155
+	{
156
+		$cidrData = explode('/', $range);
157
+
158
+		if (!isset($cidrData[1])) {
159
+			return array($range);
160
+		}
161
+
162
+		$blow = (
163
+			str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) &
164
+			str_pad(str_pad("", $cidrData[1], "1"), 32, "0")
165
+		);
166
+		$bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1"));
167
+
168
+		$list = array();
169
+
170
+		$bindecBHigh = bindec($bhigh);
171
+		for ($x = bindec($blow); $x <= $bindecBHigh; $x++) {
172
+			$list[] = long2ip($x);
173
+		}
174
+
175
+		return $list;
176
+	}
177 177
 }
Please login to merge, or discard this patch.
smarty-plugins/modifier.timespan.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -16,78 +16,78 @@
 block discarded – undo
16 16
  */
17 17
 function smarty_modifier_timespan($input)
18 18
 {
19
-    $remaining = abs(floor($input));
19
+	$remaining = abs(floor($input));
20 20
 
21
-    $seconds = $remaining % 60;
22
-    $remaining = $remaining - $seconds;
21
+	$seconds = $remaining % 60;
22
+	$remaining = $remaining - $seconds;
23 23
 
24
-    $minutes = $remaining % (60 * 60);
25
-    $remaining = $remaining - $minutes;
26
-    $minutes /= 60;
24
+	$minutes = $remaining % (60 * 60);
25
+	$remaining = $remaining - $minutes;
26
+	$minutes /= 60;
27 27
 
28
-    $hours = $remaining % (60 * 60 * 24);
29
-    $remaining = $remaining - $hours;
30
-    $hours /= (60 * 60);
28
+	$hours = $remaining % (60 * 60 * 24);
29
+	$remaining = $remaining - $hours;
30
+	$hours /= (60 * 60);
31 31
 
32
-    $days = $remaining % (60 * 60 * 24 * 7);
33
-    $weeks = $remaining - $days;
34
-    $days /= (60 * 60 * 24);
35
-    $weeks /= (60 * 60 * 24 * 7);
32
+	$days = $remaining % (60 * 60 * 24 * 7);
33
+	$weeks = $remaining - $days;
34
+	$days /= (60 * 60 * 24);
35
+	$weeks /= (60 * 60 * 24 * 7);
36 36
 
37
-    $stringval = '';
38
-    $trip = false;
37
+	$stringval = '';
38
+	$trip = false;
39 39
 
40
-    if ($weeks > 0) {
41
-        $stringval .= "${weeks}w ";
42
-    }
40
+	if ($weeks > 0) {
41
+		$stringval .= "${weeks}w ";
42
+	}
43 43
 
44
-    if ($days > 0) {
45
-        if ($stringval !== '') {
46
-            $trip = true;
47
-        }
44
+	if ($days > 0) {
45
+		if ($stringval !== '') {
46
+			$trip = true;
47
+		}
48 48
 
49
-        $stringval .= "${days}d ";
49
+		$stringval .= "${days}d ";
50 50
 
51
-        if ($trip) {
52
-            return trim($stringval);
53
-        }
54
-    }
51
+		if ($trip) {
52
+			return trim($stringval);
53
+		}
54
+	}
55 55
 
56
-    if ($hours > 0) {
57
-        if ($stringval !== '') {
58
-            $trip = true;
59
-        }
56
+	if ($hours > 0) {
57
+		if ($stringval !== '') {
58
+			$trip = true;
59
+		}
60 60
 
61
-        $stringval .= "${hours}h ";
61
+		$stringval .= "${hours}h ";
62 62
 
63
-        if ($trip) {
64
-            return trim($stringval);
65
-        }
66
-    }
63
+		if ($trip) {
64
+			return trim($stringval);
65
+		}
66
+	}
67 67
 
68
-    if ($minutes > 0) {
69
-        if ($stringval !== '') {
70
-            $trip = true;
71
-        }
68
+	if ($minutes > 0) {
69
+		if ($stringval !== '') {
70
+			$trip = true;
71
+		}
72 72
 
73
-        $stringval .= "${minutes}m ";
73
+		$stringval .= "${minutes}m ";
74 74
 
75
-        if ($trip) {
76
-            return trim($stringval);
77
-        }
78
-    }
75
+		if ($trip) {
76
+			return trim($stringval);
77
+		}
78
+	}
79 79
 
80
-    if ($seconds > 0) {
81
-        if ($stringval !== '') {
82
-            $trip = true;
83
-        }
80
+	if ($seconds > 0) {
81
+		if ($stringval !== '') {
82
+			$trip = true;
83
+		}
84 84
 
85
-        $stringval .= "${seconds}s ";
85
+		$stringval .= "${seconds}s ";
86 86
 
87
-        if ($trip) {
88
-            return trim($stringval);
89
-        }
90
-    }
87
+		if ($trip) {
88
+			return trim($stringval);
89
+		}
90
+	}
91 91
 
92
-    return trim($stringval);
92
+	return trim($stringval);
93 93
 }
94 94
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Validation/ValidationError.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -12,102 +12,102 @@
 block discarded – undo
12 12
 
13 13
 class ValidationError
14 14
 {
15
-    const NAME_EMPTY = "name_empty";
16
-    const NAME_TOO_LONG = "name_too_long";
17
-    const NAME_EXISTS = "name_exists";
18
-    const NAME_EXISTS_SUL = "name_exists_sul";
19
-    const NAME_NUMONLY = "name_numonly";
20
-    const NAME_INVALIDCHAR = "name_invalidchar";
21
-    const NAME_SANITISED = "name_sanitised";
22
-    const NAME_IP = "name_ip";
23
-    const EMAIL_EMPTY = "email_empty";
24
-    const EMAIL_WIKIMEDIA = "email_wikimedia";
25
-    const EMAIL_INVALID = "email_invalid";
26
-    const EMAIL_MISMATCH = "email_mismatch";
27
-    const OPEN_REQUEST_NAME = "open_request_name";
28
-    const BANNED = "banned";
29
-    const BANNED_TOR = "banned_tor";
30
-    /**
31
-     * @var array Error text for the above
32
-     */
33
-    private static $errorText = array(
34
-        self::NAME_EMPTY        => 'You\'ve not chosen a username!',
35
-        self::NAME_TOO_LONG     => 'Your chosen username is too long. Please choose a shorter one.',
36
-        self::NAME_EXISTS       => 'I\'m sorry, but the username you selected is already taken. Please try another. '
37
-            . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore '
38
-            . '[[User:example]] would become [[User:Example]].',
39
-        self::NAME_EXISTS_SUL   => 'I\'m sorry, but the username you selected is already taken. Please try another. '
40
-            . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore '
41
-            . '[[User:example]] would become [[User:Example]].',
42
-        self::NAME_NUMONLY      => 'The username you chose is invalid: it consists entirely of numbers. Please retry '
43
-            . 'with a valid username.',
44
-        self::NAME_INVALIDCHAR  => 'There appears to be an invalid character in your username. Please note that the '
45
-            . 'following characters are not allowed: <code># @ / &lt; &gt; [ ] | { }</code>',
46
-        self::NAME_SANITISED    => 'Your requested username has been automatically adjusted due to technical '
47
-            . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.',
48
-        self::NAME_IP           => 'The username you chose is invalid: it cannot be an IP address',
49
-        self::EMAIL_EMPTY       => 'You need to supply an email address.',
50
-        self::EMAIL_WIKIMEDIA   => 'Please provide your email address here.',
51
-        self::EMAIL_INVALID     => 'Invalid E-mail address supplied. Please check you entered it correctly.',
52
-        self::EMAIL_MISMATCH    => 'The email addresses you entered do not match. Please try again.',
53
-        self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.',
54
-        self::BANNED            => 'Sorry, you are currently banned from requesting accounts using this tool.',
55
-        self::BANNED_TOR        => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. '
56
-            . 'Please note that Tor is also currently banned from editing Wikipedia.',
57
-    );
58
-    /**
59
-     * Summary of $errorCode
60
-     * @var string
61
-     */
62
-    private $errorCode;
63
-    /**
64
-     * Summary of $isError
65
-     * @var bool
66
-     */
67
-    private $isError;
15
+	const NAME_EMPTY = "name_empty";
16
+	const NAME_TOO_LONG = "name_too_long";
17
+	const NAME_EXISTS = "name_exists";
18
+	const NAME_EXISTS_SUL = "name_exists_sul";
19
+	const NAME_NUMONLY = "name_numonly";
20
+	const NAME_INVALIDCHAR = "name_invalidchar";
21
+	const NAME_SANITISED = "name_sanitised";
22
+	const NAME_IP = "name_ip";
23
+	const EMAIL_EMPTY = "email_empty";
24
+	const EMAIL_WIKIMEDIA = "email_wikimedia";
25
+	const EMAIL_INVALID = "email_invalid";
26
+	const EMAIL_MISMATCH = "email_mismatch";
27
+	const OPEN_REQUEST_NAME = "open_request_name";
28
+	const BANNED = "banned";
29
+	const BANNED_TOR = "banned_tor";
30
+	/**
31
+	 * @var array Error text for the above
32
+	 */
33
+	private static $errorText = array(
34
+		self::NAME_EMPTY        => 'You\'ve not chosen a username!',
35
+		self::NAME_TOO_LONG     => 'Your chosen username is too long. Please choose a shorter one.',
36
+		self::NAME_EXISTS       => 'I\'m sorry, but the username you selected is already taken. Please try another. '
37
+			. 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore '
38
+			. '[[User:example]] would become [[User:Example]].',
39
+		self::NAME_EXISTS_SUL   => 'I\'m sorry, but the username you selected is already taken. Please try another. '
40
+			. 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore '
41
+			. '[[User:example]] would become [[User:Example]].',
42
+		self::NAME_NUMONLY      => 'The username you chose is invalid: it consists entirely of numbers. Please retry '
43
+			. 'with a valid username.',
44
+		self::NAME_INVALIDCHAR  => 'There appears to be an invalid character in your username. Please note that the '
45
+			. 'following characters are not allowed: <code># @ / &lt; &gt; [ ] | { }</code>',
46
+		self::NAME_SANITISED    => 'Your requested username has been automatically adjusted due to technical '
47
+			. 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.',
48
+		self::NAME_IP           => 'The username you chose is invalid: it cannot be an IP address',
49
+		self::EMAIL_EMPTY       => 'You need to supply an email address.',
50
+		self::EMAIL_WIKIMEDIA   => 'Please provide your email address here.',
51
+		self::EMAIL_INVALID     => 'Invalid E-mail address supplied. Please check you entered it correctly.',
52
+		self::EMAIL_MISMATCH    => 'The email addresses you entered do not match. Please try again.',
53
+		self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.',
54
+		self::BANNED            => 'Sorry, you are currently banned from requesting accounts using this tool.',
55
+		self::BANNED_TOR        => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. '
56
+			. 'Please note that Tor is also currently banned from editing Wikipedia.',
57
+	);
58
+	/**
59
+	 * Summary of $errorCode
60
+	 * @var string
61
+	 */
62
+	private $errorCode;
63
+	/**
64
+	 * Summary of $isError
65
+	 * @var bool
66
+	 */
67
+	private $isError;
68 68
 
69
-    /**
70
-     * Summary of __construct
71
-     *
72
-     * @param string $errorCode
73
-     * @param bool   $isError
74
-     */
75
-    public function __construct($errorCode, $isError = true)
76
-    {
77
-        $this->errorCode = $errorCode;
78
-        $this->isError = $isError;
79
-    }
69
+	/**
70
+	 * Summary of __construct
71
+	 *
72
+	 * @param string $errorCode
73
+	 * @param bool   $isError
74
+	 */
75
+	public function __construct($errorCode, $isError = true)
76
+	{
77
+		$this->errorCode = $errorCode;
78
+		$this->isError = $isError;
79
+	}
80 80
 
81
-    /**
82
-     * Summary of getErrorCode
83
-     * @return string
84
-     */
85
-    public function getErrorCode()
86
-    {
87
-        return $this->errorCode;
88
-    }
81
+	/**
82
+	 * Summary of getErrorCode
83
+	 * @return string
84
+	 */
85
+	public function getErrorCode()
86
+	{
87
+		return $this->errorCode;
88
+	}
89 89
 
90
-    /**
91
-     * @return string
92
-     * @throws Exception
93
-     */
94
-    public function getErrorMessage()
95
-    {
96
-        $text = self::$errorText[$this->errorCode];
90
+	/**
91
+	 * @return string
92
+	 * @throws Exception
93
+	 */
94
+	public function getErrorMessage()
95
+	{
96
+		$text = self::$errorText[$this->errorCode];
97 97
 
98
-        if ($text == null) {
99
-            throw new Exception('Unknown validation error');
100
-        }
98
+		if ($text == null) {
99
+			throw new Exception('Unknown validation error');
100
+		}
101 101
 
102
-        return $text;
103
-    }
102
+		return $text;
103
+	}
104 104
 
105
-    /**
106
-     * Summary of isError
107
-     * @return bool
108
-     */
109
-    public function isError()
110
-    {
111
-        return $this->isError;
112
-    }
105
+	/**
106
+	 * Summary of isError
107
+	 * @return bool
108
+	 */
109
+	public function isError()
110
+	{
111
+		return $this->isError;
112
+	}
113 113
 }
Please login to merge, or discard this patch.