Passed
Push — dependabot/composer/newinterna... ( 13eb18 )
by
unknown
04:37
created
includes/DataObjects/Comment.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -20,172 +20,172 @@
 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
-     * Retrieves all comments for a request, optionally filtered
31
-     *
32
-     * @param integer     $id      Request ID to search by
33
-     * @param PdoDatabase $database
34
-     * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
-     *                             comments visible to $userId
36
-     * @param null|int    $userId  User to filter by
37
-     *
38
-     * @return Comment[]
39
-     */
40
-    public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
-    {
42
-        if ($showAll) {
43
-            $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
-        }
45
-        else {
46
-            $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+
29
+	/**
30
+	 * Retrieves all comments for a request, optionally filtered
31
+	 *
32
+	 * @param integer     $id      Request ID to search by
33
+	 * @param PdoDatabase $database
34
+	 * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
+	 *                             comments visible to $userId
36
+	 * @param null|int    $userId  User to filter by
37
+	 *
38
+	 * @return Comment[]
39
+	 */
40
+	public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
+	{
42
+		if ($showAll) {
43
+			$statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
+		}
45
+		else {
46
+			$statement = $database->prepare(<<<SQL
47 47
 SELECT * FROM comment
48 48
 WHERE request = :target AND (visibility = 'user' OR user = :userid);
49 49
 SQL
50
-            );
51
-            $statement->bindValue(':userid', $userId);
52
-        }
53
-
54
-        $statement->bindValue(':target', $id);
55
-
56
-        $statement->execute();
57
-
58
-        $result = array();
59
-        /** @var Comment $v */
60
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
-            $v->setDatabase($database);
62
-            $result[] = $v;
63
-        }
64
-
65
-        return $result;
66
-    }
67
-
68
-    /**
69
-     * @throws Exception
70
-     */
71
-    public function save()
72
-    {
73
-        if ($this->isNew()) {
74
-            // insert
75
-            $statement = $this->dbObject->prepare(<<<SQL
50
+			);
51
+			$statement->bindValue(':userid', $userId);
52
+		}
53
+
54
+		$statement->bindValue(':target', $id);
55
+
56
+		$statement->execute();
57
+
58
+		$result = array();
59
+		/** @var Comment $v */
60
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
+			$v->setDatabase($database);
62
+			$result[] = $v;
63
+		}
64
+
65
+		return $result;
66
+	}
67
+
68
+	/**
69
+	 * @throws Exception
70
+	 */
71
+	public function save()
72
+	{
73
+		if ($this->isNew()) {
74
+			// insert
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 INSERT INTO comment ( time, user, comment, visibility, request )
77 77
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request );
78 78
 SQL
79
-            );
80
-            $statement->bindValue(":user", $this->user);
81
-            $statement->bindValue(":comment", $this->comment);
82
-            $statement->bindValue(":visibility", $this->visibility);
83
-            $statement->bindValue(":request", $this->request);
84
-
85
-            if ($statement->execute()) {
86
-                $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-        }
92
-        else {
93
-            // update
94
-            $statement = $this->dbObject->prepare(<<<SQL
79
+			);
80
+			$statement->bindValue(":user", $this->user);
81
+			$statement->bindValue(":comment", $this->comment);
82
+			$statement->bindValue(":visibility", $this->visibility);
83
+			$statement->bindValue(":request", $this->request);
84
+
85
+			if ($statement->execute()) {
86
+				$this->id = (int)$this->dbObject->lastInsertId();
87
+			}
88
+			else {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+		}
92
+		else {
93
+			// update
94
+			$statement = $this->dbObject->prepare(<<<SQL
95 95
 UPDATE comment
96 96
 SET comment = :comment, visibility = :visibility, updateversion = updateversion + 1
97 97
 WHERE id = :id AND updateversion = :updateversion
98 98
 LIMIT 1;
99 99
 SQL
100
-            );
101
-
102
-            $statement->bindValue(':id', $this->id);
103
-            $statement->bindValue(':updateversion', $this->updateversion);
104
-
105
-            $statement->bindValue(':comment', $this->comment);
106
-            $statement->bindValue(':visibility', $this->visibility);
107
-
108
-            if (!$statement->execute()) {
109
-                throw new Exception($statement->errorInfo());
110
-            }
111
-
112
-            if ($statement->rowCount() !== 1) {
113
-                throw new OptimisticLockFailedException();
114
-            }
115
-
116
-            $this->updateversion++;
117
-        }
118
-    }
119
-
120
-    /**
121
-     * @return DateTimeImmutable
122
-     */
123
-    public function getTime()
124
-    {
125
-        return new DateTimeImmutable($this->time);
126
-    }
127
-
128
-    /**
129
-     * @return int
130
-     */
131
-    public function getUser()
132
-    {
133
-        return $this->user;
134
-    }
135
-
136
-    /**
137
-     * @param int $user
138
-     */
139
-    public function setUser($user)
140
-    {
141
-        $this->user = $user;
142
-    }
143
-
144
-    /**
145
-     * @return string
146
-     */
147
-    public function getComment()
148
-    {
149
-        return $this->comment;
150
-    }
151
-
152
-    /**
153
-     * @param string $comment
154
-     */
155
-    public function setComment($comment)
156
-    {
157
-        $this->comment = $comment;
158
-    }
159
-
160
-    /**
161
-     * @return string
162
-     */
163
-    public function getVisibility()
164
-    {
165
-        return $this->visibility;
166
-    }
167
-
168
-    /**
169
-     * @param string $visibility
170
-     */
171
-    public function setVisibility($visibility)
172
-    {
173
-        $this->visibility = $visibility;
174
-    }
175
-
176
-    /**
177
-     * @return int
178
-     */
179
-    public function getRequest()
180
-    {
181
-        return $this->request;
182
-    }
183
-
184
-    /**
185
-     * @param int $request
186
-     */
187
-    public function setRequest($request)
188
-    {
189
-        $this->request = $request;
190
-    }
100
+			);
101
+
102
+			$statement->bindValue(':id', $this->id);
103
+			$statement->bindValue(':updateversion', $this->updateversion);
104
+
105
+			$statement->bindValue(':comment', $this->comment);
106
+			$statement->bindValue(':visibility', $this->visibility);
107
+
108
+			if (!$statement->execute()) {
109
+				throw new Exception($statement->errorInfo());
110
+			}
111
+
112
+			if ($statement->rowCount() !== 1) {
113
+				throw new OptimisticLockFailedException();
114
+			}
115
+
116
+			$this->updateversion++;
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * @return DateTimeImmutable
122
+	 */
123
+	public function getTime()
124
+	{
125
+		return new DateTimeImmutable($this->time);
126
+	}
127
+
128
+	/**
129
+	 * @return int
130
+	 */
131
+	public function getUser()
132
+	{
133
+		return $this->user;
134
+	}
135
+
136
+	/**
137
+	 * @param int $user
138
+	 */
139
+	public function setUser($user)
140
+	{
141
+		$this->user = $user;
142
+	}
143
+
144
+	/**
145
+	 * @return string
146
+	 */
147
+	public function getComment()
148
+	{
149
+		return $this->comment;
150
+	}
151
+
152
+	/**
153
+	 * @param string $comment
154
+	 */
155
+	public function setComment($comment)
156
+	{
157
+		$this->comment = $comment;
158
+	}
159
+
160
+	/**
161
+	 * @return string
162
+	 */
163
+	public function getVisibility()
164
+	{
165
+		return $this->visibility;
166
+	}
167
+
168
+	/**
169
+	 * @param string $visibility
170
+	 */
171
+	public function setVisibility($visibility)
172
+	{
173
+		$this->visibility = $visibility;
174
+	}
175
+
176
+	/**
177
+	 * @return int
178
+	 */
179
+	public function getRequest()
180
+	{
181
+		return $this->request;
182
+	}
183
+
184
+	/**
185
+	 * @param int $request
186
+	 */
187
+	public function setRequest($request)
188
+	{
189
+		$this->request = $request;
190
+	}
191 191
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@  discard block
 block discarded – undo
41 41
     {
42 42
         if ($showAll) {
43 43
             $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
-        }
45
-        else {
44
+        } else {
46 45
             $statement = $database->prepare(<<<SQL
47 46
 SELECT * FROM comment
48 47
 WHERE request = :target AND (visibility = 'user' OR user = :userid);
@@ -84,12 +83,10 @@  discard block
 block discarded – undo
84 83
 
85 84
             if ($statement->execute()) {
86 85
                 $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
86
+            } else {
89 87
                 throw new Exception($statement->errorInfo());
90 88
             }
91
-        }
92
-        else {
89
+        } else {
93 90
             // update
94 91
             $statement = $this->dbObject->prepare(<<<SQL
95 92
 UPDATE comment
Please login to merge, or discard this patch.
includes/DataObjects/UserRole.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@
 block discarded – undo
15 15
 
16 16
 class UserRole extends DataObject
17 17
 {
18
-    /** @var int */
19
-    private $user;
20
-    /** @var string */
21
-    private $role;
18
+	/** @var int */
19
+	private $user;
20
+	/** @var string */
21
+	private $role;
22 22
 
23
-    /**
24
-     * @param int         $userId
25
-     * @param PdoDatabase $database
26
-     *
27
-     * @return UserRole[]
28
-     */
29
-    public static function getForUser($userId, PdoDatabase $database)
30
-    {
31
-        $sql = 'SELECT * FROM userrole WHERE user = :user';
32
-        $statement = $database->prepare($sql);
33
-        $statement->bindValue(':user', $userId);
23
+	/**
24
+	 * @param int         $userId
25
+	 * @param PdoDatabase $database
26
+	 *
27
+	 * @return UserRole[]
28
+	 */
29
+	public static function getForUser($userId, PdoDatabase $database)
30
+	{
31
+		$sql = 'SELECT * FROM userrole WHERE user = :user';
32
+		$statement = $database->prepare($sql);
33
+		$statement->bindValue(':user', $userId);
34 34
 
35
-        $statement->execute();
35
+		$statement->execute();
36 36
 
37
-        $result = array();
37
+		$result = array();
38 38
 
39
-        /** @var Ban $v */
40
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
41
-            $v->setDatabase($database);
42
-            $result[] = $v;
43
-        }
39
+		/** @var Ban $v */
40
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
41
+			$v->setDatabase($database);
42
+			$result[] = $v;
43
+		}
44 44
 
45
-        return $result;
46
-    }
45
+		return $result;
46
+	}
47 47
 
48
-    /**
49
-     * Saves a data object to the database, either updating or inserting a record.
50
-     *
51
-     * @throws Exception
52
-     */
53
-    public function save()
54
-    {
55
-        if ($this->isNew()) {
56
-            // insert
57
-            $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);'
58
-            );
59
-            $statement->bindValue(":user", $this->user);
60
-            $statement->bindValue(":role", $this->role);
48
+	/**
49
+	 * Saves a data object to the database, either updating or inserting a record.
50
+	 *
51
+	 * @throws Exception
52
+	 */
53
+	public function save()
54
+	{
55
+		if ($this->isNew()) {
56
+			// insert
57
+			$statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);'
58
+			);
59
+			$statement->bindValue(":user", $this->user);
60
+			$statement->bindValue(":role", $this->role);
61 61
 
62
-            if ($statement->execute()) {
63
-                $this->id = (int)$this->dbObject->lastInsertId();
64
-            }
65
-            else {
66
-                throw new Exception($statement->errorInfo());
67
-            }
68
-        }
69
-        else {
70
-            // update
71
-            throw new Exception('Updating roles is not available');
72
-        }
73
-    }
62
+			if ($statement->execute()) {
63
+				$this->id = (int)$this->dbObject->lastInsertId();
64
+			}
65
+			else {
66
+				throw new Exception($statement->errorInfo());
67
+			}
68
+		}
69
+		else {
70
+			// update
71
+			throw new Exception('Updating roles is not available');
72
+		}
73
+	}
74 74
 
