Failed Conditions
Push — php8 ( f7c5b0...7c6ccd )
by Simon
15:01
created
includes/DataObjects/User.php 2 patches
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -22,153 +22,153 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class User extends DataObject
24 24
 {
25
-    const STATUS_ACTIVE = 'Active';
26
-    const STATUS_DEACTIVATED = 'Deactivated';
27
-    const STATUS_NEW = 'New';
28
-
29
-    private static CommunityUser $community;
30
-
31
-    private $username;
32
-    private $email;
33
-    private $status = self::STATUS_NEW;
34
-    private $onwikiname;
35
-    private $lastactive = "0000-00-00 00:00:00";
36
-    private $forcelogout = 0;
37
-    private $forceidentified = null;
38
-    private $confirmationdiff = 0;
39
-    /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
40
-    private static $currentUser;
41
-    #region Object load methods
42
-
43
-    /**
44
-     * Gets the currently logged in user
45
-     *
46
-     * @param PdoDatabase $database
47
-     *
48
-     * @return User|CommunityUser
49
-     */
50
-    public static function getCurrent(PdoDatabase $database)
51
-    {
52
-        if (self::$currentUser === null) {
53
-            $sessionId = WebRequest::getSessionUserId();
54
-
55
-            if ($sessionId !== null) {
56
-                /** @var User $user */
57
-                $user = self::getById($sessionId, $database);
58
-
59
-                if ($user === false) {
60
-                    self::$currentUser = new CommunityUser();
61
-                }
62
-                else {
63
-                    self::$currentUser = $user;
64
-                }
65
-            }
66
-            else {
67
-                $anonymousCoward = new CommunityUser();
68
-
69
-                self::$currentUser = $anonymousCoward;
70
-            }
71
-        }
72
-
73
-        return self::$currentUser;
74
-    }
75
-
76
-    /**
77
-     * Gets a user by their user ID
78
-     *
79
-     * Pass -1 to get the community user.
80
-     *
81
-     * @param int|null    $id
82
-     * @param PdoDatabase $database
83
-     *
84
-     * @return User|false
85
-     */
86
-    public static function getById($id, PdoDatabase $database)
87
-    {
88
-        if ($id === null || $id == -1) {
89
-            return new CommunityUser();
90
-        }
91
-
92
-        /** @var User|false $user */
93
-        $user = parent::getById($id, $database);
94
-
95
-        return $user;
96
-    }
97
-
98
-    public static function getCommunity(): CommunityUser
99
-    {
100
-        if (!isset(self::$community)) {
101
-            self::$community = new CommunityUser();
102
-        }
103
-
104
-        return self::$community;
105
-    }
106
-
107
-    /**
108
-     * Gets a user by their username
109
-     *
110
-     * @param  string      $username
111
-     * @param  PdoDatabase $database
112
-     *
113
-     * @return CommunityUser|User|false
114
-     */
115
-    public static function getByUsername($username, PdoDatabase $database)
116
-    {
117
-        if ($username === self::getCommunity()->getUsername()) {
118
-            return new CommunityUser();
119
-        }
120
-
121
-        $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
122
-        $statement->bindValue(":id", $username);
123
-
124
-        $statement->execute();
125
-
126
-        $resultObject = $statement->fetchObject(get_called_class());
127
-
128
-        if ($resultObject != false) {
129
-            $resultObject->setDatabase($database);
130
-        }
131
-
132
-        return $resultObject;
133
-    }
134
-
135
-    /**
136
-     * Gets a user by their on-wiki username.
137
-     *
138
-     * @param string      $username
139
-     * @param PdoDatabase $database
140
-     *
141
-     * @return User|false
142
-     */
143
-    public static function getByOnWikiUsername($username, PdoDatabase $database)
144
-    {
145
-        $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
146
-        $statement->bindValue(":id", $username);
147
-        $statement->execute();
148
-
149
-        $resultObject = $statement->fetchObject(get_called_class());
150
-
151
-        if ($resultObject != false) {
152
-            $resultObject->setDatabase($database);
153
-
154
-            return $resultObject;
155
-        }
156
-
157
-        return false;
158
-    }
159
-
160
-    #endregion
161
-
162
-    /**
163
-     * Saves the current object
164
-     *
165
-     * @throws Exception
166
-     */
167
-    public function save()
168
-    {
169
-        if ($this->isNew()) {
170
-            // insert
171
-            $statement = $this->dbObject->prepare(<<<SQL
25
+	const STATUS_ACTIVE = 'Active';
26
+	const STATUS_DEACTIVATED = 'Deactivated';
27
+	const STATUS_NEW = 'New';
28
+
29
+	private static CommunityUser $community;
30
+
31
+	private $username;
32
+	private $email;
33
+	private $status = self::STATUS_NEW;
34
+	private $onwikiname;
35
+	private $lastactive = "0000-00-00 00:00:00";
36
+	private $forcelogout = 0;
37
+	private $forceidentified = null;
38
+	private $confirmationdiff = 0;
39
+	/** @var User Cache variable of the current user - it's never going to change in the middle of a request. */
40
+	private static $currentUser;
41
+	#region Object load methods
42
+
43
+	/**
44
+	 * Gets the currently logged in user
45
+	 *
46
+	 * @param PdoDatabase $database
47
+	 *
48
+	 * @return User|CommunityUser
49
+	 */
50
+	public static function getCurrent(PdoDatabase $database)
51
+	{
52
+		if (self::$currentUser === null) {
53
+			$sessionId = WebRequest::getSessionUserId();
54
+
55
+			if ($sessionId !== null) {
56
+				/** @var User $user */
57
+				$user = self::getById($sessionId, $database);
58
+
59
+				if ($user === false) {
60
+					self::$currentUser = new CommunityUser();
61
+				}
62
+				else {
63
+					self::$currentUser = $user;
64
+				}
65
+			}
66
+			else {
67
+				$anonymousCoward = new CommunityUser();
68
+
69
+				self::$currentUser = $anonymousCoward;
70
+			}
71
+		}
72
+
73
+		return self::$currentUser;
74
+	}
75
+
76
+	/**
77
+	 * Gets a user by their user ID
78
+	 *
79
+	 * Pass -1 to get the community user.
80
+	 *
81
+	 * @param int|null    $id
82
+	 * @param PdoDatabase $database
83
+	 *
84
+	 * @return User|false
85
+	 */
86
+	public static function getById($id, PdoDatabase $database)
87
+	{
88
+		if ($id === null || $id == -1) {
89
+			return new CommunityUser();
90
+		}
91
+
92
+		/** @var User|false $user */
93
+		$user = parent::getById($id, $database);
94
+
95
+		return $user;
96
+	}
97
+
98
+	public static function getCommunity(): CommunityUser
99
+	{
100
+		if (!isset(self::$community)) {
101
+			self::$community = new CommunityUser();
102
+		}
103
+
104
+		return self::$community;
105
+	}
106
+
107
+	/**
108
+	 * Gets a user by their username
109
+	 *
110
+	 * @param  string      $username
111
+	 * @param  PdoDatabase $database
112
+	 *
113
+	 * @return CommunityUser|User|false
114
+	 */
115
+	public static function getByUsername($username, PdoDatabase $database)
116
+	{
117
+		if ($username === self::getCommunity()->getUsername()) {
118
+			return new CommunityUser();
119
+		}
120
+
121
+		$statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;");
122
+		$statement->bindValue(":id", $username);
123
+
124
+		$statement->execute();
125
+
126
+		$resultObject = $statement->fetchObject(get_called_class());
127
+
128
+		if ($resultObject != false) {
129
+			$resultObject->setDatabase($database);
130
+		}
131
+
132
+		return $resultObject;
133
+	}
134
+
135
+	/**
136
+	 * Gets a user by their on-wiki username.
137
+	 *
138
+	 * @param string      $username
139
+	 * @param PdoDatabase $database
140
+	 *
141
+	 * @return User|false
142
+	 */
143
+	public static function getByOnWikiUsername($username, PdoDatabase $database)
144
+	{
145
+		$statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;");
146
+		$statement->bindValue(":id", $username);
147
+		$statement->execute();
148
+
149
+		$resultObject = $statement->fetchObject(get_called_class());
150
+
151
+		if ($resultObject != false) {
152
+			$resultObject->setDatabase($database);
153
+
154
+			return $resultObject;
155
+		}
156
+
157
+		return false;
158
+	}
159
+
160
+	#endregion
161
+
162
+	/**
163
+	 * Saves the current object
164
+	 *
165
+	 * @throws Exception
166
+	 */
167
+	public function save()
168
+	{
169
+		if ($this->isNew()) {
170
+			// insert
171
+			$statement = $this->dbObject->prepare(<<<SQL
172 172
 				INSERT INTO `user` ( 
173 173
 					username, email, status, onwikiname, 
174 174
 					lastactive, forcelogout, forceidentified,
@@ -179,25 +179,25 @@  discard block
 block discarded – undo
179 179
 					:confirmationdiff
180 180
 				);
181 181
 SQL
182
-            );
183
-            $statement->bindValue(":username", $this->username);
184
-            $statement->bindValue(":email", $this->email);
185
-            $statement->bindValue(":status", $this->status);
186
-            $statement->bindValue(":onwikiname", $this->onwikiname);
187
-            $statement->bindValue(":lastactive", $this->lastactive);
188
-            $statement->bindValue(":forcelogout", $this->forcelogout);
189
-            $statement->bindValue(":confirmationdiff", $this->confirmationdiff);
190
-
191
-            if ($statement->execute()) {
192
-                $this->id = (int)$this->dbObject->lastInsertId();
193
-            }
194
-            else {
195
-                throw new Exception($statement->errorInfo());
196
-            }
197
-        }
198
-        else {
199
-            // update
200
-            $statement = $this->dbObject->prepare(<<<SQL
182
+			);
183
+			$statement->bindValue(":username", $this->username);
184
+			$statement->bindValue(":email", $this->email);
185
+			$statement->bindValue(":status", $this->status);
186
+			$statement->bindValue(":onwikiname", $this->onwikiname);
187
+			$statement->bindValue(":lastactive", $this->lastactive);
188
+			$statement->bindValue(":forcelogout", $this->forcelogout);
189
+			$statement->bindValue(":confirmationdiff", $this->confirmationdiff);
190
+
191
+			if ($statement->execute()) {
192
+				$this->id = (int)$this->dbObject->lastInsertId();
193
+			}
194
+			else {
195
+				throw new Exception($statement->errorInfo());
196
+			}
197
+		}
198
+		else {
199
+			// update
200
+			$statement = $this->dbObject->prepare(<<<SQL
201 201
 				UPDATE `user` SET 
202 202
 					username = :username, email = :email, 
203 203
 					status = :status,
@@ -208,233 +208,233 @@  discard block
 block discarded – undo
208 208
                     updateversion = updateversion + 1
209 209
 				WHERE id = :id AND updateversion = :updateversion;
210 210
 SQL
211
-            );
212
-
213
-            $statement->bindValue(':id', $this->id);
214
-            $statement->bindValue(':updateversion', $this->updateversion);
215
-
216
-            $statement->bindValue(':username', $this->username);
217
-            $statement->bindValue(':email', $this->email);
218
-            $statement->bindValue(':status', $this->status);
219
-            $statement->bindValue(':onwikiname', $this->onwikiname);
220
-            $statement->bindValue(':lastactive', $this->lastactive);
221
-            $statement->bindValue(':forcelogout', $this->forcelogout);
222
-            $statement->bindValue(':confirmationdiff', $this->confirmationdiff);
223
-
224
-            if (!$statement->execute()) {
225
-                throw new Exception($statement->errorInfo());
226
-            }
227
-
228
-            if ($statement->rowCount() !== 1) {
229
-                throw new OptimisticLockFailedException();
230
-            }
231
-
232
-            $this->updateversion++;
233
-        }
234
-    }
235
-
236
-    #region properties
237
-
238
-    /**
239
-     * Gets the tool username
240
-     * @return string
241
-     */
242
-    public function getUsername()
243
-    {
244
-        return $this->username;
245
-    }
246
-
247
-    /**
248
-     * Sets the tool username
249
-     *
250
-     * @param string $username
251
-     */
252
-    public function setUsername($username)
253
-    {
254
-        $this->username = $username;
255
-
256
-        // If this isn't a brand new user, then it's a rename, force the logout
257
-        if (!$this->isNew()) {
258
-            $this->forcelogout = 1;
259
-        }
260
-    }
261
-
262
-    /**
263
-     * Gets the user's email address
264
-     * @return string
265
-     */
266
-    public function getEmail()
267
-    {
268
-        return $this->email;
269
-    }
270
-
271
-    /**
272
-     * Sets the user's email address
273
-     *
274
-     * @param string $email
275
-     */
276
-    public function setEmail($email)
277
-    {
278
-        $this->email = $email;
279
-    }
280
-
281
-    /**
282
-     * Gets the status (Active, New, Deactivated, etc) of the user.
283
-     * @return string
284
-     */
285
-    public function getStatus()
286
-    {
287
-        return $this->status;
288
-    }
289
-
290
-    /**
291
-     * @param string $status
292
-     */
293
-    public function setStatus($status)
294
-    {
295
-        $this->status = $status;
296
-    }
297
-
298
-    /**
299
-     * Gets the user's on-wiki name
300
-     * @return string
301
-     */
302
-    public function getOnWikiName()
303
-    {
304
-        return $this->onwikiname;
305
-    }
306
-
307
-    /**
308
-     * Sets the user's on-wiki name
309
-     *
310
-     * This can have interesting side-effects with OAuth.
311
-     *
312
-     * @param string $onWikiName
313
-     */
314
-    public function setOnWikiName($onWikiName)
315
-    {
316
-        $this->onwikiname = $onWikiName;
317
-    }
318
-
319
-    /**
320
-     * Gets the last activity date for the user
321
-     *
322
-     * @return string
323
-     * @todo This should probably return an instance of DateTime
324
-     */
325
-    public function getLastActive()
326
-    {
327
-        return $this->lastactive;
328
-    }
329
-
330
-    /**
331
-     * Gets the user's forced logout status
332
-     *
333
-     * @return bool
334
-     */
335
-    public function getForceLogout()
336
-    {
337
-        return $this->forcelogout == 1;
338
-    }
339
-
340
-    /**
341
-     * Sets the user's forced logout status
342
-     *
343
-     * @param bool $forceLogout
344
-     */
345
-    public function setForceLogout($forceLogout)
346
-    {
347
-        $this->forcelogout = $forceLogout ? 1 : 0;
348
-    }
349
-
350
-    /**
351
-     * Gets the user's confirmation diff. Unused if OAuth is in use.
352
-     * @return int the diff ID
353
-     */
354
-    public function getConfirmationDiff()
355
-    {
356
-        return $this->confirmationdiff;
357
-    }
358
-
359
-    /**
360
-     * Sets the user's confirmation diff.
361
-     *
362
-     * @param int $confirmationDiff
363
-     */
364
-    public function setConfirmationDiff($confirmationDiff)
365
-    {
366
-        $this->confirmationdiff = $confirmationDiff;
367
-    }
368
-
369
-    #endregion
370
-
371
-    #region user access checks
372
-
373
-    public function isActive()
374
-    {
375
-        return $this->status == self::STATUS_ACTIVE;
376
-    }
377
-
378
-    /**
379
-     * DO NOT USE FOR TESTING IDENTIFICATION STATUS.
380
-     *
381
-     * This only returns any overrides in the database for identification status,
382
-     * and is thus not suitable on its own to determine if a user is identified.
383
-     *
384
-     * Most (all?) users should have a null value here; this is only here as an
385
-     * emergency override in case things go horribly, horribly wrong. For
386
-     * example, when WMF completely change the layout of the ID noticeboard.
387
-     */
388
-    public function getForceIdentified(): ?bool
389
-    {
390
-        if ($this->forceidentified === null) {
391
-            return null;
392
-        }
393
-
394
-        return $this->forceidentified === 1;
395
-    }
396
-
397
-    /**
398
-     * Tests if the user is new
399
-     * @return bool
400
-     * @category Security-Critical
401
-     */
402
-    public function isNewUser()
403
-    {
404
-        return $this->status == self::STATUS_NEW;
405
-    }
406
-
407
-    /**
408
-     * Tests if the user has been deactivated and is unable to access the tool
409
-     * @return bool
410
-     * @category Security-Critical
411
-     */
412
-    public function isDeactivated(): bool
413
-    {
414
-        return $this->status == self::STATUS_DEACTIVATED;
415
-    }
416
-
417
-    /**
418
-     * Tests if the user is the community user
419
-     *
420
-     * @todo     decide if this means logged out. I think it usually does.
421
-     * @return bool
422
-     * @category Security-Critical
423
-     */
424
-    public function isCommunityUser()
425
-    {
426
-        return false;
427
-    }
428
-
429
-    #endregion 
430
-
431
-    /**
432
-     * Gets the approval date of the user
433
-     * @return DateTime|false
434
-     */
435
-    public function getApprovalDate()
436
-    {
437
-        $query = $this->dbObject->prepare(<<<SQL
211
+			);
212
+
213
+			$statement->bindValue(':id', $this->id);
214
+			$statement->bindValue(':updateversion', $this->updateversion);
215
+
216
+			$statement->bindValue(':username', $this->username);
217
+			$statement->bindValue(':email', $this->email);
218
+			$statement->bindValue(':status', $this->status);
219
+			$statement->bindValue(':onwikiname', $this->onwikiname);
220
+			$statement->bindValue(':lastactive', $this->lastactive);
221
+			$statement->bindValue(':forcelogout', $this->forcelogout);
222
+			$statement->bindValue(':confirmationdiff', $this->confirmationdiff);
223
+
224
+			if (!$statement->execute()) {
225
+				throw new Exception($statement->errorInfo());
226
+			}
227
+
228
+			if ($statement->rowCount() !== 1) {
229
+				throw new OptimisticLockFailedException();
230
+			}
231
+
232
+			$this->updateversion++;
233
+		}
234
+	}
235
+
236
+	#region properties
237
+
238
+	/**
239
+	 * Gets the tool username
240
+	 * @return string
241
+	 */
242
+	public function getUsername()
243
+	{
244
+		return $this->username;
245
+	}
246
+
247
+	/**
248
+	 * Sets the tool username
249
+	 *
250
+	 * @param string $username
251
+	 */
252
+	public function setUsername($username)
253
+	{
254
+		$this->username = $username;
255
+
256
+		// If this isn't a brand new user, then it's a rename, force the logout
257
+		if (!$this->isNew()) {
258
+			$this->forcelogout = 1;
259
+		}
260
+	}
261
+
262
+	/**
263
+	 * Gets the user's email address
264
+	 * @return string
265
+	 */
266
+	public function getEmail()
267
+	{
268
+		return $this->email;
269
+	}
270
+
271
+	/**
272
+	 * Sets the user's email address
273
+	 *
274
+	 * @param string $email
275
+	 */
276
+	public function setEmail($email)
277
+	{
278
+		$this->email = $email;
279
+	}
280
+
281
+	/**
282
+	 * Gets the status (Active, New, Deactivated, etc) of the user.
283
+	 * @return string
284
+	 */
285
+	public function getStatus()
286
+	{
287
+		return $this->status;
288
+	}
289
+
290
+	/**
291
+	 * @param string $status
292
+	 */
293
+	public function setStatus($status)
294
+	{
295
+		$this->status = $status;
296
+	}
297
+
298
+	/**
299
+	 * Gets the user's on-wiki name
300
+	 * @return string
301
+	 */
302
+	public function getOnWikiName()
303
+	{
304
+		return $this->onwikiname;
305
+	}
306
+
307
+	/**
308
+	 * Sets the user's on-wiki name
309
+	 *
310
+	 * This can have interesting side-effects with OAuth.
311
+	 *
312
+	 * @param string $onWikiName
313
+	 */
314
+	public function setOnWikiName($onWikiName)
315
+	{
316
+		$this->onwikiname = $onWikiName;
317
+	}
318
+
319
+	/**
320
+	 * Gets the last activity date for the user
321
+	 *
322
+	 * @return string
323
+	 * @todo This should probably return an instance of DateTime
324
+	 */
325
+	public function getLastActive()
326
+	{
327
+		return $this->lastactive;
328
+	}
329
+
330
+	/**
331
+	 * Gets the user's forced logout status
332
+	 *
333
+	 * @return bool
334
+	 */
335
+	public function getForceLogout()
336
+	{
337
+		return $this->forcelogout == 1;
338
+	}
339
+
340
+	/**
341
+	 * Sets the user's forced logout status
342
+	 *
343
+	 * @param bool $forceLogout
344
+	 */
345
+	public function setForceLogout($forceLogout)
346
+	{
347
+		$this->forcelogout = $forceLogout ? 1 : 0;
348
+	}
349
+
350
+	/**
351
+	 * Gets the user's confirmation diff. Unused if OAuth is in use.
352
+	 * @return int the diff ID
353
+	 */
354
+	public function getConfirmationDiff()
355
+	{
356
+		return $this->confirmationdiff;
357
+	}
358
+
359
+	/**
360
+	 * Sets the user's confirmation diff.
361
+	 *
362
+	 * @param int $confirmationDiff
363
+	 */
364
+	public function setConfirmationDiff($confirmationDiff)
365
+	{
366
+		$this->confirmationdiff = $confirmationDiff;
367
+	}
368
+
369
+	#endregion
370
+
371
+	#region user access checks
372
+
373
+	public function isActive()
374
+	{
375
+		return $this->status == self::STATUS_ACTIVE;
376
+	}
377
+
378
+	/**
379
+	 * DO NOT USE FOR TESTING IDENTIFICATION STATUS.
380
+	 *
381
+	 * This only returns any overrides in the database for identification status,
382
+	 * and is thus not suitable on its own to determine if a user is identified.
383
+	 *
384
+	 * Most (all?) users should have a null value here; this is only here as an
385
+	 * emergency override in case things go horribly, horribly wrong. For
386
+	 * example, when WMF completely change the layout of the ID noticeboard.
387
+	 */
388
+	public function getForceIdentified(): ?bool
389
+	{
390
+		if ($this->forceidentified === null) {
391
+			return null;
392
+		}
393
+
394
+		return $this->forceidentified === 1;
395
+	}
396
+
397
+	/**
398
+	 * Tests if the user is new
399
+	 * @return bool
400
+	 * @category Security-Critical
401
+	 */
402
+	public function isNewUser()
403
+	{
404
+		return $this->status == self::STATUS_NEW;
405
+	}
406
+
407
+	/**
408
+	 * Tests if the user has been deactivated and is unable to access the tool
409
+	 * @return bool
410
+	 * @category Security-Critical
411
+	 */
412
+	public function isDeactivated(): bool
413
+	{
414
+		return $this->status == self::STATUS_DEACTIVATED;
415
+	}
416
+
417
+	/**
418
+	 * Tests if the user is the community user
419
+	 *
420
+	 * @todo     decide if this means logged out. I think it usually does.
421
+	 * @return bool
422
+	 * @category Security-Critical
423
+	 */
424
+	public function isCommunityUser()
425
+	{
426
+		return false;
427
+	}
428
+
429
+	#endregion 
430
+
431
+	/**
432
+	 * Gets the approval date of the user
433
+	 * @return DateTime|false
434
+	 */
435
+	public function getApprovalDate()
436
+	{
437
+		$query = $this->dbObject->prepare(<<<SQL
438 438
 			SELECT timestamp 
439 439
 			FROM log 
440 440
 			WHERE objectid = :userid
@@ -443,12 +443,12 @@  discard block
 block discarded – undo
443 443
 			ORDER BY id DESC 
444 444
 			LIMIT 1;
445 445
 SQL
446
-        );
447
-        $query->execute(array(":userid" => $this->id));
446
+		);
447
+		$query->execute(array(":userid" => $this->id));
448 448
 
449
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
450
-        $query->closeCursor();
449
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn());
450
+		$query->closeCursor();
451 451
 
452
-        return $data;
453
-    }
452
+		return $data;
453
+	}
454 454
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,12 +58,10 @@  discard block
 block discarded – undo
