Completed
Push — bootstrap4 ( dc7ca1...d74498 )
by Simon
06:19
created
includes/Pages/PageTeam.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     protected function main()
21 21
     {
22
-        $path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
+        $path = $this->getSiteConfiguration()->getFilePath().'/team.json';
23 23
         $json = file_get_contents($path);
24 24
 
25 25
         $teamData = json_decode($json, true);
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -12,31 +12,31 @@
 block discarded – undo
12 12
 
13 13
 class PageTeam extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
-        $json = file_get_contents($path);
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
+		$json = file_get_contents($path);
23 23
 
24
-        $teamData = json_decode($json, true);
24
+		$teamData = json_decode($json, true);
25 25
 
26
-        $active = array();
27
-        $inactive = array();
26
+		$active = array();
27
+		$inactive = array();
28 28
 
29
-        foreach ($teamData as $name => $item) {
30
-            if (count($item['Role']) == 0) {
31
-                $inactive[$name] = $item;
32
-            }
33
-            else {
34
-                $active[$name] = $item;
35
-            }
36
-        }
29
+		foreach ($teamData as $name => $item) {
30
+			if (count($item['Role']) == 0) {
31
+				$inactive[$name] = $item;
32
+			}
33
+			else {
34
+				$active[$name] = $item;
35
+			}
36
+		}
37 37
 
38
-        $this->assign('developer', $active);
39
-        $this->assign('inactiveDeveloper', $inactive);
40
-        $this->setTemplate('team/team.tpl');
41
-    }
38
+		$this->assign('developer', $active);
39
+		$this->assign('inactiveDeveloper', $inactive);
40
+		$this->setTemplate('team/team.tpl');
41
+	}
42 42
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsUsers.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
         }
63 63
 
64 64
         $safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8');
65
-        $this->setHtmlTitle($safeUsername . ' :: Users :: Statistics');
65
+        $this->setHtmlTitle($safeUsername.' :: Users :: Statistics');
66 66
 
67 67
         $activitySummary = $database->prepare(<<<SQL
68 68
 SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
 
22 22
 class StatsUsers extends InternalPageBase
23 23
 {
24
-    public function main()
25
-    {
26
-        $this->setHtmlTitle('Users :: Statistics');
24
+	public function main()
25
+	{
26
+		$this->setHtmlTitle('Users :: Statistics');
27 27
 
28
-        $database = $this->getDatabase();
28
+		$database = $this->getDatabase();
29 29
 
30
-        $query = <<<SQL
30
+		$query = <<<SQL
31 31
 select
32 32
     u.id
33 33
     , u.username
@@ -43,36 +43,36 @@  discard block
 block discarded – undo
43 43
 where u.status = 'Active'
44 44
 SQL;
45 45
 
46
-        $users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC);
47
-        $this->assign('users', $users);
46
+		$users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC);
47
+		$this->assign('users', $users);
48 48
 
49
-        $this->assign('statsPageTitle', 'Account Creation Tool users');
50
-        $this->setTemplate("statistics/users.tpl");
51
-    }
49
+		$this->assign('statsPageTitle', 'Account Creation Tool users');
50
+		$this->setTemplate("statistics/users.tpl");
51
+	}
52 52
 
53
-    /**
54
-     * Entry point for the detail action.
55
-     *
56
-     * @throws ApplicationLogicException
57
-     */
58
-    protected function detail()
59
-    {
60
-        $userId = WebRequest::getInt('user');
61
-        if ($userId === null) {
62
-            throw new ApplicationLogicException("User not found");
63
-        }
53
+	/**
54
+	 * Entry point for the detail action.
55
+	 *
56
+	 * @throws ApplicationLogicException
57
+	 */
58
+	protected function detail()
59
+	{
60
+		$userId = WebRequest::getInt('user');
61
+		if ($userId === null) {
62
+			throw new ApplicationLogicException("User not found");
63
+		}
64 64
 
65
-        $database = $this->getDatabase();
65
+		$database = $this->getDatabase();
66 66
 
67
-        $user = User::getById($userId, $database);
68
-        if ($user == false) {
69
-            throw new ApplicationLogicException('User not found');
70
-        }
67
+		$user = User::getById($userId, $database);
68
+		if ($user == false) {
69
+			throw new ApplicationLogicException('User not found');
70
+		}
71 71
 
72
-        $safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8');
73
-        $this->setHtmlTitle($safeUsername . ' :: Users :: Statistics');
72
+		$safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8');
73
+		$this->setHtmlTitle($safeUsername . ' :: Users :: Statistics');
74 74
 
75
-        $activitySummary = $database->prepare(<<<SQL
75
+		$activitySummary = $database->prepare(<<<SQL
76 76
 SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count
77 77
 FROM log
78 78
 INNER JOIN user ON log.user = user.id
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 WHERE user.username = :username
81 81
 GROUP BY action;
82 82
 SQL
83
-        );
84
-        $activitySummary->execute(array(":username" => $user->getUsername()));
85
-        $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC);
83
+		);
84
+		$activitySummary->execute(array(":username" => $user->getUsername()));
85
+		$activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC);
86 86
 