75
-    #region Properties
75
+	#region Properties
76 76
 
77
-    /**
78
-     * @return int
79
-     */
80
-    public function getUser()
81
-    {
82
-        return $this->user;
83
-    }
77
+	/**
78
+	 * @return int
79
+	 */
80
+	public function getUser()
81
+	{
82
+		return $this->user;
83
+	}
84 84
 
85
-    /**
86
-     * @param int $user
87
-     */
88
-    public function setUser($user)
89
-    {
90
-        $this->user = $user;
91
-    }
85
+	/**
86
+	 * @param int $user
87
+	 */
88
+	public function setUser($user)
89
+	{
90
+		$this->user = $user;
91
+	}
92 92
 
93
-    /**
94
-     * @return string
95
-     */
96
-    public function getRole()
97
-    {
98
-        return $this->role;
99
-    }
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function getRole()
97
+	{
98
+		return $this->role;
99
+	}
100 100
 
101
-    /**
102
-     * @param string $role
103
-     */
104
-    public function setRole($role)
105
-    {
106
-        $this->role = $role;
107
-    }
108
-    #endregion
101
+	/**
102
+	 * @param string $role
103
+	 */
104
+	public function setRole($role)
105
+	{
106
+		$this->role = $role;
107
+	}
108
+	#endregion
109 109
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,12 +61,10 @@
 block discarded – undo
61 61
 
62 62
             if ($statement->execute()) {
63 63
                 $this->id = (int)$this->dbObject->lastInsertId();
64
-            }
65
-            else {
64
+            } else {
66 65
                 throw new Exception($statement->errorInfo());
67 66
             }
68
-        }
69
-        else {
67
+        } else {
70 68
             // update
71 69
             throw new Exception('Updating roles is not available');
72 70
         }
Please login to merge, or discard this patch.
includes/DataObjects/SiteNotice.php 2 patches
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.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@
 block discarded – undo
47 47
         if ($this->isNew()) {
48 48
             // insert
49 49
             throw new Exception('Not allowed to create new site notice object');
50
-        }
51
-        else {
50
+        } else {
52 51
             // update
53 52
             $statement = $this->dbObject->prepare(<<<SQL
54 53
 UPDATE sitenotice
Please login to merge, or discard this patch.
includes/DataObjects/Notification.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -22,73 +22,73 @@
 block discarded – undo
22 22
  */
23 23
 class Notification extends DataObject
24 24
 {
25
-    private $date;
26
-    private $type;
27
-    private $text;
25
+	private $date;
26
+	private $type;
27
+	private $text;
28 28
 
29
-    public function delete()
30
-    {
31
-        throw new Exception("You shouldn't be doing this...");
32
-    }
29
+	public function delete()
30
+	{
31
+		throw new Exception("You shouldn't be doing this...");
32
+	}
33 33
 
34
-    public function save()
35
-    {
36
-        if ($this->isNew()) {
37
-            // insert
38
-            $statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );");
39
-            $statement->bindValue(":type", $this->type);
40
-            $statement->bindValue(":text", $this->text);
34
+	public function save()
35
+	{
36
+		if ($this->isNew()) {
37
+			// insert
38
+			$statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );");
39
+			$statement->bindValue(":type", $this->type);
40
+			$statement->bindValue(":text", $this->text);
41 41
 
42
-            if ($statement->execute()) {
43
-                $this->id = (int)$this->dbObject->lastInsertId();
44
-            }
45
-            else {
46
-                throw new Exception($statement->errorInfo());
47
-            }
48
-        }
49
-        else {
50
-            throw new Exception("You shouldn't be doing this...");
51
-        }
52
-    }
42
+			if ($statement->execute()) {
43
+				$this->id = (int)$this->dbObject->lastInsertId();
44
+			}
45
+			else {
46
+				throw new Exception($statement->errorInfo());
47
+			}
48
+		}
49
+		else {
50
+			throw new Exception("You shouldn't be doing this...");
51
+		}
52
+	}
53 53
 
54
-    public function getDate()
55
-    {
56
-        return new DateTimeImmutable($this->date);
57
-    }
54
+	public function getDate()
55
+	{
56
+		return new DateTimeImmutable($this->date);
57
+	}
58 58
 
59
-    /**
60
-     * @return int
61
-     */
62
-    public function getType()
63
-    {
64
-        return $this->type;
65
-    }
59
+	/**
60
+	 * @return int
61
+	 */
62
+	public function getType()
63
+	{
64
+		return $this->type;
65
+	}
66 66
 
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getText()
71
-    {
72
-        return $this->text;
73
-    }
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getText()
71
+	{
72
+		return $this->text;
73
+	}
74 74
 
75
-    /**
76
-     * Summary of setType
77
-     *
78
-     * @param int $type
79
-     */
80
-    public function setType($type)
81
-    {
82
-        $this->type = $type;
83
-    }
75
+	/**
76
+	 * Summary of setType
77
+	 *
78
+	 * @param int $type
79
+	 */
80
+	public function setType($type)
81
+	{
82
+		$this->type = $type;
83
+	}
84 84
 
85
-    /**
86
-     * Summary of setText
87
-     *
88
-     * @param string $text
89
-     */
90
-    public function setText($text)
91
-    {
92
-        $this->text = $text;
93
-    }
85
+	/**
86
+	 * Summary of setText
87
+	 *
88
+	 * @param string $text
89
+	 */
90
+	public function setText($text)
91
+	{
92
+		$this->text = $text;
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,12 +41,10 @@
 block discarded – undo
41 41
 
42 42
             if ($statement->execute()) {
43 43
                 $this->id = (int)$this->dbObject->lastInsertId();
44
-            }
45
-            else {
44
+            } else {
46 45
                 throw new Exception($statement->errorInfo());
47 46
             }
48
-        }
49
-        else {
47
+        } else {
50 48
             throw new Exception("You shouldn't be doing this...");
51 49
         }
52 50
     }
Please login to merge, or discard this patch.
includes/DataObjects/Request.php 3 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   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -408,7 +408,7 @@
 block discarded – undo
408 408
             . '|' . $this->forwardedip  // } private data not known to those without access
409 409
             . '|' . $this->useragent    // }
410 410
             . '|' . $this->email        // }
411
-            . '|' . $this->status;      // to rudimentarily invalidate the token on status change
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.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -67,12 +67,10 @@
 block discarded – undo
67 67
 
68 68
             if ($statement->execute()) {
69 69
                 $this->id = (int)$this->dbObject->lastInsertId();
70
-            }
71
-            else {
70
+            } else {
72 71
                 throw new Exception($statement->errorInfo());
73 72
             }
