Completed
Pull Request — newinternal (#285)
by Simon
07:17 queued 04:17
created
includes/DataObjects/SiteNotice.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,75 +20,75 @@
 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
 LIMIT 1;
58 58
 SQL
59
-            );
60
-            $statement->bindValue(':updateversion', $this->updateversion);
59
+			);
60
+			$statement->bindValue(':updateversion', $this->updateversion);
61 61
 
62
-            $statement->bindValue(':content', $this->content);
62
+			$statement->bindValue(':content', $this->content);
63 63
 
64
-            if (!$statement->execute()) {
65
-                throw new Exception($statement->errorInfo());
66
-            }
64
+			if (!$statement->execute()) {
65
+				throw new Exception($statement->errorInfo());
66
+			}
67 67
 
68
-            if ($statement->rowCount() !== 1) {
69
-                throw new OptimisticLockFailedException();
70
-            }
68
+			if ($statement->rowCount() !== 1) {
69
+				throw new OptimisticLockFailedException();
70
+			}
71 71
 
72
-            $this->updateversion++;
73
-        }
74
-    }
72
+			$this->updateversion++;
73
+		}
74
+	}
75 75
 
76
-    /**
77
-     * Gets the content of the message
78
-     * @return string
79
-     */
80
-    public function getContent()
81
-    {
82
-        return $this->content;
83
-    }
76
+	/**
77
+	 * Gets the content of the message
78
+	 * @return string
79
+	 */
80
+	public function getContent()
81
+	{
82
+		return $this->content;
83
+	}
84 84
 
85
-    /**
86
-     * Sets the content of the message
87
-     *
88
-     * @param string $content
89
-     */
90
-    public function setContent($content)
91
-    {
92
-        $this->content = $content;
93
-    }
85
+	/**
86
+	 * Sets the content of the message
87
+	 *
88
+	 * @param string $content
89
+	 */
90
+	public function setContent($content)
91
+	{
92
+		$this->content = $content;
93
+	}
94 94
 }
Please login to merge, or discard this patch.
includes/DataObjects/CommunityUser.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -16,227 +16,227 @@
 block discarded – undo
16 16
  */
17 17
 class CommunityUser extends User