87
-        $this->assign("user", $user);
88
-        $this->assign("activity", $activitySummaryData);
87
+		$this->assign("user", $user);
88
+		$this->assign("activity", $activitySummaryData);
89 89
 
90
-        $usersCreatedQuery = $database->prepare(<<<SQL
90
+		$usersCreatedQuery = $database->prepare(<<<SQL
91 91
 SELECT log.timestamp time, request.name name, request.id id
92 92
 FROM log
93 93
 INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request')
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
     AND (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y')
99 99
 ORDER BY log.timestamp;
100 100
 SQL
101
-        );
102
-        $usersCreatedQuery->execute(array(":username" => $user->getUsername()));
103
-        $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
104
-        $this->assign("created", $usersCreated);
101
+		);
102
+		$usersCreatedQuery->execute(array(":username" => $user->getUsername()));
103
+		$usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
104
+		$this->assign("created", $usersCreated);
105 105
 
106
-        $usersNotCreatedQuery = $database->prepare(<<<SQL
106
+		$usersNotCreatedQuery = $database->prepare(<<<SQL
107 107
 SELECT log.timestamp time, request.name name, request.id id
108 108
 FROM log
109 109
 JOIN request ON request.id = log.objectid AND log.objecttype = 'Request'
@@ -114,37 +114,37 @@  discard block
 block discarded – undo
114 114
     AND (emailtemplate.oncreated = '0' OR log.action = 'Closed custom-n' OR log.action = 'Closed 0')
115 115
 ORDER BY log.timestamp;
116 116
 SQL
117
-        );
118
-        $usersNotCreatedQuery->execute(array(":username" => $user->getUsername()));
119
-        $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
120
-        $this->assign("notcreated", $usersNotCreated);
121
-
122
-        /** @var Log[] $logs */
123
-        $logs = LogSearchHelper::get($database)
124
-            ->byObjectType('User')
125
-            ->byObjectId($user->getId())
126
-            ->getRecordCount($logCount)
127
-            ->fetch();
128
-
129
-        if ($logCount === 0) {
130
-            $this->assign('accountlog', array());
131
-        }
132
-        else {
133
-            list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
134
-
135
-            $this->assign("accountlog", $logData);
136
-            $this->assign("users", $users);
137
-        }
138
-
139
-        $currentUser = User::getCurrent($database);
140
-        $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class));
141
-        $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class));
142
-        $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class));
143
-        $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class));
144
-        $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class));
145
-        $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class));
146
-
147
-        $this->assign('statsPageTitle', 'Account Creation Tool users');
148
-        $this->setTemplate("statistics/userdetail.tpl");
149
-    }
117
+		);
118
+		$usersNotCreatedQuery->execute(array(":username" => $user->getUsername()));
119
+		$usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
120
+		$this->assign("notcreated", $usersNotCreated);
121
+
122
+		/** @var Log[] $logs */
123
+		$logs = LogSearchHelper::get($database)
124
+			->byObjectType('User')
125
+			->byObjectId($user->getId())
126
+			->getRecordCount($logCount)
127
+			->fetch();
128
+
129
+		if ($logCount === 0) {
130
+			$this->assign('accountlog', array());
131
+		}
132
+		else {
133
+			list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
134
+
135
+			$this->assign("accountlog", $logData);
136
+			$this->assign("users", $users);
137
+		}
138
+
139
+		$currentUser = User::getCurrent($database);
140
+		$this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class));
141
+		$this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class));
142
+		$this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class));
143
+		$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class));
144
+		$this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class));
145
+		$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class));
146
+
147
+		$this->assign('statsPageTitle', 'Account Creation Tool users');
148
+		$this->setTemplate("statistics/userdetail.tpl");
149
+	}
150 150
 }