74
-        }
75
-        else {
73
+        } else {
76 74
             // update
77 75
             $statement = $this->dbObject->prepare(<<<SQL
78 76
 UPDATE `request` SET
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 2 patches
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.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -183,12 +183,10 @@
 block discarded – undo
183 183
 
184 184
             if ($statement->execute()) {
185 185
                 $this->id = (int)$this->dbObject->lastInsertId();
186
-            }
187
-            else {
186
+            } else {
188 187
                 throw new Exception($statement->errorInfo());
189 188
             }
190
-        }
191
-        else {
189
+        } else {
192 190
             // update
193 191
             $statement = $this->dbObject->prepare(<<<SQL
194 192
 UPDATE `emailtemplate`
Please login to merge, or discard this patch.
includes/DataObjects/User.php 2 patches
Indentation   +947 added lines, -947 removed lines patch added patch discarded remove patch
@@ -27,229 +27,229 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class User extends DataObject
29 29
 {
30
-    const STATUS_ACTIVE = 'Active';
31
-    const STATUS_SUSPENDED = 'Suspended';
32
-    const STATUS_DECLINED = 'Declined';
33
-    const STATUS_NEW = 'New';
34
-    private $username;
35
-    private $email;
36
-    private $password;
37
-    private $status = self::STATUS_NEW;
38
-    private $onwikiname = "##OAUTH##";
39
-    private $welcome_sig = "";
40
-    private $lastactive = "0000-00-00 00:00:00";
41
-    private $forcelogout = 0;
42
-    private $forceidentified = null;
43
-    private $welcome_template = 0;
44
-    private $abortpref = 0;
45
-    private $confirmationdiff = 0;
46
-    private $emailsig = "";
47
-    /** @var null|string */
48
-    private $oauthrequesttoken = null;
49
-    /** @var null|string */
50
-    private $oauthrequestsecret = null;
51
-    /** @var null|string */
52
-    private $oauthaccesstoken = null;
53
-    /** @var null|string */
54
-    private $oauthaccesssecret = null;
55
-    private $oauthidentitycache = null;
56
-    /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
57
-    private static $currentUser;
58
-    /** @var null|JWT The identity cache */
59
-    private $identityCache = null;
60
-    #region Object load methods
61
-
62
-    /**
63
-     * Gets the currently logged in user
64
-     *
65
-     * @param PdoDatabase $database
66
-     *
67
-     * @return User|CommunityUser
68
-     */
69
-    public static function getCurrent(PdoDatabase $database)
70
-    {
71
-        if (self::$currentUser === null) {
72
-            $sessionId = WebRequest::getSessionUserId();
73
-
74
-            if ($sessionId !== null) {
75
-                /** @var User $user */
76
-                $user = self::getById($sessionId, $database);
77
-
78
-                if ($user === false) {
79
-                    self::$currentUser = new CommunityUser();
80
-                }
81
-                else {
82
-                    self::$currentUser = $user;
83
-                }
84
-            }
85
-            else {
86
-                $anonymousCoward = new CommunityUser();
87
-
88
-                self::$currentUser = $anonymousCoward;
89
-            }
90
-        }
91
-
92
-        return self::$currentUser;
93
-    }
94
-
95
-    /**
96
-     * Gets a user by their user ID
97
-     *
98
-     * Pass -1 to get the community user.
99
-     *
100
-     * @param int|null    $id
101
-     * @param PdoDatabase $database
102
-     *
103
-     * @return User|false
104
-     */
105
-    public static function getById($id, PdoDatabase $database)
106
-    {
107
-        if ($id === null || $id == -1) {
108
-            return new CommunityUser();
109
-        }
110
-
111
-        /** @var User|false $user */
112
-        $user = parent::getById($id, $database);
113
-
114
-        return $user;
115
-    }
116
-
117
-    /**
118
-     * @return CommunityUser
119
-     */
120
-    public static function getCommunity()
121
-    {
122
-        return new CommunityUser();
123
-    }
124
-
125
-    /**
126
-     * Gets a user by their username
127
-     *
128
-     * @param  string      $username
129
-     * @param  PdoDatabase $database
130
-     *
131
-     * @return CommunityUser|User|false
132
-     */
133
-    public static function getByUsername($username, PdoDatabase $database)
134
-    {
135
-        global $communityUsername;
136
-        if ($username == $communityUsername) {
137
-            return new CommunityUser();
138
-        }
139
-
140
-        $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
141
-        $statement->bindValue(":id", $username);
142
-
143
-        $statement->execute();
144
-
145
-        $resultObject = $statement->fetchObject(get_called_class());
146
-
147
-        if ($resultObject != false) {
148
-            $resultObject->setDatabase($database);
149
-        }
150
-
151
-        return $resultObject;
152
-    }
153
-
154
-    /**
155
-     * Gets a user by their on-wiki username.
156
-     *
157
-     * Don't use without asking me first. It's really inefficient in it's current implementation.
158
-     * We need to restructure the user table again to make this more efficient.
159
-     * We don't actually store the on-wiki name in the table any more, instead we
160
-     * are storing JSON in a column (!!). Yep, my fault. Code review is an awesome thing.
161
-     *            -- stw 2015-10-20
162
-     *
163
-     * @param string      $username
164
-     * @param PdoDatabase $database
165
-     *
166
-     * @return User|false
167
-     */
168
-    public static function getByOnWikiUsername($username, PdoDatabase $database)
169
-    {
170
-        // Firstly, try to search by the efficient database lookup.
171
-        $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
172
-        $statement->bindValue(":id", $username);
173
-        $statement->execute();
174
-
175
-        $resultObject = $statement->fetchObject(get_called_class());
176
-
177
-        if ($resultObject != false) {
178
-            $resultObject->setDatabase($database);
179
-
180
-            return $resultObject;
181
-        }
182
-
183
-        // For active users, the above has failed. Let's do it the hard way.
184
-        $sqlStatement = "SELECT * FROM user WHERE onwikiname = '##OAUTH##' AND oauthaccesstoken IS NOT NULL;";
185
-        $statement = $database->prepare($sqlStatement);
186
-        $statement->execute();
187
-        $resultSet = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
188
-
189
-        /** @var User $user */
190
-        foreach ($resultSet as $user) {
191
-            // We have to set this before doing OAuth queries. :(
192
-            $user->setDatabase($database);
193
-
194
-            // Using cached data here!
195
-            if ($user->getOAuthOnWikiName(true) == $username) {
196
-                // Success.
197
-                return $user;
198
-            }
199
-        }
200
-
201
-        // Cached data failed. Let's do it the *REALLY* hard way.
202
-        foreach ($resultSet as $user) {
203
-            // We have to set this before doing OAuth queries. :(
204
-            $user->setDatabase($database);
205
-
206
-            // Don't use the cached data, but instead query the API.
207
-            if ($user->getOAuthOnWikiName(false) == $username) {
208
-                // Success.
209
-                return $user;
210
-            }
211
-        }
212
-
213
-        // Nope. Sorry.
214
-        return false;
215
-    }
216
-
217
-    /**
218
-     * Gets a user by their OAuth request token
219
-     *
220
-     * @param string      $requestToken
221
-     * @param PdoDatabase $database
222
-     *
223
-     * @return User|false
224
-     */
225
-    public static function getByRequestToken($requestToken, PdoDatabase $database)
226
-    {
227
-        $statement = $database->prepare("SELECT * FROM user WHERE oauthrequesttoken = :id LIMIT 1;");
228
-        $statement->bindValue(":id", $requestToken);
229
-
230
-        $statement->execute();
231
-
232
-        $resultObject = $statement->fetchObject(get_called_class());
233
-
234
-        if ($resultObject != false) {
235
-            $resultObject->setDatabase($database);
236
-        }
237
-
238
-        return $resultObject;
239
-    }
240
-
241
-    #endregion
242
-
243
-    /**
244
-     * Saves the current object
245
-     *
246
-     * @throws Exception
247
-     */
248
-    public function save()
249
-    {
250
-        if ($this->isNew()) {
251
-            // insert
252
-            $statement = $this->dbObject->prepare(<<<SQL
30
+	const STATUS_ACTIVE = 'Active';
31
+	const STATUS_SUSPENDED = 'Suspended';
32
+	const STATUS_DECLINED = 'Declined';
33
+	const STATUS_NEW = 'New';
34
+	private $username;
35
+	private $email;
36
+	private $password;
37
+	private $status = self::STATUS_NEW;
38
+	private $onwikiname = "##OAUTH##";
39
+	private $welcome_sig = "";
40
+	private $lastactive = "0000-00-00 00:00:00";
41
+	private $forcelogout = 0;
42
+	private $forceidentified = null;
43
+	private $welcome_template = 0;
44
+	private $abortpref = 0;
45
+	private $confirmationdiff = 0;
46
+	private $emailsig = "";
47
+	/** @var null|string */
48
+	private $oauthrequesttoken = null;
49
+	/** @var null|string */
50
+	private $oauthrequestsecret = null;
51
+	/** @var null|string */
52
+	private $oauthaccesstoken = null;
53
+	/** @var null|string */
54
+	private $oauthaccesssecret = null;
55
+	private $oauthidentitycache = null;
56
+	/** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
57
+	private static $currentUser;
58
+	/** @var null|JWT The identity cache */
59
+	private $identityCache = null;
60
+	#region Object load methods
61
+
62
+	/**
63
+	 * Gets the currently logged in user
64
+	 *
65
+	 * @param PdoDatabase $database
66
+	 *
67
+	 * @return User|CommunityUser
68
+	 */
69
+	public static function getCurrent(PdoDatabase $database)
70
+	{
71
+		if (self::$currentUser === null) {
72
+			$sessionId = WebRequest::getSessionUserId();
73
+
74
+			if ($sessionId !== null) {
75
+				/** @var User $user */
76
+				$user = self::getById($sessionId, $database);
77
+
78
+				if ($user === false) {
79
+					self::$currentUser = new CommunityUser();
80
+				}
81
+				else {
82
+					self::$currentUser = $user;
83
+				}
84
+			}
85
+			else {
86
+				$anonymousCoward = new CommunityUser();
87
+
88
+				self::$currentUser = $anonymousCoward;
89
+			}
90
+		}
91
+
92
+		return self::$currentUser;
93
+	}
94
+
95
+	/**
96
+	 * Gets a user by their user ID
97
+	 *
98
+	 * Pass -1 to get the community user.
99
+	 *
100
+	 * @param int|null    $id
101
+	 * @param PdoDatabase $database
102
+	 *
103
+	 * @return User|false
104
+	 */
105
+	public static function getById($id, PdoDatabase $database)
106
+	{
107
+		if ($id === null || $id == -1) {
108
+			return new CommunityUser();
109
+		}
110
+
111
+		/** @var User|false $user */
112
+		$user = parent::getById($id, $database);
113
+
114
+		return $user;
115
+	}
116
+
117
+	/**
118
+	 * @return CommunityUser
119
+	 */
120
+	public static function getCommunity()
121
+	{
122
+		return new CommunityUser();
123
+	}
124
+
125
+	/**
126
+	 * Gets a user by their username
127
+	 *
128
+	 * @param  string      $username
129
+	 * @param  PdoDatabase $database
130
+	 *
131
+	 * @return CommunityUser|User|false
132
+	 */
133
+	public static function getByUsername($username, PdoDatabase $database)
134
+	{
135
+		global $communityUsername;
136
+		if ($username == $communityUsername) {
137
+			return new CommunityUser();
138
+		}
139
+
140
+		$statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
141
+		$statement->bindValue(":id", $username);
142
+
143
+		$statement->execute();
144
+
145
+		$resultObject = $statement->fetchObject(get_called_class());
146
+
147
+		if ($resultObject != false) {
148
+			$resultObject->setDatabase($database);
149
+		}
150
+
151
+		return $resultObject;
152
+	}
153
+
154
+	/**
155
+	 * Gets a user by their on-wiki username.
156
+	 *
157
+	 * Don't use without asking me first. It's really inefficient in it's current implementation.
158
+	 * We need to restructure the user table again to make this more efficient.
159
+	 * We don't actually store the on-wiki name in the table any more, instead we
160
+	 * are storing JSON in a column (!!). Yep, my fault. Code review is an awesome thing.
161
+	 *            -- stw 2015-10-20
162
+	 *
163
+	 * @param string      $username
164
+	 * @param PdoDatabase $database
165
+	 *
166
+	 * @return User|false
167
+	 */
168
+	public static function getByOnWikiUsername($username, PdoDatabase $database)
169
+	{
170
+		// Firstly, try to search by the efficient database lookup.
171
+		$statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
172
+		$statement->bindValue(":id", $username);
173
+		$statement->execute();
174
+
175
+		$resultObject = $statement->fetchObject(get_called_class());
176
+
177
+		if ($resultObject != false) {
178
+			$resultObject->setDatabase($database);
179
+
180
+			return $resultObject;
181
+		}
182
+
183
+		// For active users, the above has failed. Let's do it the hard way.
184
+		$sqlStatement = "SELECT * FROM user WHERE onwikiname = '##OAUTH##' AND oauthaccesstoken IS NOT NULL;";
185
+		$statement = $database->prepare($sqlStatement);
186
+		$statement->execute();
187
+		$resultSet = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
188
+
189
+		/** @var User $user */
190
+		foreach ($resultSet as $user) {
191
+			// We have to set this before doing OAuth queries. :(
192
+			$user->setDatabase($database);
193
+
194
+			// Using cached data here!
195
+			if ($user->getOAuthOnWikiName(true) == $username) {
196
+				// Success.
197
+				return $user;
198
+			}
199
+		}
200
+
201
+		// Cached data failed. Let's do it the *REALLY* hard way.
202
+		foreach ($resultSet as $user) {
203
+			// We have to set this before doing OAuth queries. :(
204
+			$user->setDatabase($database);
205
+
206
+			// Don't use the cached data, but instead query the API.
207
+			if ($user->getOAuthOnWikiName(false) == $username) {
208
+				// Success.
209
+				return $user;
210
+			}
211
+		}
212
+
213
+		// Nope. Sorry.
214
+		return false;
215
+	}
216
+
217
+	/**
218
+	 * Gets a user by their OAuth request token
219
+	 *
220
+	 * @param string      $requestToken
221
+	 * @param PdoDatabase $database
222
+	 *
223
+	 * @return User|false
224
+	 */
225
+	public static function getByRequestToken($requestToken, PdoDatabase $database)
226
+	{
227
+		$statement = $database->prepare("SELECT * FROM user WHERE oauthrequesttoken = :id LIMIT 1;");
228
+		$statement->bindValue(":id", $requestToken);
229
+
230
+		$statement->execute();
231
+
232
+		$resultObject = $statement->fetchObject(get_called_class());
233
+
234
+		if ($resultObject != false) {
235
+			$resultObject->setDatabase($database);
236
+		}
237
+
238
+		return $resultObject;
239
+	}
240
+
241
+	#endregion
242
+
243
+	/**
244
+	 * Saves the current object
245
+	 *
246
+	 * @throws Exception
247
+	 */
248
+	public function save()
249
+	{
250
+		if ($this->isNew()) {
251
+			// insert
252
+			$statement = $this->dbObject->prepare(<<<SQL
253 253
 				INSERT INTO `user` ( 
254 254
 					username, email, password, status, onwikiname, welcome_sig, 
255 255
 					lastactive, forcelogout, forceidentified,
@@ -263,35 +263,35 @@  discard block
 block discarded – undo
263 263
 					:ort, :ors, :oat, :oas
264 264
 				);
265 265
 SQL
266
-            );
267
-            $statement->bindValue(":username", $this->username);
268
-            $statement->bindValue(":email", $this->email);
269
-            $statement->bindValue(":password", $this->password);
270
-            $statement->bindValue(":status", $this->status);
271
-            $statement->bindValue(":onwikiname", $this->onwikiname);
272
-            $statement->bindValue(":welcome_sig", $this->welcome_sig);
273
-            $statement->bindValue(":lastactive", $this->lastactive);
274
-            $statement->bindValue(":forcelogout", $this->forcelogout);
275
-            $statement->bindValue(":forceidentified", $this->forceidentified);
276
-            $statement->bindValue(":welcome_template", $this->welcome_template);
277
-            $statement->bindValue(":abortpref", $this->abortpref);
278
-            $statement->bindValue(":confirmationdiff", $this->confirmationdiff);
279
-            $statement->bindValue(":emailsig", $this->emailsig);
280
-            $statement->bindValue(":ort", $this->oauthrequesttoken);
281
-            $statement->bindValue(":ors", $this->oauthrequestsecret);
282
-            $statement->bindValue(":oat", $this->oauthaccesstoken);
283
-            $statement->bindValue(":oas", $this->oauthaccesssecret);
284
-
285
-            if ($statement->execute()) {
286
-                $this->id = (int)$this->dbObject->lastInsertId();
287
-            }
288
-            else {
289
-                throw new Exception($statement->errorInfo());
290
-            }
291
-        }
292
-        else {
293
-            // update
294
-            $statement = $this->dbObject->prepare(<<<SQL
266
+			);
267
+			$statement->bindValue(":username", $this->username);
268
+			$statement->bindValue(":email", $this->email);
269
+			$statement->bindValue(":password", $this->password);
270
+			$statement->bindValue(":status", $this->status);
271
+			$statement->bindValue(":onwikiname", $this->onwikiname);
272
+			$statement->bindValue(":welcome_sig", $this->welcome_sig);
273
+			$statement->bindValue(":lastactive", $this->lastactive);
274
+			$statement->bindValue(":forcelogout", $this->forcelogout);
275
+			$statement->bindValue(":forceidentified", $this->forceidentified);
276
+			$statement->bindValue(":welcome_template", $this->welcome_template);
277
+			$statement->bindValue(":abortpref", $this->abortpref);
278
+			$statement->bindValue(":confirmationdiff", $this->confirmationdiff);
279
+			$statement->bindValue(":emailsig", $this->emailsig);
280
+			$statement->bindValue(":ort", $this->oauthrequesttoken);
281
+			$statement->bindValue(":ors", $this->oauthrequestsecret);
282
+			$statement->bindValue(":oat", $this->oauthaccesstoken);
283
+			$statement->bindValue(":oas", $this->oauthaccesssecret);
284
+
285
+			if ($statement->execute()) {
286
+				$this->id = (int)$this->dbObject->lastInsertId();
287
+			}
288
+			else {
289
+				throw new Exception($statement->errorInfo());
290
+			}
291
+		}
292
+		else {
293
+			// update
294
+			$statement = $this->dbObject->prepare(<<<SQL
295 295
 				UPDATE `user` SET 
296 296
 					username = :username, email = :email, 
297 297
 					password = :password, status = :status,
@@ -306,695 +306,695 @@  discard block
 block discarded – undo
306 306
 				WHERE id = :id AND updateversion = :updateversion
307 307
 				LIMIT 1;
308 308
 SQL
309
-            );
310
-            $statement->bindValue(":forceidentified", $this->forceidentified);
311
-
312
-            $statement->bindValue(':id', $this->id);
313
-            $statement->bindValue(':updateversion', $this->updateversion);
314
-
315
-            $statement->bindValue(':username', $this->username);
316
-            $statement->bindValue(':email', $this->email);
317
-            $statement->bindValue(':password', $this->password);
318
-            $statement->bindValue(':status', $this->status);
319
-            $statement->bindValue(':onwikiname', $this->onwikiname);
320
-            $statement->bindValue(':welcome_sig', $this->welcome_sig);
321
-            $statement->bindValue(':lastactive', $this->lastactive);
322
-            $statement->bindValue(':forcelogout', $this->forcelogout);
323
-            $statement->bindValue(':forceidentified', $this->forceidentified);
324
-            $statement->bindValue(':welcome_template', $this->welcome_template);
325
-            $statement->bindValue(':abortpref', $this->abortpref);
326
-            $statement->bindValue(':confirmationdiff', $this->confirmationdiff);
327
-            $statement->bindValue(':emailsig', $this->emailsig);
328
-            $statement->bindValue(':ort', $this->oauthrequesttoken);
329
-            $statement->bindValue(':ors', $this->oauthrequestsecret);
330
-            $statement->bindValue(':oat', $this->oauthaccesstoken);
331
-            $statement->bindValue(':oas', $this->oauthaccesssecret);
332
-
333
-            if (!$statement->execute()) {
334
-                throw new Exception($statement->errorInfo());
335
-            }
336
-
337
-            if ($statement->rowCount() !== 1) {
338
-                throw new OptimisticLockFailedException();
339
-            }
340
-
341
-            $this->updateversion++;
342
-        }
343
-    }
344
-
345
-    /**
346
-     * Authenticates the user with the supplied password
347
-     *
348
-     * @param string $password
349
-     *
350
-     * @return bool
351
-     * @throws Exception
352
-     * @category Security-Critical
353
-     */
354
-    public function authenticate($password)
355
-    {
356
-        $result = AuthUtility::testCredentials($password, $this->password);
357
-
358
-        if ($result === true) {
359
-            // password version is out of date, update it.
360
-            if (!AuthUtility::isCredentialVersionLatest($this->password)) {
361
-                $this->password = AuthUtility::encryptPassword($password);
362
-                $this->save();
363
-            }
364
-        }
365
-
366
-        return $result;
367
-    }
368
-
369
-    #region properties
370
-
371
-    /**
372
-     * Gets the tool username
373
-     * @return string
374
-     */
375
-    public function getUsername()
376
-    {
377
-        return $this->username;
378
-    }
379
-
380
-    /**
381
-     * Sets the tool username
382
-     *
383
-     * @param string $username
384
-     */
385
-    public function setUsername($username)
386
-    {
387
-        $this->username = $username;
388
-
389
-        // If this isn't a brand new user, then it's a rename, force the logout
390
-        if (!$this->isNew()) {
391
-            $this->forcelogout = 1;
392
-        }
393
-    }
394
-
395
-    /**
396
-     * Gets the user's email address
397
-     * @return string
398
-     */
399
-    public function getEmail()
400
-    {
401
-        return $this->email;
402
-    }
403
-
404
-    /**
405
-     * Sets the user's email address
406
-     *
407
-     * @param string $email
408
-     */
409
-    public function setEmail($email)
410
-    {
411
-        $this->email = $email;
412
-    }
413
-
414
-    /**
415
-     * Sets the user's password
416
-     *
417
-     * @param string $password the plaintext password
418
-     *
419
-     * @category Security-Critical
420
-     */
421
-    public function setPassword($password)
422
-    {
423
-        $this->password = AuthUtility::encryptPassword($password);
424
-    }
425
-
426
-    /**
427
-     * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
428
-     * @return string
429
-     */
430
-    public function getStatus()
431
-    {
432
-        return $this->status;
433
-    }
434
-
435
-    /**
436
-     * @param string $status
437
-     */
438
-    public function setStatus($status)
439
-    {
440
-        $this->status = $status;
441
-    }
442
-
443
-    /**
444
-     * Gets the user's on-wiki name
445
-     * @return string
446
-     */
447
-    public function getOnWikiName()
448
-    {
449
-        if ($this->oauthaccesstoken !== null) {
450
-            try {
451
-                return $this->getOAuthOnWikiName();
452
-            }
453
-            catch (Exception $ex) {
454
-                // urm.. log this?
455
-                return $this->onwikiname;
456
-            }
457
-        }
458
-
459
-        return $this->onwikiname;
460
-    }
461
-
462
-    /**
463
-     * This is probably NOT the function you want!
464
-     *
465
-     * Take a look at getOnWikiName() instead.
466
-     * @return string
467
-     */
468
-    public function getStoredOnWikiName()
469
-    {
470
-        return $this->onwikiname;
471
-    }
472
-
473
-    /**
474
-     * Sets the user's on-wiki name
475
-     *
476
-     * This can have interesting side-effects with OAuth.
477
-     *
478
-     * @param string $onWikiName
479
-     */
480
-    public function setOnWikiName($onWikiName)
481
-    {
482
-        $this->onwikiname = $onWikiName;
483
-    }
484
-
485
-    /**
486
-     * Gets the welcome signature
487
-     * @return string
488
-     */
489
-    public function getWelcomeSig()
490
-    {
491
-        return $this->welcome_sig;
492
-    }
493
-
494
-    /**
495
-     * Sets the welcome signature
496
-     *
497
-     * @param string $welcomeSig
498
-     */
499
-    public function setWelcomeSig($welcomeSig)
500
-    {
501
-        $this->welcome_sig = $welcomeSig;
502
-    }
503
-
504
-    /**
505
-     * Gets the last activity date for the user
506
-     *
507
-     * @return string
508
-     * @todo This should probably return an instance of DateTime
509
-     */
510
-    public function getLastActive()
511
-    {
512
-        return $this->lastactive;
513
-    }
514
-
515
-    /**
516
-     * Gets the user's forced logout status
517
-     *
518
-     * @return bool
519
-     */
520
-    public function getForceLogout()
521
-    {
522
-        return $this->forcelogout == 1;
523
-    }
524
-
525
-    /**
526
-     * Sets the user's forced logout status
527
-     *
528
-     * @param bool $forceLogout
529
-     */
530
-    public function setForceLogout($forceLogout)
531
-    {
532
-        $this->forcelogout = $forceLogout ? 1 : 0;
533
-    }
534
-
535
-    /**
536
-     * Returns the ID of the welcome template used.
537
-     * @return int
538
-     */
539
-    public function getWelcomeTemplate()
540
-    {
541
-        return $this->welcome_template;
542
-    }
543
-
544
-    /**
545
-     * Sets the ID of the welcome template used.
546
-     *
547
-     * @param int $welcomeTemplate
548
-     */
549
-    public function setWelcomeTemplate($welcomeTemplate)
550
-    {
551
-        $this->welcome_template = $welcomeTemplate;
552
-    }
553
-
554
-    /**
555
-     * Gets the user's abort preference
556
-     * @todo this is badly named too! Also a bool that's actually an int.
557
-     * @return int
558
-     */
559
-    public function getAbortPref()
560
-    {
561
-        return $this->abortpref;
562
-    }
563
-
564
-    /**
565
-     * Sets the user's abort preference
566
-     * @todo rename, retype, and re-comment.
567
-     *
568
-     * @param int $abortPreference
569
-     */
570
-    public function setAbortPref($abortPreference)
571
-    {
572
-        $this->abortpref = $abortPreference;
573
-    }
574
-
575
-    /**
576
-     * Gets the user's confirmation diff. Unused if OAuth is in use.
577
-     * @return int the diff ID
578
-     */
579
-    public function getConfirmationDiff()
580
-    {
581
-        return $this->confirmationdiff;
582
-    }
583
-
584
-    /**
585
-     * Sets the user's confirmation diff.
586
-     *
587
-     * @param int $confirmationDiff
588
-     */
589
-    public function setConfirmationDiff($confirmationDiff)
590
-    {
591
-        $this->confirmationdiff = $confirmationDiff;
592
-    }
593
-
594
-    /**
595
-     * Gets the users' email signature used on outbound mail.
596
-     * @todo rename me!
597
-     * @return string
598
-     */
599
-    public function getEmailSig()
600
-    {
601
-        return $this->emailsig;
602
-    }
603
-
604
-    /**
605
-     * Sets the user's email signature for outbound mail.
606
-     *
607
-     * @param string $emailSignature
608
-     */
609
-    public function setEmailSig($emailSignature)
610
-    {
611
-        $this->emailsig = $emailSignature;
612
-    }
613
-
614
-    /**
615
-     * Gets the user's OAuth request token.
616
-     *
617
-     * @todo move me to a collaborator.
618
-     * @return null|string
619
-     */
620
-    public function getOAuthRequestToken()
621
-    {
622
-        return $this->oauthrequesttoken;
623
-    }
624
-
625
-    /**
626
-     * Sets the user's OAuth request token
627
-     * @todo move me to a collaborator
628
-     *
629
-     * @param string $oAuthRequestToken
630
-     */
631
-    public function setOAuthRequestToken($oAuthRequestToken)
632
-    {
633
-        $this->oauthrequesttoken = $oAuthRequestToken;
634
-    }
635
-
636
-    /**
637
-     * Gets the users OAuth request secret
638
-     * @category Security-Critical
639
-     * @todo     move me to a collaborator
640
-     * @return null|string
641
-     */
642
-    public function getOAuthRequestSecret()
643
-    {
644
-        return $this->oauthrequestsecret;
645
-    }
646
-
647
-    /**
648
-     * Sets the user's OAuth request secret
649
-     * @todo move me to a collaborator
650
-     *
651
-     * @param string $oAuthRequestSecret
652
-     */
653
-    public function setOAuthRequestSecret($oAuthRequestSecret)
654
-    {
655
-        $this->oauthrequestsecret = $oAuthRequestSecret;
656
-    }
657
-
658
-    /**
659
-     * Gets the user's access token
660
-     * @category Security-Critical
661
-     * @todo     move me to a collaborator
662
-     * @return null|string
663
-     */
664
-    public function getOAuthAccessToken()
665
-    {
666
-        return $this->oauthaccesstoken;
667
-    }
668
-
669
-    /**
670
-     * Sets the user's access token
671
-     * @todo move me to a collaborator
672
-     *
673
-     * @param string $oAuthAccessToken
674
-     */
675
-    public function setOAuthAccessToken($oAuthAccessToken)
676
-    {
677
-        $this->oauthaccesstoken = $oAuthAccessToken;
678
-    }
679
-
680
-    /**
681
-     * Gets the user's OAuth access secret
682
-     * @category Security-Critical
683
-     * @todo     move me to a collaborator
684
-     * @return null|string
685
-     */
686
-    public function getOAuthAccessSecret()
687
-    {
688
-        return $this->oauthaccesssecret;
689
-    }
690
-
691
-    /**
692
-     * Sets the user's OAuth access secret
693
-     * @todo move me to a collaborator
694
-     *
695
-     * @param string $oAuthAccessSecret
696
-     */
697
-    public function setOAuthAccessSecret($oAuthAccessSecret)
698
-    {
699
-        $this->oauthaccesssecret = $oAuthAccessSecret;
700
-    }
701
-
702
-    #endregion
703
-
704
-    #region user access checks
705
-
706
-    public function isActive()
707
-    {
708
-        return $this->status == self::STATUS_ACTIVE;
709
-    }
710
-
711
-    /**
712
-     * Tests if the user is identified
713
-     *
714
-     * @param IdentificationVerifier $iv
715
-     *
716
-     * @return bool
717
-     * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
718
-     *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
719
-     *       to play it safe for now.
720
-     * @category Security-Critical
721
-     */
722
-    public function isIdentified(IdentificationVerifier $iv)
723
-    {
724
-        if ($this->forceidentified === 0 || $this->forceidentified === "0") {
725
-            // User forced to unidentified in the database.
726
-            return false;
727
-        }
728
-        elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
729
-            // User forced to identified in the database.
730
-            return true;
731
-        }
732
-        else {
733
-            // User not forced to any particular identified status; consult IdentificationVerifier
734
-            return $iv->isUserIdentified($this->getOnWikiName());
735
-        }
736
-    }
737
-
738
-    /**
739
-     * Tests if the user is suspended
740
-     * @return bool
741
-     * @category Security-Critical
742
-     */
743
-    public function isSuspended()
744
-    {
745
-        return $this->status == self::STATUS_SUSPENDED;
746
-    }
747
-
748
-    /**
749
-     * Tests if the user is new
750
-     * @return bool
751
-     * @category Security-Critical
752
-     */
753
-    public function isNewUser()
754
-    {
755
-        return $this->status == self::STATUS_NEW;
756
-    }
757
-
758
-    /**
759
-     * Tests if the user has been declined access to the tool
760
-     * @return bool
761
-     * @category Security-Critical
762
-     */
763
-    public function isDeclined()
764
-    {
765
-        return $this->status == self::STATUS_DECLINED;
766
-    }
767
-
768
-    /**
769
-     * Tests if the user is the community user
770
-     *
771
-     * @todo     decide if this means logged out. I think it usually does.
772
-     * @return bool
773
-     * @category Security-Critical
774
-     */
775
-    public function isCommunityUser()
776
-    {
777
-        return false;
778
-    }
779
-
780
-    #endregion 
781
-
782
-    #region OAuth
783
-
784
-    /**
785
-     * @todo     move me to a collaborator
786
-     *
787
-     * @param bool $useCached
788
-     *
789
-     * @return mixed|null
790
-     * @category Security-Critical
791
-     */
792
-    public function getOAuthIdentity($useCached = false)
793
-    {
794
-        if ($this->oauthaccesstoken === null) {
795
-            $this->clearOAuthData();
796
-        }
797
-
798
-        global $oauthConsumerToken, $oauthMediaWikiCanonicalServer;
799
-
800
-        if ($this->oauthidentitycache == null) {
801
-            $this->identityCache = null;
802
-        }
803
-        else {
804
-            $this->identityCache = unserialize($this->oauthidentitycache);
805
-        }
806
-
807
-        // check the cache
808
-        if (
809
-            $this->identityCache != null &&
810
-            $this->identityCache->aud == $oauthConsumerToken &&
811
-            $this->identityCache->iss == $oauthMediaWikiCanonicalServer
812
-        ) {
813
-            if (
814
-                $useCached || (
815
-                    DateTime::createFromFormat("U", $this->identityCache->iat) < new DateTime() &&
816
-                    DateTime::createFromFormat("U", $this->identityCache->exp) > new DateTime()
817
-                )
818
-            ) {
819
-                // Use cached value - it's either valid or we don't care.
820
-                return $this->identityCache;
821
-            }
822
-            else {
823
-                // Cache expired and not forcing use of cached value
824
-                $this->getIdentityCache();
825
-
826
-                return $this->identityCache;
827
-            }
828
-        }
829
-        else {
830
-            // Cache isn't ours or doesn't exist
831
-            $this->getIdentityCache();
832
-
833
-            return $this->identityCache;
834
-        }
835
-    }
836
-
837
-    /**
838
-     * @todo     move me to a collaborator
839
-     *
840
-     * @param mixed $useCached Set to false for everything where up-to-date data is important.
841
-     *
842
-     * @return mixed
843
-     * @category Security-Critical
844
-     */
845
-    private function getOAuthOnWikiName($useCached = false)
846
-    {
847
-        $identity = $this->getOAuthIdentity($useCached);
848
-        if ($identity !== null) {
849
-            return $identity->username;
850
-        }
851
-
852
-        return false;
853
-    }
854
-
855
-    /**
856
-     * @return bool
857
-     * @todo move me to a collaborator
858
-     */
859
-    public function isOAuthLinked()
860
-    {
861
-        if ($this->onwikiname === "##OAUTH##") {
862
-            return true; // special value. If an account must be oauth linked, this is true.
863
-        }
864
-
865
-        return $this->oauthaccesstoken !== null;
866
-    }
867
-
868
-    /**
869
-     * @return null
870
-     * @todo move me to a collaborator
871
-     */
872
-    public function clearOAuthData()
873
-    {
874
-        $this->identityCache = null;
875
-        $this->oauthidentitycache = null;
876
-        $clearCacheQuery = "UPDATE user SET oauthidentitycache = NULL WHERE id = :id;";
877
-        $this->dbObject->prepare($clearCacheQuery)->execute(array(":id" => $this->id));
878
-
879
-        return null;
880
-    }
881
-
882
-    /**
883
-     * @throws Exception
884
-     * @todo     move me to a collaborator
885
-     * @category Security-Critical
886
-     */
887
-    private function getIdentityCache()
888
-    {
889
-        /** @var IOAuthHelper $oauthHelper */
890
-        global $oauthHelper;
891
-
892
-        try {
893
-            $this->identityCache = $oauthHelper->getIdentityTicket($this->oauthaccesstoken, $this->oauthaccesssecret);
894
-
895
-            $this->oauthidentitycache = serialize($this->identityCache);
896
-            $this->dbObject->prepare("UPDATE user SET oauthidentitycache = :identity WHERE id = :id;")
897
-                ->execute(array(":id" => $this->id, ":identity" => $this->oauthidentitycache));
898
-        }
899
-        catch (UnexpectedValueException $ex) {
900
-            $this->identityCache = null;
901
-            $this->oauthidentitycache = null;
902
-            $this->dbObject->prepare("UPDATE user SET oauthidentitycache = NULL WHERE id = :id;")
903
-                ->execute(array(":id" => $this->id));
904
-
905
-            SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage());
906
-        }
907
-    }
908
-
909
-    /**
910
-     * @return bool
911
-     * @todo move me to a collaborator
912
-     */
913
-    public function oauthCanUse()
914
-    {
915
-        try {
916
-            return in_array('useoauth', $this->getOAuthIdentity()->grants);
917
-        }
918
-        catch (Exception $ex) {
919
-            return false;
920
-        }
921
-    }
922
-
923
-    /**
924
-     * @return bool
925
-     * @todo move me to a collaborator
926
-     */
927
-    public function oauthCanEdit()
928
-    {
929
-        try {
930
-            return in_array('useoauth', $this->getOAuthIdentity()->grants)
931
-            && in_array('createeditmovepage', $this->getOAuthIdentity()->grants)
932
-            && in_array('createtalk', $this->getOAuthIdentity()->rights)
933
-            && in_array('edit', $this->getOAuthIdentity()->rights)
934
-            && in_array('writeapi', $this->getOAuthIdentity()->rights);
935
-        }
936
-        catch (Exception $ex) {
937
-            return false;
938
-        }
939
-    }
940
-
941
-    /**
942
-     * @return bool
943
-     * @todo move me to a collaborator
944
-     */
945
-    public function oauthCanCreateAccount()
946
-    {
947
-        try {
948
-            return in_array('useoauth', $this->getOAuthIdentity()->grants)
949
-            && in_array('createaccount', $this->getOAuthIdentity()->grants)
950
-            && in_array('createaccount', $this->getOAuthIdentity()->rights)
951
-            && in_array('writeapi', $this->getOAuthIdentity()->rights);
952
-        }
953
-        catch (Exception $ex) {
954
-            return false;
955
-        }
956
-    }
957
-
958
-    /**
959
-     * @return bool
960
-     * @todo     move me to a collaborator
961
-     * @category Security-Critical
962
-     */
963
-    protected function oauthCanCheckUser()
964
-    {
965
-        if (!$this->isOAuthLinked()) {
966
-            return false;
967
-        }
968
-
969
-        try {
970
-            $identity = $this->getOAuthIdentity();
971
-
972
-            return in_array('checkuser', $identity->rights);
973
-        }
974
-        catch (Exception $ex) {
975
-            return false;
976
-        }
977
-    }
978
-
979
-    #endregion
980
-
981
-    /**
982
-     * Gets a hash of data for the user to reset their password with.
983
-     * @category Security-Critical
984
-     * @return string
985
-     */
986
-    public function getForgottenPasswordHash()
987
-    {
988
-        return md5($this->username . $this->email . $this->welcome_template . $this->id . $this->password);
989
-    }
990
-
991
-    /**
992
-     * Gets the approval date of the user
993
-     * @return DateTime|false
994
-     */
995
-    public function getApprovalDate()
996
-    {
997
-        $query = $this->dbObject->prepare(<<<SQL
309
+			);
310
+			$statement->bindValue(":forceidentified", $this->forceidentified);
311
+
312
+			$statement->bindValue(':id', $this->id);
313
+			$statement->bindValue(':updateversion', $this->updateversion);
314
+
315
+			$statement->bindValue(':username', $this->username);
316
+			$statement->bindValue(':email', $this->email);
317
+			$statement->bindValue(':password', $this->password);
318
+			$statement->bindValue(':status', $this->status);
319
+			$statement->bindValue(':onwikiname', $this->onwikiname);
320
+			$statement->bindValue(':welcome_sig', $this->welcome_sig);
321
+			$statement->bindValue(':lastactive', $this->lastactive);
322
+			$statement->bindValue(':forcelogout', $this->forcelogout);
323
+			$statement->bindValue(':forceidentified', $this->forceidentified);
324
+			$statement->bindValue(':welcome_template', $this->welcome_template);
325
+			$statement->bindValue(':abortpref', $this->abortpref);
326
+			$statement->bindValue(':confirmationdiff', $this->confirmationdiff);
327
+			$statement->bindValue(':emailsig', $this->emailsig);
328
+			$statement->bindValue(':ort', $this->oauthrequesttoken);
329
+			$statement->bindValue(':ors', $this->oauthrequestsecret);
330
+			$statement->bindValue(':oat', $this->oauthaccesstoken);
331
+			$statement->bindValue(':oas', $this->oauthaccesssecret);
332
+
333
+			if (!$statement->execute()) {
334
+				throw new Exception($statement->errorInfo());
335
+			}
336
+
337
+			if ($statement->rowCount() !== 1) {
338
+				throw new OptimisticLockFailedException();
339
+			}
340
+
341
+			$this->updateversion++;
342
+		}
343
+	}
344
+
345
+	/**
346
+	 * Authenticates the user with the supplied password
347
+	 *
348
+	 * @param string $password
349
+	 *
350
+	 * @return bool
351
+	 * @throws Exception
352
+	 * @category Security-Critical
353
+	 */
354
+	public function authenticate($password)
355
+	{
356
+		$result = AuthUtility::testCredentials($password, $this->password);
357
+
358
+		if ($result === true) {
359
+			// password version is out of date, update it.
360
+			if (!AuthUtility::isCredentialVersionLatest($this->password)) {
361
+				$this->password = AuthUtility::encryptPassword($password);
362
+				$this->save();
363
+			}
364
+		}
365
+
366
+		return $result;
367
+	}
368
+
369
+	#region properties
370
+
371
+	/**
372
+	 * Gets the tool username
373
+	 * @return string
374
+	 */
375
+	public function getUsername()
376
+	{
377
+		return $this->username;
378
+	}
379
+
380
+	/**
381
+	 * Sets the tool username
382
+	 *
383
+	 * @param string $username
384
+	 */
385
+	public function setUsername($username)
386
+	{
387
+		$this->username = $username;
388
+
389
+		// If this isn't a brand new user, then it's a rename, force the logout
390
+		if (!$this->isNew()) {
391
+			$this->forcelogout = 1;
392
+		}
393
+	}
394
+
395
+	/**
396
+	 * Gets the user's email address
397
+	 * @return string
398
+	 */
399
+	public function getEmail()
400
+	{
401
+		return $this->email;
402
+	}
403
+
404
+	/**
405
+	 * Sets the user's email address
406
+	 *
407
+	 * @param string $email
408
+	 */
409
+	public function setEmail($email)
410
+	{
411
+		$this->email = $email;
412
+	}
413
+
414
+	/**
415
+	 * Sets the user's password
416
+	 *
417
+	 * @param string $password the plaintext password
418
+	 *
419
+	 * @category Security-Critical
420
+	 */
421
+	public function setPassword($password)
422
+	{
423
+		$this->password = AuthUtility::encryptPassword($password);
424
+	}
425
+
426
+	/**
427
+	 * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user.
428
+	 * @return string
429
+	 */
430
+	public function getStatus()
431
+	{
432
+		return $this->status;
433
+	}
434
+
435
+	/**
436
+	 * @param string $status
437
+	 */
438
+	public function setStatus($status)
439
+	{
440
+		$this->status = $status;
441
+	}
442
+
443
+	/**
444
+	 * Gets the user's on-wiki name
445
+	 * @return string
446
+	 */
447
+	public function getOnWikiName()
448
+	{
449
+		if ($this->oauthaccesstoken !== null) {
450
+			try {
451
+				return $this->getOAuthOnWikiName();
452
+			}
453
+			catch (Exception $ex) {
454
+				// urm.. log this?
455
+				return $this->onwikiname;
456
+			}
457
+		}
458
+
459
+		return $this->onwikiname;
460
+	}
461
+
462
+	/**
463
+	 * This is probably NOT the function you want!
464
+	 *
465
+	 * Take a look at getOnWikiName() instead.
466
+	 * @return string
467
+	 */
468
+	public function getStoredOnWikiName()
469
+	{
470
+		return $this->onwikiname;
471
+	}
472
+
473
+	/**
474
+	 * Sets the user's on-wiki name
475
+	 *
476
+	 * This can have interesting side-effects with OAuth.
477
+	 *
478
+	 * @param string $onWikiName
479
+	 */
480
+	public function setOnWikiName($onWikiName)
481
+	{
482
+		$this->onwikiname = $onWikiName;
483
+	}
484
+
485
+	/**
486
+	 * Gets the welcome signature
487
+	 * @return string
488
+	 */
489
+	public function getWelcomeSig()
490
+	{
491
+		return $this->welcome_sig;
492
+	}
493
+
494
+	/**
495
+	 * Sets the welcome signature
496
+	 *
497
+	 * @param string $welcomeSig
498
+	 */
499
+	public function setWelcomeSig($welcomeSig)
500
+	{
501
+		$this->welcome_sig = $welcomeSig;
502
+	}
503
+
504
+	/**
505
+	 * Gets the last activity date for the user
506
+	 *
507
+	 * @return string
508
+	 * @todo This should probably return an instance of DateTime
509
+	 */
510
+	public function getLastActive()
511
+	{
512
+		return $this->lastactive;
513
+	}
514
+
515
+	/**
516
+	 * Gets the user's forced logout status
517
+	 *
518
+	 * @return bool
519
+	 */
520
+	public function getForceLogout()
521
+	{
522
+		return $this->forcelogout == 1;
523
+	}
524
+
525
+	/**
526
+	 * Sets the user's forced logout status
527
+	 *
528
+	 * @param bool $forceLogout
529
+	 */
530
+	public function setForceLogout($forceLogout)
531
+	{
532
+		$this->forcelogout = $forceLogout ? 1 : 0;
533
+	}
534
+
535
+	/**
536
+	 * Returns the ID of the welcome template used.
537
+	 * @return int
538
+	 */
539
+	public function getWelcomeTemplate()
540
+	{
541
+		return $this->welcome_template;
542
+	}
543
+
544
+	/**
545
+	 * Sets the ID of the welcome template used.
546
+	 *
547
+	 * @param int $welcomeTemplate
548
+	 */
549
+	public function setWelcomeTemplate($welcomeTemplate)
550
+	{
551
+		$this->welcome_template = $welcomeTemplate;
552
+	}
553
+
554
+	/**
555
+	 * Gets the user's abort preference
556
+	 * @todo this is badly named too! Also a bool that's actually an int.
557
+	 * @return int
558
+	 */
559
+	public function getAbortPref()
560
+	{
561
+		return $this->abortpref;
562
+	}
563
+
564
+	/**
565
+	 * Sets the user's abort preference
566
+	 * @todo rename, retype, and re-comment.
567
+	 *
568
+	 * @param int $abortPreference
569
+	 */
570
+	public function setAbortPref($abortPreference)
571
+	{
572
+		$this->abortpref = $abortPreference;
573
+	}
574
+
575
+	/**
576
+	 * Gets the user's confirmation diff. Unused if OAuth is in use.
577
+	 * @return int the diff ID
578
+	 */
579
+	public function getConfirmationDiff()
580
+	{
581
+		return $this->confirmationdiff;
582
+	}
583
+
584
+	/**
585
+	 * Sets the user's confirmation diff.
586
+	 *
587
+	 * @param int $confirmationDiff
588
+	 */
589
+	public function setConfirmationDiff($confirmationDiff)
590
+	{
591
+		$this->confirmationdiff = $confirmationDiff;
592
+	}
593
+
594
+	/**
595
+	 * Gets the users' email signature used on outbound mail.
596
+	 * @todo rename me!
597
+	 * @return string
598
+	 */
599
+	public function getEmailSig()
600
+	{
601
+		return $this->emailsig;
602
+	}
603
+
604
+	/**
605
+	 * Sets the user's email signature for outbound mail.
606
+	 *
607
+	 * @param string $emailSignature
608
+	 */
609
+	public function setEmailSig($emailSignature)
610
+	{
611
+		$this->emailsig = $emailSignature;
612
+	}
613
+
614
+	/**
615
+	 * Gets the user's OAuth request token.
616
+	 *
617
+	 * @todo move me to a collaborator.
618
+	 * @return null|string
619
+	 */
620
+	public function getOAuthRequestToken()
621
+	{
622
+		return $this->oauthrequesttoken;
623
+	}
624
+
625
+	/**
626
+	 * Sets the user's OAuth request token
627
+	 * @todo move me to a collaborator
628
+	 *
629
+	 * @param string $oAuthRequestToken
630
+	 */
631
+	public function setOAuthRequestToken($oAuthRequestToken)
632
+	{
633
+		$this->oauthrequesttoken = $oAuthRequestToken;
634
+	}
635
+
636
+	/**
637
+	 * Gets the users OAuth request secret
638
+	 * @category Security-Critical
639
+	 * @todo     move me to a collaborator
640
+	 * @return null|string
641
+	 */
642
+	public function getOAuthRequestSecret()
643
+	{
644
+		return $this->oauthrequestsecret;
645
+	}
646
+
647
+	/**
648
+	 * Sets the user's OAuth request secret
649
+	 * @todo move me to a collaborator
650
+	 *
651
+	 * @param string $oAuthRequestSecret
652
+	 */
653
+	public function setOAuthRequestSecret($oAuthRequestSecret)
654
+	{
655
+		$this->oauthrequestsecret = $oAuthRequestSecret;
656
+	}
657
+
658
+	/**
659
+	 * Gets the user's access token
660
+	 * @category Security-Critical
661
+	 * @todo     move me to a collaborator
662
+	 * @return null|string
663
+	 */
664
+	public function getOAuthAccessToken()
665
+	{
666
+		return $this->oauthaccesstoken;
667
+	}
668
+
669
+	/**
670
+	 * Sets the user's access token
671
+	 * @todo move me to a collaborator
672
+	 *
673
+	 * @param string $oAuthAccessToken
674
+	 */
675
+	public function setOAuthAccessToken($oAuthAccessToken)
676
+	{
677
+		$this->oauthaccesstoken = $oAuthAccessToken;
678
+	}
679
+
680
+	/**
681
+	 * Gets the user's OAuth access secret
682
+	 * @category Security-Critical
683
+	 * @todo     move me to a collaborator
684
+	 * @return null|string
685
+	 */
686
+	public function getOAuthAccessSecret()
687
+	{
688
+		return $this->oauthaccesssecret;
689
+	}
690
+
691
+	/**
692
+	 * Sets the user's OAuth access secret
693
+	 * @todo move me to a collaborator
694
+	 *
695
+	 * @param string $oAuthAccessSecret
696
+	 */
697
+	public function setOAuthAccessSecret($oAuthAccessSecret)
698
+	{
699
+		$this->oauthaccesssecret = $oAuthAccessSecret;
700
+	}
701
+
702
+	#endregion
703
+
704
+	#region user access checks
705
+
706
+	public function isActive()
707
+	{
708
+		return $this->status == self::STATUS_ACTIVE;
709
+	}
710
+
711
+	/**
712
+	 * Tests if the user is identified
713
+	 *
714
+	 * @param IdentificationVerifier $iv
715
+	 *
716
+	 * @return bool
717
+	 * @todo     Figure out what on earth is going on with PDO's typecasting here.  Apparently, it returns string("0") for
718
+	 *       the force-unidentified case, and int(1) for the identified case?!  This is quite ugly, but probably needed
719
+	 *       to play it safe for now.
720
+	 * @category Security-Critical
721
+	 */
722
+	public function isIdentified(IdentificationVerifier $iv)
723
+	{
724
+		if ($this->forceidentified === 0 || $this->forceidentified === "0") {
725
+			// User forced to unidentified in the database.
726
+			return false;
727
+		}
728
+		elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
729
+			// User forced to identified in the database.
730
+			return true;
731
+		}
732
+		else {
733
+			// User not forced to any particular identified status; consult IdentificationVerifier
734
+			return $iv->isUserIdentified($this->getOnWikiName());
735
+		}
736
+	}
737
+
738
+	/**
739
+	 * Tests if the user is suspended
740
+	 * @return bool
741
+	 * @category Security-Critical
742
+	 */
743
+	public function isSuspended()
744
+	{
745
+		return $this->status == self::STATUS_SUSPENDED;
746
+	}
747
+
748
+	/**
749
+	 * Tests if the user is new
750
+	 * @return bool
751
+	 * @category Security-Critical
752
+	 */
753
+	public function isNewUser()
754
+	{
755
+		return $this->status == self::STATUS_NEW;
756
+	}
757
+
758
+	/**
759
+	 * Tests if the user has been declined access to the tool
760
+	 * @return bool
761
+	 * @category Security-Critical
762
+	 */
763
+	public function isDeclined()
764
+	{
765
+		return $this->status == self::STATUS_DECLINED;
766
+	}
767
+
768
+	/**
769
+	 * Tests if the user is the community user
770
+	 *
771
+	 * @todo     decide if this means logged out. I think it usually does.
772
+	 * @return bool
773
+	 * @category Security-Critical
774
+	 */
775
+	public function isCommunityUser()
776
+	{
777
+		return false;
778
+	}
779
+
780
+	#endregion 
781
+
782
+	#region OAuth
783
+
784
+	/**
785
+	 * @todo     move me to a collaborator
786
+	 *
787
+	 * @param bool $useCached
788
+	 *
789
+	 * @return mixed|null
790
+	 * @category Security-Critical
791
+	 */
792
+	public function getOAuthIdentity($useCached = false)
793
+	{
794
+		if ($this->oauthaccesstoken === null) {
795
+			$this->clearOAuthData();
796
+		}
797
+
798
+		global $oauthConsumerToken, $oauthMediaWikiCanonicalServer;
799
+
800
+		if ($this->oauthidentitycache == null) {
801
+			$this->identityCache = null;
802
+		}
803
+		else {
804
+			$this->identityCache = unserialize($this->oauthidentitycache);
805
+		}
806
+
807
+		// check the cache
808
+		if (
809
+			$this->identityCache != null &&
810
+			$this->identityCache->aud == $oauthConsumerToken &&
811
+			$this->identityCache->iss == $oauthMediaWikiCanonicalServer
812
+		) {
813
+			if (
814
+				$useCached || (
815
+					DateTime::createFromFormat("U", $this->identityCache->iat) < new DateTime() &&
816
+					DateTime::createFromFormat("U", $this->identityCache->exp) > new DateTime()
817
+				)
818
+			) {
819
+				// Use cached value - it's either valid or we don't care.
820
+				return $this->identityCache;
821
+			}
822
+			else {
823
+				// Cache expired and not forcing use of cached value
824
+				$this->getIdentityCache();
825
+
826
+				return $this->identityCache;
827
+			}
828
+		}
829
+		else {
830
+			// Cache isn't ours or doesn't exist
831
+			$this->getIdentityCache();
832
+
833
+			return $this->identityCache;
834
+		}
835
+	}
836
+
837
+	/**
838
+	 * @todo     move me to a collaborator
839
+	 *
840
+	 * @param mixed $useCached Set to false for everything where up-to-date data is important.
841
+	 *
842
+	 * @return mixed
843
+	 * @category Security-Critical
844
+	 */
845
+	private function getOAuthOnWikiName($useCached = false)
846
+	{
847
+		$identity = $this->getOAuthIdentity($useCached);
848
+		if ($identity !== null) {
849
+			return $identity->username;
850
+		}
851
+
852
+		return false;
853
+	}
854
+
855
+	/**
856
+	 * @return bool
857
+	 * @todo move me to a collaborator
858
+	 */
859
+	public function isOAuthLinked()
860
+	{
861
+		if ($this->onwikiname === "##OAUTH##") {
862
+			return true; // special value. If an account must be oauth linked, this is true.
863
+		}
864
+
865
+		return $this->oauthaccesstoken !== null;
866
+	}
867
+
868
+	/**
869
+	 * @return null
870
+	 * @todo move me to a collaborator
871
+	 */
872
+	public function clearOAuthData()
873
+	{
874
+		$this->identityCache = null;
875
+		$this->oauthidentitycache = null;
876
+		$clearCacheQuery = "UPDATE user SET oauthidentitycache = NULL WHERE id = :id;";
877
+		$this->dbObject->prepare($clearCacheQuery)->execute(array(":id" => $this->id));
878
+
879
+		return null;
880
+	}
881
+
882
+	/**
883
+	 * @throws Exception
884
+	 * @todo     move me to a collaborator
885
+	 * @category Security-Critical
886
+	 */
887
+	private function getIdentityCache()
888
+	{
889
+		/** @var IOAuthHelper $oauthHelper */
890
+		global $oauthHelper;
891
+
892
+		try {
893
+			$this->identityCache = $oauthHelper->getIdentityTicket($this->oauthaccesstoken, $this->oauthaccesssecret);
894
+
895
+			$this->oauthidentitycache = serialize($this->identityCache);
896
+			$this->dbObject->prepare("UPDATE user SET oauthidentitycache = :identity WHERE id = :id;")
897
+				->execute(array(":id" => $this->id, ":identity" => $this->oauthidentitycache));
898
+		}
899
+		catch (UnexpectedValueException $ex) {
900
+			$this->identityCache = null;
901
+			$this->oauthidentitycache = null;
902
+			$this->dbObject->prepare("UPDATE user SET oauthidentitycache = NULL WHERE id = :id;")
903
+				->execute(array(":id" => $this->id));
904
+
905
+			SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage());
906
+		}
907
+	}
908
+
909
+	/**
910
+	 * @return bool
911
+	 * @todo move me to a collaborator
912
+	 */
913
+	public function oauthCanUse()
914
+	{
915
+		try {
916
+			return in_array('useoauth', $this->getOAuthIdentity()->grants);
917
+		}
918
+		catch (Exception $ex) {
919
+			return false;
920
+		}
921
+	}
922
+
923
+	/**
924
+	 * @return bool
925
+	 * @todo move me to a collaborator
926
+	 */
927
+	public function oauthCanEdit()
928
+	{
929
+		try {
930
+			return in_array('useoauth', $this->getOAuthIdentity()->grants)
931
+			&& in_array('createeditmovepage', $this->getOAuthIdentity()->grants)
932
+			&& in_array('createtalk', $this->getOAuthIdentity()->rights)
933
+			&& in_array('edit', $this->getOAuthIdentity()->rights)
934
+			&& in_array('writeapi', $this->getOAuthIdentity()->rights);
935
+		}
936
+		catch (Exception $ex) {
937
+			return false;
938
+		}
939
+	}
940
+
941
+	/**
942
+	 * @return bool
943
+	 * @todo move me to a collaborator
944
+	 */
945
+	public function oauthCanCreateAccount()
946
+	{
947
+		try {
948
+			return in_array('useoauth', $this->getOAuthIdentity()->grants)
949
+			&& in_array('createaccount', $this->getOAuthIdentity()->grants)
950
+			&& in_array('createaccount', $this->getOAuthIdentity()->rights)
951
+			&& in_array('writeapi', $this->getOAuthIdentity()->rights);
952
+		}
953
+		catch (Exception $ex) {
954
+			return false;
955
+		}
956
+	}
957
+
958
+	/**
959
+	 * @return bool
960
+	 * @todo     move me to a collaborator
961
+	 * @category Security-Critical
962
+	 */
963
+	protected function oauthCanCheckUser()
964
+	{
965
+		if (!$this->isOAuthLinked()) {
966
+			return false;
967
+		}
968
+
969
+		try {
970
+			$identity = $this->getOAuthIdentity();
971
+
972
+			return in_array('checkuser', $identity->rights);
973
+		}
974
+		catch (Exception $ex) {
975
+			return false;
976
+		}
977
+	}
978
+
979
+	#endregion
980
+
981
+	/**
982
+	 * Gets a hash of data for the user to reset their password with.
983
+	 * @category Security-Critical
984
+	 * @return string
985
+	 */
986
+	public function getForgottenPasswordHash()
987
+	{
988
+		return md5($this->username . $this->email . $this->welcome_template . $this->id . $this->password);
989
+	}
990
+
991
+	/**
992
+	 * Gets the approval date of the user
993
+	 * @return DateTime|false
994
+	 */
995
+	public function getApprovalDate()
996
+	{
997
+		$query = $this->dbObject->prepare(<<<SQL
998 998
 			SELECT timestamp 
999 999
 			FROM log 
1000 1000
 			WHERE objectid = :userid
@@ -1003,12 +1003,12 @@  discard block
 block discarded – undo
1003 1003
 			ORDER BY id DESC 
1004 1004
 			LIMIT 1;
1005 1005
 SQL
1006
-        );
1007
-        $query->execute(array(":userid" => $this->id));
1006
+		);
1007
+		$query->execute(array(":userid" => $this->id));
1008 1008
 
1009
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
1010
-        $query->closeCursor();
1009
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
1010
+		$query->closeCursor();
1011 1011
 
1012
-        return $data;
1013
-    }
1012
+		return $data;
1013
+	}
1014 1014
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -77,12 +77,10 @@  discard block
 block discarded – undo