58 58
 
59 59
                 if ($user === false) {
60 60
                     self::$currentUser = new CommunityUser();
61
-                }
62
-                else {
61
+                } else {
63 62
                     self::$currentUser = $user;
64 63
                 }
65
-            }
66
-            else {
64
+            } else {
67 65
                 $anonymousCoward = new CommunityUser();
68 66
 
69 67
                 self::$currentUser = $anonymousCoward;
@@ -190,12 +188,10 @@  discard block
 block discarded – undo
190 188
 
191 189
             if ($statement->execute()) {
192 190
                 $this->id = (int)$this->dbObject->lastInsertId();
193
-            }
194
-            else {
191
+            } else {
195 192
                 throw new Exception($statement->errorInfo());
196 193
             }
197
-        }
198
-        else {
194
+        } else {
199 195
             // update
200 196
             $statement = $this->dbObject->prepare(<<<SQL
201 197
 				UPDATE `user` SET 
Please login to merge, or discard this patch.
includes/DataObjects/CommunityUser.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -17,120 +17,120 @@
 block discarded – undo
17 17
  */
18 18
 class CommunityUser extends User
19 19
 {
20
-    public function getId()
21
-    {
22
-        return -1;
23
-    }
24
-
25
-    public function save()
26
-    {
27
-        // Do nothing
28
-    }
29
-
30
-    #region properties
31
-
32
-    /**
33
-     * @return string
34
-     */
35
-    public function getUsername()
36
-    {
37
-        return '[Community]';
38
-    }
39
-
40
-    public function setUsername($username)
41
-    {
42
-    }
43
-
44
-    /**
45
-     * @return string
46
-     */
47
-    public function getEmail()
48
-    {
49
-        global $cDataClearEmail;
50
-
51
-        return $cDataClearEmail;
52
-    }
53
-
54
-    public function setEmail($email)
55
-    {
56
-    }
57
-
58
-    public function getStatus()
59
-    {
60
-        return "Community";
61
-    }
62
-
63
-    public function getOnWikiName()
64
-    {
65
-        return "127.0.0.1";
66
-    }
67
-
68
-    public function setOnWikiName($onWikiName)
69
-    {
70
-    }
71
-
72
-    public function getLastActive()
73
-    {
74
-        $now = new DateTime();
75
-
76
-        return $now->format("Y-m-d H:i:s");
77
-    }
78
-
79
-    public function getForceLogout()
80
-    {
81
-        return true;
82
-    }
83
-
84
-    public function setForceLogout($forceLogout)
85
-    {
86
-    }
87
-
88
-    /**
89
-     * @param string $status
90
-     */
91
-    public function setStatus($status)
92
-    {
93
-    }
94
-
95
-    public function getConfirmationDiff()
96
-    {
97
-        return null;
98
-    }
99
-
100
-    public function setConfirmationDiff($confirmationDiff)
101
-    {
102
-    }
103
-
104
-
105
-    public function setUseAlternateSkin($useAlternate)
106
-    {
107
-    }
108
-
109
-    #endregion
110
-
111
-    #region user access checks
112
-
113
-    public function isNewUser()
114
-    {
115
-        return false;
116
-    }
117
-
118
-    public function isDeactivated(): bool
119
-    {
120
-        return false;
121
-    }
122
-
123
-    public function isCommunityUser()
124
-    {
125
-        return true;
126
-    }
127
-
128
-    #endregion
20
+	public function getId()
21
+	{
22
+		return -1;
23
+	}
24
+
25
+	public function save()
26
+	{
27
+		// Do nothing
28
+	}
29
+
30
+	#region properties
31
+
32
+	/**
33
+	 * @return string
34
+	 */
35
+	public function getUsername()
36
+	{
37
+		return '[Community]';
38
+	}
39
+
40
+	public function setUsername($username)
41
+	{
42
+	}
43
+
44
+	/**
45
+	 * @return string
46
+	 */
47
+	public function getEmail()
48
+	{
49
+		global $cDataClearEmail;
50
+
51
+		return $cDataClearEmail;
52
+	}
53
+
54
+	public function setEmail($email)
55
+	{
56
+	}
57
+
58
+	public function getStatus()
59
+	{
60
+		return "Community";
61
+	}
62
+
63
+	public function getOnWikiName()
64
+	{
65
+		return "127.0.0.1";
66
+	}
67
+
68
+	public function setOnWikiName($onWikiName)
69
+	{
70
+	}
71
+
72
+	public function getLastActive()
73
+	{
74
+		$now = new DateTime();
75
+
76
+		return $now->format("Y-m-d H:i:s");
77
+	}
78
+
79
+	public function getForceLogout()
80
+	{
81
+		return true;
82
+	}
83
+
84
+	public function setForceLogout($forceLogout)
85
+	{
86
+	}
87
+
88
+	/**
89
+	 * @param string $status
90
+	 */
91
+	public function setStatus($status)
92
+	{
93
+	}
94
+
95
+	public function getConfirmationDiff()
96
+	{
97
+		return null;
98
+	}
99
+
100
+	public function setConfirmationDiff($confirmationDiff)
101
+	{
102
+	}
103
+
104
+
105
+	public function setUseAlternateSkin($useAlternate)
106
+	{
107
+	}
108
+
109
+	#endregion
110
+
111
+	#region user access checks
112
+
113
+	public function isNewUser()
114
+	{
115
+		return false;
116
+	}
117
+
118
+	public function isDeactivated(): bool
119
+	{
120
+		return false;
121
+	}
122
+
123
+	public function isCommunityUser()
124
+	{
125
+		return true;
126
+	}
127
+
128
+	#endregion
129 129
 
130
-    public function getApprovalDate()
131
-    {
132
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
133
-
134
-        return $data;
135
-    }
130
+	public function getApprovalDate()
131
+	{
132
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
133
+
134
+		return $data;
135
+	}
136 136
 }
Please login to merge, or discard this patch.
includes/DataObjects/Domain.php 1 patch
Indentation   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -18,94 +18,94 @@  discard block
 block discarded – undo
18 18
 
19 19
 class Domain extends DataObject
20 20
 {
21
-    /** @var string */
22
-    private $shortname;
23
-    /** @var string */
24
-    private $longname;
25
-    /** @var string */
26
-    private $wikiarticlepath;
27
-    /** @var string */
28
-    private $wikiapipath;
29
-    /** @var int */
30
-    private $enabled = 0;
31
-    /** @var int|null */
32
-    private $defaultclose;
33
-    /** @var string */
34
-    private $defaultlanguage = 'en';
35
-    /** @var string */
36
-    private $emailreplyaddress;
37
-    /** @var string|null */
38
-    private $notificationtarget;
39
-    /** @var string */
40
-    private $localdocumentation;
41
-
42
-    /** @var Domain Cache variable of the current domain */
43
-    private static $currentDomain;
44
-
45
-    public static function getCurrent(PdoDatabase $database)
46
-    {
47
-        if (self::$currentDomain === null) {
48
-            $sessionDomain = WebRequest::getSessionDomain();
49
-
50
-            if ($sessionDomain !== null) {
51
-                /** @var Domain $domain */
52
-                $domain = self::getById($sessionDomain, $database);
53
-
54
-                if ($domain === false) {
55
-                    self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
56
-                }
57
-                else {
58
-                    self::$currentDomain = $domain;
59
-                }
60
-            }
61
-            else {
62
-                self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
63
-            }
64
-        }
65
-
66
-        return self::$currentDomain;
67
-    }
68
-
69
-    public static function getByShortName(string $shortName, PdoDatabase $database)
70
-    {
71
-        $statement = $database->prepare(<<<SQL
21
+	/** @var string */
22
+	private $shortname;
23
+	/** @var string */
24
+	private $longname;
25
+	/** @var string */
26
+	private $wikiarticlepath;
27
+	/** @var string */
28
+	private $wikiapipath;
29
+	/** @var int */
30
+	private $enabled = 0;
31
+	/** @var int|null */
32
+	private $defaultclose;
33
+	/** @var string */
34
+	private $defaultlanguage = 'en';
35
+	/** @var string */
36
+	private $emailreplyaddress;
37
+	/** @var string|null */
38
+	private $notificationtarget;
39
+	/** @var string */
40
+	private $localdocumentation;
41
+
42
+	/** @var Domain Cache variable of the current domain */
43
+	private static $currentDomain;
44
+
45
+	public static function getCurrent(PdoDatabase $database)
46
+	{
47
+		if (self::$currentDomain === null) {
48
+			$sessionDomain = WebRequest::getSessionDomain();
49
+
50
+			if ($sessionDomain !== null) {
51
+				/** @var Domain $domain */
52
+				$domain = self::getById($sessionDomain, $database);
53
+
54
+				if ($domain === false) {
55
+					self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
56
+				}
57
+				else {
58
+					self::$currentDomain = $domain;
59
+				}
60
+			}
61
+			else {
62
+				self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
63
+			}
64
+		}
65
+
66
+		return self::$currentDomain;
67
+	}
68
+
69
+	public static function getByShortName(string $shortName, PdoDatabase $database)
70
+	{
71
+		$statement = $database->prepare(<<<SQL
72 72
             SELECT * FROM domain WHERE shortname = :name;
73 73
 SQL
74
-        );
74
+		);
75 75
 
76
-        $statement->execute([
77
-            ':name' => $shortName,
78
-        ]);
76
+		$statement->execute([
77
+			':name' => $shortName,
78
+		]);
79 79
 
80
-        /** @var RequestForm|false $result */
81
-        $result = $statement->fetchObject(get_called_class());
80
+		/** @var RequestForm|false $result */
81
+		$result = $statement->fetchObject(get_called_class());
82 82
 
83
-        if ($result !== false) {
84
-            $result->setDatabase($database);
85
-        }
83
+		if ($result !== false) {
84
+			$result->setDatabase($database);
85
+		}
86 86
 
87
-        return $result;
88
-    }
87
+		return $result;
88
+	}
89 89
 
90
-    public static function getAll(PdoDatabase $database) {
91
-        $statement = $database->prepare("SELECT * FROM domain;");
92
-        $statement->execute();
90
+	public static function getAll(PdoDatabase $database) {
91
+		$statement = $database->prepare("SELECT * FROM domain;");
92
+		$statement->execute();
93 93
 
94
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
94
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
95 95
 
96
-        /** @var Domain $t */
97
-        foreach ($resultObject as $t) {
98
-            $t->setDatabase($database);
99
-        }
96
+		/** @var Domain $t */
97
+		foreach ($resultObject as $t) {
98
+			$t->setDatabase($database);
99
+		}
100 100
 
101
-        return $resultObject;
102
-    }
101
+		return $resultObject;
102
+	}
103 103
 
104
-    public function save()
105
-    {
106
-        if ($this->isNew()) {
107
-            // insert
108
-            $statement = $this->dbObject->prepare(<<<SQL
104
+	public function save()
105
+	{
106
+		if ($this->isNew()) {
107
+			// insert
108
+			$statement = $this->dbObject->prepare(<<<SQL
109 109
                 INSERT INTO domain (
110 110
                     shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, 
111 111
                     emailreplyaddress, notificationtarget, localdocumentation
@@ -114,29 +114,29 @@  discard block
 block discarded – undo
114 114
                     :emailreplyaddress, :notificationtarget, :localdocumentation
115 115
                 );
116 116
 SQL
117
-            );
118
-
119
-            $statement->bindValue(":shortname", $this->shortname);
120
-            $statement->bindValue(":longname", $this->longname);
121
-            $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
122
-            $statement->bindValue(":wikiapipath", $this->wikiapipath);
123
-            $statement->bindValue(":enabled", $this->enabled);
124
-            $statement->bindValue(":defaultclose", $this->defaultclose);
125
-            $statement->bindValue(":defaultlanguage", $this->defaultlanguage);
126
-            $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
127
-            $statement->bindValue(":notificationtarget", $this->notificationtarget);
128
-            $statement->bindValue(":localdocumentation", $this->localdocumentation);
129
-
130
-
131
-            if ($statement->execute()) {
132
-                $this->id = (int)$this->dbObject->lastInsertId();
133
-            }
134
-            else {
135
-                throw new Exception($statement->errorInfo());
136
-            }
137
-        }
138
-        else {
139
-            $statement = $this->dbObject->prepare(<<<SQL
117
+			);
118
+
119
+			$statement->bindValue(":shortname", $this->shortname);
120
+			$statement->bindValue(":longname", $this->longname);
121
+			$statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
122
+			$statement->bindValue(":wikiapipath", $this->wikiapipath);
123
+			$statement->bindValue(":enabled", $this->enabled);
124
+			$statement->bindValue(":defaultclose", $this->defaultclose);
125
+			$statement->bindValue(":defaultlanguage", $this->defaultlanguage);
126
+			$statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
127
+			$statement->bindValue(":notificationtarget", $this->notificationtarget);
128
+			$statement->bindValue(":localdocumentation", $this->localdocumentation);
129
+
130
+
131
+			if ($statement->execute()) {
132
+				$this->id = (int)$this->dbObject->lastInsertId();
133
+			}
134
+			else {
135
+				throw new Exception($statement->errorInfo());
136
+			}
137
+		}
138
+		else {
139
+			$statement = $this->dbObject->prepare(<<<SQL
140 140
                 UPDATE domain SET
141 141
                     longname = :longname,
142 142
                     wikiarticlepath = :wikiarticlepath,
@@ -151,190 +151,190 @@  discard block
 block discarded – undo
151 151
                     updateversion = updateversion + 1
152 152
 				WHERE id = :id AND updateversion = :updateversion;
153 153
 SQL
154
-            );
155
-
156
-            $statement->bindValue(":longname", $this->longname);
157
-            $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
158
-            $statement->bindValue(":wikiapipath", $this->wikiapipath);
159
-            $statement->bindValue(":enabled", $this->enabled);
160
-            $statement->bindValue(":defaultclose", $this->defaultclose);
161
-            $statement->bindValue(":defaultlanguage", $this->defaultlanguage);
162
-            $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
163
-            $statement->bindValue(":notificationtarget", $this->notificationtarget);
164
-            $statement->bindValue(":localdocumentation", $this->localdocumentation);
165
-
166
-            $statement->bindValue(':id', $this->id);
167
-            $statement->bindValue(':updateversion', $this->updateversion);
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 getShortName(): string
185
-    {
186
-        return $this->shortname;
187
-    }
188
-
189
-    /**
190
-     * @param string $shortName
191
-     */
192
-    public function setShortName(string $shortName): void
193
-    {
194
-        $this->shortname = $shortName;
195
-    }
196
-
197
-    /**
198
-     * @return string
199
-     */
200
-    public function getLongName(): string
201
-    {
202
-        return $this->longname;
203
-    }
204
-
205
-    /**
206
-     * @param string $longName
207
-     */
208
-    public function setLongName(string $longName): void
209
-    {
210
-        $this->longname = $longName;
211
-    }
212
-
213
-    /**
214
-     * @return string
215
-     */
216
-    public function getWikiArticlePath(): string
217
-    {
218
-        return $this->wikiarticlepath;
219
-    }
220
-
221
-    /**
222
-     * @param string $wikiArticlePath
223
-     */
224
-    public function setWikiArticlePath(string $wikiArticlePath): void
225
-    {
226
-        $this->wikiarticlepath = $wikiArticlePath;
227
-    }
228
-
229
-    /**
230
-     * @return string
231
-     */
232
-    public function getWikiApiPath(): string
233
-    {
234
-        return $this->wikiapipath;
235
-    }
236
-
237
-    /**
238
-     * @param string $wikiApiPath
239
-     */
240
-    public function setWikiApiPath(string $wikiApiPath): void
241
-    {
242
-        $this->wikiapipath = $wikiApiPath;
243
-    }
244
-
245
-    /**
246
-     * @return bool
247
-     */
248
-    public function isEnabled(): bool
249
-    {
250
-        return $this->enabled == 1;
251
-    }
252
-
253
-    /**
254
-     * @param bool $enabled
255
-     */
256
-    public function setEnabled(bool $enabled): void
257
-    {
258
-        $this->enabled = $enabled ? 1 : 0;
259
-    }
260
-
261
-    /**
262
-     * @return int
263
-     */
264
-    public function getDefaultClose(): ?int
265
-    {
266
-        return $this->defaultclose;
267
-    }
268
-
269
-    /**
270
-     * @param int $defaultClose
271
-     */
272
-    public function setDefaultClose(?int $defaultClose): void
273
-    {
274
-        $this->defaultclose = $defaultClose;
275
-    }
276
-
277
-    /**
278
-     * @return string
279
-     */
280
-    public function getDefaultLanguage(): string
281
-    {
282
-        return $this->defaultlanguage;
283
-    }
284
-
285
-    /**
286
-     * @param string $defaultLanguage
287
-     */
288
-    public function setDefaultLanguage(string $defaultLanguage): void
289
-    {
290
-        $this->defaultlanguage = $defaultLanguage;
291
-    }
292
-
293
-    /**
294
-     * @return string
295
-     */
296
-    public function getEmailReplyAddress(): string
297
-    {
298
-        return $this->emailreplyaddress;
299
-    }
300
-
301
-    /**
302
-     * @param string $emailReplyAddress
303
-     */
304
-    public function setEmailReplyAddress(string $emailReplyAddress): void
305
-    {
306
-        $this->emailreplyaddress = $emailReplyAddress;
307
-    }
308
-
309
-    /**
310
-     * @return string|null
311
-     */
312
-    public function getNotificationTarget(): ?string
313
-    {
314
-        return $this->notificationtarget;
315
-    }
316
-
317
-    /**
318
-     * @param string|null $notificationTarget
319
-     */
320
-    public function setNotificationTarget(?string $notificationTarget): void
321
-    {
322
-        $this->notificationtarget = $notificationTarget;
323
-    }
324
-
325
-    /**
326
-     * @return string
327
-     */
328
-    public function getLocalDocumentation(): string
329
-    {
330
-        return $this->localdocumentation;
331
-    }
332
-
333
-    /**
334
-     * @param string $localDocumentation
335
-     */
336
-    public function setLocalDocumentation(string $localDocumentation): void
337
-    {
338
-        $this->localdocumentation = $localDocumentation;
339
-    }
154
+			);
155
+
156
+			$statement->bindValue(":longname", $this->longname);
157
+			$statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
158
+			$statement->bindValue(":wikiapipath", $this->wikiapipath);
159
+			$statement->bindValue(":enabled", $this->enabled);
160
+			$statement->bindValue(":defaultclose", $this->defaultclose);
161
+			$statement->bindValue(":defaultlanguage", $this->defaultlanguage);
162
+			$statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
163
+			$statement->bindValue(":notificationtarget", $this->notificationtarget);
164
+			$statement->bindValue(":localdocumentation", $this->localdocumentation);
165
+
166
+			$statement->bindValue(':id', $this->id);
167
+			$statement->bindValue(':updateversion', $this->updateversion);
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 getShortName(): string
185
+	{
186
+		return $this->shortname;
187
+	}
188
+
189
+	/**
190
+	 * @param string $shortName
191
+	 */
192
+	public function setShortName(string $shortName): void
193
+	{
194
+		$this->shortname = $shortName;
195
+	}
196
+
197
+	/**
198
+	 * @return string
199
+	 */
200
+	public function getLongName(): string
201
+	{
202
+		return $this->longname;
203
+	}
204
+
205
+	/**
206
+	 * @param string $longName
207
+	 */
208
+	public function setLongName(string $longName): void
209
+	{
210
+		$this->longname = $longName;
211
+	}
212
+
213
+	/**
214
+	 * @return string
215
+	 */
216
+	public function getWikiArticlePath(): string
217
+	{
218
+		return $this->wikiarticlepath;
219
+	}
220
+
221
+	/**
222
+	 * @param string $wikiArticlePath
223
+	 */
224
+	public function setWikiArticlePath(string $wikiArticlePath): void
225
+	{
226
+		$this->wikiarticlepath = $wikiArticlePath;
227
+	}
228
+
229
+	/**
230
+	 * @return string
231
+	 */
232
+	public function getWikiApiPath(): string
233
+	{
234
+		return $this->wikiapipath;
235
+	}
236
+
237
+	/**
238
+	 * @param string $wikiApiPath
239
+	 */
240
+	public function setWikiApiPath(string $wikiApiPath): void
241
+	{
242
+		$this->wikiapipath = $wikiApiPath;
243
+	}
244
+
245
+	/**
246
+	 * @return bool
247
+	 */
248
+	public function isEnabled(): bool
249
+	{
250
+		return $this->enabled == 1;
251
+	}
252
+
253
+	/**
254
+	 * @param bool $enabled
255
+	 */
256
+	public function setEnabled(bool $enabled): void
257
+	{
258
+		$this->enabled = $enabled ? 1 : 0;
259
+	}
260
+
261
+	/**
262
+	 * @return int
263
+	 */
264
+	public function getDefaultClose(): ?int
265
+	{
266
+		return $this->defaultclose;
267
+	}
268
+
269
+	/**
270
+	 * @param int $defaultClose
271
+	 */
272
+	public function setDefaultClose(?int $defaultClose): void
273
+	{
274
+		$this->defaultclose = $defaultClose;
275
+	}
276
+
277
+	/**
278
+	 * @return string
279
+	 */
280
+	public function getDefaultLanguage(): string
281
+	{
282
+		return $this->defaultlanguage;
283
+	}
284
+
285
+	/**
286
+	 * @param string $defaultLanguage
287
+	 */
288
+	public function setDefaultLanguage(string $defaultLanguage): void
289
+	{
290
+		$this->defaultlanguage = $defaultLanguage;
291
+	}
292
+
293
+	/**
294
+	 * @return string
295
+	 */
296
+	public function getEmailReplyAddress(): string
297
+	{
298
+		return $this->emailreplyaddress;
299
+	}
300
+
301
+	/**
302
+	 * @param string $emailReplyAddress
303
+	 */
304
+	public function setEmailReplyAddress(string $emailReplyAddress): void
305
+	{
306
+		$this->emailreplyaddress = $emailReplyAddress;
307
+	}
308
+
309
+	/**
310
+	 * @return string|null
311
+	 */
312
+	public function getNotificationTarget(): ?string
313
+	{
314
+		return $this->notificationtarget;
315
+	}
316
+
317
+	/**
318
+	 * @param string|null $notificationTarget
319
+	 */
320
+	public function setNotificationTarget(?string $notificationTarget): void
321
+	{
322
+		$this->notificationtarget = $notificationTarget;
323
+	}
324
+
325
+	/**
326
+	 * @return string
327
+	 */
328
+	public function getLocalDocumentation(): string
329
+	{
330
+		return $this->localdocumentation;
331
+	}
332
+
333
+	/**
334
+	 * @param string $localDocumentation
335
+	 */
336
+	public function setLocalDocumentation(string $localDocumentation): void
337
+	{
338
+		$this->localdocumentation = $localDocumentation;
339
+	}
340 340
 }
341 341
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Exceptions/AccessDeniedException.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -27,66 +27,66 @@
 block discarded – undo
27 27
  */
28 28
 class AccessDeniedException extends ReadableException
29 29
 {
30
-    use NavigationMenuAccessControl;
31
-    use LogEntryLookup;
30
+	use NavigationMenuAccessControl;
31
+	use LogEntryLookup;
32 32
 
33
-    private ISecurityManager $securityManager;
34
-    private IDomainAccessManager $domainAccessManager;
33
+	private ISecurityManager $securityManager;
34
+	private IDomainAccessManager $domainAccessManager;
35 35
 
36
-    /**
37
-     * AccessDeniedException constructor.
38
-     *
39
-     * @param ISecurityManager     $securityManager
40
-     * @param IDomainAccessManager $domainAccessManager
41
-     */
42
-    public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager)
43
-    {
44
-        $this->securityManager = $securityManager;
45
-        $this->domainAccessManager = $domainAccessManager;
46
-    }
36
+	/**
37
+	 * AccessDeniedException constructor.
38
+	 *
39
+	 * @param ISecurityManager     $securityManager
40
+	 * @param IDomainAccessManager $domainAccessManager
41
+	 */
42
+	public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager)
43
+	{
44
+		$this->securityManager = $securityManager;
45
+		$this->domainAccessManager = $domainAccessManager;
46
+	}
47 47
 
48
-    public function getReadableError()
49
-    {
50
-        if (!headers_sent()) {
51
-            header("HTTP/1.1 403 Forbidden");
52
-        }
48
+	public function getReadableError()
49
+	{
50
+		if (!headers_sent()) {
51
+			header("HTTP/1.1 403 Forbidden");
52
+		}
53 53
 
54
-        $this->setUpSmarty();
54
+		$this->setUpSmarty();
55 55
 
56
-        // uck. We should still be able to access the database in this situation though.
57
-        $database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration());
58
-        $currentUser = User::getCurrent($database);
59
-        $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN));
60
-        $this->assign('currentUser', $currentUser);
61
-        $this->assign('currentDomain', Domain::getCurrent($database));
56
+		// uck. We should still be able to access the database in this situation though.
57
+		$database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration());
58
+		$currentUser = User::getCurrent($database);
59
+		$this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN));
60
+		$this->assign('currentUser', $currentUser);
61
+		$this->assign('currentDomain', Domain::getCurrent($database));
62 62
 
63
-        $this->setupNavMenuAccess($currentUser);
63
+		$this->setupNavMenuAccess($currentUser);
64 64
 
65
-        if ($currentUser->isDeactivated()) {
66
-            $this->assign('htmlTitle', 'Account Deactivated');
67
-            $this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $database));
65
+		if ($currentUser->isDeactivated()) {
66
+			$this->assign('htmlTitle', 'Account Deactivated');
67
+			$this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $database));
68 68
 
