Failed Conditions
Pull Request — newinternal-bugfixing (#286)
by Simon
06:57 queued 03:32
created
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.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,13 +114,13 @@
 block discarded – undo
114 114
             }
115 115
 
116 116
             // match a regex of an CIDR range:
117
-            $ipcidr = '@' . RegexConstants::IPV4 . RegexConstants::IPV4_CIDR . '@';
117
+            $ipcidr = '@'.RegexConstants::IPV4.RegexConstants::IPV4_CIDR.'@';
118 118
             if (preg_match($ipcidr, $line) === 1) {
119 119
                 $iprange[] = $line;
120 120
                 continue;
121 121
             }
122 122
 
123
-            $ipnoncidr = '@' . RegexConstants::IPV4 . '@';
123
+            $ipnoncidr = '@'.RegexConstants::IPV4.'@';
124 124
             if (preg_match($ipnoncidr, $line) === 1) {
125 125
                 $ip[] = $line;
126 126
                 continue;
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/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/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->setOAuthHelper(new OAuthHelper(
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->setOAuthHelper(new OAuthHelper(
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/RegexConstants.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class RegexConstants
12 12
 {
13
-    const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?';
14
-    const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?';
15
-    const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
16
-    const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
13
+	const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?';
14
+	const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?';
15
+	const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
16
+	const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/HttpHelper.php 2 patches
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -12,103 +12,103 @@
 block discarded – undo
12 12
 
13 13
 class HttpHelper
14 14
 {
15
-    private $curlHandle;
16
-
17
-    /**
18
-     * HttpHelper constructor.
19
-     *
20
-     * @param string  $userAgent
21
-     * @param boolean $disableVerifyPeer
22
-     */
23
-    public function __construct($userAgent, $disableVerifyPeer)
24
-    {
25
-        $this->curlHandle = curl_init();
26
-
27
-        curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
28
-        curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent);
29
-        curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true);
30
-
31
-        if ($disableVerifyPeer) {
32
-            curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
33
-        }
34
-    }
35
-
36
-    public function __destruct()
37
-    {
38
-        curl_close($this->curlHandle);
39
-    }
40
-
41
-    /**
42
-     * Fetches the content of a URL, with an optional parameter set.
43
-     *
44
-     * @param string     $url        The URL to fetch.
45
-     * @param null|array $parameters Key/value pair of GET parameters to add to the request.
46
-     *                               Null lets you handle it yourself.
47
-     *
48
-     * @param array      $headers
49
-     *
50
-     * @return string
51
-     * @throws CurlException
52
-     */
53
-    public function get($url, $parameters = null, $headers = array())
54
-    {
55
-        if ($parameters !== null && is_array($parameters)) {
56
-            $getString = '?' . http_build_query($parameters);
57
-            $url .= $getString;
58
-        }
59
-
60
-        curl_setopt($this->curlHandle, CURLOPT_URL, $url);
61
-
62
-        // Make sure we're doing a GET
63
-        curl_setopt($this->curlHandle, CURLOPT_POST, false);
64
-
65
-        curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
66
-
67
-        $result = curl_exec($this->curlHandle);
68
-
69
-        if ($result === false) {
70
-            $error = curl_error($this->curlHandle);
71
-            throw new CurlException('Remote request failed with error ' . $error);
72
-        }
73
-
74
-        return $result;
75
-    }
76
-
77
-    /**
78
-     * Posts data to a URL
79
-     *
80
-     * @param string $url        The URL to fetch.
81
-     * @param array  $parameters Key/value pair of POST parameters to add to the request.
82
-     * @param array  $headers
83
-     *
84
-     * @return string
85
-     * @throws CurlException
86
-     */
87
-    public function post($url, $parameters, $headers = array())
88
-    {
89
-        curl_setopt($this->curlHandle, CURLOPT_URL, $url);
90
-
91
-        // Make sure we're doing a POST
92
-        curl_setopt($this->curlHandle, CURLOPT_POST, true);
93
-        curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters));
94
-
95
-        curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
96
-
97
-        $result = curl_exec($this->curlHandle);
98
-
99
-        if ($result === false) {
100
-            $error = curl_error($this->curlHandle);
101
-            throw new CurlException('Remote request failed with error ' . $error);
102
-        }
103
-
104
-        return $result;
105
-    }
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function getError()
111
-    {
112
-        return curl_error($this->curlHandle);
113
-    }
15
+	private $curlHandle;
16
+
17
+	/**
18
+	 * HttpHelper constructor.
19
+	 *
20
+	 * @param string  $userAgent
21
+	 * @param boolean $disableVerifyPeer
22
+	 */
23
+	public function __construct($userAgent, $disableVerifyPeer)
24
+	{
25
+		$this->curlHandle = curl_init();
26
+
27
+		curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
28
+		curl_setopt($this->curlHandle, CURLOPT_USERAGENT, $userAgent);
29
+		curl_setopt($this->curlHandle, CURLOPT_FAILONERROR, true);
30
+
31
+		if ($disableVerifyPeer) {
32
+			curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
33
+		}
34
+	}
35
+
36
+	public function __destruct()
37
+	{
38
+		curl_close($this->curlHandle);
39
+	}
40
+
41
+	/**
42
+	 * Fetches the content of a URL, with an optional parameter set.
43
+	 *
44
+	 * @param string     $url        The URL to fetch.
45
+	 * @param null|array $parameters Key/value pair of GET parameters to add to the request.
46
+	 *                               Null lets you handle it yourself.
47
+	 *
48
+	 * @param array      $headers
49
+	 *
50
+	 * @return string
51
+	 * @throws CurlException
52
+	 */
53
+	public function get($url, $parameters = null, $headers = array())
54
+	{
55
+		if ($parameters !== null && is_array($parameters)) {
56
+			$getString = '?' . http_build_query($parameters);
57
+			$url .= $getString;
58
+		}
59
+
60
+		curl_setopt($this->curlHandle, CURLOPT_URL, $url);
61
+
62
+		// Make sure we're doing a GET
63
+		curl_setopt($this->curlHandle, CURLOPT_POST, false);
64
+
65
+		curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
66
+
67
+		$result = curl_exec($this->curlHandle);
68
+
69
+		if ($result === false) {
70
+			$error = curl_error($this->curlHandle);
71
+			throw new CurlException('Remote request failed with error ' . $error);
72
+		}
73
+
74
+		return $result;
75
+	}
76
+
77
+	/**
78
+	 * Posts data to a URL
79
+	 *
80
+	 * @param string $url        The URL to fetch.
81
+	 * @param array  $parameters Key/value pair of POST parameters to add to the request.
82
+	 * @param array  $headers
83
+	 *
84
+	 * @return string
85
+	 * @throws CurlException
86
+	 */
87
+	public function post($url, $parameters, $headers = array())
88
+	{
89
+		curl_setopt($this->curlHandle, CURLOPT_URL, $url);
90
+
91
+		// Make sure we're doing a POST
92
+		curl_setopt($this->curlHandle, CURLOPT_POST, true);
93
+		curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters));
94
+
95
+		curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, $headers);
96
+
97
+		$result = curl_exec($this->curlHandle);
98
+
99
+		if ($result === false) {
100
+			$error = curl_error($this->curlHandle);
101
+			throw new CurlException('Remote request failed with error ' . $error);
102
+		}
103
+
104
+		return $result;
105
+	}
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function getError()
111
+	{
112
+		return curl_error($this->curlHandle);
113
+	}
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public function get($url, $parameters = null, $headers = array())
54 54
     {
55 55
         if ($parameters !== null && is_array($parameters)) {
56
-            $getString = '?' . http_build_query($parameters);
56
+            $getString = '?'.http_build_query($parameters);
57 57
             $url .= $getString;
58 58
         }
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
         if ($result === false) {
70 70
             $error = curl_error($this->curlHandle);
71
-            throw new CurlException('Remote request failed with error ' . $error);
71
+            throw new CurlException('Remote request failed with error '.$error);
72 72
         }
73 73
 
74 74
         return $result;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
         if ($result === false) {
100 100
             $error = curl_error($this->curlHandle);
101
-            throw new CurlException('Remote request failed with error ' . $error);
101
+            throw new CurlException('Remote request failed with error '.$error);
102 102
         }
103 103
 
104 104
         return $result;
Please login to merge, or discard this patch.
includes/Helpers/SearchHelpers/RequestSearchHelper.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
     {
64 64
         $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
65 65
         $this->parameterList[] = $ipAddress;
66
-        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
66
+        $this->parameterList[] = '%'.trim($ipAddress, '%').'%';
67 67
 
68 68
         return $this;
69 69
     }
Please login to merge, or discard this patch.
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -14,117 +14,117 @@
 block discarded – undo
14 14
 
15 15
 class RequestSearchHelper extends SearchHelperBase
16 16
 {
17
-    /**
18
-     * RequestSearchHelper constructor.
19
-     *
20
-     * @param PdoDatabase $database
21
-     */
22
-    protected function __construct(PdoDatabase $database)
23
-    {
24
-        parent::__construct($database, 'request', Request::class);
25
-    }
26
-
27
-    /**
28
-     * Initiates a search for requests
29
-     *
30
-     * @param PdoDatabase $database
31
-     *
32
-     * @return RequestSearchHelper
33
-     */
34
-    public static function get(PdoDatabase $database)
35
-    {
36
-        $helper = new RequestSearchHelper($database);
37
-
38
-        return $helper;
39
-    }
40
-
41
-    /**
42
-     * Filters the results by IP address
43
-     *
44
-     * @param string $ipAddress
45
-     *
46
-     * @return $this
47
-     */
48
-    public function byIp($ipAddress)
49
-    {
50
-        $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
51
-        $this->parameterList[] = $ipAddress;
52
-        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
53
-
54
-        return $this;
55
-    }
56
-
57
-    /**
58
-     * Filters the results by email address
59
-     *
60
-     * @param string $emailAddress
61
-     *
62
-     * @return $this
63
-     */
64
-    public function byEmailAddress($emailAddress)
65
-    {
66
-        $this->whereClause .= ' AND email LIKE ?';
67
-        $this->parameterList[] = $emailAddress;
68
-
69
-        return $this;
70
-    }
71
-
72
-    /**
73
-     * Filters the results by name
74
-     *
75
-     * @param string $name
76
-     *
77
-     * @return $this
78
-     */
79
-    public function byName($name)
80
-    {
81
-        $this->whereClause .= ' AND name LIKE ?';
82
-        $this->parameterList[] = $name;
83
-
84
-        return $this;
85
-    }
86
-
87
-    /**
88
-     * Excludes a request from the results
89
-     *
90
-     * @param int $requestId
91
-     *
92
-     * @return $this
93
-     */
94
-    public function excludingRequest($requestId)
95
-    {
96
-        $this->whereClause .= ' AND id <> ?';
97
-        $this->parameterList[] = $requestId;
98
-
99
-        return $this;
100
-    }
101
-
102
-    /**
103
-     * Filters the results to only those with a confirmed email address
104
-     *
105
-     * @return $this
106
-     */
107
-    public function withConfirmedEmail()
108
-    {
109
-        $this->whereClause .= ' AND emailconfirm = ?';
110
-        $this->parameterList[] = 'Confirmed';
111
-
112
-        return $this;
113
-    }
114
-
115
-    /**
116
-     * Filters the results to exclude purged data
117
-     *
118
-     * @param SiteConfiguration $configuration
119
-     *
120
-     * @return $this
121
-     */
122
-    public function excludingPurgedData(SiteConfiguration $configuration)
123
-    {
124
-        $this->whereClause .= ' AND ip <> ? AND email <> ?';
125
-        $this->parameterList[] = $configuration->getDataClearIp();
126
-        $this->parameterList[] = $configuration->getDataClearEmail();
127
-
128
-        return $this;
129
-    }
17
+	/**
18
+	 * RequestSearchHelper constructor.
19
+	 *
20
+	 * @param PdoDatabase $database
21
+	 */
22
+	protected function __construct(PdoDatabase $database)
23
+	{
24
+		parent::__construct($database, 'request', Request::class);
25
+	}
26
+
27
+	/**
28
+	 * Initiates a search for requests
29
+	 *
30
+	 * @param PdoDatabase $database
31
+	 *
32
+	 * @return RequestSearchHelper
33
+	 */
34
+	public static function get(PdoDatabase $database)
35
+	{
36
+		$helper = new RequestSearchHelper($database);
37
+
38
+		return $helper;
39
+	}
40
+
41
+	/**
42
+	 * Filters the results by IP address
43
+	 *
44
+	 * @param string $ipAddress
45
+	 *
46
+	 * @return $this
47
+	 */
48
+	public function byIp($ipAddress)
49
+	{
50
+		$this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
51
+		$this->parameterList[] = $ipAddress;
52
+		$this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
53
+
54
+		return $this;
55
+	}
56
+
57
+	/**
58
+	 * Filters the results by email address
59
+	 *
60
+	 * @param string $emailAddress
61
+	 *
62
+	 * @return $this
63
+	 */
64
+	public function byEmailAddress($emailAddress)
65
+	{
66
+		$this->whereClause .= ' AND email LIKE ?';
67
+		$this->parameterList[] = $emailAddress;
68
+
69
+		return $this;
70
+	}
71
+
72
+	/**
73
+	 * Filters the results by name
74
+	 *
75
+	 * @param string $name
76
+	 *
77
+	 * @return $this
78
+	 */
79
+	public function byName($name)
80
+	{
81
+		$this->whereClause .= ' AND name LIKE ?';
82
+		$this->parameterList[] = $name;
83
+
84
+		return $this;
85
+	}
86
+
87
+	/**
88
+	 * Excludes a request from the results
89
+	 *
90
+	 * @param int $requestId
91
+	 *
92
+	 * @return $this
93
+	 */
94
+	public function excludingRequest($requestId)
95
+	{
96
+		$this->whereClause .= ' AND id <> ?';
97
+		$this->parameterList[] = $requestId;
98
+
99
+		return $this;
100
+	}
101
+
102
+	/**
103
+	 * Filters the results to only those with a confirmed email address
104
+	 *
105
+	 * @return $this
106
+	 */
107
+	public function withConfirmedEmail()
108
+	{
109
+		$this->whereClause .= ' AND emailconfirm = ?';
110
+		$this->parameterList[] = 'Confirmed';
111
+
112
+		return $this;
113
+	}
114
+
115
+	/**
116
+	 * Filters the results to exclude purged data
117
+	 *
118
+	 * @param SiteConfiguration $configuration
119
+	 *
120
+	 * @return $this
121
+	 */
122
+	public function excludingPurgedData(SiteConfiguration $configuration)
123
+	{
124
+		$this->whereClause .= ' AND ip <> ? AND email <> ?';
125
+		$this->parameterList[] = $configuration->getDataClearIp();
126
+		$this->parameterList[] = $configuration->getDataClearEmail();
127
+
128
+		return $this;
129
+	}
130 130
 }
131 131
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/WikiTextHelper.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -12,52 +12,52 @@
 block discarded – undo
12 12
 
13 13
 class WikiTextHelper
14 14
 {
15
-    /**
16
-     * @var SiteConfiguration
17
-     */
18
-    private $configuration;
19
-    /**
20
-     * @var HttpHelper
21
-     */
22
-    private $http;
23
-
24
-    /**
25
-     * WikiTextHelper constructor.
26
-     *
27
-     * @param SiteConfiguration $configuration
28
-     * @param HttpHelper        $http
29
-     */
30
-    public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
-    {
32
-        $this->configuration = $configuration;
33
-        $this->http = $http;
34
-    }
35
-
36
-    /**
37
-     * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
-     *
39
-     * @param string $wikiText
40
-     *
41
-     * @return string
42
-     */
43
-    public function getHtmlForWikiText($wikiText)
44
-    {
45
-        $endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
-
47
-        $parameters = array(
48
-            'action'             => 'parse',
49
-            'pst'                => true,
50
-            'contentmodel'       => 'wikitext',
51
-            'disablelimitreport' => true,
52
-            'disabletoc'         => true,
53
-            'disableeditsection' => true,
54
-            'format'             => 'php',
55
-            'text'               => $wikiText,
56
-        );
57
-
58
-        $apiResult = $this->http->get($endpoint, $parameters);
59
-        $parseResult = unserialize($apiResult);
60
-
61
-        return $parseResult['parse']['text']['*'];
62
-    }
15
+	/**
16
+	 * @var SiteConfiguration
17
+	 */
18
+	private $configuration;
19
+	/**
20
+	 * @var HttpHelper
21
+	 */
22
+	private $http;
23
+
24
+	/**
25
+	 * WikiTextHelper constructor.
26
+	 *
27
+	 * @param SiteConfiguration $configuration
28
+	 * @param HttpHelper        $http
29
+	 */
30
+	public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
+	{
32
+		$this->configuration = $configuration;
33
+		$this->http = $http;
34
+	}
35
+
36
+	/**
37
+	 * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
+	 *
39
+	 * @param string $wikiText
40
+	 *
41
+	 * @return string
42
+	 */
43
+	public function getHtmlForWikiText($wikiText)
44
+	{
45
+		$endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
+
47
+		$parameters = array(
48
+			'action'             => 'parse',
49
+			'pst'                => true,
50
+			'contentmodel'       => 'wikitext',
51
+			'disablelimitreport' => true,
52
+			'disabletoc'         => true,
53
+			'disableeditsection' => true,
54
+			'format'             => 'php',
55
+			'text'               => $wikiText,
56
+		);
57
+
58
+		$apiResult = $this->http->get($endpoint, $parameters);
59
+		$parseResult = unserialize($apiResult);
60
+
61
+		return $parseResult['parse']['text']['*'];
62
+	}
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/OAuthHelper.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -21,231 +21,231 @@
 block discarded – undo
21 21
 
22 22
 class OAuthHelper implements IOAuthHelper
23 23
 {
24
-    private $oauthConsumer;
25
-    /**
26
-     * @var string
27
-     */
28
-    private $oauthEndpoint;
29
-    /**
30
-     * @var string
31
-     */
32
-    private $consumerToken;
33
-    /**
34
-     * @var string
35
-     */
36
-    private $consumerSecret;
37
-    /**
38
-     * @var HttpHelper
39
-     */
40
-    private $httpHelper;
41
-    /**
42
-     * @var string
43
-     */
44
-    private $mediawikiWebServiceEndpoint;
45
-
46
-    /**
47
-     * OAuthHelper constructor.
48
-     *
49
-     * @param string     $oauthEndpoint
50
-     * @param string     $consumerKey
51
-     * @param string     $consumerSecret
52
-     * @param HttpHelper $httpHelper
53
-     * @param string     $mediawikiWebServiceEndpoint
54
-     */
55
-    public function __construct(
56
-        $oauthEndpoint,
57
-        $consumerKey,
58
-        $consumerSecret,
59
-        HttpHelper $httpHelper,
60
-        $mediawikiWebServiceEndpoint
61
-    ) {
62
-        $this->oauthEndpoint = $oauthEndpoint;
63
-        $this->consumerToken = $consumerKey;
64
-        $this->consumerSecret = $consumerSecret;
65
-        $this->httpHelper = $httpHelper;
66
-
67
-        $this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret);
68
-        $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
69
-    }
70
-
71
-    /**
72
-     * @return stdClass
73
-     *
74
-     * @throws Exception
75
-     * @throws CurlException
76
-     */
77
-    public function getRequestToken()
78
-    {
79
-        $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
80
-
81
-        $parsedUrl = parse_url($endpoint);
82
-        $urlParameters = array();
83
-        parse_str($parsedUrl['query'], $urlParameters);
84
-
85
-        $req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters);
86
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
87
-        $req_req->sign_request($hmac_method, $this->oauthConsumer, null);
88
-
89
-        $targetUrl = (string)$req_req;
90
-
91
-        $data = $this->httpHelper->get($targetUrl, null);
92
-
93
-        if ($data === false) {
94
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
95
-        }
96
-
97
-        $token = json_decode($data);
98
-
99
-        if (!isset($token)) {
100
-            throw new Exception('Unknown error encountered getting request token while decoding json data.');
101
-        }
102
-
103
-        if (isset($token->error)) {
104
-            throw new Exception('Error encountered while getting request token: ' . $token->error);
105
-        }
106
-
107
-        return $token;
108
-    }
109
-
110
-    /**
111
-     * @param string $requestToken
112
-     *
113
-     * @return string
114
-     */
115
-    public function getAuthoriseUrl($requestToken)
116
-    {
117
-        return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}";
118
-    }
119
-
120
-    /**
121
-     * @param string $oauthRequestToken
122
-     * @param string $oauthRequestSecret
123
-     * @param string $oauthVerifier
124
-     *
125
-     * @return stdClass
126
-     * @throws CurlException
127
-     * @throws Exception
128
-     */
129
-    public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130
-    {
131
-        $endpoint = $this->oauthEndpoint . '/token&format=json';
132
-
133
-        $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134
-
135
-        $parsedUrl = parse_url($endpoint);
136
-        parse_str($parsedUrl['query'], $urlParameters);
137
-        $urlParameters['oauth_verifier'] = trim($oauthVerifier);
138
-
139
-        $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint,
140
-            $urlParameters);
141
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
142
-        $acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer);
143
-
144
-        $targetUrl = (string)$acc_req;
145
-
146
-        $data = $this->httpHelper->get($targetUrl, null);
147
-
148
-        if ($data === false) {
149
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
150
-        }
151
-
152
-        $token = json_decode($data);
153
-
154
-        if (!isset($token)) {
155
-            throw new Exception('Unknown error encountered getting access token while decoding json data.');
156
-        }
157
-
158
-        if (isset($token->error)) {
159
-            throw new Exception('Error encountered while getting access token: ' . $token->error);
160
-        }
161
-
162
-        return $token;
163
-    }
164
-
165
-    /**
166
-     * @param string $oauthAccessToken
167
-     * @param string $oauthAccessSecret
168
-     *
169
-     * @return JWT
170
-     * @throws CurlException
171
-     * @throws Exception
172
-     */
173
-    public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174
-    {
175
-        $endpoint = $this->oauthEndpoint . '/identify&format=json';
176
-
177
-        $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178
-
179
-        $parsedUrl = parse_url($endpoint);
180
-        parse_str($parsedUrl['query'], $urlParameters);
181
-
182
-        $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint,
183
-            $urlParameters);
184
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
185
-        $acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken);
186
-
187
-        $targetUrl = (string)$acc_req;
188
-
189
-        $data = $this->httpHelper->get($targetUrl, null);
190
-
191
-        if ($data === false) {
192
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
193
-        }
194
-
195
-        $decodedData = json_decode($data);
196
-
197
-        if (isset($decodedData->error)) {
198
-            throw new Exception($decodedData->error);
199
-        }
200
-
201
-        $identity = JWT::decode($data, $this->consumerSecret);
202
-
203
-        return $identity;
204
-    }
205
-
206
-    /**
207
-     * @param array  $apiParams    array of parameters to send to the API
208
-     * @param string $accessToken  user's access token
209
-     * @param string $accessSecret user's secret
210
-     * @param string $method       HTTP method
211
-     *
212
-     * @return stdClass
213
-     * @throws ApplicationLogicException
214
-     * @throws CurlException
215
-     * @throws Exception
216
-     */
217
-    public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET')
218
-    {
219
-        $userToken = new OAuthToken($accessToken, $accessSecret);
220
-
221
-        $apiParams['format'] = 'json';
222
-
223
-        $api_req = OAuthRequest::from_consumer_and_token(
224
-            $this->oauthConsumer, // Consumer
225
-            $userToken, // User Access Token
226
-            $method, // HTTP Method
227
-            $this->mediawikiWebServiceEndpoint, // Endpoint url
228
-            $apiParams    // Extra signed parameters
229
-        );
230
-
231
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
24
+	private $oauthConsumer;
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $oauthEndpoint;
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private $consumerToken;
33
+	/**
34
+	 * @var string
35
+	 */
36
+	private $consumerSecret;
37
+	/**
38
+	 * @var HttpHelper
39
+	 */
40
+	private $httpHelper;
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private $mediawikiWebServiceEndpoint;
45
+
46
+	/**
47
+	 * OAuthHelper constructor.
48
+	 *
49
+	 * @param string     $oauthEndpoint
50
+	 * @param string     $consumerKey
51
+	 * @param string     $consumerSecret
52
+	 * @param HttpHelper $httpHelper
53
+	 * @param string     $mediawikiWebServiceEndpoint
54
+	 */
55
+	public function __construct(
56
+		$oauthEndpoint,
57
+		$consumerKey,
58
+		$consumerSecret,
59
+		HttpHelper $httpHelper,
60
+		$mediawikiWebServiceEndpoint
61
+	) {
62
+		$this->oauthEndpoint = $oauthEndpoint;
63
+		$this->consumerToken = $consumerKey;
64
+		$this->consumerSecret = $consumerSecret;
65
+		$this->httpHelper = $httpHelper;
66
+
67
+		$this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret);
68
+		$this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint;
69
+	}
70
+
71
+	/**
72
+	 * @return stdClass
73
+	 *
74
+	 * @throws Exception
75
+	 * @throws CurlException
76
+	 */
77
+	public function getRequestToken()
78
+	{
79
+		$endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
80
+
81
+		$parsedUrl = parse_url($endpoint);
82
+		$urlParameters = array();
83
+		parse_str($parsedUrl['query'], $urlParameters);
84
+
85
+		$req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters);
86
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
87
+		$req_req->sign_request($hmac_method, $this->oauthConsumer, null);
88
+
89
+		$targetUrl = (string)$req_req;
90
+
91
+		$data = $this->httpHelper->get($targetUrl, null);
92
+
93
+		if ($data === false) {
94
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
95
+		}
96
+
97
+		$token = json_decode($data);
98
+
99
+		if (!isset($token)) {
100
+			throw new Exception('Unknown error encountered getting request token while decoding json data.');
101
+		}
102
+
103
+		if (isset($token->error)) {
104
+			throw new Exception('Error encountered while getting request token: ' . $token->error);
105
+		}
106
+
107
+		return $token;
108
+	}
109
+
110
+	/**
111
+	 * @param string $requestToken
112
+	 *
113
+	 * @return string
114
+	 */
115
+	public function getAuthoriseUrl($requestToken)
116
+	{
117
+		return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}";
118
+	}
119
+
120
+	/**
121
+	 * @param string $oauthRequestToken
122
+	 * @param string $oauthRequestSecret
123
+	 * @param string $oauthVerifier
124
+	 *
125
+	 * @return stdClass
126
+	 * @throws CurlException
127
+	 * @throws Exception
128
+	 */
129
+	public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130
+	{
131
+		$endpoint = $this->oauthEndpoint . '/token&format=json';
132
+
133
+		$requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134
+
135
+		$parsedUrl = parse_url($endpoint);
136
+		parse_str($parsedUrl['query'], $urlParameters);
137
+		$urlParameters['oauth_verifier'] = trim($oauthVerifier);
138
+
139
+		$acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint,
140
+			$urlParameters);
141
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
142
+		$acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer);
143
+
144
+		$targetUrl = (string)$acc_req;
145
+
146
+		$data = $this->httpHelper->get($targetUrl, null);
147
+
148
+		if ($data === false) {
149
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
150
+		}
151
+
152
+		$token = json_decode($data);
153
+
154
+		if (!isset($token)) {
155
+			throw new Exception('Unknown error encountered getting access token while decoding json data.');
156
+		}
157
+
158
+		if (isset($token->error)) {
159
+			throw new Exception('Error encountered while getting access token: ' . $token->error);
160
+		}
161
+
162
+		return $token;
163
+	}
164
+
165
+	/**
166
+	 * @param string $oauthAccessToken
167
+	 * @param string $oauthAccessSecret
168
+	 *
169
+	 * @return JWT
170
+	 * @throws CurlException
171
+	 * @throws Exception
172
+	 */
173
+	public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174
+	{
175
+		$endpoint = $this->oauthEndpoint . '/identify&format=json';
176
+
177
+		$oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178
+
179
+		$parsedUrl = parse_url($endpoint);
180
+		parse_str($parsedUrl['query'], $urlParameters);
181
+
182
+		$acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint,
183
+			$urlParameters);
184
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
185
+		$acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken);
186
+
187
+		$targetUrl = (string)$acc_req;
188
+
189
+		$data = $this->httpHelper->get($targetUrl, null);
190
+
191
+		if ($data === false) {
192
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
193
+		}
194
+
195
+		$decodedData = json_decode($data);
196
+
197
+		if (isset($decodedData->error)) {
198
+			throw new Exception($decodedData->error);
199
+		}
200
+
201
+		$identity = JWT::decode($data, $this->consumerSecret);
202
+
203
+		return $identity;
204
+	}
205
+
206
+	/**
207
+	 * @param array  $apiParams    array of parameters to send to the API
208
+	 * @param string $accessToken  user's access token
209
+	 * @param string $accessSecret user's secret
210
+	 * @param string $method       HTTP method
211
+	 *
212
+	 * @return stdClass
213
+	 * @throws ApplicationLogicException
214
+	 * @throws CurlException
215
+	 * @throws Exception
216
+	 */
217
+	public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET')
218
+	{
219
+		$userToken = new OAuthToken($accessToken, $accessSecret);
220
+
221
+		$apiParams['format'] = 'json';
222
+
223
+		$api_req = OAuthRequest::from_consumer_and_token(
224
+			$this->oauthConsumer, // Consumer
225
+			$userToken, // User Access Token
226
+			$method, // HTTP Method
227
+			$this->mediawikiWebServiceEndpoint, // Endpoint url
228
+			$apiParams    // Extra signed parameters
229
+		);
230
+
231
+		$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
232 232
 
233
-        $api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken);
234
-
235
-        if ($method == 'GET') {
236
-            $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams);
237
-        }
238
-        elseif ($method == 'POST') {
239
-            $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams);
240
-        }
241
-        else {
242
-            throw new ApplicationLogicException('Unsupported HTTP Method');
243
-        }
244
-
245
-        if ($data === false) {
246
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
247
-        }
248
-
249
-        return json_decode($data);
250
-    }
233
+		$api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken);
234
+
235
+		if ($method == 'GET') {
236
+			$data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams);
237
+		}
238
+		elseif ($method == 'POST') {
239
+			$data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams);
240
+		}
241
+		else {
242
+			throw new ApplicationLogicException('Unsupported HTTP Method');
243
+		}
244
+
245
+		if ($data === false) {
246
+			throw new Exception('Curl error: ' . $this->httpHelper->getError());
247
+		}
248
+
249
+		return json_decode($data);
250
+	}
251 251
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function getRequestToken()
78 78
     {
79
-        $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob';
79
+        $endpoint = $this->oauthEndpoint.'/initiate&format=json&oauth_callback=oob';
80 80
 
81 81
         $parsedUrl = parse_url($endpoint);
82 82
         $urlParameters = array();
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $data = $this->httpHelper->get($targetUrl, null);
92 92
 
93 93
         if ($data === false) {
94
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
94
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
95 95
         }
96 96
 
97 97
         $token = json_decode($data);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         }