Please login to merge, or discard this patch.
includes/Pages/PageLogin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
             }
37 37
             else {
38 38
                 // This is the login form, not the request form. We need protection here.
39
-                $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri());
39
+                $this->redirectUrl('https://'.WebRequest::serverName().WebRequest::requestUri());
40 40
 
41 41
                 return;
42 42
             }
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -20,137 +20,137 @@
 block discarded – undo
20 20
  */
21 21
 class PageLogin extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     */
26
-    protected function main()
27
-    {
28
-        // Start by enforcing HTTPS
29
-        if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) {
30
-            if (WebRequest::isHttps()) {
31
-                // Client can clearly use HTTPS, so let's enforce it for all connections.
32
-                if (!headers_sent()) {
33
-                    header("Strict-Transport-Security: max-age=15768000");
34
-                }
35
-            }
36
-            else {
37
-                // This is the login form, not the request form. We need protection here.
38
-                $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri());
39
-
40
-                return;
41
-            }
42
-        }
43
-
44
-        if (WebRequest::wasPosted()) {
45
-            // POST. Do some authentication.
46
-            $this->validateCSRFToken();
47
-
48
-            $user = null;
49
-            try {
50
-                $user = $this->getAuthenticatingUser();
51
-            }
52
-            catch (ApplicationLogicException $ex) {
53
-                SessionAlert::error($ex->getMessage());
54
-                $this->redirect('login');
55
-
56
-                return;
57
-            }
58
-
59
-            // Touch force logout
60
-            $user->setForceLogout(false);
61
-            $user->save();
62
-
63
-            if ($this->getSiteConfiguration()->getEnforceOAuth()) {
64
-                if (!$user->isOAuthLinked()) {
65
-                    $oauthHelper = $this->getOAuthHelper();
66
-
67
-                    $requestToken = $oauthHelper->getRequestToken();
68
-                    $user->setOAuthRequestToken($requestToken->key);
69
-                    $user->setOAuthRequestSecret($requestToken->secret);
70
-                    $user->save();
71
-
72
-                    WebRequest::setPartialLogin($user);
73
-                    $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
74
-
75
-                    return;
76
-                }
77
-            }
78
-
79
-            // User is partially linked to OAuth. This is not allowed. Enforce it for this user.
80
-            if ($user->getOnWikiName() === '##OAUTH##') {
81
-                $oauthHelper = $this->getOAuthHelper();
82
-
83
-                $requestToken = $oauthHelper->getRequestToken();
84
-                $user->setOAuthRequestToken($requestToken->key);
85
-                $user->setOAuthRequestSecret($requestToken->secret);
86
-                $user->save();
87
-
88
-                WebRequest::setPartialLogin($user);
89
-                $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
90
-
91
-                return;
92
-            }
93
-
94
-            WebRequest::setLoggedInUser($user);
95
-
96
-            $this->goBackWhenceYouCame($user);
97
-        }
98
-        else {
99
-            // GET. Show the form
100
-            $this->assignCSRFToken();
101
-            $this->setTemplate("login.tpl");
102
-        }
103
-    }
104
-
105
-    /**
106
-     * @return User
107
-     * @throws ApplicationLogicException
108
-     */
109
-    private function getAuthenticatingUser()
110
-    {
111
-        $username = WebRequest::postString("username");
112
-        $password = WebRequest::postString("password");
113
-
114
-        if ($username === null || $password === null || $username === "" || $password === "") {
115
-            throw new ApplicationLogicException("No username/password specified");
116
-        }
117
-
118
-        /** @var User $user */
119
-        $user = User::getByUsername($username, $this->getDatabase());
120
-
121
-        if ($user == false || !$user->authenticate($password)) {
122
-            throw new ApplicationLogicException("Authentication failed");
123
-        }
124
-
125
-        return $user;
126
-    }
127
-
128
-    protected function isProtectedPage()
129
-    {
130
-        return false;
131
-    }
132
-
133
-    /**
134
-     * Redirect the user back to wherever they came from after a successful login
135
-     *
136
-     * @param User $user
137
-     */
138
-    private function goBackWhenceYouCame(User $user)
139
-    {
140
-        // Redirect to wherever the user came from
141
-        $redirectDestination = WebRequest::clearPostLoginRedirect();
142
-        if ($redirectDestination !== null) {
143
-            $this->redirectUrl($redirectDestination);
144
-        }
145
-        else {
146
-            if ($user->isNewUser()) {
147
-                // home page isn't allowed, go to preferences instead
148
-                $this->redirect('preferences');
149
-            }
150
-            else {
151
-                // go to the home page
152
-                $this->redirect('');
153
-            }
154
-        }
155
-    }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 */
26
+	protected function main()
27
+	{
28
+		// Start by enforcing HTTPS
29
+		if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) {
30
+			if (WebRequest::isHttps()) {
31
+				// Client can clearly use HTTPS, so let's enforce it for all connections.
32
+				if (!headers_sent()) {
33
+					header("Strict-Transport-Security: max-age=15768000");
34
+				}
35
+			}
36
+			else {
37
+				// This is the login form, not the request form. We need protection here.
38
+				$this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri());
39
+
40
+				return;
41
+			}
42
+		}
43
+
44
+		if (WebRequest::wasPosted()) {
45
+			// POST. Do some authentication.
46
+			$this->validateCSRFToken();
47
+
48
+			$user = null;
49
+			try {
50
+				$user = $this->getAuthenticatingUser();
51
+			}
52
+			catch (ApplicationLogicException $ex) {
53
+				SessionAlert::error($ex->getMessage());
54
+				$this->redirect('login');
55
+
56
+				return;
57
+			}
58
+
59
+			// Touch force logout
60
+			$user->setForceLogout(false);
61
+			$user->save();
62
+
63
+			if ($this->getSiteConfiguration()->getEnforceOAuth()) {
64
+				if (!$user->isOAuthLinked()) {
65
+					$oauthHelper = $this->getOAuthHelper();
66
+
67
+					$requestToken = $oauthHelper->getRequestToken();
68
+					$user->setOAuthRequestToken($requestToken->key);
69
+					$user->setOAuthRequestSecret($requestToken->secret);
70
+					$user->save();
71
+
72
+					WebRequest::setPartialLogin($user);
73
+					$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
74
+
75
+					return;
76
+				}
77
+			}
78
+
79
+			// User is partially linked to OAuth. This is not allowed. Enforce it for this user.
80
+			if ($user->getOnWikiName() === '##OAUTH##') {
81
+				$oauthHelper = $this->getOAuthHelper();
82
+
83
+				$requestToken = $oauthHelper->getRequestToken();
84
+				$user->setOAuthRequestToken($requestToken->key);
85
+				$user->setOAuthRequestSecret($requestToken->secret);
86
+				$user->save();
87
+
88
+				WebRequest::setPartialLogin($user);
89
+				$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
90
+
91
+				return;
92
+			}
93
+
94
+			WebRequest::setLoggedInUser($user);
95
+
96
+			$this->goBackWhenceYouCame($user);
97
+		}
98
+		else {
99
+			// GET. Show the form
100
+			$this->assignCSRFToken();
101
+			$this->setTemplate("login.tpl");
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * @return User
107
+	 * @throws ApplicationLogicException
108
+	 */
109
+	private function getAuthenticatingUser()
110
+	{
111
+		$username = WebRequest::postString("username");
112
+		$password = WebRequest::postString("password");
113
+
114
+		if ($username === null || $password === null || $username === "" || $password === "") {
115
+			throw new ApplicationLogicException("No username/password specified");
116
+		}
117
+
118
+		/** @var User $user */
119
+		$user = User::getByUsername($username, $this->getDatabase());
120
+
121
+		if ($user == false || !$user->authenticate($password)) {
122
+			throw new ApplicationLogicException("Authentication failed");
123
+		}
124
+
125
+		return $user;
126
+	}
127
+
128
+	protected function isProtectedPage()
129
+	{
130
+		return false;
131
+	}
132
+
133
+	/**
134
+	 * Redirect the user back to wherever they came from after a successful login
135
+	 *
136
+	 * @param User $user
137
+	 */
138
+	private function goBackWhenceYouCame(User $user)
139
+	{
140
+		// Redirect to wherever the user came from
141
+		$redirectDestination = WebRequest::clearPostLoginRedirect();
142
+		if ($redirectDestination !== null) {
143
+			$this->redirectUrl($redirectDestination);
144
+		}
145
+		else {
146
+			if ($user->isNewUser()) {
147
+				// home page isn't allowed, go to preferences instead
148
+				$this->redirect('preferences');
149
+			}
150
+			else {
151
+				// go to the home page
152
+				$this->redirect('');
153
+			}
154
+		}
155
+	}
156 156
 }
