Passed
Push — dependabot/composer/newinterna... ( 13eb18 )
by
unknown
04:37
created
includes/Providers/TorExitProvider.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@
 block discarded – undo
13 13
 
14 14
 class TorExitProvider
15 15
 {
16
-    /** @var PdoDatabase */
17
-    private $database;
18
-
19
-    /**
20
-     * TorExitProvider constructor.
21
-     *
22
-     * @param PdoDatabase $database
23
-     */
24
-    public function __construct(PdoDatabase $database)
25
-    {
26
-        $this->database = $database;
27
-    }
28
-
29
-    /**
30
-     * Checks whether an IP address is a Tor exit node for one of the pre-cached IP addresses.
31
-     *
32
-     * @param string $ip IP Address
33
-     *
34
-     * @return bool
35
-     */
36
-    public function isTorExit($ip)
37
-    {
38
-        $statement = $this->database->prepare('SELECT COUNT(1) FROM tornodecache WHERE ipaddr = :ip');
39
-
40
-        $statement->execute(array(':ip' => $ip));
41
-
42
-        $count = $statement->fetchColumn();
43
-        $statement->closeCursor();
44
-
45
-        if ($count > 0) {
46
-            return true;
47
-        }
48
-        else {
49
-            return false;
50
-        }
51
-    }
52
-
53
-    public static function regenerate(PdoDatabase $database, HttpHelper $httpHelper, $destinationIps)
54
-    {
55
-        $query = <<<SQL
16
+	/** @var PdoDatabase */
17
+	private $database;
18
+
19
+	/**
20
+	 * TorExitProvider constructor.
21
+	 *
22
+	 * @param PdoDatabase $database
23
+	 */
24
+	public function __construct(PdoDatabase $database)
25
+	{
26
+		$this->database = $database;
27
+	}
28
+
29
+	/**
30
+	 * Checks whether an IP address is a Tor exit node for one of the pre-cached IP addresses.
31
+	 *
32
+	 * @param string $ip IP Address
33
+	 *
34
+	 * @return bool
35
+	 */
36
+	public function isTorExit($ip)
37
+	{
38
+		$statement = $this->database->prepare('SELECT COUNT(1) FROM tornodecache WHERE ipaddr = :ip');
39
+
40
+		$statement->execute(array(':ip' => $ip));
41
+
42
+		$count = $statement->fetchColumn();
43
+		$statement->closeCursor();
44
+
45
+		if ($count > 0) {
46
+			return true;
47
+		}
48
+		else {
49
+			return false;
50
+		}
51
+	}
52
+
53
+	public static function regenerate(PdoDatabase $database, HttpHelper $httpHelper, $destinationIps)
54
+	{
55
+		$query = <<<SQL
56 56
 INSERT INTO tornodecache (ipaddr, exitaddr, exitport)
57 57
 VALUES (:ipaddr, :exitaddr, :exitport)
58 58
 ON DUPLICATE KEY
59 59
 UPDATE touched = CURRENT_TIMESTAMP, updateversion = updateversion + 1
60 60
 SQL;
61 61
 
62
-        $statement = $database->prepare($query);
62
+		$statement = $database->prepare($query);
63 63
 
64
-        foreach ($destinationIps as $ip) {
65
-            echo 'Fetching data for ' . $ip . PHP_EOL;
64
+		foreach ($destinationIps as $ip) {
65
+			echo 'Fetching data for ' . $ip . PHP_EOL;
66 66
 
67
-            $statement->bindValue(':exitaddr', $ip);
67
+			$statement->bindValue(':exitaddr', $ip);
68 68
 
69
-            $http = $httpHelper->get(
70
-                'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
71
-                array(
72
-                    'ip'   => $ip,
73
-                    'port' => 80,
74
-                ));
69
+			$http = $httpHelper->get(
70
+				'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
71
+				array(
72
+					'ip'   => $ip,
73
+					'port' => 80,
74
+				));
75 75
 
76
-            $https = $httpHelper->get(
77
-                'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
78
-                array(
79
-                    'ip'   => $ip,
80
-                    'port' => 443,
81
-                ));
76
+			$https = $httpHelper->get(
77
+				'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
78
+				array(
79
+					'ip'   => $ip,
80
+					'port' => 443,
81
+				));
82 82
 
83
-            foreach (array(80 => $http, 443 => $https) as $port => $response) {
84
-                echo '  Running for port ' . $ip . ':' . $port . PHP_EOL;
83
+			foreach (array(80 => $http, 443 => $https) as $port => $response) {
84
+				echo '  Running for port ' . $ip . ':' . $port . PHP_EOL;
85 85
 
86
-                $statement->bindValue(':exitport', $port);
86
+				$statement->bindValue(':exitport', $port);
87 87
 
88
-                $lines = explode("\n", $response);
88
+				$lines = explode("\n", $response);
89 89
 
90
-                foreach ($lines as $line) {
91
-                    // line contains a comment char, just skip the line.
92
-                    // This is OK as of 2016-04-06  --stw
93
-                    if (strpos($line, '#') !== false) {
94
-                        continue;
95
-                    }
90
+				foreach ($lines as $line) {
91
+					// line contains a comment char, just skip the line.
92
+					// This is OK as of 2016-04-06  --stw
93
+					if (strpos($line, '#') !== false) {
94
+						continue;
95
+					}
96 96
 
97
-                    $statement->bindValue(':ipaddr', $line);
98
-                    $statement->execute();
99
-                }
100
-            }
97
+					$statement->bindValue(':ipaddr', $line);
98
+					$statement->execute();
99
+				}
100
+			}
101 101
 
102
-            echo 'Done for ' . $ip . PHP_EOL;
103
-        }
102
+			echo 'Done for ' . $ip . PHP_EOL;
103
+		}
104 104
 
105
-        // kill old cached entries
106
-        $database->exec('DELETE FROM tornodecache WHERE touched < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)');
107
-    }
105
+		// kill old cached entries
106
+		$database->exec('DELETE FROM tornodecache WHERE touched < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)');
107
+	}
108 108
 }
