Failed Conditions
Push — newinternal ( 216d62...410e59 )
by Simon
05:28 queued 13s
created
includes/Pages/RequestAction/PageSendToUser.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 
18 18
 class PageSendToUser extends RequestActionBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @throws ApplicationLogicException
23
-     * @throws Exception
24
-     */
25
-    protected function main()
26
-    {
27
-        $this->checkPosted();
28
-        $database = $this->getDatabase();
29
-        $request = $this->getRequest($database);
30
-
31
-        if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
-            throw new ApplicationLogicException('You don\'t have this request reserved!');
33
-        }
34
-
35
-        $username = WebRequest::postString('user');
36
-        if ($username === null) {
37
-            throw new ApplicationLogicException('User must be specified');
38
-        }
39
-
40
-        $user = User::getByUsername($username, $database);
41
-        if ($user === false) {
42
-            throw new ApplicationLogicException('User not found');
43
-        }
44
-
45
-        if (!$user->isActive()) {
46
-            throw new ApplicationLogicException('User is currently not active on the tool');
47
-        }
48
-
49
-        $request->setReserved($user->getId());
50
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
-        $request->save();
52
-
53
-        Logger::sendReservation($database, $request, $user);
54
-        $this->getNotificationHelper()->requestReservationSent($request, $user);
55
-        SessionAlert::success("Reservation sent successfully");
56
-
57
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
58
-    }
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @throws ApplicationLogicException
23
+	 * @throws Exception
24
+	 */
25
+	protected function main()
26
+	{
27
+		$this->checkPosted();
28
+		$database = $this->getDatabase();
29
+		$request = $this->getRequest($database);
30
+
31
+		if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
+			throw new ApplicationLogicException('You don\'t have this request reserved!');
33
+		}
34
+
35
+		$username = WebRequest::postString('user');
36
+		if ($username === null) {
37
+			throw new ApplicationLogicException('User must be specified');
38
+		}
39
+
40
+		$user = User::getByUsername($username, $database);
41
+		if ($user === false) {
42
+			throw new ApplicationLogicException('User not found');
43
+		}
44
+
45
+		if (!$user->isActive()) {
46
+			throw new ApplicationLogicException('User is currently not active on the tool');
47
+		}
48
+
49
+		$request->setReserved($user->getId());
50
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
+		$request->save();
52
+
53
+		Logger::sendReservation($database, $request, $user);
54
+		$this->getNotificationHelper()->requestReservationSent($request, $user);
55
+		SessionAlert::success("Reservation sent successfully");
56
+
57
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
58
+	}
59 59
 }
Please login to merge, or discard this patch.
includes/Pages/PageEmailManagement.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -19,175 +19,175 @@
 block discarded – undo
19 19
 
