Passed
Push — dependabot/composer/newinterna... ( 13eb18 )
by
unknown
04:37
created
includes/DataObjects/Ban.php 2 patches
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -19,268 +19,268 @@
 block discarded – undo
19 19
  */
20 20
 class Ban extends DataObject
21 21
 {
22
-    private $type;
23
-    private $target;
24
-    private $user;
25
-    private $reason;
26
-    private $date;
27
-    private $duration;
28
-    private $active;
29
-
30
-    /**
31
-     * Gets all active bans, filtered by the optional target.
32
-     *
33
-     * @param string|null $target
34
-     * @param PdoDatabase $database
35
-     *
36
-     * @return Ban[]
37
-     */
38
-    public static function getActiveBans($target, PdoDatabase $database)
39
-    {
40
-        if ($target !== null) {
41
-            $query = <<<SQL
22
+	private $type;
23
+	private $target;
24
+	private $user;
25
+	private $reason;
26
+	private $date;
27
+	private $duration;
28
+	private $active;
29
+
30
+	/**
31
+	 * Gets all active bans, filtered by the optional target.
32
+	 *
33
+	 * @param string|null $target
34
+	 * @param PdoDatabase $database
35
+	 *
36
+	 * @return Ban[]
37
+	 */
38
+	public static function getActiveBans($target, PdoDatabase $database)
39
+	{
40
+		if ($target !== null) {
41
+			$query = <<<SQL
42 42
 SELECT * FROM ban WHERE target = :target AND (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;
43 43
 SQL;
44
-            $statement = $database->prepare($query);
45
-            $statement->bindValue(":target", $target);
46
-        }
47
-        else {
48
-            $query = "SELECT * FROM ban WHERE (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;";
49
-            $statement = $database->prepare($query);
50
-        }
51
-
52
-        $statement->execute();
53
-
54
-        $result = array();
55
-
56
-        /** @var Ban $v */
57
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
58
-            $v->setDatabase($database);
59
-            $result[] = $v;
60
-        }
61
-
62
-        return $result;
63
-    }
64
-
65
-    /**
66
-     * Gets a ban by it's ID if it's currently active.
67
-     *
68
-     * @param     integer $id
69
-     * @param PdoDatabase $database
70
-     *
71
-     * @return Ban
72
-     */
73
-    public static function getActiveId($id, PdoDatabase $database)
74
-    {
75
-        $statement = $database->prepare(<<<SQL
44
+			$statement = $database->prepare($query);
45
+			$statement->bindValue(":target", $target);
46
+		}
47
+		else {
48
+			$query = "SELECT * FROM ban WHERE (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;";
49
+			$statement = $database->prepare($query);
50
+		}
51
+
52
+		$statement->execute();
53
+
54
+		$result = array();
55
+
56
+		/** @var Ban $v */
57
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
58
+			$v->setDatabase($database);
59
+			$result[] = $v;
60
+		}
61
+
62
+		return $result;
63
+	}
64
+
65
+	/**
66
+	 * Gets a ban by it's ID if it's currently active.
67
+	 *
68
+	 * @param     integer $id
69
+	 * @param PdoDatabase $database
70
+	 *
71
+	 * @return Ban
72
+	 */
73
+	public static function getActiveId($id, PdoDatabase $database)
74
+	{
75
+		$statement = $database->prepare(<<<SQL
76 76
 SELECT *
77 77
 FROM ban
78 78
 WHERE id = :id  AND (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;
79 79
 SQL
80
-        );
81
-        $statement->bindValue(":id", $id);
82
-
83
-        $statement->execute();
84
-
85
-        $resultObject = $statement->fetchObject(get_called_class());
86
-
87
-        if ($resultObject != false) {
88
-            $resultObject->setDatabase($database);
89
-        }
90
-
91
-        return $resultObject;
92
-    }
93
-
94
-    /**
95
-     * Get all active bans for a target and type.
96
-     *
97
-     * @param string      $target
98
-     * @param string      $type
99
-     * @param PdoDatabase $database
100
-     *
101
-     * @return Ban
102
-     */
103
-    public static function getBanByTarget($target, $type, PdoDatabase $database)
104
-    {
105
-        $query = <<<SQL
80
+		);
81
+		$statement->bindValue(":id", $id);
82
+
83
+		$statement->execute();
84
+
85
+		$resultObject = $statement->fetchObject(get_called_class());
86
+
87
+		if ($resultObject != false) {
88
+			$resultObject->setDatabase($database);
89
+		}
90
+
91
+		return $resultObject;
92
+	}
93
+
94
+	/**
95
+	 * Get all active bans for a target and type.
96
+	 *
97
+	 * @param string      $target
98
+	 * @param string      $type
99
+	 * @param PdoDatabase $database
100
+	 *
101
+	 * @return Ban
102
+	 */
103
+	public static function getBanByTarget($target, $type, PdoDatabase $database)
104
+	{
105
+		$query = <<<SQL
106 106
 SELECT * FROM ban
107 107
 WHERE type = :type
108 108
 	AND target = :target
109 109
 	AND (duration > UNIX_TIMESTAMP() OR duration = -1)
110 110
 	AND active = 1;
111 111
 SQL;
112
-        $statement = $database->prepare($query);
113
-        $statement->bindValue(":target", $target);
114
-        $statement->bindValue(":type", $type);
112
+		$statement = $database->prepare($query);
113
+		$statement->bindValue(":target", $target);
114
+		$statement->bindValue(":type", $type);
115 115
 
116
-        $statement->execute();
116
+		$statement->execute();
117 117
 
118
-        $resultObject = $statement->fetchObject(get_called_class());
118
+		$resultObject = $statement->fetchObject(get_called_class());
119 119
 
120
-        if ($resultObject != false) {
121
-            $resultObject->setDatabase($database);
122
-        }
120
+		if ($resultObject != false) {
121
+			$resultObject->setDatabase($database);
122
+		}
123 123
 
124
-        return $resultObject;
125
-    }
124
+		return $resultObject;
125
+	}
126 126
 
127
-    /**
128
-     * @throws Exception
129
-     */
130
-    public function save()
131
-    {
132
-        if ($this->isNew()) {
133
-            // insert
134
-            $statement = $this->dbObject->prepare(<<<SQL
127
+	/**
128
+	 * @throws Exception
129
+	 */
130
+	public function save()
131
+	{
132
+		if ($this->isNew()) {
133
+			// insert
134
+			$statement = $this->dbObject->prepare(<<<SQL
135 135
 INSERT INTO `ban` (type, target, user, reason, date, duration, active)
136 136
 VALUES (:type, :target, :user, :reason, CURRENT_TIMESTAMP(), :duration, :active);
137 137
 SQL
138
-            );
139
-            $statement->bindValue(":type", $this->type);
140
-            $statement->bindValue(":target", $this->target);
141
-            $statement->bindValue(":user", $this->user);
142
-            $statement->bindValue(":reason", $this->reason);
143
-            $statement->bindValue(":duration", $this->duration);
144
-            $statement->bindValue(":active", $this->active);
145
-
146
-            if ($statement->execute()) {
147
-                $this->id = (int)$this->dbObject->lastInsertId();
148
-            }
149
-            else {
150
-                throw new Exception($statement->errorInfo());
151
-            }
152
-        }
153
-        else {
154
-            // update
155
-            $statement = $this->dbObject->prepare(<<<SQL
138
+			);
139
+			$statement->bindValue(":type", $this->type);
140
+			$statement->bindValue(":target", $this->target);
141
+			$statement->bindValue(":user", $this->user);
142
+			$statement->bindValue(":reason", $this->reason);
143
+			$statement->bindValue(":duration", $this->duration);
144
+			$statement->bindValue(":active", $this->active);
145
+
146
+			if ($statement->execute()) {
147
+				$this->id = (int)$this->dbObject->lastInsertId();
148
+			}
149
+			else {
150
+				throw new Exception($statement->errorInfo());
151
+			}
152
+		}
153
+		else {
154
+			// update
155
+			$statement = $this->dbObject->prepare(<<<SQL
156 156
 UPDATE `ban`
157 157
 SET duration = :duration, active = :active, user = :user, updateversion = updateversion + 1
158 158
 WHERE id = :id AND updateversion = :updateversion
159 159
 LIMIT 1;
160 160
 SQL
161
-            );
162
-            $statement->bindValue(':id', $this->id);
163
-            $statement->bindValue(':updateversion', $this->updateversion);
164
-
165
-            $statement->bindValue(':duration', $this->duration);
166
-            $statement->bindValue(':active', $this->active);
167
-            $statement->bindValue(':user', $this->user);
168
-
169
-            if (!$statement->execute()) {
170
-                throw new Exception($statement->errorInfo());
171
-            }
172
-
173
-            if ($statement->rowCount() !== 1) {
174
-                throw new OptimisticLockFailedException();
175
-            }
176
-
177
-            $this->updateversion++;
178
-        }
179
-    }
180
-
181
-    /**
182
-     * @return string
183
-     */
184
-    public function getType()
185
-    {
186
-        return $this->type;
187
-    }
188
-
189
-    /**
190
-     * @param string $type
191
-     */
192
-    public function setType($type)
193
-    {
194
-        $this->type = $type;
195
-    }
196
-
197
-    /**
198
-     * @return string
199
-     */
200
-    public function getTarget()
201
-    {
202
-        return $this->target;
203
-    }
204
-
205
-    /**
206
-     * @param string $target
207
-     */
208
-    public function setTarget($target)
209
-    {
210
-        $this->target = $target;
211
-    }
212
-
213
-    /**
214
-     * @return string
215
-     */
216
-    public function getReason()
217
-    {
218
-        return $this->reason;
219
-    }
220
-
221
-    /**
222
-     * @param string $reason
223
-     */
224
-    public function setReason($reason)
225
-    {
226
-        $this->reason = $reason;
227
-    }
228
-
229
-    /**
230
-     * @return mixed
231
-     */
232
-    public function getDate()
233
-    {
234
-        return $this->date;
235
-    }
236
-
237
-    /**
238
-     * @return mixed
239
-     */
240
-    public function getDuration()
241
-    {
242
-        return $this->duration;
243
-    }
244
-
245
-    /**
246
-     * @param mixed $duration
247
-     */
248
-    public function setDuration($duration)
249
-    {
250
-        $this->duration = $duration;
251
-    }
252
-
253
-    /**
254
-     * @return bool
255
-     */
256
-    public function isActive()
257
-    {
258
-        return $this->active == 1;
259
-    }
260
-
261
-    /**
262
-     * @param bool $active
263
-     */
264
-    public function setActive($active)
265
-    {
266
-        $this->active = $active ? 1 : 0;
267
-    }
268
-
269
-    /**
270
-     * @return int
271
-     */
272
-    public function getUser()
273
-    {
274
-        return $this->user;
275
-    }
276
-
277
-    /**
278
-     * @param int $user UserID of user who is setting the ban
279
-     *
280
-     * @throws Exception
281
-     */
282
-    public function setUser($user)
283
-    {
284
-        $this->user = $user;
285
-    }
161
+			);
162
+			$statement->bindValue(':id', $this->id);
163
+			$statement->bindValue(':updateversion', $this->updateversion);
164
+
165
+			$statement->bindValue(':duration', $this->duration);
166
+			$statement->bindValue(':active', $this->active);
167
+			$statement->bindValue(':user', $this->user);
168
+
169
+			if (!$statement->execute()) {
170
+				throw new Exception($statement->errorInfo());
171
+			}
172
+
173
+			if ($statement->rowCount() !== 1) {
174
+				throw new OptimisticLockFailedException();
175
+			}
176
+
177
+			$this->updateversion++;
178
+		}
179
+	}
180
+
181
+	/**
182
+	 * @return string
183
+	 */
184
+	public function getType()
185
+	{
186
+		return $this->type;
187
+	}
188
+
189
+	/**
190
+	 * @param string $type
191
+	 */
192
+	public function setType($type)
193
+	{
194
+		$this->type = $type;
195
+	}
196
+
197
+	/**
198
+	 * @return string
199
+	 */
200
+	public function getTarget()
201
+	{
202
+		return $this->target;
203
+	}
204
+
205
+	/**
206
+	 * @param string $target
207
+	 */
208
+	public function setTarget($target)
209
+	{
210
+		$this->target = $target;
211
+	}
212
+
213
+	/**
214
+	 * @return string
215
+	 */
216
+	public function getReason()
217
+	{
218
+		return $this->reason;
219
+	}
220
+
221
+	/**
222
+	 * @param string $reason
223
+	 */
224
+	public function setReason($reason)
225
+	{
226
+		$this->reason = $reason;
227
+	}
228
+
229
+	/**
230
+	 * @return mixed
231
+	 */
232
+	public function getDate()
233
+	{
234
+		return $this->date;
235
+	}
236
+
237
+	/**
238
+	 * @return mixed
239
+	 */
240
+	public function getDuration()
241
+	{
242
+		return $this->duration;
243
+	}
244
+
245
+	/**
246
+	 * @param mixed $duration
247
+	 */
248
+	public function setDuration($duration)
249
+	{
250
+		$this->duration = $duration;
251
+	}
252
+
253
+	/**
254
+	 * @return bool
255
+	 */
256
+	public function isActive()
257
+	{
258
+		return $this->active == 1;
259
+	}
260
+
261
+	/**
262
+	 * @param bool $active
263
+	 */
264
+	public function setActive($active)
265
+	{
266
+		$this->active = $active ? 1 : 0;
267
+	}
268
+
269
+	/**
270
+	 * @return int
271
+	 */
272
+	public function getUser()
273
+	{
274
+		return $this->user;
275
+	}
276
+
277
+	/**
278
+	 * @param int $user UserID of user who is setting the ban
279
+	 *
280
+	 * @throws Exception
281
+	 */
282
+	public function setUser($user)
283
+	{
284
+		$this->user = $user;
285
+	}
286 286
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@  discard block
 block discarded – undo
43 43
 SQL;
44 44
             $statement = $database->prepare($query);
45 45
             $statement->bindValue(":target", $target);
46
-        }
47
-        else {
46
+        } else {
48 47
             $query = "SELECT * FROM ban WHERE (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;";
49 48
             $statement = $database->prepare($query);
50 49
         }