69
-            return $this->fetchTemplate("exception/account-deactivated.tpl");
70
-        }
69
+			return $this->fetchTemplate("exception/account-deactivated.tpl");
70
+		}
71 71
 
72
-        if ($currentUser->isNewUser()) {
73
-            $this->assign('htmlTitle', 'Account Pending');
72
+		if ($currentUser->isNewUser()) {
73
+			$this->assign('htmlTitle', 'Account Pending');
74 74
 
75
-            return $this->fetchTemplate("exception/account-new.tpl");
76
-        }
75
+			return $this->fetchTemplate("exception/account-new.tpl");
76
+		}
77 77
 
78
-        return $this->fetchTemplate("exception/access-denied.tpl");
79
-    }
78
+		return $this->fetchTemplate("exception/access-denied.tpl");
79
+	}
80 80
 
81 81
 
82 82
 
83
-    protected function getSecurityManager(): ISecurityManager
84
-    {
85
-        return $this->securityManager;
86
-    }
83
+	protected function getSecurityManager(): ISecurityManager
84
+	{
85
+		return $this->securityManager;
86
+	}
87 87
 
88
-    public function getDomainAccessManager(): IDomainAccessManager
89
-    {
90
-        return $this->domainAccessManager;
91
-    }
88
+	public function getDomainAccessManager(): IDomainAccessManager
89
+	{
90
+		return $this->domainAccessManager;
91
+	}
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Exceptions/NotIdentifiedException.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -19,50 +19,50 @@
 block discarded – undo