20 20
 class PageEmailManagement extends InternalPageBase
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
-        $this->setHtmlTitle('Close Emails');
29
-
30
-        // Get all active email templates
31
-        $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
-        $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
-
34
-        $this->assign('activeTemplates', $activeTemplates);
35
-        $this->assign('inactiveTemplates', $inactiveTemplates);
36
-
37
-        $user = User::getCurrent($this->getDatabase());
38
-        $this->assign('canCreate', $this->barrierTest('create', $user));
39
-        $this->assign('canEdit', $this->barrierTest('edit', $user));
40
-
41
-        $this->setTemplate('email-management/main.tpl');
42
-    }
43
-
44
-    protected function view()
45
-    {
46
-        $this->setHtmlTitle('Close Emails');
47
-
48
-        $database = $this->getDatabase();
49
-        $template = $this->getTemplate($database);
50
-
51
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
53
-
54
-        $this->assign('id', $template->getId());
55
-        $this->assign('emailTemplate', $template);
56
-        $this->assign('createdid', $createdId);
57
-        $this->assign('requeststates', $requestStates);
58
-
59
-        $this->setTemplate('email-management/view.tpl');
60
-    }
61
-
62
-    /**
63
-     * @param PdoDatabase $database
64
-     *
65
-     * @return EmailTemplate
66
-     * @throws ApplicationLogicException
67
-     */
68
-    protected function getTemplate(PdoDatabase $database)
69
-    {
70
-        $templateId = WebRequest::getInt('id');
71
-        if ($templateId === null) {
72
-            throw new ApplicationLogicException('Template not specified');
73
-        }
74
-        $template = EmailTemplate::getById($templateId, $database);
75
-        if ($template === false || !is_a($template, EmailTemplate::class)) {
76
-            throw new ApplicationLogicException('Template not found');
77
-        }
78
-
79
-        return $template;
80
-    }
81
-
82
-    protected function edit()
83
-    {
84
-        $this->setHtmlTitle('Close Emails');
85
-
86
-        $database = $this->getDatabase();
87
-        $template = $this->getTemplate($database);
88
-
89
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
91
-
92
-        if (WebRequest::wasPosted()) {
93
-            $this->validateCSRFToken();
94
-
95
-            $this->modifyTemplateData($template);
96
-
97
-            $other = EmailTemplate::getByName($template->getName(), $database);
98
-            if ($other !== false && $other->getId() !== $template->getId()) {
99
-                throw new ApplicationLogicException('A template with this name already exists');
100
-            }
101
-
102
-            if ($template->getId() === $createdId) {
103
-                $template->setDefaultAction(EmailTemplate::CREATED);
104
-                $template->setActive(true);
105
-                $template->setPreloadOnly(false);
106
-            }
107
-
108
-            // optimistically lock on load of edit form
109
-            $updateVersion = WebRequest::postInt('updateversion');
110
-            $template->setUpdateVersion($updateVersion);
111
-
112
-            $template->save();
113
-            Logger::editedEmail($database, $template);
114
-            $this->getNotificationHelper()->emailEdited($template);
115
-            SessionAlert::success("Email template has been saved successfully.");
116
-
117
-            $this->redirect('emailManagement');
118
-        }
119
-        else {
120
-            $this->assignCSRFToken();
121
-            $this->assign('id', $template->getId());
122
-            $this->assign('emailTemplate', $template);
123
-            $this->assign('createdid', $createdId);
124
-            $this->assign('requeststates', $requestStates);
125
-
126
-            $this->setTemplate('email-management/edit.tpl');
127
-        }
128
-    }
129
-
130
-    /**
131
-     * @param EmailTemplate $template
132
-     *
133
-     * @throws ApplicationLogicException
134
-     */
135
-    private function modifyTemplateData(EmailTemplate $template)
136
-    {
137
-        $name = WebRequest::postString('name');
138
-        if ($name === null || $name === '') {
139
-            throw new ApplicationLogicException('Name not specified');
140
-        }
141
-
142
-        $template->setName($name);
143
-
144
-        $text = WebRequest::postString('text');
145
-        if ($text === null || $text === '') {
146
-            throw new ApplicationLogicException('Text not specified');
147
-        }
148
-
149
-        $template->setText($text);
150
-
151
-        $template->setJsquestion(WebRequest::postString('jsquestion'));
152
-
153
-        $template->setDefaultAction(WebRequest::postString('defaultaction'));
154
-        $template->setActive(WebRequest::postBoolean('active'));
155
-        $template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
-    }
157
-
158
-    protected function create()
159
-    {
160
-        $this->setHtmlTitle('Close Emails');
161
-
162
-        $database = $this->getDatabase();
163
-
164
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
165
-
166
-        if (WebRequest::wasPosted()) {
167
-            $this->validateCSRFToken();
168
-            $template = new EmailTemplate();
169
-            $template->setDatabase($database);
170
-
171
-            $this->modifyTemplateData($template);
172
-
173
-            $other = EmailTemplate::getByName($template->getName(), $database);
174
-            if ($other !== false) {
175
-                throw new ApplicationLogicException('A template with this name already exists');
176
-            }
177
-
178
-            $template->save();
179
-
180
-            Logger::createEmail($database, $template);
181
-            $this->getNotificationHelper()->emailCreated($template);
182
-
183
-            SessionAlert::success("Email template has been saved successfully.");
184
-
185
-            $this->redirect('emailManagement');
186
-        }
187
-        else {
188
-            $this->assignCSRFToken();
189
-            $this->assign('requeststates', $requestStates);
190
-            $this->setTemplate('email-management/create.tpl');
191
-        }
192
-    }
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->setHtmlTitle('Close Emails');
29
+
30
+		// Get all active email templates
31
+		$activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
+		$inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
+
34
+		$this->assign('activeTemplates', $activeTemplates);
35
+		$this->assign('inactiveTemplates', $inactiveTemplates);
36
+
37
+		$user = User::getCurrent($this->getDatabase());
38
+		$this->assign('canCreate', $this->barrierTest('create', $user));
39
+		$this->assign('canEdit', $this->barrierTest('edit', $user));
40
+
41
+		$this->setTemplate('email-management/main.tpl');
42
+	}
43
+
44
+	protected function view()
45
+	{
46
+		$this->setHtmlTitle('Close Emails');
47
+
48
+		$database = $this->getDatabase();
49
+		$template = $this->getTemplate($database);
50
+
51
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
53
+
54
+		$this->assign('id', $template->getId());
55
+		$this->assign('emailTemplate', $template);
56
+		$this->assign('createdid', $createdId);
57
+		$this->assign('requeststates', $requestStates);
58
+
59
+		$this->setTemplate('email-management/view.tpl');
60
+	}
61
+
62
+	/**
63
+	 * @param PdoDatabase $database
64
+	 *
65
+	 * @return EmailTemplate
66
+	 * @throws ApplicationLogicException
67
+	 */
68
+	protected function getTemplate(PdoDatabase $database)
69
+	{
70
+		$templateId = WebRequest::getInt('id');
71
+		if ($templateId === null) {
72
+			throw new ApplicationLogicException('Template not specified');
73
+		}
74
+		$template = EmailTemplate::getById($templateId, $database);
75
+		if ($template === false || !is_a($template, EmailTemplate::class)) {
76
+			throw new ApplicationLogicException('Template not found');
77
+		}
78
+
79
+		return $template;
80
+	}
81
+
82
+	protected function edit()
83
+	{
84
+		$this->setHtmlTitle('Close Emails');
85
+
86
+		$database = $this->getDatabase();
87
+		$template = $this->getTemplate($database);
88
+
89
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
91
+
92
+		if (WebRequest::wasPosted()) {
93
+			$this->validateCSRFToken();
94
+
95
+			$this->modifyTemplateData($template);
96
+
97
+			$other = EmailTemplate::getByName($template->getName(), $database);
98
+			if ($other !== false && $other->getId() !== $template->getId()) {
99
+				throw new ApplicationLogicException('A template with this name already exists');
100
+			}
101
+
102
+			if ($template->getId() === $createdId) {
103
+				$template->setDefaultAction(EmailTemplate::CREATED);
104
+				$template->setActive(true);
105
+				$template->setPreloadOnly(false);
106
+			}
107
+
108
+			// optimistically lock on load of edit form
109
+			$updateVersion = WebRequest::postInt('updateversion');
110
+			$template->setUpdateVersion($updateVersion);
111
+
112
+			$template->save();
113
+			Logger::editedEmail($database, $template);
114
+			$this->getNotificationHelper()->emailEdited($template);
115
+			SessionAlert::success("Email template has been saved successfully.");
116
+
117
+			$this->redirect('emailManagement');
118
+		}
119
+		else {
120
+			$this->assignCSRFToken();
121
+			$this->assign('id', $template->getId());
122
+			$this->assign('emailTemplate', $template);
123
+			$this->assign('createdid', $createdId);
124
+			$this->assign('requeststates', $requestStates);
125
+
126
+			$this->setTemplate('email-management/edit.tpl');
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * @param EmailTemplate $template
132
+	 *
133
+	 * @throws ApplicationLogicException
134
+	 */
135
+	private function modifyTemplateData(EmailTemplate $template)
136
+	{
137
+		$name = WebRequest::postString('name');
138
+		if ($name === null || $name === '') {
139
+			throw new ApplicationLogicException('Name not specified');
140
+		}
141
+
142
+		$template->setName($name);
143
+
144
+		$text = WebRequest::postString('text');
145
+		if ($text === null || $text === '') {
146
+			throw new ApplicationLogicException('Text not specified');
147
+		}
148
+
149
+		$template->setText($text);
150
+
151
+		$template->setJsquestion(WebRequest::postString('jsquestion'));
152
+
153
+		$template->setDefaultAction(WebRequest::postString('defaultaction'));
154
+		$template->setActive(WebRequest::postBoolean('active'));
155
+		$template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
+	}
157
+
158
+	protected function create()
159
+	{
160
+		$this->setHtmlTitle('Close Emails');
161
+
162
+		$database = $this->getDatabase();
163
+
164
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
165
+
166
+		if (WebRequest::wasPosted()) {
167
+			$this->validateCSRFToken();
168
+			$template = new EmailTemplate();
169
+			$template->setDatabase($database);
170
+
171
+			$this->modifyTemplateData($template);
172
+
173
+			$other = EmailTemplate::getByName($template->getName(), $database);
174
+			if ($other !== false) {
175
+				throw new ApplicationLogicException('A template with this name already exists');
176
+			}
177
+
178
+			$template->save();
179
+
180
+			Logger::createEmail($database, $template);
181
+			$this->getNotificationHelper()->emailCreated($template);
182
+
183
+			SessionAlert::success("Email template has been saved successfully.");
184
+
185
+			$this->redirect('emailManagement');
186
+		}
187
+		else {
188
+			$this->assignCSRFToken();
189
+			$this->assign('requeststates', $requestStates);
190
+			$this->setTemplate('email-management/create.tpl');
191
+		}
192
+	}
193 193
 }
Please login to merge, or discard this patch.
includes/Pages/PageWelcomeTemplateManagement.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -19,223 +19,223 @@
 block discarded – undo
19 19
 
20 20
 class PageWelcomeTemplateManagement extends InternalPageBase
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
-        $templateList = WelcomeTemplate::getAll($this->getDatabase());
29
-
30
-        $this->assignCSRFToken();
31
-
32
-        $user = User::getCurrent($this->getDatabase());
33
-        $this->assign('canEdit', $this->barrierTest('edit', $user));
34
-        $this->assign('canAdd', $this->barrierTest('add', $user));
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		$templateList = WelcomeTemplate::getAll($this->getDatabase());
29
+
30
+		$this->assignCSRFToken();
31
+
32
+		$user = User::getCurrent($this->getDatabase());
33
+		$this->assign('canEdit', $this->barrierTest('edit', $user));
34
+		$this->assign('canAdd', $this->barrierTest('add', $user));
35 35
 
36
-        $this->assign('templateList', $templateList);
37
-        $this->setTemplate('welcome-template/list.tpl');
38
-    }
36
+		$this->assign('templateList', $templateList);
37
+		$this->setTemplate('welcome-template/list.tpl');
38
+	}
39 39
 