@@ -145,12 +144,10 @@  discard block
 block discarded – undo
145 144
 
146 145
             if ($statement->execute()) {
147 146
                 $this->id = (int)$this->dbObject->lastInsertId();
148
-            }
149
-            else {
147
+            } else {
150 148
                 throw new Exception($statement->errorInfo());
151 149
             }
152
-        }
153
-        else {
150
+        } else {
154 151
             // update
155 152
             $statement = $this->dbObject->prepare(<<<SQL
156 153
 UPDATE `ban`
Please login to merge, or discard this patch.
includes/DataObjects/Log.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -17,151 +17,151 @@
 block discarded – undo
17 17
  */
18 18
 class Log extends DataObject
19 19
 {
20
-    /** @var int */
21
-    private $objectid;
22
-    /** @var string */
23
-    private $objecttype;
24
-    /** @var int */
25
-    private $user;
26
-    /** @var string */
27
-    private $action;
28
-    private $timestamp;
29
-    /** @var string|null */
30
-    private $comment;
31
-
32
-    /**
33
-     * @throws Exception
34
-     */
35
-    public function save()
36
-    {
37
-        if ($this->isNew()) {
38
-            $statement = $this->dbObject->prepare(<<<SQL
20
+	/** @var int */
21
+	private $objectid;
22
+	/** @var string */
23
+	private $objecttype;
24
+	/** @var int */
25
+	private $user;
26
+	/** @var string */
27
+	private $action;
28
+	private $timestamp;
29
+	/** @var string|null */
30
+	private $comment;
31
+
32
+	/**
33
+	 * @throws Exception
34
+	 */
35
+	public function save()
36
+	{
37
+		if ($this->isNew()) {
38
+			$statement = $this->dbObject->prepare(<<<SQL
39 39
                 INSERT INTO log (objectid, objecttype, user, action, timestamp, comment) 
40 40
                 VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment);
41 41
 SQL
42
-            );
43
-
44
-            $statement->bindValue(":id", $this->objectid);
45
-            $statement->bindValue(":type", $this->objecttype);
46
-            $statement->bindValue(":user", $this->user);
47
-            $statement->bindValue(":action", $this->action);
48
-            $statement->bindValue(":comment", $this->comment);
49
-
50
-            if ($statement->execute()) {
51
-                $this->id = (int)$this->dbObject->lastInsertId();
52
-            }
53
-            else {
54
-                throw new Exception($statement->errorInfo());
55
-            }
56
-        }
57
-        else {
58
-            throw new Exception("Updating logs is not available");
59
-        }
60
-    }
61
-
62
-    /**
63
-     * @throws Exception
64
-     */
65
-    public function delete()
66
-    {
67
-        throw new Exception("Deleting logs is not available.");
68
-    }
69
-
70
-    /**
71
-     * @return int
72
-     */
73
-    public function getObjectId()
74
-    {
75
-        return $this->objectid;
76
-    }
77
-
78
-    /**
79
-     * Summary of setObjectId
80
-     *
81
-     * @param int $objectId
82
-     */
83
-    public function setObjectId($objectId)
84
-    {
85
-        $this->objectid = $objectId;
86
-    }
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getObjectType()
92
-    {
93
-        return $this->objecttype;
94
-    }
95
-
96
-    /**
97
-     * Summary of setObjectType
98
-     *
99
-     * @param string $objectType
100
-     */
101
-    public function setObjectType($objectType)
102
-    {
103
-        $this->objecttype = $objectType;
104
-    }
105
-
106
-    /**
107
-     * @return int
108
-     */
109
-    public function getUser()
110
-    {
111
-        return $this->user;
112
-    }
113
-
114
-    /**
115
-     * Summary of setUser
116
-     *
117
-     * @param User $user
118
-     */
119
-    public function setUser(User $user)
120
-    {
121
-        $this->user = $user->getId();
122
-    }
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function getAction()
128
-    {
129
-        return $this->action;
130
-    }
131
-
132
-    /**
133
-     * Summary of setAction
134
-     *
135
-     * @param string $action
136
-     */
137
-    public function setAction($action)
138
-    {
139
-        $this->action = $action;
140
-    }
141
-
142
-    /**
143
-     * @return DateTimeImmutable
144
-     */
145
-    public function getTimestamp()
146
-    {
147
-        return new DateTimeImmutable($this->timestamp);
148
-    }
149
-
150
-    /**
151
-     * @return string|null
152
-     */
153
-    public function getComment()
154
-    {
155
-        return $this->comment;
156
-    }
157
-
158
-    /**
159
-     * Summary of setComment
160
-     *
161
-     * @param string $comment
162
-     */
163
-    public function setComment($comment)
164
-    {
165
-        $this->comment = $comment;
166
-    }
42
+			);
43
+
44
+			$statement->bindValue(":id", $this->objectid);
45
+			$statement->bindValue(":type", $this->objecttype);
46
+			$statement->bindValue(":user", $this->user);
47
+			$statement->bindValue(":action", $this->action);
48
+			$statement->bindValue(":comment", $this->comment);
49
+
50
+			if ($statement->execute()) {
51
+				$this->id = (int)$this->dbObject->lastInsertId();
52
+			}
53
+			else {
54
+				throw new Exception($statement->errorInfo());
55
+			}
56
+		}
57
+		else {
58
+			throw new Exception("Updating logs is not available");
59
+		}
60
+	}
61
+
62
+	/**
63
+	 * @throws Exception
64
+	 */
65
+	public function delete()
66
+	{
67
+		throw new Exception("Deleting logs is not available.");
68
+	}
69
+
70
+	/**
71
+	 * @return int
72
+	 */
73
+	public function getObjectId()
74
+	{
75
+		return $this->objectid;
76
+	}
77
+
78
+	/**
79
+	 * Summary of setObjectId
80
+	 *
81
+	 * @param int $objectId
82
+	 */
83
+	public function setObjectId($objectId)
84
+	{
85
+		$this->objectid = $objectId;
86
+	}
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getObjectType()
92
+	{
93
+		return $this->objecttype;
94
+	}
95
+
96
+	/**
97
+	 * Summary of setObjectType
98
+	 *
99
+	 * @param string $objectType
100
+	 */
101
+	public function setObjectType($objectType)
102
+	{
103
+		$this->objecttype = $objectType;
104
+	}
105
+
106
+	/**
107
+	 * @return int
108
+	 */
109
+	public function getUser()
110
+	{
111
+		return $this->user;
112
+	}
113
+
114
+	/**
115
+	 * Summary of setUser
116
+	 *
117
+	 * @param User $user
118
+	 */
119
+	public function setUser(User $user)
120
+	{
121
+		$this->user = $user->getId();
122
+	}
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function getAction()
128
+	{
129
+		return $this->action;
130
+	}
131
+
132
+	/**
133
+	 * Summary of setAction
134
+	 *
135
+	 * @param string $action
136
+	 */
137
+	public function setAction($action)
138
+	{
139
+		$this->action = $action;
140
+	}
141
+
142
+	/**
143
+	 * @return DateTimeImmutable
144
+	 */
145
+	public function getTimestamp()
146
+	{
147
+		return new DateTimeImmutable($this->timestamp);
148
+	}
149
+
150
+	/**
151
+	 * @return string|null
152
+	 */
153
+	public function getComment()
154
+	{
155
+		return $this->comment;
156
+	}
157
+
158
+	/**
159
+	 * Summary of setComment
160
+	 *
161
+	 * @param string $comment
162
+	 */
163
+	public function setComment($comment)
164
+	{
165
+		$this->comment = $comment;
166
+	}
167 167
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,12 +49,10 @@
 block discarded – undo
49 49
 
50 50
             if ($statement->execute()) {
51 51
                 $this->id = (int)$this->dbObject->lastInsertId();
52
-            }
53
-            else {
52
+            } else {
54 53
                 throw new Exception($statement->errorInfo());
55 54
             }
56
-        }
57
-        else {
55
+        } else {
58 56
             throw new Exception("Updating logs is not available");
59 57
         }
60 58
     }