77 77
 
78 78
                 if ($user === false) {
79 79
                     self::$currentUser = new CommunityUser();
80
-                }
81
-                else {
80
+                } else {
82 81
                     self::$currentUser = $user;
83 82
                 }
84
-            }
85
-            else {
83
+            } else {
86 84
                 $anonymousCoward = new CommunityUser();
87 85
 
88 86
                 self::$currentUser = $anonymousCoward;
@@ -284,12 +282,10 @@  discard block
 block discarded – undo
284 282
 
285 283
             if ($statement->execute()) {
286 284
                 $this->id = (int)$this->dbObject->lastInsertId();
287
-            }
288
-            else {
285
+            } else {
289 286
                 throw new Exception($statement->errorInfo());
290 287
             }
291
-        }
292
-        else {
288
+        } else {
293 289
             // update
294 290
             $statement = $this->dbObject->prepare(<<<SQL
295 291
 				UPDATE `user` SET 
@@ -724,12 +720,10 @@  discard block
 block discarded – undo
724 720
         if ($this->forceidentified === 0 || $this->forceidentified === "0") {
725 721
             // User forced to unidentified in the database.
726 722
             return false;
727
-        }
728
-        elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
723
+        } elseif ($this->forceidentified === 1 || $this->forceidentified === "1") {
729 724
             // User forced to identified in the database.
730 725
             return true;
731
-        }
732
-        else {
726
+        } else {
733 727
             // User not forced to any particular identified status; consult IdentificationVerifier
734 728
             return $iv->isUserIdentified($this->getOnWikiName());
735 729
         }
@@ -799,8 +793,7 @@  discard block
 block discarded – undo
799 793
 
800 794
         if ($this->oauthidentitycache == null) {
801 795
             $this->identityCache = null;
802
-        }
803
-        else {
796
+        } else {
804 797
             $this->identityCache = unserialize($this->oauthidentitycache);
805 798
         }
806 799
 
@@ -818,15 +811,13 @@  discard block
 block discarded – undo
818 811
             ) {
819 812
                 // Use cached value - it's either valid or we don't care.
820 813
                 return $this->identityCache;
821
-            }
822
-            else {
814
+            } else {
823 815
                 // Cache expired and not forcing use of cached value
824 816
                 $this->getIdentityCache();
825 817
 
826 818
                 return $this->identityCache;
827 819
             }
