Failed Conditions
Push — newinternal ( 216d62...410e59 )
by Simon
05:28 queued 13s
created
redir.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -7,46 +7,46 @@
 block discarded – undo
7 7
  ******************************************************************************/
8 8
 
9 9
 $toolList = array(
10
-    'tparis-pcount'      => '//tools.wmflabs.org/supercount/index.php?user=%DATA%&project=en.wikipedia',
11
-    'guc'                => '//tools.wmflabs.org/guc/?by=date&user=%DATA%',
12
-    'oq-whois'           => 'https://whois.domaintools.com/%DATA%',
13
-    'tl-whois'           => 'https://tools.wmflabs.org/whois/gateway.py?lookup=true&ip=%DATA%',
14
-    'honeypot'           => 'https://www.projecthoneypot.org/ip_%DATA%',
15
-    'stopforumspam'      => 'https://www.stopforumspam.com/ipcheck/%DATA%',
16
-    'google'             => 'https://www.google.com/search?q=%DATA%',
17
-    'domain'             => 'http://%DATA%/',
18
-    'rangefinder'        => 'https://tools.wmflabs.org/rangeblockfinder/?ip=%DATA%',
10
+	'tparis-pcount'      => '//tools.wmflabs.org/supercount/index.php?user=%DATA%&project=en.wikipedia',
11
+	'guc'                => '//tools.wmflabs.org/guc/?by=date&user=%DATA%',
12
+	'oq-whois'           => 'https://whois.domaintools.com/%DATA%',
13
+	'tl-whois'           => 'https://tools.wmflabs.org/whois/gateway.py?lookup=true&ip=%DATA%',
14
+	'honeypot'           => 'https://www.projecthoneypot.org/ip_%DATA%',
15
+	'stopforumspam'      => 'https://www.stopforumspam.com/ipcheck/%DATA%',
16
+	'google'             => 'https://www.google.com/search?q=%DATA%',
17
+	'domain'             => 'http://%DATA%/',
18
+	'rangefinder'        => 'https://tools.wmflabs.org/rangeblockfinder/?ip=%DATA%',
19 19
 	'ipcheck'            => 'https://ipcheck.toolforge.org/index.php?ip=%DATA%',
20 20
 	'bgpview'            => 'https://bgpview.io/ip/%DATA%'
21 21
 );
22 22
 
23 23
 if (!isset($_GET['tool'])
24
-    || !isset($toolList[$_GET['tool']])
25
-    || !isset($_GET['data'])
24
+	|| !isset($toolList[$_GET['tool']])
25
+	|| !isset($_GET['data'])
26 26
 ) {
27
-    header("HTTP/1.1 403 Forbidden");
27
+	header("HTTP/1.1 403 Forbidden");
28 28
 
29
-    return;
29
+	return;
30 30
 }
31 31
 
32 32
 if (isset($_GET['round2'])) {
33
-    $data = $_GET['data'];
34
-    $tool = $_GET['tool'];
33
+	$data = $_GET['data'];
34
+	$tool = $_GET['tool'];
35 35
 
36
-    if ($tool === 'domain') {
37
-        // quick security check - if you want to exploit something, you better be sure your exploit resolves via dns.
38
-        // this is not intended to catch everything, just as a quick sanity check.
39
-        if (gethostbyname($data) == $data) {
40
-            echo 'Error resolving hostname, it doesn\'t look like this domain exists.';
41
-            die();
42
-        }
43
-    }
44
-    else {
45
-        $data = urlencode($data);
46
-    }
36
+	if ($tool === 'domain') {
37
+		// quick security check - if you want to exploit something, you better be sure your exploit resolves via dns.
38
+		// this is not intended to catch everything, just as a quick sanity check.
39
+		if (gethostbyname($data) == $data) {
40
+			echo 'Error resolving hostname, it doesn\'t look like this domain exists.';
41
+			die();
42
+		}
43
+	}
44
+	else {
45
+		$data = urlencode($data);
46
+	}
47 47
 
48
-    echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>';
48
+	echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>';
49 49
 }
50 50
 else {
51
-    header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true");
51
+	header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true");
52 52
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,8 +45,8 @@
 block discarded – undo
45 45
         $data = urlencode($data);
46 46
     }
47 47
 
48
-    echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>';
48
+    echo '<script>window.location.href='.json_encode(str_replace("%DATA%", $data, $toolList[$tool])).'</script>';
49 49
 }
50 50
 else {
51
-    header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true");
51
+    header("Location: ".$_SERVER["REQUEST_URI"]."&round2=true");
52 52
 }
Please login to merge, or discard this patch.
includes/Providers/IpLocationProvider.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -21,107 +21,107 @@
 block discarded – undo
21 21
  */
22 22
 class IpLocationProvider implements ILocationProvider
23 23
 {
24
-    /** @var string */
25
-    private $apiKey;
26
-    /** @var PdoDatabase */
27
-    private $database;
28
-    /** @var HttpHelper */
29
-    private $httpHelper;
30
-
31
-    /**
32
-     * IpLocationProvider constructor.
33
-     *
34
-     * @param PdoDatabase $database
35
-     * @param string      $apiKey
36
-     * @param HttpHelper  $httpHelper
37
-     */
38
-    public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
-    {
40
-        $this->database = $database;
41
-        $this->apiKey = $apiKey;
42
-        $this->httpHelper = $httpHelper;
43
-    }
44
-
45
-    /**
46
-     * @param string $address
47
-     *
48
-     * @return array|null
49
-     * @throws Exception
50
-     * @throws OptimisticLockFailedException
51
-     */
52
-    public function getIpLocation($address)
53
-    {
54
-        $address = trim($address);
55
-
56
-        // lets look in our database first.
57
-        $location = GeoLocation::getByAddress($address, $this->database, true);
58
-
59
-        if ($location != null) {
60
-            // touch cache timer
61
-            $location->save();
62
-
63
-            return $location->getData();
64
-        }
65
-
66
-        // OK, it's not there, let's do an IP2Location lookup.
67
-        $result = $this->getResult($address);
68
-
69
-        if ($result != null) {
70
-            $location = new GeoLocation();
71
-            $location->setDatabase($this->database);
72
-            $location->setAddress($address);
73
-            $location->setData($result);
74
-            $location->save();
75
-
76
-            return $result;
77
-        }
78
-
79
-        return null;
80
-    }
81
-
82
-    // adapted from http://www.ipinfodb.com/ip_location_api.php
83
-
84
-    /**
85
-     * @param string $ip
86
-     *
87
-     * @return array|null
88
-     */
89
-    private function getResult($ip)
90
-    {
91
-        try {
92
-            if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
-                $xml = $this->httpHelper->get($this->getApiBase(), array(
94
-                    'key'    => $this->apiKey,
95
-                    'ip'     => $ip,
96
-                    'format' => 'xml',
97
-                ));
98
-
99
-                $response = @new SimpleXMLElement($xml);
100
-
101
-                $result = array();
102
-
103
-                foreach ($response as $field => $value) {
104
-                    $result[(string)$field] = (string)$value;
105
-                }
106
-
107
-                return $result;
108
-            }
109
-        }
110
-        catch (Exception $ex) {
111
-            return null;
112
-
113
-            // LOGME: do something smart here, or wherever we use this value.
114
-            // This is just a temp hack to squash errors on the UI for now.
115
-        }
116
-
117
-        return null;
118
-    }
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    protected function getApiBase()
124
-    {
125
-        return "http://api.ipinfodb.com/v3/ip-city/";
126
-    }
24
+	/** @var string */
25
+	private $apiKey;
26
+	/** @var PdoDatabase */
27
+	private $database;
28
+	/** @var HttpHelper */
29
+	private $httpHelper;
30
+
31
+	/**
32
+	 * IpLocationProvider constructor.
33
+	 *
34
+	 * @param PdoDatabase $database
35
+	 * @param string      $apiKey
36
+	 * @param HttpHelper  $httpHelper
37
+	 */
38
+	public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
+	{
40
+		$this->database = $database;
41
+		$this->apiKey = $apiKey;
42
+		$this->httpHelper = $httpHelper;
43
+	}
44
+
45
+	/**
46
+	 * @param string $address
47
+	 *
48
+	 * @return array|null
49
+	 * @throws Exception
50
+	 * @throws OptimisticLockFailedException
51
+	 */
52
+	public function getIpLocation($address)
53
+	{
54
+		$address = trim($address);
55
+
56
+		// lets look in our database first.
57
+		$location = GeoLocation::getByAddress($address, $this->database, true);
58
+
59
+		if ($location != null) {
60
+			// touch cache timer
61
+			$location->save();
62
+
63
+			return $location->getData();
64
+		}
65
+
66
+		// OK, it's not there, let's do an IP2Location lookup.
67
+		$result = $this->getResult($address);
68
+
69
+		if ($result != null) {
70
+			$location = new GeoLocation();
71
+			$location->setDatabase($this->database);
72
+			$location->setAddress($address);
73
+			$location->setData($result);
74
+			$location->save();
75
+
76
+			return $result;
77
+		}
78
+
79
+		return null;
80
+	}
81
+
82
+	// adapted from http://www.ipinfodb.com/ip_location_api.php
83
+
84
+	/**
85
+	 * @param string $ip
86
+	 *
87
+	 * @return array|null
88
+	 */
89
+	private function getResult($ip)
90
+	{
91
+		try {
92
+			if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
+				$xml = $this->httpHelper->get($this->getApiBase(), array(
94
+					'key'    => $this->apiKey,
95
+					'ip'     => $ip,
96
+					'format' => 'xml',
97
+				));
98
+
99
+				$response = @new SimpleXMLElement($xml);
100
+
101
+				$result = array();
102
+
103
+				foreach ($response as $field => $value) {
104
+					$result[(string)$field] = (string)$value;
105
+				}
106
+
107
+				return $result;
108
+			}
109
+		}
110
+		catch (Exception $ex) {
111
+			return null;
112
+
113
+			// LOGME: do something smart here, or wherever we use this value.
114
+			// This is just a temp hack to squash errors on the UI for now.
115
+		}
116
+
117
+		return null;
118
+	}
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	protected function getApiBase()
124
+	{
125
+		return "http://api.ipinfodb.com/v3/ip-city/";
126
+	}
127 127
 }
Please login to merge, or discard this patch.
includes/PdoDatabase.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -15,113 +15,113 @@
 block discarded – undo
15 15
 
16 16
 class PdoDatabase extends PDO