Please login to merge, or discard this patch.
includes/Pages/PageEditComment.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -20,67 +20,67 @@
 block discarded – undo
20 20
 
21 21
 class PageEditComment extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     * @throws ApplicationLogicException
26
-     */
27
-    protected function main()
28
-    {
29
-        $commentId = WebRequest::getInt('id');
30
-        if ($commentId === null) {
31
-            throw new ApplicationLogicException('Comment ID not specified');
32
-        }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 * @throws ApplicationLogicException
26
+	 */
27
+	protected function main()
28
+	{
29
+		$commentId = WebRequest::getInt('id');
30
+		if ($commentId === null) {
31
+			throw new ApplicationLogicException('Comment ID not specified');
32
+		}
33 33
 
34
-        $database = $this->getDatabase();
34
+		$database = $this->getDatabase();
35 35
 
36
-        /** @var Comment $comment */
37
-        $comment = Comment::getById($commentId, $database);
38
-        if ($comment === false) {
39
-            throw new ApplicationLogicException('Comment not found');
40
-        }
36
+		/** @var Comment $comment */
37
+		$comment = Comment::getById($commentId, $database);
38
+		if ($comment === false) {
39
+			throw new ApplicationLogicException('Comment not found');
40
+		}
41 41
 
42
-        $currentUser = User::getCurrent($database);
43
-        if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
-            throw new AccessDeniedException($this->getSecurityManager());
45
-        }
42
+		$currentUser = User::getCurrent($database);
43
+		if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
+			throw new AccessDeniedException($this->getSecurityManager());
45
+		}
46 46
 