109 109
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,8 +44,7 @@
 block discarded – undo
44 44
 
45 45
         if ($count > 0) {
46 46
             return true;
47
-        }
48
-        else {
47
+        } else {
49 48
             return false;
50 49
         }
51 50
     }
Please login to merge, or discard this patch.
includes/Providers/CachedApiAntispoofProvider.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -22,77 +22,77 @@
 block discarded – undo
22 22
  */
23 23
 class CachedApiAntispoofProvider implements IAntiSpoofProvider
24 24
 {
25
-    /**
26
-     * @var PdoDatabase
27
-     */
28
-    private $database;
29
-    /**
30
-     * @var string
31
-     */
32
-    private $mediawikiWebServiceEndpoint;
33
-    /**
34
-     * @var HttpHelper
35
-     */
36
-    private $httpHelper;
25
+	/**
26
+	 * @var PdoDatabase
27
+	 */
28
+	private $database;
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private $mediawikiWebServiceEndpoint;
33
+	/**
34
+	 * @var HttpHelper
35
+	 */
36
+	private $httpHelper;
37 37
 
38
-    public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper)
39
-    {
40
-        $this->database = $database;
41
-        $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
42
-        $this->httpHelper = $httpHelper;
43
-    }
38
+	public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper)
39
+	{
40
+		$this->database = $database;
41
+		$this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
42
+		$this->httpHelper = $httpHelper;
43
+	}
44 44
 
45
-    public function getSpoofs($username)
46
-    {
47
-        /** @var AntiSpoofCache $cacheResult */
48
-        $cacheResult = AntiSpoofCache::getByUsername($username, $this->database);
49
-        if ($cacheResult == false) {
50
-            // get the data from the API
51
-            $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array(
52
-                'action'   => 'antispoof',
53
-                'format'   => 'php',
54
-                'username' => $username,
55
-            ));
45
+	public function getSpoofs($username)
46
+	{
47
+		/** @var AntiSpoofCache $cacheResult */
48
+		$cacheResult = AntiSpoofCache::getByUsername($username, $this->database);
49
+		if ($cacheResult == false) {
50
+			// get the data from the API
51
+			$data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array(
52
+				'action'   => 'antispoof',
53
+				'format'   => 'php',
54
+				'username' => $username,
55
+			));
56 56
 
57
-            $cacheEntry = new AntiSpoofCache();
58
-            $cacheEntry->setDatabase($this->database);
59
-            $cacheEntry->setUsername($username);
60
-            $cacheEntry->setData($data);
61
-            $cacheEntry->save();
57
+			$cacheEntry = new AntiSpoofCache();
58
+			$cacheEntry->setDatabase($this->database);
59
+			$cacheEntry->setUsername($username);
60
+			$cacheEntry->setData($data);
61
+			$cacheEntry->save();
62 62
 
63
-            $cacheResult = $cacheEntry;
64
-        }
65
-        else {
66
-            $data = $cacheResult->getData();
67
-        }
63
+			$cacheResult = $cacheEntry;
64
+		}
65
+		else {
66
+			$data = $cacheResult->getData();
67
+		}
68 68
 
69
-        $result = unserialize($data);
69
+		$result = unserialize($data);
70 70
 
71
-        if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) {
72
-            $cacheResult->delete();
71
+		if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) {
72
+			$cacheResult->delete();
73 73
 
74
-            if (isset($result['error']['info'])) {
75
-                throw new Exception("Unrecognised API response to query: " . $result['error']['info']);
76
-            }
74
+			if (isset($result['error']['info'])) {
75
+				throw new Exception("Unrecognised API response to query: " . $result['error']['info']);
76
+			}
77 77
 
78
-            throw new Exception("Unrecognised API response to query.");
79
-        }
78
+			throw new Exception("Unrecognised API response to query.");
79
+		}
80 80
 
81
-        if ($result['antispoof']['result'] == "pass") {
82
-            // All good here!
83
-            return array();
84
-        }
81
+		if ($result['antispoof']['result'] == "pass") {
82
+			// All good here!
83
+			return array();
84
+		}
85 85
 
86
-        if ($result['antispoof']['result'] == "conflict") {
87
-            // we've got conflicts, let's do something with them.
88
-            return $result['antispoof']['users'];
89
-        }
86
+		if ($result['antispoof']['result'] == "conflict") {
87
+			// we've got conflicts, let's do something with them.
88
+			return $result['antispoof']['users'];
89
+		}
90 90
 
91
-        if ($result['antispoof']['result'] == "error") {
92
-            // we've got conflicts, let's do something with them.
93
-            throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']);
94
-        }
91
+		if ($result['antispoof']['result'] == "error") {
92
+			// we've got conflicts, let's do something with them.
93
+			throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']);
94
+		}
95 95
 
96
-        throw new Exception("Unrecognised API response to query.");
97
-    }
96
+		throw new Exception("Unrecognised API response to query.");
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,7 @@
 block discarded – undo