102 102
 
103 103
         if (isset($token->error)) {
104
-            throw new Exception('Error encountered while getting request token: ' . $token->error);
104
+            throw new Exception('Error encountered while getting request token: '.$token->error);
105 105
         }
106 106
 
107 107
         return $token;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier)
130 130
     {
131
-        $endpoint = $this->oauthEndpoint . '/token&format=json';
131
+        $endpoint = $this->oauthEndpoint.'/token&format=json';
132 132
 
133 133
         $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret);
134 134
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         $data = $this->httpHelper->get($targetUrl, null);
147 147
 
148 148
         if ($data === false) {
149
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
149
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
150 150
         }
151 151
 
152 152
         $token = json_decode($data);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         if (isset($token->error)) {
159
-            throw new Exception('Error encountered while getting access token: ' . $token->error);
159
+            throw new Exception('Error encountered while getting access token: '.$token->error);
160 160
         }
161 161
 
162 162
         return $token;
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret)
174 174
     {
175
-        $endpoint = $this->oauthEndpoint . '/identify&format=json';
175
+        $endpoint = $this->oauthEndpoint.'/identify&format=json';
176 176
 
177 177
         $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret);
178 178
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $data = $this->httpHelper->get($targetUrl, null);
190 190
 
191 191
         if ($data === false) {
192
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
192
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
193 193
         }
194 194
 
195 195
         $decodedData = json_decode($data);
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         }
244 244
 
245 245
         if ($data === false) {
246
-            throw new Exception('Curl error: ' . $this->httpHelper->getError());
246
+            throw new Exception('Curl error: '.$this->httpHelper->getError());
247 247
         }
248 248
 
249 249
         return json_decode($data);
Please login to merge, or discard this patch.