40
-    /**
41
-     * Handles the requests for selecting a template to use.
42
-     *
43
-     * @throws ApplicationLogicException
44
-     */
45
-    protected function select()
46
-    {
47
-        // get rid of GETs
48
-        if (!WebRequest::wasPosted()) {
49
-            $this->redirect('welcomeTemplates');
50
-        }
51
-
52
-        $this->validateCSRFToken();
53
-
54
-        $user = User::getCurrent($this->getDatabase());
55
-
56
-        if (WebRequest::postBoolean('disable')) {
57
-            $user->setWelcomeTemplate(null);
58
-            $user->save();
59
-
60
-            SessionAlert::success('Disabled automatic user welcoming.');
61
-            $this->redirect('welcomeTemplates');
62
-
63
-            return;
64
-        }
65
-
66
-        $database = $this->getDatabase();
40
+	/**
41
+	 * Handles the requests for selecting a template to use.
42
+	 *
43
+	 * @throws ApplicationLogicException
44
+	 */
45
+	protected function select()
46
+	{
47
+		// get rid of GETs
48
+		if (!WebRequest::wasPosted()) {
49
+			$this->redirect('welcomeTemplates');
50
+		}
51
+
52
+		$this->validateCSRFToken();
53
+
54
+		$user = User::getCurrent($this->getDatabase());
55
+
56
+		if (WebRequest::postBoolean('disable')) {
57
+			$user->setWelcomeTemplate(null);
58
+			$user->save();
59
+
60
+			SessionAlert::success('Disabled automatic user welcoming.');
61
+			$this->redirect('welcomeTemplates');
62
+
63
+			return;
64
+		}
65
+
66
+		$database = $this->getDatabase();
67 67
 
68
-        $templateId = WebRequest::postInt('template');
69
-        /** @var false|WelcomeTemplate $template */
70
-        $template = WelcomeTemplate::getById($templateId, $database);
68
+		$templateId = WebRequest::postInt('template');
69
+		/** @var false|WelcomeTemplate $template */
70
+		$template = WelcomeTemplate::getById($templateId, $database);
71 71
 
72
-        if ($template === false || $template->isDeleted()) {
73
-            throw new ApplicationLogicException('Unknown template');
74
-        }
72
+		if ($template === false || $template->isDeleted()) {
73
+			throw new ApplicationLogicException('Unknown template');
74
+		}
75 75
 
76
-        $user->setWelcomeTemplate($template->getId());
77
-        $user->save();
76
+		$user->setWelcomeTemplate($template->getId());
77
+		$user->save();
78 78
 
79
-        SessionAlert::success("Updated selected welcome template for automatic welcoming.");
79
+		SessionAlert::success("Updated selected welcome template for automatic welcoming.");
80 80
 
81
-        $this->redirect('welcomeTemplates');
82
-    }
81
+		$this->redirect('welcomeTemplates');
82
+	}
83 83
 
84
-    /**
85
-     * Handles the requests for viewing a template.
86
-     *
87
-     * @throws ApplicationLogicException
88
-     */
89
-    protected function view()
90
-    {
91
-        $database = $this->getDatabase();
84
+	/**
85
+	 * Handles the requests for viewing a template.
86
+	 *
87
+	 * @throws ApplicationLogicException
88
+	 */
89
+	protected function view()
90
+	{
91
+		$database = $this->getDatabase();
92 92
 
93
-        $templateId = WebRequest::getInt('template');
93
+		$templateId = WebRequest::getInt('template');
94 94
 
95
-        /** @var WelcomeTemplate $template */
96
-        $template = WelcomeTemplate::getById($templateId, $database);
95
+		/** @var WelcomeTemplate $template */
96
+		$template = WelcomeTemplate::getById($templateId, $database);
97 97
 
98
-        if ($template === false) {
99
-            throw new ApplicationLogicException('Cannot find requested template');
100
-        }
98
+		if ($template === false) {
99
+			throw new ApplicationLogicException('Cannot find requested template');
100
+		}
101 101
 
102
-        $templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
102
+		$templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode());
103 103
 
104
-        $this->assign('templateHtml', $templateHtml);
105
-        $this->assign('template', $template);
106
-        $this->setTemplate('welcome-template/view.tpl');
107
-    }
104
+		$this->assign('templateHtml', $templateHtml);
105
+		$this->assign('template', $template);
106
+		$this->setTemplate('welcome-template/view.tpl');
107
+	}
108 108
 
109
-    /**
110
-     * Handler for the add action to create a new welcome template
111
-     *
112
-     * @throws Exception
113
-     */
114
-    protected function add()
115
-    {
116
-        if (WebRequest::wasPosted()) {
117
-            $this->validateCSRFToken();
118
-            $database = $this->getDatabase();
109
+	/**
110
+	 * Handler for the add action to create a new welcome template
111
+	 *
112
+	 * @throws Exception
113
+	 */
114
+	protected function add()
115
+	{
116
+		if (WebRequest::wasPosted()) {
117
+			$this->validateCSRFToken();
118
+			$database = $this->getDatabase();
119 119
 
120
-            $userCode = WebRequest::postString('usercode');
121
-            $botCode = WebRequest::postString('botcode');
120
+			$userCode = WebRequest::postString('usercode');
121
+			$botCode = WebRequest::postString('botcode');
122 122
 
123
-            $this->validate($userCode, $botCode);
123
+			$this->validate($userCode, $botCode);
124 124
 
125
-            $template = new WelcomeTemplate();
126
-            $template->setDatabase($database);
127
-            $template->setUserCode($userCode);
128
-            $template->setBotCode($botCode);
129
-            $template->save();
125
+			$template = new WelcomeTemplate();
126
+			$template->setDatabase($database);
127
+			$template->setUserCode($userCode);
128
+			$template->setBotCode($botCode);
129
+			$template->save();
130 130
 
131
-            Logger::welcomeTemplateCreated($database, $template);
131
+			Logger::welcomeTemplateCreated($database, $template);
132 132
 
133
-            $this->getNotificationHelper()->welcomeTemplateCreated($template);
133
+			$this->getNotificationHelper()->welcomeTemplateCreated($template);
134 134
 
135
-            SessionAlert::success("Template successfully created.");
135
+			SessionAlert::success("Template successfully created.");
136 136
 
137
-            $this->redirect('welcomeTemplates');
138
-        }
139
-        else {
140
-            $this->assignCSRFToken();
141
-            $this->setTemplate("welcome-template/add.tpl");
142
-        }
143
-    }
137
+			$this->redirect('welcomeTemplates');
138
+		}
139
+		else {
140
+			$this->assignCSRFToken();
141
+			$this->setTemplate("welcome-template/add.tpl");
142
+		}
143
+	}
144 144
 
145
-    /**
146
-     * Hander for editing templates
147
-     */
148
-    protected function edit()
149
-    {
150
-        $database = $this->getDatabase();
145
+	/**
146
+	 * Hander for editing templates
147
+	 */
148
+	protected function edit()
149
+	{
150
+		$database = $this->getDatabase();
151 151
 
152
-        $templateId = WebRequest::getInt('template');
152
+		$templateId = WebRequest::getInt('template');
153 153
 
154
-        /** @var WelcomeTemplate $template */
155
-        $template = WelcomeTemplate::getById($templateId, $database);
154
+		/** @var WelcomeTemplate $template */
155
+		$template = WelcomeTemplate::getById($templateId, $database);
156 156
 
157
-        if ($template === false) {
158
-            throw new ApplicationLogicException('Cannot find requested template');
159
-        }
157
+		if ($template === false) {
158
+			throw new ApplicationLogicException('Cannot find requested template');
159
+		}
160 160
 
161
-        if ($template->isDeleted()) {
162
-            throw new ApplicationLogicException('The specified template has been deleted');
163
-        }
161
+		if ($template->isDeleted()) {
162
+			throw new ApplicationLogicException('The specified template has been deleted');
163
+		}
164 164
 
165
-        if (WebRequest::wasPosted()) {
166
-            $this->validateCSRFToken();
165
+		if (WebRequest::wasPosted()) {
166
+			$this->validateCSRFToken();
167 167
 
168
-            $userCode = WebRequest::postString('usercode');
169
-            $botCode = WebRequest::postString('botcode');
168
+			$userCode = WebRequest::postString('usercode');
169
+			$botCode = WebRequest::postString('botcode');
170 170
 
171
-            $this->validate($userCode, $botCode);
171
+			$this->validate($userCode, $botCode);
172 172
 
173
-            $template->setUserCode($userCode);
174
-            $template->setBotCode($botCode);
175
-            $template->setUpdateVersion(WebRequest::postInt('updateversion'));
176
-            $template->save();
173
+			$template->setUserCode($userCode);
174
+			$template->setBotCode($botCode);
175
+			$template->setUpdateVersion(WebRequest::postInt('updateversion'));
176
+			$template->save();
177 177
 
178
-            Logger::welcomeTemplateEdited($database, $template);
178
+			Logger::welcomeTemplateEdited($database, $template);
179 179
 
180
-            SessionAlert::success("Template updated.");
180
+			SessionAlert::success("Template updated.");
181 181
 
182
-            $this->getNotificationHelper()->welcomeTemplateEdited($template);
182
+			$this->getNotificationHelper()->welcomeTemplateEdited($template);
183 183
 
184
-            $this->redirect('welcomeTemplates');
185
-        }
186
-        else {
187
-            $this->assignCSRFToken();
188
-            $this->assign('template', $template);
189
-            $this->setTemplate('welcome-template/edit.tpl');
190
-        }
191
-    }
184
+			$this->redirect('welcomeTemplates');
185
+		}
186
+		else {
187
+			$this->assignCSRFToken();
188
+			$this->assign('template', $template);
189
+			$this->setTemplate('welcome-template/edit.tpl');
190
+		}
191
+	}
192 192
 