61 61
             $cacheEntry->save();
62 62
 
63 63
             $cacheResult = $cacheEntry;
64
-        }
65
-        else {
64
+        } else {
66 65
             $data = $cacheResult->getData();
67 66
         }
68 67
 
Please login to merge, or discard this patch.
includes/IdentificationVerifier.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -26,131 +26,131 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class IdentificationVerifier
28 28
 {
29
-    /**
30
-     * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia
31
-     * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard.  Note that URL encoding
32
-     * of these values is *not* necessary; this is done automatically.
33
-     *
34
-     * @var string[]
35
-     * @category Security-Critical
36
-     */
37
-    private static $apiQueryParameters = array(
38
-        'action'   => 'query',
39
-        'format'   => 'json',
40
-        'prop'     => 'links',
41
-        'titles'   => 'Access to nonpublic information policy/Noticeboard',
42
-        // Username of the user to be checked, with User: prefix, goes here!  Set in isIdentifiedOnWiki()
43
-        'pltitles' => '',
44
-    );
45
-    /** @var HttpHelper */
46
-    private $httpHelper;
47
-    /** @var SiteConfiguration */
48
-    private $siteConfiguration;
49
-    /** @var PdoDatabase */
50
-    private $dbObject;
51
-
52
-    /**
53
-     * IdentificationVerifier constructor.
54
-     *
55
-     * @param HttpHelper        $httpHelper
56
-     * @param SiteConfiguration $siteConfiguration
57
-     * @param PdoDatabase       $dbObject
58
-     */
59
-    public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
60
-    {
61
-        $this->httpHelper = $httpHelper;
62
-        $this->siteConfiguration = $siteConfiguration;
63
-        $this->dbObject = $dbObject;
64
-    }
65
-
66
-    /**
67
-     * Checks if the given user is identified to the Wikimedia Foundation.
68
-     *
69
-     * @param string $onWikiName The Wikipedia username of the user
70
-     *
71
-     * @return bool
72
-     * @category Security-Critical
73
-     */
74
-    public function isUserIdentified($onWikiName)
75
-    {
76
-        if ($this->checkIdentificationCache($onWikiName)) {
77
-            return true;
78
-        }
79
-        else {
80
-            if ($this->isIdentifiedOnWiki($onWikiName)) {
81
-                $this->cacheIdentificationStatus($onWikiName);
82
-
83
-                return true;
84
-            }
85
-            else {
86
-                return false;
87
-            }
88
-        }
89
-    }
90
-
91
-    /**
92
-     * Checks if the given user has a valid entry in the idcache table.
93
-     *
94
-     * @param string $onWikiName The Wikipedia username of the user
95
-     *
96
-     * @return bool
97
-     * @category Security-Critical
98
-     */
99
-    private function checkIdentificationCache($onWikiName)
100
-    {
101
-        $interval = $this->siteConfiguration->getIdentificationCacheExpiry();
102
-
103
-        $query = <<<SQL
29
+	/**
30
+	 * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia
31
+	 * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard.  Note that URL encoding
32
+	 * of these values is *not* necessary; this is done automatically.
33
+	 *
34
+	 * @var string[]
35
+	 * @category Security-Critical
36
+	 */
37
+	private static $apiQueryParameters = array(
38
+		'action'   => 'query',
39
+		'format'   => 'json',
40
+		'prop'     => 'links',
41
+		'titles'   => 'Access to nonpublic information policy/Noticeboard',
42
+		// Username of the user to be checked, with User: prefix, goes here!  Set in isIdentifiedOnWiki()
43
+		'pltitles' => '',
44
+	);
45
+	/** @var HttpHelper */
46
+	private $httpHelper;
47
+	/** @var SiteConfiguration */
48
+	private $siteConfiguration;
49
+	/** @var PdoDatabase */
50
+	private $dbObject;
51
+
52
+	/**
53
+	 * IdentificationVerifier constructor.
54
+	 *
55
+	 * @param HttpHelper        $httpHelper
56
+	 * @param SiteConfiguration $siteConfiguration
57
+	 * @param PdoDatabase       $dbObject
58
+	 */
59
+	public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
60
+	{
61
+		$this->httpHelper = $httpHelper;
62
+		$this->siteConfiguration = $siteConfiguration;
63
+		$this->dbObject = $dbObject;
64
+	}
65
+
66
+	/**
67
+	 * Checks if the given user is identified to the Wikimedia Foundation.
68
+	 *
69
+	 * @param string $onWikiName The Wikipedia username of the user
70
+	 *
71
+	 * @return bool
72
+	 * @category Security-Critical
73
+	 */
74
+	public function isUserIdentified($onWikiName)
75
+	{
76
+		if ($this->checkIdentificationCache($onWikiName)) {
77
+			return true;
78
+		}
79
+		else {
80
+			if ($this->isIdentifiedOnWiki($onWikiName)) {
81
+				$this->cacheIdentificationStatus($onWikiName);
82
+
83
+				return true;
84
+			}
85
+			else {
86
+				return false;
87
+			}
88
+		}
89
+	}
90
+
91
+	/**
92
+	 * Checks if the given user has a valid entry in the idcache table.
93
+	 *
94
+	 * @param string $onWikiName The Wikipedia username of the user
95
+	 *
96
+	 * @return bool
97
+	 * @category Security-Critical
98
+	 */
99
+	private function checkIdentificationCache($onWikiName)
100
+	{
101
+		$interval = $this->siteConfiguration->getIdentificationCacheExpiry();
102
+
103
+		$query = <<<SQL
104 104
 			SELECT COUNT(`id`)
105 105
 			FROM `idcache`
106 106
 			WHERE `onwikiusername` = :onwikiname
107 107
 				AND DATE_ADD(`checktime`, INTERVAL {$interval}) >= NOW();
108 108
 SQL;
109
-        $stmt = $this->dbObject->prepare($query);
110
-        $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
111
-        $stmt->execute();
112
-
113
-        // Guaranteed by the query to only return a single row with a single column
114
-        $results = $stmt->fetch(PDO::FETCH_NUM);
115
-
116
-        // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a
117
-        // unique key - but meh.
118
-        return $results[0] != 0;
119
-    }
120
-
121
-    /**
122
-     * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the
123
-     * idcache table.  Meant to be called periodically by a maintenance script.
124
-     *
125
-     * @param SiteConfiguration $siteConfiguration
126
-     * @param PdoDatabase       $dbObject
127
-     *
128
-     * @return void
129
-     */
130
-    public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
131
-    {
132
-        $interval = $siteConfiguration->getIdentificationCacheExpiry();
133
-
134
-        $query = <<<SQL
109
+		$stmt = $this->dbObject->prepare($query);
110
+		$stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
111
+		$stmt->execute();
112
+
113
+		// Guaranteed by the query to only return a single row with a single column
114
+		$results = $stmt->fetch(PDO::FETCH_NUM);
115
+
116
+		// I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a
117
+		// unique key - but meh.
118
+		return $results[0] != 0;
119
+	}
120
+
121
+	/**
122
+	 * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the
123
+	 * idcache table.  Meant to be called periodically by a maintenance script.
124
+	 *
125
+	 * @param SiteConfiguration $siteConfiguration
126
+	 * @param PdoDatabase       $dbObject
127
+	 *
128
+	 * @return void
129
+	 */
130
+	public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject)
131
+	{
132
+		$interval = $siteConfiguration->getIdentificationCacheExpiry();
133
+
134
+		$query = <<<SQL
135 135
 			DELETE FROM `idcache`
136 136
 			WHERE DATE_ADD(`checktime`, INTERVAL {$interval}) < NOW();
137 137
 SQL;
138
-        $dbObject->prepare($query)->execute();
139
-    }
140
-
141
-    /**
142
-     * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified.  This
143
-     * is so we don't have to hit the API every single time we check.  The cache entry is valid for as long as specified
144
-     * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()).
145
-     *
146
-     * @param string $onWikiName The Wikipedia username of the user
147
-     *
148
-     * @return void
149
-     * @category Security-Critical
150
-     */
151
-    private function cacheIdentificationStatus($onWikiName)
152
-    {
153
-        $query = <<<SQL
138
+		$dbObject->prepare($query)->execute();
139
+	}
140
+
141
+	/**
142
+	 * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified.  This
143
+	 * is so we don't have to hit the API every single time we check.  The cache entry is valid for as long as specified
144
+	 * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()).
145
+	 *
146
+	 * @param string $onWikiName The Wikipedia username of the user
147
+	 *
148
+	 * @return void
149
+	 * @category Security-Critical
150
+	 */
151
+	private function cacheIdentificationStatus($onWikiName)
152
+	{
153
+		$query = <<<SQL
154 154
 			INSERT INTO `idcache`
155 155
 				(`onwikiusername`)
156 156
 			VALUES
@@ -159,44 +159,44 @@  discard block
 block discarded – undo
159 159
 				`onwikiusername` = VALUES(`onwikiusername`),
160 160
 				`checktime` = CURRENT_TIMESTAMP;
161 161
 SQL;
162
-        $stmt = $this->dbObject->prepare($query);
163
-        $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
164
-        $stmt->execute();
165
-    }
166
-
167
-    /**
168
-     * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard.
169
-     *
170
-     * @param string $onWikiName The Wikipedia username of the user
171
-     *
172
-     * @return bool
173
-     * @throws EnvironmentException
174
-     * @category Security-Critical
175
-     */
176
-    private function isIdentifiedOnWiki($onWikiName)
177
-    {
178
-        $strings = new StringFunctions();
179
-
180
-        // First character of Wikipedia usernames is always capitalized.
181
-        $onWikiName = $strings->ucfirst($onWikiName);
182
-
183
-        $parameters = self::$apiQueryParameters;
184
-        $parameters['pltitles'] = "User:" . $onWikiName;
185
-
186
-        try {
187
-            $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint();
188
-            $response = $this->httpHelper->get($endpoint, $parameters);
189
-            $response = json_decode($response, true);
190
-        } catch (CurlException $ex) {
191
-            // failed getting identification status, so throw a nicer error.
192
-            $m = 'Could not contact metawiki API to determine user\' identification status. '
193
-                . 'This is probably a transient error, so please try again.';
194
-
195
-            throw new EnvironmentException($m, 0, $ex);
196
-        }
197
-
198
-        $page = @array_pop($response['query']['pages']);
199
-
200
-        return @$page['links'][0]['title'] === "User:" . $onWikiName;
201
-    }
162
+		$stmt = $this->dbObject->prepare($query);
163
+		$stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR);
164
+		$stmt->execute();
165
+	}
166
+
167
+	/**
168
+	 * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard.
169
+	 *
170
+	 * @param string $onWikiName The Wikipedia username of the user
171
+	 *
172
+	 * @return bool
173
+	 * @throws EnvironmentException
174
+	 * @category Security-Critical
175
+	 */
176
+	private function isIdentifiedOnWiki($onWikiName)
177
+	{
178
+		$strings = new StringFunctions();
179
+
180
+		// First character of Wikipedia usernames is always capitalized.
181
+		$onWikiName = $strings->ucfirst($onWikiName);
182
+
183
+		$parameters = self::$apiQueryParameters;
184
+		$parameters['pltitles'] = "User:" . $onWikiName;
185
+
186
+		try {
187
+			$endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint();
188
+			$response = $this->httpHelper->get($endpoint, $parameters);
189
+			$response = json_decode($response, true);
190
+		} catch (CurlException $ex) {
191
+			// failed getting identification status, so throw a nicer error.
192
+			$m = 'Could not contact metawiki API to determine user\' identification status. '
193
+				. 'This is probably a transient error, so please try again.';
194
+
195
+			throw new EnvironmentException($m, 0, $ex);
196
+		}
197
+
198
+		$page = @array_pop($response['query']['pages']);
199
+
200
+		return @$page['links'][0]['title'] === "User:" . $onWikiName;
201
+	}
202 202
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -75,14 +75,12 @@  discard block
 block discarded – undo
