Completed
Push — bootstrap4 ( c24853...dc7ca1 )
by Simon
06:16
created
includes/Security/Token.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -12,80 +12,80 @@
 block discarded – undo
12 12
 
13 13
 class Token
14 14
 {
15
-    /** @var string */
16
-    private $tokenData;
17
-    /** @var string */
18
-    private $context;
19
-    /** @var DateTimeImmutable */
20
-    private $generationTimestamp;
21
-    /** @var DateTimeImmutable */
22
-    private $usageTimestamp;
23
-    /** @var bool */
24
-    private $used;
15
+	/** @var string */
16
+	private $tokenData;
17
+	/** @var string */
18
+	private $context;
19
+	/** @var DateTimeImmutable */
20
+	private $generationTimestamp;
21
+	/** @var DateTimeImmutable */
22
+	private $usageTimestamp;
23
+	/** @var bool */
24
+	private $used;
25 25
 
26
-    /**
27
-     * Token constructor.
28
-     *
29
-     * @param string $tokenData
30
-     * @param string $context
31
-     */
32
-    public function __construct($tokenData, $context)
33
-    {
34
-        $this->tokenData = $tokenData;
35
-        $this->context = $context;
36
-        $this->generationTimestamp = new DateTimeImmutable();
37
-        $this->usageTimestamp = null;
38
-        $this->used = false;
39
-    }
26
+	/**
27
+	 * Token constructor.
28
+	 *
29
+	 * @param string $tokenData
30
+	 * @param string $context
31
+	 */
32
+	public function __construct($tokenData, $context)
33
+	{
34
+		$this->tokenData = $tokenData;
35
+		$this->context = $context;
36
+		$this->generationTimestamp = new DateTimeImmutable();
37
+		$this->usageTimestamp = null;
38
+		$this->used = false;
39
+	}
40 40
 
41
-    /**
42
-     * @return DateTimeImmutable
43
-     */
44
-    public function getGenerationTimestamp()
45
-    {
46
-        return $this->generationTimestamp;
47
-    }
41
+	/**
42
+	 * @return DateTimeImmutable
43
+	 */
44
+	public function getGenerationTimestamp()
45
+	{
46
+		return $this->generationTimestamp;
47
+	}
48 48
 
49
-    /**
50
-     * @return string
51
-     */
52
-    public function getContext()
53
-    {
54
-        return $this->context;
55
-    }
49
+	/**
50
+	 * @return string
51
+	 */
52
+	public function getContext()
53
+	{
54
+		return $this->context;
55
+	}
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function getTokenData()
61
-    {
62
-        return $this->tokenData;
63
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function getTokenData()
61
+	{
62
+		return $this->tokenData;
63
+	}
64 64
 
65
-    /**
66
-     * Returns a value indicating whether the token has already been used or not
67
-     *
68
-     * @return boolean
69
-     */
70
-    public function isUsed()
71
-    {
72
-        return $this->used;
73
-    }
65
+	/**
66
+	 * Returns a value indicating whether the token has already been used or not
67
+	 *
68
+	 * @return boolean
69
+	 */
70
+	public function isUsed()
71
+	{
72
+		return $this->used;
73
+	}
74 74
 
75
-    /**
76
-     * Marks the token as used
77
-     */
78
-    public function markAsUsed()
79
-    {
80
-        $this->used = true;
81
-        $this->usageTimestamp = new DateTimeImmutable();
82
-    }
75
+	/**
76
+	 * Marks the token as used
77
+	 */
78
+	public function markAsUsed()
79
+	{
80
+		$this->used = true;
81
+		$this->usageTimestamp = new DateTimeImmutable();
82
+	}
83 83
 
84
-    /**
85
-     * @return DateTimeImmutable
86
-     */
87
-    public function getUsageTimestamp()
88
-    {
89
-        return $this->usageTimestamp;
90
-    }
84
+	/**
85
+	 * @return DateTimeImmutable
86
+	 */
87
+	public function getUsageTimestamp()
88
+	{
89
+		return $this->usageTimestamp;
90
+	}
91 91
 }
92 92
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Security/TokenManager.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -13,91 +13,91 @@
 block discarded – undo
13 13
 
14 14
 class TokenManager
15 15
 {
16
-    /**
17
-     * Validates a CSRF token
18
-     *
19
-     * @param string      $data    The token data string itself
20
-     * @param string|null $context Token context for extra validation
21
-     *
22
-     * @return bool
23
-     */
24
-    public function validateToken($data, $context = null)
25
-    {
26
-        if (!is_string($data) || strlen($data) === 0) {
27
-            // Nothing to validate
28
-            return false;
29
-        }
30
-
31
-        $tokens = WebRequest::getSessionTokenData();
32
-
33
-        // if the token doesn't exist, then it's not valid
34
-        if (!array_key_exists($data, $tokens)) {
35
-            return false;
36
-        }
37
-
38
-        /** @var Token $token */
39
-        $token = unserialize($tokens[$data]);
40
-
41
-        if ($token->getTokenData() !== $data) {
42
-            return false;
43
-        }
44
-
45
-        if ($token->getContext() !== $context) {
46
-            return false;
47
-        }
48
-
49
-        if ($token->isUsed()) {
50
-            return false;
51
-        }
52
-
53
-        // mark the token as used, and save it back to the session
54
-        $token->markAsUsed();
55
-        $this->storeToken($token);
56
-
57
-        return true;
58
-    }
59
-
60
-    /**
61
-     * @param string|null $context An optional context for extra validation
62
-     *
63
-     * @return Token
64
-     */
65
-    public function getNewToken($context = null)
66
-    {
67
-        $token = new Token($this->generateTokenData(), $context);
68
-        $this->storeToken($token);
69
-
70
-        return $token;
71
-    }
72
-
73
-    /**
74
-     * Stores a token in the session data
75
-     *
76
-     * @param Token $token
77
-     */
78
-    private function storeToken(Token $token)
79
-    {
80
-        $tokens = WebRequest::getSessionTokenData();
81
-        $tokens[$token->getTokenData()] = serialize($token);
82
-        WebRequest::setSessionTokenData($tokens);
83
-    }
84
-
85
-    /**
86
-     * Generates a security token
87
-     *
88
-     * @return string
89
-     * @throws Exception
90
-     *
91
-     * @category Security-Critical
92
-     */
93
-    private function generateTokenData()
94
-    {
95
-        $genBytes = openssl_random_pseudo_bytes(33);
96
-
97
-        if ($genBytes !== false) {
98
-            return base64_encode($genBytes);
99
-        }
100
-
101
-        throw new Exception('Unable to generate secure token.');
102
-    }
16
+	/**
17
+	 * Validates a CSRF token
18
+	 *
19
+	 * @param string      $data    The token data string itself
20
+	 * @param string|null $context Token context for extra validation
21
+	 *
22
+	 * @return bool
23
+	 */
24
+	public function validateToken($data, $context = null)
25
+	{
26
+		if (!is_string($data) || strlen($data) === 0) {
27
+			// Nothing to validate
28
+			return false;
29
+		}
30
+
31
+		$tokens = WebRequest::getSessionTokenData();
32
+
33
+		// if the token doesn't exist, then it's not valid
34
+		if (!array_key_exists($data, $tokens)) {
35
+			return false;
36
+		}
37
+
38
+		/** @var Token $token */
39
+		$token = unserialize($tokens[$data]);
40
+
41
+		if ($token->getTokenData() !== $data) {
42
+			return false;
43
+		}
44
+
45
+		if ($token->getContext() !== $context) {
46
+			return false;
47
+		}
48
+
49
+		if ($token->isUsed()) {
50
+			return false;
51
+		}
52
+
53
+		// mark the token as used, and save it back to the session
54
+		$token->markAsUsed();
55
+		$this->storeToken($token);
56
+
57
+		return true;
58
+	}
59
+
60
+	/**
61
+	 * @param string|null $context An optional context for extra validation
62
+	 *
63
+	 * @return Token
64
+	 */
65
+	public function getNewToken($context = null)
66
+	{
67
+		$token = new Token($this->generateTokenData(), $context);
68
+		$this->storeToken($token);
69
+
70
+		return $token;
71
+	}
72
+
73
+	/**
74
+	 * Stores a token in the session data
75
+	 *
76
+	 * @param Token $token
77
+	 */
78
+	private function storeToken(Token $token)
79
+	{
80
+		$tokens = WebRequest::getSessionTokenData();
81
+		$tokens[$token->getTokenData()] = serialize($token);
82
+		WebRequest::setSessionTokenData($tokens);
83
+	}
84
+
85
+	/**
86
+	 * Generates a security token
87
+	 *
88
+	 * @return string
89
+	 * @throws Exception
90
+	 *
91
+	 * @category Security-Critical
92
+	 */
93
+	private function generateTokenData()
94
+	{
95
+		$genBytes = openssl_random_pseudo_bytes(33);
96
+
97
+		if ($genBytes !== false) {
98
+			return base64_encode($genBytes);
99
+		}
100
+
101
+		throw new Exception('Unable to generate secure token.');
102
+	}
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Router/ApiRequestRouter.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -20,43 +20,43 @@
 block discarded – undo
20 20
 
21 21
 class ApiRequestRouter implements IRequestRouter
22 22
 {
23
-    /**
24
-     * @return string[]
25
-     */
26
-    public static function getActionList()
27
-    {
28
-        return array("count", "status", "stats", "help", "monitor");
29
-    }
23
+	/**
24
+	 * @return string[]
25
+	 */
26
+	public static function getActionList()
27
+	{
28
+		return array("count", "status", "stats", "help", "monitor");
29
+	}
30 30
 
31
-    /**
32
-     * @return IRoutedTask
33
-     * @throws Exception
34
-     */
35
-    public function route()
36
-    {
37
-        $requestAction = WebRequest::getString('action');
31
+	/**
32
+	 * @return IRoutedTask
33
+	 * @throws Exception
34
+	 */
35
+	public function route()
36
+	{
37
+		$requestAction = WebRequest::getString('action');
38 38
 
39
-        switch ($requestAction) {
40
-            case "count":
41
-                $result = new CountAction();
42
-                break;
43
-            case "status":
44
-                $result = new StatusAction();
45
-                break;
46
-            case "stats":
47
-                $result = new StatsAction();
48
-                break;
49
-            case "help":
50
-                $result = new HelpAction();
51
-                break;
52
-            case "monitor":
53
-                $result = new MonitorAction();
54
-                break;
55
-            default:
56
-                $result = new UnknownAction();
57
-                break;
58
-        }
39
+		switch ($requestAction) {
40
+			case "count":
41
+				$result = new CountAction();
42
+				break;
43
+			case "status":
44
+				$result = new StatusAction();
45
+				break;
46
+			case "stats":
47
+				$result = new StatsAction();
48
+				break;
49
+			case "help":
50
+				$result = new HelpAction();
51
+				break;
52
+			case "monitor":
53
+				$result = new MonitorAction();
54
+				break;
55
+			default:
56
+				$result = new UnknownAction();
57
+				break;
58
+		}
59 59
 
60
-        return $result;
61
-    }
60
+		return $result;
61
+	}
62 62
 }
63 63
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Router/OAuthRequestRouter.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
17 17
  */
18 18
 class OAuthRequestRouter extends RequestRouter
19 19
 {
20
-    protected function getRouteFromPath($pathInfo)
21
-    {
22
-        // Hardcode the route for this entry point
23
-        return array(PageOAuth::class, 'callback');
24
-    }
20
+	protected function getRouteFromPath($pathInfo)
21
+	{
22
+		// Hardcode the route for this entry point
23
+		return array(PageOAuth::class, 'callback');
24
+	}
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Router/IRequestRouter.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@
 block discarded – undo
18 18
  */
19 19
 interface IRequestRouter
20 20
 {
21
-    /**
22
-     * @return IRoutedTask
23
-     * @throws Exception
24
-     */
25
-    public function route();
21
+	/**
22
+	 * @return IRoutedTask
23
+	 * @throws Exception
24
+	 */
25
+	public function route();
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
includes/AutoLoader.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,36 +13,36 @@
 block discarded – undo
13 13
  */
14 14
 class AutoLoader
15 15
 {
16
-    public static function load($class)
17
-    {
18
-        // handle namespaces sensibly
19
-        if (strpos($class, "Waca") !== false) {
20
-            // strip off the initial namespace
21
-            $class = str_replace("Waca\\", "", $class);
16
+	public static function load($class)
17
+	{
18
+		// handle namespaces sensibly
19
+		if (strpos($class, "Waca") !== false) {
20
+			// strip off the initial namespace
21
+			$class = str_replace("Waca\\", "", $class);
22 22
 
23
-            // swap backslashes for forward slashes to map to directory names
24
-            $class = str_replace("\\", "/", $class);
25
-        }
23
+			// swap backslashes for forward slashes to map to directory names
24
+			$class = str_replace("\\", "/", $class);
25
+		}
26 26
 
27
-        $paths = array(
28
-            __DIR__ . '/' . $class . ".php",
29
-            __DIR__ . '/DataObjects/' . $class . ".php",
30
-            __DIR__ . '/Providers/' . $class . ".php",
31
-            __DIR__ . '/Providers/Interfaces/' . $class . ".php",
32
-            __DIR__ . '/Validation/' . $class . ".php",
33
-            __DIR__ . '/Helpers/' . $class . ".php",
34
-            __DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35
-            __DIR__ . '/' . $class . ".php",
36
-        );
27
+		$paths = array(
28
+			__DIR__ . '/' . $class . ".php",
29
+			__DIR__ . '/DataObjects/' . $class . ".php",
30
+			__DIR__ . '/Providers/' . $class . ".php",
31
+			__DIR__ . '/Providers/Interfaces/' . $class . ".php",
32
+			__DIR__ . '/Validation/' . $class . ".php",
33
+			__DIR__ . '/Helpers/' . $class . ".php",
34
+			__DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35
+			__DIR__ . '/' . $class . ".php",
36
+		);
37 37
 
38
-        foreach ($paths as $file) {
39
-            if (file_exists($file)) {
40
-                require_once($file);
41
-            }
38
+		foreach ($paths as $file) {
39
+			if (file_exists($file)) {
40
+				require_once($file);
41
+			}
42 42
 
43
-            if (class_exists($class)) {
44
-                return;
45
-            }
46
-        }
47
-    }
43
+			if (class_exists($class)) {
44
+				return;
45
+			}
46
+		}
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@
 block discarded – undo
25 25
         }
26 26
 
27 27
         $paths = array(
28
-            __DIR__ . '/' . $class . ".php",
29
-            __DIR__ . '/DataObjects/' . $class . ".php",
30
-            __DIR__ . '/Providers/' . $class . ".php",
31
-            __DIR__ . '/Providers/Interfaces/' . $class . ".php",
32
-            __DIR__ . '/Validation/' . $class . ".php",
33
-            __DIR__ . '/Helpers/' . $class . ".php",
34
-            __DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35
-            __DIR__ . '/' . $class . ".php",
28
+            __DIR__.'/'.$class.".php",
29
+            __DIR__.'/DataObjects/'.$class.".php",
30
+            __DIR__.'/Providers/'.$class.".php",
31
+            __DIR__.'/Providers/Interfaces/'.$class.".php",
32
+            __DIR__.'/Validation/'.$class.".php",
33
+            __DIR__.'/Helpers/'.$class.".php",
34
+            __DIR__.'/Helpers/Interfaces/'.$class.".php",
35
+            __DIR__.'/'.$class.".php",
36 36
         );
37 37
 
38 38
         foreach ($paths as $file) {
Please login to merge, or discard this patch.
includes/StringFunctions.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -10,77 +10,77 @@
 block discarded – undo
10 10
 
11 11
 class StringFunctions
12 12
 {
13
-    /**
14
-     * Formats a string to be used as a username.
15
-     *
16
-     * @param $username
17
-     *
18
-     * @return string
19
-     */
20
-    public function formatAsUsername($username)
21
-    {
22
-        // trim whitespace from the ends
23
-        $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username);
13
+	/**
14
+	 * Formats a string to be used as a username.
15
+	 *
16
+	 * @param $username
17
+	 *
18
+	 * @return string
19
+	 */
20
+	public function formatAsUsername($username)
21
+	{
22
+		// trim whitespace from the ends
23
+		$uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username);
24 24
 
25
-        // convert first char to uppercase
26
-        $uname = $this->ucfirst($uname);
25
+		// convert first char to uppercase
26
+		$uname = $this->ucfirst($uname);
27 27
 
28
-        // replace spaces with underscores
29
-        $uname = mb_ereg_replace("[ ]+", "_", $uname);
28
+		// replace spaces with underscores
29
+		$uname = mb_ereg_replace("[ ]+", "_", $uname);
30 30
 
31
-        // trim underscores from the end
32
-        $uname = mb_ereg_replace("[_]+$", "", $uname);
31
+		// trim underscores from the end
32
+		$uname = mb_ereg_replace("[_]+$", "", $uname);
33 33
 
34
-        return $uname;
35
-    }
34
+		return $uname;
35
+	}
36 36
 
37
-    /**
38
-     * Formats a string to be used as an email (specifically strips whitespace
39
-     * from the beginning/end of the Email, as well as immediately before/after
40
-     * the @ in the Email).
41
-     *
42
-     * @param $email
43
-     *
44
-     * @return string
45
-     */
46
-    public static function formatAsEmail($email)
47
-    {
48
-        // trim whitespace from the ends
49
-        $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email);
37
+	/**
38
+	 * Formats a string to be used as an email (specifically strips whitespace
39
+	 * from the beginning/end of the Email, as well as immediately before/after
40
+	 * the @ in the Email).
41
+	 *
42
+	 * @param $email
43
+	 *
44
+	 * @return string
45
+	 */
46
+	public static function formatAsEmail($email)
47
+	{
48
+		// trim whitespace from the ends
49
+		$newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email);
50 50
 
51
-        // trim whitespace from around the email address
52
-        $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail);
53
-        $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail);
51
+		// trim whitespace from around the email address
52
+		$newemail = mb_ereg_replace("[ \t]+@", "@", $newemail);
53
+		$newemail = mb_ereg_replace("@[ \t]+", "@", $newemail);
54 54
 
55
-        return $newemail;
56
-    }
55
+		return $newemail;
56
+	}
57 57
 
58
-    /**
59
-     * Returns true if a string is a multibyte string
60
-     *
61
-     * @param string $string
62
-     *
63
-     * @return bool
64
-     */
65
-    public function isMultibyte($string)
66
-    {
67
-        return strlen($string) !== mb_strlen($string);
68
-    }
58
+	/**
59
+	 * Returns true if a string is a multibyte string
60
+	 *
61
+	 * @param string $string
62
+	 *
63
+	 * @return bool
64
+	 */
65
+	public function isMultibyte($string)
66
+	{
67
+		return strlen($string) !== mb_strlen($string);
68
+	}
69 69
 
70
-    /**
71
-     * Make a string's first character uppercase
72
-     *
73
-     * @param string $string
74
-     *
75
-     * @return string
76
-     */
77
-    public function ucfirst($string)
78
-    {
79
-        if (ord($string) < 128) {
80
-            return ucfirst($string);
81
-        }
82
-        else {
83
-            return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
84
-        }
85
-    }
70
+	/**
71
+	 * Make a string's first character uppercase
72
+	 *
73
+	 * @param string $string
74
+	 *
75
+	 * @return string
76
+	 */
77
+	public function ucfirst($string)
78
+	{
79
+		if (ord($string) < 128) {
80
+			return ucfirst($string);
81
+		}
82
+		else {
83
+			return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
             return ucfirst($string);
81 81
         }
82 82
         else {
83
-            return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
83
+            return mb_strtoupper(mb_substr($string, 0, 1)).mb_substr($string, 1);
84 84
         }
85 85
     }
86 86
 }
Please login to merge, or discard this patch.
includes/ConsoleTasks/UpdateTorExitTask.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,14 +13,14 @@
 block discarded – undo
13 13
 
14 14
 class UpdateTorExitTask extends ConsoleTaskBase
15 15
 {
16
-    /**
17
-     * @return void
18
-     */
19
-    public function execute()
20
-    {
21
-        TorExitProvider::regenerate(
22
-            $this->getDatabase(),
23
-            $this->getHttpHelper(),
24
-            $this->getSiteConfiguration()->getTorExitPaths());
25
-    }
16
+	/**
17
+	 * @return void
18
+	 */
19
+	public function execute()
20
+	{
21
+		TorExitProvider::regenerate(
22
+			$this->getDatabase(),
23
+			$this->getHttpHelper(),
24
+			$this->getSiteConfiguration()->getTorExitPaths());
25
+	}
26 26
 }
27 27
\ No newline at end of file
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.