193
-    protected function delete()
194
-    {
195
-        $this->redirect('welcomeTemplates');
193
+	protected function delete()
194
+	{
195
+		$this->redirect('welcomeTemplates');
196 196
 
197
-        if (!WebRequest::wasPosted()) {
198
-            return;
199
-        }
197
+		if (!WebRequest::wasPosted()) {
198
+			return;
199
+		}
200 200
 
201
-        $this->validateCSRFToken();
201
+		$this->validateCSRFToken();
202 202
 
203
-        $database = $this->getDatabase();
203
+		$database = $this->getDatabase();
204 204
 
205
-        $templateId = WebRequest::postInt('template');
206
-        $updateVersion = WebRequest::postInt('updateversion');
205
+		$templateId = WebRequest::postInt('template');
206
+		$updateVersion = WebRequest::postInt('updateversion');
207 207
 
208
-        /** @var WelcomeTemplate $template */
209
-        $template = WelcomeTemplate::getById($templateId, $database);
208
+		/** @var WelcomeTemplate $template */
209
+		$template = WelcomeTemplate::getById($templateId, $database);
210 210
 
211
-        if ($template === false || $template->isDeleted()) {
212
-            throw new ApplicationLogicException('Cannot find requested template');
213
-        }
211
+		if ($template === false || $template->isDeleted()) {
212
+			throw new ApplicationLogicException('Cannot find requested template');
213
+		}
214 214
 
215
-        // set the update version to the version sent by the client (optimisticly lock from initial page load)
216
-        $template->setUpdateVersion($updateVersion);
215
+		// set the update version to the version sent by the client (optimisticly lock from initial page load)
216
+		$template->setUpdateVersion($updateVersion);
217 217
 
218
-        $database
219
-            ->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
220
-            ->execute(array(":id" => $templateId));
218
+		$database
219
+			->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;")
220
+			->execute(array(":id" => $templateId));
221 221
 
222
-        Logger::welcomeTemplateDeleted($database, $template);
222
+		Logger::welcomeTemplateDeleted($database, $template);
223 223
 
224
-        $template->delete();
224
+		$template->delete();
225 225
 
226
-        SessionAlert::success(
227
-            "Template deleted. Any users who were using this template have had automatic welcoming disabled.");
228
-        $this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
229
-    }
226
+		SessionAlert::success(
227
+			"Template deleted. Any users who were using this template have had automatic welcoming disabled.");
228
+		$this->getNotificationHelper()->welcomeTemplateDeleted($templateId);
229
+	}
230 230
 
231
-    private function validate($userCode, $botCode)
232
-    {
233
-        if ($userCode === null) {
234
-            throw new ApplicationLogicException('User code cannot be null');
235
-        }
231
+	private function validate($userCode, $botCode)
232
+	{
233
+		if ($userCode === null) {
234
+			throw new ApplicationLogicException('User code cannot be null');
235
+		}
236 236
 
237
-        if ($botCode === null) {
238
-            throw new ApplicationLogicException('Bot code cannot be null');
239
-        }
240
-    }
237
+		if ($botCode === null) {
238
+			throw new ApplicationLogicException('Bot code cannot be null');
239
+		}
240
+	}
241 241
 }
Please login to merge, or discard this patch.
includes/Pages/PageEditComment.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -20,67 +20,67 @@
 block discarded – undo
20 20
 
21 21
 class PageEditComment extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     * @throws ApplicationLogicException
26
-     */
27
-    protected function main()
28
-    {
29
-        $commentId = WebRequest::getInt('id');
30
-        if ($commentId === null) {
31
-            throw new ApplicationLogicException('Comment ID not specified');
32
-        }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 * @throws ApplicationLogicException
26
+	 */
27
+	protected function main()
28
+	{
29
+		$commentId = WebRequest::getInt('id');
30
+		if ($commentId === null) {
31
+			throw new ApplicationLogicException('Comment ID not specified');
32
+		}
33 33
 
34
-        $database = $this->getDatabase();
34
+		$database = $this->getDatabase();
35 35
 
36
-        /** @var Comment $comment */
37
-        $comment = Comment::getById($commentId, $database);
38
-        if ($comment === false) {
39
-            throw new ApplicationLogicException('Comment not found');
40
-        }
36
+		/** @var Comment $comment */
37
+		$comment = Comment::getById($commentId, $database);
38
+		if ($comment === false) {
39
+			throw new ApplicationLogicException('Comment not found');
40
+		}
41 41
 
42
-        $currentUser = User::getCurrent($database);
43
-        if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
-            throw new AccessDeniedException($this->getSecurityManager());
45
-        }
42
+		$currentUser = User::getCurrent($database);
43
+		if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) {
44
+			throw new AccessDeniedException($this->getSecurityManager());
45
+		}
46 46
 
47
-        /** @var Request $request */
48
-        $request = Request::getById($comment->getRequest(), $database);
47
+		/** @var Request $request */
48
+		$request = Request::getById($comment->getRequest(), $database);
49 49
 
50
-        if ($request === false) {
51
-            throw new ApplicationLogicException('Request was not found.');
52
-        }
50
+		if ($request === false) {
51
+			throw new ApplicationLogicException('Request was not found.');
52
+		}
53 53
 