47
-        /** @var Request $request */
48
-        $request = Request::getById($comment->getRequest(), $database);
47
+		/** @var Request $request */
48
+		$request = Request::getById($comment->getRequest(), $database);
49 49
 
50
-        if ($request === false) {
51
-            throw new ApplicationLogicException('Request was not found.');
52
-        }
50
+		if ($request === false) {
51
+			throw new ApplicationLogicException('Request was not found.');
52
+		}
53 53
 
54
-        if (WebRequest::wasPosted()) {
55
-            $this->validateCSRFToken();
56
-            $newComment = WebRequest::postString('newcomment');
57
-            $visibility = WebRequest::postString('visibility');
54
+		if (WebRequest::wasPosted()) {
55
+			$this->validateCSRFToken();
56
+			$newComment = WebRequest::postString('newcomment');
57
+			$visibility = WebRequest::postString('visibility');
58 58
 
59
-            if ($visibility !== 'user' && $visibility !== 'admin') {
60
-                throw new ApplicationLogicException('Comment visibility is not valid');
61
-            }
59
+			if ($visibility !== 'user' && $visibility !== 'admin') {
60
+				throw new ApplicationLogicException('Comment visibility is not valid');
61
+			}
62 62
 
63
-            // optimisticly lock from the load of the edit comment form
64
-            $updateVersion = WebRequest::postInt('updateversion');
65
-            $comment->setUpdateVersion($updateVersion);
63
+			// optimisticly lock from the load of the edit comment form
64
+			$updateVersion = WebRequest::postInt('updateversion');
65
+			$comment->setUpdateVersion($updateVersion);
66 66
 
67
-            $comment->setComment($newComment);
68
-            $comment->setVisibility($visibility);
67
+			$comment->setComment($newComment);
68
+			$comment->setVisibility($visibility);
69 69
 
70
-            $comment->save();
70
+			$comment->save();
71 71
 
72
-            Logger::editComment($database, $comment, $request);
73
-            $this->getNotificationHelper()->commentEdited($comment, $request);
74
-            SessionAlert::success("Comment has been saved successfully");
72
+			Logger::editComment($database, $comment, $request);
73
+			$this->getNotificationHelper()->commentEdited($comment, $request);
74
+			SessionAlert::success("Comment has been saved successfully");
75 75
 
76
-            $this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
-        }
78
-        else {
79
-            $this->assignCSRFToken();
80
-            $this->assign('comment', $comment);
81
-            $this->assign('request', $request);
82
-            $this->assign('user', User::getById($comment->getUser(), $database));
83
-            $this->setTemplate('edit-comment.tpl');
84
-        }
85
-    }
76
+			$this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
+		}
78
+		else {
79
+			$this->assignCSRFToken();
80
+			$this->assign('comment', $comment);
81
+			$this->assign('request', $request);
82
+			$this->assign('user', User::getById($comment->getUser(), $database));
83
+			$this->setTemplate('edit-comment.tpl');
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@
 block discarded – undo
74 74
             SessionAlert::success("Comment has been saved successfully");
75 75
 
76 76
             $this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
-        }
78
-        else {
77
+        } else {
79 78
             $this->assignCSRFToken();
80 79
             $this->assign('comment', $comment);
81 80
             $this->assign('request', $request);
Please login to merge, or discard this patch.
includes/Pages/Page404.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@
 block discarded – undo
12 12
 
13 13
 class Page404 extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no actions are called.
17
-     */
18
-    protected function main()
19
-    {
20
-        if (!headers_sent()) {
21
-            header("HTTP/1.1 404 Not Found");
22
-        }
15
+	/**
16
+	 * Main function for this page, when no actions are called.
17
+	 */
18
+	protected function main()
19
+	{
20
+		if (!headers_sent()) {
21
+			header("HTTP/1.1 404 Not Found");
22
+		}
23 23
 
24
-        $this->setTemplate("404.tpl");
25
-    }
24
+		$this->setTemplate("404.tpl");
25
+	}
26 26
 
27
-    protected function isProtectedPage()
28
-    {
29
-        return false;
30
-    }
27
+	protected function isProtectedPage()
28
+	{
29
+		return false;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
includes/Pages/PageSearch.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -20,156 +20,156 @@
 block discarded – undo
20 20
 
21 21
 class PageSearch extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     */
26
-    protected function main()
27
-    {
28
-        $this->setHtmlTitle('Search');
29
-
30
-        // Dual-mode page
31
-        if (WebRequest::wasPosted()) {
32
-            $this->validateCSRFToken();
33
-
34
-            $searchType = WebRequest::postString('type');
35
-            $searchTerm = WebRequest::postString('term');
36
-
37
-            $validationError = "";
38
-            if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) {
39
-                SessionAlert::error($validationError, "Search error");
40
-                $this->redirect("search");
41
-
42
-                return;
43
-            }
44
-
45
-            $results = array();
46
-
47
-            switch ($searchType) {
48
-                case 'name':
49
-                    $results = $this->getNameSearchResults($searchTerm);
50
-                    break;
51
-                case 'email':
52
-                    $results = $this->getEmailSearchResults($searchTerm);
53
-                    break;
54
-                case 'ip':
55
-                    $results = $this->getIpSearchResults($searchTerm);
56
-                    break;
57
-            }
58
-
59
-            // deal with results
60
-            $this->assign('requests', $results);
61
-            $this->assign('term', $searchTerm);
62
-            $this->assign('target', $searchType);
63
-
64
-            $userIds = array_map(
65
-                function(Request $entry) {
66
-                    return $entry->getReserved();
67
-                },
68
-                $results);
69
-            $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
70
-            $this->assign('userlist', $userList);
71
-
72
-            $currentUser = User::getCurrent($this->getDatabase());
73
-            $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
74
-            $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
75
-
76
-            $this->assignCSRFToken();
77
-            $this->setTemplate('search/searchResult.tpl');
78
-        }
79
-        else {
80
-            $this->assignCSRFToken();
81
-            $this->setTemplate('search/searchForm.tpl');
82
-        }
83
-    }
84
-
85
-    /**
86
-     * Gets search results by name
87
-     *
88
-     * @param string $searchTerm
89
-     *
90
-     * @returns Request[]
91
-     */
92
-    private function getNameSearchResults($searchTerm)
93
-    {
94
-        $padded = '%' . $searchTerm . '%';
95
-
96
-        /** @var Request[] $requests */
97
-        $requests = RequestSearchHelper::get($this->getDatabase())
98
-            ->byName($padded)
99
-            ->excludingPurgedData($this->getSiteConfiguration())
100
-            ->fetch();
101
-
102
-        return $requests;
103
-    }
104
-
105
-    /**
106
-     * Gets search results by email
107
-     *
108
-     * @param string $searchTerm
109
-     *
110
-     * @return Request[]
111
-     * @throws ApplicationLogicException
112
-     */
113
-    private function getEmailSearchResults($searchTerm)
114
-    {
115
-        if ($searchTerm === "@") {
116
-            throw new ApplicationLogicException('The search term "@" is not valid for email address searches!');
117
-        }
118
-
119
-        $padded = '%' . $searchTerm . '%';
120
-
121
-        /** @var Request[] $requests */
122
-        $requests = RequestSearchHelper::get($this->getDatabase())
123
-            ->byEmailAddress($padded)
124
-            ->excludingPurgedData($this->getSiteConfiguration())
125
-            ->fetch();
126
-
127
-        return $requests;
128
-    }
129
-
130
-    /**
131
-     * Gets search results by IP address or XFF IP address
132
-     *
133
-     * @param string $searchTerm
134
-     *
135
-     * @returns Request[]
136
-     */
137
-    private function getIpSearchResults($searchTerm)
138
-    {
139
-        /** @var Request[] $requests */
140
-        $requests = RequestSearchHelper::get($this->getDatabase())
141
-            ->byIp($searchTerm)
142
-            ->excludingPurgedData($this->getSiteConfiguration())
143
-            ->fetch();
144
-
145
-        return $requests;
146
-    }
147
-
148
-    /**
149
-     * @param string $searchType
150
-     * @param string $searchTerm
151
-     *
152
-     * @param string $errorMessage
153
-     *
154
-     * @return bool true if parameters are valid
155
-     * @throws ApplicationLogicException
156
-     */
157
-    protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage)
158
-    {
159
-        if (!in_array($searchType, array('name', 'email', 'ip'))) {
160
-            $errorMessage = 'Unknown search type';
161
-
162
-            return false;
163
-        }
164
-
165
-        if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) {
166
-            $errorMessage = 'No search term specified entered';
167
-
168
-            return false;
169
-        }
170
-
171
-        $errorMessage = "";
172
-
173
-        return true;
174
-    }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->setHtmlTitle('Search');
29
+
30
+		// Dual-mode page
31
+		if (WebRequest::wasPosted()) {
32
+			$this->validateCSRFToken();
33
+
34
+			$searchType = WebRequest::postString('type');
35
+			$searchTerm = WebRequest::postString('term');
36
+
37
+			$validationError = "";
38
+			if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) {
39
+				SessionAlert::error($validationError, "Search error");
40
+				$this->redirect("search");
41
+
42
+				return;
43
+			}
44
+
45
+			$results = array();
46
+
47
+			switch ($searchType) {
48
+				case 'name':
49
+					$results = $this->getNameSearchResults($searchTerm);
50
+					break;
51
+				case 'email':
52
+					$results = $this->getEmailSearchResults($searchTerm);
53
+					break;
54
+				case 'ip':
55
+					$results = $this->getIpSearchResults($searchTerm);
56
+					break;
57
+			}
58
+
59
+			// deal with results
60
+			$this->assign('requests', $results);
61
+			$this->assign('term', $searchTerm);
62
+			$this->assign('target', $searchType);
63
+
64
+			$userIds = array_map(
65
+				function(Request $entry) {
66
+					return $entry->getReserved();
67
+				},
68
+				$results);
69
+			$userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
70
+			$this->assign('userlist', $userList);
71
+
72
+			$currentUser = User::getCurrent($this->getDatabase());
73
+			$this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
74
+			$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
75
+
76
+			$this->assignCSRFToken();
77
+			$this->setTemplate('search/searchResult.tpl');
78
+		}
79
+		else {
80
+			$this->assignCSRFToken();
81
+			$this->setTemplate('search/searchForm.tpl');
82
+		}
83
+	}
84
+
85
+	/**
86
+	 * Gets search results by name
87
+	 *
88
+	 * @param string $searchTerm
89
+	 *
90
+	 * @returns Request[]
91
+	 */
92
+	private function getNameSearchResults($searchTerm)
93
+	{
94
+		$padded = '%' . $searchTerm . '%';
95
+
96
+		/** @var Request[] $requests */
97
+		$requests = RequestSearchHelper::get($this->getDatabase())
98
+			->byName($padded)
99
+			->excludingPurgedData($this->getSiteConfiguration())
100
+			->fetch();
101
+
102
+		return $requests;
103
+	}
104
+
105
+	/**
106
+	 * Gets search results by email
107
+	 *
108
+	 * @param string $searchTerm
109
+	 *
110
+	 * @return Request[]
111
+	 * @throws ApplicationLogicException
112
+	 */
113
+	private function getEmailSearchResults($searchTerm)
114
+	{
115
+		if ($searchTerm === "@") {
116
+			throw new ApplicationLogicException('The search term "@" is not valid for email address searches!');
117
+		}
118
+
119
+		$padded = '%' . $searchTerm . '%';
120
+
121
+		/** @var Request[] $requests */
122
+		$requests = RequestSearchHelper::get($this->getDatabase())
123
+			->byEmailAddress($padded)
124
+			->excludingPurgedData($this->getSiteConfiguration())
125
+			->fetch();
126
+
127
+		return $requests;
128
+	}
129
+
130
+	/**
131
+	 * Gets search results by IP address or XFF IP address
132
+	 *
133
+	 * @param string $searchTerm
134
+	 *
135
+	 * @returns Request[]
136
+	 */
137
+	private function getIpSearchResults($searchTerm)
138
+	{
139
+		/** @var Request[] $requests */
140
+		$requests = RequestSearchHelper::get($this->getDatabase())
141
+			->byIp($searchTerm)
142
+			->excludingPurgedData($this->getSiteConfiguration())
143
+			->fetch();
144
+
145
+		return $requests;
146
+	}
147
+
148
+	/**
149
+	 * @param string $searchType
150
+	 * @param string $searchTerm
151
+	 *
152
+	 * @param string $errorMessage
153
+	 *
154
+	 * @return bool true if parameters are valid
155
+	 * @throws ApplicationLogicException
156
+	 */
157
+	protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage)
158
+	{
159
+		if (!in_array($searchType, array('name', 'email', 'ip'))) {
160
+			$errorMessage = 'Unknown search type';
161
+
162
+			return false;
163
+		}
164
+
165
+		if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) {
166
+			$errorMessage = 'No search term specified entered';
167
+
168
+			return false;
169
+		}
170
+
171
+		$errorMessage = "";
172
+
173
+		return true;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,8 @@  discard block
 block discarded – undo