19 19
 
20 20
 class NotIdentifiedException extends ReadableException
21 21
 {
22
-    use NavigationMenuAccessControl;
22
+	use NavigationMenuAccessControl;
23 23
 
24
-    private ISecurityManager $securityManager;
25
-    private IDomainAccessManager $domainAccessManager;
24
+	private ISecurityManager $securityManager;
25
+	private IDomainAccessManager $domainAccessManager;
26 26
 
27
-    public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager)
28
-    {
29
-        $this->securityManager = $securityManager;
30
-        $this->domainAccessManager = $domainAccessManager;
31
-    }
27
+	public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager)
28
+	{
29
+		$this->securityManager = $securityManager;
30
+		$this->domainAccessManager = $domainAccessManager;
31
+	}
32 32
 
33
-    /**
34
-     * Returns a readable HTML error message that's displayable to the user using templates.
35
-     * @return string
36
-     */
37
-    public function getReadableError()
38
-    {
39
-        if (!headers_sent()) {
40
-            header("HTTP/1.1 403 Forbidden");
41
-        }
33
+	/**
34
+	 * Returns a readable HTML error message that's displayable to the user using templates.
35
+	 * @return string
36
+	 */
37
+	public function getReadableError()
38
+	{
39
+		if (!headers_sent()) {
40
+			header("HTTP/1.1 403 Forbidden");
41
+		}
42 42
 
43
-        $this->setUpSmarty();
43
+		$this->setUpSmarty();
44 44
 
45
-        // uck. We should still be able to access the database in this situation though.
46
-        $database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration());
47
-        $currentUser = User::getCurrent($database);
48
-        $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN));
49
-        $this->assign('currentUser', $currentUser);
50
-        $this->assign('currentDomain', Domain::getCurrent($database));
45
+		// uck. We should still be able to access the database in this situation though.
46
+		$database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration());
47
+		$currentUser = User::getCurrent($database);
48
+		$this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN));
49
+		$this->assign('currentUser', $currentUser);
50
+		$this->assign('currentDomain', Domain::getCurrent($database));
51 51
 
52
-        if ($this->securityManager !== null) {
53
-            $this->setupNavMenuAccess($currentUser);
54
-        }
52
+		if ($this->securityManager !== null) {
53
+			$this->setupNavMenuAccess($currentUser);
54
+		}
55 55
 
56
-        return $this->fetchTemplate("exception/not-identified.tpl");
57
-    }
56
+		return $this->fetchTemplate("exception/not-identified.tpl");
57
+	}
58 58
 
59
-    protected function getSecurityManager(): ISecurityManager
60
-    {
61
-        return $this->securityManager;
62
-    }
59
+	protected function getSecurityManager(): ISecurityManager
60
+	{
61
+		return $this->securityManager;
62
+	}
63 63
 
64
-    public function getDomainAccessManager(): IDomainAccessManager
65
-    {
66
-        return $this->domainAccessManager;
67
-    }
64
+	public function getDomainAccessManager(): IDomainAccessManager
65
+	{
66
+		return $this->domainAccessManager;
67
+	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -18,64 +18,64 @@
 block discarded – undo
18 18
 
19 19
 class PageLog extends PagedInternalPageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Logs');
27
-
28
-        $filterUser = WebRequest::getString('filterUser');
29
-        $filterAction = WebRequest::getString('filterAction');
30
-        $filterObjectType = WebRequest::getString('filterObjectType');
31
-        $filterObjectId = WebRequest::getInt('filterObjectId');
32
-
33
-        $database = $this->getDatabase();
34
-
35
-        if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
-            $filterObjectType = null;
37
-        }
38
-
39
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
40
-
41
-        // FIXME: domains
42
-        $logSearch = LogSearchHelper::get($database, 1);
43
-
44
-        if ($filterUser !== null) {
45
-            $userObj = User::getByUsername($filterUser, $database);
46
-            if ($userObj !== false) {
47
-                $logSearch->byUser($userObj->getId());
48
-            }
49
-            else {
50
-                $logSearch->byUser(-1);
51
-            }
52
-        }
53
-        if ($filterAction !== null) {
54
-            $logSearch->byAction($filterAction);
55
-        }
56
-        if ($filterObjectType !== null) {
57
-            $logSearch->byObjectType($filterObjectType);
58
-        }
59
-        if ($filterObjectId !== null) {
60
-            $logSearch->byObjectId($filterObjectId);
61
-        }
62
-
63
-        $this->setSearchHelper($logSearch);
64
-        $this->setupLimits();
65
-
66
-        /** @var Log[] $logs */
67
-        $logs = $logSearch->getRecordCount($count)->fetch();
68
-
69
-        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
70
-
71
-        $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
72
-
73
-        $this->assign("logs", $logData);
74
-        $this->assign("users", $users);
75
-
76
-        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
77
-        $this->assign('allObjectTypes', LogHelper::getObjectTypes());
78
-
79
-        $this->setTemplate("logs/main.tpl");
80
-    }
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Logs');
27
+
28
+		$filterUser = WebRequest::getString('filterUser');
29
+		$filterAction = WebRequest::getString('filterAction');
30
+		$filterObjectType = WebRequest::getString('filterObjectType');
31
+		$filterObjectId = WebRequest::getInt('filterObjectId');
32
+
33
+		$database = $this->getDatabase();
34
+
35
+		if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
+			$filterObjectType = null;
37
+		}
38
+
39
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
40
+
41
+		// FIXME: domains
42
+		$logSearch = LogSearchHelper::get($database, 1);
43
+
44
+		if ($filterUser !== null) {
45
+			$userObj = User::getByUsername($filterUser, $database);
46
+			if ($userObj !== false) {
47
+				$logSearch->byUser($userObj->getId());
48
+			}
49
+			else {
50
+				$logSearch->byUser(-1);
51
+			}
52
+		}
53
+		if ($filterAction !== null) {
54
+			$logSearch->byAction($filterAction);
55
+		}
56
+		if ($filterObjectType !== null) {
57
+			$logSearch->byObjectType($filterObjectType);
58
+		}
59
+		if ($filterObjectId !== null) {
60
+			$logSearch->byObjectId($filterObjectId);
61
+		}
62
+
63
+		$this->setSearchHelper($logSearch);
64
+		$this->setupLimits();
65
+
66
+		/** @var Log[] $logs */
67
+		$logs = $logSearch->getRecordCount($count)->fetch();
68
+
69
+		list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
70
+
71
+		$this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
72
+
73
+		$this->assign("logs", $logData);
74
+		$this->assign("users", $users);
75
+
76
+		$this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
77
+		$this->assign('allObjectTypes', LogHelper::getObjectTypes());
78
+
79
+		$this->setTemplate("logs/main.tpl");
80
+	}
81 81
 }
Please login to merge, or discard this patch.
includes/Pages/PageJobQueue.php 2 patches
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -29,309 +29,309 @@
 block discarded – undo
29 29
 
30 30
 class PageJobQueue extends PagedInternalPageBase
31 31
 {
32
-    /**
33
-     * Main function for this page, when no specific actions are called.
34
-     * @return void
35
-     */
36
-    protected function main()
37
-    {
38
-        $this->setHtmlTitle('Job Queue Management');
39
-
40
-        $this->prepareMaps();
41
-
42
-        $database = $this->getDatabase();
43
-
44
-        /** @var JobQueue[] $jobList */
45
-        // FIXME: domains
46
-        $jobList = JobQueueSearchHelper::get($database, 1)
47
-            ->statusIn([
48
-                JobQueue::STATUS_QUEUED,
49
-                JobQueue::STATUS_READY,
50
-                JobQueue::STATUS_WAITING,
51
-                JobQueue::STATUS_RUNNING,
52
-                JobQueue::STATUS_FAILED,
53
-            ])
54
-            ->notAcknowledged()
55
-            ->fetch();
56
-
57
-        $userIds = array();
58
-        $requestIds = array();
59
-
60
-        foreach ($jobList as $job) {
61
-            $userIds[] = $job->getTriggerUserId();
62
-            $requestIds[] = $job->getRequest();
63
-
64
-            $job->setDatabase($database);
65
-        }
66
-
67
-        $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
68
-
69
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
70
-        // FIXME: domains
71
-        $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
72
-
73
-        $this->assign('joblist', $jobList);
74
-        $this->setTemplate('jobqueue/main.tpl');
75
-    }
76
-
77
-    protected function all()
78
-    {
79
-        $this->setHtmlTitle('All Jobs');
80
-
81
-        $this->prepareMaps();
82
-
83
-        $database = $this->getDatabase();
84
-
85
-        // FIXME: domains
86
-        $searchHelper = JobQueueSearchHelper::get($database, 1);
87
-        $this->setSearchHelper($searchHelper);
88
-        $this->setupLimits();
89
-
90
-        $filterUser = WebRequest::getString('filterUser');
91
-        $filterTask = WebRequest::getString('filterTask');
92
-        $filterStatus = WebRequest::getString('filterStatus');
93
-        $filterRequest = WebRequest::getString('filterRequest');
94
-        $order = WebRequest::getString('order');
95
-
96
-        if ($filterUser !== null) {
97
-            $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
98
-        }
99
-
100
-        if ($filterTask !== null) {
101
-            $searchHelper->byTask($filterTask);
102
-        }
103
-
104
-        if ($filterStatus !== null) {
105
-            $searchHelper->byStatus($filterStatus);
106
-        }
107
-
108
-        if ($filterRequest !== null) {
109
-            $searchHelper->byRequest($filterRequest);
110
-        }
32
+	/**
33
+	 * Main function for this page, when no specific actions are called.
34
+	 * @return void
35
+	 */
36
+	protected function main()
37
+	{
38
+		$this->setHtmlTitle('Job Queue Management');
39
+
40
+		$this->prepareMaps();
41
+
42
+		$database = $this->getDatabase();
43
+
44
+		/** @var JobQueue[] $jobList */
45
+		// FIXME: domains
46
+		$jobList = JobQueueSearchHelper::get($database, 1)
47
+			->statusIn([
48
+				JobQueue::STATUS_QUEUED,
49
+				JobQueue::STATUS_READY,
50
+				JobQueue::STATUS_WAITING,
51
+				JobQueue::STATUS_RUNNING,
52
+				JobQueue::STATUS_FAILED,
53
+			])
54
+			->notAcknowledged()
55
+			->fetch();
56
+
57
+		$userIds = array();
58
+		$requestIds = array();
59
+
60
+		foreach ($jobList as $job) {
61
+			$userIds[] = $job->getTriggerUserId();
62
+			$requestIds[] = $job->getRequest();
63
+
64
+			$job->setDatabase($database);
65
+		}
66
+
67
+		$this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
68
+
69
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
70
+		// FIXME: domains
71
+		$this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
72
+
73
+		$this->assign('joblist', $jobList);
74
+		$this->setTemplate('jobqueue/main.tpl');
75
+	}
76
+
77
+	protected function all()
78
+	{
79
+		$this->setHtmlTitle('All Jobs');
80
+
81
+		$this->prepareMaps();
82
+
83
+		$database = $this->getDatabase();
84
+
85
+		// FIXME: domains
86
+		$searchHelper = JobQueueSearchHelper::get($database, 1);
87
+		$this->setSearchHelper($searchHelper);
88
+		$this->setupLimits();
89
+
90
+		$filterUser = WebRequest::getString('filterUser');
91
+		$filterTask = WebRequest::getString('filterTask');
92
+		$filterStatus = WebRequest::getString('filterStatus');
93
+		$filterRequest = WebRequest::getString('filterRequest');
94
+		$order = WebRequest::getString('order');
95
+
96
+		if ($filterUser !== null) {
97
+			$searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
98
+		}
99
+
100
+		if ($filterTask !== null) {
101
+			$searchHelper->byTask($filterTask);
102
+		}
103
+
104
+		if ($filterStatus !== null) {
105
+			$searchHelper->byStatus($filterStatus);
106
+		}
107
+
108
+		if ($filterRequest !== null) {
109
+			$searchHelper->byRequest($filterRequest);
110
+		}
111 111
         
112
-        if ($order === null) {
113
-            $searchHelper->newestFirst();
114
-        }
115
-
116
-        /** @var JobQueue[] $jobList */
117
-        $jobList = $searchHelper->getRecordCount($count)->fetch();
112
+		if ($order === null) {
113
+			$searchHelper->newestFirst();
114
+		}
115
+
116
+		/** @var JobQueue[] $jobList */
117
+		$jobList = $searchHelper->getRecordCount($count)->fetch();
118 118
 
119
-        $this->setupPageData($count, array(
120
-            'filterUser' => $filterUser,
121
-            'filterTask' => $filterTask,
122
-            'filterStatus' => $filterStatus,
123
-            'filterRequest' => $filterRequest,
124
-            'order' => $order,
125
-        ));
119
+		$this->setupPageData($count, array(
120
+			'filterUser' => $filterUser,
121
+			'filterTask' => $filterTask,
122
+			'filterStatus' => $filterStatus,
123
+			'filterRequest' => $filterRequest,
124
+			'order' => $order,
125
+		));
126 126
 
127
-        $userIds = array();
128
-        $requestIds = array();
127
+		$userIds = array();
128
+		$requestIds = array();
129 129
 
130
-        foreach ($jobList as $job) {
131
-            $userIds[] = $job->getTriggerUserId();
132
-            $requestIds[] = $job->getRequest();
130
+		foreach ($jobList as $job) {
131
+			$userIds[] = $job->getTriggerUserId();
132
+			$requestIds[] = $job->getRequest();
133 133
 
134
-            $job->setDatabase($database);
135
-        }
134
+			$job->setDatabase($database);
135
+		}
136 136
 
137
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
138
-            return UserSearchHelper::get($database)->fetchColumn('username');
139
-        });
137
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
138
+			return UserSearchHelper::get($database)->fetchColumn('username');
139
+		});
140 140
 