Please login to merge, or discard this patch.
includes/Pages/Request/PageEmailConfirmationRequired.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@
 block discarded – undo
12 12
 
13 13
 class PageEmailConfirmationRequired extends PublicInterfacePageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $this->setTemplate('request/email-confirmation.tpl');
22
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->setTemplate('request/email-confirmation.tpl');
22
+	}
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/Request/PageRequestAccount.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -19,150 +19,150 @@
 block discarded – undo
19 19
 
20 20
 class PageRequestAccount extends PublicInterfacePageBase
21 21
 {
22
-    /**
23
-     * Main function for this page, when no specific actions are called.
24
-     * @return void
25
-     */
26
-    protected function main()
27
-    {
28
-        // dual mode page
29
-        if (WebRequest::wasPosted()) {
30
-            $request = $this->createNewRequest();
31
-
32
-            $validationErrors = $this->validateRequest($request);
33
-
34
-            if (count($validationErrors) > 0) {
35
-                foreach ($validationErrors as $validationError) {
36
-                    SessionAlert::error($validationError->getErrorMessage());
37
-                }
38
-
39
-                // Preserve the data after an error
40
-                WebRequest::setSessionContext('accountReq',
41
-                    array(
42
-                        'username' => WebRequest::postString('name'),
43
-                        'email'    => WebRequest::postEmail('email'),
44
-                        'comments' => WebRequest::postString('comments'),
45
-                    )
46
-                );
47
-
48
-                // Validation error, bomb out early.
49
-                $this->redirect();
50
-
51
-                return;
52
-            }
53
-
54
-            // actually save the request to the database
55
-            if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
56
-                $this->saveAsEmailConfirmation($request);
57
-            }
58
-            else {
59
-                $this->saveWithoutEmailConfirmation($request);
60
-            }
61
-        }
62
-        else {
63
-            // set the form values from the session context
64
-            $context = WebRequest::getSessionContext('accountReq');
65
-            if ($context !== null && is_array($context)) {
66
-                $this->assign('username', $context['username']);
67
-                $this->assign('email', $context['email']);
68
-                $this->assign('comments', $context['comments']);
69
-            }
70
-
71
-            // Clear it for a refresh
72
-            WebRequest::setSessionContext('accountReq', null);
73
-
74
-            $this->setTemplate('request/request-form.tpl');
75
-        }
76
-    }
77
-
78
-    /**
79
-     * @return Request
80
-     */
81
-    protected function createNewRequest()
82
-    {
83
-        $request = new Request();
84
-        $request->setDatabase($this->getDatabase());
85
-
86
-        $request->setName(WebRequest::postString('name'));
87
-        $request->setEmail(WebRequest::postEmail('email'));
88
-        $request->setComment(WebRequest::postString('comments'));
89
-
90
-        $request->setIp(WebRequest::remoteAddress());
91
-        $request->setForwardedIp(WebRequest::forwardedAddress());
92
-
93
-        $request->setUserAgent(WebRequest::userAgent());
94
-
95
-        return $request;
96
-    }
97
-
98
-    /**
99
-     * @param Request $request
100
-     *
101
-     * @return ValidationError[]
102
-     */
103
-    protected function validateRequest($request)
104
-    {
105
-        $validationHelper = new RequestValidationHelper(
106
-            new BanHelper($this->getDatabase()),
107
-            $request,
108
-            WebRequest::postEmail('emailconfirm'),
109
-            $this->getDatabase(),
110
-            $this->getAntiSpoofProvider(),
111
-            $this->getXffTrustProvider(),
112
-            $this->getHttpHelper(),
113
-            $this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(),
114
-            $this->getSiteConfiguration()->getTitleBlacklistEnabled(),
115
-            $this->getTorExitProvider());
116
-
117
-        // These are arrays of ValidationError.
118
-        $nameValidation = $validationHelper->validateName();
119
-        $emailValidation = $validationHelper->validateEmail();
120
-        $otherValidation = $validationHelper->validateOther();
121
-
122
-        $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation);
123
-
124
-        return $validationErrors;
125
-    }
126
-
127
-    /**
128
-     * @param Request $request
129
-     *
130
-     * @throws Exception
131
-     */
132
-    protected function saveAsEmailConfirmation(Request $request)
133
-    {
134
-        $request->generateEmailConfirmationHash();
135
-        $request->save();
136
-
137
-        $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
138
-            $request->getIp(),
139
-            $request->getForwardedIp());
140
-
141
-        $this->assign("ip", $trustedIp);
142
-        $this->assign("id", $request->getId());
143
-        $this->assign("hash", $request->getEmailConfirm());
144
-
145
-        // Sends the confirmation email to the user.
146
-        $this->getEmailHelper()->sendMail(
147
-            $request->getEmail(),
148
-            "[ACC #{$request->getId()}] English Wikipedia Account Request",
149
-            $this->fetchTemplate('request/confirmation-mail.tpl'));
150
-
151
-        $this->redirect('emailConfirmationRequired');
152
-    }
153
-
154
-    /**
155
-     * @param Request $request
156
-     *
157
-     * @throws Exception
158
-     */
159
-    protected function saveWithoutEmailConfirmation(Request $request)
160
-    {
161
-        $request->setEmailConfirm(0); // fixme Since it can't be null
162
-        $request->save();
163
-
164
-        $this->getNotificationHelper()->requestReceived($request);
165
-
166
-        $this->redirect('requestSubmitted');
167
-    }
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		// dual mode page
29
+		if (WebRequest::wasPosted()) {
30
+			$request = $this->createNewRequest();
31
+
32
+			$validationErrors = $this->validateRequest($request);
33
+
34
+			if (count($validationErrors) > 0) {
35
+				foreach ($validationErrors as $validationError) {
36
+					SessionAlert::error($validationError->getErrorMessage());
37
+				}
38
+
39
+				// Preserve the data after an error
40
+				WebRequest::setSessionContext('accountReq',
41
+					array(
42
+						'username' => WebRequest::postString('name'),
43
+						'email'    => WebRequest::postEmail('email'),
44
+						'comments' => WebRequest::postString('comments'),
45
+					)
46
+				);
47
+
48
+				// Validation error, bomb out early.
49
+				$this->redirect();
50
+
51
+				return;
52
+			}
53
+
54
+			// actually save the request to the database
55
+			if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) {
56
+				$this->saveAsEmailConfirmation($request);
57
+			}
58
+			else {
59
+				$this->saveWithoutEmailConfirmation($request);
60
+			}
61
+		}
62
+		else {
63
+			// set the form values from the session context
64
+			$context = WebRequest::getSessionContext('accountReq');
65
+			if ($context !== null && is_array($context)) {
66
+				$this->assign('username', $context['username']);
67
+				$this->assign('email', $context['email']);
68
+				$this->assign('comments', $context['comments']);
69
+			}
70
+
71
+			// Clear it for a refresh
72
+			WebRequest::setSessionContext('accountReq', null);
73
+
74
+			$this->setTemplate('request/request-form.tpl');
75
+		}
76
+	}
77
+
78
+	/**
79
+	 * @return Request
80
+	 */
81
+	protected function createNewRequest()
82
+	{
83
+		$request = new Request();
84
+		$request->setDatabase($this->getDatabase());
85
+
86
+		$request->setName(WebRequest::postString('name'));
87
+		$request->setEmail(WebRequest::postEmail('email'));
88
+		$request->setComment(WebRequest::postString('comments'));
89
+
90
+		$request->setIp(WebRequest::remoteAddress());
91
+		$request->setForwardedIp(WebRequest::forwardedAddress());
92
+
93
+		$request->setUserAgent(WebRequest::userAgent());
94
+
95
+		return $request;
96
+	}
97
+
98
+	/**
99
+	 * @param Request $request
100
+	 *
101
+	 * @return ValidationError[]
102
+	 */
103
+	protected function validateRequest($request)
104
+	{
105
+		$validationHelper = new RequestValidationHelper(
106
+			new BanHelper($this->getDatabase()),
107
+			$request,
108
+			WebRequest::postEmail('emailconfirm'),
109
+			$this->getDatabase(),
110
+			$this->getAntiSpoofProvider(),
111
+			$this->getXffTrustProvider(),
112
+			$this->getHttpHelper(),
113
+			$this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(),
114
+			$this->getSiteConfiguration()->getTitleBlacklistEnabled(),
115
+			$this->getTorExitProvider());
116
+
117
+		// These are arrays of ValidationError.
118
+		$nameValidation = $validationHelper->validateName();
119
+		$emailValidation = $validationHelper->validateEmail();
120
+		$otherValidation = $validationHelper->validateOther();
121
+
122
+		$validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation);
123
+
124
+		return $validationErrors;
125
+	}
126
+
127
+	/**
128
+	 * @param Request $request
129
+	 *
130
+	 * @throws Exception
131
+	 */
132
+	protected function saveAsEmailConfirmation(Request $request)
133
+	{
134
+		$request->generateEmailConfirmationHash();
135
+		$request->save();
136
+
137
+		$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
138
+			$request->getIp(),
139
+			$request->getForwardedIp());
140
+
141
+		$this->assign("ip", $trustedIp);
142
+		$this->assign("id", $request->getId());
143
+		$this->assign("hash", $request->getEmailConfirm());
144
+
145
+		// Sends the confirmation email to the user.
146
+		$this->getEmailHelper()->sendMail(
147
+			$request->getEmail(),
148
+			"[ACC #{$request->getId()}] English Wikipedia Account Request",
149
+			$this->fetchTemplate('request/confirmation-mail.tpl'));
150
+
151
+		$this->redirect('emailConfirmationRequired');
152
+	}
153
+
154
+	/**
155
+	 * @param Request $request
156
+	 *
157
+	 * @throws Exception
158
+	 */
159
+	protected function saveWithoutEmailConfirmation(Request $request)
160
+	{
161
+		$request->setEmailConfirm(0); // fixme Since it can't be null
162
+		$request->save();
163
+
164
+		$this->getNotificationHelper()->requestReceived($request);
165
+
166
+		$this->redirect('requestSubmitted');
167
+	}
168 168
 }
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/Request/PageRequestSubmitted.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@
 block discarded – undo