62 62
             $this->assign('target', $searchType);
63 63
 
64 64
             $userIds = array_map(
65
-                function(Request $entry) {
65
+                function(Request $entry)
66
+                {
66 67
                     return $entry->getReserved();
67 68
                 },
68 69
                 $results);
@@ -75,8 +76,7 @@  discard block
 block discarded – undo
75 76
 
76 77
             $this->assignCSRFToken();
77 78
             $this->setTemplate('search/searchResult.tpl');
78
-        }
79
-        else {
79
+        } else {
80 80
             $this->assignCSRFToken();
81 81
             $this->setTemplate('search/searchForm.tpl');
82 82
         }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterOption.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@
 block discarded – undo
12 12
 
13 13
 class PageRegisterOption extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $this->setTemplate('registration/option.tpl');
22
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->setTemplate('registration/option.tpl');
22
+	}
23 23
 
24
-    protected function isProtectedPage()
25
-    {
26
-        return false;
27
-    }
24
+	protected function isProtectedPage()
25
+	{
26
+		return false;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterBase.php 2 patches
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -18,202 +18,202 @@
 block discarded – undo
18 18
 
19 19
 abstract class PageRegisterBase extends InternalPageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     */
24
-    protected function main()
25
-    {
26
-        $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup();
27
-
28
-        // Dual-mode page
29
-        if (WebRequest::wasPosted()) {
30
-            $this->validateCSRFToken();
31
-
32
-            try {
33
-                $this->handlePost($useOAuthSignup);
34
-            }
35
-            catch (ApplicationLogicException $ex) {
36
-                SessionAlert::error($ex->getMessage());
37
-                $this->redirect('register');
38
-            }
39
-        }
40
-        else {
41
-            $this->assignCSRFToken();
42
-            $this->assign("useOAuthSignup", $useOAuthSignup);
43
-            $this->setTemplate($this->getRegistrationTemplate());
44
-        }
45
-    }
46
-
47
-    protected abstract function getRegistrationTemplate();
48
-
49
-    protected function isProtectedPage()
50
-    {
51
-        return false;
52
-    }
53
-
54
-    /**
55
-     * @param string $emailAddress
56
-     *
57
-     * @throws ApplicationLogicException
58
-     */
59
-    protected function validateUniqueEmail($emailAddress)
60
-    {
61
-        $query = 'SELECT COUNT(id) FROM user WHERE email = :email';
62
-        $statement = $this->getDatabase()->prepare($query);
63
-        $statement->execute(array(':email' => $emailAddress));
64
-
65
-        if ($statement->fetchColumn() > 0) {
66
-            throw new ApplicationLogicException('That email address is already in use on this system.');
67
-        }
68
-
69
-        $statement->closeCursor();
70
-    }
71
-
72
-    /**
73
-     * @param $emailAddress
74
-     * @param $password
75
-     * @param $username
76
-     * @param $useOAuthSignup
77
-     * @param $confirmationId
78
-     * @param $onwikiUsername
79
-     *
80
-     * @throws ApplicationLogicException
81
-     */
82
-    protected function validateRequest(
83
-        $emailAddress,
84
-        $password,
85
-        $username,
86
-        $useOAuthSignup,
87
-        $confirmationId,
88
-        $onwikiUsername
89
-    ) {
90
-        if (!WebRequest::postBoolean('guidelines')) {
91
-            throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.');
92
-        }
93
-
94
-        $this->validateGeneralInformation($emailAddress, $password, $username);
95
-        $this->validateUniqueEmail($emailAddress);
96
-        $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername);
97
-    }
98
-
99
-    /**
100
-     * @param $useOAuthSignup
101
-     * @param $confirmationId
102
-     * @param $onwikiUsername
103
-     *
104
-     * @throws ApplicationLogicException
105
-     */
106
-    protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername)
107
-    {
108
-        if (!$useOAuthSignup) {
109
-            if ($confirmationId === null || $confirmationId <= 0) {
110
-                throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.');
111
-            }
112
-
113
-            if ($onwikiUsername === null) {
114
-                throw new ApplicationLogicException('Please specify your on-wiki username.');
115
-            }
116
-        }
117
-    }
118
-
119
-    /**
120
-     * @param $emailAddress
121
-     * @param $password
122
-     * @param $username
123
-     *
124
-     * @throws ApplicationLogicException
125
-     */
126
-    protected function validateGeneralInformation($emailAddress, $password, $username)
127
-    {
128
-        if ($emailAddress === null) {
129
-            throw new ApplicationLogicException('Your email address appears to be invalid!');
130
-        }
131
-
132
-        if ($password !== WebRequest::postString('pass2')) {
133
-            throw new ApplicationLogicException('Your passwords did not match, please try again.');
134
-        }
135
-
136
-        if (User::getByUsername($username, $this->getDatabase()) !== false) {
137
-            throw new ApplicationLogicException('That username is already in use on this system.');
138
-        }
139
-    }
140
-
141
-    /**
142
-     * @param $useOAuthSignup
143
-     *
144
-     * @throws ApplicationLogicException
145
-     * @throws \Exception
146
-     */
147
-    protected function handlePost($useOAuthSignup)
148
-    {
149
-        // Get the data
150
-        $emailAddress = WebRequest::postEmail('email');
151
-        $password = WebRequest::postString('pass');
152
-        $username = WebRequest::postString('name');
153
-
154
-        // Only set if OAuth is disabled
155
-        $confirmationId = WebRequest::postInt('conf_revid');
156
-        $onwikiUsername = WebRequest::postString('wname');
157
-
158
-        // Do some validation
159
-        $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId,
160
-            $onwikiUsername);
161
-
162
-        $database = $this->getDatabase();
163
-
164
-        $user = new User();
165
-        $user->setDatabase($database);
166
-
167
-        $user->setUsername($username);
168
-        $user->setPassword($password);
169
-        $user->setEmail($emailAddress);
170
-
171
-        if (!$useOAuthSignup) {
172
-            $user->setOnWikiName($onwikiUsername);
173
-            $user->setConfirmationDiff($confirmationId);
174
-        }
175
-
176
-        $user->save();
177
-
178
-        $defaultRole = $this->getDefaultRole();
179
-
180
-        $role = new UserRole();
181
-        $role->setDatabase($database);
182
-        $role->setUser($user->getId());
183
-        $role->setRole($defaultRole);
184
-        $role->save();
185
-
186
-        // Log now to get the signup date.
187
-        Logger::newUser($database, $user);
188
-        Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array());
189
-
190
-        if ($useOAuthSignup) {
191
-            $oauthHelper = $this->getOAuthHelper();
192
-
193
-            $requestToken = $oauthHelper->getRequestToken();
194
-            $user->setOAuthRequestToken($requestToken->key);
195
-            $user->setOAuthRequestSecret($requestToken->secret);
196
-            $user->save();
197
-
198
-            WebRequest::setPartialLogin($user);
199
-
200
-            $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
201
-        }
202
-        else {
203
-            // only notify if we're not using the oauth signup.
204
-            $this->getNotificationHelper()->userNew($user);
205
-            WebRequest::setLoggedInUser($user);
206
-            $this->redirect('preferences');
207
-        }
208
-    }
209
-
210
-    protected abstract function getDefaultRole();
211
-
212
-    /**
213
-     * Entry point for registration complete
214
-     */
215
-    protected function done()
216
-    {
217
-        $this->setTemplate('registration/alert-registrationcomplete.tpl');
218
-    }
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 */
24
+	protected function main()
25
+	{
26
+		$useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup();
27
+
28
+		// Dual-mode page
29
+		if (WebRequest::wasPosted()) {
30
+			$this->validateCSRFToken();
31
+
32
+			try {
33
+				$this->handlePost($useOAuthSignup);
34
+			}
35
+			catch (ApplicationLogicException $ex) {
36
+				SessionAlert::error($ex->getMessage());
37
+				$this->redirect('register');
38
+			}
39
+		}
40
+		else {
41
+			$this->assignCSRFToken();
42
+			$this->assign("useOAuthSignup", $useOAuthSignup);
43
+			$this->setTemplate($this->getRegistrationTemplate());
44
+		}
45
+	}
46
+
47
+	protected abstract function getRegistrationTemplate();
48
+
49
+	protected function isProtectedPage()
50
+	{
51
+		return false;
52
+	}
53
+
54
+	/**
55
+	 * @param string $emailAddress
56
+	 *
57
+	 * @throws ApplicationLogicException
58
+	 */
59
+	protected function validateUniqueEmail($emailAddress)
60
+	{
61
+		$query = 'SELECT COUNT(id) FROM user WHERE email = :email';
62
+		$statement = $this->getDatabase()->prepare($query);
63
+		$statement->execute(array(':email' => $emailAddress));
64
+
65
+		if ($statement->fetchColumn() > 0) {
66
+			throw new ApplicationLogicException('That email address is already in use on this system.');
67
+		}
68
+
69
+		$statement->closeCursor();
70
+	}
71
+
72
+	/**
73
+	 * @param $emailAddress
74
+	 * @param $password
75
+	 * @param $username
76
+	 * @param $useOAuthSignup
77
+	 * @param $confirmationId
78
+	 * @param $onwikiUsername
79
+	 *
80
+	 * @throws ApplicationLogicException
81
+	 */
82
+	protected function validateRequest(
83
+		$emailAddress,
84
+		$password,
85
+		$username,
86
+		$useOAuthSignup,
87
+		$confirmationId,
88
+		$onwikiUsername
89
+	) {
90
+		if (!WebRequest::postBoolean('guidelines')) {
91
+			throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.');
92
+		}
93
+
94
+		$this->validateGeneralInformation($emailAddress, $password, $username);
95
+		$this->validateUniqueEmail($emailAddress);
96
+		$this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername);
97
+	}
98
+
99
+	/**
100
+	 * @param $useOAuthSignup
101
+	 * @param $confirmationId
102
+	 * @param $onwikiUsername
103
+	 *
104
+	 * @throws ApplicationLogicException
105
+	 */
106
+	protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername)
107
+	{
108
+		if (!$useOAuthSignup) {
109
+			if ($confirmationId === null || $confirmationId <= 0) {
110
+				throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.');
111
+			}
112
+
113
+			if ($onwikiUsername === null) {
114
+				throw new ApplicationLogicException('Please specify your on-wiki username.');
115
+			}
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * @param $emailAddress
121
+	 * @param $password
122
+	 * @param $username
123
+	 *
124
+	 * @throws ApplicationLogicException
125
+	 */
126
+	protected function validateGeneralInformation($emailAddress, $password, $username)
127
+	{
128
+		if ($emailAddress === null) {
129
+			throw new ApplicationLogicException('Your email address appears to be invalid!');
130
+		}
131
+
132
+		if ($password !== WebRequest::postString('pass2')) {
133
+			throw new ApplicationLogicException('Your passwords did not match, please try again.');
134
+		}
135
+
136
+		if (User::getByUsername($username, $this->getDatabase()) !== false) {
137
+			throw new ApplicationLogicException('That username is already in use on this system.');
138
+		}
139
+	}
140
+
141
+	/**
142
+	 * @param $useOAuthSignup
143
+	 *
144
+	 * @throws ApplicationLogicException
145
+	 * @throws \Exception
146
+	 */
147
+	protected function handlePost($useOAuthSignup)
148
+	{
149
+		// Get the data
150
+		$emailAddress = WebRequest::postEmail('email');
151
+		$password = WebRequest::postString('pass');
152
+		$username = WebRequest::postString('name');
153
+
154
+		// Only set if OAuth is disabled
155
+		$confirmationId = WebRequest::postInt('conf_revid');
156
+		$onwikiUsername = WebRequest::postString('wname');
157
+
158
+		// Do some validation
159
+		$this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId,
160
+			$onwikiUsername);
161
+
162
+		$database = $this->getDatabase();
163
+
164
+		$user = new User();
165
+		$user->setDatabase($database);
166
+
167
+		$user->setUsername($username);
168
+		$user->setPassword($password);
169
+		$user->setEmail($emailAddress);
170
+
171
+		if (!$useOAuthSignup) {
172
+			$user->setOnWikiName($onwikiUsername);
173
+			$user->setConfirmationDiff($confirmationId);
174
+		}
175
+
176
+		$user->save();
177
+
178
+		$defaultRole = $this->getDefaultRole();
179
+
180
+		$role = new UserRole();
181
+		$role->setDatabase($database);
182
+		$role->setUser($user->getId());
183
+		$role->setRole($defaultRole);
184
+		$role->save();
185
+
186
+		// Log now to get the signup date.
187
+		Logger::newUser($database, $user);
188
+		Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array());
189
+
190
+		if ($useOAuthSignup) {
191
+			$oauthHelper = $this->getOAuthHelper();
192
+
193
+			$requestToken = $oauthHelper->getRequestToken();
194
+			$user->setOAuthRequestToken($requestToken->key);
195
+			$user->setOAuthRequestSecret($requestToken->secret);
196
+			$user->save();
197
+
198
+			WebRequest::setPartialLogin($user);
199
+
200
+			$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
201
+		}
202
+		else {
203
+			// only notify if we're not using the oauth signup.
204
+			$this->getNotificationHelper()->userNew($user);
205
+			WebRequest::setLoggedInUser($user);
206
+			$this->redirect('preferences');
207
+		}
208
+	}
209
+
210
+	protected abstract function getDefaultRole();
211
+
212
+	/**
213
+	 * Entry point for registration complete
214
+	 */
215
+	protected function done()
216
+	{
217
+		$this->setTemplate('registration/alert-registrationcomplete.tpl');
218
+	}
219 219
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@  discard block
 block discarded – undo