141
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
142
-        // FIXME: domains!
143
-        $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
141
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
142
+		// FIXME: domains!
143
+		$this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name'));
144 144
 
145
-        $this->assign('joblist', $jobList);
145
+		$this->assign('joblist', $jobList);
146 146
 
147
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
147
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
148 148
 
149
-        $this->setTemplate('jobqueue/all.tpl');
150
-    }
149
+		$this->setTemplate('jobqueue/all.tpl');
150
+	}
151 151
 
152
-    protected function view()
153
-    {
154
-        $jobId = WebRequest::getInt('id');
155
-        $database = $this->getDatabase();
152
+	protected function view()
153
+	{
154
+		$jobId = WebRequest::getInt('id');
155
+		$database = $this->getDatabase();
156 156
 
157
-        if ($jobId === null) {
158
-            throw new ApplicationLogicException('No job specified');
159
-        }
157
+		if ($jobId === null) {
158
+			throw new ApplicationLogicException('No job specified');
159
+		}
160 160
 
161
-        /** @var JobQueue $job */
162
-        $job = JobQueue::getById($jobId, $database);
161
+		/** @var JobQueue $job */
162
+		$job = JobQueue::getById($jobId, $database);
163 163
 
164
-        if ($job === false) {
165
-            throw new ApplicationLogicException('Could not find requested job');
166
-        }
164
+		if ($job === false) {
165
+			throw new ApplicationLogicException('Could not find requested job');
166
+		}
167 167
 
168
-        $this->prepareMaps();
168
+		$this->prepareMaps();
169 169
 
170
-        $this->assign('user', User::getById($job->getTriggerUserId(), $database));
171
-        $this->assign('request', Request::getById($job->getRequest(), $database));
172
-        $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
173
-        $this->assign('parent', JobQueue::getById($job->getParent(), $database));
170
+		$this->assign('user', User::getById($job->getTriggerUserId(), $database));
171
+		$this->assign('request', Request::getById($job->getRequest(), $database));
172
+		$this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
173
+		$this->assign('parent', JobQueue::getById($job->getParent(), $database));
174 174
 
175
-        /** @var Log[] $logs */
176
-        // FIXME: domains
177
-        $logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue')
178
-            ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
179
-        if ($logCount === 0) {
180
-            $this->assign('log', array());
181
-        }
182
-        else {
183
-            list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
175
+		/** @var Log[] $logs */
176
+		// FIXME: domains
177
+		$logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue')
178
+			->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
179
+		if ($logCount === 0) {
180
+			$this->assign('log', array());
181
+		}
182
+		else {
183
+			list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
184 184
 
185
-            $this->assign("log", $logData);
186
-            $this->assign("users", $users);
187
-        }
185
+			$this->assign("log", $logData);
186
+			$this->assign("users", $users);
187
+		}
188 188
 
189
-        $this->assignCSRFToken();
189
+		$this->assignCSRFToken();
190 190
 
191
-        $this->assign('job', $job);
191
+		$this->assign('job', $job);
192 192
 
193
-        $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
194
-        $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
195
-        $this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database)));
193
+		$this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
194
+		$this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
195
+		$this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database)));
196 196
 
197
-        if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) {
198
-            if ($job->getEmailTemplate() === null) {
199
-                $params = json_decode($job->getParameters());
197
+		if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) {
198
+			if ($job->getEmailTemplate() === null) {
199
+				$params = json_decode($job->getParameters());
200 200
 
201
-                if (isset($params->emailText)) {
202
-                    $this->assign("creationEmailText", $params->emailText);
203
-                }
204
-            }
205
-        }
201
+				if (isset($params->emailText)) {
202
+					$this->assign("creationEmailText", $params->emailText);
203
+				}
204
+			}
205
+		}
206 206
 
207
-        $this->setHtmlTitle('Job #{$job->getId()|escape}');
208
-        $this->setTemplate('jobqueue/view.tpl');
209
-    }
207
+		$this->setHtmlTitle('Job #{$job->getId()|escape}');
208
+		$this->setTemplate('jobqueue/view.tpl');
209
+	}
210 210
 
211
-    protected function acknowledge()
212
-    {
213
-        if (!WebRequest::wasPosted()) {
214
-            throw new ApplicationLogicException('This page does not support GET methods.');
215
-        }
211
+	protected function acknowledge()
212
+	{
213
+		if (!WebRequest::wasPosted()) {
214
+			throw new ApplicationLogicException('This page does not support GET methods.');
215
+		}
216 216
 
217
-        $this->validateCSRFToken();
217
+		$this->validateCSRFToken();
218 218
 
219
-        $jobId = WebRequest::postInt('job');
220
-        $database = $this->getDatabase();
219
+		$jobId = WebRequest::postInt('job');
220
+		$database = $this->getDatabase();
221 221
 
222
-        if ($jobId === null) {
223
-            throw new ApplicationLogicException('No job specified');
224
-        }
222
+		if ($jobId === null) {
223
+			throw new ApplicationLogicException('No job specified');
224
+		}
225 225
 
226
-        /** @var JobQueue $job */
227
-        $job = JobQueue::getById($jobId, $database);
226
+		/** @var JobQueue $job */
227
+		$job = JobQueue::getById($jobId, $database);
228 228
 
229
-        if ($job === false) {
230
-            throw new ApplicationLogicException('Could not find requested job');
231
-        }
229
+		if ($job === false) {
230
+			throw new ApplicationLogicException('Could not find requested job');
231
+		}
232 232
 
233
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
234
-        $job->setAcknowledged(true);
235
-        $job->save();
233
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
234
+		$job->setAcknowledged(true);
235
+		$job->save();
236 236
 
237
-        Logger::backgroundJobAcknowledged($database, $job);
237
+		Logger::backgroundJobAcknowledged($database, $job);
238 238
 
239
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
240
-    }
241
-
242
-    protected function cancel()
243
-    {
244
-        if (!WebRequest::wasPosted()) {
245
-            throw new ApplicationLogicException('This page does not support GET methods.');
246
-        }
247
-
248
-        $this->validateCSRFToken();
249
-
250
-        $jobId = WebRequest::postInt('job');
251
-        $database = $this->getDatabase();
252
-
253
-        if ($jobId === null) {
254
-            throw new ApplicationLogicException('No job specified');
255
-        }
256
-
257
-        /** @var JobQueue $job */
258
-        $job = JobQueue::getById($jobId, $database);
259
-
260
-        if ($job === false) {
261
-            throw new ApplicationLogicException('Could not find requested job');
262
-        }
263
-
264
-        if ($job->getStatus() !== JobQueue::STATUS_READY
265
-            && $job->getStatus() !== JobQueue::STATUS_QUEUED
266
-            && $job->getStatus() === JobQueue::STATUS_WAITING) {
267
-            throw new ApplicationLogicException('Cannot cancel job not queued for execution');
268
-        }
269
-
270
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
271
-        $job->setStatus(JobQueue::STATUS_CANCELLED);
272
-        $job->setError("Manually cancelled");
273
-        $job->setAcknowledged(null);
274
-        $job->save();
275
-
276
-        Logger::backgroundJobCancelled($this->getDatabase(), $job);
277
-
278
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
279
-    }
280
-
281
-    protected function requeue()
282
-    {
283
-        if (!WebRequest::wasPosted()) {
284
-            throw new ApplicationLogicException('This page does not support GET methods.');
285
-        }
239
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
240
+	}
241
+
242
+	protected function cancel()
243
+	{
244
+		if (!WebRequest::wasPosted()) {
245
+			throw new ApplicationLogicException('This page does not support GET methods.');
246
+		}
247
+
248
+		$this->validateCSRFToken();
249
+
250
+		$jobId = WebRequest::postInt('job');
251
+		$database = $this->getDatabase();
252
+
253
+		if ($jobId === null) {
254
+			throw new ApplicationLogicException('No job specified');
255
+		}
256
+
257
+		/** @var JobQueue $job */
258
+		$job = JobQueue::getById($jobId, $database);
259
+
260
+		if ($job === false) {
261
+			throw new ApplicationLogicException('Could not find requested job');
262
+		}
263
+
264
+		if ($job->getStatus() !== JobQueue::STATUS_READY
265
+			&& $job->getStatus() !== JobQueue::STATUS_QUEUED
266
+			&& $job->getStatus() === JobQueue::STATUS_WAITING) {
267
+			throw new ApplicationLogicException('Cannot cancel job not queued for execution');
268
+		}
269
+
270
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
271
+		$job->setStatus(JobQueue::STATUS_CANCELLED);
272
+		$job->setError("Manually cancelled");
273
+		$job->setAcknowledged(null);
274
+		$job->save();
275
+
276
+		Logger::backgroundJobCancelled($this->getDatabase(), $job);
277
+
278
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
279
+	}
280
+
281
+	protected function requeue()
282
+	{
283
+		if (!WebRequest::wasPosted()) {
284
+			throw new ApplicationLogicException('This page does not support GET methods.');
285
+		}
286 286
 
287
-        $this->validateCSRFToken();
287
+		$this->validateCSRFToken();
288 288
 
289
-        $jobId = WebRequest::postInt('job');
290
-        $database = $this->getDatabase();
291
-
292
-        if ($jobId === null) {
293
-            throw new ApplicationLogicException('No job specified');
294
-        }
295
-
296
-        /** @var JobQueue|false $job */
297
-        $job = JobQueue::getById($jobId, $database);
298
-
299
-        if ($job === false) {
300
-            throw new ApplicationLogicException('Could not find requested job');
301
-        }
302
-
303
-        $job->setStatus(JobQueue::STATUS_QUEUED);
304
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
305
-        $job->setAcknowledged(null);
306
-        $job->setError(null);
307
-        $job->save();
308
-
309
-        /** @var Request $request */
310
-        $request = Request::getById($job->getRequest(), $database);
311
-        $request->setStatus(RequestStatus::JOBQUEUE);
312
-        $request->save();
313
-
314
-        Logger::enqueuedJobQueue($database, $request);
315
-        Logger::backgroundJobRequeued($database, $job);
289
+		$jobId = WebRequest::postInt('job');
290
+		$database = $this->getDatabase();
291
+
292
+		if ($jobId === null) {
293
+			throw new ApplicationLogicException('No job specified');
294
+		}
295
+
296
+		/** @var JobQueue|false $job */
297
+		$job = JobQueue::getById($jobId, $database);
298
+
299
+		if ($job === false) {
300
+			throw new ApplicationLogicException('Could not find requested job');
301
+		}
302
+
303
+		$job->setStatus(JobQueue::STATUS_QUEUED);
304
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
305
+		$job->setAcknowledged(null);
306
+		$job->setError(null);
307
+		$job->save();
308
+
309
+		/** @var Request $request */
310
+		$request = Request::getById($job->getRequest(), $database);
311
+		$request->setStatus(RequestStatus::JOBQUEUE);
312
+		$request->save();
313
+
314
+		Logger::enqueuedJobQueue($database, $request);
315
+		Logger::backgroundJobRequeued($database, $job);
316 316
 
317
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
318
-    }
319
-
320
-    protected function prepareMaps()
321
-    {
322
-        $taskNameMap = JobQueue::getTaskDescriptions();
323
-
324
-        $statusDecriptionMap = array(
325
-            JobQueue::STATUS_CANCELLED => 'The job was cancelled',
326
-            JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
327
-            JobQueue::STATUS_FAILED    => 'The job encountered an error',
328
-            JobQueue::STATUS_QUEUED    => 'The job is in the queue',
329
-            JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
330
-            JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
331
-            JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
332
-            JobQueue::STATUS_HELD      => 'The job has manually held from processing',
333
-        );
334
-        $this->assign('taskNameMap', $taskNameMap);
335
-        $this->assign('statusDescriptionMap', $statusDecriptionMap);
336
-    }
317
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
318
+	}
319
+
320
+	protected function prepareMaps()
321
+	{
322
+		$taskNameMap = JobQueue::getTaskDescriptions();
323
+
324
+		$statusDecriptionMap = array(
325
+			JobQueue::STATUS_CANCELLED => 'The job was cancelled',
326
+			JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
327
+			JobQueue::STATUS_FAILED    => 'The job encountered an error',
328
+			JobQueue::STATUS_QUEUED    => 'The job is in the queue',
329
+			JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
330
+			JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
331
+			JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
332
+			JobQueue::STATUS_HELD      => 'The job has manually held from processing',
333
+		);
334
+		$this->assign('taskNameMap', $taskNameMap);
335
+		$this->assign('statusDescriptionMap', $statusDecriptionMap);
336
+	}
337 337
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -134,7 +134,8 @@  discard block
 block discarded – undo