18 18
 {
19
-    public function getId()
20
-    {
21
-        return -1;
22
-    }
23
-
24
-    public function save()
25
-    {
26
-        // Do nothing
27
-    }
28
-
29
-    public function authenticate($password)
30
-    {
31
-        // Impossible to log in as this user
32
-        return false;
33
-    }
34
-
35
-    #region properties
36
-
37
-    /**
38
-     * @return string
39
-     */
40
-    public function getUsername()
41
-    {
42
-        global $communityUsername;
43
-
44
-        return $communityUsername;
45
-    }
46
-
47
-    public function setUsername($username)
48
-    {
49
-    }
50
-
51
-    /**
52
-     * @return string
53
-     */
54
-    public function getEmail()
55
-    {
56
-        global $cDataClearEmail;
57
-
58
-        return $cDataClearEmail;
59
-    }
60
-
61
-    public function setEmail($email)
62
-    {
63
-    }
64
-
65
-    public function setPassword($password)
66
-    {
67
-    }
68
-
69
-    public function getStatus()
70
-    {
71
-        return "Community";
72
-    }
73
-
74
-    public function getOnWikiName()
75
-    {
76
-        return "127.0.0.1";
77
-    }
78
-
79
-    public function getStoredOnWikiName()
80
-    {
81
-        return $this->getOnWikiName();
82
-    }
83
-
84
-    public function setOnWikiName($onWikiName)
85
-    {
86
-    }
87
-
88
-    public function getWelcomeSig()
89
-    {
90
-        return null;
91
-    }
92
-
93
-    public function setWelcomeSig($welcomeSig)
94
-    {
95
-    }
96
-
97
-    public function getLastActive()
98
-    {
99
-        $now = new DateTime();
100
-
101
-        return $now->format("Y-m-d H:i:s");
102
-    }
103
-
104
-    public function getForceLogout()
105
-    {
106
-        return true;
107
-    }
108
-
109
-    public function setForceLogout($forceLogout)
110
-    {
111
-    }
112
-
113
-    /**
114
-     * @param string $status
115
-     */
116
-    public function setStatus($status)
117
-    {
118
-    }
119
-
120
-    public function getWelcomeTemplate()
121
-    {
122
-        return 0;
123
-    }
124
-
125
-    public function setWelcomeTemplate($welcomeTemplate)
126
-    {
127
-    }
128
-
129
-    public function getAbortPref()
130
-    {
131
-        return 0;
132
-    }
133
-
134
-    public function setAbortPref($abortPreference)
135
-    {
136
-    }
137
-
138
-    public function getConfirmationDiff()
139
-    {
140
-        return null;
141
-    }
142
-
143
-    public function setConfirmationDiff($confirmationDiff)
144
-    {
145
-    }
146
-
147
-    public function getEmailSig()
148
-    {
149
-        return null;
150
-    }
151
-
152
-    public function setEmailSig($emailSignature)
153
-    {
154
-    }
155
-
156
-    #endregion
157
-
158
-    #region user access checks
159
-
160
-    public function isAdmin()
161
-    {
162
-        return false;
163
-    }
164
-
165
-    public function isCheckuser()
166
-    {
167
-        return false;
168
-    }
169
-
170
-    public function isIdentified(IdentificationVerifier $iv)
171
-    {
172
-        return false;
173
-    }
174
-
175
-    public function isSuspended()
176
-    {
177
-        return false;
178
-    }
179
-
180
-    public function isNewUser()
181
-    {
182
-        return false;
183
-    }
184
-
185
-    public function isUser()
186
-    {
187
-        return false;
188
-    }
189
-
190
-    public function isDeclined()
191
-    {
192
-        return false;
193
-    }
194
-
195
-    public function isCommunityUser()
196
-    {
197
-        return true;
198
-    }
199
-
200
-    #endregion 
201
-
202
-    #region OAuth
203
-
204
-    public function getOAuthIdentity($useCached = false)
205
-    {
206
-        return null;
207
-    }
208
-
209
-    public function isOAuthLinked()
210
-    {
211
-        return false;
212
-    }
213
-
214
-    public function oauthCanUse()
215
-    {
216
-        return false;
217
-    }
218
-
219
-    public function oauthCanEdit()
220
-    {
221
-        return false;
222
-    }
223
-
224
-    public function oauthCanCreateAccount()
225
-    {
226
-        return false;
227
-    }
228
-
229
-    protected function oauthCanCheckUser()
230
-    {
231
-        return false;
232
-    }
233
-
234
-    #endregion
235
-
236
-    public function getApprovalDate()
237
-    {
238
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
239
-
240
-        return $data;
241
-    }
19
+	public function getId()
20
+	{
21
+		return -1;
22
+	}
23
+
24
+	public function save()
25
+	{
26
+		// Do nothing
27
+	}
28
+
29
+	public function authenticate($password)
30
+	{
31
+		// Impossible to log in as this user
32
+		return false;
33
+	}
34
+
35
+	#region properties
36
+
37
+	/**
38
+	 * @return string
39
+	 */
40
+	public function getUsername()
41
+	{
42
+		global $communityUsername;
43
+
44
+		return $communityUsername;
45
+	}
46
+
47
+	public function setUsername($username)
48
+	{
49
+	}
50
+
51
+	/**
52
+	 * @return string
53
+	 */
54
+	public function getEmail()
55
+	{
56
+		global $cDataClearEmail;
57
+
58
+		return $cDataClearEmail;
59
+	}
60
+
61
+	public function setEmail($email)
62
+	{
63
+	}
64
+
65
+	public function setPassword($password)
66
+	{
67
+	}
68
+
69
+	public function getStatus()
70
+	{
71
+		return "Community";
72
+	}
73
+
74
+	public function getOnWikiName()
75
+	{
76
+		return "127.0.0.1";
77
+	}
78
+
79
+	public function getStoredOnWikiName()
80
+	{
81
+		return $this->getOnWikiName();
82
+	}
83
+
84
+	public function setOnWikiName($onWikiName)
85
+	{
86
+	}
87
+
88
+	public function getWelcomeSig()
89
+	{
90
+		return null;
91
+	}
92
+
93
+	public function setWelcomeSig($welcomeSig)
94
+	{
95
+	}
96
+
97
+	public function getLastActive()
98
+	{
99
+		$now = new DateTime();
100
+
101
+		return $now->format("Y-m-d H:i:s");
102
+	}
103
+
104
+	public function getForceLogout()
105
+	{
106
+		return true;
107
+	}
108
+
109
+	public function setForceLogout($forceLogout)
110
+	{
111
+	}
112
+
113
+	/**
114
+	 * @param string $status
115
+	 */
116
+	public function setStatus($status)
117
+	{
118
+	}
119
+
120
+	public function getWelcomeTemplate()
121
+	{
122
+		return 0;
123
+	}
124
+
125
+	public function setWelcomeTemplate($welcomeTemplate)
126
+	{
127
+	}
128
+
129
+	public function getAbortPref()
130
+	{
131
+		return 0;
132
+	}
133
+
134
+	public function setAbortPref($abortPreference)
135
+	{
136
+	}
137
+
138
+	public function getConfirmationDiff()
139
+	{
140
+		return null;
141
+	}
142
+
143
+	public function setConfirmationDiff($confirmationDiff)
144
+	{
145
+	}
146
+
147
+	public function getEmailSig()
148
+	{
149
+		return null;
150
+	}
151
+
152
+	public function setEmailSig($emailSignature)
153
+	{
154
+	}
155
+
156
+	#endregion
157
+
158
+	#region user access checks
159
+
160
+	public function isAdmin()
161
+	{
162
+		return false;
163
+	}
164
+
165
+	public function isCheckuser()
166
+	{
167
+		return false;
168
+	}
169
+
170
+	public function isIdentified(IdentificationVerifier $iv)
171
+	{
172
+		return false;
173
+	}
174
+
175
+	public function isSuspended()
176
+	{
177
+		return false;
178
+	}
179
+
180
+	public function isNewUser()
181
+	{
182
+		return false;
183
+	}
184
+
185
+	public function isUser()
186
+	{
187
+		return false;
188
+	}
189
+
190
+	public function isDeclined()
191
+	{
192
+		return false;
193
+	}
194
+
195
+	public function isCommunityUser()
196
+	{
197
+		return true;
198
+	}
199
+
200
+	#endregion 
201
+
202
+	#region OAuth
203
+
204
+	public function getOAuthIdentity($useCached = false)
205
+	{
206
+		return null;
207
+	}
208
+
209
+	public function isOAuthLinked()
210
+	{
211
+		return false;
212
+	}
213
+
214
+	public function oauthCanUse()
215
+	{
216
+		return false;
217
+	}
218
+
219
+	public function oauthCanEdit()
220
+	{
221
+		return false;
222
+	}
223
+
224
+	public function oauthCanCreateAccount()
225
+	{
226
+		return false;
227
+	}
228
+
229
+	protected function oauthCanCheckUser()
230
+	{
231
+		return false;
232
+	}
233
+
234
+	#endregion
235
+
236
+	public function getApprovalDate()
237
+	{
238
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
239
+
240
+		return $data;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
includes/DataObjects/Request.php 2 patches
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -21,30 +21,30 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Request extends DataObject
23 23
 {
24
-    private $email;
25
-    private $ip;
26
-    private $name;
27
-    /** @var string|null */
28
-    private $comment;
29
-    private $status = "Open";
30
-    private $date;
31
-    private $emailsent = 0;
32
-    private $emailconfirm;
33
-    /** @var int|null */
34
-    private $reserved = null;
35
-    private $useragent;
36
-    private $forwardedip;
37
-    private $hasComments = false;
38
-    private $hasCommentsResolved = false;
39
-
40
-    /**
41
-     * @throws Exception
42
-     */
43
-    public function save()
44
-    {
45
-        if ($this->isNew()) {
46
-            // insert
47
-            $statement = $this->dbObject->prepare(<<<SQL
24
+	private $email;
25
+	private $ip;
26
+	private $name;
27
+	/** @var string|null */
28
+	private $comment;
29
+	private $status = "Open";
30
+	private $date;
31
+	private $emailsent = 0;
32
+	private $emailconfirm;
33
+	/** @var int|null */
34
+	private $reserved = null;
35
+	private $useragent;
36
+	private $forwardedip;
37
+	private $hasComments = false;
38
+	private $hasCommentsResolved = false;
39
+
40
+	/**
41
+	 * @throws Exception
42
+	 */
43
+	public function save()
44
+	{
45
+		if ($this->isNew()) {
46
+			// insert
47
+			$statement = $this->dbObject->prepare(<<<SQL
48 48
 INSERT INTO `request` (
49 49
 	email, ip, name, comment, status, date, emailsent,
50 50
 	emailconfirm, reserved, useragent, forwardedip
@@ -53,28 +53,28 @@  discard block
 block discarded – undo
53 53
 	:emailconfirm, :reserved, :useragent, :forwardedip
54 54
 );
55 55
 SQL
56
-            );
57
-            $statement->bindValue(':email', $this->email);
58
-            $statement->bindValue(':ip', $this->ip);
59
-            $statement->bindValue(':name', $this->name);
60
-            $statement->bindValue(':comment', $this->comment);
61
-            $statement->bindValue(':status', $this->status);
62
-            $statement->bindValue(':emailsent', $this->emailsent);
63
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
64
-            $statement->bindValue(':reserved', $this->reserved);
65
-            $statement->bindValue(':useragent', $this->useragent);
66
-            $statement->bindValue(':forwardedip', $this->forwardedip);
67
-
68
-            if ($statement->execute()) {
69
-                $this->id = (int)$this->dbObject->lastInsertId();
70
-            }
71
-            else {
72
-                throw new Exception($statement->errorInfo());
73
-            }
74
-        }
75
-        else {
76
-            // update
77
-            $statement = $this->dbObject->prepare(<<<SQL
56
+			);
57
+			$statement->bindValue(':email', $this->email);
58
+			$statement->bindValue(':ip', $this->ip);
59
+			$statement->bindValue(':name', $this->name);
60
+			$statement->bindValue(':comment', $this->comment);
61
+			$statement->bindValue(':status', $this->status);
62
+			$statement->bindValue(':emailsent', $this->emailsent);
63
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
64
+			$statement->bindValue(':reserved', $this->reserved);
65
+			$statement->bindValue(':useragent', $this->useragent);
66
+			$statement->bindValue(':forwardedip', $this->forwardedip);
67
+
68
+			if ($statement->execute()) {
69
+				$this->id = (int)$this->dbObject->lastInsertId();
70
+			}
71
+			else {
72
+				throw new Exception($statement->errorInfo());
73
+			}
74
+		}
75
+		else {
76
+			// update
77
+			$statement = $this->dbObject->prepare(<<<SQL
78 78
 UPDATE `request` SET
79 79
 	status = :status,
80 80
 	emailsent = :emailsent,
@@ -84,241 +84,241 @@  discard block
 block discarded – undo
84 84
 WHERE id = :id AND updateversion = :updateversion
85 85
 LIMIT 1;
86 86
 SQL
87
-            );
88
-
89
-            $statement->bindValue(':id', $this->id);
90
-            $statement->bindValue(':updateversion', $this->updateversion);
91
-
92
-            $statement->bindValue(':status', $this->status);
93
-            $statement->bindValue(':emailsent', $this->emailsent);
94
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
95
-            $statement->bindValue(':reserved', $this->reserved);
96
-
97
-            if (!$statement->execute()) {
98
-                throw new Exception($statement->errorInfo());
99
-            }
100
-
101
-            if ($statement->rowCount() !== 1) {
102
-                throw new OptimisticLockFailedException();
103
-            }
104
-
105
-            $this->updateversion++;
106
-        }
107
-    }
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function getIp()
113
-    {
114
-        return $this->ip;
115
-    }
116
-
117
-    /**
118
-     * @param string $ip
119
-     */
120
-    public function setIp($ip)
121
-    {
122
-        $this->ip = $ip;
123
-    }
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function getName()
129
-    {
130
-        return $this->name;
131
-    }
132
-
133
-    /**
134
-     * @param string $name
135
-     */
136
-    public function setName($name)
137
-    {
138
-        $this->name = $name;
139
-    }
140
-
141
-    /**
142
-     * @return string|null
143
-     */
144
-    public function getComment()
145
-    {
146
-        return $this->comment;
147
-    }
148
-
149
-    /**
150
-     * @param string $comment
151
-     */
152
-    public function setComment($comment)
153
-    {
154
-        $this->comment = $comment;
155
-    }
156
-
157
-    /**
158
-     * @return string
159
-     */
160
-    public function getStatus()
161
-    {
162
-        return $this->status;
163
-    }
164
-
165
-    /**
166
-     * @param string $status
167
-     */
168
-    public function setStatus($status)
169
-    {
170
-        $this->status = $status;
171
-    }
172
-
173
-    /**
174
-     * Returns the time the request was first submitted
175
-     *
176
-     * @return DateTimeImmutable
177
-     */
178
-    public function getDate()
179
-    {
180
-        return new DateTimeImmutable($this->date);
181
-    }
182
-
183
-    /**
184
-     * @return bool
185
-     */
186
-    public function getEmailSent()
187
-    {
188
-        return $this->emailsent == "1";
189
-    }
190
-
191
-    /**
192
-     * @param bool $emailSent
193
-     */
194
-    public function setEmailSent($emailSent)
195
-    {
196
-        $this->emailsent = $emailSent ? 1 : 0;
197
-    }
198
-
199
-    /**
200
-     * @return int|null
201
-     */
202
-    public function getReserved()
203
-    {
204
-        return $this->reserved;
205
-    }
206
-
207
-    /**
208
-     * @param int|null $reserved
209
-     */
210
-    public function setReserved($reserved)
211
-    {
212
-        $this->reserved = $reserved;
213
-    }
214
-
215
-    /**
216
-     * @return string
217
-     */
218
-    public function getUserAgent()
219
-    {
220
-        return $this->useragent;
221
-    }
222
-
223
-    /**
224
-     * @param string $useragent
225
-     */
226
-    public function setUserAgent($useragent)
227
-    {
228
-        $this->useragent = $useragent;
229
-    }
230
-
231
-    /**
232
-     * @return string|null
233
-     */
234
-    public function getForwardedIp()
235
-    {
236
-        return $this->forwardedip;
237
-    }
238
-
239
-    /**
240
-     * @param string|null $forwardedip
241
-     */
242
-    public function setForwardedIp($forwardedip)
243
-    {
244
-        $this->forwardedip = $forwardedip;
245
-    }
246
-
247
-    /**
248
-     * @return bool
249
-     */
250
-    public function hasComments()
251
-    {
252
-        if ($this->hasCommentsResolved) {
253
-            return $this->hasComments;
254
-        }
255
-
256
-        if ($this->comment != "") {
257
-            $this->hasComments = true;
258
-            $this->hasCommentsResolved = true;
259
-
260
-            return true;
261
-        }
262
-
263
-        $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
264
-        $commentsQuery->bindValue(":id", $this->id);
265
-
266
-        $commentsQuery->execute();
267
-
268
-        $this->hasComments = ($commentsQuery->fetchColumn() != 0);
269
-        $this->hasCommentsResolved = true;
270
-
271
-        return $this->hasComments;
272
-    }
273
-
274
-    /**
275
-     * @return string
276
-     */
277
-    public function getEmailConfirm()
278
-    {
279
-        return $this->emailconfirm;
280
-    }
281
-
282
-    /**
283
-     * @param string $emailconfirm
284
-     */
285
-    public function setEmailConfirm($emailconfirm)
286
-    {
287
-        $this->emailconfirm = $emailconfirm;
288
-    }
289
-
290
-    public function generateEmailConfirmationHash()
291
-    {
292
-        $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
293
-    }
294
-
295
-    /**
296
-     * @return string|null
297
-     */
298
-    public function getEmail()
299
-    {
300
-        return $this->email;
301
-    }
302
-
303
-    /**
304
-     * @param string|null $email
305
-     */
306
-    public function setEmail($email)
307
-    {
308
-        $this->email = $email;
309
-    }
310
-
311
-    /**
312
-     * @return string
313
-     * @throws Exception
314
-     */
315
-    public function getClosureReason()
316
-    {
317
-        if ($this->status != 'Closed') {
318
-            throw new Exception("Can't get closure reason for open request.");
319
-        }
320
-
321
-        $statement = $this->dbObject->prepare(<<<SQL
87
+			);
88
+
89
+			$statement->bindValue(':id', $this->id);
90
+			$statement->bindValue(':updateversion', $this->updateversion);
91
+
92
+			$statement->bindValue(':status', $this->status);
93
+			$statement->bindValue(':emailsent', $this->emailsent);
94
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
95
+			$statement->bindValue(':reserved', $this->reserved);
96
+
97
+			if (!$statement->execute()) {
98
+				throw new Exception($statement->errorInfo());
99
+			}
100
+
101
+			if ($statement->rowCount() !== 1) {
102
+				throw new OptimisticLockFailedException();
103
+			}
104
+
105
+			$this->updateversion++;
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function getIp()
113
+	{
114
+		return $this->ip;
115
+	}
116
+
117
+	/**
118
+	 * @param string $ip
119
+	 */
120
+	public function setIp($ip)
121
+	{
122
+		$this->ip = $ip;
123
+	}
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function getName()
129
+	{
130
+		return $this->name;
131
+	}
132
+
133
+	/**
134
+	 * @param string $name
135
+	 */
136
+	public function setName($name)
137
+	{
138
+		$this->name = $name;
139
+	}
140
+
141
+	/**
142
+	 * @return string|null
143
+	 */
144
+	public function getComment()
145
+	{
146
+		return $this->comment;
147
+	}
148
+
149
+	/**
150
+	 * @param string $comment
151
+	 */
152
+	public function setComment($comment)
153
+	{
154
+		$this->comment = $comment;
155
+	}
156
+
157
+	/**
158
+	 * @return string
159
+	 */
160
+	public function getStatus()
161
+	{
162
+		return $this->status;
163
+	}
164
+
165
+	/**
166
+	 * @param string $status
167
+	 */
168
+	public function setStatus($status)
169
+	{
170
+		$this->status = $status;
171
+	}
172
+
173
+	/**
174
+	 * Returns the time the request was first submitted
175
+	 *
176
+	 * @return DateTimeImmutable
177
+	 */
178
+	public function getDate()
179
+	{
180
+		return new DateTimeImmutable($this->date);
181
+	}
182
+
183
+	/**
184
+	 * @return bool
185
+	 */
186
+	public function getEmailSent()
187
+	{
188
+		return $this->emailsent == "1";
189
+	}
190
+
191
+	/**
192
+	 * @param bool $emailSent
193
+	 */
194
+	public function setEmailSent($emailSent)
195
+	{
196
+		$this->emailsent = $emailSent ? 1 : 0;
197
+	}
198
+
199
+	/**
200
+	 * @return int|null
201
+	 */
202
+	public function getReserved()
203
+	{
204
+		return $this->reserved;
205
+	}
206
+
207
+	/**
208
+	 * @param int|null $reserved
209
+	 */
210
+	public function setReserved($reserved)
211
+	{
212
+		$this->reserved = $reserved;
213
+	}
214
+
215
+	/**
216
+	 * @return string
217
+	 */
218
+	public function getUserAgent()
219
+	{
220
+		return $this->useragent;
221
+	}
222
+
223
+	/**
224
+	 * @param string $useragent
225
+	 */
226
+	public function setUserAgent($useragent)
227
+	{
228
+		$this->useragent = $useragent;
229
+	}
230
+
231
+	/**
232
+	 * @return string|null
233
+	 */
234
+	public function getForwardedIp()
235
+	{
236
+		return $this->forwardedip;
237
+	}
238
+
239
+	/**
240
+	 * @param string|null $forwardedip
241
+	 */
242
+	public function setForwardedIp($forwardedip)
243
+	{
244
+		$this->forwardedip = $forwardedip;
245
+	}
246
+
247
+	/**
248
+	 * @return bool
249
+	 */
250
+	public function hasComments()
251
+	{
252
+		if ($this->hasCommentsResolved) {
253
+			return $this->hasComments;
254
+		}
255
+
256
+		if ($this->comment != "") {
257
+			$this->hasComments = true;
258
+			$this->hasCommentsResolved = true;
259
+
260
+			return true;
261
+		}
262
+
263
+		$commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
264
+		$commentsQuery->bindValue(":id", $this->id);
265
+
266
+		$commentsQuery->execute();
267
+
268
+		$this->hasComments = ($commentsQuery->fetchColumn() != 0);
269
+		$this->hasCommentsResolved = true;
270
+
271
+		return $this->hasComments;
272
+	}
273
+
274
+	/**
275
+	 * @return string
276
+	 */
277
+	public function getEmailConfirm()
278
+	{
279
+		return $this->emailconfirm;
280
+	}
281
+
282
+	/**
283
+	 * @param string $emailconfirm
284
+	 */
285
+	public function setEmailConfirm($emailconfirm)
286
+	{
287
+		$this->emailconfirm = $emailconfirm;
288
+	}
289
+
290
+	public function generateEmailConfirmationHash()
291
+	{
292
+		$this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
293
+	}
294
+
295
+	/**
296
+	 * @return string|null
297
+	 */
298
+	public function getEmail()
299
+	{
300
+		return $this->email;
301
+	}
302
+
303
+	/**
304
+	 * @param string|null $email
305
+	 */
306
+	public function setEmail($email)
307
+	{
308
+		$this->email = $email;
309
+	}
310
+
311
+	/**
312
+	 * @return string
313
+	 * @throws Exception
314
+	 */
315
+	public function getClosureReason()
316
+	{
317
+		if ($this->status != 'Closed') {
318
+			throw new Exception("Can't get closure reason for open request.");
319
+		}
320
+
321
+		$statement = $this->dbObject->prepare(<<<SQL
322 322
 SELECT closes.mail_desc
323 323
 FROM log
324 324
 INNER JOIN closes ON log.action = closes.closes
@@ -328,25 +328,25 @@  discard block
 block discarded – undo
328 328
 ORDER BY log.timestamp DESC
329 329
 LIMIT 1;
330 330
 SQL
331
-        );
331
+		);
332 332
 
333
-        $statement->bindValue(":requestId", $this->id);
334
-        $statement->execute();
335
-        $reason = $statement->fetchColumn();
333
+		$statement->bindValue(":requestId", $this->id);
334
+		$statement->execute();
335
+		$reason = $statement->fetchColumn();
336 336
 
337
-        return $reason;
338
-    }
337
+		return $reason;
338
+	}
339 339
 
340
-    /**
341
-     * Gets a value indicating whether the request was closed as created or not.
342
-     */
343
-    public function getWasCreated()
344
-    {
345
-        if ($this->status != 'Closed') {
346
-            throw new Exception("Can't get closure reason for open request.");
347
-        }
340
+	/**
341
+	 * Gets a value indicating whether the request was closed as created or not.
342
+	 */
343
+	public function getWasCreated()
344
+	{
345
+		if ($this->status != 'Closed') {
346
+			throw new Exception("Can't get closure reason for open request.");
347
+		}
348 348
 
349
-        $statement = $this->dbObject->prepare(<<<SQL
349
+		$statement = $this->dbObject->prepare(<<<SQL
350 350
 SELECT emailtemplate.oncreated, log.action
351 351
 FROM log
352 352
 LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action
@@ -356,60 +356,60 @@  discard block
 block discarded – undo
356 356
 ORDER BY log.timestamp DESC
357 357
 LIMIT 1;
358 358
 SQL
359
-        );
360
-
361
-        $statement->bindValue(":requestId", $this->id);
362
-        $statement->execute();
363
-        $onCreated = $statement->fetchColumn(0);
364
-        $logAction = $statement->fetchColumn(1);
365
-        $statement->closeCursor();
366
-
367
-        if ($onCreated === null) {
368
-            return $logAction === "Closed custom-y";
369
-        }
370
-
371
-        return (bool)$onCreated;
372
-    }
373
-
374
-    /**
375
-     * @return DateTime
376
-     */
377
-    public function getClosureDate()
378
-    {
379
-        $logQuery = $this->dbObject->prepare(<<<SQL
359
+		);
360
+
361
+		$statement->bindValue(":requestId", $this->id);
362
+		$statement->execute();
363
+		$onCreated = $statement->fetchColumn(0);
364
+		$logAction = $statement->fetchColumn(1);
365
+		$statement->closeCursor();
366
+
367
+		if ($onCreated === null) {
368
+			return $logAction === "Closed custom-y";
369
+		}
370
+
371
+		return (bool)$onCreated;
372
+	}
373
+
374
+	/**
375
+	 * @return DateTime
376
+	 */
377
+	public function getClosureDate()
378
+	{
379
+		$logQuery = $this->dbObject->prepare(<<<SQL
380 380
 SELECT timestamp FROM log
381 381
 WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%'
382 382
 ORDER BY timestamp DESC LIMIT 1;
383 383
 SQL
384
-        );
385
-        $logQuery->bindValue(":request", $this->getId());
386
-        $logQuery->execute();
387
-        $logTime = $logQuery->fetchColumn();
388
-        $logQuery->closeCursor();
389
-
390
-        return new DateTime($logTime);
391
-    }
392
-
393
-    /**
394
-     * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
395
-     * data to unauthorised* users.
396
-     *
397
-     * *:Not tool admins, check users, or the reserving user.
398
-     *
399
-     * @return string
400
-     *
401
-     * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
402
-     *       Maybe depend on the last logged action timestamp?
403
-     */
404
-    public function getRevealHash()
405
-    {
406
-        $data = $this->id         // unique per request
407
-            . '|' . $this->ip           // }
408
-            . '|' . $this->forwardedip  // } private data not known to those without access
409
-            . '|' . $this->useragent    // }
410
-            . '|' . $this->email        // }
411
-            . '|' . $this->status;      // to rudimentarily invalidate the token on status change
412
-
413
-        return hash('sha256', $data);
414
-    }
384
+		);
385
+		$logQuery->bindValue(":request", $this->getId());
386
+		$logQuery->execute();
387
+		$logTime = $logQuery->fetchColumn();
388
+		$logQuery->closeCursor();
389
+
390
+		return new DateTime($logTime);
391
+	}
392
+
393
+	/**
394
+	 * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
395
+	 * data to unauthorised* users.
396
+	 *
397
+	 * *:Not tool admins, check users, or the reserving user.
398
+	 *
399
+	 * @return string
400
+	 *
401
+	 * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
402
+	 *       Maybe depend on the last logged action timestamp?
403
+	 */
404
+	public function getRevealHash()
405
+	{
406
+		$data = $this->id         // unique per request
407
+			. '|' . $this->ip           // }
408
+			. '|' . $this->forwardedip  // } private data not known to those without access
409
+			. '|' . $this->useragent    // }
410
+			. '|' . $this->email        // }
411
+			. '|' . $this->status;      // to rudimentarily invalidate the token on status change
412
+
413
+		return hash('sha256', $data);
414
+	}
415 415
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -404,11 +404,11 @@
 block discarded – undo
404 404
     public function getRevealHash()
405 405
     {
406 406
         $data = $this->id         // unique per request
407
-            . '|' . $this->ip           // }
408
-            . '|' . $this->forwardedip  // } private data not known to those without access
409
-            . '|' . $this->useragent    // }
410
-            . '|' . $this->email        // }
411
-            . '|' . $this->status;      // to rudimentarily invalidate the token on status change
407
+            . '|'.$this->ip           // }
408
+            . '|'.$this->forwardedip  // } private data not known to those without access
409
+            . '|'.$this->useragent    // }
410
+            . '|'.$this->email        // }
411
+            . '|'.$this->status; // to rudimentarily invalidate the token on status change
412 412
 
413 413
         return hash('sha256', $data);
414 414
     }
Please login to merge, or discard this patch.
includes/DataObjects/AntiSpoofCache.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -18,101 +18,101 @@
 block discarded – undo
18 18
  */
19 19
 class AntiSpoofCache extends DataObject
20 20
 {
21
-    /** @var string */
22
-    protected $username;
23
-    /** @var string */
24
-    protected $data;
25
-    /** @var string */
26
-    protected $timestamp;
27
-
28
-    /**
29
-     * @param   string    $username
30
-     * @param PdoDatabase $database
31
-     *
32
-     * @return AntiSpoofCache|false
33
-     */
34
-    public static function getByUsername($username, PdoDatabase $database)
35
-    {
36
-        $statement = $database->prepare(<<<SQL
21
+	/** @var string */
22
+	protected $username;
23
+	/** @var string */
24
+	protected $data;
25
+	/** @var string */
26
+	protected $timestamp;
27
+
28
+	/**
29
+	 * @param   string    $username
30
+	 * @param PdoDatabase $database
31
+	 *
32
+	 * @return AntiSpoofCache|false
33
+	 */
34
+	public static function getByUsername($username, PdoDatabase $database)
35
+	{
36
+		$statement = $database->prepare(<<<SQL
37 37
 SELECT *
38 38
 FROM antispoofcache
39 39
 WHERE username = :id AND timestamp > date_sub(now(), INTERVAL 3 HOUR)
40 40
 LIMIT 1
41 41
 SQL
42
-        );
43
-        $statement->bindValue(":id", $username);
44
-
45
-        $statement->execute();
46
-
47
-        $resultObject = $statement->fetchObject(get_called_class());
48
-
49
-        if ($resultObject != false) {
50
-            $resultObject->setDatabase($database);
51
-        }
52
-
53
-        return $resultObject;
54
-    }
55
-
56
-    /**
57
-     * @return string
58
-     */
59
-    public function getUsername()
60
-    {
61
-        return $this->username;
62
-    }
63
-
64
-    /**
65
-     * @param string $username
66
-     */
67
-    public function setUsername($username)
68
-    {
69
-        $this->username = $username;
70
-    }
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    public function getData()
76
-    {
77
-        return $this->data;
78
-    }
79
-
80
-    /**
81
-     * @param string $data
82
-     */
83
-    public function setData($data)
84
-    {
85
-        $this->data = $data;
86
-    }
87
-
88
-    /**
89
-     * @return DateTimeImmutable
90
-     */
91
-    public function getTimestamp()
92
-    {
93
-        return new DateTimeImmutable($this->timestamp);
94
-    }
95
-
96
-    /**
97
-     * @throws Exception
98
-     */
99
-    public function save()
100
-    {
101
-        if ($this->isNew()) {
102
-            // insert
103
-            // clear old data first
104
-            $this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);");
105
-
106
-            $statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);");
107
-            $statement->bindValue(":username", $this->username);
108
-            $statement->bindValue(":data", $this->data);
109
-
110
-            if ($statement->execute()) {
111
-                $this->id = (int)$this->dbObject->lastInsertId();
112
-            }
113
-            else {
114
-                throw new Exception($statement->errorInfo());
115
-            }
116
-        }
117
-    }
42
+		);
43
+		$statement->bindValue(":id", $username);
44
+
45
+		$statement->execute();
46
+
47
+		$resultObject = $statement->fetchObject(get_called_class());
48
+
49
+		if ($resultObject != false) {
50
+			$resultObject->setDatabase($database);
51
+		}
52
+
53
+		return $resultObject;
54
+	}
55
+
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function getUsername()
60
+	{
61
+		return $this->username;
62
+	}
63
+
64
+	/**
65
+	 * @param string $username
66
+	 */
67
+	public function setUsername($username)
68
+	{
69
+		$this->username = $username;
70
+	}
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	public function getData()
76
+	{
77
+		return $this->data;
78
+	}
79
+
80
+	/**
81
+	 * @param string $data
82
+	 */
83
+	public function setData($data)
84
+	{
85
+		$this->data = $data;
86
+	}
87
+
88
+	/**
89
+	 * @return DateTimeImmutable
90
+	 */
91
+	public function getTimestamp()
92
+	{
93
+		return new DateTimeImmutable($this->timestamp);
94
+	}
95
+
96
+	/**
97
+	 * @throws Exception
98
+	 */
99
+	public function save()
100
+	{
101
+		if ($this->isNew()) {
102
+			// insert
103
+			// clear old data first
104
+			$this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);");
105
+
106
+			$statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);");
107
+			$statement->bindValue(":username", $this->username);
108
+			$statement->bindValue(":data", $this->data);
109
+
110
+			if ($statement->execute()) {
111
+				$this->id = (int)$this->dbObject->lastInsertId();
112
+			}
113
+			else {
114
+				throw new Exception($statement->errorInfo());
115
+			}
116
+		}
117
+	}
118 118
 }
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -21,176 +21,176 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EmailTemplate extends DataObject
23 23
 {
24
-    /** Note, also used in template-table.tpl */
25
-    const CREATED = "created";
26
-    /** Note, also used in template-table.tpl */
27
-    const NOT_CREATED = "not created";
28
-    /** Note, also used in template-table.tpl */
29
-    const NONE = null;
30
-    /** @var string the name of the template */
31
-    private $name;
32
-    private $text;
33
-    /** @var string|null */
34
-    private $jsquestion;
35
-    private $active = 1;
36
-    private $preloadonly = 0;
37
-    private $defaultaction = self::NOT_CREATED;
38
-
39
-    /**
40
-     * Gets active non-preload templates
41
-     *
42
-     * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
-     * @param PdoDatabase $database
44
-     *
45
-     * @return array|false
46
-     */
47
-    public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
-    {
49
-        global $createdid;
50
-
51
-        $statement = $database->prepare(<<<SQL
24
+	/** Note, also used in template-table.tpl */
25
+	const CREATED = "created";
26
+	/** Note, also used in template-table.tpl */
27
+	const NOT_CREATED = "not created";
28
+	/** Note, also used in template-table.tpl */
29
+	const NONE = null;
30
+	/** @var string the name of the template */
31
+	private $name;
32
+	private $text;
33
+	/** @var string|null */
34
+	private $jsquestion;
35
+	private $active = 1;
36
+	private $preloadonly = 0;
37
+	private $defaultaction = self::NOT_CREATED;
38
+
39
+	/**
40
+	 * Gets active non-preload templates
41
+	 *
42
+	 * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
+	 * @param PdoDatabase $database
44
+	 *
45
+	 * @return array|false
46
+	 */
47
+	public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
+	{
49
+		global $createdid;
50
+
51
+		$statement = $database->prepare(<<<SQL
52 52
 SELECT * FROM `emailtemplate`
53 53
 WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND id != :createdid;
54 54
 SQL
55
-        );
56
-        $statement->bindValue(":createdid", $createdid);
57
-        $statement->bindValue(":forcreated", $defaultAction);
58
-
59
-        $statement->execute();
60
-
61
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
-
63
-        /** @var EmailTemplate $t */
64
-        foreach ($resultObject as $t) {
65
-            $t->setDatabase($database);
66
-        }
67
-
68
-        return $resultObject;
69
-    }
70
-
71
-    /**
72
-     * Gets active non-preload and preload templates, optionally filtered by the default action.
73
-     *
74
-     * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
-     *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
-     *                                        just get everything.
77
-     * @param PdoDatabase      $database
78
-     *
79
-     * @return array|false
80
-     */
81
-    public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
-    {
83
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
-
85
-        if ($defaultAction === false) {
86
-            $statement = $database->prepare(
87
-                "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
-        }
89
-
90
-        if ($defaultAction === null) {
91
-            $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
-        }
93
-
94
-        $statement->bindValue(":forcreated", $defaultAction);
95
-
96
-        $statement->execute();
97
-
98
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
-
100
-        /** @var EmailTemplate $t */
101
-        foreach ($resultObject as $t) {
102
-            $t->setDatabase($database);
103
-        }
104
-
105
-        return $resultObject;
106
-    }
107
-
108
-    /**
109
-     * Gets all the unactive templates
110
-     *
111
-     * @param PdoDatabase $database
112
-     *
113
-     * @return array
114
-     */
115
-    public static function getAllInactiveTemplates(PdoDatabase $database)
116
-    {
117
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
-        $statement->execute();
119
-
120
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
-
122
-        /** @var EmailTemplate $t */
123
-        foreach ($resultObject as $t) {
124
-            $t->setDatabase($database);
125
-        }
126
-
127
-        return $resultObject;
128
-    }
129
-
130
-    /**
131
-     * @param string      $name
132
-     * @param PdoDatabase $database
133
-     *
134
-     * @return EmailTemplate|false
135
-     */
136
-    public static function getByName($name, PdoDatabase $database)
137
-    {
138
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
-        $statement->bindValue(":name", $name);
140
-
141
-        $statement->execute();
142
-
143
-        $resultObject = $statement->fetchObject(get_called_class());
144
-
145
-        if ($resultObject != false) {
146
-            $resultObject->setDatabase($database);
147
-        }
148
-
149
-        return $resultObject;
150
-    }
151
-
152
-    /**
153
-     * @return EmailTemplate
154
-     */
155
-    public static function getDroppedTemplate()
156
-    {
157
-        $t = new EmailTemplate();
158
-        $t->id = 0;
159
-        $t->active = 1;
160
-        $t->name = 'Dropped';
161
-
162
-        return $t;
163
-    }
164
-
165
-    /**
166
-     * @throws Exception
167
-     */
168
-    public function save()
169
-    {
170
-        if ($this->isNew()) {
171
-            // insert
172
-            $statement = $this->dbObject->prepare(<<<SQL
55
+		);
56
+		$statement->bindValue(":createdid", $createdid);
57
+		$statement->bindValue(":forcreated", $defaultAction);
58
+
59
+		$statement->execute();
60
+
61
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
+
63
+		/** @var EmailTemplate $t */
64
+		foreach ($resultObject as $t) {
65
+			$t->setDatabase($database);
66
+		}
67
+
68
+		return $resultObject;
69
+	}
70
+
71
+	/**
72
+	 * Gets active non-preload and preload templates, optionally filtered by the default action.
73
+	 *
74
+	 * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
+	 *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
+	 *                                        just get everything.
77
+	 * @param PdoDatabase      $database
78
+	 *
79
+	 * @return array|false
80
+	 */
81
+	public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
+	{
83
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
+
85
+		if ($defaultAction === false) {
86
+			$statement = $database->prepare(
87
+				"SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
+		}
89
+
90
+		if ($defaultAction === null) {
91
+			$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
+		}
93
+
94
+		$statement->bindValue(":forcreated", $defaultAction);
95
+
96
+		$statement->execute();
97
+
98
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
+
100
+		/** @var EmailTemplate $t */
101
+		foreach ($resultObject as $t) {
102
+			$t->setDatabase($database);
103
+		}
104
+
105
+		return $resultObject;
106
+	}
107
+
108
+	/**
109
+	 * Gets all the unactive templates
110
+	 *
111
+	 * @param PdoDatabase $database
112
+	 *
113
+	 * @return array
114
+	 */
115
+	public static function getAllInactiveTemplates(PdoDatabase $database)
116
+	{
117
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
+		$statement->execute();
119
+
120
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
+
122
+		/** @var EmailTemplate $t */
123
+		foreach ($resultObject as $t) {
124
+			$t->setDatabase($database);
125
+		}
126
+
127
+		return $resultObject;
128
+	}
129
+
130
+	/**
131
+	 * @param string      $name
132
+	 * @param PdoDatabase $database
133
+	 *
134
+	 * @return EmailTemplate|false
135
+	 */
136
+	public static function getByName($name, PdoDatabase $database)
137
+	{
138
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
+		$statement->bindValue(":name", $name);
140
+
141
+		$statement->execute();
142
+
143
+		$resultObject = $statement->fetchObject(get_called_class());
144
+
145
+		if ($resultObject != false) {
146
+			$resultObject->setDatabase($database);
147
+		}
148
+
149
+		return $resultObject;
150
+	}
151
+
152
+	/**
153
+	 * @return EmailTemplate
154
+	 */
155
+	public static function getDroppedTemplate()
156
+	{
157
+		$t = new EmailTemplate();
158
+		$t->id = 0;
159
+		$t->active = 1;
160
+		$t->name = 'Dropped';
161
+
162
+		return $t;
163
+	}
164
+
165
+	/**
166
+	 * @throws Exception
167
+	 */
168
+	public function save()
169
+	{
170
+		if ($this->isNew()) {
171
+			// insert
172
+			$statement = $this->dbObject->prepare(<<<SQL
173 173
 INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly)
174 174
 VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly);
175 175
 SQL
176
-            );
177
-            $statement->bindValue(":name", $this->name);
178
-            $statement->bindValue(":text", $this->text);
179
-            $statement->bindValue(":jsquestion", $this->jsquestion);
180
-            $statement->bindValue(":defaultaction", $this->defaultaction);
181
-            $statement->bindValue(":active", $this->active);
182
-            $statement->bindValue(":preloadonly", $this->preloadonly);
183
-
184
-            if ($statement->execute()) {
185
-                $this->id = (int)$this->dbObject->lastInsertId();
186
-            }
187
-            else {
188
-                throw new Exception($statement->errorInfo());
189
-            }
190
-        }
191
-        else {
192
-            // update
193
-            $statement = $this->dbObject->prepare(<<<SQL
176
+			);
177
+			$statement->bindValue(":name", $this->name);
178
+			$statement->bindValue(":text", $this->text);
179
+			$statement->bindValue(":jsquestion", $this->jsquestion);
180
+			$statement->bindValue(":defaultaction", $this->defaultaction);
181
+			$statement->bindValue(":active", $this->active);
182
+			$statement->bindValue(":preloadonly", $this->preloadonly);
183
+
184
+			if ($statement->execute()) {
185
+				$this->id = (int)$this->dbObject->lastInsertId();
186
+			}
187
+			else {
188
+				throw new Exception($statement->errorInfo());
189
+			}
190
+		}
191
+		else {
192
+			// update
193
+			$statement = $this->dbObject->prepare(<<<SQL
194 194
 UPDATE `emailtemplate`
195 195
 SET name = :name,
196 196
 	text = :text,
@@ -202,130 +202,130 @@  discard block
 block discarded – undo
202 202
 WHERE id = :id AND updateversion = :updateversion
203 203
 LIMIT 1;
204 204
 SQL
205
-            );
206
-            $statement->bindValue(':id', $this->id);
207
-            $statement->bindValue(':updateversion', $this->updateversion);
208
-
209
-            $statement->bindValue(':name', $this->name);
210
-            $statement->bindValue(":text", $this->text);
211
-            $statement->bindValue(":jsquestion", $this->jsquestion);
212
-            $statement->bindValue(":defaultaction", $this->defaultaction);
213
-            $statement->bindValue(":active", $this->active);
214
-            $statement->bindValue(":preloadonly", $this->preloadonly);
215
-
216
-            if (!$statement->execute()) {
217
-                throw new Exception($statement->errorInfo());
218
-            }
219
-
220
-            if ($statement->rowCount() !== 1) {
221
-                throw new OptimisticLockFailedException();
222
-            }
223
-
224
-            $this->updateversion++;
225
-        }
226
-    }
227
-
228
-    /**
229
-     * Override delete() from DataObject
230
-     */
231
-    public function delete()
232
-    {
233
-        throw new Exception("You shouldn't be doing that, you'll break logs.");
234
-    }
235
-
236
-    /**
237
-     * @return string
238
-     */
239
-    public function getName()
240
-    {
241
-        return $this->name;
242
-    }
243
-
244
-    /**
245
-     * @param string $name
246
-     */
247
-    public function setName($name)
248
-    {
249
-        $this->name = $name;
250
-    }
251
-
252
-    /**
253
-     * @return string
254
-     */
255
-    public function getText()
256
-    {
257
-        return $this->text;
258
-    }
259
-
260
-    /**
261
-     * @param string $text
262
-     */
263
-    public function setText($text)
264
-    {
265
-        $this->text = $text;
266
-    }
267
-
268
-    /**
269
-     * @return string|null
270
-     */
271
-    public function getJsquestion()
272
-    {
273
-        return $this->jsquestion;
274
-    }
275
-
276
-    /**
277
-     * @param string $jsquestion
278
-     */
279
-    public function setJsquestion($jsquestion)
280
-    {
281
-        $this->jsquestion = $jsquestion;
282
-    }
283
-
284
-    /**
285
-     * @return string
286
-     */
287
-    public function getDefaultAction()
288
-    {
289
-        return $this->defaultaction;
290
-    }
291
-
292
-    /**
293
-     * @param string $defaultAction
294
-     */
295
-    public function setDefaultAction($defaultAction)
296
-    {
297
-        $this->defaultaction = $defaultAction;
298
-    }
299
-
300
-    /**
301
-     * @return bool
302
-     */
303
-    public function getActive()
304
-    {
305
-        return $this->active == 1;
306
-    }
307
-
308
-    /**
309
-     * @param bool $active
310
-     */
311
-    public function setActive($active)
312
-    {
313
-        $this->active = $active ? 1 : 0;
314
-    }
315
-
316
-    /**
317
-     * @return bool
318
-     */
319
-    public function getPreloadOnly()
320
-    {
321
-        return $this->preloadonly == 1;
322
-    }
323
-
324
-    /**
325
-     * @param bool $preloadonly
326
-     */
327
-    public function setPreloadOnly($preloadonly)
328
-    {
329
-        $this->preloadonly = $preloadonly ? 1 : 0;
330
-    }
205
+			);
206
+			$statement->bindValue(':id', $this->id);
207
+			$statement->bindValue(':updateversion', $this->updateversion);
208
+
209
+			$statement->bindValue(':name', $this->name);
210
+			$statement->bindValue(":text", $this->text);
211
+			$statement->bindValue(":jsquestion", $this->jsquestion);
212
+			$statement->bindValue(":defaultaction", $this->defaultaction);
213
+			$statement->bindValue(":active", $this->active);
214
+			$statement->bindValue(":preloadonly", $this->preloadonly);
215
+
216
+			if (!$statement->execute()) {
217
+				throw new Exception($statement->errorInfo());
218
+			}
219
+
220
+			if ($statement->rowCount() !== 1) {
221
+				throw new OptimisticLockFailedException();
222
+			}
223
+
224
+			$this->updateversion++;
225
+		}
226
+	}
227
+
228
+	/**
229
+	 * Override delete() from DataObject
230
+	 */
231
+	public function delete()
232
+	{
233
+		throw new Exception("You shouldn't be doing that, you'll break logs.");
234
+	}
235
+
236
+	/**
237
+	 * @return string
238
+	 */
239
+	public function getName()
240
+	{
241
+		return $this->name;
242
+	}
243
+
244
+	/**
245
+	 * @param string $name
246
+	 */
247
+	public function setName($name)
248
+	{
249
+		$this->name = $name;
250
+	}
251
+
252
+	/**
253
+	 * @return string
254
+	 */
255
+	public function getText()
256
+	{
257
+		return $this->text;
258
+	}
259
+
260
+	/**
261
+	 * @param string $text
262
+	 */
263
+	public function setText($text)
264
+	{
265
+		$this->text = $text;
266
+	}
267
+
268
+	/**
269
+	 * @return string|null
270
+	 */
271
+	public function getJsquestion()
272
+	{
273
+		return $this->jsquestion;
274
+	}
275
+
276
+	/**
277
+	 * @param string $jsquestion
278
+	 */
279
+	public function setJsquestion($jsquestion)
280
+	{
281
+		$this->jsquestion = $jsquestion;
282
+	}
283
+
284
+	/**
285
+	 * @return string
286
+	 */
287
+	public function getDefaultAction()
288
+	{
289
+		return $this->defaultaction;
290
+	}
291
+
292
+	/**
293
+	 * @param string $defaultAction
294
+	 */
295
+	public function setDefaultAction($defaultAction)
296
+	{
297
+		$this->defaultaction = $defaultAction;
298
+	}
299
+
300
+	/**
301
+	 * @return bool
302
+	 */
303
+	public function getActive()
304
+	{
305
+		return $this->active == 1;
306
+	}
307
+
308
+	/**
309
+	 * @param bool $active
310
+	 */
311
+	public function setActive($active)
312
+	{
313
+		$this->active = $active ? 1 : 0;
314
+	}
315
+
316
+	/**
317
+	 * @return bool
318
+	 */
319
+	public function getPreloadOnly()
320
+	{
321
+		return $this->preloadonly == 1;
322
+	}
323
+
324
+	/**
325
+	 * @param bool $preloadonly
326
+	 */
327
+	public function setPreloadOnly($preloadonly)
328
+	{
329
+		$this->preloadonly = $preloadonly ? 1 : 0;
330
+	}
331 331
 }
Please login to merge, or discard this patch.
includes/DataObjects/GeoLocation.php 1 patch
Indentation   +99 added lines, -99 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
-     *
32
-     * @return GeoLocation
33
-     */
34
-    public static function getByAddress($address, PdoDatabase $database)
35
-    {
36
-        $statement = $database->prepare("SELECT * FROM geolocation WHERE address = :id LIMIT 1;");
37
-        $statement->bindValue(":id", $address);
38
-
39
-        $statement->execute();
40
-
41
-        $resultObject = $statement->fetchObject(get_called_class());
42
-
43
-        if ($resultObject != false) {
44
-            $resultObject->setDatabase($database);
45
-        }
46
-
47
-        return $resultObject;
48
-    }
49
-
50
-    public function save()
51
-    {
52
-        if ($this->isNew()) {
53
-            // insert
54
-            $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
+	 *
32
+	 * @return GeoLocation
33
+	 */
34
+	public static function getByAddress($address, PdoDatabase $database)
35
+	{
36
+		$statement = $database->prepare("SELECT * FROM geolocation WHERE address = :id LIMIT 1;");
37
+		$statement->bindValue(":id", $address);
38
+
39
+		$statement->execute();
40
+
41
+		$resultObject = $statement->fetchObject(get_called_class());
42
+
43
+		if ($resultObject != false) {
44
+			$resultObject->setDatabase($database);
45
+		}
46
+
47
+		return $resultObject;
48
+	}
49
+
50
+	public function save()
51
+	{
52
+		if ($this->isNew()) {
53
+			// insert
54
+			$statement = $this->dbObject->prepare(<<<SQL
55 55
 INSERT INTO `geolocation` (address, data) VALUES (:address, :data);
56 56
 SQL
57
-            );
58
-            $statement->bindValue(":address", $this->address);
59
-            $statement->bindValue(":data", $this->data);
60
-
61
-            if ($statement->execute()) {
62
-                $this->id = (int)$this->dbObject->lastInsertId();
63
-            }
64
-            else {
65
-                throw new Exception($statement->errorInfo());
66
-            }
67
-        }
68
-        else {
69
-            // update
70
-            $statement = $this->dbObject->prepare(<<<SQL
57
+			);
58
+			$statement->bindValue(":address", $this->address);
59
+			$statement->bindValue(":data", $this->data);
60
+
61
+			if ($statement->execute()) {
62
+				$this->id = (int)$this->dbObject->lastInsertId();
63
+			}
64
+			else {
65
+				throw new Exception($statement->errorInfo());
66
+			}
67
+		}
68
+		else {
69
+			// update
70
+			$statement = $this->dbObject->prepare(<<<SQL
71 71
 UPDATE `geolocation`
72 72
 SET address = :address, data = :data, updateversion = updateversion + 1
73 73
 WHERE id = :id AND updateversion = :updateversion
74 74
 LIMIT 1;
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/Comment.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -20,173 +20,173 @@
 block discarded – undo
20 20
  */
21 21
 class Comment extends DataObject
22 22
 {
23
-    private $time;
24
-    private $user;
25
-    private $comment;
26
-    private $visibility = "user";
27
-    private $request;
28
-
29
-    /**
30
-     * @param integer     $id
31
-     * @param PdoDatabase $database
32
-     *
33
-     * @return Comment[]
34
-     * @throws Exception
35
-     */
36
-    public static function getForRequest($id, PdoDatabase $database)
37
-    {
38
-        $currentUser = User::getCurrent($database);
39
-
40
-        if ($currentUser->isAdmin() || $currentUser->isCheckuser()) {
41
-            // current user is an admin or checkuser, so retrieve everything.
42
-            $statement = $database->prepare("SELECT * FROM comment WHERE request = :target;");
43
-        }
44
-        else {
45
-            // current user isn't an admin, so limit to only those which are visible to users, and private comments
46
-            // the user has posted themselves.
47
-            $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+
29
+	/**
30
+	 * @param integer     $id
31
+	 * @param PdoDatabase $database
32
+	 *
33
+	 * @return Comment[]
34
+	 * @throws Exception
35
+	 */
36
+	public static function getForRequest($id, PdoDatabase $database)
37
+	{
38
+		$currentUser = User::getCurrent($database);
39
+
40
+		if ($currentUser->isAdmin() || $currentUser->isCheckuser()) {
41
+			// current user is an admin or checkuser, so retrieve everything.
42
+			$statement = $database->prepare("SELECT * FROM comment WHERE request = :target;");
43
+		}
44
+		else {
45
+			// current user isn't an admin, so limit to only those which are visible to users, and private comments
46
+			// the user has posted themselves.
47
+			$statement = $database->prepare(<<<SQL
48 48
 SELECT * FROM comment
49 49
 WHERE request = :target AND (visibility = 'user' OR user = :userid);
50 50
 SQL
51
-            );
52
-            $statement->bindValue(":userid", $currentUser->getId());
53
-        }
54
-
55
-        $statement->bindValue(":target", $id);
56
-
57
-        $statement->execute();
58
-
59
-        $result = array();
60
-        /** @var Comment $v */
61
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
62
-            $v->setDatabase($database);
63
-            $result[] = $v;
64
-        }
65
-
66
-        return $result;
67
-    }
68
-
69
-    /**
70
-     * @throws Exception
71
-     */
72
-    public function save()
73
-    {
74
-        if ($this->isNew()) {
75
-            // insert
76
-            $statement = $this->dbObject->prepare(<<<SQL
51
+			);
52
+			$statement->bindValue(":userid", $currentUser->getId());
53
+		}
54
+
55
+		$statement->bindValue(":target", $id);
56
+
57
+		$statement->execute();
58
+
59
+		$result = array();
60
+		/** @var Comment $v */
61
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
62
+			$v->setDatabase($database);
63
+			$result[] = $v;
64
+		}
65
+
66
+		return $result;
67
+	}
68
+
69
+	/**
70
+	 * @throws Exception
71
+	 */
72
+	public function save()
73
+	{
74
+		if ($this->isNew()) {
75
+			// insert
76
+			$statement = $this->dbObject->prepare(<<<SQL
77 77
 INSERT INTO comment ( time, user, comment, visibility, request )
78 78
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request );
79 79
 SQL
80
-            );
81
-            $statement->bindValue(":user", $this->user);
82
-            $statement->bindValue(":comment", $this->comment);
83
-            $statement->bindValue(":visibility", $this->visibility);
84
-            $statement->bindValue(":request", $this->request);
85
-
86
-            if ($statement->execute()) {
87
-                $this->id = (int)$this->dbObject->lastInsertId();
88
-            }
89
-            else {
90
-                throw new Exception($statement->errorInfo());
91
-            }
92
-        }
93
-        else {
94
-            // update
95
-            $statement = $this->dbObject->prepare(<<<SQL
80
+			);
81
+			$statement->bindValue(":user", $this->user);
82
+			$statement->bindValue(":comment", $this->comment);
83
+			$statement->bindValue(":visibility", $this->visibility);
84
+			$statement->bindValue(":request", $this->request);
85
+
86
+			if ($statement->execute()) {
87
+				$this->id = (int)$this->dbObject->lastInsertId();
88
+			}
89
+			else {
90
+				throw new Exception($statement->errorInfo());
91
+			}
92
+		}
93
+		else {
94
+			// update
95
+			$statement = $this->dbObject->prepare(<<<SQL
96 96
 UPDATE comment
97 97
 SET comment = :comment, visibility = :visibility, updateversion = updateversion + 1
98 98
 WHERE id = :id AND updateversion = :updateversion
99 99
 LIMIT 1;
100 100
 SQL
101
-            );
102
-
103
-            $statement->bindValue(':id', $this->id);
104
-            $statement->bindValue(':updateversion', $this->updateversion);
105
-
106
-            $statement->bindValue(':comment', $this->comment);
107
-            $statement->bindValue(':visibility', $this->visibility);
108
-
109
-            if (!$statement->execute()) {
110
-                throw new Exception($statement->errorInfo());
111
-            }
112
-
113
-            if ($statement->rowCount() !== 1) {
114
-                throw new OptimisticLockFailedException();
115
-            }
116
-
117
-            $this->updateversion++;
118
-        }
119
-    }
120
-
121
-    /**
122
-     * @return DateTimeImmutable
123
-     */
124
-    public function getTime()
125
-    {
126
-        return new DateTimeImmutable($this->time);
127
-    }
128
-
129
-    /**
130
-     * @return int
131
-     */
132
-    public function getUser()
133
-    {
134
-        return $this->user;
135
-    }
136
-
137
-    /**
138
-     * @param int $user
139
-     */
140
-    public function setUser($user)
141
-    {
142
-        $this->user = $user;
143
-    }
144
-
145
-    /**
146
-     * @return string
147
-     */
148
-    public function getComment()
149
-    {
150
-        return $this->comment;
151
-    }
152
-
153
-    /**
154
-     * @param string $comment
155
-     */
156
-    public function setComment($comment)
157
-    {
158
-        $this->comment = $comment;
159
-    }
160
-
161
-    /**
162
-     * @return string
163
-     */
164
-    public function getVisibility()
165
-    {
166
-        return $this->visibility;
167
-    }
168
-
169
-    /**
170
-     * @param string $visibility
171
-     */
172
-    public function setVisibility($visibility)
173
-    {
174
-        $this->visibility = $visibility;
175
-    }
176
-
177
-    /**
178
-     * @return int
179
-     */
180
-    public function getRequest()
181
-    {
182
-        return $this->request;
183
-    }
184
-
185
-    /**
186
-     * @param int $request
187
-     */
188
-    public function setRequest($request)
189
-    {
190
-        $this->request = $request;
191
-    }
101
+			);
102
+
103
+			$statement->bindValue(':id', $this->id);
104
+			$statement->bindValue(':updateversion', $this->updateversion);
105
+
106
+			$statement->bindValue(':comment', $this->comment);
107
+			$statement->bindValue(':visibility', $this->visibility);
108
+
109
+			if (!$statement->execute()) {
110
+				throw new Exception($statement->errorInfo());
111
+			}
112
+
113
+			if ($statement->rowCount() !== 1) {
114
+				throw new OptimisticLockFailedException();
115
+			}
116
+
117
+			$this->updateversion++;
118
+		}
119
+	}
120
+
121
+	/**
122
+	 * @return DateTimeImmutable
123
+	 */
124
+	public function getTime()
125
+	{
126
+		return new DateTimeImmutable($this->time);
127
+	}
128
+
129
+	/**
130
+	 * @return int
131
+	 */
132
+	public function getUser()
133
+	{
134
+		return $this->user;
135
+	}
136
+
137
+	/**
138
+	 * @param int $user
139
+	 */
140
+	public function setUser($user)
141
+	{
142
+		$this->user = $user;
143
+	}
144
+
145
+	/**
146
+	 * @return string
147
+	 */
148
+	public function getComment()
149
+	{
150
+		return $this->comment;
151
+	}
152
+
153
+	/**
154
+	 * @param string $comment
155
+	 */
156
+	public function setComment($comment)
157
+	{
158
+		$this->comment = $comment;
159
+	}
160
+
161
+	/**
162
+	 * @return string
163
+	 */
164
+	public function getVisibility()
165
+	{
166
+		return $this->visibility;
167
+	}
168
+
169
+	/**
170
+	 * @param string $visibility
171
+	 */
172
+	public function setVisibility($visibility)
173
+	{
174
+		$this->visibility = $visibility;
175
+	}
176
+
177
+	/**
178
+	 * @return int
179
+	 */
180
+	public function getRequest()
181
+	{
182
+		return $this->request;
183
+	}
184
+
185
+	/**
186
+	 * @param int $request
187
+	 */
188
+	public function setRequest($request)
189
+	{
190
+		$this->request = $request;
191
+	}
192 192
 }
Please login to merge, or discard this patch.
includes/DataObjects/User.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         $userCount = count($userIds);
377 377
 
378 378
         // Firstly, let's create a string of question marks, which will do as positional parameters.
379
-        $inSection = str_repeat('?,', $userCount - 1) . '?';
379
+        $inSection = str_repeat('?,', $userCount - 1).'?';
380 380
 
381 381
         // Now, let's put that into the query. Direct string building here is OK, we're not dealing with user input,
382 382
         // only the *count* of user input, which is safe.
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
             $this->dbObject->prepare("UPDATE user SET oauthidentitycache = NULL WHERE id = :id;")
1092 1092
                 ->execute(array(":id" => $this->id));
1093 1093
 
1094
-            SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage());
1094
+            SessionAlert::warning("OAuth error getting identity from MediaWiki: ".$ex->getMessage());
1095 1095
         }