54
-        if (WebRequest::wasPosted()) {
55
-            $this->validateCSRFToken();
56
-            $newComment = WebRequest::postString('newcomment');
57
-            $visibility = WebRequest::postString('visibility');
54
+		if (WebRequest::wasPosted()) {
55
+			$this->validateCSRFToken();
56
+			$newComment = WebRequest::postString('newcomment');
57
+			$visibility = WebRequest::postString('visibility');
58 58
 
59
-            if ($visibility !== 'user' && $visibility !== 'admin') {
60
-                throw new ApplicationLogicException('Comment visibility is not valid');
61
-            }
59
+			if ($visibility !== 'user' && $visibility !== 'admin') {
60
+				throw new ApplicationLogicException('Comment visibility is not valid');
61
+			}
62 62
 
63
-            // optimisticly lock from the load of the edit comment form
64
-            $updateVersion = WebRequest::postInt('updateversion');
65
-            $comment->setUpdateVersion($updateVersion);
63
+			// optimisticly lock from the load of the edit comment form
64
+			$updateVersion = WebRequest::postInt('updateversion');
65
+			$comment->setUpdateVersion($updateVersion);
66 66
 
67
-            $comment->setComment($newComment);
68
-            $comment->setVisibility($visibility);
67
+			$comment->setComment($newComment);
68
+			$comment->setVisibility($visibility);
69 69
 
70
-            $comment->save();
70
+			$comment->save();
71 71
 
72
-            Logger::editComment($database, $comment, $request);
73
-            $this->getNotificationHelper()->commentEdited($comment, $request);
74
-            SessionAlert::success("Comment has been saved successfully");
72
+			Logger::editComment($database, $comment, $request);
73
+			$this->getNotificationHelper()->commentEdited($comment, $request);
74
+			SessionAlert::success("Comment has been saved successfully");
75 75
 
76
-            $this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
-        }
78
-        else {
79
-            $this->assignCSRFToken();
80
-            $this->assign('comment', $comment);
81
-            $this->assign('request', $request);
82
-            $this->assign('user', User::getById($comment->getUser(), $database));
83
-            $this->setTemplate('edit-comment.tpl');
84
-        }
85
-    }
76
+			$this->redirect('viewRequest', null, array('id' => $comment->getRequest()));
77
+		}
78
+		else {
79
+			$this->assignCSRFToken();
80
+			$this->assign('comment', $comment);
81
+			$this->assign('request', $request);
82
+			$this->assign('user', User::getById($comment->getUser(), $database));
83
+			$this->setTemplate('edit-comment.tpl');
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterStandard.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
 
11 11
 class PageRegisterStandard extends PageRegisterBase
12 12
 {
13
-    /**
14
-     * @return string
15
-     */
16
-    protected function getRegistrationTemplate()
17
-    {
18
-        return "registration/register.tpl";
19
-    }
13
+	/**
14
+	 * @return string
15
+	 */
16
+	protected function getRegistrationTemplate()
17
+	{
18
+		return "registration/register.tpl";
19
+	}
20 20
 
21
-    /**
22
-     * @return string
23
-     */
24
-    protected function getDefaultRole()
25
-    {
26
-        return 'user';
27
-    }
21
+	/**
22
+	 * @return string
23
+	 */
24
+	protected function getDefaultRole()
25
+	{
26
+		return 'user';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/PageSiteNotice.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 
16 16
 class PageSiteNotice extends InternalPageBase
17 17
 {
18
-    /**
19
-     * Main function for this page, when no specific actions are called.
20
-     * @return void
21
-     */
22
-    protected function main()
23
-    {
24
-        $this->setHtmlTitle('Site Notice');
25
-
26
-        $database = $this->getDatabase();
27
-
28
-        /** @var SiteNotice $siteNoticeMessage */
29
-        $siteNoticeMessage = SiteNotice::getById(1, $database);
30
-
31
-        // Dual-mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-
35
-            $siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
-            $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
-            $siteNoticeMessage->save();
38
-
39
-            Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
-            $this->getNotificationHelper()->siteNoticeEdited();
41
-
42
-            $this->redirect();
43
-        }
44
-        else {
45
-            $this->assignCSRFToken();
46
-
47
-            $this->setTemplate('site-notice/edit-form.tpl');
48
-            $this->assign('message', $siteNoticeMessage);
49
-        }
50
-    }
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->setHtmlTitle('Site Notice');
25
+
26
+		$database = $this->getDatabase();
27
+
28
+		/** @var SiteNotice $siteNoticeMessage */
29
+		$siteNoticeMessage = SiteNotice::getById(1, $database);
30
+
31
+		// Dual-mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+
35
+			$siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
+			$siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
+			$siteNoticeMessage->save();
38
+
39
+			Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
+			$this->getNotificationHelper()->siteNoticeEdited();
41
+
42
+			$this->redirect();
43
+		}
44
+		else {
45
+			$this->assignCSRFToken();
46
+
47
+			$this->setTemplate('site-notice/edit-form.tpl');
48
+			$this->assign('message', $siteNoticeMessage);
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
includes/Pages/Page404.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@
 block discarded – undo
12 12
 
13 13
 class Page404 extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no actions are called.
17
-     */
18
-    protected function main()
19
-    {
20
-        if (!headers_sent()) {
21
-            header("HTTP/1.1 404 Not Found");
22
-        }
15
+	/**
16
+	 * Main function for this page, when no actions are called.
17
+	 */
18
+	protected function main()
19
+	{
20
+		if (!headers_sent()) {
21
+			header("HTTP/1.1 404 Not Found");
22
+		}
23 23
 
24
-        $this->setTemplate("404.tpl");
25
-    }
24
+		$this->setTemplate("404.tpl");
25
+	}
26 26
 
27
-    protected function isProtectedPage()
28
-    {
29
-        return false;
30
-    }
27
+	protected function isProtectedPage()
28
+	{
29
+		return false;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
includes/Pages/PageSearch.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -20,156 +20,156 @@
 block discarded – undo
20 20
 
21 21
 class PageSearch extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     */
26
-    protected function main()
27
-    {
28
-        $this->setHtmlTitle('Search');
29
-
30
-        // Dual-mode page
31
-        if (WebRequest::wasPosted()) {
32
-            $this->validateCSRFToken();
33
-
34
-            $searchType = WebRequest::postString('type');
35
-            $searchTerm = WebRequest::postString('term');
36
-
37
-            $validationError = "";
38
-            if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) {
39
-                SessionAlert::error($validationError, "Search error");
40
-                $this->redirect("search");
41
-
42
-                return;
43
-            }
44
-
45
-            $results = array();
46
-
47
-            switch ($searchType) {
48
-                case 'name':
49
-                    $results = $this->getNameSearchResults($searchTerm);
50
-                    break;
51
-                case 'email':
52
-                    $results = $this->getEmailSearchResults($searchTerm);
53
-                    break;
54
-                case 'ip':
55
-                    $results = $this->getIpSearchResults($searchTerm);
56
-                    break;
57
-            }
58
-
59
-            // deal with results
60
-            $this->assign('requests', $results);
61
-            $this->assign('term', $searchTerm);
62
-            $this->assign('target', $searchType);
63
-
64
-            $userIds = array_map(
65
-                function(Request $entry) {
66
-                    return $entry->getReserved();
67
-                },
68
-                $results);
69
-            $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
70
-            $this->assign('userlist', $userList);
71
-
72
-            $currentUser = User::getCurrent($this->getDatabase());
73
-            $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
74
-            $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
75
-
76
-            $this->assignCSRFToken();
77
-            $this->setTemplate('search/searchResult.tpl');
78
-        }
79
-        else {
80
-            $this->assignCSRFToken();
81
-            $this->setTemplate('search/searchForm.tpl');
82
-        }
83
-    }
84
-
85
-    /**
86
-     * Gets search results by name
87
-     *
88
-     * @param string $searchTerm
89
-     *
90
-     * @returns Request[]
91
-     */
92
-    private function getNameSearchResults($searchTerm)
93
-    {
94
-        $padded = '%' . $searchTerm . '%';
95
-
96
-        /** @var Request[] $requests */
97
-        $requests = RequestSearchHelper::get($this->getDatabase())
98
-            ->byName($padded)
99
-            ->excludingPurgedData($this->getSiteConfiguration())
100
-            ->fetch();
101
-
102
-        return $requests;
103
-    }
104
-
105
-    /**
106
-     * Gets search results by email
107
-     *
108
-     * @param string $searchTerm
109
-     *
110
-     * @return Request[]
111
-     * @throws ApplicationLogicException
112
-     */
113
-    private function getEmailSearchResults($searchTerm)
114
-    {
115
-        if ($searchTerm === "@") {
116
-            throw new ApplicationLogicException('The search term "@" is not valid for email address searches!');
117
-        }
118
-
119
-        $padded = '%' . $searchTerm . '%';
120
-
121
-        /** @var Request[] $requests */
122
-        $requests = RequestSearchHelper::get($this->getDatabase())
123
-            ->byEmailAddress($padded)
124
-            ->excludingPurgedData($this->getSiteConfiguration())
125
-            ->fetch();
126
-
127
-        return $requests;
128
-    }
129
-
130
-    /**
131
-     * Gets search results by IP address or XFF IP address
132
-     *
133
-     * @param string $searchTerm
134
-     *
135
-     * @returns Request[]
136
-     */
137
-    private function getIpSearchResults($searchTerm)
138
-    {
139
-        /** @var Request[] $requests */
140
-        $requests = RequestSearchHelper::get($this->getDatabase())
141
-            ->byIp($searchTerm)
142
-            ->excludingPurgedData($this->getSiteConfiguration())
143
-            ->fetch();
144
-
145
-        return $requests;
146
-    }
147
-
148
-    /**
149
-     * @param string $searchType
150
-     * @param string $searchTerm
151
-     *
152
-     * @param string $errorMessage
153
-     *
154
-     * @return bool true if parameters are valid
155
-     * @throws ApplicationLogicException
156
-     */
157
-    protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage)
158
-    {
159
-        if (!in_array($searchType, array('name', 'email', 'ip'))) {
160
-            $errorMessage = 'Unknown search type';
161
-
162
-            return false;
163
-        }
164
-
165
-        if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) {
166
-            $errorMessage = 'No search term specified entered';
167
-
168
-            return false;
169
-        }
170
-
171
-        $errorMessage = "";
172
-
173
-        return true;
174
-    }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->setHtmlTitle('Search');
29
+
30
+		// Dual-mode page
31
+		if (WebRequest::wasPosted()) {
32
+			$this->validateCSRFToken();
33
+
34
+			$searchType = WebRequest::postString('type');
35
+			$searchTerm = WebRequest::postString('term');
36
+
37
+			$validationError = "";
38
+			if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) {
39
+				SessionAlert::error($validationError, "Search error");
40
+				$this->redirect("search");
41
+
42
+				return;
43
+			}
44
+
45
+			$results = array();
46
+
47
+			switch ($searchType) {
48
+				case 'name':
49
+					$results = $this->getNameSearchResults($searchTerm);
50
+					break;
51
+				case 'email':
52
+					$results = $this->getEmailSearchResults($searchTerm);
53
+					break;
54
+				case 'ip':
55
+					$results = $this->getIpSearchResults($searchTerm);
56
+					break;
57
+			}
58
+
59
+			// deal with results
60
+			$this->assign('requests', $results);
61
+			$this->assign('term', $searchTerm);
62
+			$this->assign('target', $searchType);
63
+
64
+			$userIds = array_map(
65
+				function(Request $entry) {
66
+					return $entry->getReserved();
67
+				},
68
+				$results);
69
+			$userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
70
+			$this->assign('userlist', $userList);
71
+
72
+			$currentUser = User::getCurrent($this->getDatabase());
73
+			$this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
74
+			$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
75
+
76
+			$this->assignCSRFToken();
77
+			$this->setTemplate('search/searchResult.tpl');
78
+		}
79
+		else {
80
+			$this->assignCSRFToken();
81
+			$this->setTemplate('search/searchForm.tpl');
82
+		}
83
+	}
84
+
85
+	/**
86
+	 * Gets search results by name
87
+	 *
88
+	 * @param string $searchTerm
89
+	 *
90
+	 * @returns Request[]
91
+	 */
92
+	private function getNameSearchResults($searchTerm)
93
+	{
94
+		$padded = '%' . $searchTerm . '%';
95
+
96
+		/** @var Request[] $requests */
97
+		$requests = RequestSearchHelper::get($this->getDatabase())
98
+			->byName($padded)
99
+			->excludingPurgedData($this->getSiteConfiguration())
100
+			->fetch();
101
+
102
+		return $requests;
103
+	}
104
+
105
+	/**
106
+	 * Gets search results by email
107
+	 *
108
+	 * @param string $searchTerm
109
+	 *
110
+	 * @return Request[]
111
+	 * @throws ApplicationLogicException
112
+	 */
113
+	private function getEmailSearchResults($searchTerm)
114
+	{
115
+		if ($searchTerm === "@") {
116
+			throw new ApplicationLogicException('The search term "@" is not valid for email address searches!');
117
+		}
118
+
119
+		$padded = '%' . $searchTerm . '%';
120
+
121
+		/** @var Request[] $requests */
122
+		$requests = RequestSearchHelper::get($this->getDatabase())
123
+			->byEmailAddress($padded)
124
+			->excludingPurgedData($this->getSiteConfiguration())
125
+			->fetch();
126
+
127
+		return $requests;
128
+	}
129
+
130
+	/**
131
+	 * Gets search results by IP address or XFF IP address
132
+	 *
133
+	 * @param string $searchTerm
134
+	 *
135
+	 * @returns Request[]
136
+	 */
137
+	private function getIpSearchResults($searchTerm)
138
+	{
139
+		/** @var Request[] $requests */
140
+		$requests = RequestSearchHelper::get($this->getDatabase())
141
+			->byIp($searchTerm)
142
+			->excludingPurgedData($this->getSiteConfiguration())
143
+			->fetch();
144
+
145
+		return $requests;
146
+	}
147
+
148
+	/**
149
+	 * @param string $searchType
150
+	 * @param string $searchTerm
151
+	 *
152
+	 * @param string $errorMessage
153
+	 *
154
+	 * @return bool true if parameters are valid
155
+	 * @throws ApplicationLogicException
156
+	 */
157
+	protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage)
158
+	{
159
+		if (!in_array($searchType, array('name', 'email', 'ip'))) {
160
+			$errorMessage = 'Unknown search type';
161
+
162
+			return false;
163
+		}
164
+
165
+		if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) {
166
+			$errorMessage = 'No search term specified entered';
167
+
168
+			return false;
169
+		}
170
+
171
+		$errorMessage = "";
172
+
173
+		return true;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function getNameSearchResults($searchTerm)
93 93
     {
94
-        $padded = '%' . $searchTerm . '%';
94
+        $padded = '%'.$searchTerm.'%';
95 95
 
96 96
         /** @var Request[] $requests */
97 97
         $requests = RequestSearchHelper::get($this->getDatabase())
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             throw new ApplicationLogicException('The search term "@" is not valid for email address searches!');
117 117
         }