17 17
 {
18
-    /**
19
-     * @var PdoDatabase[]
20
-     */
21
-    private static $connections = array();
22
-    /**
23
-     * @var bool True if a transaction is active
24
-     */
25
-    protected $hasActiveTransaction = false;
26
-
27
-    /**
28
-     * Unless you're doing low-level work, this is not the function you want.
29
-     *
30
-     * @param string $connectionName
31
-     *
32
-     * @return PdoDatabase
33
-     * @throws Exception
34
-     */
35
-    public static function getDatabaseConnection($connectionName)
36
-    {
37
-        if (!isset(self::$connections[$connectionName])) {
38
-            global $cDatabaseConfig;
39
-
40
-            if (!array_key_exists($connectionName, $cDatabaseConfig)) {
41
-                throw new Exception("Database configuration not found for alias $connectionName");
42
-            }
43
-
44
-            try {
45
-                $databaseObject = new PdoDatabase(
46
-                    $cDatabaseConfig[$connectionName]["dsrcname"],
47
-                    $cDatabaseConfig[$connectionName]["username"],
48
-                    $cDatabaseConfig[$connectionName]["password"],
49
-                    $cDatabaseConfig[$connectionName]["options"]
50
-                );
51
-            }
52
-            catch (PDOException $ex) {
53
-                // wrap around any potential stack traces which may include passwords
54
-                throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage());
55
-            }
56
-
57
-            $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
58
-
59
-            // emulating prepared statements gives a performance boost on MySQL.
60
-            //
61
-            // however, our version of PDO doesn't seem to understand parameter types when emulating
62
-            // the prepared statements, so we're forced to turn this off for now.
63
-            // -- stw 2014-02-11
64
-            $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
65
-
66
-            self::$connections[$connectionName] = $databaseObject;
67
-        }
68
-
69
-        return self::$connections[$connectionName];
70
-    }
71
-
72
-    /**
73
-     * Determines if this connection has a transaction in progress or not
74
-     * @return boolean true if there is a transaction in progress.
75
-     */
76
-    public function hasActiveTransaction()
77
-    {
78
-        return $this->hasActiveTransaction;
79
-    }
80
-
81
-    /**
82
-     * Summary of beginTransaction
83
-     * @return bool
84
-     */
85
-    public function beginTransaction()
86
-    {
87
-        // Override the pre-existing method, which doesn't stop you from
88
-        // starting transactions within transactions - which doesn't work and
89
-        // will throw an exception. This eliminates the need to catch exceptions
90
-        // all over the rest of the code
91
-        if ($this->hasActiveTransaction) {
92
-            return false;
93
-        }
94
-        else {
95
-            // set the transaction isolation level for every transaction.
96
-            $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;");
97
-
98
-            // start a new transaction, and return whether or not the start was
99
-            // successful
100
-            $this->hasActiveTransaction = parent::beginTransaction();
101
-
102
-            return $this->hasActiveTransaction;
103
-        }
104
-    }
105
-
106
-    /**
107
-     * Commits the active transaction
108
-     */
109
-    public function commit()
110
-    {
111
-        if ($this->hasActiveTransaction) {
112
-            parent::commit();
113
-            $this->hasActiveTransaction = false;
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Rolls back a transaction
119
-     */
120
-    public function rollBack()
121
-    {
122
-        if ($this->hasActiveTransaction) {
123
-            parent::rollback();
124
-            $this->hasActiveTransaction = false;
125
-        }
126
-    }
18
+	/**
19
+	 * @var PdoDatabase[]
20
+	 */
21
+	private static $connections = array();
22
+	/**
23
+	 * @var bool True if a transaction is active
24
+	 */
25
+	protected $hasActiveTransaction = false;
26
+
27
+	/**
28
+	 * Unless you're doing low-level work, this is not the function you want.
29
+	 *
30
+	 * @param string $connectionName
31
+	 *
32
+	 * @return PdoDatabase
33
+	 * @throws Exception
34
+	 */
35
+	public static function getDatabaseConnection($connectionName)
36
+	{
37
+		if (!isset(self::$connections[$connectionName])) {
38
+			global $cDatabaseConfig;
39
+
40
+			if (!array_key_exists($connectionName, $cDatabaseConfig)) {
41
+				throw new Exception("Database configuration not found for alias $connectionName");
42
+			}
43
+
44
+			try {
45
+				$databaseObject = new PdoDatabase(
46
+					$cDatabaseConfig[$connectionName]["dsrcname"],
47
+					$cDatabaseConfig[$connectionName]["username"],
48
+					$cDatabaseConfig[$connectionName]["password"],
49
+					$cDatabaseConfig[$connectionName]["options"]
50
+				);
51
+			}
52
+			catch (PDOException $ex) {
53
+				// wrap around any potential stack traces which may include passwords
54
+				throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage());
55
+			}
56
+
57
+			$databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
58
+
59
+			// emulating prepared statements gives a performance boost on MySQL.
60
+			//
61
+			// however, our version of PDO doesn't seem to understand parameter types when emulating
62
+			// the prepared statements, so we're forced to turn this off for now.
63
+			// -- stw 2014-02-11
64
+			$databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
65
+
66
+			self::$connections[$connectionName] = $databaseObject;
67
+		}
68
+
69
+		return self::$connections[$connectionName];
70
+	}
71
+
72
+	/**
73
+	 * Determines if this connection has a transaction in progress or not
74
+	 * @return boolean true if there is a transaction in progress.
75
+	 */
76
+	public function hasActiveTransaction()
77
+	{
78
+		return $this->hasActiveTransaction;
79
+	}
80
+
81
+	/**
82
+	 * Summary of beginTransaction
83
+	 * @return bool
84
+	 */
85
+	public function beginTransaction()
86
+	{
87
+		// Override the pre-existing method, which doesn't stop you from
88
+		// starting transactions within transactions - which doesn't work and
89
+		// will throw an exception. This eliminates the need to catch exceptions
90
+		// all over the rest of the code
91
+		if ($this->hasActiveTransaction) {
92
+			return false;
93
+		}
94
+		else {
95
+			// set the transaction isolation level for every transaction.
96
+			$this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;");
97
+
98
+			// start a new transaction, and return whether or not the start was
99
+			// successful
100
+			$this->hasActiveTransaction = parent::beginTransaction();
101
+
102
+			return $this->hasActiveTransaction;
103
+		}
104
+	}
105
+
106
+	/**
107
+	 * Commits the active transaction
108
+	 */
109
+	public function commit()
110
+	{
111
+		if ($this->hasActiveTransaction) {
112
+			parent::commit();
113
+			$this->hasActiveTransaction = false;
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * Rolls back a transaction
119
+	 */
120
+	public function rollBack()
121
+	{
122
+		if ($this->hasActiveTransaction) {
123
+			parent::rollback();
124
+			$this->hasActiveTransaction = false;
125
+		}
126
+	}
127 127
 }
Please login to merge, or discard this patch.
includes/DataObjects/RDnsCache.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -19,109 +19,109 @@
 block discarded – undo
19 19
  */
20 20
 class RDnsCache extends DataObject
21 21
 {
22
-    private $address;
23
-    private $data;
24
-    private $creation;
25
-
26
-    /**
27
-     * @param string      $address
28
-     * @param PdoDatabase $database
29
-     *
30
-     * @return RDnsCache|false
31
-     */
32
-    public static function getByAddress($address, PdoDatabase $database)
33
-    {
34
-        // @todo add cache invalidation (timestamp?)
35
-        $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;");
36
-        $statement->bindValue(":id", $address);
37
-
38
-        $statement->execute();
39
-
40
-        $resultObject = $statement->fetchObject(get_called_class());
41
-
42
-        if ($resultObject != false) {
43
-            $resultObject->setDatabase($database);
44
-        }
45
-
46
-        return $resultObject;
47
-    }
48
-
49
-    public function save()
50
-    {
51
-        if ($this->isNew()) {
52
-            // insert
53
-            $statement = $this->dbObject->prepare(<<<SQL
22
+	private $address;
23
+	private $data;
24
+	private $creation;
25
+
26
+	/**
27
+	 * @param string      $address
28
+	 * @param PdoDatabase $database
29
+	 *
30
+	 * @return RDnsCache|false
31
+	 */
32
+	public static function getByAddress($address, PdoDatabase $database)
33
+	{
34
+		// @todo add cache invalidation (timestamp?)
35
+		$statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;");
36
+		$statement->bindValue(":id", $address);
37
+
38
+		$statement->execute();
39
+
40
+		$resultObject = $statement->fetchObject(get_called_class());
41
+
42
+		if ($resultObject != false) {
43
+			$resultObject->setDatabase($database);
44
+		}
45
+
46
+		return $resultObject;
47
+	}
48
+
49
+	public function save()
50
+	{
51
+		if ($this->isNew()) {
52
+			// insert
53
+			$statement = $this->dbObject->prepare(<<<SQL
54 54
 INSERT INTO `rdnscache` (address, data) VALUES (:address, :data);
55 55
 SQL
56
-            );
57
-            $statement->bindValue(":address", $this->address);
58
-            $statement->bindValue(":data", $this->data);
59
-
60
-            if ($statement->execute()) {
61
-                $this->id = (int)$this->dbObject->lastInsertId();
62
-            }
63
-            else {
64
-                throw new Exception($statement->errorInfo());
65
-            }
66
-        }
67
-        else {
68
-            // update
69
-            $statement = $this->dbObject->prepare(<<<SQL
56
+			);
57
+			$statement->bindValue(":address", $this->address);
58
+			$statement->bindValue(":data", $this->data);
59
+
60
+			if ($statement->execute()) {
61
+				$this->id = (int)$this->dbObject->lastInsertId();
62
+			}
63
+			else {
64
+				throw new Exception($statement->errorInfo());
65
+			}
66
+		}
67
+		else {
68
+			// update
69
+			$statement = $this->dbObject->prepare(<<<SQL
70 70
 UPDATE `rdnscache`
71 71
 SET address = :address, data = :data, updateversion = updateversion + 1
72 72
 WHERE id = :id AND updateversion = :updateversion;
73 73
 SQL
74
-            );
75
-
76
-            $statement->bindValue(':id', $this->id);
77
-            $statement->bindValue(':updateversion', $this->updateversion);
78
-
79
-            $statement->bindValue(':address', $this->address);
80
-            $statement->bindValue(':data', $this->data);
81
-
82
-            if (!$statement->execute()) {
83
-                throw new Exception($statement->errorInfo());
84
-            }
85
-
86
-            if ($statement->rowCount() !== 1) {
87
-                throw new OptimisticLockFailedException();
88
-            }
89
-
90
-            $this->updateversion++;
91
-        }
92
-    }
93
-
94
-    public function getAddress()
95
-    {
96
-        return $this->address;
97
-    }
98
-
99
-    /**
100
-     * @param string $address
101
-     */
102
-    public function setAddress($address)
103
-    {
104
-        $this->address = $address;
105
-    }
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function getData()
111
-    {
112
-        return unserialize($this->data);
113
-    }
114
-
115
-    public function setData($data)
116
-    {
117
-        $this->data = serialize($data);
118
-    }
119
-
120
-    /**
121
-     * @return DateTimeImmutable
122
-     */
123
-    public function getCreation()
124
-    {
125
-        return new DateTimeImmutable($this->creation);
126
-    }
74
+			);
75
+
76
+			$statement->bindValue(':id', $this->id);
77
+			$statement->bindValue(':updateversion', $this->updateversion);
78
+
79
+			$statement->bindValue(':address', $this->address);
80
+			$statement->bindValue(':data', $this->data);
81
+
82
+			if (!$statement->execute()) {
83
+				throw new Exception($statement->errorInfo());
84
+			}
85
+
86
+			if ($statement->rowCount() !== 1) {
87
+				throw new OptimisticLockFailedException();
88
+			}
89
+
90
+			$this->updateversion++;
91
+		}
92
+	}
93
+
94
+	public function getAddress()
95
+	{
96
+		return $this->address;
97
+	}
98
+
99
+	/**
100
+	 * @param string $address
101
+	 */
102
+	public function setAddress($address)
103
+	{
104
+		$this->address = $address;
105
+	}
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function getData()
111
+	{
112
+		return unserialize($this->data);
113
+	}
114
+
115
+	public function setData($data)
116
+	{
117
+		$this->data = serialize($data);
118
+	}
119
+
120
+	/**
121
+	 * @return DateTimeImmutable
122
+	 */
123
+	public function getCreation()
124
+	{
125
+		return new DateTimeImmutable($this->creation);
126
+	}
127 127
 }
Please login to merge, or discard this patch.
includes/DataObjects/GeoLocation.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -21,110 +21,110 @@
 block discarded – undo
21 21
  */
22 22
 class GeoLocation extends DataObject
23 23
 {
24
-    private $address;
25
-    private $data;
26
-    private $creation;
27
-
28
-    /**
29
-     * @param string      $address
30
-     * @param PdoDatabase $database
31
-     * @param bool        $forUpdate
32
-     * @return GeoLocation
33
-     */
34
-    public static function getByAddress($address, PdoDatabase $database, $forUpdate = false)
35
-    {
36
-        $lockMode = $forUpdate ? ' FOR UPDATE' : '';
37
-        $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode;
38
-
39
-        $statement = $database->prepare($sql);
40
-        $statement->bindValue(":id", $address);
41
-
42
-        $statement->execute();
43
-
44
-        $resultObject = $statement->fetchObject(get_called_class());
45
-
46
-        if ($resultObject != false) {
47
-            $resultObject->setDatabase($database);
48
-        }
49
-
50
-        return $resultObject;
51
-    }
52
-
53
-    public function save()
54
-    {
55
-        if ($this->isNew()) {
56
-            // insert
57
-            $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;");
58
-
59
-            $statement->bindValue(":address", $this->address);
60
-            $statement->bindValue(":data", $this->data);
61
-
62
-            if ($statement->execute()) {
63
-                $this->id = (int)$this->dbObject->lastInsertId();
64
-            }
65
-            else {
66
-                throw new Exception($statement->errorInfo());
67
-            }
68
-        }
69
-        else {
70
-            // update
71
-            $statement = $this->dbObject->prepare(<<<SQL
24
+	private $address;
25
+	private $data;
26
+	private $creation;
27
+
28
+	/**
29
+	 * @param string      $address
30
+	 * @param PdoDatabase $database
31
+	 * @param bool        $forUpdate
32
+	 * @return GeoLocation
33
+	 */
34
+	public static function getByAddress($address, PdoDatabase $database, $forUpdate = false)
35
+	{
36
+		$lockMode = $forUpdate ? ' FOR UPDATE' : '';
37
+		$sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode;
38
+
39
+		$statement = $database->prepare($sql);
40
+		$statement->bindValue(":id", $address);
41
+
42
+		$statement->execute();
43
+
44
+		$resultObject = $statement->fetchObject(get_called_class());
45
+
46
+		if ($resultObject != false) {
47
+			$resultObject->setDatabase($database);
48
+		}
49
+
50
+		return $resultObject;
51
+	}
52
+
53
+	public function save()
54
+	{
55
+		if ($this->isNew()) {
56
+			// insert
57
+			$statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;");
58
+
59
+			$statement->bindValue(":address", $this->address);
60
+			$statement->bindValue(":data", $this->data);
61
+
62
+			if ($statement->execute()) {
63
+				$this->id = (int)$this->dbObject->lastInsertId();
64
+			}
65
+			else {
66
+				throw new Exception($statement->errorInfo());
67
+			}
68
+		}
69
+		else {
70
+			// update
71
+			$statement = $this->dbObject->prepare(<<<SQL
72 72
 UPDATE `geolocation`
73 73
 SET address = :address, data = :data, updateversion = updateversion + 1
74 74
 WHERE id = :id AND updateversion = :updateversion;
75 75
 SQL
76
-            );
77
-
78
-            $statement->bindValue(":id", $this->id);
79
-            $statement->bindValue(":updateversion", $this->updateversion);
80
-
81
-            $statement->bindValue(":address", $this->address);
82
-            $statement->bindValue(":data", $this->data);
83
-
84
-            if (!$statement->execute()) {
85
-                throw new Exception($statement->errorInfo());
86
-            }
87
-
88
-            if ($statement->rowCount() !== 1) {
89
-                throw new OptimisticLockFailedException();
90
-            }
91
-
92
-            $this->updateversion++;
93
-        }
94
-    }
95
-
96
-    public function getAddress()
97
-    {
98
-        return $this->address;
99
-    }
100
-
101
-    /**
102
-     * @param string $address
103
-     */
104
-    public function setAddress($address)
105
-    {
106
-        $this->address = $address;
107
-    }
108
-
109
-    /**
110
-     * @return array
111
-     */
112
-    public function getData()
113
-    {
114
-        return unserialize($this->data);
115
-    }
116
-
117
-    /**
118
-     * @param array $data
119
-     */
120
-    public function setData($data)
121
-    {
122
-        $this->data = serialize($data);
123
-    }
124
-
125
-    /** @return DateTimeImmutable */
126
-    public function getCreation()
127
-    {
128
-        return new DateTimeImmutable($this->creation);
129
-    }
76
+			);
77
+
78
+			$statement->bindValue(":id", $this->id);
79
+			$statement->bindValue(":updateversion", $this->updateversion);
80
+
81
+			$statement->bindValue(":address", $this->address);
82
+			$statement->bindValue(":data", $this->data);
83
+
84
+			if (!$statement->execute()) {
85
+				throw new Exception($statement->errorInfo());
86
+			}
87
+
88
+			if ($statement->rowCount() !== 1) {
89
+				throw new OptimisticLockFailedException();
90
+			}
91
+
92
+			$this->updateversion++;
93
+		}
94
+	}
95
+
96
+	public function getAddress()
97
+	{
98
+		return $this->address;
99
+	}
100
+
101
+	/**
102
+	 * @param string $address
103
+	 */
104
+	public function setAddress($address)
105
+	{
106
+		$this->address = $address;
107
+	}
108
+
109
+	/**
110
+	 * @return array
111
+	 */
112
+	public function getData()
113
+	{
114
+		return unserialize($this->data);
115
+	}
116
+
117
+	/**
118
+	 * @param array $data
119
+	 */
120
+	public function setData($data)
121
+	{
122
+		$this->data = serialize($data);
123
+	}
124
+
125
+	/** @return DateTimeImmutable */
126
+	public function getCreation()
127
+	{
128
+		return new DateTimeImmutable($this->creation);
129
+	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
     public static function getByAddress($address, PdoDatabase $database, $forUpdate = false)
35 35
     {
36 36
         $lockMode = $forUpdate ? ' FOR UPDATE' : '';
37
-        $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode;
37
+        $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1".$lockMode;
38 38
 
39 39
         $statement = $database->prepare($sql);
40 40
         $statement->bindValue(":id", $address);
Please login to merge, or discard this patch.
includes/DataObjects/Request.php 1 patch
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -21,30 +21,30 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Request extends DataObject
23 23
 {
24
-    private $email;
25
-    private $ip;
26
-    private $name;
27
-    /** @var string|null */
28
-    private $comment;
29
-    private $status = "Open";
30
-    private $date;
31
-    private $emailsent = 0;
32
-    private $emailconfirm;
33
-    /** @var int|null */
34
-    private $reserved = null;
35
-    private $useragent;
36
-    private $forwardedip;
37
-    private $hasComments = false;
38
-    private $hasCommentsResolved = false;
39
-
40
-    /**
41
-     * @throws Exception
42
-     */
43
-    public function save()
44
-    {
45
-        if ($this->isNew()) {
46
-            // insert
47
-            $statement = $this->dbObject->prepare(<<<SQL
24
+	private $email;
25
+	private $ip;
26
+	private $name;
27
+	/** @var string|null */
28
+	private $comment;
29
+	private $status = "Open";
30
+	private $date;
31
+	private $emailsent = 0;
32
+	private $emailconfirm;
33
+	/** @var int|null */
34
+	private $reserved = null;
35
+	private $useragent;
36
+	private $forwardedip;
37
+	private $hasComments = false;
38
+	private $hasCommentsResolved = false;
39
+
40
+	/**
41
+	 * @throws Exception
42
+	 */
43
+	public function save()
44
+	{
45
+		if ($this->isNew()) {
46
+			// insert
47
+			$statement = $this->dbObject->prepare(<<<SQL
48 48
 INSERT INTO `request` (
49 49
 	email, ip, name, comment, status, date, emailsent,
50 50
 	emailconfirm, reserved, useragent, forwardedip
@@ -53,28 +53,28 @@  discard block
 block discarded – undo
53 53
 	:emailconfirm, :reserved, :useragent, :forwardedip
54 54
 );
55 55
 SQL
56
-            );
57
-            $statement->bindValue(':email', $this->email);
58
-            $statement->bindValue(':ip', $this->ip);
59
-            $statement->bindValue(':name', $this->name);
60
-            $statement->bindValue(':comment', $this->comment);
61
-            $statement->bindValue(':status', $this->status);
62
-            $statement->bindValue(':emailsent', $this->emailsent);
63
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
64
-            $statement->bindValue(':reserved', $this->reserved);
65
-            $statement->bindValue(':useragent', $this->useragent);
66
-            $statement->bindValue(':forwardedip', $this->forwardedip);
67
-
68
-            if ($statement->execute()) {
69
-                $this->id = (int)$this->dbObject->lastInsertId();
70
-            }
71
-            else {
72
-                throw new Exception($statement->errorInfo());
73
-            }
74
-        }
75
-        else {
76
-            // update
77
-            $statement = $this->dbObject->prepare(<<<SQL
56
+			);
57
+			$statement->bindValue(':email', $this->email);
58
+			$statement->bindValue(':ip', $this->ip);
59
+			$statement->bindValue(':name', $this->name);
60
+			$statement->bindValue(':comment', $this->comment);
61
+			$statement->bindValue(':status', $this->status);
62
+			$statement->bindValue(':emailsent', $this->emailsent);
63
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
64
+			$statement->bindValue(':reserved', $this->reserved);
65
+			$statement->bindValue(':useragent', $this->useragent);
66
+			$statement->bindValue(':forwardedip', $this->forwardedip);
67
+
68
+			if ($statement->execute()) {
69
+				$this->id = (int)$this->dbObject->lastInsertId();
70
+			}
71
+			else {
72
+				throw new Exception($statement->errorInfo());
73
+			}
74
+		}
75
+		else {
76
+			// update
77
+			$statement = $this->dbObject->prepare(<<<SQL
78 78
 UPDATE `request` SET
79 79
 	status = :status,
80 80
 	emailsent = :emailsent,
@@ -83,163 +83,163 @@  discard block
 block discarded – undo
83 83
 	updateversion = updateversion + 1
84 84
 WHERE id = :id AND updateversion = :updateversion;
85 85
 SQL
86
-            );
87
-
88
-            $statement->bindValue(':id', $this->id);
89
-            $statement->bindValue(':updateversion', $this->updateversion);
90
-
91
-            $statement->bindValue(':status', $this->status);
92
-            $statement->bindValue(':emailsent', $this->emailsent);
93
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
94
-            $statement->bindValue(':reserved', $this->reserved);
95
-
96
-            if (!$statement->execute()) {
97
-                throw new Exception($statement->errorInfo());
98
-            }
99
-
100
-            if ($statement->rowCount() !== 1) {
101
-                throw new OptimisticLockFailedException();
102
-            }
103
-
104
-            $this->updateversion++;
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function getIp()
112
-    {
113
-        return $this->ip;
114
-    }
115
-
116
-    /**
117
-     * @param string $ip
118
-     */
119
-    public function setIp($ip)
120
-    {
121
-        $this->ip = $ip;
122
-    }
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function getName()
128
-    {
129
-        return $this->name;
130
-    }
131
-
132
-    /**
133
-     * @param string $name
134
-     */
135
-    public function setName($name)
136
-    {
137
-        $this->name = $name;
138
-    }
139
-
140
-    /**
141
-     * @return string|null
142
-     */
143
-    public function getComment()
144
-    {
145
-        return $this->comment;
146
-    }
147
-
148
-    /**
149
-     * @param string $comment
150
-     */
151
-    public function setComment($comment)
152
-    {
153
-        $this->comment = $comment;
154
-    }
155
-
156
-    /**
157
-     * @return string
158
-     */
159
-    public function getStatus()
160
-    {
161
-        return $this->status;
162
-    }
163
-
164
-    /**
165
-     * @param string $status
166
-     */
167
-    public function setStatus($status)
168
-    {
169
-        $this->status = $status;
170
-    }
171
-
172
-    /**
173
-     * Returns the time the request was first submitted
174
-     *
175
-     * @return DateTimeImmutable
176
-     */
177
-    public function getDate()
178
-    {
179
-        return new DateTimeImmutable($this->date);
180
-    }
181
-
182
-    /**
183
-     * @return bool
184
-     */
185
-    public function getEmailSent()
186
-    {
187
-        return $this->emailsent == "1";
188
-    }
189
-
190
-    /**
191
-     * @param bool $emailSent
192
-     */
193
-    public function setEmailSent($emailSent)
194
-    {
195
-        $this->emailsent = $emailSent ? 1 : 0;
196
-    }
197
-
198
-    /**
199
-     * @return int|null
200
-     */
201
-    public function getReserved()
202
-    {
203
-        return $this->reserved;
204
-    }
205
-
206
-    /**
207
-     * @param int|null $reserved
208
-     */
209
-    public function setReserved($reserved)
210
-    {
211
-        $this->reserved = $reserved;
212
-    }
213
-
214
-    /**
215
-     * @return string
216
-     */
217
-    public function getUserAgent()
218
-    {
219
-        return $this->useragent;
220
-    }
221
-
222
-    /**
223
-     * @param string $useragent
224
-     */
225
-    public function setUserAgent($useragent)
226
-    {
227
-        $this->useragent = $useragent;
228
-    }
229
-
230
-    /**
231
-     * @return string|null
232
-     */
233
-    public function getForwardedIp()
234
-    {
235
-        return $this->forwardedip;
236
-    }
237
-
238
-    /**
239
-     * @param string|null $forwardedip
240
-     */
241
-    public function setForwardedIp($forwardedip)
242
-    {
86
+			);
87
+
88
+			$statement->bindValue(':id', $this->id);
89
+			$statement->bindValue(':updateversion', $this->updateversion);
90
+
91
+			$statement->bindValue(':status', $this->status);
92
+			$statement->bindValue(':emailsent', $this->emailsent);
93
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
94
+			$statement->bindValue(':reserved', $this->reserved);
95
+
96
+			if (!$statement->execute()) {
97
+				throw new Exception($statement->errorInfo());
98
+			}
99
+
100
+			if ($statement->rowCount() !== 1) {
101
+				throw new OptimisticLockFailedException();
102
+			}
103
+
104
+			$this->updateversion++;
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @return string
110
+	 */
111
+	public function getIp()
112
+	{
113
+		return $this->ip;
114
+	}
115
+
116
+	/**
117
+	 * @param string $ip
118
+	 */
119
+	public function setIp($ip)
120
+	{
121
+		$this->ip = $ip;
122
+	}
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function getName()
128
+	{
129
+		return $this->name;
130
+	}
131
+
132
+	/**
133
+	 * @param string $name
134
+	 */
135
+	public function setName($name)
136
+	{
137
+		$this->name = $name;
138
+	}
139
+
140
+	/**
141
+	 * @return string|null
142
+	 */
143
+	public function getComment()
144
+	{
145
+		return $this->comment;
146
+	}
147
+
148
+	/**
149
+	 * @param string $comment
150
+	 */
151
+	public function setComment($comment)
152
+	{
153
+		$this->comment = $comment;
154
+	}
155
+
156
+	/**
157
+	 * @return string
158
+	 */
159
+	public function getStatus()
160
+	{
161
+		return $this->status;
162
+	}
163
+
164
+	/**
165
+	 * @param string $status
166
+	 */
167
+	public function setStatus($status)
168
+	{
169
+		$this->status = $status;
170
+	}
171
+
172
+	/**
173
+	 * Returns the time the request was first submitted
174
+	 *
175
+	 * @return DateTimeImmutable
176
+	 */
177
+	public function getDate()
178
+	{
179
+		return new DateTimeImmutable($this->date);
180
+	}
181
+
182
+	/**
183
+	 * @return bool
184
+	 */
185
+	public function getEmailSent()
186
+	{
187
+		return $this->emailsent == "1";
188
+	}
189
+
190
+	/**
191
+	 * @param bool $emailSent
192
+	 */
193
+	public function setEmailSent($emailSent)
194
+	{
195
+		$this->emailsent = $emailSent ? 1 : 0;
196
+	}
197
+
198
+	/**
199
+	 * @return int|null
200
+	 */
201
+	public function getReserved()
202
+	{
203
+		return $this->reserved;
204
+	}
205
+
206
+	/**
207
+	 * @param int|null $reserved
208
+	 */
209
+	public function setReserved($reserved)
210
+	{
211
+		$this->reserved = $reserved;
212
+	}
213
+
214
+	/**
215
+	 * @return string
216
+	 */
217
+	public function getUserAgent()
218
+	{
219
+		return $this->useragent;
220
+	}
221
+
222
+	/**
223
+	 * @param string $useragent
224
+	 */
225
+	public function setUserAgent($useragent)
226
+	{
227
+		$this->useragent = $useragent;
228
+	}
229
+
230
+	/**
231
+	 * @return string|null
232
+	 */
233
+	public function getForwardedIp()
234
+	{
235
+		return $this->forwardedip;
236
+	}
237
+
238
+	/**
239
+	 * @param string|null $forwardedip
240
+	 */
241
+	public function setForwardedIp($forwardedip)
242
+	{
243 243
 		// Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't.
244 244
 
245 245
 		$xff = explode(',', $forwardedip);
@@ -253,83 +253,83 @@  discard block
 block discarded – undo
253 253
 		}
254 254
 
255 255
 		$this->forwardedip = implode(", ", $valid);
256
-    }
257
-
258
-    /**
259
-     * @return bool
260
-     */
261
-    public function hasComments()
262
-    {
263
-        if ($this->hasCommentsResolved) {
264
-            return $this->hasComments;
265
-        }
266
-
267
-        if ($this->comment != "") {
268
-            $this->hasComments = true;
269
-            $this->hasCommentsResolved = true;
270
-
271
-            return true;
272
-        }
273
-
274
-        $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
275
-        $commentsQuery->bindValue(":id", $this->id);
276
-
277
-        $commentsQuery->execute();
278
-
279
-        $this->hasComments = ($commentsQuery->fetchColumn() != 0);
280
-        $this->hasCommentsResolved = true;
281
-
282
-        return $this->hasComments;
283
-    }
284
-
285
-    /**
286
-     * @return string
287
-     */
288
-    public function getEmailConfirm()
289
-    {
290
-        return $this->emailconfirm;
291
-    }
292
-
293
-    /**
294
-     * @param string $emailconfirm
295
-     */
296
-    public function setEmailConfirm($emailconfirm)
297
-    {
298
-        $this->emailconfirm = $emailconfirm;
299
-    }
300
-
301
-    public function generateEmailConfirmationHash()
302
-    {
303
-        $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
304
-    }
305
-
306
-    /**
307
-     * @return string|null
308
-     */
309
-    public function getEmail()
310
-    {
311
-        return $this->email;
312
-    }
313
-
314
-    /**
315
-     * @param string|null $email
316
-     */
317
-    public function setEmail($email)
318
-    {
319
-        $this->email = $email;
320
-    }
321
-
322
-    /**
323
-     * @return string
324
-     * @throws Exception
325
-     */
326
-    public function getClosureReason()
327
-    {
328
-        if ($this->status != 'Closed') {
329
-            throw new Exception("Can't get closure reason for open request.");
330
-        }
331
-
332
-        $statement = $this->dbObject->prepare(<<<SQL
256
+	}
257
+
258
+	/**
259
+	 * @return bool
260
+	 */
261
+	public function hasComments()
262
+	{
263
+		if ($this->hasCommentsResolved) {
264
+			return $this->hasComments;
265
+		}
266
+
267
+		if ($this->comment != "") {
268
+			$this->hasComments = true;
269
+			$this->hasCommentsResolved = true;
270
+
271
+			return true;
272
+		}
273
+
274
+		$commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
275
+		$commentsQuery->bindValue(":id", $this->id);
276
+
277
+		$commentsQuery->execute();
278
+
279
+		$this->hasComments = ($commentsQuery->fetchColumn() != 0);
280
+		$this->hasCommentsResolved = true;
281
+
282
+		return $this->hasComments;
283
+	}
284
+
285
+	/**
286
+	 * @return string
287
+	 */
288
+	public function getEmailConfirm()
289
+	{
290
+		return $this->emailconfirm;
291
+	}
292
+
293
+	/**
294
+	 * @param string $emailconfirm
295
+	 */
296
+	public function setEmailConfirm($emailconfirm)
297
+	{
298
+		$this->emailconfirm = $emailconfirm;
299
+	}
300
+
301
+	public function generateEmailConfirmationHash()
302
+	{
303
+		$this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
304
+	}
305
+
306
+	/**
307
+	 * @return string|null
308
+	 */
309
+	public function getEmail()
310
+	{
311
+		return $this->email;
312
+	}
313
+
314
+	/**
315
+	 * @param string|null $email
316
+	 */
317
+	public function setEmail($email)
318
+	{
319
+		$this->email = $email;
320
+	}
321
+
322
+	/**
323
+	 * @return string
324
+	 * @throws Exception
325
+	 */
326
+	public function getClosureReason()
327
+	{
328
+		if ($this->status != 'Closed') {
329
+			throw new Exception("Can't get closure reason for open request.");
330
+		}
331
+
332
+		$statement = $this->dbObject->prepare(<<<SQL
333 333
 SELECT closes.mail_desc
334 334
 FROM log
335 335
 INNER JOIN closes ON log.action = closes.closes
@@ -339,25 +339,25 @@  discard block
 block discarded – undo
339 339
 ORDER BY log.timestamp DESC
340 340
 LIMIT 1;
341 341
 SQL
342
-        );
343
-
344
-        $statement->bindValue(":requestId", $this->id);
345
-        $statement->execute();
346
-        $reason = $statement->fetchColumn();
347
-
348
-        return $reason;
349
-    }
350
-
351
-    /**
352
-     * Gets a value indicating whether the request was closed as created or not.
353
-     */
354
-    public function getWasCreated()
355
-    {
356
-        if ($this->status != 'Closed') {
357
-            throw new Exception("Can't get closure reason for open request.");
358
-        }
342
+		);
343
+
344
+		$statement->bindValue(":requestId", $this->id);
345
+		$statement->execute();
346
+		$reason = $statement->fetchColumn();
347
+
348
+		return $reason;
349
+	}
350
+
351
+	/**
352
+	 * Gets a value indicating whether the request was closed as created or not.
353
+	 */
354
+	public function getWasCreated()
355
+	{
356
+		if ($this->status != 'Closed') {
357
+			throw new Exception("Can't get closure reason for open request.");
358
+		}
359 359
 
360
-        $statement = $this->dbObject->prepare(<<<SQL
360
+		$statement = $this->dbObject->prepare(<<<SQL
361 361
 SELECT emailtemplate.oncreated, log.action
362 362
 FROM log
363 363
 LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action
@@ -367,60 +367,60 @@  discard block
 block discarded – undo
367 367
 ORDER BY log.timestamp DESC
368 368
 LIMIT 1;
369 369
 SQL
370
-        );
371
-
372
-        $statement->bindValue(":requestId", $this->id);
373
-        $statement->execute();
374
-        $onCreated = $statement->fetchColumn(0);
375
-        $logAction = $statement->fetchColumn(1);
376
-        $statement->closeCursor();
377
-
378
-        if ($onCreated === null) {
379
-            return $logAction === "Closed custom-y";
380
-        }
381
-
382
-        return (bool)$onCreated;
383
-    }
384
-
385
-    /**
386
-     * @return DateTime
387
-     */
388
-    public function getClosureDate()
389
-    {
390
-        $logQuery = $this->dbObject->prepare(<<<SQL
370
+		);
371
+
372
+		$statement->bindValue(":requestId", $this->id);
373
+		$statement->execute();
374
+		$onCreated = $statement->fetchColumn(0);
375
+		$logAction = $statement->fetchColumn(1);
376
+		$statement->closeCursor();
377
+
378
+		if ($onCreated === null) {
379
+			return $logAction === "Closed custom-y";
380
+		}
381
+
382
+		return (bool)$onCreated;
383
+	}
384
+
385
+	/**
386
+	 * @return DateTime
387
+	 */
388
+	public function getClosureDate()
389
+	{
390
+		$logQuery = $this->dbObject->prepare(<<<SQL
391 391
 SELECT timestamp FROM log
392 392
 WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%'
393 393
 ORDER BY timestamp DESC LIMIT 1;
394 394
 SQL
395
-        );
396
-        $logQuery->bindValue(":request", $this->getId());
397
-        $logQuery->execute();
398
-        $logTime = $logQuery->fetchColumn();
399
-        $logQuery->closeCursor();
400
-
401
-        return new DateTime($logTime);
402
-    }
403
-
404
-    /**
405
-     * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
406
-     * data to unauthorised* users.
407
-     *
408
-     * *:Not tool admins, check users, or the reserving user.
409
-     *
410
-     * @return string
411
-     *
412
-     * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
413
-     *       Maybe depend on the last logged action timestamp?
414
-     */
415
-    public function getRevealHash()
416
-    {
417
-        $data = $this->id         // unique per request
418
-            . '|' . $this->ip           // }
419
-            . '|' . $this->forwardedip  // } private data not known to those without access
420
-            . '|' . $this->useragent    // }
421
-            . '|' . $this->email        // }
422
-            . '|' . $this->status;      // to rudimentarily invalidate the token on status change
423
-
424
-        return hash('sha256', $data);
425
-    }
395
+		);
396
+		$logQuery->bindValue(":request", $this->getId());
397
+		$logQuery->execute();
398
+		$logTime = $logQuery->fetchColumn();
399
+		$logQuery->closeCursor();
400
+
401
+		return new DateTime($logTime);
402
+	}
403
+
404
+	/**
405
+	 * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
406
+	 * data to unauthorised* users.
407
+	 *
408
+	 * *:Not tool admins, check users, or the reserving user.
409
+	 *
410
+	 * @return string
411
+	 *
412
+	 * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
413
+	 *       Maybe depend on the last logged action timestamp?
414
+	 */
415
+	public function getRevealHash()
416
+	{
417
+		$data = $this->id         // unique per request
418
+			. '|' . $this->ip           // }
419
+			. '|' . $this->forwardedip  // } private data not known to those without access
420
+			. '|' . $this->useragent    // }
421
+			. '|' . $this->email        // }
422
+			. '|' . $this->status;      // to rudimentarily invalidate the token on status change
423
+
424
+		return hash('sha256', $data);
425
+	}
426 426
 }
Please login to merge, or discard this patch.
includes/DataObjects/WelcomeTemplate.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -19,166 +19,166 @@
 block discarded – undo
19 19
  */
20 20
 class WelcomeTemplate extends DataObject
21 21
 {
22
-    /** @var string */
23
-    private $usercode;
24
-    /** @var string */
25
-    private $botcode;
26
-    private $usageCache;
27
-    private $deleted = 0;
28
-
29
-    /**
30
-     * Summary of getAll
31
-     *
32
-     * @param PdoDatabase $database
33
-     *
34
-     * @return WelcomeTemplate[]
35
-     */
36
-    public static function getAll(PdoDatabase $database)
37
-    {
38
-        $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
-
40
-        $statement->execute();
41
-
42
-        $result = array();
43
-        /** @var WelcomeTemplate $v */
44
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
-            $v->setDatabase($database);
46
-            $result[] = $v;
47
-        }
48
-
49
-        return $result;
50
-    }
51
-
52
-    /**
53
-     * @throws Exception
54
-     */
55
-    public function save()
56
-    {
57
-        if ($this->isNew()) {
58
-            // insert
59
-            $statement = $this->dbObject->prepare(<<<SQL
22
+	/** @var string */
23
+	private $usercode;
24
+	/** @var string */
25
+	private $botcode;
26
+	private $usageCache;
27
+	private $deleted = 0;
28
+
29
+	/**
30
+	 * Summary of getAll
31
+	 *
32
+	 * @param PdoDatabase $database
33
+	 *
34
+	 * @return WelcomeTemplate[]
35
+	 */
36
+	public static function getAll(PdoDatabase $database)
37
+	{
38
+		$statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
+
40
+		$statement->execute();
41
+
42
+		$result = array();
43
+		/** @var WelcomeTemplate $v */
44
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
+			$v->setDatabase($database);
46
+			$result[] = $v;
47
+		}
48
+
49
+		return $result;
50
+	}
51
+
52
+	/**
53
+	 * @throws Exception
54
+	 */
55
+	public function save()
56
+	{
57
+		if ($this->isNew()) {
58
+			// insert
59
+			$statement = $this->dbObject->prepare(<<<SQL
60 60
 INSERT INTO welcometemplate (usercode, botcode) VALUES (:usercode, :botcode);
61 61
 SQL
62
-            );
63
-            $statement->bindValue(":usercode", $this->usercode);
64
-            $statement->bindValue(":botcode", $this->botcode);
65
-
66
-            if ($statement->execute()) {
67
-                $this->id = (int)$this->dbObject->lastInsertId();
68
-            }
69
-            else {
70
-                throw new Exception($statement->errorInfo());
71
-            }
72
-        }
73
-        else {
74
-            // update
75
-            $statement = $this->dbObject->prepare(<<<SQL
62
+			);
63
+			$statement->bindValue(":usercode", $this->usercode);
64
+			$statement->bindValue(":botcode", $this->botcode);
65
+
66
+			if ($statement->execute()) {
67
+				$this->id = (int)$this->dbObject->lastInsertId();
68
+			}
69
+			else {
70
+				throw new Exception($statement->errorInfo());
71
+			}
72
+		}
73
+		else {
74
+			// update
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 UPDATE `welcometemplate`
77 77
 SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1
78 78
 WHERE id = :id AND updateversion = :updateversion;
79 79
 SQL
80
-            );
81
-
82
-            $statement->bindValue(':id', $this->id);
83
-            $statement->bindValue(':updateversion', $this->updateversion);
84
-
85
-            $statement->bindValue(':usercode', $this->usercode);
86
-            $statement->bindValue(':botcode', $this->botcode);
87
-
88
-            if (!$statement->execute()) {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-
92
-            if ($statement->rowCount() !== 1) {
93
-                throw new OptimisticLockFailedException();
94
-            }
95
-
96
-            $this->updateversion++;
97
-        }
98
-    }
99
-
100
-    /**
101
-     * @return string
102
-     */
103
-    public function getUserCode()
104
-    {
105
-        return $this->usercode;
106
-    }
107
-
108
-    /**
109
-     * @param string $usercode
110
-     */
111
-    public function setUserCode($usercode)
112
-    {
113
-        $this->usercode = $usercode;
114
-    }
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public function getBotCode()
120
-    {
121
-        return $this->botcode;
122
-    }
123
-
124
-    /**
125
-     * @param string $botcode
126
-     */
127
-    public function setBotCode($botcode)
128
-    {
129
-        $this->botcode = $botcode;
130
-    }
131
-
132
-    /**
133
-     * @return User[]
134
-     */
135
-    public function getUsersUsingTemplate()
136
-    {
137
-        if ($this->usageCache === null) {
138
-            $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
139
-
140
-            $statement->execute(array(":id" => $this->id));
141
-
142
-            $result = array();
143
-            /** @var WelcomeTemplate $v */
144
-            foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
145
-                $v->setDatabase($this->dbObject);
146
-                $result[] = $v;
147
-            }
148
-
149
-            $this->usageCache = $result;
150
-        }
151
-
152
-        return $this->usageCache;
153
-    }
154
-
155
-    /**
156
-     * Deletes the object from the database
157
-     */
158
-    public function delete()
159
-    {
160
-        if ($this->id === null) {
161
-            // wtf?
162
-            return;
163
-        }
164
-
165
-        $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
166
-        $statement = $this->dbObject->prepare($deleteQuery);
167
-
168
-        $statement->bindValue(":id", $this->id);
169
-        $statement->bindValue(":updateversion", $this->updateversion);
170
-        $statement->execute();
171
-
172
-        if ($statement->rowCount() !== 1) {
173
-            throw new OptimisticLockFailedException();
174
-        }
175
-    }
176
-
177
-    /**
178
-     * @return bool
179
-     */
180
-    public function isDeleted()
181
-    {
182
-        return ((int)$this->deleted) === 1;
183
-    }
80
+			);
81
+
82
+			$statement->bindValue(':id', $this->id);
83
+			$statement->bindValue(':updateversion', $this->updateversion);
84
+
85
+			$statement->bindValue(':usercode', $this->usercode);
86
+			$statement->bindValue(':botcode', $this->botcode);
87
+
88
+			if (!$statement->execute()) {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+
92
+			if ($statement->rowCount() !== 1) {
93
+				throw new OptimisticLockFailedException();
94
+			}
95
+
96
+			$this->updateversion++;
97
+		}
98
+	}
99
+
100
+	/**
101
+	 * @return string
102
+	 */
103
+	public function getUserCode()
104
+	{
105
+		return $this->usercode;
106
+	}
107
+
108
+	/**
109
+	 * @param string $usercode
110
+	 */
111
+	public function setUserCode($usercode)
112
+	{
113
+		$this->usercode = $usercode;
114
+	}
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public function getBotCode()
120
+	{
121
+		return $this->botcode;
122
+	}
123
+
124
+	/**
125
+	 * @param string $botcode
126
+	 */
127
+	public function setBotCode($botcode)
128
+	{
129
+		$this->botcode = $botcode;
130
+	}
131
+
132
+	/**
133
+	 * @return User[]
134
+	 */
135
+	public function getUsersUsingTemplate()
136
+	{
137
+		if ($this->usageCache === null) {
138
+			$statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
139
+
140
+			$statement->execute(array(":id" => $this->id));
141
+
142
+			$result = array();
143
+			/** @var WelcomeTemplate $v */
144
+			foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
145
+				$v->setDatabase($this->dbObject);
146
+				$result[] = $v;
147
+			}
148
+
149
+			$this->usageCache = $result;
150
+		}
151
+
152
+		return $this->usageCache;
153
+	}
154
+
155
+	/**
156
+	 * Deletes the object from the database
157
+	 */
158
+	public function delete()
159
+	{
160
+		if ($this->id === null) {
161
+			// wtf?
162
+			return;
163
+		}
164
+
165
+		$deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
166
+		$statement = $this->dbObject->prepare($deleteQuery);
167
+
168
+		$statement->bindValue(":id", $this->id);
169
+		$statement->bindValue(":updateversion", $this->updateversion);
170
+		$statement->execute();
171
+
172
+		if ($statement->rowCount() !== 1) {
173
+			throw new OptimisticLockFailedException();
174
+		}
175
+	}
176
+
177
+	/**
178
+	 * @return bool
179
+	 */
180
+	public function isDeleted()
181
+	{
182
+		return ((int)$this->deleted) === 1;
183
+	}
184 184
 }
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -21,176 +21,176 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EmailTemplate extends DataObject
23 23
 {
24
-    /** Note, also used in template-table.tpl */
25
-    const CREATED = "created";
26
-    /** Note, also used in template-table.tpl */
27
-    const NOT_CREATED = "not created";
28
-    /** Note, also used in template-table.tpl */
29
-    const NONE = null;
30
-    /** @var string the name of the template */
31
-    private $name;
32
-    private $text;
33
-    /** @var string|null */
34
-    private $jsquestion;
35
-    private $active = 1;
36
-    private $preloadonly = 0;
37
-    private $defaultaction = self::NOT_CREATED;
38
-
39
-    /**
40
-     * Gets active non-preload templates
41
-     *
42
-     * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
-     * @param PdoDatabase $database
44
-     *
45
-     * @return array|false
46
-     */
47
-    public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
-    {
49
-        global $createdid;
50
-
51
-        $statement = $database->prepare(<<<SQL
24
+	/** Note, also used in template-table.tpl */
25
+	const CREATED = "created";
26
+	/** Note, also used in template-table.tpl */
27
+	const NOT_CREATED = "not created";
28
+	/** Note, also used in template-table.tpl */
29
+	const NONE = null;
30
+	/** @var string the name of the template */
31
+	private $name;
32
+	private $text;
33
+	/** @var string|null */
34
+	private $jsquestion;
35
+	private $active = 1;
36
+	private $preloadonly = 0;
37
+	private $defaultaction = self::NOT_CREATED;
38
+
39
+	/**
40
+	 * Gets active non-preload templates
41
+	 *
42
+	 * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
+	 * @param PdoDatabase $database
44
+	 *
45
+	 * @return array|false
46
+	 */
47
+	public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
+	{
49
+		global $createdid;
50
+
51
+		$statement = $database->prepare(<<<SQL
52 52
 SELECT * FROM `emailtemplate`
53 53
 WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND id != :createdid;
54 54
 SQL
55
-        );
56
-        $statement->bindValue(":createdid", $createdid);
57
-        $statement->bindValue(":forcreated", $defaultAction);
58
-
59
-        $statement->execute();
60
-
61
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
-
63
-        /** @var EmailTemplate $t */
64
-        foreach ($resultObject as $t) {
65
-            $t->setDatabase($database);
66
-        }
67
-
68
-        return $resultObject;
69
-    }
70
-
71
-    /**
72
-     * Gets active non-preload and preload templates, optionally filtered by the default action.
73
-     *
74
-     * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
-     *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
-     *                                        just get everything.
77
-     * @param PdoDatabase      $database
78
-     *
79
-     * @return array|false
80
-     */
81
-    public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
-    {
83
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
-
85
-        if ($defaultAction === false) {
86
-            $statement = $database->prepare(
87
-                "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
-        }
89
-
90
-        if ($defaultAction === null) {
91
-            $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
-        }
93
-
94
-        $statement->bindValue(":forcreated", $defaultAction);
95
-
96
-        $statement->execute();
97
-
98
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
-
100
-        /** @var EmailTemplate $t */
101
-        foreach ($resultObject as $t) {
102
-            $t->setDatabase($database);
103
-        }
104
-
105
-        return $resultObject;
106
-    }
107
-
108
-    /**
109
-     * Gets all the unactive templates
110
-     *
111
-     * @param PdoDatabase $database
112
-     *
113
-     * @return array
114
-     */
115
-    public static function getAllInactiveTemplates(PdoDatabase $database)
116
-    {
117
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
-        $statement->execute();
119
-
120
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
-
122
-        /** @var EmailTemplate $t */
123
-        foreach ($resultObject as $t) {
124
-            $t->setDatabase($database);
125
-        }
126
-
127
-        return $resultObject;
128
-    }
129
-
130
-    /**
131
-     * @param string      $name
132
-     * @param PdoDatabase $database
133
-     *
134
-     * @return EmailTemplate|false
135
-     */
136
-    public static function getByName($name, PdoDatabase $database)
137
-    {
138
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
-        $statement->bindValue(":name", $name);
140
-
141
-        $statement->execute();
142
-
143
-        $resultObject = $statement->fetchObject(get_called_class());
144
-
145
-        if ($resultObject != false) {
146
-            $resultObject->setDatabase($database);
147
-        }
148
-
149
-        return $resultObject;
150
-    }
151
-
152
-    /**
153
-     * @return EmailTemplate
154
-     */
155
-    public static function getDroppedTemplate()
156
-    {
157
-        $t = new EmailTemplate();
158
-        $t->id = 0;
159
-        $t->active = 1;
160
-        $t->name = 'Dropped';
161
-
162
-        return $t;
163
-    }
164
-
165
-    /**
166
-     * @throws Exception
167
-     */
168
-    public function save()
169
-    {
170
-        if ($this->isNew()) {
171
-            // insert
172
-            $statement = $this->dbObject->prepare(<<<SQL
55
+		);
56
+		$statement->bindValue(":createdid", $createdid);
57
+		$statement->bindValue(":forcreated", $defaultAction);
58
+
59
+		$statement->execute();
60
+
61
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
+
63
+		/** @var EmailTemplate $t */
64
+		foreach ($resultObject as $t) {
65
+			$t->setDatabase($database);
66
+		}
67
+
68
+		return $resultObject;
69
+	}
70
+
71
+	/**
72
+	 * Gets active non-preload and preload templates, optionally filtered by the default action.
73
+	 *
74
+	 * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
+	 *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
+	 *                                        just get everything.
77
+	 * @param PdoDatabase      $database
78
+	 *
79
+	 * @return array|false
80
+	 */
81
+	public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
+	{
83
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
+
85
+		if ($defaultAction === false) {
86
+			$statement = $database->prepare(
87
+				"SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
+		}
89
+
90
+		if ($defaultAction === null) {
91
+			$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
+		}
93
+
94
+		$statement->bindValue(":forcreated", $defaultAction);
95
+
96
+		$statement->execute();
97
+
98
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
+
100
+		/** @var EmailTemplate $t */
101
+		foreach ($resultObject as $t) {
102
+			$t->setDatabase($database);
103
+		}
104
+
105
+		return $resultObject;
106
+	}
107
+
108
+	/**
109
+	 * Gets all the unactive templates
110
+	 *
111
+	 * @param PdoDatabase $database
112
+	 *
113
+	 * @return array
114
+	 */
115
+	public static function getAllInactiveTemplates(PdoDatabase $database)
116
+	{
117
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
+		$statement->execute();
119
+
120
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
+
122
+		/** @var EmailTemplate $t */
123
+		foreach ($resultObject as $t) {
124
+			$t->setDatabase($database);
125
+		}
126
+
127
+		return $resultObject;
128
+	}
129
+
130
+	/**
131
+	 * @param string      $name
132
+	 * @param PdoDatabase $database
133
+	 *
134
+	 * @return EmailTemplate|false
135
+	 */
136
+	public static function getByName($name, PdoDatabase $database)
137
+	{
138
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
+		$statement->bindValue(":name", $name);
140
+
141
+		$statement->execute();
142
+
143
+		$resultObject = $statement->fetchObject(get_called_class());
144
+
145
+		if ($resultObject != false) {
146
+			$resultObject->setDatabase($database);
147
+		}
148
+
149
+		return $resultObject;
150
+	}
151
+
152
+	/**
153
+	 * @return EmailTemplate
154
+	 */
155
+	public static function getDroppedTemplate()
156
+	{
157
+		$t = new EmailTemplate();
158
+		$t->id = 0;
159
+		$t->active = 1;
160
+		$t->name = 'Dropped';
161
+
162
+		return $t;
163
+	}
164
+
165
+	/**
166
+	 * @throws Exception
167
+	 */
168
+	public function save()
169
+	{
170
+		if ($this->isNew()) {
171
+			// insert
172
+			$statement = $this->dbObject->prepare(<<<SQL
173 173
 INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly)
174 174
 VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly);
175 175
 SQL
176
-            );
177
-            $statement->bindValue(":name", $this->name);
178
-            $statement->bindValue(":text", $this->text);
179
-            $statement->bindValue(":jsquestion", $this->jsquestion);
180
-            $statement->bindValue(":defaultaction", $this->defaultaction);
181
-            $statement->bindValue(":active", $this->active);
182
-            $statement->bindValue(":preloadonly", $this->preloadonly);
183
-
184
-            if ($statement->execute()) {
185
-                $this->id = (int)$this->dbObject->lastInsertId();
186
-            }
187
-            else {
188
-                throw new Exception($statement->errorInfo());
189
-            }
190
-        }
191
-        else {
192
-            // update
193
-            $statement = $this->dbObject->prepare(<<<SQL
176
+			);
177
+			$statement->bindValue(":name", $this->name);
178
+			$statement->bindValue(":text", $this->text);
179
+			$statement->bindValue(":jsquestion", $this->jsquestion);
180
+			$statement->bindValue(":defaultaction", $this->defaultaction);
181
+			$statement->bindValue(":active", $this->active);
182
+			$statement->bindValue(":preloadonly", $this->preloadonly);
183
+
184
+			if ($statement->execute()) {
185
+				$this->id = (int)$this->dbObject->lastInsertId();
186
+			}
187
+			else {
188
+				throw new Exception($statement->errorInfo());
189
+			}
190
+		}
191
+		else {
192
+			// update
193
+			$statement = $this->dbObject->prepare(<<<SQL
194 194
 UPDATE `emailtemplate`
195 195
 SET name = :name,
196 196
 	text = :text,
@@ -201,130 +201,130 @@  discard block
 block discarded – undo
201 201
 	updateversion = updateversion + 1
202 202
 WHERE id = :id AND updateversion = :updateversion;
203 203
 SQL
204
-            );
205
-            $statement->bindValue(':id', $this->id);
206
-            $statement->bindValue(':updateversion', $this->updateversion);
207
-
208
-            $statement->bindValue(':name', $this->name);
209
-            $statement->bindValue(":text", $this->text);
210
-            $statement->bindValue(":jsquestion", $this->jsquestion);
211
-            $statement->bindValue(":defaultaction", $this->defaultaction);
212
-            $statement->bindValue(":active", $this->active);
213
-            $statement->bindValue(":preloadonly", $this->preloadonly);
214
-
215
-            if (!$statement->execute()) {
216
-                throw new Exception($statement->errorInfo());
217
-            }
218
-
219
-            if ($statement->rowCount() !== 1) {
220
-                throw new OptimisticLockFailedException();
221
-            }
222
-
223
-            $this->updateversion++;
224
-        }
225
-    }
226
-
227
-    /**
228
-     * Override delete() from DataObject
229
-     */
230
-    public function delete()
231
-    {
232
-        throw new Exception("You shouldn't be doing that, you'll break logs.");
233
-    }
234
-
235
-    /**
236
-     * @return string
237
-     */
238
-    public function getName()
239
-    {
240
-        return $this->name;
241
-    }
242
-
243
-    /**
244
-     * @param string $name
245
-     */
246
-    public function setName($name)
247
-    {
248
-        $this->name = $name;
249
-    }
250
-
251
-    /**
252
-     * @return string
253
-     */
254
-    public function getText()
255
-    {
256
-        return $this->text;
257
-    }
258
-
259
-    /**
260
-     * @param string $text
261
-     */
262
-    public function setText($text)
263
-    {
264
-        $this->text = $text;
265
-    }
266
-
267
-    /**
268
-     * @return string|null
269
-     */
270
-    public function getJsquestion()
271
-    {
272
-        return $this->jsquestion;
273
-    }
274
-
275
-    /**
276
-     * @param string $jsquestion
277
-     */
278
-    public function setJsquestion($jsquestion)
279
-    {
280
-        $this->jsquestion = $jsquestion;
281
-    }
282
-
283
-    /**
284
-     * @return string
285
-     */
286
-    public function getDefaultAction()
287
-    {
288
-        return $this->defaultaction;
289
-    }
290
-
291
-    /**
292
-     * @param string $defaultAction
293
-     */
294
-    public function setDefaultAction($defaultAction)
295
-    {
296
-        $this->defaultaction = $defaultAction;
297
-    }
298
-
299
-    /**
300
-     * @return bool
301
-     */
302
-    public function getActive()
303
-    {
304
-        return $this->active == 1;
305
-    }
306
-
307
-    /**
308
-     * @param bool $active
309
-     */
310
-    public function setActive($active)
311
-    {
312
-        $this->active = $active ? 1 : 0;
313
-    }
314
-
315
-    /**
316
-     * @return bool
317
-     */
318
-    public function getPreloadOnly()
319
-    {
320
-        return $this->preloadonly == 1;
321
-    }
322
-
323
-    /**
324
-     * @param bool $preloadonly
325
-     */
326
-    public function setPreloadOnly($preloadonly)
327
-    {
328
-        $this->preloadonly = $preloadonly ? 1 : 0;
329
-    }
204
+			);
205
+			$statement->bindValue(':id', $this->id);
206
+			$statement->bindValue(':updateversion', $this->updateversion);
207
+
208
+			$statement->bindValue(':name', $this->name);
209
+			$statement->bindValue(":text", $this->text);
210
+			$statement->bindValue(":jsquestion", $this->jsquestion);
211
+			$statement->bindValue(":defaultaction", $this->defaultaction);
212
+			$statement->bindValue(":active", $this->active);
213
+			$statement->bindValue(":preloadonly", $this->preloadonly);
214
+
215
+			if (!$statement->execute()) {
216
+				throw new Exception($statement->errorInfo());
217
+			}
218
+
219
+			if ($statement->rowCount() !== 1) {
220
+				throw new OptimisticLockFailedException();
221
+			}
222
+
223
+			$this->updateversion++;
224
+		}
225
+	}
226
+
227
+	/**
228
+	 * Override delete() from DataObject
229
+	 */
230
+	public function delete()
231
+	{
232
+		throw new Exception("You shouldn't be doing that, you'll break logs.");
233
+	}
234
+
235
+	/**
236
+	 * @return string
237
+	 */
238
+	public function getName()
239
+	{
240
+		return $this->name;
241
+	}
242
+
243
+	/**
244
+	 * @param string $name
245
+	 */
246
+	public function setName($name)
247
+	{
248
+		$this->name = $name;
249
+	}
250
+
251
+	/**
252
+	 * @return string
253
+	 */
254
+	public function getText()
255
+	{
256
+		return $this->text;
257
+	}
258
+
259
+	/**
260
+	 * @param string $text
261
+	 */
262
+	public function setText($text)
263
+	{
264
+		$this->text = $text;
265
+	}
266
+
267
+	/**
268
+	 * @return string|null
269
+	 */
270
+	public function getJsquestion()
271
+	{
272
+		return $this->jsquestion;
273
+	}
274
+
275
+	/**
276
+	 * @param string $jsquestion
277
+	 */
278
+	public function setJsquestion($jsquestion)
279
+	{
280
+		$this->jsquestion = $jsquestion;
281
+	}
282
+
283
+	/**
284
+	 * @return string
285
+	 */
286
+	public function getDefaultAction()
287
+	{
288
+		return $this->defaultaction;
289
+	}
290
+
291
+	/**
292
+	 * @param string $defaultAction
293
+	 */
294
+	public function setDefaultAction($defaultAction)
295
+	{
296
+		$this->defaultaction = $defaultAction;
297
+	}
298
+
299
+	/**
300
+	 * @return bool
301
+	 */
302
+	public function getActive()
303
+	{
304
+		return $this->active == 1;
305
+	}
306
+
307
+	/**
308
+	 * @param bool $active
309
+	 */
310
+	public function setActive($active)
311
+	{
312
+		$this->active = $active ? 1 : 0;
313
+	}
314
+
315
+	/**
316
+	 * @return bool
317
+	 */
318
+	public function getPreloadOnly()
319
+	{
320
+		return $this->preloadonly == 1;
321
+	}
322
+
323
+	/**
324
+	 * @param bool $preloadonly
325
+	 */
326
+	public function setPreloadOnly($preloadonly)
327
+	{
328
+		$this->preloadonly = $preloadonly ? 1 : 0;
329
+	}
330 330
 }
Please login to merge, or discard this patch.
includes/DataObjects/User.php 1 patch
Indentation   +542 added lines, -542 removed lines patch added patch discarded remove patch
@@ -21,159 +21,159 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class User extends DataObject
23 23
 {
24
-    const STATUS_ACTIVE = 'Active';
25
-    const STATUS_SUSPENDED = 'Suspended';
26
-    const STATUS_DECLINED = 'Declined';
27
-    const STATUS_NEW = 'New';
28
-    const CREATION_MANUAL = 0;
29
-    const CREATION_OAUTH = 1;
30
-    const CREATION_BOT = 2;
31
-    private $username;
32
-    private $email;
33
-    private $status = self::STATUS_NEW;
34
-    private $onwikiname;
35
-    private $welcome_sig = "";
36
-    private $lastactive = "0000-00-00 00:00:00";
37
-    private $forcelogout = 0;
38
-    private $forceidentified = null;
39
-    private $welcome_template = 0;
40
-    private $abortpref = 0;
41
-    private $confirmationdiff = 0;
42
-    private $emailsig = "";
43
-    private $creationmode = 0;
44
-    /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
45
-    private static $currentUser;
46
-    #region Object load methods
47
-
48
-    /**
49
-     * Gets the currently logged in user
50
-     *
51
-     * @param PdoDatabase $database
52
-     *
53
-     * @return User|CommunityUser
54
-     */
55
-    public static function getCurrent(PdoDatabase $database)
56
-    {
57
-        if (self::$currentUser === null) {
58
-            $sessionId = WebRequest::getSessionUserId();
59
-
60
-            if ($sessionId !== null) {
61
-                /** @var User $user */
62
-                $user = self::getById($sessionId, $database);
63
-
64
-                if ($user === false) {
65
-                    self::$currentUser = new CommunityUser();
66
-                }
67
-                else {
68
-                    self::$currentUser = $user;
69
-                }
70
-            }
71
-            else {
72
-                $anonymousCoward = new CommunityUser();
73
-
74
-                self::$currentUser = $anonymousCoward;
75
-            }
76
-        }
77
-
78
-        return self::$currentUser;
79
-    }
80
-
81
-    /**
82
-     * Gets a user by their user ID
83
-     *
84
-     * Pass -1 to get the community user.
85
-     *
86
-     * @param int|null    $id
87
-     * @param PdoDatabase $database
88
-     *
89
-     * @return User|false
90
-     */
91
-    public static function getById($id, PdoDatabase $database)
92
-    {
93
-        if ($id === null || $id == -1) {
94
-            return new CommunityUser();
95
-        }
96
-
97
-        /** @var User|false $user */
98
-        $user = parent::getById($id, $database);
99
-
100
-        return $user;
101
-    }
102
-
103
-    /**
104
-     * @return CommunityUser
105
-     */
106
-    public static function getCommunity()
107
-    {
108
-        return new CommunityUser();
109
-    }
110
-
111
-    /**
112
-     * Gets a user by their username
113
-     *
114
-     * @param  string      $username
115
-     * @param  PdoDatabase $database
116
-     *
117
-     * @return CommunityUser|User|false
118
-     */
119
-    public static function getByUsername($username, PdoDatabase $database)
120
-    {
121
-        global $communityUsername;
122
-        if ($username == $communityUsername) {
123
-            return new CommunityUser();
124
-        }
125
-
126
-        $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
127
-        $statement->bindValue(":id", $username);
128
-
129
-        $statement->execute();
130
-
131
-        $resultObject = $statement->fetchObject(get_called_class());
132
-
133
-        if ($resultObject != false) {
134
-            $resultObject->setDatabase($database);
135
-        }
136
-
137
-        return $resultObject;
138
-    }
139
-
140
-    /**
141
-     * Gets a user by their on-wiki username.
142
-     *
143
-     * @param string      $username
144
-     * @param PdoDatabase $database
145
-     *
146
-     * @return User|false
147
-     */
148
-    public static function getByOnWikiUsername($username, PdoDatabase $database)
149
-    {
150
-        $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
151
-        $statement->bindValue(":id", $username);
152
-        $statement->execute();
153
-
154
-        $resultObject = $statement->fetchObject(get_called_class());
155
-
156
-        if ($resultObject != false) {
157
-            $resultObject->setDatabase($database);
158
-
159
-            return $resultObject;
160
-        }
161
-
162
-        return false;
163
-    }
164
-
165
-    #endregion
166
-
167
-    /**
168
-     * Saves the current object
169
-     *
170
-     * @throws Exception
171
-     */
172
-    public function save()
173
-    {
174
-        if ($this->isNew()) {
175
-            // insert
176
-            $statement = $this->dbObject->prepare(<<<SQL
24
+	const STATUS_ACTIVE = 'Active';
25
+	const STATUS_SUSPENDED = 'Suspended';
26
+	const STATUS_DECLINED = 'Declined';
27
+	const STATUS_NEW = 'New';
28
+	const CREATION_MANUAL = 0;
29
+	const CREATION_OAUTH = 1;
30
+	const CREATION_BOT = 2;
31
+	private $username;
32
+	private $email;
33
+	private $status = self::STATUS_NEW;
34
+	private $onwikiname;
35
+	private $welcome_sig = "";
36
+	private $lastactive = "0000-00-00 00:00:00";
37
+	private $forcelogout = 0;
38
+	private $forceidentified = null;
39
+	private $welcome_template = 0;
40
+	private $abortpref = 0;
41
+	private $confirmationdiff = 0;
42
+	private $emailsig = "";
43
+	private $creationmode = 0;
44
+	/** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
45
+	private static $currentUser;
46
+	#region Object load methods
47
+
48
+	/**
49
+	 * Gets the currently logged in user
50
+	 *
51
+	 * @param PdoDatabase $database
52
+	 *
53
+	 * @return User|CommunityUser
54
+	 */
55
+	public static function getCurrent(PdoDatabase $database)
56
+	{
57
+		if (self::$currentUser === null) {
58
+			$sessionId = WebRequest::getSessionUserId();
59
+
60
+			if ($sessionId !== null) {
61
+				/** @var User $user */
62
+				$user = self::getById($sessionId, $database);
63
+
64
+				if ($user === false) {
65
+					self::$currentUser = new CommunityUser();
66
+				}
67
+				else {
68
+					self::$currentUser = $user;
69
+				}
70
+			}
71
+			else {
72
+				$anonymousCoward = new CommunityUser();
73
+
74
+				self::$currentUser = $anonymousCoward;
75
+			}
76
+		}
77
+
78
+		return self::$currentUser;
79
+	}
80
+
81
+	/**
82
+	 * Gets a user by their user ID
83
+	 *
84
+	 * Pass -1 to get the community user.
85
+	 *
86
+	 * @param int|null    $id
87
+	 * @param PdoDatabase $database
88
+	 *
89
+	 * @return User|false
90
+	 */
91
+	public static function getById($id, PdoDatabase $database)
92
+	{
93
+		if ($id === null || $id == -1) {
94
+			return new CommunityUser();
95
+		}
96
+
97
+		/** @var User|false $user */
98
+		$user = parent::getById($id, $database);
99
+
100
+		return $user;
101
+	}
102
+
103
+	/**
104
+	 * @return CommunityUser
105
+	 */
106
+	public static function getCommunity()
107
+	{
108
+		return new CommunityUser();
109
+	}
110
+
111
+	/**
112
+	 * Gets a user by their username
113
+	 *
114
+	 * @param  string      $username
115
+	 * @param  PdoDatabase $database
116
+	 *
117
+	 * @return CommunityUser|User|false
118
+	 */
119
+	public static function getByUsername($username, PdoDatabase $database)
120
+	{
121
+		global $communityUsername;
122
+		if ($username == $communityUsername) {
123
+			return new CommunityUser();
124
+		}
125
+
126
+		$statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
127
+		$statement->bindValue(":id", $username);
128
+
129
+		$statement->execute();
130
+
131
+		$resultObject = $statement->fetchObject(get_called_class());
132
+
133
+		if ($resultObject != false) {
134
+			$resultObject->setDatabase($database);
135
+		}
136
+
137
+		return $resultObject;
138
+	}
139
+
140
+	/**
141
+	 * Gets a user by their on-wiki username.
142
+	 *
143
+	 * @param string      $username
144
+	 * @param PdoDatabase $database
145
+	 *
146
+	 * @return User|false
147
+	 */
148
+	public static function getByOnWikiUsername($username, PdoDatabase $database)
149
+	{
150
+		$statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
151
+		$statement->bindValue(":id", $username);
152
+		$statement->execute();
153
+
154
+		$resultObject = $statement->fetchObject(get_called_class());
155
+
156
+		if ($resultObject != false) {
157
+			$resultObject->setDatabase($database);
158
+
159
+			return $resultObject;
160
+		}
161
+
162
+		return false;
163
+	}
164
+
165
+	#endregion
166
+
167
+	/**
168
+	 * Saves the current object
169
+	 *
170
+	 * @throws Exception
171
+	 */
172
+	public function save()
173
+	{
174
+		if ($this->isNew()) {
175
+			// insert
176
+			$statement = $this->dbObject->prepare(<<<SQL
177 177
 				INSERT INTO `user` ( 
178 178
 					username, email, status, onwikiname, welcome_sig, 
179 179
 					lastactive, forcelogout, forceidentified,
@@ -184,31 +184,31 @@  discard block
 block discarded – undo
184 184
 					:welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode
185 185
 				);
186 186
 SQL
187
-            );
188
-            $statement->bindValue(":username", $this->username);
189
-            $statement->bindValue(":email", $this->email);
190
-            $statement->bindValue(":status", $this->status);
191
-            $statement->bindValue(":onwikiname", $this->onwikiname);
192
-            $statement->bindValue(":welcome_sig", $this->welcome_sig);
193
-            $statement->bindValue(":lastactive", $this->lastactive);
194
-            $statement->bindValue(":forcelogout", $this->forcelogout);
195
-            $statement->bindValue(":forceidentified", $this->forceidentified);
196
-            $statement->bindValue(":welcome_template", $this->welcome_template);
197
-            $statement->bindValue(":abortpref", $this->abortpref);
198
-            $statement->bindValue(":confirmationdiff", $this->confirmationdiff);
199
-            $statement->bindValue(":emailsig", $this->emailsig);
200
-            $statement->bindValue(":creationmode", $this->creationmode);
201
-
202
-            if ($statement->execute()) {
203
-                $this->id = (int)$this->dbObject->lastInsertId();
204
-            }
205
-            else {
206
-                throw new Exception($statement->errorInfo());
207
-            }
208
-        }
209
-        else {
210
-            // update
211
-            $statement = $this->dbObject->prepare(<<<SQL
187
+			);
188
+			$statement->bindValue(":username", $this->username);
189
+			$statement->bindValue(":email", $this->email);
190
+			$statement->bindValue(":status", $this->status);
191
+			$statement->bindValue(":onwikiname", $this->onwikiname);
192
+			$statement->bindValue(":welcome_sig", $this->welcome_sig);
193
+			$statement->bindValue(":lastactive", $this->lastactive);
194
+			$statement->bindValue(":forcelogout", $this->forcelogout);
195
+			$statement->bindValue(":forceidentified", $this->forceidentified);
196
+			$statement->bindValue(":welcome_template", $this->welcome_template);
197
+			$statement->bindValue(":abortpref", $this->abortpref);
198
+			$statement->bindValue(":confirmationdiff", $this->confirmationdiff);
199
+			$statement->bindValue(":emailsig", $this->emailsig);
200
+			$statement->bindValue(":creationmode", $this->creationmode);
201
+
202
+			if ($statement->execute()) {
203
+				$this->id = (int)$this->dbObject->lastInsertId();
204
+			}
205
+			else {
206
+				throw new Exception($statement->errorInfo());
207
+			}
208
+		}
209
+		else {
210
+			// update
211
+			$statement = $this->dbObject->prepare(<<<SQL
212 212
 				UPDATE `user` SET 
213 213
 					username = :username, email = :email, 
214 214
 					status = :status,
@@ -220,364 +220,364 @@  discard block
 block discarded – undo
220 220
 					creationmode = :creationmode, updateversion = updateversion + 1
221 221
 				WHERE id = :id AND updateversion = :updateversion;
222 222
 SQL
223
-            );
224
-            $statement->bindValue(":forceidentified", $this->forceidentified);
225
-
226
-            $statement->bindValue(':id', $this->id);
227
-            $statement->bindValue(':updateversion', $this->updateversion);
228
-
229
-            $statement->bindValue(':username', $this->username);
230
-            $statement->bindValue(':email', $this->email);
231
-            $statement->bindValue(':status', $this->status);
232
-            $statement->bindValue(':onwikiname', $this->onwikiname);
233
-            $statement->bindValue(':welcome_sig', $this->welcome_sig);
234
-            $statement->bindValue(':lastactive', $this->lastactive);
235
-            $statement->bindValue(':forcelogout', $this->forcelogout);
236
-            $statement->bindValue(':forceidentified', $this->forceidentified);
237
-            $statement->bindValue(':welcome_template', $this->welcome_template);
238
-            $statement->bindValue(':abortpref', $this->abortpref);
239
-            $statement->bindValue(':confirmationdiff', $this->confirmationdiff);
240
-            $statement->bindValue(':emailsig', $this->emailsig);
241
-            $statement->bindValue(':creationmode', $this->creationmode);
242
-
243
-            if (!$statement->execute()) {
244
-                throw new Exception($statement->errorInfo());
245
-            }
246
-
247
-            if ($statement->rowCount() !== 1) {
248
-                throw new OptimisticLockFailedException();
249
-            }
250
-
251
-            $this->updateversion++;
252
-        }
253
-    }
254
-
255
-    #region properties
256
-
257
-    /**
258
-     * Gets the tool username
259
-     * @return string
260
-     */
261
-    public function getUsername()
262
-    {
263
-        return $this->username;
264
-    }
265
-
266
-    /**
267
-     * Sets the tool username
268
-     *
269
-     * @param string $username
270
-     */
271
-    public function setUsername($username)
272
-    {
273
-        $this->username = $username;
274
-
275
-        // If this isn't a brand new user, then it's a rename, force the logout
276
-        if (!$this->isNew()) {
277
-            $this->forcelogout = 1;
278
-        }
279
-    }
280
-
281
-    /**
282
-     * Gets the user's email address
283
-     * @return string
284
-     */
285
-    public function getEmail()
286
-    {
287
-        return $this->email;
288
-    }
289
-
290
-    /**
291
-     * Sets the user's email address
292
-     *
293
-     * @param string $email
294
-     */
295
-    public function setEmail($email)
296
-    {
297
-        $this->email = $email;
298
-    }
299
-
300
-    /**
301
-     * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
302
-     * @return string
303
-     */
304
-    public function getStatus()
305
-    {
306
-        return $this->status;
307
-    }
308
-
309
-    /**
310
-     * @param string $status
311
-     */
312
-    public function setStatus($status)
313
-    {
314
-        $this->status = $status;
315
-    }
316
-
317
-    /**
318
-     * Gets the user's on-wiki name
319
-     * @return string
320
-     */
321
-    public function getOnWikiName()
322
-    {
323
-        return $this->onwikiname;
324
-    }
325
-
326
-    /**
327
-     * Sets the user's on-wiki name
328
-     *
329
-     * This can have interesting side-effects with OAuth.
330
-     *
331
-     * @param string $onWikiName
332
-     */
333
-    public function setOnWikiName($onWikiName)
334
-    {
335
-        $this->onwikiname = $onWikiName;
336
-    }
337
-
338
-    /**
339
-     * Gets the welcome signature
340
-     * @return string
341
-     */
342
-    public function getWelcomeSig()
343
-    {
344
-        return $this->welcome_sig;
345
-    }
346
-
347
-    /**
348
-     * Sets the welcome signature
349
-     *
350
-     * @param string $welcomeSig
351
-     */
352
-    public function setWelcomeSig($welcomeSig)
353
-    {
354
-        $this->welcome_sig = $welcomeSig;
355
-    }
356
-
357
-    /**
358
-     * Gets the last activity date for the user
359
-     *
360
-     * @return string
361
-     * @todo This should probably return an instance of DateTime
362
-     */
363
-    public function getLastActive()
364
-    {
365
-        return $this->lastactive;
366
-    }
367
-
368
-    /**
369
-     * Gets the user's forced logout status
370
-     *
371
-     * @return bool
372
-     */
373
-    public function getForceLogout()
374
-    {
375
-        return $this->forcelogout == 1;
376
-    }
377
-
378
-    /**
379
-     * Sets the user's forced logout status
380
-     *
381
-     * @param bool $forceLogout
382
-     */
383
-    public function setForceLogout($forceLogout)
384
-    {
385
-        $this->forcelogout = $forceLogout ? 1 : 0;
386
-    }
387
-
388
-    /**
389
-     * Returns the ID of the welcome template used.
390
-     * @return int
391
-     */
392
-    public function getWelcomeTemplate()
393
-    {
394
-        return $this->welcome_template;
395
-    }
396
-
397
-    /**
398
-     * Sets the ID of the welcome template used.
399
-     *
400
-     * @param int $welcomeTemplate
401
-     */
402
-    public function setWelcomeTemplate($welcomeTemplate)
403
-    {
404
-        $this->welcome_template = $welcomeTemplate;
405
-    }
406
-
407
-    /**
408
-     * Gets the user's abort preference
409
-     * @todo this is badly named too! Also a bool that's actually an int.
410
-     * @return int
411
-     */
412
-    public function getAbortPref()
413
-    {
414
-        return $this->abortpref;
415
-    }
416
-
417
-    /**
418
-     * Sets the user's abort preference
419
-     * @todo rename, retype, and re-comment.
420
-     *
421
-     * @param int $abortPreference
422
-     */
423
-    public function setAbortPref($abortPreference)
424
-    {
425
-        $this->abortpref = $abortPreference;
426
-    }
427
-
428
-    /**
429
-     * Gets the user's confirmation diff. Unused if OAuth is in use.
430
-     * @return int the diff ID
431
-     */
432
-    public function getConfirmationDiff()
433
-    {
434
-        return $this->confirmationdiff;
435
-    }
436
-
437
-    /**
438
-     * Sets the user's confirmation diff.
439
-     *
440
-     * @param int $confirmationDiff
441
-     */
442
-    public function setConfirmationDiff($confirmationDiff)
443
-    {
444
-        $this->confirmationdiff = $confirmationDiff;
445
-    }
446
-
447
-    /**
448
-     * Gets the users' email signature used on outbound mail.
449
-     * @todo rename me!
450
-     * @return string
451
-     */
452
-    public function getEmailSig()
453
-    {
454
-        return $this->emailsig;
455
-    }
456
-
457
-    /**
458
-     * Sets the user's email signature for outbound mail.
459
-     *
460
-     * @param string $emailSignature
461
-     */
462
-    public function setEmailSig($emailSignature)
463
-    {
464
-        $this->emailsig = $emailSignature;
465
-    }
466
-
467
-    /**
468
-     * @return int
469
-     */
470
-    public function getCreationMode()
471
-    {
472
-        return $this->creationmode;
473
-    }
474
-
475
-    /**
476
-     * @param $creationMode int
477
-     */
478
-    public function setCreationMode($creationMode)
479
-    {
480
-        $this->creationmode = $creationMode;
481
-    }
482
-
483
-    #endregion
484
-
485
-    #region user access checks
486
-
487
-    public function isActive()
488
-    {
489
-        return $this->status == self::STATUS_ACTIVE;
490
-    }
491
-
492
-    /**
493
-     * Tests if the user is identified
494
-     *
495
-     * @param IdentificationVerifier $iv
496
-     *
497
-     * @return bool
498
-     * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
499
-     *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
500
-     *       to play it safe for now.
501
-     * @category Security-Critical
502
-     */
503
-    public function isIdentified(IdentificationVerifier $iv)
504
-    {
505
-        if ($this->forceidentified === 0 || $this->forceidentified === "0") {
506
-            // User forced to unidentified in the database.
507
-            return false;
508
-        }
509
-        elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
510
-            // User forced to identified in the database.
511
-            return true;
512
-        }
513
-        else {
514
-            // User not forced to any particular identified status; consult IdentificationVerifier
515
-            return $iv->isUserIdentified($this->getOnWikiName());
516
-        }
517
-    }
518
-
519
-    /**
520
-     * Tests if the user is suspended
521
-     * @return bool
522
-     * @category Security-Critical
523
-     */
524
-    public function isSuspended()
525
-    {
526
-        return $this->status == self::STATUS_SUSPENDED;
527
-    }
528
-
529
-    /**
530
-     * Tests if the user is new
531
-     * @return bool
532
-     * @category Security-Critical
533
-     */
534
-    public function isNewUser()
535
-    {
536
-        return $this->status == self::STATUS_NEW;
537
-    }
538
-
539
-    /**
540
-     * Tests if the user has been declined access to the tool
541
-     * @return bool
542
-     * @category Security-Critical
543
-     */
544
-    public function isDeclined()
545
-    {
546
-        return $this->status == self::STATUS_DECLINED;
547
-    }
548
-
549
-    /**
550
-     * Tests if the user is the community user
551
-     *
552
-     * @todo     decide if this means logged out. I think it usually does.
553
-     * @return bool
554
-     * @category Security-Critical
555
-     */
556
-    public function isCommunityUser()
557
-    {
558
-        return false;
559
-    }
560
-
561
-    #endregion 
562
-
563
-    /**
564
-     * Gets a hash of data for the user to reset their password with.
565
-     * @category Security-Critical
566
-     * @return string
567
-     */
568
-    public function getForgottenPasswordHash()
569
-    {
570
-        // FIXME
571
-        return md5($this->username . $this->email . $this->welcome_template . $this->id);
572
-    }
573
-
574
-    /**
575
-     * Gets the approval date of the user
576
-     * @return DateTime|false
577
-     */
578
-    public function getApprovalDate()
579
-    {
580
-        $query = $this->dbObject->prepare(<<<SQL
223
+			);
224
+			$statement->bindValue(":forceidentified", $this->forceidentified);
225
+
226
+			$statement->bindValue(':id', $this->id);
227
+			$statement->bindValue(':updateversion', $this->updateversion);
228
+
229
+			$statement->bindValue(':username', $this->username);
230
+			$statement->bindValue(':email', $this->email);
231
+			$statement->bindValue(':status', $this->status);
232
+			$statement->bindValue(':onwikiname', $this->onwikiname);
233
+			$statement->bindValue(':welcome_sig', $this->welcome_sig);
234
+			$statement->bindValue(':lastactive', $this->lastactive);
235
+			$statement->bindValue(':forcelogout', $this->forcelogout);
236
+			$statement->bindValue(':forceidentified', $this->forceidentified);
237
+			$statement->bindValue(':welcome_template', $this->welcome_template);
238
+			$statement->bindValue(':abortpref', $this->abortpref);
239
+			$statement->bindValue(':confirmationdiff', $this->confirmationdiff);
240
+			$statement->bindValue(':emailsig', $this->emailsig);
241
+			$statement->bindValue(':creationmode', $this->creationmode);
242
+
243
+			if (!$statement->execute()) {
244
+				throw new Exception($statement->errorInfo());
245
+			}
246
+
247
+			if ($statement->rowCount() !== 1) {
248
+				throw new OptimisticLockFailedException();
249
+			}
250
+
251
+			$this->updateversion++;
252
+		}
253
+	}
254
+
255
+	#region properties
256
+
257
+	/**
258
+	 * Gets the tool username
259
+	 * @return string
260
+	 */
261
+	public function getUsername()
262
+	{
263
+		return $this->username;
264
+	}
265
+
266
+	/**
267
+	 * Sets the tool username
268
+	 *
269
+	 * @param string $username
270
+	 */
271
+	public function setUsername($username)
272
+	{
273
+		$this->username = $username;
274
+
275
+		// If this isn't a brand new user, then it's a rename, force the logout
276
+		if (!$this->isNew()) {
277
+			$this->forcelogout = 1;
278
+		}
279
+	}
280
+
281
+	/**
282
+	 * Gets the user's email address
283
+	 * @return string
284
+	 */
285
+	public function getEmail()
286
+	{
287
+		return $this->email;
288
+	}
289
+
290
+	/**
291
+	 * Sets the user's email address
292
+	 *
293
+	 * @param string $email
294
+	 */
295
+	public function setEmail($email)
296
+	{
297
+		$this->email = $email;
298
+	}
299
+
300
+	/**
301
+	 * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
302
+	 * @return string
303
+	 */
304
+	public function getStatus()
305
+	{
306
+		return $this->status;
307
+	}
308
+
309
+	/**
310
+	 * @param string $status
311
+	 */
312
+	public function setStatus($status)
313
+	{
314
+		$this->status = $status;
315
+	}
316
+
317
+	/**
318
+	 * Gets the user's on-wiki name
319
+	 * @return string
320
+	 */
321
+	public function getOnWikiName()
322
+	{
323
+		return $this->onwikiname;
324
+	}
325
+
326
+	/**
327
+	 * Sets the user's on-wiki name
328
+	 *
329
+	 * This can have interesting side-effects with OAuth.
330
+	 *
331
+	 * @param string $onWikiName
332
+	 */
333
+	public function setOnWikiName($onWikiName)
334
+	{
335
+		$this->onwikiname = $onWikiName;
336
+	}
337
+
338
+	/**
339
+	 * Gets the welcome signature
340
+	 * @return string
341
+	 */
342
+	public function getWelcomeSig()
343
+	{
344
+		return $this->welcome_sig;
345
+	}
346
+
347
+	/**
348
+	 * Sets the welcome signature
349
+	 *
350
+	 * @param string $welcomeSig
351
+	 */
352
+	public function setWelcomeSig($welcomeSig)
353
+	{
354
+		$this->welcome_sig = $welcomeSig;
355
+	}
356
+
357
+	/**
358
+	 * Gets the last activity date for the user
359
+	 *
360
+	 * @return string
361
+	 * @todo This should probably return an instance of DateTime
362
+	 */
363
+	public function getLastActive()
364
+	{
365
+		return $this->lastactive;
366
+	}
367
+
368
+	/**
369
+	 * Gets the user's forced logout status
370
+	 *
371
+	 * @return bool
372
+	 */
373
+	public function getForceLogout()
374
+	{
375
+		return $this->forcelogout == 1;
376
+	}
377
+
378
+	/**
379
+	 * Sets the user's forced logout status
380
+	 *
381
+	 * @param bool $forceLogout
382
+	 */
383
+	public function setForceLogout($forceLogout)
384
+	{
385
+		$this->forcelogout = $forceLogout ? 1 : 0;
386
+	}
387
+
388
+	/**
389
+	 * Returns the ID of the welcome template used.
390
+	 * @return int
391
+	 */
392
+	public function getWelcomeTemplate()
393
+	{
394
+		return $this->welcome_template;
395
+	}
396
+
397
+	/**
398
+	 * Sets the ID of the welcome template used.
399
+	 *
400
+	 * @param int $welcomeTemplate
401
+	 */
402
+	public function setWelcomeTemplate($welcomeTemplate)
403
+	{
404
+		$this->welcome_template = $welcomeTemplate;
405
+	}
406
+
407
+	/**
408
+	 * Gets the user's abort preference
409
+	 * @todo this is badly named too! Also a bool that's actually an int.
410
+	 * @return int
411
+	 */
412
+	public function getAbortPref()
413
+	{
414
+		return $this->abortpref;
415
+	}
416
+
417
+	/**
418
+	 * Sets the user's abort preference
419
+	 * @todo rename, retype, and re-comment.
420
+	 *
421
+	 * @param int $abortPreference
422
+	 */
423
+	public function setAbortPref($abortPreference)
424
+	{
425
+		$this->abortpref = $abortPreference;
426
+	}
427
+
428
+	/**
429
+	 * Gets the user's confirmation diff. Unused if OAuth is in use.
430
+	 * @return int the diff ID
431
+	 */
432
+	public function getConfirmationDiff()
433
+	{
434
+		return $this->confirmationdiff;
435
+	}
436
+
437
+	/**
438
+	 * Sets the user's confirmation diff.
439
+	 *
440
+	 * @param int $confirmationDiff
441
+	 */
442
+	public function setConfirmationDiff($confirmationDiff)
443
+	{
444
+		$this->confirmationdiff = $confirmationDiff;
445
+	}
446
+
447
+	/**
448
+	 * Gets the users' email signature used on outbound mail.
449
+	 * @todo rename me!
450
+	 * @return string
451
+	 */
452
+	public function getEmailSig()
453
+	{
454
+		return $this->emailsig;
455
+	}
456
+
457
+	/**
458
+	 * Sets the user's email signature for outbound mail.
459
+	 *
460
+	 * @param string $emailSignature
461
+	 */
462
+	public function setEmailSig($emailSignature)
463
+	{
464
+		$this->emailsig = $emailSignature;
465
+	}
466
+
467
+	/**
468
+	 * @return int
469
+	 */
470
+	public function getCreationMode()
471
+	{
472
+		return $this->creationmode;
473
+	}
474
+
475
+	/**
476
+	 * @param $creationMode int
477
+	 */
478
+	public function setCreationMode($creationMode)
479
+	{
480
+		$this->creationmode = $creationMode;
481
+	}
482
+
483
+	#endregion
484
+
485
+	#region user access checks
486
+
487
+	public function isActive()
488
+	{
489
+		return $this->status == self::STATUS_ACTIVE;
490
+	}
491
+
492
+	/**
493
+	 * Tests if the user is identified
494
+	 *
495
+	 * @param IdentificationVerifier $iv
496
+	 *
497
+	 * @return bool
498
+	 * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
499
+	 *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
500
+	 *       to play it safe for now.
501
+	 * @category Security-Critical
502
+	 */
503
+	public function isIdentified(IdentificationVerifier $iv)
504
+	{
505
+		if ($this->forceidentified === 0 || $this->forceidentified === "0") {
506
+			// User forced to unidentified in the database.
507
+			return false;
508
+		}
509
+		elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
510
+			// User forced to identified in the database.
511
+			return true;
512
+		}
513
+		else {
514
+			// User not forced to any particular identified status; consult IdentificationVerifier
515
+			return $iv->isUserIdentified($this->getOnWikiName());
516
+		}
517
+	}
518
+
519
+	/**
520
+	 * Tests if the user is suspended
521
+	 * @return bool
522
+	 * @category Security-Critical
523
+	 */
524
+	public function isSuspended()
525
+	{
526
+		return $this->status == self::STATUS_SUSPENDED;
527
+	}
528
+
529
+	/**
530
+	 * Tests if the user is new
531
+	 * @return bool
532
+	 * @category Security-Critical
533
+	 */
534
+	public function isNewUser()
535
+	{
536
+		return $this->status == self::STATUS_NEW;
537
+	}
538
+
539
+	/**
540
+	 * Tests if the user has been declined access to the tool
541
+	 * @return bool
542
+	 * @category Security-Critical
543
+	 */
544
+	public function isDeclined()
545
+	{
546
+		return $this->status == self::STATUS_DECLINED;
547
+	}
548
+
549
+	/**
550
+	 * Tests if the user is the community user
551
+	 *
552
+	 * @todo     decide if this means logged out. I think it usually does.
553
+	 * @return bool
554
+	 * @category Security-Critical
555
+	 */
556
+	public function isCommunityUser()
557
+	{
558
+		return false;
559
+	}
560
+
561
+	#endregion 
562
+
563
+	/**
564
+	 * Gets a hash of data for the user to reset their password with.
565
+	 * @category Security-Critical
566
+	 * @return string
567
+	 */
568
+	public function getForgottenPasswordHash()
569
+	{
570
+		// FIXME
571
+		return md5($this->username . $this->email . $this->welcome_template . $this->id);
572
+	}
573
+
574
+	/**
575
+	 * Gets the approval date of the user
576
+	 * @return DateTime|false
577
+	 */
578
+	public function getApprovalDate()
579
+	{
580
+		$query = $this->dbObject->prepare(<<<SQL
581 581
 			SELECT timestamp 
582 582
 			FROM log 
583 583
 			WHERE objectid = :userid
@@ -586,12 +586,12 @@  discard block
 block discarded – undo
586 586
 			ORDER BY id DESC 
587 587
 			LIMIT 1;
588 588
 SQL
589
-        );
590
-        $query->execute(array(":userid" => $this->id));
589
+		);
590
+		$query->execute(array(":userid" => $this->id));
591 591
 
592
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
593
-        $query->closeCursor();
592
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
593
+		$query->closeCursor();
594 594
 
595
-        return $data;
596
-    }
595
+		return $data;
596
+	}
597 597
 }
Please login to merge, or discard this patch.