134 134
             $job->setDatabase($database);
135 135
         }
136 136
 
137
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
137
+        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database)
138
+        {
138 139
             return UserSearchHelper::get($database)->fetchColumn('username');
139 140
         });
140 141
 
@@ -178,8 +179,7 @@  discard block
 block discarded – undo
178 179
             ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
179 180
         if ($logCount === 0) {
180 181
             $this->assign('log', array());
181
-        }
182
-        else {
182
+        } else {
183 183
             list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager());
184 184
 
185 185
             $this->assign("log", $logData);
Please login to merge, or discard this patch.
includes/Pages/PageUserManagement.php 2 patches
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@  discard block
 block discarded – undo
64 64
             $this->assign('deactivatedUsers', $deactivatedUsers);
65 65
 
66 66
             UserSearchHelper::get($database)->getRoleMap($roleMap);
67
-        }
68
-        else {
67
+        } else {
69 68
             $this->assign("showAll", false);
70 69
             $this->assign('deactivatedUsers', array());
71 70
 
@@ -159,8 +158,7 @@  discard block
 block discarded – undo
159 158
                     if ($newValue === 0) {
160 159
                         if ($r['globalOnly']) {
161 160
                             $globalDelete[] = $r['object'];
162
-                        }
163
-                        else {
161
+                        } else {
164 162
                             $delete[] = $r['object'];
165 163
                         }
166 164
                     }
@@ -168,8 +166,7 @@  discard block
 block discarded – undo
168 166
                     if ($newValue === 1) {
169 167
                         if ($r['globalOnly']) {
170 168
                             $globalAdd[] = $name;
171
-                        }
172
-                        else {
169
+                        } else {
173 170
                             $add[] = $name;
174 171
                         }
175 172
                     }
@@ -231,8 +228,7 @@  discard block
 block discarded – undo
231 228
             SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
232 229
 
233 230
             $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
234
-        }
235
-        else {
231
+        } else {
236 232
             $this->assignCSRFToken();
237 233
             $this->setTemplate('usermanagement/roleedit.tpl');
238 234
             $this->assign('user', $user);
@@ -293,8 +289,7 @@  discard block
 block discarded – undo
293 289
             $this->redirect('userManagement');
294 290
 
295 291
             return;
296
-        }
297
-        else {
292
+        } else {
298 293
             $this->assignCSRFToken();
299 294
             $this->setTemplate('usermanagement/changelevel-reason.tpl');
300 295
             $this->assign('user', $user);
@@ -352,8 +347,7 @@  discard block
 block discarded – undo
352 347
             $this->redirect("userManagement");
353 348
 
354 349
             return;
355
-        }
356
-        else {
350
+        } else {
357 351
             $this->assignCSRFToken();
358 352
             $this->setTemplate("usermanagement/changelevel-reason.tpl");
359 353
             $this->assign("user", $user);
@@ -436,8 +430,7 @@  discard block
 block discarded – undo
436 430
             $this->redirect("userManagement");
437 431
 
438 432
             return;
439
-        }
440
-        else {
433
+        } else {
441 434
             $this->assignCSRFToken();
442 435
             $this->setTemplate('usermanagement/renameuser.tpl');
443 436
             $this->assign('user', $user);
@@ -505,8 +498,7 @@  discard block
 block discarded – undo
505 498
             $this->redirect("userManagement");
506 499
 
507 500
             return;
508
-        }
509
-        else {
501
+        } else {
510 502
             $this->assignCSRFToken();
511 503
             $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
512 504
                 $this->getSiteConfiguration());