36 36
                 SessionAlert::error($ex->getMessage());
37 37
                 $this->redirect('register');
38 38
             }
39
-        }
40
-        else {
39
+        } else {
41 40
             $this->assignCSRFToken();
42 41
             $this->assign("useOAuthSignup", $useOAuthSignup);
43 42
             $this->setTemplate($this->getRegistrationTemplate());
@@ -198,8 +197,7 @@  discard block
 block discarded – undo
198 197
             WebRequest::setPartialLogin($user);
199 198
 
200 199
             $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
201
-        }
202
-        else {
200
+        } else {
203 201
             // only notify if we're not using the oauth signup.
204 202
             $this->getNotificationHelper()->userNew($user);
205 203
             WebRequest::setLoggedInUser($user);
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterStandard.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
 
11 11
 class PageRegisterStandard extends PageRegisterBase
12 12
 {
13
-    /**
14
-     * @return string
15
-     */
16
-    protected function getRegistrationTemplate()
17
-    {
18
-        return "registration/register.tpl";
19
-    }
13
+	/**
14
+	 * @return string
15
+	 */
16
+	protected function getRegistrationTemplate()
17
+	{
18
+		return "registration/register.tpl";
19
+	}
20 20
 
21
-    /**
22
-     * @return string
23
-     */
24
-    protected function getDefaultRole()
25
-    {
26
-        return 'user';
27
-    }
21
+	/**
22
+	 * @return string
23
+	 */
24
+	protected function getDefaultRole()
25
+	{
26
+		return 'user';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/PageSiteNotice.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 
16 16
 class PageSiteNotice extends InternalPageBase
17 17
 {
18
-    /**
19
-     * Main function for this page, when no specific actions are called.
20
-     * @return void
21
-     */
22
-    protected function main()
23
-    {
24
-        $this->setHtmlTitle('Site Notice');
25
-
26
-        $database = $this->getDatabase();
27
-
28
-        /** @var SiteNotice $siteNoticeMessage */
29
-        $siteNoticeMessage = SiteNotice::getById(1, $database);
30
-
31
-        // Dual-mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-
35
-            $siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
-            $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
-            $siteNoticeMessage->save();
38
-
39
-            Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
-            $this->getNotificationHelper()->siteNoticeEdited();
41
-
42
-            $this->redirect();
43
-        }
44
-        else {
45
-            $this->assignCSRFToken();
46
-
47
-            $this->setTemplate('site-notice/edit-form.tpl');
48
-            $this->assign('message', $siteNoticeMessage);
49
-        }
50
-    }
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->setHtmlTitle('Site Notice');
25
+
26
+		$database = $this->getDatabase();
27
+
28
+		/** @var SiteNotice $siteNoticeMessage */
29
+		$siteNoticeMessage = SiteNotice::getById(1, $database);
30
+
31
+		// Dual-mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+
35
+			$siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
+			$siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
+			$siteNoticeMessage->save();
38
+
39
+			Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
+			$this->getNotificationHelper()->siteNoticeEdited();
41
+
42
+			$this->redirect();
43
+		}
44
+		else {
45
+			$this->assignCSRFToken();
46
+
47
+			$this->setTemplate('site-notice/edit-form.tpl');
48
+			$this->assign('message', $siteNoticeMessage);
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@
 block discarded – undo
40 40
             $this->getNotificationHelper()->siteNoticeEdited();
41 41
 
42 42
             $this->redirect();
43
-        }
44
-        else {
43
+        } else {
45 44
             $this->assignCSRFToken();
46 45
 
47 46
             $this->setTemplate('site-notice/edit-form.tpl');
Please login to merge, or discard this patch.