12 12
 
13 13
 class PageRequestSubmitted extends PublicInterfacePageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $this->setTemplate('request/email-confirmed.tpl');
22
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->setTemplate('request/email-confirmed.tpl');
22
+	}
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/Request/PageConfirmEmail.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -18,67 +18,67 @@
 block discarded – undo
18 18
 
19 19
 class PageConfirmEmail extends PublicInterfacePageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     * @throws ApplicationLogicException
24
-     * @throws Exception
25
-     */
26
-    protected function main()
27
-    {
28
-        $id = WebRequest::getInt('id');
29
-        $si = WebRequest::getString('si');
30
-
31
-        if ($id === null || $si === null) {
32
-            throw new ApplicationLogicException('Link incomplete - please double check the link you received.');
33
-        }
34
-
35
-        /** @var Request|false $request */
36
-        $request = Request::getById($id, $this->getDatabase());
37
-
38
-        if ($request === false) {
39
-            throw new ApplicationLogicException('Request not found');
40
-        }
41
-
42
-        if ($request->getEmailConfirm() === 'Confirmed') {
43
-            // request has already been confirmed. Bomb out silently.
44
-            $this->redirect('requestSubmitted');
45
-
46
-            return;
47
-        }
48
-
49
-        if ($request->getEmailConfirm() === $si) {
50
-            $request->setEmailConfirm('Confirmed');
51
-        }
52
-        else {
53
-            throw new ApplicationLogicException('The confirmation value does not appear to match the expected value');
54
-        }
55
-
56
-        try {
57
-            $request->save();
58
-        }
59
-        catch (OptimisticLockFailedException $ex) {
60
-            // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting
61
-            // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they
62
-            // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the
63
-            // case.
64
-
65
-            $request = Request::getById($id, $this->getDatabase());
66
-            if ($request->getEmailConfirm() === 'Confirmed') {
67
-                // we've already done the sanity checks above
68
-
69
-                $this->redirect('requestSubmitted');
70
-
71
-                // skip the log and notification
72
-                return;
73
-            }
74
-
75
-            // something really weird happened. Another race condition?
76
-            throw $ex;
77
-        }
78
-
79
-        Logger::emailConfirmed($this->getDatabase(), $request);
80
-        $this->getNotificationHelper()->requestReceived($request);
81
-
82
-        $this->redirect('requestSubmitted');
83
-    }
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 * @throws ApplicationLogicException
24
+	 * @throws Exception
25
+	 */
26
+	protected function main()
27
+	{
28
+		$id = WebRequest::getInt('id');
29
+		$si = WebRequest::getString('si');
30
+
31
+		if ($id === null || $si === null) {
32
+			throw new ApplicationLogicException('Link incomplete - please double check the link you received.');
33
+		}
34
+
35
+		/** @var Request|false $request */
36
+		$request = Request::getById($id, $this->getDatabase());
37
+
38
+		if ($request === false) {
39
+			throw new ApplicationLogicException('Request not found');
40
+		}
41
+
42
+		if ($request->getEmailConfirm() === 'Confirmed') {
43
+			// request has already been confirmed. Bomb out silently.
44
+			$this->redirect('requestSubmitted');
45
+
46
+			return;
47
+		}
48
+
49
+		if ($request->getEmailConfirm() === $si) {
50
+			$request->setEmailConfirm('Confirmed');
51
+		}
52
+		else {
53
+			throw new ApplicationLogicException('The confirmation value does not appear to match the expected value');
54
+		}
55
+
56
+		try {
57
+			$request->save();
58
+		}
59
+		catch (OptimisticLockFailedException $ex) {
60
+			// Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting
61
+			// to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they
62
+			// double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the
63
+			// case.
64
+
65
+			$request = Request::getById($id, $this->getDatabase());
66
+			if ($request->getEmailConfirm() === 'Confirmed') {
67
+				// we've already done the sanity checks above
68
+
69
+				$this->redirect('requestSubmitted');
70
+
71
+				// skip the log and notification
72
+				return;
73
+			}
74
+
75
+			// something really weird happened. Another race condition?
76
+			throw $ex;
77
+		}
78
+
79
+		Logger::emailConfirmed($this->getDatabase(), $request);
80
+		$this->getNotificationHelper()->requestReceived($request);
81
+
82
+		$this->redirect('requestSubmitted');
83
+	}
84 84
 }
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/RequestActionBase.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,37 +16,37 @@
 block discarded – undo