828
-        }
829
-        else {
820
+        } else {
830 821
             // Cache isn't ours or doesn't exist
831 822
             $this->getIdentityCache();
832 823
 
Please login to merge, or discard this patch.
includes/DataObjects/AntiSpoofCache.php 2 patches
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.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -109,8 +109,7 @@
 block discarded – undo
109 109
 
110 110
             if ($statement->execute()) {
111 111
                 $this->id = (int)$this->dbObject->lastInsertId();
112
-            }
113
-            else {
112
+            } else {
114 113
                 throw new Exception($statement->errorInfo());
115 114
             }
116 115
         }
Please login to merge, or discard this patch.
includes/DataObjects/WelcomeTemplate.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -19,167 +19,167 @@
 block discarded – undo
19 19
  */
20 20
 class WelcomeTemplate extends DataObject
21 21
 {
22
-    /** @var string */
23
-    private $usercode;
24
-    /** @var string */
25
-    private $botcode;
26
-    private $usageCache;
27
-    private $deleted = 0;
28
-
29
-    /**
30
-     * Summary of getAll
31
-     *
32
-     * @param PdoDatabase $database
33
-     *
34
-     * @return WelcomeTemplate[]
35
-     */
36
-    public static function getAll(PdoDatabase $database)
37
-    {
38
-        $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
-
40
-        $statement->execute();
41
-
42
-        $result = array();
43
-        /** @var WelcomeTemplate $v */
44
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
-            $v->setDatabase($database);
46
-            $result[] = $v;
47
-        }
48
-
49
-        return $result;
50
-    }
51
-
52
-    /**
53
-     * @throws Exception
54
-     */
55
-    public function save()
56
-    {
57
-        if ($this->isNew()) {
58
-            // insert
59
-            $statement = $this->dbObject->prepare(<<<SQL
22
+	/** @var string */
23
+	private $usercode;
24
+	/** @var string */
25
+	private $botcode;
26
+	private $usageCache;
27
+	private $deleted = 0;
28
+
29
+	/**
30
+	 * Summary of getAll
31
+	 *
32
+	 * @param PdoDatabase $database
33
+	 *
34
+	 * @return WelcomeTemplate[]
35
+	 */
36
+	public static function getAll(PdoDatabase $database)
37
+	{
38
+		$statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
+
40
+		$statement->execute();
41
+
42
+		$result = array();
43
+		/** @var WelcomeTemplate $v */
44
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
+			$v->setDatabase($database);
46
+			$result[] = $v;
47
+		}
48
+
49
+		return $result;
50
+	}
51
+
52
+	/**
53
+	 * @throws Exception
54
+	 */
55
+	public function save()
56
+	{
57
+		if ($this->isNew()) {
58
+			// insert
59
+			$statement = $this->dbObject->prepare(<<<SQL
60 60
 INSERT INTO welcometemplate (usercode, botcode) VALUES (:usercode, :botcode);
61 61
 SQL
62
-            );
63
-            $statement->bindValue(":usercode", $this->usercode);
64
-            $statement->bindValue(":botcode", $this->botcode);
65
-
66
-            if ($statement->execute()) {
67
-                $this->id = (int)$this->dbObject->lastInsertId();
68
-            }
69
-            else {
70
-                throw new Exception($statement->errorInfo());
71
-            }
72
-        }
73
-        else {
74
-            // update
75
-            $statement = $this->dbObject->prepare(<<<SQL
62
+			);
63
+			$statement->bindValue(":usercode", $this->usercode);
64
+			$statement->bindValue(":botcode", $this->botcode);
65
+
66
+			if ($statement->execute()) {
67
+				$this->id = (int)$this->dbObject->lastInsertId();
68
+			}
69
+			else {
70
+				throw new Exception($statement->errorInfo());
71
+			}
72
+		}
73
+		else {
74
+			// update
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 UPDATE `welcometemplate`
77 77
 SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1
78 78
 WHERE id = :id AND updateversion = :updateversion
79 79
 LIMIT 1;
80 80
 SQL
81
-            );
82
-
83
-            $statement->bindValue(':id', $this->id);
84
-            $statement->bindValue(':updateversion', $this->updateversion);
85
-
86
-            $statement->bindValue(':usercode', $this->usercode);
87
-            $statement->bindValue(':botcode', $this->botcode);
88
-
89
-            if (!$statement->execute()) {
90
-                throw new Exception($statement->errorInfo());
91
-            }
92
-
93
-            if ($statement->rowCount() !== 1) {
94
-                throw new OptimisticLockFailedException();
95
-            }
96
-
97
-            $this->updateversion++;
98
-        }
99
-    }
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getUserCode()
105
-    {
106
-        return $this->usercode;
107
-    }
108
-
109
-    /**
110
-     * @param string $usercode
111
-     */
112
-    public function setUserCode($usercode)
113
-    {
114
-        $this->usercode = $usercode;
115
-    }
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function getBotCode()
121
-    {
122
-        return $this->botcode;
123
-    }
124
-
125
-    /**
126
-     * @param string $botcode
127
-     */
128
-    public function setBotCode($botcode)
129
-    {
130
-        $this->botcode = $botcode;
131
-    }
132
-
133
-    /**
134
-     * @return User[]
135
-     */
136
-    public function getUsersUsingTemplate()
137
-    {
138
-        if ($this->usageCache === null) {
139
-            $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
140
-
141
-            $statement->execute(array(":id" => $this->id));
142
-
143
-            $result = array();
144
-            /** @var WelcomeTemplate $v */
145
-            foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
146
-                $v->setDatabase($this->dbObject);
147
-                $result[] = $v;
148
-            }
149
-
150
-            $this->usageCache = $result;
151
-        }
152
-
153
-        return $this->usageCache;
154
-    }
155
-
156
-    /**
157
-     * Deletes the object from the database
158
-     */
159
-    public function delete()
160
-    {
161
-        if ($this->id === null) {
162
-            // wtf?
163
-            return;
164
-        }
165
-
166
-        $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
167
-        $statement = $this->dbObject->prepare($deleteQuery);
168
-
169
-        $statement->bindValue(":id", $this->id);
170
-        $statement->bindValue(":updateversion", $this->updateversion);
171
-        $statement->execute();
172
-
173
-        if ($statement->rowCount() !== 1) {
174
-            throw new OptimisticLockFailedException();
175
-        }
176
-    }
177
-
178
-    /**
179
-     * @return bool
180
-     */
181
-    public function isDeleted()
182
-    {
183
-        return ((int)$this->deleted) === 1;
184
-    }
81
+			);
82
+
83
+			$statement->bindValue(':id', $this->id);
84
+			$statement->bindValue(':updateversion', $this->updateversion);
85
+
86
+			$statement->bindValue(':usercode', $this->usercode);
87
+			$statement->bindValue(':botcode', $this->botcode);
88
+
89
+			if (!$statement->execute()) {
90
+				throw new Exception($statement->errorInfo());
91
+			}
92
+
93
+			if ($statement->rowCount() !== 1) {
94
+				throw new OptimisticLockFailedException();
95
+			}
96
+
97
+			$this->updateversion++;
98
+		}
99
+	}
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getUserCode()
105
+	{
106
+		return $this->usercode;
107
+	}
108
+
109
+	/**
110
+	 * @param string $usercode
111
+	 */
112
+	public function setUserCode($usercode)
113
+	{
114
+		$this->usercode = $usercode;
115
+	}
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function getBotCode()
121
+	{
122
+		return $this->botcode;
123
+	}
124
+
125
+	/**
126
+	 * @param string $botcode
127
+	 */
128
+	public function setBotCode($botcode)
129
+	{
130
+		$this->botcode = $botcode;
131
+	}
132
+
133
+	/**
134
+	 * @return User[]
135
+	 */
136
+	public function getUsersUsingTemplate()
137
+	{
138
+		if ($this->usageCache === null) {
139
+			$statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
140
+
141
+			$statement->execute(array(":id" => $this->id));
142
+
143
+			$result = array();
144
+			/** @var WelcomeTemplate $v */
145
+			foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
146
+				$v->setDatabase($this->dbObject);
147
+				$result[] = $v;
148
+			}
149
+
150
+			$this->usageCache = $result;
151
+		}
152
+
153
+		return $this->usageCache;
154
+	}
155
+
156
+	/**
157
+	 * Deletes the object from the database
158
+	 */
159
+	public function delete()
160
+	{
161
+		if ($this->id === null) {
162
+			// wtf?
163
+			return;
164
+		}
165
+
166
+		$deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
167
+		$statement = $this->dbObject->prepare($deleteQuery);
168
+
169
+		$statement->bindValue(":id", $this->id);
170
+		$statement->bindValue(":updateversion", $this->updateversion);
171
+		$statement->execute();
172
+
173
+		if ($statement->rowCount() !== 1) {
174
+			throw new OptimisticLockFailedException();
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * @return bool
180
+	 */
181
+	public function isDeleted()
182
+	{
183
+		return ((int)$this->deleted) === 1;
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,12 +65,10 @@
 block discarded – undo
65 65
 
66 66
             if ($statement->execute()) {
67 67
                 $this->id = (int)$this->dbObject->lastInsertId();
68
-            }
69
-            else {
68
+            } else {
70 69
                 throw new Exception($statement->errorInfo());
71 70
             }
72
-        }
73
-        else {
71
+        } else {
74 72
             // update
75 73
             $statement = $this->dbObject->prepare(<<<SQL
76 74
 UPDATE `welcometemplate`
Please login to merge, or discard this patch.