Please login to merge, or discard this patch.
Indentation   +600 added lines, -600 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class PageUserManagement extends InternalPageBase
34 34
 {
35
-    const OAUTH_STATE_NONE = 'none';
36
-    const OAUTH_STATE_PARTIAL = 'partial';
37
-    const OAUTH_STATE_FULL = 'full';
38
-
39
-    // FIXME: domains
40
-    /** @var string */
41
-    private $adminMailingList = '[email protected]';
42
-
43
-    private function getOAuthStatusMap(PdoDatabase $database): array
44
-    {
45
-        $oauthStatusQuery = $database->prepare(
46
-            <<<SQL
35
+	const OAUTH_STATE_NONE = 'none';
36
+	const OAUTH_STATE_PARTIAL = 'partial';
37
+	const OAUTH_STATE_FULL = 'full';
38
+
39
+	// FIXME: domains
40
+	/** @var string */
41
+	private $adminMailingList = '[email protected]';
42
+
43
+	private function getOAuthStatusMap(PdoDatabase $database): array
44
+	{
45
+		$oauthStatusQuery = $database->prepare(
46
+			<<<SQL
47 47
     SELECT u.id,
48 48
            CASE
49 49
                WHEN SUM(IF(ot.type = :access, 1, 0)) OVER (PARTITION BY ot.user) > 0 THEN :full
@@ -53,592 +53,592 @@  discard block
 block discarded – undo
53 53
     FROM user u 
54 54
     LEFT JOIN oauthtoken ot ON u.id = ot.user;
55 55
 SQL
56
-        );
57
-
58
-        $oauthStatusQuery->execute([
59
-            ':access' => OAuthUserHelper::TOKEN_ACCESS,
60
-            ':request' => OAuthUserHelper::TOKEN_REQUEST,
61
-            ':full' => self::OAUTH_STATE_FULL,
62
-            ':partial' => self::OAUTH_STATE_PARTIAL,
63
-            ':none' => self::OAUTH_STATE_NONE,
64
-        ]);
65
-        $oauthStatusRawData = $oauthStatusQuery->fetchAll(PDO::FETCH_ASSOC);
66
-        $oauthStatusQuery->closeCursor();
67
-        $oauthStatusMap = [];
68
-
69
-        foreach ($oauthStatusRawData as $row) {
70
-            $oauthStatusMap[(int)$row['id']] = $row['status'];
71
-        }
72
-
73
-        return $oauthStatusMap;
74
-    }
75
-
76
-    /**
77
-     * Main function for this page, when no specific actions are called.
78
-     */
79
-    protected function main()
80
-    {
81
-        $this->setHtmlTitle('User Management');
82
-
83
-        $database = $this->getDatabase();
84
-        $currentUser = User::getCurrent($database);
85
-
86
-        $userSearchRequest = WebRequest::getString('usersearch');
87
-        if ($userSearchRequest !== null) {
88
-            $searchedUser = User::getByUsername($userSearchRequest, $database);
89
-            if ($searchedUser !== false) {
90
-                $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]);
91
-                return;
92
-            }
93
-        }
94
-
95
-        $this->assign('oauthStatusMap', $this->getOAuthStatusMap($database));
96
-
97
-        if (WebRequest::getBoolean("showAll")) {
98
-            $this->assign("showAll", true);
99
-
100
-            $deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch();
101
-            $this->assign('deactivatedUsers', $deactivatedUsers);
102
-
103
-            UserSearchHelper::get($database)->getRoleMap($roleMap);
104
-        }
105
-        else {
106
-            $this->assign("showAll", false);
107
-            $this->assign('deactivatedUsers', array());
108
-
109
-            UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
110
-        }
111
-
112
-        $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
113
-        $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
114
-        $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
115
-        $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
116
-        $stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch();
117
-        $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
118
-        $this->assign('newUsers', $newUsers);
119
-        $this->assign('normalUsers', $normalUsers);
120
-        $this->assign('adminUsers', $adminUsers);
121
-        $this->assign('checkUsers', $checkUsers);
122
-        $this->assign('stewards', $stewards);
123
-        $this->assign('toolRoots', $toolRoots);
124
-
125
-        $this->assign('roles', $roleMap);
126
-
127
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
128
-
129
-        $this->assign('canApprove', $this->barrierTest('approve', $currentUser));
130
-        $this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser));
131
-        $this->assign('canRename', $this->barrierTest('rename', $currentUser));
132
-        $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
133
-        $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
134
-
135
-        // FIXME: domains!
136
-        /** @var Domain $domain */
137
-        $domain = Domain::getById(1, $this->getDatabase());
138
-        $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
139
-
140
-        $this->setTemplate("usermanagement/main.tpl");
141
-    }
142
-
143
-    #region Access control
144
-
145
-    /**
146
-     * Action target for editing the roles assigned to a user
147
-     *
148
-     * @throws ApplicationLogicException
149
-     * @throws SmartyException
150
-     * @throws OptimisticLockFailedException
151
-     * @throws Exception
152
-     */
153
-    protected function editRoles(): void
154
-    {
155
-        $this->setHtmlTitle('User Management');
156
-        $database = $this->getDatabase();
157
-        $domain = Domain::getCurrent($database);
158
-        $userId = WebRequest::getInt('user');
159
-
160
-        /** @var User|false $user */
161
-        $user = User::getById($userId, $database);
162
-
163
-        if ($user === false || $user->isCommunityUser()) {
164
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
165
-        }
166
-
167
-        $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId()));
168
-
169
-        // Dual-mode action
170
-        if (WebRequest::wasPosted()) {
171
-            $this->validateCSRFToken();
172
-
173
-            $reason = WebRequest::postString('reason');
174
-            if ($reason === false || trim($reason) === '') {
175
-                throw new ApplicationLogicException('No reason specified for roles change');
176
-            }
177
-
178
-            /** @var UserRole[] $delete */
179
-            $delete = array();
180
-            /** @var string[] $add */
181
-            $add = array();
182
-
183
-            /** @var UserRole[] $globalDelete */
184
-            $globalDelete = array();
185
-            /** @var string[] $globalAdd */
186
-            $globalAdd = array();
187
-
188
-            foreach ($roleData as $name => $r) {
189
-                if ($r['allowEdit'] !== 1) {
190
-                    // not allowed, to touch this, so ignore it
191
-                    continue;
192
-                }
193
-
194
-                $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
195
-                if ($newValue !== $r['active']) {
196
-                    if ($newValue === 0) {
197
-                        if ($r['globalOnly']) {
198
-                            $globalDelete[] = $r['object'];
199
-                        }
200
-                        else {
201
-                            $delete[] = $r['object'];
202
-                        }
203
-                    }
204
-
205
-                    if ($newValue === 1) {
206
-                        if ($r['globalOnly']) {
207
-                            $globalAdd[] = $name;
208
-                        }
209
-                        else {
210
-                            $add[] = $name;
211
-                        }
212
-                    }
213
-                }
214
-            }
215
-
216
-            // Check there's something to do
217
-            if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) {
218
-                $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
219
-                SessionAlert::warning('No changes made to roles.');
220
-
221
-                return;
222
-            }
223
-
224
-            $removed = array();
225
-            $globalRemoved = array();
226
-
227
-            foreach ($delete as $d) {
228
-                $removed[] = $d->getRole();
229
-                $d->delete();
230
-            }
231
-
232
-            foreach ($globalDelete as $d) {
233
-                $globalRemoved[] = $d->getRole();
234
-                $d->delete();
235
-            }
236
-
237
-            foreach ($add as $x) {
238
-                $a = new UserRole();
239
-                $a->setUser($user->getId());
240
-                $a->setRole($x);
241
-                $a->setDomain($domain->getId());
242
-                $a->setDatabase($database);
243
-                $a->save();
244
-            }
245
-
246
-            foreach ($globalAdd as $x) {
247
-                $a = new UserRole();
248
-                $a->setUser($user->getId());
249
-                $a->setRole($x);
250
-                $a->setDomain(null);
251
-                $a->setDatabase($database);
252
-                $a->save();
253
-            }
254
-
255
-            if ((count($add) + count($delete)) > 0) {
256
-                Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId());
257
-            }
258
-
259
-            if ((count($globalAdd) + count($globalDelete)) > 0) {
260
-                Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved);
261
-            }
262
-
263
-            // dummy save for optimistic locking. If this fails, the entire txn will roll back.
264
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
265
-            $user->save();
266
-
267
-            $this->getNotificationHelper()->userRolesEdited($user, $reason);
268
-            SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
269
-
270
-            $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
271
-        }
272
-        else {
273
-            $this->assignCSRFToken();
274
-            $this->setTemplate('usermanagement/roleedit.tpl');
275
-            $this->assign('user', $user);
276
-            $this->assign('roleData', $roleData);
277
-        }
278
-    }
279
-
280
-    /**
281
-     * Action target for deactivating users
282
-     *
283
-     * @throws ApplicationLogicException
284
-     */
285
-    protected function deactivate()
286
-    {
287
-        $this->setHtmlTitle('User Management');
288
-
289
-        $database = $this->getDatabase();
290
-
291
-        $userId = WebRequest::getInt('user');
292
-
293
-        /** @var User $user */
294
-        $user = User::getById($userId, $database);
295
-
296
-        if ($user === false || $user->isCommunityUser()) {
297
-            throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.');
298
-        }
299
-
300
-        if ($user->isDeactivated()) {
301
-            throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.');
302
-        }
303
-
304
-        // Dual-mode action
305
-        if (WebRequest::wasPosted()) {
306
-            $this->validateCSRFToken();
307
-            $reason = WebRequest::postString('reason');
308
-
309
-            if ($reason === null || trim($reason) === '') {
310
-                throw new ApplicationLogicException('No reason provided');
311
-            }
312
-
313
-            $user->setStatus(User::STATUS_DEACTIVATED);
314
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
315
-            $user->save();
316
-            Logger::deactivatedUser($database, $user, $reason);
317
-
318
-            $this->getNotificationHelper()->userDeactivated($user);
319
-            SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
320
-
321
-            // send email
322
-            $this->sendStatusChangeEmail(
323
-                'Your WP:ACC account has been deactivated',
324
-                'usermanagement/emails/deactivated.tpl',
325
-                $reason,
326
-                $user,
327
-                User::getCurrent($database)->getUsername()
328
-            );
329
-
330
-            $this->redirect('userManagement');
331
-
332
-            return;
333
-        }
334
-        else {
335
-            $this->assignCSRFToken();
336
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
337
-            $this->assign('user', $user);
338
-            $this->assign('status', User::STATUS_DEACTIVATED);
339
-            $this->assign("showReason", true);
340
-
341
-            if (WebRequest::getString('preload')) {
342
-                $this->assign('preload', WebRequest::getString('preload'));
343
-            }
344
-        }
345
-    }
346
-
347
-    /**
348
-     * Entry point for the approve action
349
-     *
350
-     * @throws ApplicationLogicException
351
-     */
352
-    protected function approve()
353
-    {
354
-        $this->setHtmlTitle('User Management');
355
-
356
-        $database = $this->getDatabase();
357
-
358
-        $userId = WebRequest::getInt('user');
359
-        $user = User::getById($userId, $database);
360
-
361
-        if ($user === false || $user->isCommunityUser()) {
362
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
363
-        }
364
-
365
-        if ($user->isActive()) {
366
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
367
-        }
368
-
369
-        // Dual-mode action
370
-        if (WebRequest::wasPosted()) {
371
-            $this->validateCSRFToken();
372
-            $user->setStatus(User::STATUS_ACTIVE);
373
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
374
-            $user->save();
375
-            Logger::approvedUser($database, $user);
376
-
377
-            $this->getNotificationHelper()->userApproved($user);
378
-            SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
379
-
380
-            // send email
381
-            $this->sendStatusChangeEmail(
382
-                'Your WP:ACC account has been approved',
383
-                'usermanagement/emails/approved.tpl',
384
-                null,
385
-                $user,
386
-                User::getCurrent($database)->getUsername()
387
-            );
388
-
389
-            $this->redirect("userManagement");
390
-
391
-            return;
392
-        }
393
-        else {
394
-            $this->assignCSRFToken();
395
-            $this->setTemplate("usermanagement/changelevel-reason.tpl");
396
-            $this->assign("user", $user);
397
-            $this->assign("status", "Active");
398
-            $this->assign("showReason", false);
399
-        }
400
-    }
401
-
402
-    #endregion
403
-
404
-    #region Renaming / Editing
405
-
406
-    /**
407
-     * Entry point for the rename action
408
-     *
409
-     * @throws ApplicationLogicException
410
-     */
411
-    protected function rename()
412
-    {
413
-        $this->setHtmlTitle('User Management');
414
-
415
-        $database = $this->getDatabase();
416
-
417
-        $userId = WebRequest::getInt('user');
418
-        $user = User::getById($userId, $database);
419
-
420
-        if ($user === false || $user->isCommunityUser()) {
421
-            throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
422
-        }
423
-
424
-        // Dual-mode action
425
-        if (WebRequest::wasPosted()) {
426
-            $this->validateCSRFToken();
427
-            $newUsername = WebRequest::postString('newname');
428
-
429
-            if ($newUsername === null || trim($newUsername) === "") {
430
-                throw new ApplicationLogicException('The new username cannot be empty');
431
-            }
432
-
433
-            if (User::getByUsername($newUsername, $database) != false) {
434
-                throw new ApplicationLogicException('The new username already exists');
435
-            }
436
-
437
-            $oldUsername = $user->getUsername();
438
-            $user->setUsername($newUsername);
439
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
440
-
441
-            $user->save();
442
-
443
-            $logEntryData = serialize(array(
444
-                'old' => $oldUsername,
445
-                'new' => $newUsername,
446
-            ));
447
-
448
-            Logger::renamedUser($database, $user, $logEntryData);
449
-
450
-            SessionAlert::quick("Changed User "
451
-                . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
452
-                . " name to "
453
-                . htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
454
-
455
-            $this->getNotificationHelper()->userRenamed($user, $oldUsername);
456
-
457
-            // send an email to the user.
458
-            $this->assign('targetUsername', $user->getUsername());
459
-            $this->assign('toolAdmin', User::getCurrent($database)->getUsername());
460
-            $this->assign('oldUsername', $oldUsername);
461
-            $this->assign('mailingList', $this->adminMailingList);
462
-
463
-            // FIXME: domains!
464
-            /** @var Domain $domain */
465
-            $domain = Domain::getById(1, $database);
466
-            $this->getEmailHelper()->sendMail(
467
-                $this->adminMailingList,
468
-                $user->getEmail(),
469
-                'Your username on WP:ACC has been changed',
470
-                $this->fetchTemplate('usermanagement/emails/renamed.tpl')
471
-            );
472
-
473
-            $this->redirect("userManagement");
474
-
475
-            return;
476
-        }
477
-        else {
478
-            $this->assignCSRFToken();
479
-            $this->setTemplate('usermanagement/renameuser.tpl');
480
-            $this->assign('user', $user);
481
-        }
482
-    }
483
-
484
-    /**
485
-     * Entry point for the edit action
486
-     *
487
-     * @throws ApplicationLogicException
488
-     */
489
-    protected function editUser()
490
-    {
491
-        $this->setHtmlTitle('User Management');
492
-
493
-        $database = $this->getDatabase();
494
-
495
-        $userId = WebRequest::getInt('user');
496
-        $user = User::getById($userId, $database);
497
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
498
-
499
-        if ($user === false || $user->isCommunityUser()) {
500
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
501
-        }
502
-
503
-        // FIXME: domains
504
-        $prefs = new PreferenceManager($database, $user->getId(), 1);
505
-
506
-        // Dual-mode action
507
-        if (WebRequest::wasPosted()) {
508
-            $this->validateCSRFToken();
509
-            $newEmail = WebRequest::postEmail('user_email');
510
-            $newOnWikiName = WebRequest::postString('user_onwikiname');
511
-
512
-            if ($newEmail === null) {
513
-                throw new ApplicationLogicException('Invalid email address');
514
-            }
515
-
516
-            if ($this->validateUnusedEmail($newEmail, $userId)) {
517
-                throw new ApplicationLogicException('The specified email address is already in use.');
518
-            }
519
-
520
-            if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) {
521
-                if (trim($newOnWikiName) == "") {
522
-                    throw new ApplicationLogicException('New on-wiki username cannot be blank');
523
-                }
524
-
525
-                $user->setOnWikiName($newOnWikiName);
526
-            }
527
-
528
-            $user->setEmail($newEmail);
529
-
530
-            $prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode'));
531
-
532
-            $prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation'));
533
-
534
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
535
-
536
-            $user->save();
537
-
538
-            Logger::userPreferencesChange($database, $user);
539
-            $this->getNotificationHelper()->userPrefChange($user);
540
-            SessionAlert::quick('Changes to user\'s preferences have been saved');
541
-
542
-            $this->redirect("userManagement");
543
-
544
-            return;
545
-        }
546
-        else {
547
-            $this->assignCSRFToken();
548
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
549
-                $this->getSiteConfiguration());
550
-            $this->setTemplate('usermanagement/edituser.tpl');
551
-            $this->assign('user', $user);
552
-            $this->assign('oauth', $oauth);
553
-
554
-            $this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE));
555
-            $this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE));
556
-
557
-            $this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false);
558
-
559
-            $this->assign('canManualCreate',
560
-                $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
561
-            $this->assign('canOauthCreate',
562
-                $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
563
-            $this->assign('canBotCreate',
564
-                $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
565
-        }
566
-    }
567
-
568
-    #endregion
569
-
570
-    private function validateUnusedEmail(string $email, int $userId) : bool {
571
-        $query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid';
572
-        $statement = $this->getDatabase()->prepare($query);
573
-        $statement->execute(array(':email' => $email, ':uid' => $userId));
574
-        $inUse = $statement->fetchColumn() > 0;
575
-        $statement->closeCursor();
576
-
577
-        return $inUse;
578
-    }
579
-
580
-    /**
581
-     * Sends a status change email to the user.
582
-     *
583
-     * @param string      $subject           The subject of the email
584
-     * @param string      $template          The smarty template to use
585
-     * @param string|null $reason            The reason for performing the status change
586
-     * @param User        $user              The user affected
587
-     * @param string      $toolAdminUsername The tool admin's username who is making the edit
588
-     */
589
-    private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
590
-    {
591
-        $this->assign('targetUsername', $user->getUsername());
592
-        $this->assign('toolAdmin', $toolAdminUsername);
593
-        $this->assign('actionReason', $reason);
594
-        $this->assign('mailingList', $this->adminMailingList);
595
-
596
-        // FIXME: domains!
597
-        /** @var Domain $domain */
598
-        $domain = Domain::getById(1, $this->getDatabase());
599
-        $this->getEmailHelper()->sendMail(
600
-            $this->adminMailingList,
601
-            $user->getEmail(),
602
-            $subject,
603
-            $this->fetchTemplate($template)
604
-        );
605
-    }
606
-
607
-    /**
608
-     * @param UserRole[] $activeRoles
609
-     *
610
-     * @return array
611
-     */
612
-    private function getRoleData($activeRoles)
613
-    {
614
-        $availableRoles = $this->getSecurityManager()->getAvailableRoles();
615
-
616
-        $currentUser = User::getCurrent($this->getDatabase());
617
-        $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
618
-
619
-        $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
620
-
621
-        $roleData = array();
622
-        foreach ($availableRoles as $role => $data) {
623
-            $intersection = array_intersect($data['editableBy'], $userRoles);
624
-
625
-            $roleData[$role] = $initialValue;
626
-            $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
627
-            $roleData[$role]['description'] = $data['description'];
628
-            $roleData[$role]['globalOnly'] = $data['globalOnly'];
629
-        }
630
-
631
-        foreach ($activeRoles as $role) {
632
-            if (!isset($roleData[$role->getRole()])) {
633
-                // This value is no longer available in the configuration, allow changing (aka removing) it.
634
-                $roleData[$role->getRole()] = $initialValue;
635
-                $roleData[$role->getRole()]['allowEdit'] = 1;
636
-            }
637
-
638
-            $roleData[$role->getRole()]['object'] = $role;
639
-            $roleData[$role->getRole()]['active'] = 1;
640
-        }
641
-
642
-        return $roleData;
643
-    }
56
+		);
57
+
58
+		$oauthStatusQuery->execute([
59
+			':access' => OAuthUserHelper::TOKEN_ACCESS,
60
+			':request' => OAuthUserHelper::TOKEN_REQUEST,
61
+			':full' => self::OAUTH_STATE_FULL,
62
+			':partial' => self::OAUTH_STATE_PARTIAL,
63
+			':none' => self::OAUTH_STATE_NONE,
64
+		]);
65
+		$oauthStatusRawData = $oauthStatusQuery->fetchAll(PDO::FETCH_ASSOC);
66
+		$oauthStatusQuery->closeCursor();
67
+		$oauthStatusMap = [];
68
+
69
+		foreach ($oauthStatusRawData as $row) {
70
+			$oauthStatusMap[(int)$row['id']] = $row['status'];
71
+		}
72
+
73
+		return $oauthStatusMap;
74
+	}
75
+
76
+	/**
77
+	 * Main function for this page, when no specific actions are called.
78
+	 */
79
+	protected function main()
80
+	{
81
+		$this->setHtmlTitle('User Management');
82
+
83
+		$database = $this->getDatabase();
84
+		$currentUser = User::getCurrent($database);
85
+
86
+		$userSearchRequest = WebRequest::getString('usersearch');
87
+		if ($userSearchRequest !== null) {
88
+			$searchedUser = User::getByUsername($userSearchRequest, $database);
89
+			if ($searchedUser !== false) {
90
+				$this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]);
91
+				return;
92
+			}
93
+		}
94
+
95
+		$this->assign('oauthStatusMap', $this->getOAuthStatusMap($database));
96
+
97
+		if (WebRequest::getBoolean("showAll")) {
98
+			$this->assign("showAll", true);
99
+
100
+			$deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch();
101
+			$this->assign('deactivatedUsers', $deactivatedUsers);
102
+
103
+			UserSearchHelper::get($database)->getRoleMap($roleMap);
104
+		}
105
+		else {
106
+			$this->assign("showAll", false);
107
+			$this->assign('deactivatedUsers', array());
108
+
109
+			UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
110
+		}
111
+
112
+		$newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
113
+		$normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
114
+		$adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
115
+		$checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
116
+		$stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch();
117
+		$toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
118
+		$this->assign('newUsers', $newUsers);
119
+		$this->assign('normalUsers', $normalUsers);
120
+		$this->assign('adminUsers', $adminUsers);
121
+		$this->assign('checkUsers', $checkUsers);
122
+		$this->assign('stewards', $stewards);
123
+		$this->assign('toolRoots', $toolRoots);
124
+
125
+		$this->assign('roles', $roleMap);
126
+
127
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
128
+
129
+		$this->assign('canApprove', $this->barrierTest('approve', $currentUser));
130
+		$this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser));
131
+		$this->assign('canRename', $this->barrierTest('rename', $currentUser));
132
+		$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
133
+		$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
134
+
135
+		// FIXME: domains!
136
+		/** @var Domain $domain */
137
+		$domain = Domain::getById(1, $this->getDatabase());
138
+		$this->assign('mediawikiScriptPath', $domain->getWikiArticlePath());
139
+
140
+		$this->setTemplate("usermanagement/main.tpl");
141
+	}
142
+
143
+	#region Access control
144
+
145
+	/**
146
+	 * Action target for editing the roles assigned to a user
147
+	 *
148
+	 * @throws ApplicationLogicException
149
+	 * @throws SmartyException
150
+	 * @throws OptimisticLockFailedException
151
+	 * @throws Exception
152
+	 */
153
+	protected function editRoles(): void
154
+	{
155
+		$this->setHtmlTitle('User Management');
156
+		$database = $this->getDatabase();
157
+		$domain = Domain::getCurrent($database);
158
+		$userId = WebRequest::getInt('user');
159
+
160
+		/** @var User|false $user */
161
+		$user = User::getById($userId, $database);
162
+
163
+		if ($user === false || $user->isCommunityUser()) {
164
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
165
+		}
166
+
167
+		$roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId()));
168
+
169
+		// Dual-mode action
170
+		if (WebRequest::wasPosted()) {
171
+			$this->validateCSRFToken();
172
+
173
+			$reason = WebRequest::postString('reason');
174
+			if ($reason === false || trim($reason) === '') {
175
+				throw new ApplicationLogicException('No reason specified for roles change');
176
+			}
177
+
178
+			/** @var UserRole[] $delete */
179
+			$delete = array();
180
+			/** @var string[] $add */
181
+			$add = array();
182
+
183
+			/** @var UserRole[] $globalDelete */
184
+			$globalDelete = array();
185
+			/** @var string[] $globalAdd */
186
+			$globalAdd = array();
187
+
188
+			foreach ($roleData as $name => $r) {
189
+				if ($r['allowEdit'] !== 1) {
190
+					// not allowed, to touch this, so ignore it
191
+					continue;
192
+				}
193
+
194
+				$newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
195
+				if ($newValue !== $r['active']) {
196
+					if ($newValue === 0) {
197
+						if ($r['globalOnly']) {
198
+							$globalDelete[] = $r['object'];
199
+						}
200
+						else {
201
+							$delete[] = $r['object'];
202
+						}
203
+					}
204
+
205
+					if ($newValue === 1) {
206
+						if ($r['globalOnly']) {
207
+							$globalAdd[] = $name;
208
+						}
209
+						else {
210
+							$add[] = $name;
211
+						}
212
+					}
213
+				}
214
+			}
215
+
216
+			// Check there's something to do
217
+			if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) {
218
+				$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
219
+				SessionAlert::warning('No changes made to roles.');
220
+
221
+				return;
222
+			}
223
+
224
+			$removed = array();
225
+			$globalRemoved = array();
226
+
227
+			foreach ($delete as $d) {
228
+				$removed[] = $d->getRole();
229
+				$d->delete();
230
+			}
231
+
232
+			foreach ($globalDelete as $d) {
233
+				$globalRemoved[] = $d->getRole();
234
+				$d->delete();
235
+			}
236
+
237
+			foreach ($add as $x) {
238
+				$a = new UserRole();
239
+				$a->setUser($user->getId());
240
+				$a->setRole($x);
241
+				$a->setDomain($domain->getId());
242
+				$a->setDatabase($database);
243
+				$a->save();
244
+			}
245
+
246
+			foreach ($globalAdd as $x) {
247
+				$a = new UserRole();
248
+				$a->setUser($user->getId());
249
+				$a->setRole($x);
250
+				$a->setDomain(null);
251
+				$a->setDatabase($database);
252
+				$a->save();
253
+			}
254
+
255
+			if ((count($add) + count($delete)) > 0) {
256
+				Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId());
257
+			}
258
+
259
+			if ((count($globalAdd) + count($globalDelete)) > 0) {
260
+				Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved);
261
+			}
262
+
263
+			// dummy save for optimistic locking. If this fails, the entire txn will roll back.
264
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
265
+			$user->save();
266
+
267
+			$this->getNotificationHelper()->userRolesEdited($user, $reason);
268
+			SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
269
+
270
+			$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
271
+		}
272
+		else {
273
+			$this->assignCSRFToken();
274
+			$this->setTemplate('usermanagement/roleedit.tpl');
275
+			$this->assign('user', $user);
276
+			$this->assign('roleData', $roleData);
277
+		}
278
+	}
279
+
280
+	/**
281
+	 * Action target for deactivating users
282
+	 *
283
+	 * @throws ApplicationLogicException
284
+	 */
285
+	protected function deactivate()
286
+	{
287
+		$this->setHtmlTitle('User Management');
288
+
289
+		$database = $this->getDatabase();
290
+
291
+		$userId = WebRequest::getInt('user');
292
+
293
+		/** @var User $user */
294
+		$user = User::getById($userId, $database);
295
+
296
+		if ($user === false || $user->isCommunityUser()) {
297
+			throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.');
298
+		}
299
+
300
+		if ($user->isDeactivated()) {
301
+			throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.');
302
+		}
303
+
304
+		// Dual-mode action
305
+		if (WebRequest::wasPosted()) {
306
+			$this->validateCSRFToken();
307
+			$reason = WebRequest::postString('reason');
308
+
309
+			if ($reason === null || trim($reason) === '') {
310
+				throw new ApplicationLogicException('No reason provided');
311
+			}
312
+
313
+			$user->setStatus(User::STATUS_DEACTIVATED);
314
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
315
+			$user->save();
316
+			Logger::deactivatedUser($database, $user, $reason);
317
+
318
+			$this->getNotificationHelper()->userDeactivated($user);
319
+			SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
320
+
321
+			// send email
322
+			$this->sendStatusChangeEmail(
323
+				'Your WP:ACC account has been deactivated',
324
+				'usermanagement/emails/deactivated.tpl',
325
+				$reason,
326
+				$user,
327
+				User::getCurrent($database)->getUsername()
328
+			);
329
+
330
+			$this->redirect('userManagement');
331
+
332
+			return;
333
+		}
334
+		else {
335
+			$this->assignCSRFToken();
336
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
337
+			$this->assign('user', $user);
338
+			$this->assign('status', User::STATUS_DEACTIVATED);
339
+			$this->assign("showReason", true);
340
+
341
+			if (WebRequest::getString('preload')) {
342
+				$this->assign('preload', WebRequest::getString('preload'));
343
+			}
344
+		}
345
+	}
346
+
347
+	/**
348
+	 * Entry point for the approve action
349
+	 *
350
+	 * @throws ApplicationLogicException
351
+	 */
352
+	protected function approve()
353
+	{
354
+		$this->setHtmlTitle('User Management');
355
+
356
+		$database = $this->getDatabase();
357
+
358
+		$userId = WebRequest::getInt('user');
359
+		$user = User::getById($userId, $database);
360
+
361
+		if ($user === false || $user->isCommunityUser()) {
362
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
363
+		}
364
+
365
+		if ($user->isActive()) {
366
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
367
+		}
368
+
369
+		// Dual-mode action
370
+		if (WebRequest::wasPosted()) {
371
+			$this->validateCSRFToken();
372
+			$user->setStatus(User::STATUS_ACTIVE);
373
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
374
+			$user->save();
375
+			Logger::approvedUser($database, $user);
376
+
377
+			$this->getNotificationHelper()->userApproved($user);
378
+			SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
379
+
380
+			// send email
381
+			$this->sendStatusChangeEmail(
382
+				'Your WP:ACC account has been approved',
383
+				'usermanagement/emails/approved.tpl',
384
+				null,
385
+				$user,
386
+				User::getCurrent($database)->getUsername()
387
+			);
388
+
389
+			$this->redirect("userManagement");
390
+
391
+			return;
392
+		}
393
+		else {
394
+			$this->assignCSRFToken();
395
+			$this->setTemplate("usermanagement/changelevel-reason.tpl");
396
+			$this->assign("user", $user);
397
+			$this->assign("status", "Active");
398
+			$this->assign("showReason", false);
399
+		}
400
+	}
401
+
402
+	#endregion
403
+
404
+	#region Renaming / Editing
405
+
406
+	/**
407
+	 * Entry point for the rename action
408
+	 *
409
+	 * @throws ApplicationLogicException
410
+	 */
411
+	protected function rename()
412
+	{
413
+		$this->setHtmlTitle('User Management');
414
+
415
+		$database = $this->getDatabase();
416
+
417
+		$userId = WebRequest::getInt('user');
418
+		$user = User::getById($userId, $database);
419
+
420
+		if ($user === false || $user->isCommunityUser()) {
421
+			throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
422
+		}
423
+
424
+		// Dual-mode action
425
+		if (WebRequest::wasPosted()) {
426
+			$this->validateCSRFToken();
427
+			$newUsername = WebRequest::postString('newname');
428
+
429
+			if ($newUsername === null || trim($newUsername) === "") {
430
+				throw new ApplicationLogicException('The new username cannot be empty');
431
+			}
432
+
433
+			if (User::getByUsername($newUsername, $database) != false) {
434
+				throw new ApplicationLogicException('The new username already exists');
435
+			}
436
+
437
+			$oldUsername = $user->getUsername();
438
+			$user->setUsername($newUsername);
439
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
440
+
441
+			$user->save();
442
+
443
+			$logEntryData = serialize(array(
444
+				'old' => $oldUsername,
445
+				'new' => $newUsername,
446
+			));
447
+
448
+			Logger::renamedUser($database, $user, $logEntryData);
449
+
450
+			SessionAlert::quick("Changed User "
451
+				. htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
452
+				. " name to "
453
+				. htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
454
+
455
+			$this->getNotificationHelper()->userRenamed($user, $oldUsername);
456
+
457
+			// send an email to the user.
458
+			$this->assign('targetUsername', $user->getUsername());
459
+			$this->assign('toolAdmin', User::getCurrent($database)->getUsername());
460
+			$this->assign('oldUsername', $oldUsername);
461
+			$this->assign('mailingList', $this->adminMailingList);
462
+
463
+			// FIXME: domains!
464
+			/** @var Domain $domain */
465
+			$domain = Domain::getById(1, $database);
466
+			$this->getEmailHelper()->sendMail(
467
+				$this->adminMailingList,
468
+				$user->getEmail(),
469
+				'Your username on WP:ACC has been changed',
470
+				$this->fetchTemplate('usermanagement/emails/renamed.tpl')
471
+			);
472
+
473
+			$this->redirect("userManagement");
474
+
475
+			return;
476
+		}
477
+		else {
478
+			$this->assignCSRFToken();
479
+			$this->setTemplate('usermanagement/renameuser.tpl');
480
+			$this->assign('user', $user);
481
+		}
482
+	}
483
+
484
+	/**
485
+	 * Entry point for the edit action
486
+	 *
487
+	 * @throws ApplicationLogicException
488
+	 */
489
+	protected function editUser()
490
+	{
491
+		$this->setHtmlTitle('User Management');
492
+
493
+		$database = $this->getDatabase();
494
+
495
+		$userId = WebRequest::getInt('user');
496
+		$user = User::getById($userId, $database);
497
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
498
+
499
+		if ($user === false || $user->isCommunityUser()) {
500
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
501
+		}
502
+
503
+		// FIXME: domains
504
+		$prefs = new PreferenceManager($database, $user->getId(), 1);
505
+
506
+		// Dual-mode action
507
+		if (WebRequest::wasPosted()) {
508
+			$this->validateCSRFToken();
509
+			$newEmail = WebRequest::postEmail('user_email');
510
+			$newOnWikiName = WebRequest::postString('user_onwikiname');
511
+
512
+			if ($newEmail === null) {
513
+				throw new ApplicationLogicException('Invalid email address');
514
+			}
515
+
516
+			if ($this->validateUnusedEmail($newEmail, $userId)) {
517
+				throw new ApplicationLogicException('The specified email address is already in use.');
518
+			}
519
+
520
+			if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) {
521
+				if (trim($newOnWikiName) == "") {
522
+					throw new ApplicationLogicException('New on-wiki username cannot be blank');
523
+				}
524
+
525
+				$user->setOnWikiName($newOnWikiName);
526
+			}
527
+
528
+			$user->setEmail($newEmail);
529
+
530
+			$prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode'));
531
+
532
+			$prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation'));
533
+
534
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
535
+
536
+			$user->save();
537
+
538
+			Logger::userPreferencesChange($database, $user);
539
+			$this->getNotificationHelper()->userPrefChange($user);
540
+			SessionAlert::quick('Changes to user\'s preferences have been saved');
541
+
542
+			$this->redirect("userManagement");
543
+
544
+			return;
545
+		}
546
+		else {
547
+			$this->assignCSRFToken();
548
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
549
+				$this->getSiteConfiguration());
550
+			$this->setTemplate('usermanagement/edituser.tpl');
551
+			$this->assign('user', $user);
552
+			$this->assign('oauth', $oauth);
553
+
554
+			$this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE));
555
+			$this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE));
556
+
557
+			$this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false);
558
+
559
+			$this->assign('canManualCreate',
560
+				$this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
561
+			$this->assign('canOauthCreate',
562
+				$this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'));
563
+			$this->assign('canBotCreate',
564
+				$this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'));
565
+		}
566
+	}
567
+
568
+	#endregion
569
+
570
+	private function validateUnusedEmail(string $email, int $userId) : bool {
571
+		$query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid';
572
+		$statement = $this->getDatabase()->prepare($query);
573
+		$statement->execute(array(':email' => $email, ':uid' => $userId));
574
+		$inUse = $statement->fetchColumn() > 0;
575
+		$statement->closeCursor();
576
+
577
+		return $inUse;
578
+	}
579
+
580
+	/**
581
+	 * Sends a status change email to the user.
582
+	 *
583
+	 * @param string      $subject           The subject of the email
584
+	 * @param string      $template          The smarty template to use
585
+	 * @param string|null $reason            The reason for performing the status change
586
+	 * @param User        $user              The user affected
587
+	 * @param string      $toolAdminUsername The tool admin's username who is making the edit
588
+	 */
589
+	private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
590
+	{
591
+		$this->assign('targetUsername', $user->getUsername());
592
+		$this->assign('toolAdmin', $toolAdminUsername);
593
+		$this->assign('actionReason', $reason);
594
+		$this->assign('mailingList', $this->adminMailingList);
595
+
596
+		// FIXME: domains!
597
+		/** @var Domain $domain */
598
+		$domain = Domain::getById(1, $this->getDatabase());
599
+		$this->getEmailHelper()->sendMail(
600
+			$this->adminMailingList,
601
+			$user->getEmail(),
602
+			$subject,
603
+			$this->fetchTemplate($template)
604
+		);
605
+	}
606
+
607
+	/**
608
+	 * @param UserRole[] $activeRoles
609
+	 *
610
+	 * @return array
611
+	 */
612
+	private function getRoleData($activeRoles)
613
+	{
614
+		$availableRoles = $this->getSecurityManager()->getAvailableRoles();
615
+
616
+		$currentUser = User::getCurrent($this->getDatabase());
617
+		$this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
618
+
619
+		$initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
620
+
621
+		$roleData = array();
622
+		foreach ($availableRoles as $role => $data) {
623
+			$intersection = array_intersect($data['editableBy'], $userRoles);
624
+
625
+			$roleData[$role] = $initialValue;
626
+			$roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
627
+			$roleData[$role]['description'] = $data['description'];
628
+			$roleData[$role]['globalOnly'] = $data['globalOnly'];
629
+		}
630
+
631
+		foreach ($activeRoles as $role) {
632
+			if (!isset($roleData[$role->getRole()])) {
633
+				// This value is no longer available in the configuration, allow changing (aka removing) it.
634
+				$roleData[$role->getRole()] = $initialValue;
635
+				$roleData[$role->getRole()]['allowEdit'] = 1;
636
+			}
637
+
638
+			$roleData[$role->getRole()]['object'] = $role;
639
+			$roleData[$role->getRole()]['active'] = 1;
640
+		}
641
+
642
+		return $roleData;
643
+	}
644 644
 }