16 16
 
17 17
 abstract class RequestActionBase extends InternalPageBase
18 18
 {
19
-    /**
20
-     * @param PdoDatabase $database
21
-     *
22
-     * @return Request
23
-     * @throws ApplicationLogicException
24
-     */
25
-    protected function getRequest(PdoDatabase $database)
26
-    {
27
-        $requestId = WebRequest::postInt('request');
28
-        if ($requestId === null) {
29
-            throw new ApplicationLogicException('Request ID not found');
30
-        }
31
-
32
-        /** @var Request $request */
33
-        $request = Request::getById($requestId, $database);
34
-
35
-        if ($request === false) {
36
-            throw new ApplicationLogicException('Request not found');
37
-        }
38
-
39
-        return $request;
40
-    }
41
-
42
-    final protected function checkPosted()
43
-    {
44
-        // if the request was not posted, send the user away.
45
-        if (!WebRequest::wasPosted()) {
46
-            throw new ApplicationLogicException('This page does not support GET methods.');
47
-        }
48
-
49
-        // validate the CSRF token
50
-        $this->validateCSRFToken();
51
-    }
19
+	/**
20
+	 * @param PdoDatabase $database
21
+	 *
22
+	 * @return Request
23
+	 * @throws ApplicationLogicException
24
+	 */
25
+	protected function getRequest(PdoDatabase $database)
26
+	{
27
+		$requestId = WebRequest::postInt('request');
28
+		if ($requestId === null) {
29
+			throw new ApplicationLogicException('Request ID not found');
30
+		}
31
+
32
+		/** @var Request $request */
33
+		$request = Request::getById($requestId, $database);
34
+
35
+		if ($request === false) {
36
+			throw new ApplicationLogicException('Request not found');
37
+		}
38
+
39
+		return $request;
40
+	}
41
+
42
+	final protected function checkPosted()
43
+	{
44
+		// if the request was not posted, send the user away.
45
+		if (!WebRequest::wasPosted()) {
46
+			throw new ApplicationLogicException('This page does not support GET methods.');
47
+		}
48
+
49
+		// validate the CSRF token
50
+		$this->validateCSRFToken();
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDropRequest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 
16 16
 class PageDropRequest extends PageCloseRequest
17 17
 {
18
-    protected function getTemplate(PdoDatabase $database)
19
-    {
20
-        return EmailTemplate::getDroppedTemplate();
21
-    }
18
+	protected function getTemplate(PdoDatabase $database)
19
+	{
20
+		return EmailTemplate::getDroppedTemplate();
21
+	}
22 22
 
23
-    protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
-    {
25
-        return false;
26
-    }
23
+	protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
+	{
25
+		return false;
26
+	}
27 27
 
28
-    protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
-    {
30
-        return false;
31
-    }
28
+	protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
+	{
30
+		return false;
31
+	}
32 32
 
33
-    protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList)
34
-    {
35
-    }
33
+	protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList)
34
+	{
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.