118 118
 
119
-        $padded = '%' . $searchTerm . '%';
119
+        $padded = '%'.$searchTerm.'%';
120 120
 
121 121
         /** @var Request[] $requests */
122 122
         $requests = RequestSearchHelper::get($this->getDatabase())
Please login to merge, or discard this patch.
includes/Pages/PageBan.php 1 patch
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -21,310 +21,310 @@
 block discarded – undo
21 21
 
22 22
 class PageBan extends InternalPageBase
23 23
 {
24
-    /**
25
-     * Main function for this page, when no specific actions are called.
26
-     */
27
-    protected function main()
28
-    {
29
-        $this->assignCSRFToken();
30
-
31
-        $this->setHtmlTitle('Bans');
32
-
33
-        $bans = Ban::getActiveBans(null, $this->getDatabase());
34
-
35
-        $userIds = array_map(
36
-            function(Ban $entry) {
37
-                return $entry->getUser();
38
-            },
39
-            $bans);
40
-        $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
41
-
42
-        $user = User::getCurrent($this->getDatabase());
43
-        $this->assign('canSet', $this->barrierTest('set', $user));
44
-        $this->assign('canRemove', $this->barrierTest('remove', $user));
45
-
46
-        $this->assign('usernames', $userList);
47
-        $this->assign('activebans', $bans);
48
-        $this->setTemplate('bans/banlist.tpl');
49
-    }
50
-
51
-    /**
52
-     * Entry point for the ban set action
53
-     */
54
-    protected function set()
55
-    {
56
-        $this->setHtmlTitle('Bans');
57
-
58
-        // dual-mode action
59
-        if (WebRequest::wasPosted()) {
60
-            try {
61
-                $this->handlePostMethodForSetBan();
62
-            }
63
-            catch (ApplicationLogicException $ex) {
64
-                SessionAlert::error($ex->getMessage());
65
-                $this->redirect("bans", "set");
66
-            }
67
-        }
68
-        else {
69
-            $this->handleGetMethodForSetBan();
70
-        }
71
-    }
72
-
73
-    /**
74
-     * Entry point for the ban remove action
75
-     */
76
-    protected function remove()
77
-    {
78
-        $this->setHtmlTitle('Bans');
79
-
80
-        $ban = $this->getBanForUnban();
81
-
82
-        // dual mode
83
-        if (WebRequest::wasPosted()) {
84
-            $this->validateCSRFToken();
85
-            $unbanReason = WebRequest::postString('unbanreason');
86
-
87
-            if ($unbanReason === null || trim($unbanReason) === "") {
88
-                SessionAlert::error('No unban reason specified');
89
-                $this->redirect("bans", "remove", array('id' => $ban->getId()));
90
-            }
91
-
92
-            // set optimistic locking from delete form page load
93
-            $updateVersion = WebRequest::postInt('updateversion');
94
-            $ban->setUpdateVersion($updateVersion);
95
-
96
-            $database = $this->getDatabase();
97
-            $ban->setActive(false);
98
-            $ban->save();
99
-
100
-            Logger::unbanned($database, $ban, $unbanReason);
101
-
102
-            SessionAlert::quick('Disabled ban.');
103
-            $this->getNotificationHelper()->unbanned($ban, $unbanReason);
104
-
105
-            $this->redirect('bans');
106
-        }
107
-        else {
108
-            $this->assignCSRFToken();
109
-            $this->assign('ban', $ban);
110
-            $this->setTemplate('bans/unban.tpl');
111
-        }
112
-    }
113
-
114
-    /**
115
-     * @throws ApplicationLogicException
116
-     */
117
-    private function getBanDuration()
118
-    {
119
-        $duration = WebRequest::postString('duration');
120
-        if ($duration === "other") {
121
-            $duration = strtotime(WebRequest::postString('otherduration'));
122
-
123
-            if (!$duration) {
124
-                throw new ApplicationLogicException('Invalid ban time');
125
-            }
126
-            elseif (time() > $duration) {
127
-                throw new ApplicationLogicException('Ban time has already expired!');
128
-            }
129
-
130
-            return $duration;
131
-        }
132
-        elseif ($duration === "-1") {
133
-            $duration = -1;
134
-
135
-            return $duration;
136
-        }
137
-        else {
138
-            $duration = WebRequest::postInt('duration') + time();
139
-
140
-            return $duration;
141
-        }
142
-    }
143
-
144
-    /**
145
-     * @param string $type
146
-     * @param string $target
147
-     *
148
-     * @throws ApplicationLogicException
149
-     */
150
-    private function validateBanType($type, $target)
151
-    {
152
-        switch ($type) {
153
-            case 'IP':
154
-                $this->validateIpBan($target);
155
-
156
-                return;
157
-            case 'Name':
158
-                // No validation needed here.
159
-                return;
160
-            case 'EMail':
161
-                $this->validateEmailBanTarget($target);
162
-
163
-                return;
164
-            default:
165
-                throw new ApplicationLogicException("Unknown ban type");
166
-        }
167
-    }
168
-
169
-    /**
170
-     * Handles the POST method on the set action
171
-     *
172
-     * @throws ApplicationLogicException
173
-     * @throws Exception
174
-     */
175
-    private function handlePostMethodForSetBan()
176
-    {
177
-        $this->validateCSRFToken();
178
-        $reason = WebRequest::postString('banreason');
179
-        $target = WebRequest::postString('target');
180
-
181
-        // Checks whether there is a reason entered for ban.
182
-        if ($reason === null || trim($reason) === "") {
183
-            throw new ApplicationLogicException('You must specify a ban reason');
184
-        }
185
-
186
-        // Checks whether there is a target entered to ban.
187
-        if ($target === null || trim($target) === "") {
188
-            throw new ApplicationLogicException('You must specify a target to be banned');
189
-        }
190
-
191
-        // Validate ban duration
192
-        $duration = $this->getBanDuration();
193
-
194
-        // Validate ban type & target for that type
195
-        $type = WebRequest::postString('type');
196
-        $this->validateBanType($type, $target);
197
-
198
-        $database = $this->getDatabase();
199
-
200
-        if (count(Ban::getActiveBans($target, $database)) > 0) {
201
-            throw new ApplicationLogicException('This target is already banned!');
202
-        }
203
-
204
-        $ban = new Ban();
205
-        $ban->setDatabase($database);
206
-        $ban->setActive(true);
207
-        $ban->setType($type);
208
-        $ban->setTarget($target);
209
-        $ban->setUser(User::getCurrent($database)->getId());
210
-        $ban->setReason($reason);
211
-        $ban->setDuration($duration);
212
-
213
-        $ban->save();
214
-
215
-        Logger::banned($database, $ban, $reason);
216
-
217
-        $this->getNotificationHelper()->banned($ban);
218
-        SessionAlert::quick('Ban has been set.');
219
-
220
-        $this->redirect('bans');
221
-    }
222
-
223
-    /**
224
-     * Handles the GET method on the set action
225
-     */
226
-    protected function handleGetMethodForSetBan()
227
-    {
228
-        $this->setTemplate('bans/banform.tpl');
229
-        $this->assignCSRFToken();
230
-
231
-        $banType = WebRequest::getString('type');
232
-        $banTarget = WebRequest::getInt('request');
233
-
234
-        $database = $this->getDatabase();
235
-
236
-        // if the parameters are null, skip loading a request.
237
-        if ($banType === null
238
-            || !in_array($banType, array('IP', 'Name', 'EMail'))
239
-            || $banTarget === null
240
-            || $banTarget === 0
241
-        ) {
242
-            $this->assign('bantarget', '');
243
-            $this->assign('bantype', '');
244
-
245
-            return;
246
-        }
247
-
248
-        // Set the ban type, which the user has indicated.
249
-        $this->assign('bantype', $banType);
250
-
251
-        // Attempt to resolve the correct target
252
-        /** @var Request $request */
253
-        $request = Request::getById($banTarget, $database);
254
-        if ($request === false) {
255
-            $this->assign('bantarget', '');
256
-
257
-            return;
258
-        }
259
-
260
-        $realTarget = '';
261
-        switch ($banType) {
262
-            case 'EMail':
263
-                $realTarget = $request->getEmail();
264
-                break;
265
-            case 'IP':
266
-                $xffProvider = $this->getXffTrustProvider();
267
-                $realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
268
-                break;
269
-            case 'Name':
270
-                $realTarget = $request->getName();
271
-                break;
272
-        }
273
-
274
-        $this->assign('bantarget', $realTarget);
275
-    }
276
-
277
-    /**
278
-     * Validates an IP ban target
279
-     *
280
-     * @param string $target
281
-     *
282
-     * @throws ApplicationLogicException
283
-     */
284
-    private function validateIpBan($target)
285
-    {
286
-        $squidIpList = $this->getSiteConfiguration()->getSquidList();
287
-
288
-        if (filter_var($target, FILTER_VALIDATE_IP) === false) {
289
-            throw new ApplicationLogicException('Invalid target - IP address expected.');
290
-        }
291
-
292
-        if (in_array($target, $squidIpList)) {
293
-            throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned.");
294
-        }
295
-    }
296
-
297
-    /**
298
-     * Validates an email address as a ban target
299
-     *
300
-     * @param string $target
301
-     *
302
-     * @throws ApplicationLogicException
303
-     */
304
-    private function validateEmailBanTarget($target)
305
-    {
306
-        if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) {
307
-            throw new ApplicationLogicException('Invalid target - email address expected.');
308
-        }
309
-    }
310
-
311
-    /**
312
-     * @return Ban
313
-     * @throws ApplicationLogicException
314
-     */
315
-    private function getBanForUnban()
316
-    {
317
-        $banId = WebRequest::getInt('id');
318
-        if ($banId === null || $banId === 0) {
319
-            throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug.");
320
-        }
321
-
322
-        $ban = Ban::getActiveId($banId, $this->getDatabase());
323
-
324
-        if ($ban === false) {
325
-            throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
326
-        }
327
-
328
-        return $ban;
329
-    }
24
+	/**
25
+	 * Main function for this page, when no specific actions are called.
26
+	 */
27
+	protected function main()
28
+	{
29
+		$this->assignCSRFToken();
30
+
31
+		$this->setHtmlTitle('Bans');
32
+
33
+		$bans = Ban::getActiveBans(null, $this->getDatabase());
34
+
35
+		$userIds = array_map(
36
+			function(Ban $entry) {
37
+				return $entry->getUser();
38
+			},
39
+			$bans);
40
+		$userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
41
+
42
+		$user = User::getCurrent($this->getDatabase());
43
+		$this->assign('canSet', $this->barrierTest('set', $user));
44
+		$this->assign('canRemove', $this->barrierTest('remove', $user));
45
+
46
+		$this->assign('usernames', $userList);
47
+		$this->assign('activebans', $bans);
48
+		$this->setTemplate('bans/banlist.tpl');
49
+	}
50
+
51
+	/**
52
+	 * Entry point for the ban set action
53
+	 */
54
+	protected function set()
55
+	{
56
+		$this->setHtmlTitle('Bans');
57
+
58
+		// dual-mode action
59
+		if (WebRequest::wasPosted()) {
60
+			try {
61
+				$this->handlePostMethodForSetBan();
62
+			}
63
+			catch (ApplicationLogicException $ex) {
64
+				SessionAlert::error($ex->getMessage());
65
+				$this->redirect("bans", "set");
66
+			}
67
+		}
68
+		else {
69
+			$this->handleGetMethodForSetBan();
70
+		}
71
+	}
72
+
73
+	/**
74
+	 * Entry point for the ban remove action
75
+	 */
76
+	protected function remove()
77
+	{
78
+		$this->setHtmlTitle('Bans');
79
+
80
+		$ban = $this->getBanForUnban();
81
+
82
+		// dual mode
83
+		if (WebRequest::wasPosted()) {
84
+			$this->validateCSRFToken();
85
+			$unbanReason = WebRequest::postString('unbanreason');
86
+
87
+			if ($unbanReason === null || trim($unbanReason) === "") {
88
+				SessionAlert::error('No unban reason specified');
89
+				$this->redirect("bans", "remove", array('id' => $ban->getId()));
90
+			}
91
+
92
+			// set optimistic locking from delete form page load
93
+			$updateVersion = WebRequest::postInt('updateversion');
94
+			$ban->setUpdateVersion($updateVersion);
95
+
96
+			$database = $this->getDatabase();
97
+			$ban->setActive(false);
98
+			$ban->save();
99
+
100
+			Logger::unbanned($database, $ban, $unbanReason);
101
+
102
+			SessionAlert::quick('Disabled ban.');
103
+			$this->getNotificationHelper()->unbanned($ban, $unbanReason);
104
+
105
+			$this->redirect('bans');
106
+		}
107
+		else {
108
+			$this->assignCSRFToken();
109
+			$this->assign('ban', $ban);
110
+			$this->setTemplate('bans/unban.tpl');
111
+		}
112
+	}
113
+
114
+	/**
115
+	 * @throws ApplicationLogicException
116
+	 */
117
+	private function getBanDuration()
118
+	{
119
+		$duration = WebRequest::postString('duration');
120
+		if ($duration === "other") {
121
+			$duration = strtotime(WebRequest::postString('otherduration'));
122
+
123
+			if (!$duration) {
124
+				throw new ApplicationLogicException('Invalid ban time');
125
+			}
126
+			elseif (time() > $duration) {
127
+				throw new ApplicationLogicException('Ban time has already expired!');
128
+			}
129
+
130
+			return $duration;
131
+		}
132
+		elseif ($duration === "-1") {
133
+			$duration = -1;
134
+
135
+			return $duration;
136
+		}
137
+		else {
138
+			$duration = WebRequest::postInt('duration') + time();
139
+
140
+			return $duration;
141
+		}
142
+	}
143
+
144
+	/**
145
+	 * @param string $type
146
+	 * @param string $target
147
+	 *
148
+	 * @throws ApplicationLogicException
149
+	 */
150
+	private function validateBanType($type, $target)
151
+	{
152
+		switch ($type) {
153
+			case 'IP':
154
+				$this->validateIpBan($target);
155
+
156
+				return;
157
+			case 'Name':
158
+				// No validation needed here.
159
+				return;
160
+			case 'EMail':
161
+				$this->validateEmailBanTarget($target);
162
+
163
+				return;
164
+			default:
165
+				throw new ApplicationLogicException("Unknown ban type");
166
+		}
167
+	}
168
+
169
+	/**
170
+	 * Handles the POST method on the set action
171
+	 *
172
+	 * @throws ApplicationLogicException
173
+	 * @throws Exception
174
+	 */
175
+	private function handlePostMethodForSetBan()
176
+	{
177
+		$this->validateCSRFToken();
178
+		$reason = WebRequest::postString('banreason');
179
+		$target = WebRequest::postString('target');
180
+
181
+		// Checks whether there is a reason entered for ban.
182
+		if ($reason === null || trim($reason) === "") {
183
+			throw new ApplicationLogicException('You must specify a ban reason');
184
+		}
185
+
186
+		// Checks whether there is a target entered to ban.
187
+		if ($target === null || trim($target) === "") {
188
+			throw new ApplicationLogicException('You must specify a target to be banned');
189
+		}
190
+
191
+		// Validate ban duration
192
+		$duration = $this->getBanDuration();
193
+
194
+		// Validate ban type & target for that type
195
+		$type = WebRequest::postString('type');
196
+		$this->validateBanType($type, $target);
197
+
198
+		$database = $this->getDatabase();
199
+
200
+		if (count(Ban::getActiveBans($target, $database)) > 0) {
201
+			throw new ApplicationLogicException('This target is already banned!');
202
+		}
203
+
204
+		$ban = new Ban();
205
+		$ban->setDatabase($database);
206
+		$ban->setActive(true);
207
+		$ban->setType($type);
208
+		$ban->setTarget($target);
209
+		$ban->setUser(User::getCurrent($database)->getId());
210
+		$ban->setReason($reason);
211
+		$ban->setDuration($duration);
212
+
213
+		$ban->save();
214
+
215
+		Logger::banned($database, $ban, $reason);
216
+
217
+		$this->getNotificationHelper()->banned($ban);
218
+		SessionAlert::quick('Ban has been set.');
219
+
220
+		$this->redirect('bans');
221
+	}
222
+
223
+	/**
224
+	 * Handles the GET method on the set action
225
+	 */
226
+	protected function handleGetMethodForSetBan()
227
+	{
228
+		$this->setTemplate('bans/banform.tpl');
229
+		$this->assignCSRFToken();
230
+
231
+		$banType = WebRequest::getString('type');
232
+		$banTarget = WebRequest::getInt('request');
233
+
234
+		$database = $this->getDatabase();
235
+
236
+		// if the parameters are null, skip loading a request.
237
+		if ($banType === null
238
+			|| !in_array($banType, array('IP', 'Name', 'EMail'))
239
+			|| $banTarget === null
240
+			|| $banTarget === 0
241
+		) {
242
+			$this->assign('bantarget', '');
243
+			$this->assign('bantype', '');
244
+
245
+			return;
246
+		}
247
+
248
+		// Set the ban type, which the user has indicated.
249
+		$this->assign('bantype', $banType);
250
+
251
+		// Attempt to resolve the correct target
252
+		/** @var Request $request */
253
+		$request = Request::getById($banTarget, $database);
254
+		if ($request === false) {
255
+			$this->assign('bantarget', '');
256
+
257
+			return;
258
+		}
259
+
260
+		$realTarget = '';
261
+		switch ($banType) {
262
+			case 'EMail':
263
+				$realTarget = $request->getEmail();
264
+				break;
265
+			case 'IP':
266
+				$xffProvider = $this->getXffTrustProvider();
267
+				$realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
268
+				break;
269
+			case 'Name':
270
+				$realTarget = $request->getName();
271
+				break;
272
+		}
273
+
274
+		$this->assign('bantarget', $realTarget);
275
+	}
276
+
277
+	/**
278
+	 * Validates an IP ban target
279
+	 *
280
+	 * @param string $target
281
+	 *
282
+	 * @throws ApplicationLogicException
283
+	 */
284
+	private function validateIpBan($target)
285
+	{
286
+		$squidIpList = $this->getSiteConfiguration()->getSquidList();
287
+
288
+		if (filter_var($target, FILTER_VALIDATE_IP) === false) {
289
+			throw new ApplicationLogicException('Invalid target - IP address expected.');
290
+		}
291
+
292
+		if (in_array($target, $squidIpList)) {
293
+			throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned.");
294
+		}
295
+	}
296
+
297
+	/**
298
+	 * Validates an email address as a ban target
299
+	 *
300
+	 * @param string $target
301
+	 *
302
+	 * @throws ApplicationLogicException
303
+	 */
304
+	private function validateEmailBanTarget($target)
305
+	{
306
+		if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) {
307
+			throw new ApplicationLogicException('Invalid target - email address expected.');
308
+		}
309
+	}
310
+
311
+	/**
312
+	 * @return Ban
313
+	 * @throws ApplicationLogicException
314
+	 */
315
+	private function getBanForUnban()
316
+	{
317
+		$banId = WebRequest::getInt('id');
318
+		if ($banId === null || $banId === 0) {
319
+			throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug.");
320
+		}
321
+
322
+		$ban = Ban::getActiveId($banId, $this->getDatabase());
323
+
324
+		if ($ban === false) {
325
+			throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
326
+		}
327
+
328
+		return $ban;
329
+	}
330 330
 }
Please login to merge, or discard this patch.