Please login to merge, or discard this patch.
includes/Pages/PageDomainSwitch.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -19,48 +19,48 @@
 block discarded – undo
19 19
 
20 20
 class PageDomainSwitch extends InternalPageBase
21 21
 {
22
-    /**
23
-     * @inheritDoc
24
-     */
25
-    protected function main()
26
-    {
27
-        if (!WebRequest::wasPosted()) {
28
-            $this->redirect('/');
22
+	/**
23
+	 * @inheritDoc
24
+	 */
25
+	protected function main()
26
+	{
27
+		if (!WebRequest::wasPosted()) {
28
+			$this->redirect('/');
29 29
 
30
-            return;
31
-        }
30
+			return;
31
+		}
32 32
 
33
-        $database = $this->getDatabase();
34
-        $currentUser = User::getCurrent($database);
33
+		$database = $this->getDatabase();
34
+		$currentUser = User::getCurrent($database);
35 35
 
36
-        /** @var Domain|false $newDomain */
37
-        $newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database);
36
+		/** @var Domain|false $newDomain */
37
+		$newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database);
38 38
 
39
-        if ($newDomain === false) {
40
-            $this->redirect('/');
39
+		if ($newDomain === false) {
40
+			$this->redirect('/');
41 41
 
42
-            return;
43
-        }
42
+			return;
43
+		}
44 44
 
45
-        try {
46
-            $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47
-        }
48
-        catch(DomainSwitchNotAllowedException $ex){
49
-            throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50
-        }
45
+		try {
46
+			$this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47
+		}
48
+		catch(DomainSwitchNotAllowedException $ex){
49
+			throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50
+		}
51 51
 
52
-        // try to stay on the same page if possible.
53
-        // This only checks basic ACLs and not domain privileges, so this may still result in a 403.
52
+		// try to stay on the same page if possible.
53
+		// This only checks basic ACLs and not domain privileges, so this may still result in a 403.
54 54
 
55
-        $referrer = WebRequest::postString('referrer');
56
-        $priorPath = explode('/', $referrer);
57
-        $router = new RequestRouter();
58
-        $route = $router->getRouteFromPath($priorPath);
55
+		$referrer = WebRequest::postString('referrer');
56
+		$priorPath = explode('/', $referrer);
57
+		$router = new RequestRouter();
58
+		$route = $router->getRouteFromPath($priorPath);
59 59
 
60
-        if ($this->barrierTest($route[1], $currentUser, $route[0])) {
61
-            $this->redirect('/' . $referrer);
62
-        } else {
63
-            $this->redirect('/');
64
-        }
65
-    }
60
+		if ($this->barrierTest($route[1], $currentUser, $route[0])) {
61
+			$this->redirect('/' . $referrer);
62
+		} else {
63
+			$this->redirect('/');
64
+		}
65
+	}
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
         try {
46 46
             $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47 47
         }
48
-        catch(DomainSwitchNotAllowedException $ex){
48
+        catch (DomainSwitchNotAllowedException $ex) {
49 49
             throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50 50
         }
51 51
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
         try {
46 46
             $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain);
47 47
         }
48
-        catch(DomainSwitchNotAllowedException $ex){
48
+        catch(DomainSwitchNotAllowedException $ex) {
49 49
             throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
50 50
         }
51 51
 
Please login to merge, or discard this patch.