Passed
Push — master ( 3e5dae...8d4e4c )
by Simon
12:37
created
includes/Providers/CachedRDnsLookupProvider.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -20,40 +20,40 @@
 block discarded – undo
20 20
  */
21 21
 class CachedRDnsLookupProvider implements IRDnsProvider
22 22
 {
23
-    private $database;
23
+	private $database;
24 24
 
25
-    public function __construct(PdoDatabase $database)
26
-    {
27
-        $this->database = $database;
28
-    }
25
+	public function __construct(PdoDatabase $database)
26
+	{
27
+		$this->database = $database;
28
+	}
29 29
 
30
-    public function getReverseDNS($address)
31
-    {
32
-        $address = trim($address);
30
+	public function getReverseDNS($address)
31
+	{
32
+		$address = trim($address);
33 33
 
34
-        // lets look in our cache database first.
35
-        $rDns = RDnsCache::getByAddress($address, $this->database);
34
+		// lets look in our cache database first.
35
+		$rDns = RDnsCache::getByAddress($address, $this->database);
36 36
 
37
-        if ($rDns instanceof RDnsCache) {
38
-            // touch cache timer
39
-            $rDns->save();
37
+		if ($rDns instanceof RDnsCache) {
38
+			// touch cache timer
39
+			$rDns->save();
40 40
 
41
-            return $rDns->getData();
42
-        }
41
+			return $rDns->getData();
42
+		}
43 43
 
44
-        // OK, it's not there, let's do an rDNS lookup.
45
-        $result = @ gethostbyaddr($address);
44
+		// OK, it's not there, let's do an rDNS lookup.
45
+		$result = @ gethostbyaddr($address);
46 46
 
47
-        if ($result !== false) {
48
-            $rDns = new RDnsCache();
49
-            $rDns->setDatabase($this->database);
50
-            $rDns->setAddress($address);
51
-            $rDns->setData($result);
52
-            $rDns->save();
47
+		if ($result !== false) {
48
+			$rDns = new RDnsCache();
49
+			$rDns->setDatabase($this->database);
50
+			$rDns->setAddress($address);
51
+			$rDns->setData($result);
52
+			$rDns->save();
53 53
 
54
-            return $result;
55
-        }
54
+			return $result;
55
+		}
56 56
 
57
-        return null;
58
-    }
57
+		return null;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
includes/DataObjects/GeoLocation.php 1 patch
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.
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/OAuthIdentity.php 1 patch
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -16,51 +16,51 @@  discard block
 block discarded – undo
16 16
 
17 17
 class OAuthIdentity extends DataObject
18 18
 {
19
-    #region Fields
20
-    /** @var int */
21
-    private $user;
22
-    /** @var string */
23
-    private $iss;
24
-    /** @var int */
25
-    private $sub;
26
-    /** @var string */
27
-    private $aud;
28
-    /** @var int */
29
-    private $exp;
30
-    /** @var int */
31
-    private $iat;
32
-    /** @var string */
33
-    private $username;
34
-    /** @var int */
35
-    private $editcount;
36
-    /** @var int */
37
-    private $confirmed_email;
38
-    /** @var int */
39
-    private $blocked;
40
-    /** @var string */
41
-    private $registered;
42
-    /** @var int */
43
-    private $checkuser;
44
-    /** @var int */
45
-    private $grantbasic;
46
-    /** @var int */
47
-    private $grantcreateaccount;
48
-    /** @var int */
49
-    private $granthighvolume;
50
-    /** @var int */
51
-    private $grantcreateeditmovepage;
52
-    #endregion
53
-
54
-    /**
55
-     * Saves a data object to the database, either updating or inserting a record.
56
-     * @return void
57
-     * @throws Exception
58
-     * @throws OptimisticLockFailedException
59
-     */
60
-    public function save()
61
-    {
62
-        if ($this->isNew()) {
63
-            $statement = $this->dbObject->prepare(<<<SQL
19
+	#region Fields
20
+	/** @var int */
21
+	private $user;
22
+	/** @var string */
23
+	private $iss;
24
+	/** @var int */
25
+	private $sub;
26
+	/** @var string */
27
+	private $aud;
28
+	/** @var int */
29
+	private $exp;
30
+	/** @var int */
31
+	private $iat;
32
+	/** @var string */
33
+	private $username;
34
+	/** @var int */
35
+	private $editcount;
36
+	/** @var int */
37
+	private $confirmed_email;
38
+	/** @var int */
39
+	private $blocked;
40
+	/** @var string */
41
+	private $registered;
42
+	/** @var int */
43
+	private $checkuser;
44
+	/** @var int */
45
+	private $grantbasic;
46
+	/** @var int */
47
+	private $grantcreateaccount;
48
+	/** @var int */
49
+	private $granthighvolume;
50
+	/** @var int */
51
+	private $grantcreateeditmovepage;
52
+	#endregion
53
+
54
+	/**
55
+	 * Saves a data object to the database, either updating or inserting a record.
56
+	 * @return void
57
+	 * @throws Exception
58
+	 * @throws OptimisticLockFailedException
59
+	 */
60
+	public function save()
61
+	{
62
+		if ($this->isNew()) {
63
+			$statement = $this->dbObject->prepare(<<<SQL
64 64
                 INSERT INTO oauthidentity (
65 65
                     user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, 
66 66
                     grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage
@@ -69,34 +69,34 @@  discard block
 block discarded – undo
69 69
                     :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage
70 70
                 )
71 71
 SQL
72
-            );
73
-
74
-            $statement->bindValue(':user', $this->user);
75
-            $statement->bindValue(':iss', $this->iss);
76
-            $statement->bindValue(':sub', $this->sub);
77
-            $statement->bindValue(':aud', $this->aud);
78
-            $statement->bindValue(':exp', $this->exp);
79
-            $statement->bindValue(':iat', $this->iat);
80
-            $statement->bindValue(':username', $this->username);
81
-            $statement->bindValue(':editcount', $this->editcount);
82
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
83
-            $statement->bindValue(':blocked', $this->blocked);
84
-            $statement->bindValue(':registered', $this->registered);
85
-            $statement->bindValue(':checkuser', $this->checkuser);
86
-            $statement->bindValue(':grantbasic', $this->grantbasic);
87
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
89
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
90
-
91
-            if ($statement->execute()) {
92
-                $this->id = (int)$this->dbObject->lastInsertId();
93
-            }
94
-            else {
95
-                throw new Exception($statement->errorInfo());
96
-            }
97
-        }
98
-        else {
99
-            $statement = $this->dbObject->prepare(<<<SQL
72
+			);
73
+
74
+			$statement->bindValue(':user', $this->user);
75
+			$statement->bindValue(':iss', $this->iss);
76
+			$statement->bindValue(':sub', $this->sub);
77
+			$statement->bindValue(':aud', $this->aud);
78
+			$statement->bindValue(':exp', $this->exp);
79
+			$statement->bindValue(':iat', $this->iat);
80
+			$statement->bindValue(':username', $this->username);
81
+			$statement->bindValue(':editcount', $this->editcount);
82
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
83
+			$statement->bindValue(':blocked', $this->blocked);
84
+			$statement->bindValue(':registered', $this->registered);
85
+			$statement->bindValue(':checkuser', $this->checkuser);
86
+			$statement->bindValue(':grantbasic', $this->grantbasic);
87
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
89
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
90
+
91
+			if ($statement->execute()) {
92
+				$this->id = (int)$this->dbObject->lastInsertId();
93
+			}
94
+			else {
95
+				throw new Exception($statement->errorInfo());
96
+			}
97
+		}
98
+		else {
99
+			$statement = $this->dbObject->prepare(<<<SQL
100 100
                 UPDATE oauthidentity SET
101 101
                       iss                     = :iss
102 102
                     , sub                     = :sub
@@ -116,211 +116,211 @@  discard block
 block discarded – undo
116 116
                     , updateversion           = updateversion + 1
117 117
                 WHERE  id = :id AND updateversion = :updateversion
118 118
 SQL
119
-            );
120
-
121
-            $statement->bindValue(':iss', $this->iss);
122
-            $statement->bindValue(':sub', $this->sub);
123
-            $statement->bindValue(':aud', $this->aud);
124
-            $statement->bindValue(':exp', $this->exp);
125
-            $statement->bindValue(':iat', $this->iat);
126
-            $statement->bindValue(':username', $this->username);
127
-            $statement->bindValue(':editcount', $this->editcount);
128
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
129
-            $statement->bindValue(':blocked', $this->blocked);
130
-            $statement->bindValue(':registered', $this->registered);
131
-            $statement->bindValue(':checkuser', $this->checkuser);
132
-            $statement->bindValue(':grantbasic', $this->grantbasic);
133
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
135
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
-
137
-            $statement->bindValue(':id', $this->id);
138
-            $statement->bindValue(':updateversion', $this->updateversion);
139
-
140
-            if (!$statement->execute()) {
141
-                throw new Exception($statement->errorInfo());
142
-            }
143
-
144
-            if ($statement->rowCount() !== 1) {
145
-                throw new OptimisticLockFailedException();
146
-            }
147
-
148
-            $this->updateversion++;
149
-        }
150
-    }
151
-
152
-    #region Properties
153
-
154
-    /**
155
-     * @return int
156
-     */
157
-    public function getUserId()
158
-    {
159
-        return $this->user;
160
-    }
161
-
162
-    /**
163
-     * @param int $user
164
-     */
165
-    public function setUserId($user)
166
-    {
167
-        $this->user = $user;
168
-    }
169
-
170
-    /**
171
-     * @return string
172
-     */
173
-    public function getIssuer()
174
-    {
175
-        return $this->iss;
176
-    }
177
-
178
-    /**
179
-     * @return int
180
-     */
181
-    public function getSubject()
182
-    {
183
-        return $this->sub;
184
-    }
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function getAudience()
190
-    {
191
-        return $this->aud;
192
-    }
193
-
194
-    /**
195
-     * @return int
196
-     */
197
-    public function getExpirationTime()
198
-    {
199
-        return $this->exp;
200
-    }
201
-
202
-    /**
203
-     * @return int
204
-     */
205
-    public function getIssuedAtTime()
206
-    {
207
-        return $this->iat;
208
-    }
209
-
210
-    /**
211
-     * @return string
212
-     */
213
-    public function getUsername()
214
-    {
215
-        return $this->username;
216
-    }
217
-
218
-    /**
219
-     * @return int
220
-     */
221
-    public function getEditCount()
222
-    {
223
-        return $this->editcount;
224
-    }
225
-
226
-    /**
227
-     * @return bool
228
-     */
229
-    public function getConfirmedEmail()
230
-    {
231
-        return $this->confirmed_email == 1;
232
-    }
233
-
234
-    /**
235
-     * @return bool
236
-     */
237
-    public function getBlocked()
238
-    {
239
-        return $this->blocked == 1;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    public function getRegistered()
246
-    {
247
-        return $this->registered;
248
-    }
249
-
250
-    public function getRegistrationDate()
251
-    {
252
-        return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
-    }
254
-
255
-    public function getAccountAge()
256
-    {
257
-        $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
-        $interval = $regDate->diff(new DateTimeImmutable(), true);
259
-
260
-        return $interval->days;
261
-    }
262
-
263
-    /**
264
-     * @return bool
265
-     */
266
-    public function getCheckuser()
267
-    {
268
-        return $this->checkuser == 1;
269
-    }
270
-
271
-    /**
272
-     * @return bool
273
-     */
274
-    public function getGrantBasic()
275
-    {
276
-        return $this->grantbasic == 1;
277
-    }
278
-
279
-    /**
280
-     * @return bool
281
-     */
282
-    public function getGrantCreateAccount()
283
-    {
284
-        return $this->grantcreateaccount == 1;
285
-    }
286
-
287
-    /**
288
-     * @return bool
289
-     */
290
-    public function getGrantHighVolume()
291
-    {
292
-        return $this->granthighvolume == 1;
293
-    }
294
-
295
-    /**
296
-     * @return bool
297
-     */
298
-    public function getGrantCreateEditMovePage()
299
-    {
300
-        return $this->grantcreateeditmovepage == 1;
301
-    }
302
-
303
-    #endregion Properties
304
-
305
-    /**
306
-     * Populates the fields of this instance from a provided JSON Web Token
307
-     *
308
-     * @param stdClass $jwt
309
-     */
310
-    public function populate($jwt)
311
-    {
312
-        $this->iss = $jwt->iss;
313
-        $this->sub = $jwt->sub;
314
-        $this->aud = $jwt->aud;
315
-        $this->exp = $jwt->exp;
316
-        $this->iat = $jwt->iat;
317
-        $this->username = $jwt->username;
318
-        $this->editcount = $jwt->editcount;
319
-        $this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
-        $this->blocked = $jwt->blocked ? 1 : 0;
321
-        $this->registered = $jwt->registered;
322
-
323
-        /*
119
+			);
120
+
121
+			$statement->bindValue(':iss', $this->iss);
122
+			$statement->bindValue(':sub', $this->sub);
123
+			$statement->bindValue(':aud', $this->aud);
124
+			$statement->bindValue(':exp', $this->exp);
125
+			$statement->bindValue(':iat', $this->iat);
126
+			$statement->bindValue(':username', $this->username);
127
+			$statement->bindValue(':editcount', $this->editcount);
128
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
129
+			$statement->bindValue(':blocked', $this->blocked);
130
+			$statement->bindValue(':registered', $this->registered);
131
+			$statement->bindValue(':checkuser', $this->checkuser);
132
+			$statement->bindValue(':grantbasic', $this->grantbasic);
133
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
135
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
+
137
+			$statement->bindValue(':id', $this->id);
138
+			$statement->bindValue(':updateversion', $this->updateversion);
139
+
140
+			if (!$statement->execute()) {
141
+				throw new Exception($statement->errorInfo());
142
+			}
143
+
144
+			if ($statement->rowCount() !== 1) {
145
+				throw new OptimisticLockFailedException();
146
+			}
147
+
148
+			$this->updateversion++;
149
+		}
150
+	}
151
+
152
+	#region Properties
153
+
154
+	/**
155
+	 * @return int
156
+	 */
157
+	public function getUserId()
158
+	{
159
+		return $this->user;
160
+	}
161
+
162
+	/**
163
+	 * @param int $user
164
+	 */
165
+	public function setUserId($user)
166
+	{
167
+		$this->user = $user;
168
+	}
169
+
170
+	/**
171
+	 * @return string
172
+	 */
173
+	public function getIssuer()
174
+	{
175
+		return $this->iss;
176
+	}
177
+
178
+	/**
179
+	 * @return int
180
+	 */
181
+	public function getSubject()
182
+	{
183
+		return $this->sub;
184
+	}
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function getAudience()
190
+	{
191
+		return $this->aud;
192
+	}
193
+
194
+	/**
195
+	 * @return int
196
+	 */
197
+	public function getExpirationTime()
198
+	{
199
+		return $this->exp;
200
+	}
201
+
202
+	/**
203
+	 * @return int
204
+	 */
205
+	public function getIssuedAtTime()
206
+	{
207
+		return $this->iat;
208
+	}
209
+
210
+	/**
211
+	 * @return string
212
+	 */
213
+	public function getUsername()
214
+	{
215
+		return $this->username;
216
+	}
217
+
218
+	/**
219
+	 * @return int
220
+	 */
221
+	public function getEditCount()
222
+	{
223
+		return $this->editcount;
224
+	}
225
+
226
+	/**
227
+	 * @return bool
228
+	 */
229
+	public function getConfirmedEmail()
230
+	{
231
+		return $this->confirmed_email == 1;
232
+	}
233
+
234
+	/**
235
+	 * @return bool
236
+	 */
237
+	public function getBlocked()
238
+	{
239
+		return $this->blocked == 1;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	public function getRegistered()
246
+	{
247
+		return $this->registered;
248
+	}
249
+
250
+	public function getRegistrationDate()
251
+	{
252
+		return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
+	}
254
+
255
+	public function getAccountAge()
256
+	{
257
+		$regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
+		$interval = $regDate->diff(new DateTimeImmutable(), true);
259
+
260
+		return $interval->days;
261
+	}
262
+
263
+	/**
264
+	 * @return bool
265
+	 */
266
+	public function getCheckuser()
267
+	{
268
+		return $this->checkuser == 1;
269
+	}
270
+
271
+	/**
272
+	 * @return bool
273
+	 */
274
+	public function getGrantBasic()
275
+	{
276
+		return $this->grantbasic == 1;
277
+	}
278
+
279
+	/**
280
+	 * @return bool
281
+	 */
282
+	public function getGrantCreateAccount()
283
+	{
284
+		return $this->grantcreateaccount == 1;
285
+	}
286
+
287
+	/**
288
+	 * @return bool
289
+	 */
290
+	public function getGrantHighVolume()
291
+	{
292
+		return $this->granthighvolume == 1;
293
+	}
294
+
295
+	/**
296
+	 * @return bool
297
+	 */
298
+	public function getGrantCreateEditMovePage()
299
+	{
300
+		return $this->grantcreateeditmovepage == 1;
301
+	}
302
+
303
+	#endregion Properties
304
+
305
+	/**
306
+	 * Populates the fields of this instance from a provided JSON Web Token
307
+	 *
308
+	 * @param stdClass $jwt
309
+	 */
310
+	public function populate($jwt)
311
+	{
312
+		$this->iss = $jwt->iss;
313
+		$this->sub = $jwt->sub;
314
+		$this->aud = $jwt->aud;
315
+		$this->exp = $jwt->exp;
316
+		$this->iat = $jwt->iat;
317
+		$this->username = $jwt->username;
318
+		$this->editcount = $jwt->editcount;
319
+		$this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
+		$this->blocked = $jwt->blocked ? 1 : 0;
321
+		$this->registered = $jwt->registered;
322
+
323
+		/*
324 324
          * Rights we need:
325 325
          *  Account creation
326 326
          *      createaccount      => createaccount
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
          * Any antispoof conflicts will still have to be resolved manually using the normal creation form.
343 343
          */
344 344
 
345
-        $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
-        $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
-        $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
348
-        $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0;
345
+		$this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
+		$this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
+		$this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
348
+		$this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0;
349 349
 
350
-        $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0;
351
-    }
350
+		$this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0;
351
+	}
352 352
 }
Please login to merge, or discard this patch.
includes/DataObjects/SiteNotice.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,74 +20,74 @@
 block discarded – undo
20 20
  */
21 21
 class SiteNotice extends DataObject
22 22
 {
23
-    /** @var string */
24
-    private $content;
23
+	/** @var string */
24
+	private $content;
25 25
 
26
-    /**
27
-     * Get a message.
28
-     *
29
-     * @param PdoDatabase $database
30
-     *
31
-     * @return string The content for display
32
-     */
33
-    public static function get(PdoDatabase $database)
34
-    {
35
-        /** @var SiteNotice $message */
36
-        $message = self::getById(1, $database);
26
+	/**
27
+	 * Get a message.
28
+	 *
29
+	 * @param PdoDatabase $database
30
+	 *
31
+	 * @return string The content for display
32
+	 */
33
+	public static function get(PdoDatabase $database)
34
+	{
35
+		/** @var SiteNotice $message */
36
+		$message = self::getById(1, $database);
37 37
 
38
-        return $message->getContent();
39
-    }
38
+		return $message->getContent();
39
+	}
40 40
 
41
-    /**
42
-     * Saves the object
43
-     * @throws Exception
44
-     */
45
-    public function save()
46
-    {
47
-        if ($this->isNew()) {
48
-            // insert
49
-            throw new Exception('Not allowed to create new site notice object');
50
-        }
51
-        else {
52
-            // update
53
-            $statement = $this->dbObject->prepare(<<<SQL
41
+	/**
42
+	 * Saves the object
43
+	 * @throws Exception
44
+	 */
45
+	public function save()
46
+	{
47
+		if ($this->isNew()) {
48
+			// insert
49
+			throw new Exception('Not allowed to create new site notice object');
50
+		}
51
+		else {
52
+			// update
53
+			$statement = $this->dbObject->prepare(<<<SQL
54 54
 UPDATE sitenotice
55 55
 SET content = :content, updateversion = updateversion + 1
56 56
 WHERE updateversion = :updateversion;
57 57
 SQL
58
-            );
59
-            $statement->bindValue(':updateversion', $this->updateversion);
58
+			);
59
+			$statement->bindValue(':updateversion', $this->updateversion);
60 60
 
61
-            $statement->bindValue(':content', $this->content);
61
+			$statement->bindValue(':content', $this->content);
62 62
 
63
-            if (!$statement->execute()) {
64
-                throw new Exception($statement->errorInfo());
65
-            }
63
+			if (!$statement->execute()) {
64
+				throw new Exception($statement->errorInfo());
65
+			}
66 66
 
67
-            if ($statement->rowCount() !== 1) {
68
-                throw new OptimisticLockFailedException();
69
-            }
67
+			if ($statement->rowCount() !== 1) {
68
+				throw new OptimisticLockFailedException();
69
+			}
70 70
 
71
-            $this->updateversion++;
72
-        }
73
-    }
71
+			$this->updateversion++;
72
+		}
73
+	}
74 74
 
75
-    /**
76
-     * Gets the content of the message
77
-     * @return string
78
-     */
79
-    public function getContent()
80
-    {
81
-        return $this->content;
82
-    }
75
+	/**
76
+	 * Gets the content of the message
77
+	 * @return string
78
+	 */
79
+	public function getContent()
80
+	{
81
+		return $this->content;
82
+	}
83 83
 
84
-    /**
85
-     * Sets the content of the message
86
-     *
87
-     * @param string $content
88
-     */
89
-    public function setContent($content)
90
-    {
91
-        $this->content = $content;
92
-    }
84
+	/**
85
+	 * Sets the content of the message
86
+	 *
87
+	 * @param string $content
88
+	 */
89
+	public function setContent($content)
90
+	{
91
+		$this->content = $content;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
includes/DataObjects/OAuthToken.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,42 +14,42 @@  discard block
 block discarded – undo
14 14
 
15 15
 class OAuthToken extends DataObject
16 16
 {
17
-    /** @var int */
18
-    private $user;
19
-    /** @var string */
20
-    private $token;
21
-    /** @var string */
22
-    private $secret;
23
-    /** @var string */
24
-    private $type;
25
-    /** @var string */
26
-    private $expiry;
27
-
28
-    public function save()
29
-    {
30
-        if ($this->isNew()) {
31
-            // insert
32
-            $statement = $this->dbObject->prepare(<<<SQL
17
+	/** @var int */
18
+	private $user;
19
+	/** @var string */
20
+	private $token;
21
+	/** @var string */
22
+	private $secret;
23
+	/** @var string */
24
+	private $type;
25
+	/** @var string */
26
+	private $expiry;
27
+
28
+	public function save()
29
+	{
30
+		if ($this->isNew()) {
31
+			// insert
32
+			$statement = $this->dbObject->prepare(<<<SQL
33 33
                 INSERT INTO oauthtoken ( user, token, secret, type, expiry )
34 34
                 VALUES ( :user, :token, :secret, :type, :expiry );
35 35
 SQL
36
-            );
37
-            $statement->bindValue(":user", $this->user);
38
-            $statement->bindValue(":token", $this->token);
39
-            $statement->bindValue(":secret", $this->secret);
40
-            $statement->bindValue(":type", $this->type);
41
-            $statement->bindValue(":expiry", $this->expiry);
42
-
43
-            if ($statement->execute()) {
44
-                $this->id = (int)$this->dbObject->lastInsertId();
45
-            }
46
-            else {
47
-                throw new Exception($statement->errorInfo());
48
-            }
49
-        }
50
-        else {
51
-            // update
52
-            $statement = $this->dbObject->prepare(<<<SQL
36
+			);
37
+			$statement->bindValue(":user", $this->user);
38
+			$statement->bindValue(":token", $this->token);
39
+			$statement->bindValue(":secret", $this->secret);
40
+			$statement->bindValue(":type", $this->type);
41
+			$statement->bindValue(":expiry", $this->expiry);
42
+
43
+			if ($statement->execute()) {
44
+				$this->id = (int)$this->dbObject->lastInsertId();
45
+			}
46
+			else {
47
+				throw new Exception($statement->errorInfo());
48
+			}
49
+		}
50
+		else {
51
+			// update
52
+			$statement = $this->dbObject->prepare(<<<SQL
53 53
                 UPDATE oauthtoken
54 54
                 SET   token = :token
55 55
                     , secret = :secret
@@ -58,109 +58,109 @@  discard block
 block discarded – undo
58 58
                     , updateversion = updateversion + 1
59 59
                 WHERE id = :id AND updateversion = :updateversion;
60 60
 SQL
61
-            );
62
-
63
-            $statement->bindValue(':id', $this->id);
64
-            $statement->bindValue(':updateversion', $this->updateversion);
65
-
66
-            $statement->bindValue(":token", $this->token);
67
-            $statement->bindValue(":secret", $this->secret);
68
-            $statement->bindValue(":type", $this->type);
69
-            $statement->bindValue(":expiry", $this->expiry);
70
-
71
-            if (!$statement->execute()) {
72
-                throw new Exception($statement->errorInfo());
73
-            }
74
-
75
-            if ($statement->rowCount() !== 1) {
76
-                throw new OptimisticLockFailedException();
77
-            }
78
-
79
-            $this->updateversion++;
80
-        }
81
-    }
82
-
83
-    #region properties
84
-
85
-    /**
86
-     * @return mixed
87
-     */
88
-    public function getUserId()
89
-    {
90
-        return $this->user;
91
-    }
92
-
93
-    /**
94
-     * @param mixed $user
95
-     */
96
-    public function setUserId($user)
97
-    {
98
-        $this->user = $user;
99
-    }
100
-
101
-    /**
102
-     * @return mixed
103
-     */
104
-    public function getToken()
105
-    {
106
-        return $this->token;
107
-    }
108
-
109
-    /**
110
-     * @param mixed $token
111
-     */
112
-    public function setToken($token)
113
-    {
114
-        $this->token = $token;
115
-    }
116
-
117
-    /**
118
-     * @return mixed
119
-     */
120
-    public function getSecret()
121
-    {
122
-        return $this->secret;
123
-    }
124
-
125
-    /**
126
-     * @param mixed $secret
127
-     */
128
-    public function setSecret($secret)
129
-    {
130
-        $this->secret = $secret;
131
-    }
132
-
133
-    /**
134
-     * @return mixed
135
-     */
136
-    public function getType()
137
-    {
138
-        return $this->type;
139
-    }
140
-
141
-    /**
142
-     * @param mixed $type
143
-     */
144
-    public function setType($type)
145
-    {
146
-        $this->type = $type;
147
-    }
148
-
149
-    /**
150
-     * @return string
151
-     */
152
-    public function getExpiry()
153
-    {
154
-        return $this->expiry;
155
-    }
156
-
157
-    /**
158
-     * @param string $expiry
159
-     */
160
-    public function setExpiry($expiry)
161
-    {
162
-        $this->expiry = $expiry;
163
-    }
164
-    #endregion
61
+			);
62
+
63
+			$statement->bindValue(':id', $this->id);
64
+			$statement->bindValue(':updateversion', $this->updateversion);
65
+
66
+			$statement->bindValue(":token", $this->token);
67
+			$statement->bindValue(":secret", $this->secret);
68
+			$statement->bindValue(":type", $this->type);
69
+			$statement->bindValue(":expiry", $this->expiry);
70
+
71
+			if (!$statement->execute()) {
72
+				throw new Exception($statement->errorInfo());
73
+			}
74
+
75
+			if ($statement->rowCount() !== 1) {
76
+				throw new OptimisticLockFailedException();
77
+			}
78
+
79
+			$this->updateversion++;
80
+		}
81
+	}
82
+
83
+	#region properties
84
+
85
+	/**
86
+	 * @return mixed
87
+	 */
88
+	public function getUserId()
89
+	{
90
+		return $this->user;
91
+	}
92
+
93
+	/**
94
+	 * @param mixed $user
95
+	 */
96
+	public function setUserId($user)
97
+	{
98
+		$this->user = $user;
99
+	}
100
+
101
+	/**
102
+	 * @return mixed
103
+	 */
104
+	public function getToken()
105
+	{
106
+		return $this->token;
107
+	}
108
+
109
+	/**
110
+	 * @param mixed $token
111
+	 */
112
+	public function setToken($token)
113
+	{
114
+		$this->token = $token;
115
+	}
116
+
117
+	/**
118
+	 * @return mixed
119
+	 */
120
+	public function getSecret()
121
+	{
122
+		return $this->secret;
123
+	}
124
+
125
+	/**
126
+	 * @param mixed $secret
127
+	 */
128
+	public function setSecret($secret)
129
+	{
130
+		$this->secret = $secret;
131
+	}
132
+
133
+	/**
134
+	 * @return mixed
135
+	 */
136
+	public function getType()
137
+	{
138
+		return $this->type;
139
+	}
140
+
141
+	/**
142
+	 * @param mixed $type
143
+	 */
144
+	public function setType($type)
145
+	{
146
+		$this->type = $type;
147
+	}
148
+
149
+	/**
150
+	 * @return string
151
+	 */
152
+	public function getExpiry()
153
+	{
154
+		return $this->expiry;
155
+	}
156
+
157
+	/**
158
+	 * @param string $expiry
159
+	 */
160
+	public function setExpiry($expiry)
161
+	{
162
+		$this->expiry = $expiry;
163
+	}
164
+	#endregion
165 165
 
166 166
 }
167 167
\ No newline at end of file
Please login to merge, or discard this patch.
includes/DataObjects/Log.php 1 patch
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -17,151 +17,151 @@
 block discarded – undo
17 17
  */
18 18
 class Log extends DataObject
19 19
 {
20
-    /** @var int */
21
-    private $objectid;
22
-    /** @var string */
23
-    private $objecttype;
24
-    /** @var int */
25
-    private $user;
26
-    /** @var string */
27
-    private $action;
28
-    private $timestamp;
29
-    /** @var string|null */
30
-    private $comment;
31
-
32
-    /**
33
-     * @throws Exception
34
-     */
35
-    public function save()
36
-    {
37
-        if ($this->isNew()) {
38
-            $statement = $this->dbObject->prepare(<<<SQL
20
+	/** @var int */
21
+	private $objectid;
22
+	/** @var string */
23
+	private $objecttype;
24
+	/** @var int */
25
+	private $user;
26
+	/** @var string */
27
+	private $action;
28
+	private $timestamp;
29
+	/** @var string|null */
30
+	private $comment;
31
+
32
+	/**
33
+	 * @throws Exception
34
+	 */
35
+	public function save()
36
+	{
37
+		if ($this->isNew()) {
38
+			$statement = $this->dbObject->prepare(<<<SQL
39 39
                 INSERT INTO log (objectid, objecttype, user, action, timestamp, comment) 
40 40
                 VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment);
41 41
 SQL
42
-            );
43
-
44
-            $statement->bindValue(":id", $this->objectid);
45
-            $statement->bindValue(":type", $this->objecttype);
46
-            $statement->bindValue(":user", $this->user);
47
-            $statement->bindValue(":action", $this->action);
48
-            $statement->bindValue(":comment", $this->comment);
49
-
50
-            if ($statement->execute()) {
51
-                $this->id = (int)$this->dbObject->lastInsertId();
52
-            }
53
-            else {
54
-                throw new Exception($statement->errorInfo());
55
-            }
56
-        }
57
-        else {
58
-            throw new Exception("Updating logs is not available");
59
-        }
60
-    }
61
-
62
-    /**
63
-     * @throws Exception
64
-     */
65
-    public function delete()
66
-    {
67
-        throw new Exception("Deleting logs is not available.");
68
-    }
69
-
70
-    /**
71
-     * @return int
72
-     */
73
-    public function getObjectId()
74
-    {
75
-        return $this->objectid;
76
-    }
77
-
78
-    /**
79
-     * Summary of setObjectId
80
-     *
81
-     * @param int $objectId
82
-     */
83
-    public function setObjectId($objectId)
84
-    {
85
-        $this->objectid = $objectId;
86
-    }
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getObjectType()
92
-    {
93
-        return $this->objecttype;
94
-    }
95
-
96
-    /**
97
-     * Summary of setObjectType
98
-     *
99
-     * @param string $objectType
100
-     */
101
-    public function setObjectType($objectType)
102
-    {
103
-        $this->objecttype = $objectType;
104
-    }
105
-
106
-    /**
107
-     * @return int
108
-     */
109
-    public function getUser()
110
-    {
111
-        return $this->user;
112
-    }
113
-
114
-    /**
115
-     * Summary of setUser
116
-     *
117
-     * @param User $user
118
-     */
119
-    public function setUser(User $user)
120
-    {
121
-        $this->user = $user->getId();
122
-    }
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function getAction()
128
-    {
129
-        return $this->action;
130
-    }
131
-
132
-    /**
133
-     * Summary of setAction
134
-     *
135
-     * @param string $action
136
-     */
137
-    public function setAction($action)
138
-    {
139
-        $this->action = $action;
140
-    }
141
-
142
-    /**
143
-     * @return DateTimeImmutable
144
-     */
145
-    public function getTimestamp()
146
-    {
147
-        return new DateTimeImmutable($this->timestamp);
148
-    }
149
-
150
-    /**
151
-     * @return string|null
152
-     */
153
-    public function getComment()
154
-    {
155
-        return $this->comment;
156
-    }
157
-
158
-    /**
159
-     * Summary of setComment
160
-     *
161
-     * @param string $comment
162
-     */
163
-    public function setComment($comment)
164
-    {
165
-        $this->comment = $comment;
166
-    }
42
+			);
43
+
44
+			$statement->bindValue(":id", $this->objectid);
45
+			$statement->bindValue(":type", $this->objecttype);
46
+			$statement->bindValue(":user", $this->user);
47
+			$statement->bindValue(":action", $this->action);
48
+			$statement->bindValue(":comment", $this->comment);
49
+
50
+			if ($statement->execute()) {
51
+				$this->id = (int)$this->dbObject->lastInsertId();
52
+			}
53
+			else {
54
+				throw new Exception($statement->errorInfo());
55
+			}
56
+		}
57
+		else {
58
+			throw new Exception("Updating logs is not available");
59
+		}
60
+	}
61
+
62
+	/**
63
+	 * @throws Exception
64
+	 */
65
+	public function delete()
66
+	{
67
+		throw new Exception("Deleting logs is not available.");
68
+	}
69
+
70
+	/**
71
+	 * @return int
72
+	 */
73
+	public function getObjectId()
74
+	{
75
+		return $this->objectid;
76
+	}
77
+
78
+	/**
79
+	 * Summary of setObjectId
80
+	 *
81
+	 * @param int $objectId
82
+	 */
83
+	public function setObjectId($objectId)
84
+	{
85
+		$this->objectid = $objectId;
86
+	}
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getObjectType()
92
+	{
93
+		return $this->objecttype;
94
+	}
95
+
96
+	/**
97
+	 * Summary of setObjectType
98
+	 *
99
+	 * @param string $objectType
100
+	 */
101
+	public function setObjectType($objectType)
102
+	{
103
+		$this->objecttype = $objectType;
104
+	}
105
+
106
+	/**
107
+	 * @return int
108
+	 */
109
+	public function getUser()
110
+	{
111
+		return $this->user;
112
+	}
113
+
114
+	/**
115
+	 * Summary of setUser
116
+	 *
117
+	 * @param User $user
118
+	 */
119
+	public function setUser(User $user)
120
+	{
121
+		$this->user = $user->getId();
122
+	}
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function getAction()
128
+	{
129
+		return $this->action;
130
+	}
131
+
132
+	/**
133
+	 * Summary of setAction
134
+	 *
135
+	 * @param string $action
136
+	 */
137
+	public function setAction($action)
138
+	{
139
+		$this->action = $action;
140
+	}
141
+
142
+	/**
143
+	 * @return DateTimeImmutable
144
+	 */
145
+	public function getTimestamp()
146
+	{
147
+		return new DateTimeImmutable($this->timestamp);
148
+	}
149
+
150
+	/**
151
+	 * @return string|null
152
+	 */
153
+	public function getComment()
154
+	{
155
+		return $this->comment;
156
+	}
157
+
158
+	/**
159
+	 * Summary of setComment
160
+	 *
161
+	 * @param string $comment
162
+	 */
163
+	public function setComment($comment)
164
+	{
165
+		$this->comment = $comment;
166
+	}
167 167
 }
Please login to merge, or discard this patch.
includes/DataObjects/User.php 1 patch
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -21,160 +21,160 @@  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 = null;
40
-    private $abortpref = 0;
41
-    private $confirmationdiff = 0;
42
-    private $emailsig = "";
43
-    private $creationmode = 0;
44
-    private $skin = "auto";
45
-    /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
46
-    private static $currentUser;
47
-    #region Object load methods
48
-
49
-    /**
50
-     * Gets the currently logged in user
51
-     *
52
-     * @param PdoDatabase $database
53
-     *
54
-     * @return User|CommunityUser
55
-     */
56
-    public static function getCurrent(PdoDatabase $database)
57
-    {
58
-        if (self::$currentUser === null) {
59
-            $sessionId = WebRequest::getSessionUserId();
60
-
61
-            if ($sessionId !== null) {
62
-                /** @var User $user */
63
-                $user = self::getById($sessionId, $database);
64
-
65
-                if ($user === false) {
66
-                    self::$currentUser = new CommunityUser();
67
-                }
68
-                else {
69
-                    self::$currentUser = $user;
70
-                }
71
-            }
72
-            else {
73
-                $anonymousCoward = new CommunityUser();
74
-
75
-                self::$currentUser = $anonymousCoward;
76
-            }
77
-        }
78
-
79
-        return self::$currentUser;
80
-    }
81
-
82
-    /**
83
-     * Gets a user by their user ID
84
-     *
85
-     * Pass -1 to get the community user.
86
-     *
87
-     * @param int|null    $id
88
-     * @param PdoDatabase $database
89
-     *
90
-     * @return User|false
91
-     */
92
-    public static function getById($id, PdoDatabase $database)
93
-    {
94
-        if ($id === null || $id == -1) {
95
-            return new CommunityUser();
96
-        }
97
-
98
-        /** @var User|false $user */
99
-        $user = parent::getById($id, $database);
100
-
101
-        return $user;
102
-    }
103
-
104
-    /**
105
-     * @return CommunityUser
106
-     */
107
-    public static function getCommunity()
108
-    {
109
-        return new CommunityUser();
110
-    }
111
-
112
-    /**
113
-     * Gets a user by their username
114
-     *
115
-     * @param  string      $username
116
-     * @param  PdoDatabase $database
117
-     *
118
-     * @return CommunityUser|User|false
119
-     */
120
-    public static function getByUsername($username, PdoDatabase $database)
121
-    {
122
-        global $communityUsername;
123
-        if ($username == $communityUsername) {
124
-            return new CommunityUser();
125
-        }
126
-
127
-        $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
128
-        $statement->bindValue(":id", $username);
129
-
130
-        $statement->execute();
131
-
132
-        $resultObject = $statement->fetchObject(get_called_class());
133
-
134
-        if ($resultObject != false) {
135
-            $resultObject->setDatabase($database);
136
-        }
137
-
138
-        return $resultObject;
139
-    }
140
-
141
-    /**
142
-     * Gets a user by their on-wiki username.
143
-     *
144
-     * @param string      $username
145
-     * @param PdoDatabase $database
146
-     *
147
-     * @return User|false
148
-     */
149
-    public static function getByOnWikiUsername($username, PdoDatabase $database)
150
-    {
151
-        $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
152
-        $statement->bindValue(":id", $username);
153
-        $statement->execute();
154
-
155
-        $resultObject = $statement->fetchObject(get_called_class());
156
-
157
-        if ($resultObject != false) {
158
-            $resultObject->setDatabase($database);
159
-
160
-            return $resultObject;
161
-        }
162
-
163
-        return false;
164
-    }
165
-
166
-    #endregion
167
-
168
-    /**
169
-     * Saves the current object
170
-     *
171
-     * @throws Exception
172
-     */
173
-    public function save()
174
-    {
175
-        if ($this->isNew()) {
176
-            // insert
177
-            $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 = null;
40
+	private $abortpref = 0;
41
+	private $confirmationdiff = 0;
42
+	private $emailsig = "";
43
+	private $creationmode = 0;
44
+	private $skin = "auto";
45
+	/** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
46
+	private static $currentUser;
47
+	#region Object load methods
48
+
49
+	/**
50
+	 * Gets the currently logged in user
51
+	 *
52
+	 * @param PdoDatabase $database
53
+	 *
54
+	 * @return User|CommunityUser
55
+	 */
56
+	public static function getCurrent(PdoDatabase $database)
57
+	{
58
+		if (self::$currentUser === null) {
59
+			$sessionId = WebRequest::getSessionUserId();
60
+
61
+			if ($sessionId !== null) {
62
+				/** @var User $user */
63
+				$user = self::getById($sessionId, $database);
64
+
65
+				if ($user === false) {
66
+					self::$currentUser = new CommunityUser();
67
+				}
68
+				else {
69
+					self::$currentUser = $user;
70
+				}
71
+			}
72
+			else {
73
+				$anonymousCoward = new CommunityUser();
74
+
75
+				self::$currentUser = $anonymousCoward;
76
+			}
77
+		}
78
+
79
+		return self::$currentUser;
80
+	}
81
+
82
+	/**
83
+	 * Gets a user by their user ID
84
+	 *
85
+	 * Pass -1 to get the community user.
86
+	 *
87
+	 * @param int|null    $id
88
+	 * @param PdoDatabase $database
89
+	 *
90
+	 * @return User|false
91
+	 */
92
+	public static function getById($id, PdoDatabase $database)
93
+	{
94
+		if ($id === null || $id == -1) {
95
+			return new CommunityUser();
96
+		}
97
+
98
+		/** @var User|false $user */
99
+		$user = parent::getById($id, $database);
100
+
101
+		return $user;
102
+	}
103
+
104
+	/**
105
+	 * @return CommunityUser
106
+	 */
107
+	public static function getCommunity()
108
+	{
109
+		return new CommunityUser();
110
+	}
111
+
112
+	/**
113
+	 * Gets a user by their username
114
+	 *
115
+	 * @param  string      $username
116
+	 * @param  PdoDatabase $database
117
+	 *
118
+	 * @return CommunityUser|User|false
119
+	 */
120
+	public static function getByUsername($username, PdoDatabase $database)
121
+	{
122
+		global $communityUsername;
123
+		if ($username == $communityUsername) {
124
+			return new CommunityUser();
125
+		}
126
+
127
+		$statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
128
+		$statement->bindValue(":id", $username);
129
+
130
+		$statement->execute();
131
+
132
+		$resultObject = $statement->fetchObject(get_called_class());
133
+
134
+		if ($resultObject != false) {
135
+			$resultObject->setDatabase($database);
136
+		}
137
+
138
+		return $resultObject;
139
+	}
140
+
141
+	/**
142
+	 * Gets a user by their on-wiki username.
143
+	 *
144
+	 * @param string      $username
145
+	 * @param PdoDatabase $database
146
+	 *
147
+	 * @return User|false
148
+	 */
149
+	public static function getByOnWikiUsername($username, PdoDatabase $database)
150
+	{
151
+		$statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
152
+		$statement->bindValue(":id", $username);
153
+		$statement->execute();
154
+
155
+		$resultObject = $statement->fetchObject(get_called_class());
156
+
157
+		if ($resultObject != false) {
158
+			$resultObject->setDatabase($database);
159
+
160
+			return $resultObject;
161
+		}
162
+
163
+		return false;
164
+	}
165
+
166
+	#endregion
167
+
168
+	/**
169
+	 * Saves the current object
170
+	 *
171
+	 * @throws Exception
172
+	 */
173
+	public function save()
174
+	{
175
+		if ($this->isNew()) {
176
+			// insert
177
+			$statement = $this->dbObject->prepare(<<<SQL
178 178
 				INSERT INTO `user` ( 
179 179
 					username, email, status, onwikiname, welcome_sig, 
180 180
 					lastactive, forcelogout, forceidentified,
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
 					:welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode, :skin
186 186
 				);
187 187
 SQL
188
-            );
189
-            $statement->bindValue(":username", $this->username);
190
-            $statement->bindValue(":email", $this->email);
191
-            $statement->bindValue(":status", $this->status);
192
-            $statement->bindValue(":onwikiname", $this->onwikiname);
193
-            $statement->bindValue(":welcome_sig", $this->welcome_sig);
194
-            $statement->bindValue(":lastactive", $this->lastactive);
195
-            $statement->bindValue(":forcelogout", $this->forcelogout);
196
-            $statement->bindValue(":forceidentified", $this->forceidentified);
197
-            $statement->bindValue(":welcome_template", $this->welcome_template);
198
-            $statement->bindValue(":abortpref", $this->abortpref);
199
-            $statement->bindValue(":confirmationdiff", $this->confirmationdiff);
200
-            $statement->bindValue(":emailsig", $this->emailsig);
201
-            $statement->bindValue(":creationmode", $this->creationmode);
202
-            $statement->bindValue(":skin", $this->skin);
203
-
204
-            if ($statement->execute()) {
205
-                $this->id = (int)$this->dbObject->lastInsertId();
206
-            }
207
-            else {
208
-                throw new Exception($statement->errorInfo());
209
-            }
210
-        }
211
-        else {
212
-            // update
213
-            $statement = $this->dbObject->prepare(<<<SQL
188
+			);
189
+			$statement->bindValue(":username", $this->username);
190
+			$statement->bindValue(":email", $this->email);
191
+			$statement->bindValue(":status", $this->status);
192
+			$statement->bindValue(":onwikiname", $this->onwikiname);
193
+			$statement->bindValue(":welcome_sig", $this->welcome_sig);
194
+			$statement->bindValue(":lastactive", $this->lastactive);
195
+			$statement->bindValue(":forcelogout", $this->forcelogout);
196
+			$statement->bindValue(":forceidentified", $this->forceidentified);
197
+			$statement->bindValue(":welcome_template", $this->welcome_template);
198
+			$statement->bindValue(":abortpref", $this->abortpref);
199
+			$statement->bindValue(":confirmationdiff", $this->confirmationdiff);
200
+			$statement->bindValue(":emailsig", $this->emailsig);
201
+			$statement->bindValue(":creationmode", $this->creationmode);
202
+			$statement->bindValue(":skin", $this->skin);
203
+
204
+			if ($statement->execute()) {
205
+				$this->id = (int)$this->dbObject->lastInsertId();
206
+			}
207
+			else {
208
+				throw new Exception($statement->errorInfo());
209
+			}
210
+		}
211
+		else {
212
+			// update
213
+			$statement = $this->dbObject->prepare(<<<SQL
214 214
 				UPDATE `user` SET 
215 215
 					username = :username, email = :email, 
216 216
 					status = :status,
@@ -223,380 +223,380 @@  discard block
 block discarded – undo
223 223
                     updateversion = updateversion + 1
224 224
 				WHERE id = :id AND updateversion = :updateversion;
225 225
 SQL
226
-            );
227
-            $statement->bindValue(":forceidentified", $this->forceidentified);
228
-
229
-            $statement->bindValue(':id', $this->id);
230
-            $statement->bindValue(':updateversion', $this->updateversion);
231
-
232
-            $statement->bindValue(':username', $this->username);
233
-            $statement->bindValue(':email', $this->email);
234
-            $statement->bindValue(':status', $this->status);
235
-            $statement->bindValue(':onwikiname', $this->onwikiname);
236
-            $statement->bindValue(':welcome_sig', $this->welcome_sig);
237
-            $statement->bindValue(':lastactive', $this->lastactive);
238
-            $statement->bindValue(':forcelogout', $this->forcelogout);
239
-            $statement->bindValue(':forceidentified', $this->forceidentified);
240
-            $statement->bindValue(':welcome_template', $this->welcome_template);
241
-            $statement->bindValue(':abortpref', $this->abortpref);
242
-            $statement->bindValue(':confirmationdiff', $this->confirmationdiff);
243
-            $statement->bindValue(':emailsig', $this->emailsig);
244
-            $statement->bindValue(':creationmode', $this->creationmode);
245
-            $statement->bindValue(':skin', $this->skin);
246
-
247
-            if (!$statement->execute()) {
248
-                throw new Exception($statement->errorInfo());
249
-            }
250
-
251
-            if ($statement->rowCount() !== 1) {
252
-                throw new OptimisticLockFailedException();
253
-            }
254
-
255
-            $this->updateversion++;
256
-        }
257
-    }
258
-
259
-    #region properties
260
-
261
-    /**
262
-     * Gets the tool username
263
-     * @return string
264
-     */
265
-    public function getUsername()
266
-    {
267
-        return $this->username;
268
-    }
269
-
270
-    /**
271
-     * Sets the tool username
272
-     *
273
-     * @param string $username
274
-     */
275
-    public function setUsername($username)
276
-    {
277
-        $this->username = $username;
278
-
279
-        // If this isn't a brand new user, then it's a rename, force the logout
280
-        if (!$this->isNew()) {
281
-            $this->forcelogout = 1;
282
-        }
283
-    }
284
-
285
-    /**
286
-     * Gets the user's email address
287
-     * @return string
288
-     */
289
-    public function getEmail()
290
-    {
291
-        return $this->email;
292
-    }
293
-
294
-    /**
295
-     * Sets the user's email address
296
-     *
297
-     * @param string $email
298
-     */
299
-    public function setEmail($email)
300
-    {
301
-        $this->email = $email;
302
-    }
303
-
304
-    /**
305
-     * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
306
-     * @return string
307
-     */
308
-    public function getStatus()
309
-    {
310
-        return $this->status;
311
-    }
312
-
313
-    /**
314
-     * @param string $status
315
-     */
316
-    public function setStatus($status)
317
-    {
318
-        $this->status = $status;
319
-    }
320
-
321
-    /**
322
-     * Gets the user's on-wiki name
323
-     * @return string
324
-     */
325
-    public function getOnWikiName()
326
-    {
327
-        return $this->onwikiname;
328
-    }
329
-
330
-    /**
331
-     * Sets the user's on-wiki name
332
-     *
333
-     * This can have interesting side-effects with OAuth.
334
-     *
335
-     * @param string $onWikiName
336
-     */
337
-    public function setOnWikiName($onWikiName)
338
-    {
339
-        $this->onwikiname = $onWikiName;
340
-    }
341
-
342
-    /**
343
-     * Gets the welcome signature
344
-     * @return string
345
-     */
346
-    public function getWelcomeSig()
347
-    {
348
-        return $this->welcome_sig;
349
-    }
350
-
351
-    /**
352
-     * Sets the welcome signature
353
-     *
354
-     * @param string $welcomeSig
355
-     */
356
-    public function setWelcomeSig($welcomeSig)
357
-    {
358
-        $this->welcome_sig = $welcomeSig;
359
-    }
360
-
361
-    /**
362
-     * Gets the last activity date for the user
363
-     *
364
-     * @return string
365
-     * @todo This should probably return an instance of DateTime
366
-     */
367
-    public function getLastActive()
368
-    {
369
-        return $this->lastactive;
370
-    }
371
-
372
-    /**
373
-     * Gets the user's forced logout status
374
-     *
375
-     * @return bool
376
-     */
377
-    public function getForceLogout()
378
-    {
379
-        return $this->forcelogout == 1;
380
-    }
381
-
382
-    /**
383
-     * Sets the user's forced logout status
384
-     *
385
-     * @param bool $forceLogout
386
-     */
387
-    public function setForceLogout($forceLogout)
388
-    {
389
-        $this->forcelogout = $forceLogout ? 1 : 0;
390
-    }
391
-
392
-    /**
393
-     * Returns the ID of the welcome template used.
394
-     * @return int
395
-     */
396
-    public function getWelcomeTemplate()
397
-    {
398
-        return $this->welcome_template;
399
-    }
400
-
401
-    /**
402
-     * Sets the ID of the welcome template used.
403
-     *
404
-     * @param int $welcomeTemplate
405
-     */
406
-    public function setWelcomeTemplate($welcomeTemplate)
407
-    {
408
-        $this->welcome_template = $welcomeTemplate;
409
-    }
410
-
411
-    /**
412
-     * Gets the user's abort preference
413
-     * @todo this is badly named too! Also a bool that's actually an int.
414
-     * @return int
415
-     */
416
-    public function getAbortPref()
417
-    {
418
-        return $this->abortpref;
419
-    }
420
-
421
-    /**
422
-     * Sets the user's abort preference
423
-     * @todo rename, retype, and re-comment.
424
-     *
425
-     * @param int $abortPreference
426
-     */
427
-    public function setAbortPref($abortPreference)
428
-    {
429
-        $this->abortpref = $abortPreference;
430
-    }
431
-
432
-    /**
433
-     * Gets the user's confirmation diff. Unused if OAuth is in use.
434
-     * @return int the diff ID
435
-     */
436
-    public function getConfirmationDiff()
437
-    {
438
-        return $this->confirmationdiff;
439
-    }
440
-
441
-    /**
442
-     * Sets the user's confirmation diff.
443
-     *
444
-     * @param int $confirmationDiff
445
-     */
446
-    public function setConfirmationDiff($confirmationDiff)
447
-    {
448
-        $this->confirmationdiff = $confirmationDiff;
449
-    }
450
-
451
-    /**
452
-     * Gets the users' email signature used on outbound mail.
453
-     * @todo rename me!
454
-     * @return string
455
-     */
456
-    public function getEmailSig()
457
-    {
458
-        return $this->emailsig;
459
-    }
460
-
461
-    /**
462
-     * Sets the user's email signature for outbound mail.
463
-     *
464
-     * @param string $emailSignature
465
-     */
466
-    public function setEmailSig($emailSignature)
467
-    {
468
-        $this->emailsig = $emailSignature;
469
-    }
470
-
471
-    /**
472
-     * @return int
473
-     */
474
-    public function getCreationMode()
475
-    {
476
-        return $this->creationmode;
477
-    }
478
-
479
-    /**
480
-     * @param $creationMode int
481
-     */
482
-    public function setCreationMode($creationMode)
483
-    {
484
-        $this->creationmode = $creationMode;
485
-    }
486
-
487
-    /**
488
-     * @return string
489
-     */
490
-    public function getSkin()
491
-    {
492
-        return $this->skin;
493
-    }
494
-
495
-    /**
496
-     * @param $skin string
497
-     */
498
-    public function setSkin($skin)
499
-    {
500
-        $this->skin = $skin;
501
-    }
502
-
503
-    #endregion
504
-
505
-    #region user access checks
506
-
507
-    public function isActive()
508
-    {
509
-        return $this->status == self::STATUS_ACTIVE;
510
-    }
511
-
512
-    /**
513
-     * Tests if the user is identified
514
-     *
515
-     * @param IdentificationVerifier $iv
516
-     *
517
-     * @return bool
518
-     * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
519
-     *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
520
-     *       to play it safe for now.
521
-     * @category Security-Critical
522
-     */
523
-    public function isIdentified(IdentificationVerifier $iv)
524
-    {
525
-        if ($this->forceidentified === 0 || $this->forceidentified === "0") {
526
-            // User forced to unidentified in the database.
527
-            return false;
528
-        }
529
-        elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
530
-            // User forced to identified in the database.
531
-            return true;
532
-        }
533
-        else {
534
-            // User not forced to any particular identified status; consult IdentificationVerifier
535
-            return $iv->isUserIdentified($this->getOnWikiName());
536
-        }
537
-    }
538
-
539
-    /**
540
-     * DO NOT USE FOR TESTING IDENTIFICATION STATUS.
541
-     *
542
-     * @return bool|null
543
-     */
544
-    public function getForceIdentified()
545
-    {
546
-        return $this->forceidentified;
547
-    }
548
-
549
-    /**
550
-     * Tests if the user is suspended
551
-     * @return bool
552
-     * @category Security-Critical
553
-     */
554
-    public function isSuspended()
555
-    {
556
-        return $this->status == self::STATUS_SUSPENDED;
557
-    }
558
-
559
-    /**
560
-     * Tests if the user is new
561
-     * @return bool
562
-     * @category Security-Critical
563
-     */
564
-    public function isNewUser()
565
-    {
566
-        return $this->status == self::STATUS_NEW;
567
-    }
568
-
569
-    /**
570
-     * Tests if the user has been declined access to the tool
571
-     * @return bool
572
-     * @category Security-Critical
573
-     */
574
-    public function isDeclined()
575
-    {
576
-        return $this->status == self::STATUS_DECLINED;
577
-    }
578
-
579
-    /**
580
-     * Tests if the user is the community user
581
-     *
582
-     * @todo     decide if this means logged out. I think it usually does.
583
-     * @return bool
584
-     * @category Security-Critical
585
-     */
586
-    public function isCommunityUser()
587
-    {
588
-        return false;
589
-    }
590
-
591
-    #endregion 
592
-
593
-    /**
594
-     * Gets the approval date of the user
595
-     * @return DateTime|false
596
-     */
597
-    public function getApprovalDate()
598
-    {
599
-        $query = $this->dbObject->prepare(<<<SQL
226
+			);
227
+			$statement->bindValue(":forceidentified", $this->forceidentified);
228
+
229
+			$statement->bindValue(':id', $this->id);
230
+			$statement->bindValue(':updateversion', $this->updateversion);
231
+
232
+			$statement->bindValue(':username', $this->username);
233
+			$statement->bindValue(':email', $this->email);
234
+			$statement->bindValue(':status', $this->status);
235
+			$statement->bindValue(':onwikiname', $this->onwikiname);
236
+			$statement->bindValue(':welcome_sig', $this->welcome_sig);
237
+			$statement->bindValue(':lastactive', $this->lastactive);
238
+			$statement->bindValue(':forcelogout', $this->forcelogout);
239
+			$statement->bindValue(':forceidentified', $this->forceidentified);
240
+			$statement->bindValue(':welcome_template', $this->welcome_template);
241
+			$statement->bindValue(':abortpref', $this->abortpref);
242
+			$statement->bindValue(':confirmationdiff', $this->confirmationdiff);
243
+			$statement->bindValue(':emailsig', $this->emailsig);
244
+			$statement->bindValue(':creationmode', $this->creationmode);
245
+			$statement->bindValue(':skin', $this->skin);
246
+
247
+			if (!$statement->execute()) {
248
+				throw new Exception($statement->errorInfo());
249
+			}
250
+
251
+			if ($statement->rowCount() !== 1) {
252
+				throw new OptimisticLockFailedException();
253
+			}
254
+
255
+			$this->updateversion++;
256
+		}
257
+	}
258
+
259
+	#region properties
260
+
261
+	/**
262
+	 * Gets the tool username
263
+	 * @return string
264
+	 */
265
+	public function getUsername()
266
+	{
267
+		return $this->username;
268
+	}
269
+
270
+	/**
271
+	 * Sets the tool username
272
+	 *
273
+	 * @param string $username
274
+	 */
275
+	public function setUsername($username)
276
+	{
277
+		$this->username = $username;
278
+
279
+		// If this isn't a brand new user, then it's a rename, force the logout
280
+		if (!$this->isNew()) {
281
+			$this->forcelogout = 1;
282
+		}
283
+	}
284
+
285
+	/**
286
+	 * Gets the user's email address
287
+	 * @return string
288
+	 */
289
+	public function getEmail()
290
+	{
291
+		return $this->email;
292
+	}
293
+
294
+	/**
295
+	 * Sets the user's email address
296
+	 *
297
+	 * @param string $email
298
+	 */
299
+	public function setEmail($email)
300
+	{
301
+		$this->email = $email;
302
+	}
303
+
304
+	/**
305
+	 * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
306
+	 * @return string
307
+	 */
308
+	public function getStatus()
309
+	{
310
+		return $this->status;
311
+	}
312
+
313
+	/**
314
+	 * @param string $status
315
+	 */
316
+	public function setStatus($status)
317
+	{
318
+		$this->status = $status;
319
+	}
320
+
321
+	/**
322
+	 * Gets the user's on-wiki name
323
+	 * @return string
324
+	 */
325
+	public function getOnWikiName()
326
+	{
327
+		return $this->onwikiname;
328
+	}
329
+
330
+	/**
331
+	 * Sets the user's on-wiki name
332
+	 *
333
+	 * This can have interesting side-effects with OAuth.
334
+	 *
335
+	 * @param string $onWikiName
336
+	 */
337
+	public function setOnWikiName($onWikiName)
338
+	{
339
+		$this->onwikiname = $onWikiName;
340
+	}
341
+
342
+	/**
343
+	 * Gets the welcome signature
344
+	 * @return string
345
+	 */
346
+	public function getWelcomeSig()
347
+	{
348
+		return $this->welcome_sig;
349
+	}
350
+
351
+	/**
352
+	 * Sets the welcome signature
353
+	 *
354
+	 * @param string $welcomeSig
355
+	 */
356
+	public function setWelcomeSig($welcomeSig)
357
+	{
358
+		$this->welcome_sig = $welcomeSig;
359
+	}
360
+
361
+	/**
362
+	 * Gets the last activity date for the user
363
+	 *
364
+	 * @return string
365
+	 * @todo This should probably return an instance of DateTime
366
+	 */
367
+	public function getLastActive()
368
+	{
369
+		return $this->lastactive;
370
+	}
371
+
372
+	/**
373
+	 * Gets the user's forced logout status
374
+	 *
375
+	 * @return bool
376
+	 */
377
+	public function getForceLogout()
378
+	{
379
+		return $this->forcelogout == 1;
380
+	}
381
+
382
+	/**
383
+	 * Sets the user's forced logout status
384
+	 *
385
+	 * @param bool $forceLogout
386
+	 */
387
+	public function setForceLogout($forceLogout)
388
+	{
389
+		$this->forcelogout = $forceLogout ? 1 : 0;
390
+	}
391
+
392
+	/**
393
+	 * Returns the ID of the welcome template used.
394
+	 * @return int
395
+	 */
396
+	public function getWelcomeTemplate()
397
+	{
398
+		return $this->welcome_template;
399
+	}
400
+
401
+	/**
402
+	 * Sets the ID of the welcome template used.
403
+	 *
404
+	 * @param int $welcomeTemplate
405
+	 */
406
+	public function setWelcomeTemplate($welcomeTemplate)
407
+	{
408
+		$this->welcome_template = $welcomeTemplate;
409
+	}
410
+
411
+	/**
412
+	 * Gets the user's abort preference
413
+	 * @todo this is badly named too! Also a bool that's actually an int.
414
+	 * @return int
415
+	 */
416
+	public function getAbortPref()
417
+	{
418
+		return $this->abortpref;
419
+	}
420
+
421
+	/**
422
+	 * Sets the user's abort preference
423
+	 * @todo rename, retype, and re-comment.
424
+	 *
425
+	 * @param int $abortPreference
426
+	 */
427
+	public function setAbortPref($abortPreference)
428
+	{
429
+		$this->abortpref = $abortPreference;
430
+	}
431
+
432
+	/**
433
+	 * Gets the user's confirmation diff. Unused if OAuth is in use.
434
+	 * @return int the diff ID
435
+	 */
436
+	public function getConfirmationDiff()
437
+	{
438
+		return $this->confirmationdiff;
439
+	}
440
+
441
+	/**
442
+	 * Sets the user's confirmation diff.
443
+	 *
444
+	 * @param int $confirmationDiff
445
+	 */
446
+	public function setConfirmationDiff($confirmationDiff)
447
+	{
448
+		$this->confirmationdiff = $confirmationDiff;
449
+	}
450
+
451
+	/**
452
+	 * Gets the users' email signature used on outbound mail.
453
+	 * @todo rename me!
454
+	 * @return string
455
+	 */
456
+	public function getEmailSig()
457
+	{
458
+		return $this->emailsig;
459
+	}
460
+
461
+	/**
462
+	 * Sets the user's email signature for outbound mail.
463
+	 *
464
+	 * @param string $emailSignature
465
+	 */
466
+	public function setEmailSig($emailSignature)
467
+	{
468
+		$this->emailsig = $emailSignature;
469
+	}
470
+
471
+	/**
472
+	 * @return int
473
+	 */
474
+	public function getCreationMode()
475
+	{
476
+		return $this->creationmode;
477
+	}
478
+
479
+	/**
480
+	 * @param $creationMode int
481
+	 */
482
+	public function setCreationMode($creationMode)
483
+	{
484
+		$this->creationmode = $creationMode;
485
+	}
486
+
487
+	/**
488
+	 * @return string
489
+	 */
490
+	public function getSkin()
491
+	{
492
+		return $this->skin;
493
+	}
494
+
495
+	/**
496
+	 * @param $skin string
497
+	 */
498
+	public function setSkin($skin)
499
+	{
500
+		$this->skin = $skin;
501
+	}
502
+
503
+	#endregion
504
+
505
+	#region user access checks
506
+
507
+	public function isActive()
508
+	{
509
+		return $this->status == self::STATUS_ACTIVE;
510
+	}
511
+
512
+	/**
513
+	 * Tests if the user is identified
514
+	 *
515
+	 * @param IdentificationVerifier $iv
516
+	 *
517
+	 * @return bool
518
+	 * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
519
+	 *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
520
+	 *       to play it safe for now.
521
+	 * @category Security-Critical
522
+	 */
523
+	public function isIdentified(IdentificationVerifier $iv)
524
+	{
525
+		if ($this->forceidentified === 0 || $this->forceidentified === "0") {
526
+			// User forced to unidentified in the database.
527
+			return false;
528
+		}
529
+		elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
530
+			// User forced to identified in the database.
531
+			return true;
532
+		}
533
+		else {
534
+			// User not forced to any particular identified status; consult IdentificationVerifier
535
+			return $iv->isUserIdentified($this->getOnWikiName());
536
+		}
537
+	}
538
+
539
+	/**
540
+	 * DO NOT USE FOR TESTING IDENTIFICATION STATUS.
541
+	 *
542
+	 * @return bool|null
543
+	 */
544
+	public function getForceIdentified()
545
+	{
546
+		return $this->forceidentified;
547
+	}
548
+
549
+	/**
550
+	 * Tests if the user is suspended
551
+	 * @return bool
552
+	 * @category Security-Critical
553
+	 */
554
+	public function isSuspended()
555
+	{
556
+		return $this->status == self::STATUS_SUSPENDED;
557
+	}
558
+
559
+	/**
560
+	 * Tests if the user is new
561
+	 * @return bool
562
+	 * @category Security-Critical
563
+	 */
564
+	public function isNewUser()
565
+	{
566
+		return $this->status == self::STATUS_NEW;
567
+	}
568
+
569
+	/**
570
+	 * Tests if the user has been declined access to the tool
571
+	 * @return bool
572
+	 * @category Security-Critical
573
+	 */
574
+	public function isDeclined()
575
+	{
576
+		return $this->status == self::STATUS_DECLINED;
577
+	}
578
+
579
+	/**
580
+	 * Tests if the user is the community user
581
+	 *
582
+	 * @todo     decide if this means logged out. I think it usually does.
583
+	 * @return bool
584
+	 * @category Security-Critical
585
+	 */
586
+	public function isCommunityUser()
587
+	{
588
+		return false;
589
+	}
590
+
591
+	#endregion 
592
+
593
+	/**
594
+	 * Gets the approval date of the user
595
+	 * @return DateTime|false
596
+	 */
597
+	public function getApprovalDate()
598
+	{
599
+		$query = $this->dbObject->prepare(<<<SQL
600 600
 			SELECT timestamp 
601 601
 			FROM log 
602 602
 			WHERE objectid = :userid
@@ -605,12 +605,12 @@  discard block
 block discarded – undo
605 605
 			ORDER BY id DESC 
606 606
 			LIMIT 1;
607 607
 SQL
608
-        );
609
-        $query->execute(array(":userid" => $this->id));
608
+		);
609
+		$query->execute(array(":userid" => $this->id));
610 610
 
611
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
612
-        $query->closeCursor();
611
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
612
+		$query->closeCursor();
613 613
 
614
-        return $data;
615
-    }
614
+		return $data;
615
+	}
616 616
 }
Please login to merge, or discard this patch.
includes/DataObjects/WelcomeTemplate.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -19,188 +19,188 @@
 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
-    }
184
-
185
-    public function getSectionHeader()
186
-    {
187
-        // Hard-coded for future update ability to change this per-template. This has beem moved from being hard-coded
188
-        // directly in the welcome task, and safely permits us to show the header in the welcome template preview
189
-        return "Welcome!";
190
-    }
191
-
192
-    public function getBotCodeForWikiSave(string $request, $creator)
193
-    {
194
-        $templateText = $this->getBotCode();
195
-
196
-        $templateText = str_replace('$request', $request, $templateText);
197
-        $templateText = str_replace('$creator', $creator, $templateText);
198
-
199
-        // legacy; these have been removed in Prod for now, but I'm keeping them in case someone follows the
200
-        // instructions in prod prior to deployment.
201
-        $templateText = str_replace('$signature', '~~~~', $templateText);
202
-        $templateText = str_replace('$username', $creator, $templateText);
203
-
204
-        return $templateText;
205
-    }
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
+
185
+	public function getSectionHeader()
186
+	{
187
+		// Hard-coded for future update ability to change this per-template. This has beem moved from being hard-coded
188
+		// directly in the welcome task, and safely permits us to show the header in the welcome template preview
189
+		return "Welcome!";
190
+	}
191
+
192
+	public function getBotCodeForWikiSave(string $request, $creator)
193
+	{
194
+		$templateText = $this->getBotCode();
195
+
196
+		$templateText = str_replace('$request', $request, $templateText);
197
+		$templateText = str_replace('$creator', $creator, $templateText);
198
+
199
+		// legacy; these have been removed in Prod for now, but I'm keeping them in case someone follows the
200
+		// instructions in prod prior to deployment.
201
+		$templateText = str_replace('$signature', '~~~~', $templateText);
202
+		$templateText = str_replace('$username', $creator, $templateText);
203
+
204
+		return $templateText;
205
+	}
206 206
 }
Please login to merge, or discard this patch.