1096 1096
     }
1097 1097
 
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
      */
1175 1175
     public function getForgottenPasswordHash()
1176 1176
     {
1177
-        return md5($this->username . $this->email . $this->welcome_template . $this->id . $this->password);
1177
+        return md5($this->username.$this->email.$this->welcome_template.$this->id.$this->password);
1178 1178
     }
1179 1179
 
1180 1180
     /**
Please login to merge, or discard this patch.
Indentation   +1128 added lines, -1128 removed lines patch added patch discarded remove patch
@@ -27,285 +27,285 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class User extends DataObject
29 29
 {
30
-    const STATUS_USER = 'User';
31
-    const STATUS_ADMIN = 'Admin';
32
-    const STATUS_SUSPENDED = 'Suspended';
33
-    const STATUS_DECLINED = 'Declined';
34
-    const STATUS_NEW = 'New';
35
-    private $username;
36
-    private $email;
37
-    private $password;
38
-    private $status = self::STATUS_NEW;
39
-    private $onwikiname = "##OAUTH##";
40
-    private $welcome_sig = "";
41
-    private $lastactive = "0000-00-00 00:00:00";
42
-    private $forcelogout = 0;
43
-    private $checkuser = 0;
44
-    private $forceidentified = null;
45
-    private $welcome_template = 0;
46
-    private $abortpref = 0;
47
-    private $confirmationdiff = 0;
48
-    private $emailsig = "";
49
-    /** @var null|string */
50
-    private $oauthrequesttoken = null;
51
-    /** @var null|string */
52
-    private $oauthrequestsecret = null;
53
-    /** @var null|string */
54
-    private $oauthaccesstoken = null;
55
-    /** @var null|string */
56
-    private $oauthaccesssecret = null;
57
-    private $oauthidentitycache = null;
58
-    /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
59
-    private static $currentUser;
60
-    /** @var null|JWT The identity cache */
61
-    private $identityCache = null;
62
-    #region Object load methods
63
-
64
-    /**
65
-     * Gets the currently logged in user
66
-     *
67
-     * @param PdoDatabase $database
68
-     *
69
-     * @return User|CommunityUser
70
-     */
71
-    public static function getCurrent(PdoDatabase $database)
72
-    {
73
-        if (self::$currentUser === null) {
74
-            $sessionId = WebRequest::getSessionUserId();
75
-
76
-            if ($sessionId !== null) {
77
-                /** @var User $user */
78
-                $user = self::getById($sessionId, $database);
79
-
80
-                if ($user === false) {
81
-                    self::$currentUser = new CommunityUser();
82
-                }
83
-                else {
84
-                    self::$currentUser = $user;
85
-                }
86
-            }
87
-            else {
88
-                $anonymousCoward = new CommunityUser();
89
-
90
-                self::$currentUser = $anonymousCoward;
91
-            }
92
-        }
93
-
94
-        return self::$currentUser;
95
-    }
96
-
97
-    /**
98
-     * Gets a user by their user ID
99
-     *
100
-     * Pass -1 to get the community user.
101
-     *
102
-     * @param int|null    $id
103
-     * @param PdoDatabase $database
104
-     *
105
-     * @return User|false
106
-     */
107
-    public static function getById($id, PdoDatabase $database)
108
-    {
109
-        if ($id === null || $id == -1) {
110
-            return new CommunityUser();
111
-        }
112
-
113
-        /** @var User|false $user */
114
-        $user = parent::getById($id, $database);
115
-
116
-        return $user;
117
-    }
118
-
119
-    /**
120
-     * @return CommunityUser
121
-     */
122
-    public static function getCommunity()
123
-    {
124
-        return new CommunityUser();
125
-    }
126
-
127
-    /**
128
-     * Gets a user by their username
129
-     *
130
-     * @param  string      $username
131
-     * @param  PdoDatabase $database
132
-     *
133
-     * @return CommunityUser|User|false
134
-     */
135
-    public static function getByUsername($username, PdoDatabase $database)
136
-    {
137
-        global $communityUsername;
138
-        if ($username == $communityUsername) {
139
-            return new CommunityUser();
140
-        }
141
-
142
-        $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
143
-        $statement->bindValue(":id", $username);
144
-
145
-        $statement->execute();
146
-
147
-        $resultObject = $statement->fetchObject(get_called_class());
148
-
149
-        if ($resultObject != false) {
150
-            $resultObject->setDatabase($database);
151
-        }
152
-
153
-        return $resultObject;
154
-    }
155
-
156
-    /**
157
-     * Gets a user by their on-wiki username.
158
-     *
159
-     * Don't use without asking me first. It's really inefficient in it's current implementation.
160
-     * We need to restructure the user table again to make this more efficient.
161
-     * We don't actually store the on-wiki name in the table any more, instead we
162
-     * are storing JSON in a column (!!). Yep, my fault. Code review is an awesome thing.
163
-     *            -- stw 2015-10-20
164
-     *
165
-     * @param string      $username
166
-     * @param PdoDatabase $database
167
-     *
168
-     * @return User|false
169
-     */
170
-    public static function getByOnWikiUsername($username, PdoDatabase $database)
171
-    {
172
-        // Firstly, try to search by the efficient database lookup.
173
-        $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
174
-        $statement->bindValue(":id", $username);
175
-        $statement->execute();
176
-
177
-        $resultObject = $statement->fetchObject(get_called_class());
178
-
179
-        if ($resultObject != false) {
180
-            $resultObject->setDatabase($database);
181
-
182
-            return $resultObject;
183
-        }
184
-
185
-        // For active users, the above has failed. Let's do it the hard way.
186
-        $sqlStatement = "SELECT * FROM user WHERE onwikiname = '##OAUTH##' AND oauthaccesstoken IS NOT NULL;";
187
-        $statement = $database->prepare($sqlStatement);
188
-        $statement->execute();
189
-        $resultSet = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
190
-
191
-        /** @var User $user */
192
-        foreach ($resultSet as $user) {
193
-            // We have to set this before doing OAuth queries. :(
194
-            $user->setDatabase($database);
195
-
196
-            // Using cached data here!
197
-            if ($user->getOAuthOnWikiName(true) == $username) {
198
-                // Success.
199
-                return $user;
200
-            }
201
-        }
202
-
203
-        // Cached data failed. Let's do it the *REALLY* hard way.
204
-        foreach ($resultSet as $user) {
205
-            // We have to set this before doing OAuth queries. :(
206
-            $user->setDatabase($database);
207
-
208
-            // Don't use the cached data, but instead query the API.
209
-            if ($user->getOAuthOnWikiName(false) == $username) {
210
-                // Success.
211
-                return $user;
212
-            }
213
-        }
214
-
215
-        // Nope. Sorry.
216
-        return false;
217
-    }
218
-
219
-    /**
220
-     * Gets a user by their OAuth request token
221
-     *
222
-     * @param string      $requestToken
223
-     * @param PdoDatabase $database
224
-     *
225
-     * @return User|false
226
-     */
227
-    public static function getByRequestToken($requestToken, PdoDatabase $database)
228
-    {
229
-        $statement = $database->prepare("SELECT * FROM user WHERE oauthrequesttoken = :id LIMIT 1;");
230
-        $statement->bindValue(":id", $requestToken);
231
-
232
-        $statement->execute();
233
-
234
-        $resultObject = $statement->fetchObject(get_called_class());
235
-
236
-        if ($resultObject != false) {
237
-            $resultObject->setDatabase($database);
238
-        }
239
-
240
-        return $resultObject;
241
-    }
242
-
243
-    /**
244
-     * Gets all users with a supplied status
245
-     *
246
-     * @param string      $status
247
-     * @param PdoDatabase $database
248
-     *
249
-     * @return User[]
250
-     */
251
-    public static function getAllWithStatus($status, PdoDatabase $database)
252
-    {
253
-        $statement = $database->prepare("SELECT * FROM user WHERE status = :status");
254
-        $statement->execute(array(":status" => $status));
255
-
256
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
257
-
258
-        /** @var User $u */
259
-        foreach ($resultObject as $u) {
260
-            $u->setDatabase($database);
261
-        }
262
-
263
-        return $resultObject;
264
-    }
265
-
266
-    /**
267
-     * Gets all checkusers
268
-     *
269
-     * @param PdoDatabase $database
270
-     *
271
-     * @return User[]
272
-     */
273
-    public static function getAllCheckusers(PdoDatabase $database)
274
-    {
275
-        $statement = $database->prepare("SELECT * FROM user WHERE checkuser = 1;");
276
-        $statement->execute();
277
-
278
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
279
-
280
-        $resultsCollection = array();
281
-
282
-        /** @var User $u */
283
-        foreach ($resultObject as $u) {
284
-            $u->setDatabase($database);
285
-
286
-            if (!$u->isCheckuser()) {
287
-                continue;
288
-            }
289
-
290
-            $resultsCollection[] = $u;
291
-        }
292
-
293
-        return $resultsCollection;
294
-    }
295
-
296
-    /**
297
-     * Gets all inactive users
298
-     *
299
-     * @param PdoDatabase $database
300
-     *
301
-     * @return User[]
302
-     */
303
-    public static function getAllInactive(PdoDatabase $database)
304
-    {
305
-        $date = new DateTime();
306
-        $date->modify("-45 days");
307
-
308
-        $statement = $database->prepare(<<<SQL
30
+	const STATUS_USER = 'User';
31
+	const STATUS_ADMIN = 'Admin';
32
+	const STATUS_SUSPENDED = 'Suspended';
33
+	const STATUS_DECLINED = 'Declined';
34
+	const STATUS_NEW = 'New';
35
+	private $username;
36
+	private $email;
37
+	private $password;
38
+	private $status = self::STATUS_NEW;
39
+	private $onwikiname = "##OAUTH##";
40
+	private $welcome_sig = "";
41
+	private $lastactive = "0000-00-00 00:00:00";
42
+	private $forcelogout = 0;
43
+	private $checkuser = 0;
44
+	private $forceidentified = null;
45
+	private $welcome_template = 0;
46
+	private $abortpref = 0;
47
+	private $confirmationdiff = 0;
48
+	private $emailsig = "";
49
+	/** @var null|string */
50
+	private $oauthrequesttoken = null;
51
+	/** @var null|string */
52
+	private $oauthrequestsecret = null;
53
+	/** @var null|string */
54
+	private $oauthaccesstoken = null;
55
+	/** @var null|string */
56
+	private $oauthaccesssecret = null;
57
+	private $oauthidentitycache = null;
58
+	/** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
59
+	private static $currentUser;
60
+	/** @var null|JWT The identity cache */
61
+	private $identityCache = null;
62
+	#region Object load methods
63
+
64
+	/**
65
+	 * Gets the currently logged in user
66
+	 *
67
+	 * @param PdoDatabase $database
68
+	 *
69
+	 * @return User|CommunityUser
70
+	 */
71
+	public static function getCurrent(PdoDatabase $database)
72
+	{
73
+		if (self::$currentUser === null) {
74
+			$sessionId = WebRequest::getSessionUserId();
75
+
76
+			if ($sessionId !== null) {
77
+				/** @var User $user */
78
+				$user = self::getById($sessionId, $database);
79
+
80
+				if ($user === false) {
81
+					self::$currentUser = new CommunityUser();
82
+				}
83
+				else {
84
+					self::$currentUser = $user;
85
+				}
86
+			}
87
+			else {
88
+				$anonymousCoward = new CommunityUser();
89
+
90
+				self::$currentUser = $anonymousCoward;
91
+			}
92
+		}
93
+
94
+		return self::$currentUser;
95
+	}
96
+
97
+	/**
98
+	 * Gets a user by their user ID
99
+	 *
100
+	 * Pass -1 to get the community user.
101
+	 *
102
+	 * @param int|null    $id
103
+	 * @param PdoDatabase $database
104
+	 *
105
+	 * @return User|false
106
+	 */
107
+	public static function getById($id, PdoDatabase $database)
108
+	{
109
+		if ($id === null || $id == -1) {
110
+			return new CommunityUser();
111
+		}
112
+
113
+		/** @var User|false $user */
114
+		$user = parent::getById($id, $database);
115
+
116
+		return $user;
117
+	}
118
+
119
+	/**
120
+	 * @return CommunityUser
121
+	 */
122
+	public static function getCommunity()
123
+	{
124
+		return new CommunityUser();
125
+	}
126
+
127
+	/**
128
+	 * Gets a user by their username
129
+	 *
130
+	 * @param  string      $username
131
+	 * @param  PdoDatabase $database
132
+	 *
133
+	 * @return CommunityUser|User|false
134
+	 */
135
+	public static function getByUsername($username, PdoDatabase $database)
136
+	{
137
+		global $communityUsername;
138
+		if ($username == $communityUsername) {
139
+			return new CommunityUser();
140
+		}
141
+
142
+		$statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
143
+		$statement->bindValue(":id", $username);
144
+
145
+		$statement->execute();
146
+
147
+		$resultObject = $statement->fetchObject(get_called_class());
148
+
149
+		if ($resultObject != false) {
150
+			$resultObject->setDatabase($database);
151
+		}
152
+
153
+		return $resultObject;
154
+	}
155
+
156
+	/**
157
+	 * Gets a user by their on-wiki username.
158
+	 *
159
+	 * Don't use without asking me first. It's really inefficient in it's current implementation.
160
+	 * We need to restructure the user table again to make this more efficient.
161
+	 * We don't actually store the on-wiki name in the table any more, instead we
162
+	 * are storing JSON in a column (!!). Yep, my fault. Code review is an awesome thing.
163
+	 *            -- stw 2015-10-20
164
+	 *
165
+	 * @param string      $username
166
+	 * @param PdoDatabase $database
167
+	 *
168
+	 * @return User|false
169
+	 */
170
+	public static function getByOnWikiUsername($username, PdoDatabase $database)
171
+	{
172
+		// Firstly, try to search by the efficient database lookup.
173
+		$statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
174
+		$statement->bindValue(":id", $username);
175
+		$statement->execute();
176
+
177
+		$resultObject = $statement->fetchObject(get_called_class());
178
+
179
+		if ($resultObject != false) {
180
+			$resultObject->setDatabase($database);
181
+
182
+			return $resultObject;
183
+		}
184
+
185
+		// For active users, the above has failed. Let's do it the hard way.
186
+		$sqlStatement = "SELECT * FROM user WHERE onwikiname = '##OAUTH##' AND oauthaccesstoken IS NOT NULL;";
187
+		$statement = $database->prepare($sqlStatement);
188
+		$statement->execute();
189
+		$resultSet = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
190
+
191
+		/** @var User $user */
192
+		foreach ($resultSet as $user) {
193
+			// We have to set this before doing OAuth queries. :(
194
+			$user->setDatabase($database);
195
+
196
+			// Using cached data here!
197
+			if ($user->getOAuthOnWikiName(true) == $username) {
198
+				// Success.
199
+				return $user;
200
+			}
201
+		}
202
+
203
+		// Cached data failed. Let's do it the *REALLY* hard way.
204
+		foreach ($resultSet as $user) {
205
+			// We have to set this before doing OAuth queries. :(
206
+			$user->setDatabase($database);
207
+
208
+			// Don't use the cached data, but instead query the API.
209
+			if ($user->getOAuthOnWikiName(false) == $username) {
210
+				// Success.
211
+				return $user;
212
+			}
213
+		}
214
+
215
+		// Nope. Sorry.
216
+		return false;
217
+	}
218
+
219
+	/**
220
+	 * Gets a user by their OAuth request token
221
+	 *
222
+	 * @param string      $requestToken
223
+	 * @param PdoDatabase $database
224
+	 *
225
+	 * @return User|false
226
+	 */
227
+	public static function getByRequestToken($requestToken, PdoDatabase $database)
228
+	{
229
+		$statement = $database->prepare("SELECT * FROM user WHERE oauthrequesttoken = :id LIMIT 1;");
230
+		$statement->bindValue(":id", $requestToken);
231
+
232
+		$statement->execute();
233
+
234
+		$resultObject = $statement->fetchObject(get_called_class());
235
+
236
+		if ($resultObject != false) {
237
+			$resultObject->setDatabase($database);
238
+		}
239
+
240
+		return $resultObject;
241
+	}
242
+
243
+	/**
244
+	 * Gets all users with a supplied status
245
+	 *
246
+	 * @param string      $status
247
+	 * @param PdoDatabase $database
248
+	 *
249
+	 * @return User[]
250
+	 */
251
+	public static function getAllWithStatus($status, PdoDatabase $database)
252
+	{
253
+		$statement = $database->prepare("SELECT * FROM user WHERE status = :status");
254
+		$statement->execute(array(":status" => $status));
255
+
256
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
257
+
258
+		/** @var User $u */
259
+		foreach ($resultObject as $u) {
260
+			$u->setDatabase($database);
261
+		}
262
+
263
+		return $resultObject;
264
+	}
265
+
266
+	/**
267
+	 * Gets all checkusers
268
+	 *
269
+	 * @param PdoDatabase $database
270
+	 *
271
+	 * @return User[]
272
+	 */
273
+	public static function getAllCheckusers(PdoDatabase $database)
274
+	{
275
+		$statement = $database->prepare("SELECT * FROM user WHERE checkuser = 1;");
276
+		$statement->execute();
277
+
278
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
279
+
280
+		$resultsCollection = array();
281
+
282
+		/** @var User $u */
283
+		foreach ($resultObject as $u) {
284
+			$u->setDatabase($database);
285
+
286
+			if (!$u->isCheckuser()) {
287
+				continue;
288
+			}
289
+
290
+			$resultsCollection[] = $u;
291
+		}
292
+
293
+		return $resultsCollection;
294
+	}
295
+
296
+	/**
297
+	 * Gets all inactive users
298
+	 *
299
+	 * @param PdoDatabase $database
300
+	 *
301
+	 * @return User[]
302
+	 */
303
+	public static function getAllInactive(PdoDatabase $database)
304
+	{
305
+		$date = new DateTime();
306
+		$date->modify("-45 days");
307
+
308
+		$statement = $database->prepare(<<<SQL
309 309
 			SELECT * 
310 310
 			FROM user 
311 311
 			WHERE lastactive < :lastactivelimit 
@@ -314,104 +314,104 @@  discard block
 block discarded – undo
314 314
 				AND status != 'New' 
315 315
 			ORDER BY lastactive ASC;
316 316
 SQL
317
-        );
318
-        $statement->execute(array(":lastactivelimit" => $date->format("Y-m-d H:i:s")));
319
-
320
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
321
-
322
-        /** @var User $u */
323
-        foreach ($resultObject as $u) {
324
-            $u->setDatabase($database);
325
-        }
326
-
327
-        return $resultObject;
328
-    }
329
-
330
-    /**
331
-     * Gets all the usernames in the system
332
-     *
333
-     * @param PdoDatabase      $database
334
-     * @param null|bool|string $filter If null, no filter. If true, active users only, otherwise provided status.
335
-     *
336
-     * @return string[]
337
-     */
338
-    public static function getAllUsernames(PdoDatabase $database, $filter = null)
339
-    {
340
-        if ($filter === null) {
341
-            $userListQuery = "SELECT username FROM user;";
342
-            $userListResult = $database->query($userListQuery);
343
-        }
344
-        elseif ($filter === true) {
345
-            $userListQuery = "SELECT username FROM user WHERE status IN ('User', 'Admin');";
346
-            $userListResult = $database->query($userListQuery);
347
-        }
348
-        else {
349
-            $userListQuery = "SELECT username FROM user WHERE status = :status;";
350
-            $userListResult = $database->prepare($userListQuery);
351
-            $userListResult->execute(array(":status" => $filter));
352
-        }
353
-
354
-        return $userListResult->fetchAll(PDO::FETCH_COLUMN);
355
-    }
356
-
357
-    /**
358
-     * @param array       $userIds
359
-     * @param PdoDatabase $database
360
-     *
361
-     * @return array
362
-     * @throws Exception
363
-     */
364
-    public static function getUsernames($userIds, PdoDatabase $database)
365
-    {
366
-        if (!is_array($userIds)) {
367
-            throw new Exception('getUsernames() expects array');
368
-        }
369
-
370
-        if (count($userIds) === 0) {
371
-            // empty set of data
372
-            return array();
373
-        }
374
-
375
-        // Urgh. OK. You can't use IN() with parameters directly, so let's munge something together.
376
-        $userCount = count($userIds);
377
-
378
-        // Firstly, let's create a string of question marks, which will do as positional parameters.
379
-        $inSection = str_repeat('?,', $userCount - 1) . '?';
380
-
381
-        // Now, let's put that into the query. Direct string building here is OK, we're not dealing with user input,
382
-        // only the *count* of user input, which is safe.
383
-        $query = "SELECT id, username FROM user WHERE id IN ({$inSection})";
384
-
385
-        // Prepare the query
386
-        $statement = $database->prepare($query);
387
-
388
-        // Bind the parameters and execute - in one go - since we already have a handy array kicking around.
389
-        $statement->execute($userIds);
390
-
391
-        $resultSet = $statement->fetchAll(PDO::FETCH_ASSOC);
392
-
393
-        $users = array();
394
-        foreach ($resultSet as $row) {
395
-            $users[$row['id']] = $row['username'];
396
-        }
397
-
398
-        $statement->closeCursor();
399
-
400
-        return $users;
401
-    }
402
-
403
-    #endregion
404
-
405
-    /**
406
-     * Saves the current object
407
-     *
408
-     * @throws Exception
409
-     */
410
-    public function save()
411
-    {
412
-        if ($this->isNew()) {
413
-            // insert
414
-            $statement = $this->dbObject->prepare(<<<SQL
317
+		);
318
+		$statement->execute(array(":lastactivelimit" => $date->format("Y-m-d H:i:s")));
319
+
320
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
321
+
322
+		/** @var User $u */
323
+		foreach ($resultObject as $u) {
324
+			$u->setDatabase($database);
325
+		}
326
+
327
+		return $resultObject;
328
+	}
329
+
330
+	/**
331
+	 * Gets all the usernames in the system
332
+	 *
333
+	 * @param PdoDatabase      $database
334
+	 * @param null|bool|string $filter If null, no filter. If true, active users only, otherwise provided status.
335
+	 *
336
+	 * @return string[]
337
+	 */
338
+	public static function getAllUsernames(PdoDatabase $database, $filter = null)
339
+	{
340
+		if ($filter === null) {
341
+			$userListQuery = "SELECT username FROM user;";
342
+			$userListResult = $database->query($userListQuery);
343
+		}
344
+		elseif ($filter === true) {
345
+			$userListQuery = "SELECT username FROM user WHERE status IN ('User', 'Admin');";
346
+			$userListResult = $database->query($userListQuery);
347
+		}
348
+		else {
349
+			$userListQuery = "SELECT username FROM user WHERE status = :status;";
350
+			$userListResult = $database->prepare($userListQuery);
351
+			$userListResult->execute(array(":status" => $filter));
352
+		}
353
+
354
+		return $userListResult->fetchAll(PDO::FETCH_COLUMN);
355
+	}
356
+
357
+	/**
358
+	 * @param array       $userIds
359
+	 * @param PdoDatabase $database
360
+	 *
361
+	 * @return array
362
+	 * @throws Exception
363
+	 */
364
+	public static function getUsernames($userIds, PdoDatabase $database)
365
+	{
366
+		if (!is_array($userIds)) {
367
+			throw new Exception('getUsernames() expects array');
368
+		}
369
+
370
+		if (count($userIds) === 0) {
371
+			// empty set of data
372
+			return array();
373
+		}
374
+
375
+		// Urgh. OK. You can't use IN() with parameters directly, so let's munge something together.
376
+		$userCount = count($userIds);
377
+
378
+		// Firstly, let's create a string of question marks, which will do as positional parameters.
379
+		$inSection = str_repeat('?,', $userCount - 1) . '?';
380
+
381
+		// Now, let's put that into the query. Direct string building here is OK, we're not dealing with user input,
382
+		// only the *count* of user input, which is safe.
383
+		$query = "SELECT id, username FROM user WHERE id IN ({$inSection})";
384
+
385
+		// Prepare the query
386
+		$statement = $database->prepare($query);
387
+
388
+		// Bind the parameters and execute - in one go - since we already have a handy array kicking around.
389
+		$statement->execute($userIds);
390
+
391
+		$resultSet = $statement->fetchAll(PDO::FETCH_ASSOC);
392
+
393
+		$users = array();
394
+		foreach ($resultSet as $row) {
395
+			$users[$row['id']] = $row['username'];
396
+		}
397
+
398
+		$statement->closeCursor();
399
+
400
+		return $users;
401
+	}
402
+
403
+	#endregion
404
+
405
+	/**
406
+	 * Saves the current object
407
+	 *
408
+	 * @throws Exception
409
+	 */
410
+	public function save()
411
+	{
412
+		if ($this->isNew()) {
413
+			// insert
414
+			$statement = $this->dbObject->prepare(<<<SQL
415 415
 				INSERT INTO `user` ( 
416 416
 					username, email, password, status, onwikiname, welcome_sig, 
417 417
 					lastactive, forcelogout, checkuser, forceidentified,
@@ -425,36 +425,36 @@  discard block
 block discarded – undo
425 425
 					:ort, :ors, :oat, :oas
426 426
 				);
427 427
 SQL
428
-            );
429
-            $statement->bindValue(":username", $this->username);
430
-            $statement->bindValue(":email", $this->email);
431
-            $statement->bindValue(":password", $this->password);
432
-            $statement->bindValue(":status", $this->status);
433
-            $statement->bindValue(":onwikiname", $this->onwikiname);
434
-            $statement->bindValue(":welcome_sig", $this->welcome_sig);
435
-            $statement->bindValue(":lastactive", $this->lastactive);
436
-            $statement->bindValue(":forcelogout", $this->forcelogout);
437
-            $statement->bindValue(":checkuser", $this->checkuser);
438
-            $statement->bindValue(":forceidentified", $this->forceidentified);
439
-            $statement->bindValue(":welcome_template", $this->welcome_template);
440
-            $statement->bindValue(":abortpref", $this->abortpref);
441
-            $statement->bindValue(":confirmationdiff", $this->confirmationdiff);
442
-            $statement->bindValue(":emailsig", $this->emailsig);
443
-            $statement->bindValue(":ort", $this->oauthrequesttoken);
444
-            $statement->bindValue(":ors", $this->oauthrequestsecret);
445
-            $statement->bindValue(":oat", $this->oauthaccesstoken);
446
-            $statement->bindValue(":oas", $this->oauthaccesssecret);
447
-
448
-            if ($statement->execute()) {
449
-                $this->id = (int)$this->dbObject->lastInsertId();
450
-            }
451
-            else {
452
-                throw new Exception($statement->errorInfo());
453
-            }
454
-        }
455
-        else {
456
-            // update
457
-            $statement = $this->dbObject->prepare(<<<SQL
428
+			);
429
+			$statement->bindValue(":username", $this->username);
430
+			$statement->bindValue(":email", $this->email);
431
+			$statement->bindValue(":password", $this->password);
432
+			$statement->bindValue(":status", $this->status);
433
+			$statement->bindValue(":onwikiname", $this->onwikiname);
434
+			$statement->bindValue(":welcome_sig", $this->welcome_sig);
435
+			$statement->bindValue(":lastactive", $this->lastactive);
436
+			$statement->bindValue(":forcelogout", $this->forcelogout);
437
+			$statement->bindValue(":checkuser", $this->checkuser);
438
+			$statement->bindValue(":forceidentified", $this->forceidentified);
439
+			$statement->bindValue(":welcome_template", $this->welcome_template);
440
+			$statement->bindValue(":abortpref", $this->abortpref);
441
+			$statement->bindValue(":confirmationdiff", $this->confirmationdiff);
442
+			$statement->bindValue(":emailsig", $this->emailsig);
443
+			$statement->bindValue(":ort", $this->oauthrequesttoken);
444
+			$statement->bindValue(":ors", $this->oauthrequestsecret);
445
+			$statement->bindValue(":oat", $this->oauthaccesstoken);
446
+			$statement->bindValue(":oas", $this->oauthaccesssecret);
447
+
448
+			if ($statement->execute()) {
449
+				$this->id = (int)$this->dbObject->lastInsertId();
450
+			}
451
+			else {
452
+				throw new Exception($statement->errorInfo());
453
+			}
454
+		}
455
+		else {
456
+			// update
457
+			$statement = $this->dbObject->prepare(<<<SQL
458 458
 				UPDATE `user` SET 
459 459
 					username = :username, email = :email, 
460 460
 					password = :password, status = :status,
@@ -469,721 +469,721 @@  discard block
 block discarded – undo
469 469
 				WHERE id = :id AND updateversion = :updateversion
470 470
 				LIMIT 1;
471 471
 SQL
472
-            );
473
-            $statement->bindValue(":forceidentified", $this->forceidentified);
474
-
475
-            $statement->bindValue(':id', $this->id);
476
-            $statement->bindValue(':updateversion', $this->updateversion);
477
-
478
-            $statement->bindValue(':username', $this->username);
479
-            $statement->bindValue(':email', $this->email);
480
-            $statement->bindValue(':password', $this->password);
481
-            $statement->bindValue(':status', $this->status);
482
-            $statement->bindValue(':onwikiname', $this->onwikiname);
483
-            $statement->bindValue(':welcome_sig', $this->welcome_sig);
484
-            $statement->bindValue(':lastactive', $this->lastactive);
485
-            $statement->bindValue(':forcelogout', $this->forcelogout);
486
-            $statement->bindValue(':checkuser', $this->checkuser);
487
-            $statement->bindValue(':forceidentified', $this->forceidentified);
488
-            $statement->bindValue(':welcome_template', $this->welcome_template);
489
-            $statement->bindValue(':abortpref', $this->abortpref);
490
-            $statement->bindValue(':confirmationdiff', $this->confirmationdiff);
491
-            $statement->bindValue(':emailsig', $this->emailsig);
492
-            $statement->bindValue(':ort', $this->oauthrequesttoken);
493
-            $statement->bindValue(':ors', $this->oauthrequestsecret);
494
-            $statement->bindValue(':oat', $this->oauthaccesstoken);
495
-            $statement->bindValue(':oas', $this->oauthaccesssecret);
496
-
497
-            if (!$statement->execute()) {
498
-                throw new Exception($statement->errorInfo());
499
-            }
500
-
501
-            if ($statement->rowCount() !== 1) {
502
-                throw new OptimisticLockFailedException();
503
-            }
504
-
505
-            $this->updateversion++;
506
-        }
507
-    }
508
-
509
-    /**
510
-     * Authenticates the user with the supplied password
511
-     *
512
-     * @param string $password
513
-     *
514
-     * @return bool
515
-     * @throws Exception
516
-     * @category Security-Critical
517
-     */
518
-    public function authenticate($password)
519
-    {
520
-        $result = AuthUtility::testCredentials($password, $this->password);
521
-
522
-        if ($result === true) {
523
-            // password version is out of date, update it.
524
-            if (!AuthUtility::isCredentialVersionLatest($this->password)) {
525
-                $this->password = AuthUtility::encryptPassword($password);
526
-                $this->save();
527
-            }
528
-        }
529
-
530
-        return $result;
531
-    }
532
-
533
-    #region properties
534
-
535
-    /**
536
-     * Gets the tool username
537
-     * @return string
538
-     */
539
-    public function getUsername()
540
-    {
541
-        return $this->username;
542
-    }
543
-
544
-    /**
545
-     * Sets the tool username
546
-     *
547
-     * @param string $username
548
-     */
549
-    public function setUsername($username)
550
-    {
551
-        $this->username = $username;
552
-
553
-        // If this isn't a brand new user, then it's a rename, force the logout
554
-        if (!$this->isNew()) {
555
-            $this->forcelogout = 1;
556
-        }
557
-    }
558
-
559
-    /**
560
-     * Gets the user's email address
561
-     * @return string
562
-     */
563
-    public function getEmail()
564
-    {
565
-        return $this->email;
566
-    }
567
-
568
-    /**
569
-     * Sets the user's email address
570
-     *
571
-     * @param string $email
572
-     */
573
-    public function setEmail($email)
574
-    {
575
-        $this->email = $email;
576
-    }
577
-
578
-    /**
579
-     * Sets the user's password
580
-     *
581
-     * @param string $password the plaintext password
582
-     *
583
-     * @category Security-Critical
584
-     */
585
-    public function setPassword($password)
586
-    {
587
-        $this->password = AuthUtility::encryptPassword($password);
588
-    }
589
-
590
-    /**
591
-     * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
592
-     * @return string
593
-     */
594
-    public function getStatus()
595
-    {
596
-        return $this->status;
597
-    }
598
-
599
-    /**
600
-     * @param string $status
601
-     */
602
-    public function setStatus($status)
603
-    {
604
-        $this->status = $status;
605
-    }
606
-
607
-    /**
608
-     * Gets the user's on-wiki name
609
-     * @return string
610
-     */
611
-    public function getOnWikiName()
612
-    {
613
-        if ($this->oauthaccesstoken !== null) {
614
-            try {
615
-                return $this->getOAuthOnWikiName();
616
-            }
617
-            catch (Exception $ex) {
618
-                // urm.. log this?
619
-                return $this->onwikiname;
620
-            }
621
-        }
622
-
623
-        return $this->onwikiname;
624
-    }
625
-
626
-    /**
627
-     * This is probably NOT the function you want!
628
-     *
629
-     * Take a look at getOnWikiName() instead.
630
-     * @return string
631
-     */
632
-    public function getStoredOnWikiName()
633
-    {
634
-        return $this->onwikiname;
635
-    }
636
-
637
-    /**
638
-     * Sets the user's on-wiki name
639
-     *
640
-     * This can have interesting side-effects with OAuth.
641
-     *
642
-     * @param string $onWikiName
643
-     */
644
-    public function setOnWikiName($onWikiName)
645
-    {
646
-        $this->onwikiname = $onWikiName;
647
-    }
648
-
649
-    /**
650
-     * Gets the welcome signature
651
-     * @return string
652
-     */
653
-    public function getWelcomeSig()
654
-    {
655
-        return $this->welcome_sig;
656
-    }
657
-
658
-    /**
659
-     * Sets the welcome signature
660
-     *
661
-     * @param string $welcomeSig
662
-     */
663
-    public function setWelcomeSig($welcomeSig)
664
-    {
665
-        $this->welcome_sig = $welcomeSig;
666
-    }
667
-
668
-    /**
669
-     * Gets the last activity date for the user
670
-     *
671
-     * @return string
672
-     * @todo This should probably return an instance of DateTime
673
-     */
674
-    public function getLastActive()
675
-    {
676
-        return $this->lastactive;
677
-    }
678
-
679
-    /**
680
-     * Gets the user's forced logout status
681
-     *
682
-     * @return bool
683
-     */
684
-    public function getForceLogout()
685
-    {
686
-        return $this->forcelogout == 1;
687
-    }
688
-
689
-    /**
690
-     * Sets the user's forced logout status
691
-     *
692
-     * @param bool $forceLogout
693
-     */
694
-    public function setForceLogout($forceLogout)
695
-    {
696
-        $this->forcelogout = $forceLogout ? 1 : 0;
697
-    }
698
-
699
-    /**
700
-     * Returns the ID of the welcome template used.
701
-     * @return int
702
-     */
703
-    public function getWelcomeTemplate()
704
-    {
705
-        return $this->welcome_template;
706
-    }
707
-
708
-    /**
709
-     * Sets the ID of the welcome template used.
710
-     *
711
-     * @param int $welcomeTemplate
712
-     */
713
-    public function setWelcomeTemplate($welcomeTemplate)
714
-    {
715
-        $this->welcome_template = $welcomeTemplate;
716
-    }
717
-
718
-    /**
719
-     * Gets the user's abort preference
720
-     * @todo this is badly named too! Also a bool that's actually an int.
721
-     * @return int
722
-     */
723
-    public function getAbortPref()
724
-    {
725
-        return $this->abortpref;
726
-    }
727
-
728
-    /**
729
-     * Sets the user's abort preference
730
-     * @todo rename, retype, and re-comment.
731
-     *
732
-     * @param int $abortPreference
733
-     */
734
-    public function setAbortPref($abortPreference)
735
-    {
736
-        $this->abortpref = $abortPreference;
737
-    }
738
-
739
-    /**
740
-     * Gets the user's confirmation diff. Unused if OAuth is in use.
741
-     * @return int the diff ID
742
-     */
743
-    public function getConfirmationDiff()
744
-    {
745
-        return $this->confirmationdiff;
746
-    }
747
-
748
-    /**
749
-     * Sets the user's confirmation diff.
750
-     *
751
-     * @param int $confirmationDiff
752
-     */
753
-    public function setConfirmationDiff($confirmationDiff)
754
-    {
755
-        $this->confirmationdiff = $confirmationDiff;
756
-    }
757
-
758
-    /**
759
-     * Gets the users' email signature used on outbound mail.
760
-     * @todo rename me!
761
-     * @return string
762
-     */
763
-    public function getEmailSig()
764
-    {
765
-        return $this->emailsig;
766
-    }
767
-
768
-    /**
769
-     * Sets the user's email signature for outbound mail.
770
-     *
771
-     * @param string $emailSignature
772
-     */
773
-    public function setEmailSig($emailSignature)
774
-    {
775
-        $this->emailsig = $emailSignature;
776
-    }
777
-
778
-    /**
779
-     * Gets the user's OAuth request token.
780
-     *
781
-     * @todo move me to a collaborator.
782
-     * @return null|string
783
-     */
784
-    public function getOAuthRequestToken()
785
-    {
786
-        return $this->oauthrequesttoken;
787
-    }
788
-
789
-    /**
790
-     * Sets the user's OAuth request token
791
-     * @todo move me to a collaborator
792
-     *
793
-     * @param string $oAuthRequestToken
794
-     */
795
-    public function setOAuthRequestToken($oAuthRequestToken)
796
-    {
797
-        $this->oauthrequesttoken = $oAuthRequestToken;
798
-    }
799
-
800
-    /**
801
-     * Gets the users OAuth request secret
802
-     * @category Security-Critical
803
-     * @todo     move me to a collaborator
804
-     * @return null|string
805
-     */
806
-    public function getOAuthRequestSecret()
807
-    {
808
-        return $this->oauthrequestsecret;
809
-    }
810
-
811
-    /**
812
-     * Sets the user's OAuth request secret
813
-     * @todo move me to a collaborator
814
-     *
815
-     * @param string $oAuthRequestSecret
816
-     */
817
-    public function setOAuthRequestSecret($oAuthRequestSecret)
818
-    {
819
-        $this->oauthrequestsecret = $oAuthRequestSecret;
820
-    }
821
-
822
-    /**
823
-     * Gets the user's access token
824
-     * @category Security-Critical
825
-     * @todo     move me to a collaborator
826
-     * @return null|string
827
-     */
828
-    public function getOAuthAccessToken()
829
-    {
830
-        return $this->oauthaccesstoken;
831
-    }
832
-
833
-    /**
834
-     * Sets the user's access token
835
-     * @todo move me to a collaborator
836
-     *
837
-     * @param string $oAuthAccessToken
838
-     */
839
-    public function setOAuthAccessToken($oAuthAccessToken)
840
-    {
841
-        $this->oauthaccesstoken = $oAuthAccessToken;
842
-    }
843
-
844
-    /**
845
-     * Gets the user's OAuth access secret
846
-     * @category Security-Critical
847
-     * @todo     move me to a collaborator
848
-     * @return null|string
849
-     */
850
-    public function getOAuthAccessSecret()
851
-    {
852
-        return $this->oauthaccesssecret;
853
-    }
854
-
855
-    /**
856
-     * Sets the user's OAuth access secret
857
-     * @todo move me to a collaborator
858
-     *
859
-     * @param string $oAuthAccessSecret
860
-     */
861
-    public function setOAuthAccessSecret($oAuthAccessSecret)
862
-    {
863
-        $this->oauthaccesssecret = $oAuthAccessSecret;
864
-    }
865
-
866
-    #endregion
867
-
868
-    #region user access checks
869
-
870
-    /**
871
-     * Tests if the user is an admin
872
-     * @return bool
873
-     * @category Security-Critical
874
-     */
875
-    public function isAdmin()
876
-    {
877
-        return $this->status == self::STATUS_ADMIN;
878
-    }
879
-
880
-    /**
881
-     * Tests if the user is a checkuser
882
-     * @return bool
883
-     * @category Security-Critical
884
-     */
885
-    public function isCheckuser()
886
-    {
887
-        return $this->checkuser == 1 || $this->oauthCanCheckUser();
888
-    }
889
-
890
-    /**
891
-     * Tests if the user is identified
892
-     *
893
-     * @param IdentificationVerifier $iv
894
-     *
895
-     * @return bool
896
-     * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
897
-     *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
898
-     *       to play it safe for now.
899
-     * @category Security-Critical
900
-     */
901
-    public function isIdentified(IdentificationVerifier $iv)
902
-    {
903
-        if ($this->forceidentified === 0 || $this->forceidentified === "0") {
904
-            // User forced to unidentified in the database.
905
-            return false;
906
-        }
907
-        elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
908
-            // User forced to identified in the database.
909
-            return true;
910
-        }
911
-        else {
912
-            // User not forced to any particular identified status; consult IdentificationVerifier
913
-            return $iv->isUserIdentified($this->getOnWikiName());
914
-        }
915
-    }
916
-
917
-    /**
918
-     * Tests if the user is suspended
919
-     * @return bool
920
-     * @category Security-Critical
921
-     */
922
-    public function isSuspended()
923
-    {
924
-        return $this->status == self::STATUS_SUSPENDED;
925
-    }
926
-
927
-    /**
928
-     * Tests if the user is new
929
-     * @return bool
930
-     * @category Security-Critical
931
-     */
932
-    public function isNewUser()
933
-    {
934
-        return $this->status == self::STATUS_NEW;
935
-    }
936
-
937
-    /**
938
-     * Tests if the user is a standard-level user
939
-     * @return bool
940
-     * @category Security-Critical
941
-     */
942
-    public function isUser()
943
-    {
944
-        return $this->status == self::STATUS_USER;
945
-    }
946
-
947
-    /**
948
-     * Tests if the user has been declined access to the tool
949
-     * @return bool
950
-     * @category Security-Critical
951
-     */
952
-    public function isDeclined()
953
-    {
954
-        return $this->status == self::STATUS_DECLINED;
955
-    }
956
-
957
-    /**
958
-     * Tests if the user is the community user
959
-     *
960
-     * @todo     decide if this means logged out. I think it usually does.
961
-     * @return bool
962
-     * @category Security-Critical
963
-     */
964
-    public function isCommunityUser()
965
-    {
966
-        return false;
967
-    }
968
-
969
-    #endregion 
970
-
971
-    #region OAuth
972
-
973
-    /**
974
-     * @todo     move me to a collaborator
975
-     *
976
-     * @param bool $useCached
977
-     *
978
-     * @return mixed|null
979
-     * @category Security-Critical
980
-     */
981
-    public function getOAuthIdentity($useCached = false)
982
-    {
983
-        if ($this->oauthaccesstoken === null) {
984
-            $this->clearOAuthData();
985
-        }
986
-
987
-        global $oauthConsumerToken, $oauthMediaWikiCanonicalServer;
988
-
989
-        if ($this->oauthidentitycache == null) {
990
-            $this->identityCache = null;
991
-        }
992
-        else {
993
-            $this->identityCache = unserialize($this->oauthidentitycache);
994
-        }
995
-
996
-        // check the cache
997
-        if (
998
-            $this->identityCache != null &&
999
-            $this->identityCache->aud == $oauthConsumerToken &&
1000
-            $this->identityCache->iss == $oauthMediaWikiCanonicalServer
1001
-        ) {
1002
-            if (
1003
-                $useCached || (
1004
-                    DateTime::createFromFormat("U", $this->identityCache->iat) < new DateTime() &&
1005
-                    DateTime::createFromFormat("U", $this->identityCache->exp) > new DateTime()
1006
-                )
1007
-            ) {
1008
-                // Use cached value - it's either valid or we don't care.
1009
-                return $this->identityCache;
1010
-            }
1011
-            else {
1012
-                // Cache expired and not forcing use of cached value
1013
-                $this->getIdentityCache();
1014
-
1015
-                return $this->identityCache;
1016
-            }
1017
-        }
1018
-        else {
1019
-            // Cache isn't ours or doesn't exist
1020
-            $this->getIdentityCache();
1021
-
1022
-            return $this->identityCache;
1023
-        }
1024
-    }
1025
-
1026
-    /**
1027
-     * @todo     move me to a collaborator
1028
-     *
1029
-     * @param mixed $useCached Set to false for everything where up-to-date data is important.
1030
-     *
1031
-     * @return mixed
1032
-     * @category Security-Critical
1033
-     */
1034
-    private function getOAuthOnWikiName($useCached = false)
1035
-    {
1036
-        $identity = $this->getOAuthIdentity($useCached);
1037
-        if ($identity !== null) {
1038
-            return $identity->username;
1039
-        }
1040
-
1041
-        return false;
1042
-    }
1043
-
1044
-    /**
1045
-     * @return bool
1046
-     * @todo move me to a collaborator
1047
-     */
1048
-    public function isOAuthLinked()
1049
-    {
1050
-        if ($this->onwikiname === "##OAUTH##") {
1051
-            return true; // special value. If an account must be oauth linked, this is true.
1052
-        }
1053
-
1054
-        return $this->oauthaccesstoken !== null;
1055
-    }
1056
-
1057
-    /**
1058
-     * @return null
1059
-     * @todo move me to a collaborator
1060
-     */
1061
-    public function clearOAuthData()
1062
-    {
1063
-        $this->identityCache = null;
1064
-        $this->oauthidentitycache = null;
1065
-        $clearCacheQuery = "UPDATE user SET oauthidentitycache = NULL WHERE id = :id;";
1066
-        $this->dbObject->prepare($clearCacheQuery)->execute(array(":id" => $this->id));
1067
-
1068
-        return null;
1069
-    }
1070
-
1071
-    /**
1072
-     * @throws Exception
1073
-     * @todo     move me to a collaborator
1074
-     * @category Security-Critical
1075
-     */
1076
-    private function getIdentityCache()
1077
-    {
1078
-        /** @var IOAuthHelper $oauthHelper */
1079
-        global $oauthHelper;
1080
-
1081
-        try {
1082
-            $this->identityCache = $oauthHelper->getIdentityTicket($this->oauthaccesstoken, $this->oauthaccesssecret);
1083
-
1084
-            $this->oauthidentitycache = serialize($this->identityCache);
1085
-            $this->dbObject->prepare("UPDATE user SET oauthidentitycache = :identity WHERE id = :id;")
1086
-                ->execute(array(":id" => $this->id, ":identity" => $this->oauthidentitycache));
1087
-        }
1088
-        catch (UnexpectedValueException $ex) {
1089
-            $this->identityCache = null;
1090
-            $this->oauthidentitycache = null;
1091
-            $this->dbObject->prepare("UPDATE user SET oauthidentitycache = NULL WHERE id = :id;")
1092
-                ->execute(array(":id" => $this->id));
1093
-
1094
-            SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage());
1095
-        }
1096
-    }
1097
-
1098
-    /**
1099
-     * @return bool
1100
-     * @todo move me to a collaborator
1101
-     */
1102
-    public function oauthCanUse()
1103
-    {
1104
-        try {
1105
-            return in_array('useoauth', $this->getOAuthIdentity()->grants);
1106
-        }
1107
-        catch (Exception $ex) {
1108
-            return false;
1109
-        }
1110
-    }
1111
-
1112
-    /**
1113
-     * @return bool
1114
-     * @todo move me to a collaborator
1115
-     */
1116
-    public function oauthCanEdit()
1117
-    {
1118
-        try {
1119
-            return in_array('useoauth', $this->getOAuthIdentity()->grants)
1120
-            && in_array('createeditmovepage', $this->getOAuthIdentity()->grants)
1121
-            && in_array('createtalk', $this->getOAuthIdentity()->rights)
1122
-            && in_array('edit', $this->getOAuthIdentity()->rights)
1123
-            && in_array('writeapi', $this->getOAuthIdentity()->rights);
1124
-        }
1125
-        catch (Exception $ex) {
1126
-            return false;
1127
-        }
1128
-    }
1129
-
1130
-    /**
1131
-     * @return bool
1132
-     * @todo move me to a collaborator
1133
-     */
1134
-    public function oauthCanCreateAccount()
1135
-    {
1136
-        try {
1137
-            return in_array('useoauth', $this->getOAuthIdentity()->grants)
1138
-            && in_array('createaccount', $this->getOAuthIdentity()->grants)
1139
-            && in_array('createaccount', $this->getOAuthIdentity()->rights)
1140
-            && in_array('writeapi', $this->getOAuthIdentity()->rights);
1141
-        }
1142
-        catch (Exception $ex) {
1143
-            return false;
1144
-        }
1145
-    }
1146
-
1147
-    /**
1148
-     * @return bool
1149
-     * @todo     move me to a collaborator
1150
-     * @category Security-Critical
1151
-     */
1152
-    protected function oauthCanCheckUser()
1153
-    {
1154
-        if (!$this->isOAuthLinked()) {
1155
-            return false;
1156
-        }
1157
-
1158
-        try {
1159
-            $identity = $this->getOAuthIdentity();
1160
-
1161
-            return in_array('checkuser', $identity->rights);
1162
-        }
1163
-        catch (Exception $ex) {
1164
-            return false;
1165
-        }
1166
-    }
1167
-
1168
-    #endregion
1169
-
1170
-    /**
1171
-     * Gets a hash of data for the user to reset their password with.
1172
-     * @category Security-Critical
1173
-     * @return string
1174
-     */
1175
-    public function getForgottenPasswordHash()
1176
-    {
1177
-        return md5($this->username . $this->email . $this->welcome_template . $this->id . $this->password);
1178
-    }
1179
-
1180
-    /**
1181
-     * Gets the approval date of the user
1182
-     * @return DateTime|false
1183
-     */
1184
-    public function getApprovalDate()
1185
-    {
1186
-        $query = $this->dbObject->prepare(<<<SQL
472
+			);
473
+			$statement->bindValue(":forceidentified", $this->forceidentified);
474
+
475
+			$statement->bindValue(':id', $this->id);
476
+			$statement->bindValue(':updateversion', $this->updateversion);
477
+
478
+			$statement->bindValue(':username', $this->username);
479
+			$statement->bindValue(':email', $this->email);
480
+			$statement->bindValue(':password', $this->password);
481
+			$statement->bindValue(':status', $this->status);
482
+			$statement->bindValue(':onwikiname', $this->onwikiname);
483
+			$statement->bindValue(':welcome_sig', $this->welcome_sig);
484
+			$statement->bindValue(':lastactive', $this->lastactive);
485
+			$statement->bindValue(':forcelogout', $this->forcelogout);
486
+			$statement->bindValue(':checkuser', $this->checkuser);
487
+			$statement->bindValue(':forceidentified', $this->forceidentified);
488
+			$statement->bindValue(':welcome_template', $this->welcome_template);
489
+			$statement->bindValue(':abortpref', $this->abortpref);
490
+			$statement->bindValue(':confirmationdiff', $this->confirmationdiff);
491
+			$statement->bindValue(':emailsig', $this->emailsig);
492
+			$statement->bindValue(':ort', $this->oauthrequesttoken);
493
+			$statement->bindValue(':ors', $this->oauthrequestsecret);
494
+			$statement->bindValue(':oat', $this->oauthaccesstoken);
495
+			$statement->bindValue(':oas', $this->oauthaccesssecret);
496
+
497
+			if (!$statement->execute()) {
498
+				throw new Exception($statement->errorInfo());
499
+			}
500
+
501
+			if ($statement->rowCount() !== 1) {
502
+				throw new OptimisticLockFailedException();
503
+			}
504
+
505
+			$this->updateversion++;
506
+		}
507
+	}
508
+
509
+	/**
510
+	 * Authenticates the user with the supplied password
511
+	 *
512
+	 * @param string $password
513
+	 *
514
+	 * @return bool
515
+	 * @throws Exception
516
+	 * @category Security-Critical
517
+	 */
518
+	public function authenticate($password)
519
+	{
520
+		$result = AuthUtility::testCredentials($password, $this->password);
521
+
522
+		if ($result === true) {
523
+			// password version is out of date, update it.
524
+			if (!AuthUtility::isCredentialVersionLatest($this->password)) {
525
+				$this->password = AuthUtility::encryptPassword($password);
526
+				$this->save();
527
+			}
528
+		}
529
+
530
+		return $result;
531
+	}
532
+
533
+	#region properties
534
+
535
+	/**
536
+	 * Gets the tool username
537
+	 * @return string
538
+	 */
539
+	public function getUsername()
540
+	{
541
+		return $this->username;
542
+	}
543
+
544
+	/**
545
+	 * Sets the tool username
546
+	 *
547
+	 * @param string $username
548
+	 */
549
+	public function setUsername($username)
550
+	{
551
+		$this->username = $username;
552
+
553
+		// If this isn't a brand new user, then it's a rename, force the logout
554
+		if (!$this->isNew()) {
555
+			$this->forcelogout = 1;
556
+		}
557
+	}
558
+
559
+	/**
560
+	 * Gets the user's email address
561
+	 * @return string
562
+	 */
563
+	public function getEmail()
564
+	{
565
+		return $this->email;
566
+	}
567
+
568
+	/**
569
+	 * Sets the user's email address
570
+	 *
571
+	 * @param string $email
572
+	 */
573
+	public function setEmail($email)
574
+	{
575
+		$this->email = $email;
576
+	}
577
+
578
+	/**
579
+	 * Sets the user's password
580
+	 *
581
+	 * @param string $password the plaintext password
582
+	 *
583
+	 * @category Security-Critical
584
+	 */
585
+	public function setPassword($password)
586
+	{
587
+		$this->password = AuthUtility::encryptPassword($password);
588
+	}
589
+
590
+	/**
591
+	 * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
592
+	 * @return string
593
+	 */
594
+	public function getStatus()
595
+	{
596
+		return $this->status;
597
+	}
598
+
599
+	/**
600
+	 * @param string $status
601
+	 */
602
+	public function setStatus($status)
603
+	{
604
+		$this->status = $status;
605
+	}
606
+
607
+	/**
608
+	 * Gets the user's on-wiki name
609
+	 * @return string
610
+	 */
611
+	public function getOnWikiName()
612
+	{
613
+		if ($this->oauthaccesstoken !== null) {
614
+			try {
615
+				return $this->getOAuthOnWikiName();
616
+			}
617
+			catch (Exception $ex) {
618
+				// urm.. log this?
619
+				return $this->onwikiname;
620
+			}
621
+		}
622
+
623
+		return $this->onwikiname;
624
+	}
625
+
626
+	/**
627
+	 * This is probably NOT the function you want!
628
+	 *
629
+	 * Take a look at getOnWikiName() instead.
630
+	 * @return string
631
+	 */
632
+	public function getStoredOnWikiName()
633
+	{
634
+		return $this->onwikiname;
635
+	}
636
+
637
+	/**
638
+	 * Sets the user's on-wiki name
639
+	 *
640
+	 * This can have interesting side-effects with OAuth.
641
+	 *
642
+	 * @param string $onWikiName
643
+	 */
644
+	public function setOnWikiName($onWikiName)
645
+	{
646
+		$this->onwikiname = $onWikiName;
647
+	}
648
+
649
+	/**
650
+	 * Gets the welcome signature
651
+	 * @return string
652
+	 */
653
+	public function getWelcomeSig()
654
+	{
655
+		return $this->welcome_sig;
656
+	}
657
+
658
+	/**
659
+	 * Sets the welcome signature
660
+	 *
661
+	 * @param string $welcomeSig
662
+	 */
663
+	public function setWelcomeSig($welcomeSig)
664
+	{
665
+		$this->welcome_sig = $welcomeSig;
666
+	}
667
+
668
+	/**
669
+	 * Gets the last activity date for the user
670
+	 *
671
+	 * @return string
672
+	 * @todo This should probably return an instance of DateTime
673
+	 */
674
+	public function getLastActive()
675
+	{
676
+		return $this->lastactive;
677
+	}
678
+
679
+	/**
680
+	 * Gets the user's forced logout status
681
+	 *
682
+	 * @return bool
683
+	 */
684
+	public function getForceLogout()
685
+	{
686
+		return $this->forcelogout == 1;
687
+	}
688
+
689
+	/**
690
+	 * Sets the user's forced logout status
691
+	 *
692
+	 * @param bool $forceLogout
693
+	 */
694
+	public function setForceLogout($forceLogout)
695
+	{
696
+		$this->forcelogout = $forceLogout ? 1 : 0;
697
+	}
698
+
699
+	/**
700
+	 * Returns the ID of the welcome template used.
701
+	 * @return int
702
+	 */
703
+	public function getWelcomeTemplate()
704
+	{
705
+		return $this->welcome_template;
706
+	}
707
+
708
+	/**
709
+	 * Sets the ID of the welcome template used.
710
+	 *
711
+	 * @param int $welcomeTemplate
712
+	 */
713
+	public function setWelcomeTemplate($welcomeTemplate)
714
+	{
715
+		$this->welcome_template = $welcomeTemplate;
716
+	}
717
+
718
+	/**
719
+	 * Gets the user's abort preference
720
+	 * @todo this is badly named too! Also a bool that's actually an int.
721
+	 * @return int
722
+	 */
723
+	public function getAbortPref()
724
+	{
725
+		return $this->abortpref;
726
+	}
727
+
728
+	/**
729
+	 * Sets the user's abort preference
730
+	 * @todo rename, retype, and re-comment.
731
+	 *
732
+	 * @param int $abortPreference
733
+	 */
734
+	public function setAbortPref($abortPreference)
735
+	{
736
+		$this->abortpref = $abortPreference;
737
+	}
738
+
739
+	/**
740
+	 * Gets the user's confirmation diff. Unused if OAuth is in use.
741
+	 * @return int the diff ID
742
+	 */
743
+	public function getConfirmationDiff()
744
+	{
745
+		return $this->confirmationdiff;
746
+	}
747
+
748
+	/**
749
+	 * Sets the user's confirmation diff.
750
+	 *
751
+	 * @param int $confirmationDiff
752
+	 */
753
+	public function setConfirmationDiff($confirmationDiff)
754
+	{
755
+		$this->confirmationdiff = $confirmationDiff;
756
+	}
757
+
758
+	/**
759
+	 * Gets the users' email signature used on outbound mail.
760
+	 * @todo rename me!
761
+	 * @return string
762
+	 */
763
+	public function getEmailSig()
764
+	{
765
+		return $this->emailsig;
766
+	}
767
+
768
+	/**
769
+	 * Sets the user's email signature for outbound mail.
770
+	 *
771
+	 * @param string $emailSignature
772
+	 */
773
+	public function setEmailSig($emailSignature)
774
+	{
775
+		$this->emailsig = $emailSignature;
776
+	}
777
+
778
+	/**
779
+	 * Gets the user's OAuth request token.
780
+	 *
781
+	 * @todo move me to a collaborator.
782
+	 * @return null|string
783
+	 */
784
+	public function getOAuthRequestToken()
785
+	{
786
+		return $this->oauthrequesttoken;
787
+	}
788
+
789
+	/**
790
+	 * Sets the user's OAuth request token
791
+	 * @todo move me to a collaborator
792
+	 *
793
+	 * @param string $oAuthRequestToken
794
+	 */
795
+	public function setOAuthRequestToken($oAuthRequestToken)
796
+	{
797
+		$this->oauthrequesttoken = $oAuthRequestToken;
798
+	}
799
+
800
+	/**
801
+	 * Gets the users OAuth request secret
802
+	 * @category Security-Critical
803
+	 * @todo     move me to a collaborator
804
+	 * @return null|string
805
+	 */
806
+	public function getOAuthRequestSecret()
807
+	{
808
+		return $this->oauthrequestsecret;
809
+	}
810
+
811
+	/**
812
+	 * Sets the user's OAuth request secret
813
+	 * @todo move me to a collaborator
814
+	 *
815
+	 * @param string $oAuthRequestSecret
816
+	 */
817
+	public function setOAuthRequestSecret($oAuthRequestSecret)
818
+	{
819
+		$this->oauthrequestsecret = $oAuthRequestSecret;
820
+	}
821
+
822
+	/**
823
+	 * Gets the user's access token
824
+	 * @category Security-Critical
825
+	 * @todo     move me to a collaborator
826
+	 * @return null|string
827
+	 */
828
+	public function getOAuthAccessToken()
829
+	{
830
+		return $this->oauthaccesstoken;
831
+	}
832
+
833
+	/**
834
+	 * Sets the user's access token
835
+	 * @todo move me to a collaborator
836
+	 *
837
+	 * @param string $oAuthAccessToken
838
+	 */
839
+	public function setOAuthAccessToken($oAuthAccessToken)
840
+	{
841
+		$this->oauthaccesstoken = $oAuthAccessToken;
842
+	}
843
+
844
+	/**
845
+	 * Gets the user's OAuth access secret
846
+	 * @category Security-Critical
847
+	 * @todo     move me to a collaborator
848
+	 * @return null|string
849
+	 */
850
+	public function getOAuthAccessSecret()
851
+	{
852
+		return $this->oauthaccesssecret;
853
+	}
854
+
855
+	/**
856
+	 * Sets the user's OAuth access secret
857
+	 * @todo move me to a collaborator
858
+	 *
859
+	 * @param string $oAuthAccessSecret
860
+	 */
861
+	public function setOAuthAccessSecret($oAuthAccessSecret)
862
+	{
863
+		$this->oauthaccesssecret = $oAuthAccessSecret;
864
+	}
865
+
866
+	#endregion
867
+
868
+	#region user access checks
869
+
870
+	/**
871
+	 * Tests if the user is an admin
872
+	 * @return bool
873
+	 * @category Security-Critical
874
+	 */
875
+	public function isAdmin()
876
+	{
877
+		return $this->status == self::STATUS_ADMIN;
878
+	}
879
+
880
+	/**
881
+	 * Tests if the user is a checkuser
882
+	 * @return bool
883
+	 * @category Security-Critical
884
+	 */
885
+	public function isCheckuser()
886
+	{
887
+		return $this->checkuser == 1 || $this->oauthCanCheckUser();
888
+	}
889
+
890
+	/**
891
+	 * Tests if the user is identified
892
+	 *
893
+	 * @param IdentificationVerifier $iv
894
+	 *
895
+	 * @return bool
896
+	 * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
897
+	 *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
898
+	 *       to play it safe for now.
899
+	 * @category Security-Critical
900
+	 */
901
+	public function isIdentified(IdentificationVerifier $iv)
902
+	{
903
+		if ($this->forceidentified === 0 || $this->forceidentified === "0") {
904
+			// User forced to unidentified in the database.
905
+			return false;
906
+		}
907
+		elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
908
+			// User forced to identified in the database.
909
+			return true;
910
+		}
911
+		else {
912
+			// User not forced to any particular identified status; consult IdentificationVerifier
913
+			return $iv->isUserIdentified($this->getOnWikiName());
914
+		}
915
+	}
916
+
917
+	/**
918
+	 * Tests if the user is suspended
919
+	 * @return bool
920
+	 * @category Security-Critical
921
+	 */
922
+	public function isSuspended()
923
+	{
924
+		return $this->status == self::STATUS_SUSPENDED;
925
+	}
926
+
927
+	/**
928
+	 * Tests if the user is new
929
+	 * @return bool
930
+	 * @category Security-Critical
931
+	 */
932
+	public function isNewUser()
933
+	{
934
+		return $this->status == self::STATUS_NEW;
935
+	}
936
+
937
+	/**
938
+	 * Tests if the user is a standard-level user
939
+	 * @return bool
940
+	 * @category Security-Critical
941
+	 */
942
+	public function isUser()
943
+	{
944
+		return $this->status == self::STATUS_USER;
945
+	}
946
+
947
+	/**
948
+	 * Tests if the user has been declined access to the tool
949
+	 * @return bool
950
+	 * @category Security-Critical
951
+	 */
952
+	public function isDeclined()
953
+	{
954
+		return $this->status == self::STATUS_DECLINED;
955
+	}
956
+
957
+	/**
958
+	 * Tests if the user is the community user
959
+	 *
960
+	 * @todo     decide if this means logged out. I think it usually does.
961
+	 * @return bool
962
+	 * @category Security-Critical
963
+	 */
964
+	public function isCommunityUser()
965
+	{
966
+		return false;
967
+	}
968
+
969
+	#endregion 
970
+
971
+	#region OAuth
972
+
973
+	/**
974
+	 * @todo     move me to a collaborator
975
+	 *
976
+	 * @param bool $useCached
977
+	 *
978
+	 * @return mixed|null
979
+	 * @category Security-Critical
980
+	 */
981
+	public function getOAuthIdentity($useCached = false)
982
+	{
983
+		if ($this->oauthaccesstoken === null) {
984
+			$this->clearOAuthData();
985
+		}
986
+
987
+		global $oauthConsumerToken, $oauthMediaWikiCanonicalServer;
988
+
989
+		if ($this->oauthidentitycache == null) {
990
+			$this->identityCache = null;
991
+		}
992
+		else {
993
+			$this->identityCache = unserialize($this->oauthidentitycache);
994
+		}
995
+
996
+		// check the cache
997
+		if (
998
+			$this->identityCache != null &&
999
+			$this->identityCache->aud == $oauthConsumerToken &&
1000
+			$this->identityCache->iss == $oauthMediaWikiCanonicalServer
1001
+		) {
1002
+			if (
1003
+				$useCached || (
1004
+					DateTime::createFromFormat("U", $this->identityCache->iat) < new DateTime() &&
1005
+					DateTime::createFromFormat("U", $this->identityCache->exp) > new DateTime()
1006
+				)
1007
+			) {
1008
+				// Use cached value - it's either valid or we don't care.
1009
+				return $this->identityCache;
1010
+			}
1011
+			else {
1012
+				// Cache expired and not forcing use of cached value
1013
+				$this->getIdentityCache();
1014
+
1015
+				return $this->identityCache;
1016
+			}
1017
+		}
1018
+		else {
1019
+			// Cache isn't ours or doesn't exist
1020
+			$this->getIdentityCache();
1021
+
1022
+			return $this->identityCache;
1023
+		}
1024
+	}
1025
+
1026
+	/**
1027
+	 * @todo     move me to a collaborator
1028
+	 *
1029
+	 * @param mixed $useCached Set to false for everything where up-to-date data is important.
1030
+	 *
1031
+	 * @return mixed
1032
+	 * @category Security-Critical
1033
+	 */
1034
+	private function getOAuthOnWikiName($useCached = false)
1035
+	{
1036
+		$identity = $this->getOAuthIdentity($useCached);
1037
+		if ($identity !== null) {
1038
+			return $identity->username;
1039
+		}
1040
+
1041
+		return false;
1042
+	}
1043
+
1044
+	/**
1045
+	 * @return bool
1046
+	 * @todo move me to a collaborator
1047
+	 */
1048
+	public function isOAuthLinked()
1049
+	{
1050
+		if ($this->onwikiname === "##OAUTH##") {
1051
+			return true; // special value. If an account must be oauth linked, this is true.
1052
+		}
1053
+
1054
+		return $this->oauthaccesstoken !== null;
1055
+	}
1056
+
1057
+	/**
1058
+	 * @return null
1059
+	 * @todo move me to a collaborator
1060
+	 */
1061
+	public function clearOAuthData()
1062
+	{
1063
+		$this->identityCache = null;
1064
+		$this->oauthidentitycache = null;
1065
+		$clearCacheQuery = "UPDATE user SET oauthidentitycache = NULL WHERE id = :id;";
1066
+		$this->dbObject->prepare($clearCacheQuery)->execute(array(":id" => $this->id));
1067
+
1068
+		return null;
1069
+	}
1070
+
1071
+	/**
1072
+	 * @throws Exception
1073
+	 * @todo     move me to a collaborator
1074
+	 * @category Security-Critical
1075
+	 */
1076
+	private function getIdentityCache()
1077
+	{
1078
+		/** @var IOAuthHelper $oauthHelper */
1079
+		global $oauthHelper;
1080
+
1081
+		try {
1082
+			$this->identityCache = $oauthHelper->getIdentityTicket($this->oauthaccesstoken, $this->oauthaccesssecret);
1083
+
1084
+			$this->oauthidentitycache = serialize($this->identityCache);
1085
+			$this->dbObject->prepare("UPDATE user SET oauthidentitycache = :identity WHERE id = :id;")
1086
+				->execute(array(":id" => $this->id, ":identity" => $this->oauthidentitycache));
1087
+		}
1088
+		catch (UnexpectedValueException $ex) {
1089
+			$this->identityCache = null;
1090
+			$this->oauthidentitycache = null;
1091
+			$this->dbObject->prepare("UPDATE user SET oauthidentitycache = NULL WHERE id = :id;")
1092
+				->execute(array(":id" => $this->id));
1093
+
1094
+			SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage());
1095
+		}
1096
+	}
1097
+
1098
+	/**
1099
+	 * @return bool
1100
+	 * @todo move me to a collaborator
1101
+	 */
1102
+	public function oauthCanUse()
1103
+	{
1104
+		try {
1105
+			return in_array('useoauth', $this->getOAuthIdentity()->grants);
1106
+		}
1107
+		catch (Exception $ex) {
1108
+			return false;
1109
+		}
1110
+	}
1111
+
1112
+	/**
1113
+	 * @return bool
1114
+	 * @todo move me to a collaborator
1115
+	 */
1116
+	public function oauthCanEdit()
1117
+	{
1118
+		try {
1119
+			return in_array('useoauth', $this->getOAuthIdentity()->grants)
1120
+			&& in_array('createeditmovepage', $this->getOAuthIdentity()->grants)
1121
+			&& in_array('createtalk', $this->getOAuthIdentity()->rights)
1122
+			&& in_array('edit', $this->getOAuthIdentity()->rights)
1123
+			&& in_array('writeapi', $this->getOAuthIdentity()->rights);
1124
+		}
1125
+		catch (Exception $ex) {
1126
+			return false;
1127
+		}
1128
+	}
1129
+
1130
+	/**
1131
+	 * @return bool
1132
+	 * @todo move me to a collaborator
1133
+	 */
1134
+	public function oauthCanCreateAccount()
1135
+	{
1136
+		try {
1137
+			return in_array('useoauth', $this->getOAuthIdentity()->grants)
1138
+			&& in_array('createaccount', $this->getOAuthIdentity()->grants)
1139
+			&& in_array('createaccount', $this->getOAuthIdentity()->rights)
1140
+			&& in_array('writeapi', $this->getOAuthIdentity()->rights);
1141
+		}
1142
+		catch (Exception $ex) {
1143
+			return false;
1144
+		}
1145
+	}
1146
+
1147
+	/**
1148
+	 * @return bool
1149
+	 * @todo     move me to a collaborator
1150
+	 * @category Security-Critical
1151
+	 */
1152
+	protected function oauthCanCheckUser()
1153
+	{
1154
+		if (!$this->isOAuthLinked()) {
1155
+			return false;
1156
+		}
1157
+
1158
+		try {
1159
+			$identity = $this->getOAuthIdentity();
1160
+
1161
+			return in_array('checkuser', $identity->rights);
1162
+		}
1163
+		catch (Exception $ex) {
1164
+			return false;
1165
+		}
1166
+	}
1167
+
1168
+	#endregion
1169
+
1170
+	/**
1171
+	 * Gets a hash of data for the user to reset their password with.
1172
+	 * @category Security-Critical
1173
+	 * @return string
1174
+	 */
1175
+	public function getForgottenPasswordHash()
1176
+	{
1177
+		return md5($this->username . $this->email . $this->welcome_template . $this->id . $this->password);
1178
+	}
1179
+
1180
+	/**
1181
+	 * Gets the approval date of the user
1182
+	 * @return DateTime|false
1183
+	 */
1184
+	public function getApprovalDate()
1185
+	{
1186
+		$query = $this->dbObject->prepare(<<<SQL
1187 1187
 			SELECT timestamp 
1188 1188
 			FROM log 
1189 1189
 			WHERE objectid = :userid
@@ -1192,12 +1192,12 @@  discard block
 block discarded – undo
1192 1192
 			ORDER BY id DESC 
1193 1193
 			LIMIT 1;
1194 1194
 SQL
1195
-        );
1196
-        $query->execute(array(":userid" => $this->id));
1195
+		);
1196
+		$query->execute(array(":userid" => $this->id));
1197 1197
 
1198
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
1199
-        $query->closeCursor();
1198
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
1199
+		$query->closeCursor();
1200 1200
 
1201
-        return $data;
1202
-    }
1201
+		return $data;
1202
+	}
1203 1203
 }
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.