75 75
     {
76 76
         if ($this->checkIdentificationCache($onWikiName)) {
77 77
             return true;
78
-        }
79
-        else {
78
+        } else {
80 79
             if ($this->isIdentifiedOnWiki($onWikiName)) {
81 80
                 $this->cacheIdentificationStatus($onWikiName);
82 81
 
83 82
                 return true;
84
-            }
85
-            else {
83
+            } else {
86 84
                 return false;
87 85
             }
88 86
         }
@@ -187,7 +185,8 @@  discard block
 block discarded – undo
187 185
             $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint();
188 186
             $response = $this->httpHelper->get($endpoint, $parameters);
189 187
             $response = json_decode($response, true);
190
-        } catch (CurlException $ex) {
188
+        }
189
+        catch (CurlException $ex) {
191 190
             // failed getting identification status, so throw a nicer error.
192 191
             $m = 'Could not contact metawiki API to determine user\' identification status. '
193 192
                 . 'This is probably a transient error, so please try again.';
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearOldDataTask.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 
14 14
 class ClearOldDataTask extends ConsoleTaskBase
15 15
 {
16
-    public function execute()
17
-    {
18
-        $dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval();
16
+	public function execute()
17
+	{
18
+		$dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval();
19 19
 
20
-        $query = $this->getDatabase()->prepare(<<<SQL
20
+		$query = $this->getDatabase()->prepare(<<<SQL
21 21
 UPDATE request
22 22
 SET ip = :ip, forwardedip = null, email = :mail, useragent = ''
23 23
 WHERE date < DATE_SUB(curdate(), INTERVAL {$dataClearInterval})
24 24
 AND status = 'Closed';
25 25
 SQL
26
-        );
26
+		);
27 27
 
28
-        $success = $query->execute(array(
29
-            ":ip"   => $this->getSiteConfiguration()->getDataClearIp(),
30
-            ":mail" => $this->getSiteConfiguration()->getDataClearEmail(),
31
-        ));
28
+		$success = $query->execute(array(
29
+			":ip"   => $this->getSiteConfiguration()->getDataClearIp(),
30
+			":mail" => $this->getSiteConfiguration()->getDataClearEmail(),
31
+		));
32 32
 
33
-        if (!$success) {
34
-            throw new Exception("Error in transaction: Could not clear data.");
35
-        }
36
-    }
33
+		if (!$success) {
34
+			throw new Exception("Error in transaction: Could not clear data.");
35
+		}
36
+	}
37 37
 }
38 38
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearExpiredIdentificationData.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@
 block discarded – undo
13 13
 
14 14
 class ClearExpiredIdentificationData extends ConsoleTaskBase
15 15
 {
16
-    /**
17
-     * @return void
18
-     */
19
-    public function execute()
20
-    {
21
-        IdentificationVerifier::clearExpiredCacheEntries($this->getSiteConfiguration(), $this->getDatabase());
22
-    }
16
+	/**
17
+	 * @return void
18
+	 */
19
+	public function execute()
20
+	{
21
+		IdentificationVerifier::clearExpiredCacheEntries($this->getSiteConfiguration(), $this->getDatabase());
22
+	}
23 23
 }
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearOAuthDataTask.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 
13 13
 class ClearOAuthDataTask extends ConsoleTaskBase
14 14
 {
15
-    public function execute()
16
-    {
17
-        // @fixme this is unsafe.
18
-        // What we should be doing is iterating over all OAuth users, fetching their username, and updating the onwiki
19
-        // name for the user at the same time as blatting out the OAuth credentials, otherwise we risk losing all links
20
-        // to the user's onwiki account.
15
+	public function execute()
16
+	{
17
+		// @fixme this is unsafe.
18
+		// What we should be doing is iterating over all OAuth users, fetching their username, and updating the onwiki
19
+		// name for the user at the same time as blatting out the OAuth credentials, otherwise we risk losing all links
20
+		// to the user's onwiki account.
21 21
 
22
-        $this->getDatabase()->exec(<<<SQL
22
+		$this->getDatabase()->exec(<<<SQL
23 23
         UPDATE user
24 24
         SET
25 25
             oauthrequesttoken = NULL,
@@ -28,6 +28,6 @@  discard block
 block discarded – undo
28 28
             oauthaccesssecret = NULL,
29 29
             oauthidentitycache = NULL;
30 30
 SQL
31
-        );
32
-    }
31
+		);
32
+	}
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/OldRequestCleanupTask.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,28 +12,28 @@
 block discarded – undo
12 12
 
13 13
 class OldRequestCleanupTask extends ConsoleTaskBase
14 14
 {
15
-    private $expiryTime;
15
+	private $expiryTime;
16 16
 
17
-    /**
18
-     * OldRequestCleanupTask constructor.
19
-     */
20
-    public function __construct()
21
-    {
22
-        $this->expiryTime = $this->getSiteConfiguration()->getEmailConfirmationExpiryDays();
23
-    }
17
+	/**
18
+	 * OldRequestCleanupTask constructor.
19
+	 */
20
+	public function __construct()
21
+	{
22
+		$this->expiryTime = $this->getSiteConfiguration()->getEmailConfirmationExpiryDays();
23
+	}
24 24
 
25
-    public function execute()
26
-    {
27
-        $statement = $this->getDatabase()->prepare(<<<SQL
25
+	public function execute()
26
+	{
27
+		$statement = $this->getDatabase()->prepare(<<<SQL
28 28
             DELETE FROM request
29 29
             WHERE
30 30
                 date < DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL :expiry DAY)
31 31
                 AND emailconfirm != 'Confirmed'
32 32
                 AND emailconfirm != '';
33 33
 SQL
34
-        );
34
+		);
35 35
 
36
-        $statement->bindValue(':expiry', $this->expiryTime);
37
-        $statement->execute();
38
-    }
36
+		$statement->bindValue(':expiry', $this->expiryTime);
37
+		$statement->execute();
38
+	}
39 39
 }
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/RecreateTrustedIpTableTask.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -16,152 +16,152 @@
 block discarded – undo
16 16
 
17 17
 class RecreateTrustedIpTableTask extends ConsoleTaskBase
18 18
 {
19
-    public function execute()
20
-    {
21
-
22
-        echo "Fetching file...\n";
23
-
24
-        $htmlfile = file($this->getSiteConfiguration()->getXffTrustedHostsFile(),
25
-            FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
26
-
27
-        $ip = array();
28
-        $iprange = array();
29
-        $dnsdomain = array();
30
-
31
-        echo "Sorting file...\n";
32
-        $this->readFile($htmlfile, $iprange, $ip, $dnsdomain);
33
-
34
-        echo "Exploding CIDRs...\n";
35
-        $this->explodeCidrs($iprange, $ip);
36
-
37
-        echo "Resolving DNS...\n";
38
-        $this->resolveDns($dnsdomain, $ip);
39
-
40
-        echo "Uniq-ing array...\n";
41
-
42
-        $ip = array_unique($ip);
43
-
44
-        $database = $this->getDatabase();
45
-
46
-        $database->exec('DELETE FROM xfftrustcache;');
47
-
48
-        $insert = $database->prepare('INSERT INTO xfftrustcache (ip) VALUES (:ip);');
49
-
50
-        $this->doInserts($ip, $insert);
51
-    }
52
-
53
-    /**
54
-     * @param string[] $dnsDomains  the DNS domains to resolve
55
-     * @param string[] $ipAddresses existing array of IPs to add to
56
-     */
57
-    protected function resolveDns($dnsDomains, &$ipAddresses)
58
-    {
59
-        foreach ($dnsDomains as $domain) {
60
-            $ipList = gethostbynamel($domain);
61
-
62
-            if ($ipList === false) {
63
-                echo "Invalid DNS name $domain\n";
64
-                continue;
65
-            }
66
-
67
-            foreach ($ipList as $ipAddress) {
68
-                $ipAddresses[] = $ipAddress;
69
-            }
70
-
71
-            // don't DoS
72
-            usleep(10000);
73
-        }
74
-    }
75
-
76
-    /**
77
-     * @param $iprange
78
-     * @param $ip
79
-     */
80
-    protected function explodeCidrs($iprange, &$ip)
81
-    {
82
-        foreach ($iprange as $r) {
83
-            $ips = $this->getXffTrustProvider()->explodeCidr($r);
84
-
85
-            foreach ($ips as $i) {
86
-                $ip[] = $i;
87
-            }
88
-        }
89
-    }
90
-
91
-    /**
92
-     * @param $htmlfile
93
-     * @param $iprange
94
-     * @param $ip
95
-     * @param $dnsdomain
96
-     */
97
-    protected function readFile($htmlfile, &$iprange, &$ip, &$dnsdomain)
98
-    {
99
-        foreach ($htmlfile as $line_num => $rawline) {
100
-            // remove the comments
101
-            $hashPos = strpos($rawline, '#');
102
-            if ($hashPos !== false) {
103
-                $line = substr($rawline, 0, $hashPos);
104
-            }
105
-            else {
106
-                $line = $rawline;
107
-            }
108
-
109
-            $line = trim($line);
110
-
111
-            // this was a comment or empty line...
112
-            if ($line == "") {
113
-                continue;
114
-            }
115
-
116
-            // match a regex of an CIDR range:
117
-            $ipcidr = '@' . RegexConstants::IPV4 . RegexConstants::IPV4_CIDR . '@';
118
-            if (preg_match($ipcidr, $line) === 1) {
119
-                $iprange[] = $line;
120
-                continue;
121
-            }
122
-
123
-            $ipnoncidr = '@' . RegexConstants::IPV4 . '@';
124
-            if (preg_match($ipnoncidr, $line) === 1) {
125
-                $ip[] = $line;
126
-                continue;
127
-            }
128
-
129
-            // it's probably a DNS name.
130
-            $dnsdomain[] = $line;
131
-        }
132
-    }
133
-
134
-    /**
135
-     * @param array        $ip
136
-     * @param PDOStatement $insert
137
-     *
138
-     * @throws Exception
139
-     */
140
-    protected function doInserts($ip, PDOStatement $insert)
141
-    {
142
-        $successful = true;
143
-
144
-        foreach ($ip as $i) {
145
-            if (count($i) > 15) {
146
-                echo "Rejected $i\n";
147
-                $successful = false;
148
-
149
-                continue;
150
-            }
151
-
152
-            try {
153
-                $insert->execute(array(':ip' => $i));
154
-            }
155
-            catch (PDOException $ex) {
156
-                echo "Exception on $i :\n";
157
-                echo $ex->getMessage();
158
-                $successful = false;
159
-                break;
160
-            }
161
-        }
162
-
163
-        if (!$successful) {
164
-            throw new Exception('Encountered errors during transaction processing');
165
-        }
166
-    }
19
+	public function execute()
20
+	{
21
+
22
+		echo "Fetching file...\n";
23
+
24
+		$htmlfile = file($this->getSiteConfiguration()->getXffTrustedHostsFile(),
25
+			FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
26
+
27
+		$ip = array();
28
+		$iprange = array();
29
+		$dnsdomain = array();
30
+
31
+		echo "Sorting file...\n";
32
+		$this->readFile($htmlfile, $iprange, $ip, $dnsdomain);
33
+
34
+		echo "Exploding CIDRs...\n";
35
+		$this->explodeCidrs($iprange, $ip);
36
+
37
+		echo "Resolving DNS...\n";
38
+		$this->resolveDns($dnsdomain, $ip);
39
+
40
+		echo "Uniq-ing array...\n";
41
+
42
+		$ip = array_unique($ip);
43
+
44
+		$database = $this->getDatabase();
45
+
46
+		$database->exec('DELETE FROM xfftrustcache;');
47
+
48
+		$insert = $database->prepare('INSERT INTO xfftrustcache (ip) VALUES (:ip);');
49
+
50
+		$this->doInserts($ip, $insert);
51
+	}
52
+
53
+	/**
54
+	 * @param string[] $dnsDomains  the DNS domains to resolve
55
+	 * @param string[] $ipAddresses existing array of IPs to add to
56
+	 */
57
+	protected function resolveDns($dnsDomains, &$ipAddresses)
58
+	{
59
+		foreach ($dnsDomains as $domain) {
60
+			$ipList = gethostbynamel($domain);
61
+
62
+			if ($ipList === false) {
63
+				echo "Invalid DNS name $domain\n";
64
+				continue;
65
+			}
66
+
67
+			foreach ($ipList as $ipAddress) {
68
+				$ipAddresses[] = $ipAddress;
69
+			}
70
+
71
+			// don't DoS
72
+			usleep(10000);
73
+		}
74
+	}
75
+
76
+	/**
77
+	 * @param $iprange
78
+	 * @param $ip
79
+	 */
80
+	protected function explodeCidrs($iprange, &$ip)
81
+	{
82
+		foreach ($iprange as $r) {
83
+			$ips = $this->getXffTrustProvider()->explodeCidr($r);
84
+
85
+			foreach ($ips as $i) {
86
+				$ip[] = $i;
87
+			}
88
+		}
89
+	}
90
+
91
+	/**
92
+	 * @param $htmlfile
93
+	 * @param $iprange
94
+	 * @param $ip
95
+	 * @param $dnsdomain
96
+	 */
97
+	protected function readFile($htmlfile, &$iprange, &$ip, &$dnsdomain)
98
+	{
99
+		foreach ($htmlfile as $line_num => $rawline) {
100
+			// remove the comments
101
+			$hashPos = strpos($rawline, '#');
102
+			if ($hashPos !== false) {
103
+				$line = substr($rawline, 0, $hashPos);
104
+			}
105
+			else {
106
+				$line = $rawline;
107
+			}
108
+
109
+			$line = trim($line);
110
+
111
+			// this was a comment or empty line...
112
+			if ($line == "") {
113
+				continue;
114
+			}
115
+
116
+			// match a regex of an CIDR range:
117
+			$ipcidr = '@' . RegexConstants::IPV4 . RegexConstants::IPV4_CIDR . '@';
118
+			if (preg_match($ipcidr, $line) === 1) {
119
+				$iprange[] = $line;
120
+				continue;
121
+			}
122
+
123
+			$ipnoncidr = '@' . RegexConstants::IPV4 . '@';
124
+			if (preg_match($ipnoncidr, $line) === 1) {
125
+				$ip[] = $line;
126
+				continue;
127
+			}
128
+
129
+			// it's probably a DNS name.
130
+			$dnsdomain[] = $line;
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * @param array        $ip
136
+	 * @param PDOStatement $insert
137
+	 *
138
+	 * @throws Exception
139
+	 */
140
+	protected function doInserts($ip, PDOStatement $insert)
141
+	{
142
+		$successful = true;
143
+
144
+		foreach ($ip as $i) {
145
+			if (count($i) > 15) {
146
+				echo "Rejected $i\n";
147
+				$successful = false;
148
+
149
+				continue;
150
+			}
151
+
152
+			try {
153
+				$insert->execute(array(':ip' => $i));
154
+			}
155
+			catch (PDOException $ex) {
156
+				echo "Exception on $i :\n";
157
+				echo $ex->getMessage();
158
+				$successful = false;
159
+				break;
160
+			}
161
+		}
162
+
163
+		if (!$successful) {
164
+			throw new Exception('Encountered errors during transaction processing');
165
+		}
166
+	}
167 167
 }
168 168
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,8 +101,7 @@
 block discarded – undo
101 101
             $hashPos = strpos($rawline, '#');
102 102
             if ($hashPos !== false) {
103 103
                 $line = substr($rawline, 0, $hashPos);
104
-            }
105
-            else {
104
+            } else {
106 105
                 $line = $rawline;
107 106
             }
108 107
 
Please login to merge, or discard this patch.
includes/ConsoleTasks/MigrateToRoles.php 3 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
 
17 17
 class MigrateToRoles extends ConsoleTaskBase
18 18
 {
19
-    public function execute()
20
-    {
21
-        $communityUser = User::getCommunity();
19
+	public function execute()
20
+	{
21
+		$communityUser = User::getCommunity();
22 22
 
23
-        $database = $this->getDatabase();
24
-        $statement = $database->query('SELECT id, status, checkuser FROM user;');
25
-        $update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;");
23
+		$database = $this->getDatabase();
24
+		$statement = $database->query('SELECT id, status, checkuser FROM user;');
25
+		$update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;");
26 26
 
27
-        $users = $statement->fetchAll(PDO::FETCH_ASSOC);
27
+		$users = $statement->fetchAll(PDO::FETCH_ASSOC);
28 28
 
29
-        foreach ($users as $user) {
30
-            $toAdd = array('user');
29
+		foreach ($users as $user) {
30
+			$toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
33
-                $toAdd[] = 'admin';
34
-            }
32
+			if($user['status'] === 'Admin'){
33
+				$toAdd[] = 'admin';
34
+			}
35 35
 
36
-            if($user['checkuser'] == 1){
37
-                $toAdd[] = 'checkuser';
38
-            }
36
+			if($user['checkuser'] == 1){
37
+				$toAdd[] = 'checkuser';
38
+			}
39 39
 
40
-            foreach ($toAdd as $x) {
41
-                $a = new UserRole();
42
-                $a->setUser($user['id']);
43
-                $a->setRole($x);
44
-                $a->setDatabase($database);
45
-                $a->save();
46
-            }
40
+			foreach ($toAdd as $x) {
41
+				$a = new UserRole();
42
+				$a->setUser($user['id']);
43
+				$a->setRole($x);
44
+				$a->setDatabase($database);
45
+				$a->save();
46
+			}
47 47
 
48
-            $logData = serialize(array(
49
-                'added' => $toAdd,
50
-                'removed' => array(),
51
-                'reason' => 'Initial migration'
52
-            ));
48
+			$logData = serialize(array(
49
+				'added' => $toAdd,
50
+				'removed' => array(),
51
+				'reason' => 'Initial migration'
52
+			));
53 53
 
54
-            $log = new Log();
55
-            $log->setDatabase($database);
56
-            $log->setAction('RoleChange');
57
-            $log->setObjectId($user['id']);
58
-            $log->setObjectType('User');
59
-            $log->setUser($communityUser);
60
-            $log->setComment($logData);
61
-            $log->save();
54
+			$log = new Log();
55
+			$log->setDatabase($database);
56
+			$log->setAction('RoleChange');
57
+			$log->setObjectId($user['id']);
58
+			$log->setObjectType('User');
59
+			$log->setUser($communityUser);
60
+			$log->setComment($logData);
61
+			$log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
64
-                $update->execute(array('id' => $user['id']));
65
-            }
66
-        }
63
+			if($user['status'] === 'Admin' || $user['status'] === 'User'){
64
+				$update->execute(array('id' => $user['id']));
65
+			}
66
+		}
67 67
 
68
-        $database->exec("UPDATE schemaversion SET version = 25;");
69
-    }
68
+		$database->exec("UPDATE schemaversion SET version = 25;");
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         foreach ($users as $user) {
30 30
             $toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
32
+            if ($user['status'] === 'Admin') {
33 33
                 $toAdd[] = 'admin';
34 34
             }
35 35
 
36
-            if($user['checkuser'] == 1){
36
+            if ($user['checkuser'] == 1) {
37 37
                 $toAdd[] = 'checkuser';
38 38
             }
39 39
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $log->setComment($logData);
61 61
             $log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
63
+            if ($user['status'] === 'Admin' || $user['status'] === 'User') {
64 64
                 $update->execute(array('id' => $user['id']));
65 65
             }
66 66
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         foreach ($users as $user) {
30 30
             $toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
32
+            if($user['status'] === 'Admin') {
33 33
                 $toAdd[] = 'admin';
34 34
             }
35 35
 
36
-            if($user['checkuser'] == 1){
36
+            if($user['checkuser'] == 1) {
37 37
                 $toAdd[] = 'checkuser';
38 38
             }
39 39
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $log->setComment($logData);
61 61
             $log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
63
+            if($user['status'] === 'Admin' || $user['status'] === 'User') {
64 64
                 $update->execute(array('id' => $user['id']));
65 65
             }
66 66
         }
Please login to merge, or discard this patch.