@@ -17,7 +17,6 @@ |
||
17 | 17 | use Waca\Exceptions\ApplicationLogicException; |
18 | 18 | use Waca\Fragments\RequestData; |
19 | 19 | use Waca\Helpers\LogHelper; |
20 | -use Waca\Helpers\SearchHelpers\UserSearchHelper; |
|
21 | 20 | use Waca\PdoDatabase; |
22 | 21 | use Waca\Tasks\InternalPageBase; |
23 | 22 | use Waca\WebRequest; |
@@ -24,213 +24,213 @@ |
||
24 | 24 | |
25 | 25 | class PageViewRequest extends InternalPageBase |
26 | 26 | { |
27 | - use RequestData; |
|
28 | - const STATUS_SYMBOL_OPEN = '☐'; |
|
29 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
30 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Main function for this page, when no specific actions are called. |
|
34 | - * @throws ApplicationLogicException |
|
35 | - */ |
|
36 | - protected function main() |
|
37 | - { |
|
38 | - // set up csrf protection |
|
39 | - $this->assignCSRFToken(); |
|
40 | - |
|
41 | - // get some useful objects |
|
42 | - $database = $this->getDatabase(); |
|
43 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
44 | - $config = $this->getSiteConfiguration(); |
|
45 | - $currentUser = User::getCurrent($database); |
|
46 | - |
|
47 | - // Test we should be able to look at this request |
|
48 | - if ($config->getEmailConfirmationEnabled()) { |
|
49 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
50 | - // Not allowed to look at this yet. |
|
51 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - $this->setupBasicData($request, $config); |
|
56 | - |
|
57 | - $this->setupUsernameData($request); |
|
58 | - |
|
59 | - $this->setupTitle($request); |
|
60 | - |
|
61 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
62 | - $this->setupGeneralData($database); |
|
63 | - |
|
64 | - $this->assign('requestDataCleared', false); |
|
65 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
66 | - $this->assign('requestDataCleared', true); |
|
67 | - } |
|
68 | - |
|
69 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
70 | - |
|
71 | - $this->setupLogData($request, $database); |
|
72 | - |
|
73 | - if ($allowedPrivateData) { |
|
74 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
75 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
76 | - |
|
77 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
78 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
79 | - |
|
80 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
81 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
82 | - $this->setupCheckUserData($request); |
|
83 | - } |
|
84 | - } |
|
85 | - else { |
|
86 | - $this->setTemplate('view-request/main.tpl'); |
|
87 | - } |
|
88 | - |
|
89 | - $this->addCss('/resources/viewrequest.css'); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param Request $request |
|
94 | - */ |
|
95 | - protected function setupTitle(Request $request) |
|
96 | - { |
|
97 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
98 | - if ($request->getStatus() === 'Closed') { |
|
99 | - if ($request->getWasCreated()) { |
|
100 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
101 | - } |
|
102 | - else { |
|
103 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Sets up data unrelated to the request, such as the email template information |
|
112 | - * |
|
113 | - * @param PdoDatabase $database |
|
114 | - */ |
|
115 | - protected function setupGeneralData(PdoDatabase $database) |
|
116 | - { |
|
117 | - $config = $this->getSiteConfiguration(); |
|
118 | - |
|
119 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
120 | - |
|
121 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
122 | - |
|
123 | - $this->assign('requestStates', $config->getRequestStates()); |
|
124 | - |
|
125 | - /** @var EmailTemplate $createdTemplate */ |
|
126 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
127 | - |
|
128 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
129 | - $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
130 | - $this->assign('createdId', $createdTemplate->getId()); |
|
131 | - $this->assign('createdName', $createdTemplate->getName()); |
|
132 | - |
|
133 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
134 | - $this->assign("createReasons", $createReasons); |
|
135 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
136 | - $this->assign("declineReasons", $declineReasons); |
|
137 | - |
|
138 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
139 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
140 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
141 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
142 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
143 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
144 | - } |
|
145 | - |
|
146 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
147 | - { |
|
148 | - $currentUser = User::getCurrent($database); |
|
149 | - |
|
150 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
151 | - $requestLogs = array(); |
|
152 | - |
|
153 | - if (trim($request->getComment()) !== "") { |
|
154 | - $requestLogs[] = array( |
|
155 | - 'type' => 'comment', |
|
156 | - 'security' => 'user', |
|
157 | - 'userid' => null, |
|
158 | - 'user' => $request->getName(), |
|
159 | - 'entry' => null, |
|
160 | - 'time' => $request->getDate(), |
|
161 | - 'canedit' => false, |
|
162 | - 'id' => $request->getId(), |
|
163 | - 'comment' => $request->getComment(), |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - /** @var User[] $nameCache */ |
|
168 | - $nameCache = array(); |
|
169 | - |
|
170 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
171 | - |
|
172 | - /** @var Log|Comment $entry */ |
|
173 | - foreach ($logs as $entry) { |
|
174 | - // both log and comment have a 'user' field |
|
175 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
176 | - $entryUser = User::getById($entry->getUser(), $database); |
|
177 | - $nameCache[$entry->getUser()] = $entryUser; |
|
178 | - } |
|
179 | - |
|
180 | - if ($entry instanceof Comment) { |
|
181 | - $requestLogs[] = array( |
|
182 | - 'type' => 'comment', |
|
183 | - 'security' => $entry->getVisibility(), |
|
184 | - 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
185 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
186 | - 'entry' => null, |
|
187 | - 'time' => $entry->getTime(), |
|
188 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
189 | - 'id' => $entry->getId(), |
|
190 | - 'comment' => $entry->getComment(), |
|
191 | - ); |
|
192 | - } |
|
193 | - |
|
194 | - if ($entry instanceof Log) { |
|
195 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
196 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
197 | - |
|
198 | - $requestLogs[] = array( |
|
199 | - 'type' => 'log', |
|
200 | - 'security' => 'user', |
|
201 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
202 | - 'user' => $entryUser->getUsername(), |
|
203 | - 'entry' => LogHelper::getLogDescription($entry), |
|
204 | - 'time' => $entry->getTimestamp(), |
|
205 | - 'canedit' => false, |
|
206 | - 'id' => $entry->getId(), |
|
207 | - 'comment' => $entry->getComment(), |
|
208 | - ); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
213 | - |
|
214 | - $this->assign("requestLogs", $requestLogs); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @param Request $request |
|
219 | - */ |
|
220 | - protected function setupUsernameData(Request $request) |
|
221 | - { |
|
222 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
223 | - |
|
224 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
225 | - $this->assign('requestBlacklist', $blacklistData); |
|
226 | - |
|
227 | - try { |
|
228 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
229 | - } |
|
230 | - catch (Exception $ex) { |
|
231 | - $spoofs = $ex->getMessage(); |
|
232 | - } |
|
233 | - |
|
234 | - $this->assign("spoofs", $spoofs); |
|
235 | - } |
|
27 | + use RequestData; |
|
28 | + const STATUS_SYMBOL_OPEN = '☐'; |
|
29 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
30 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Main function for this page, when no specific actions are called. |
|
34 | + * @throws ApplicationLogicException |
|
35 | + */ |
|
36 | + protected function main() |
|
37 | + { |
|
38 | + // set up csrf protection |
|
39 | + $this->assignCSRFToken(); |
|
40 | + |
|
41 | + // get some useful objects |
|
42 | + $database = $this->getDatabase(); |
|
43 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
44 | + $config = $this->getSiteConfiguration(); |
|
45 | + $currentUser = User::getCurrent($database); |
|
46 | + |
|
47 | + // Test we should be able to look at this request |
|
48 | + if ($config->getEmailConfirmationEnabled()) { |
|
49 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
50 | + // Not allowed to look at this yet. |
|
51 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + $this->setupBasicData($request, $config); |
|
56 | + |
|
57 | + $this->setupUsernameData($request); |
|
58 | + |
|
59 | + $this->setupTitle($request); |
|
60 | + |
|
61 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
62 | + $this->setupGeneralData($database); |
|
63 | + |
|
64 | + $this->assign('requestDataCleared', false); |
|
65 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
66 | + $this->assign('requestDataCleared', true); |
|
67 | + } |
|
68 | + |
|
69 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
70 | + |
|
71 | + $this->setupLogData($request, $database); |
|
72 | + |
|
73 | + if ($allowedPrivateData) { |
|
74 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
75 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
76 | + |
|
77 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
78 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
79 | + |
|
80 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
81 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
82 | + $this->setupCheckUserData($request); |
|
83 | + } |
|
84 | + } |
|
85 | + else { |
|
86 | + $this->setTemplate('view-request/main.tpl'); |
|
87 | + } |
|
88 | + |
|
89 | + $this->addCss('/resources/viewrequest.css'); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param Request $request |
|
94 | + */ |
|
95 | + protected function setupTitle(Request $request) |
|
96 | + { |
|
97 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
98 | + if ($request->getStatus() === 'Closed') { |
|
99 | + if ($request->getWasCreated()) { |
|
100 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
101 | + } |
|
102 | + else { |
|
103 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Sets up data unrelated to the request, such as the email template information |
|
112 | + * |
|
113 | + * @param PdoDatabase $database |
|
114 | + */ |
|
115 | + protected function setupGeneralData(PdoDatabase $database) |
|
116 | + { |
|
117 | + $config = $this->getSiteConfiguration(); |
|
118 | + |
|
119 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
120 | + |
|
121 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
122 | + |
|
123 | + $this->assign('requestStates', $config->getRequestStates()); |
|
124 | + |
|
125 | + /** @var EmailTemplate $createdTemplate */ |
|
126 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
127 | + |
|
128 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
129 | + $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
130 | + $this->assign('createdId', $createdTemplate->getId()); |
|
131 | + $this->assign('createdName', $createdTemplate->getName()); |
|
132 | + |
|
133 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
134 | + $this->assign("createReasons", $createReasons); |
|
135 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
136 | + $this->assign("declineReasons", $declineReasons); |
|
137 | + |
|
138 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
139 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
140 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
141 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
142 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
143 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
144 | + } |
|
145 | + |
|
146 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
147 | + { |
|
148 | + $currentUser = User::getCurrent($database); |
|
149 | + |
|
150 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
151 | + $requestLogs = array(); |
|
152 | + |
|
153 | + if (trim($request->getComment()) !== "") { |
|
154 | + $requestLogs[] = array( |
|
155 | + 'type' => 'comment', |
|
156 | + 'security' => 'user', |
|
157 | + 'userid' => null, |
|
158 | + 'user' => $request->getName(), |
|
159 | + 'entry' => null, |
|
160 | + 'time' => $request->getDate(), |
|
161 | + 'canedit' => false, |
|
162 | + 'id' => $request->getId(), |
|
163 | + 'comment' => $request->getComment(), |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + /** @var User[] $nameCache */ |
|
168 | + $nameCache = array(); |
|
169 | + |
|
170 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
171 | + |
|
172 | + /** @var Log|Comment $entry */ |
|
173 | + foreach ($logs as $entry) { |
|
174 | + // both log and comment have a 'user' field |
|
175 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
176 | + $entryUser = User::getById($entry->getUser(), $database); |
|
177 | + $nameCache[$entry->getUser()] = $entryUser; |
|
178 | + } |
|
179 | + |
|
180 | + if ($entry instanceof Comment) { |
|
181 | + $requestLogs[] = array( |
|
182 | + 'type' => 'comment', |
|
183 | + 'security' => $entry->getVisibility(), |
|
184 | + 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
185 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
186 | + 'entry' => null, |
|
187 | + 'time' => $entry->getTime(), |
|
188 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
189 | + 'id' => $entry->getId(), |
|
190 | + 'comment' => $entry->getComment(), |
|
191 | + ); |
|
192 | + } |
|
193 | + |
|
194 | + if ($entry instanceof Log) { |
|
195 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
196 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
197 | + |
|
198 | + $requestLogs[] = array( |
|
199 | + 'type' => 'log', |
|
200 | + 'security' => 'user', |
|
201 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
202 | + 'user' => $entryUser->getUsername(), |
|
203 | + 'entry' => LogHelper::getLogDescription($entry), |
|
204 | + 'time' => $entry->getTimestamp(), |
|
205 | + 'canedit' => false, |
|
206 | + 'id' => $entry->getId(), |
|
207 | + 'comment' => $entry->getComment(), |
|
208 | + ); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
213 | + |
|
214 | + $this->assign("requestLogs", $requestLogs); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @param Request $request |
|
219 | + */ |
|
220 | + protected function setupUsernameData(Request $request) |
|
221 | + { |
|
222 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
223 | + |
|
224 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
225 | + $this->assign('requestBlacklist', $blacklistData); |
|
226 | + |
|
227 | + try { |
|
228 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
229 | + } |
|
230 | + catch (Exception $ex) { |
|
231 | + $spoofs = $ex->getMessage(); |
|
232 | + } |
|
233 | + |
|
234 | + $this->assign("spoofs", $spoofs); |
|
235 | + } |
|
236 | 236 | } |
@@ -21,46 +21,46 @@ |
||
21 | 21 | |
22 | 22 | class ApiRequestRouter implements IRequestRouter |
23 | 23 | { |
24 | - /** |
|
25 | - * @return string[] |
|
26 | - */ |
|
27 | - public static function getActionList() |
|
28 | - { |
|
29 | - return array("count", "status", "stats", "help", "monitor"); |
|
30 | - } |
|
24 | + /** |
|
25 | + * @return string[] |
|
26 | + */ |
|
27 | + public static function getActionList() |
|
28 | + { |
|
29 | + return array("count", "status", "stats", "help", "monitor"); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return IRoutedTask |
|
34 | - * @throws Exception |
|
35 | - */ |
|
36 | - public function route() |
|
37 | - { |
|
38 | - $requestAction = WebRequest::getString('action'); |
|
32 | + /** |
|
33 | + * @return IRoutedTask |
|
34 | + * @throws Exception |
|
35 | + */ |
|
36 | + public function route() |
|
37 | + { |
|
38 | + $requestAction = WebRequest::getString('action'); |
|
39 | 39 | |
40 | - switch ($requestAction) { |
|
41 | - case "count": |
|
42 | - $result = new CountAction(); |
|
43 | - break; |
|
44 | - case "status": |
|
45 | - $result = new StatusAction(); |
|
46 | - break; |
|
47 | - case "stats": |
|
48 | - $result = new StatsAction(); |
|
49 | - break; |
|
50 | - case "help": |
|
51 | - $result = new HelpAction(); |
|
52 | - break; |
|
53 | - case "monitor": |
|
54 | - $result = new MonitorAction(); |
|
55 | - break; |
|
56 | - case "users": |
|
57 | - $result = new JsUsersAction(); |
|
58 | - break; |
|
59 | - default: |
|
60 | - $result = new UnknownAction(); |
|
61 | - break; |
|
62 | - } |
|
40 | + switch ($requestAction) { |
|
41 | + case "count": |
|
42 | + $result = new CountAction(); |
|
43 | + break; |
|
44 | + case "status": |
|
45 | + $result = new StatusAction(); |
|
46 | + break; |
|
47 | + case "stats": |
|
48 | + $result = new StatsAction(); |
|
49 | + break; |
|
50 | + case "help": |
|
51 | + $result = new HelpAction(); |
|
52 | + break; |
|
53 | + case "monitor": |
|
54 | + $result = new MonitorAction(); |
|
55 | + break; |
|
56 | + case "users": |
|
57 | + $result = new JsUsersAction(); |
|
58 | + break; |
|
59 | + default: |
|
60 | + $result = new UnknownAction(); |
|
61 | + break; |
|
62 | + } |
|
63 | 63 | |
64 | - return $result; |
|
65 | - } |
|
64 | + return $result; |
|
65 | + } |
|
66 | 66 | } |
@@ -23,531 +23,531 @@ |
||
23 | 23 | */ |
24 | 24 | class PageUserManagement extends InternalPageBase |
25 | 25 | { |
26 | - /** @var string */ |
|
27 | - private $adminMailingList = '[email protected]'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Main function for this page, when no specific actions are called. |
|
31 | - */ |
|
32 | - protected function main() |
|
33 | - { |
|
34 | - $this->setHtmlTitle('User Management'); |
|
35 | - |
|
36 | - $database = $this->getDatabase(); |
|
37 | - $currentUser = User::getCurrent($database); |
|
38 | - |
|
39 | - if (WebRequest::getBoolean("showAll")) { |
|
40 | - $this->assign("showAll", true); |
|
41 | - |
|
42 | - $this->assign("suspendedUsers", |
|
43 | - UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch()); |
|
44 | - $this->assign("declinedUsers", UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch()); |
|
45 | - |
|
46 | - UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
47 | - } |
|
48 | - else { |
|
49 | - $this->assign("showAll", false); |
|
50 | - $this->assign("suspendedUsers", array()); |
|
51 | - $this->assign("declinedUsers", array()); |
|
52 | - |
|
53 | - UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
54 | - } |
|
55 | - |
|
56 | - $this->assign('newUsers', UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch()); |
|
57 | - $this->assign('normalUsers', |
|
58 | - UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch()); |
|
59 | - $this->assign('adminUsers', |
|
60 | - UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch()); |
|
61 | - $this->assign('checkUsers', |
|
62 | - UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch()); |
|
63 | - $this->assign('toolRoots', |
|
64 | - UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch()); |
|
65 | - |
|
66 | - $this->assign('roles', $roleMap); |
|
67 | - |
|
68 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
69 | - |
|
70 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
71 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
72 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
73 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
74 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
75 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
76 | - |
|
77 | - $this->setTemplate("usermanagement/main.tpl"); |
|
78 | - } |
|
79 | - |
|
80 | - #region Access control |
|
81 | - |
|
82 | - /** |
|
83 | - * Action target for editing the roles assigned to a user |
|
84 | - */ |
|
85 | - protected function editRoles() |
|
86 | - { |
|
87 | - $this->setHtmlTitle('User Management'); |
|
88 | - $database = $this->getDatabase(); |
|
89 | - $userId = WebRequest::getInt('user'); |
|
90 | - |
|
91 | - /** @var User $user */ |
|
92 | - $user = User::getById($userId, $database); |
|
93 | - |
|
94 | - if ($user === false) { |
|
95 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
96 | - } |
|
97 | - |
|
98 | - $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
99 | - |
|
100 | - // Dual-mode action |
|
101 | - if (WebRequest::wasPosted()) { |
|
102 | - $this->validateCSRFToken(); |
|
103 | - |
|
104 | - $reason = WebRequest::postString('reason'); |
|
105 | - if ($reason === false || trim($reason) === '') { |
|
106 | - throw new ApplicationLogicException('No reason specified for roles change'); |
|
107 | - } |
|
108 | - |
|
109 | - /** @var UserRole[] $delete */ |
|
110 | - $delete = array(); |
|
111 | - /** @var string[] $delete */ |
|
112 | - $add = array(); |
|
113 | - |
|
114 | - foreach ($roleData as $name => $r) { |
|
115 | - if ($r['allowEdit'] !== 1) { |
|
116 | - // not allowed, to touch this, so ignore it |
|
117 | - continue; |
|
118 | - } |
|
119 | - |
|
120 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
121 | - if ($newValue !== $r['active']) { |
|
122 | - if ($newValue === 0) { |
|
123 | - $delete[] = $r['object']; |
|
124 | - } |
|
125 | - |
|
126 | - if ($newValue === 1) { |
|
127 | - $add[] = $name; |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - // Check there's something to do |
|
133 | - if ((count($add) + count($delete)) === 0) { |
|
134 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
135 | - SessionAlert::warning('No changes made to roles.'); |
|
136 | - |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - $removed = array(); |
|
141 | - |
|
142 | - /** @var UserRole $d */ |
|
143 | - foreach ($delete as $d) { |
|
144 | - $removed[] = $d->getRole(); |
|
145 | - $d->delete(); |
|
146 | - } |
|
147 | - |
|
148 | - foreach ($add as $x) { |
|
149 | - $a = new UserRole(); |
|
150 | - $a->setUser($user->getId()); |
|
151 | - $a->setRole($x); |
|
152 | - $a->setDatabase($database); |
|
153 | - $a->save(); |
|
154 | - } |
|
155 | - |
|
156 | - Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
157 | - |
|
158 | - // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
159 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
160 | - $user->save(); |
|
161 | - |
|
162 | - $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
163 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
164 | - |
|
165 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
166 | - return; |
|
167 | - } |
|
168 | - else { |
|
169 | - $this->assignCSRFToken(); |
|
170 | - $this->setTemplate('usermanagement/roleedit.tpl'); |
|
171 | - $this->assign('user', $user); |
|
172 | - $this->assign('roleData', $roleData); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Action target for suspending users |
|
178 | - * |
|
179 | - * @throws ApplicationLogicException |
|
180 | - */ |
|
181 | - protected function suspend() |
|
182 | - { |
|
183 | - $this->setHtmlTitle('User Management'); |
|
184 | - |
|
185 | - $database = $this->getDatabase(); |
|
186 | - |
|
187 | - $userId = WebRequest::getInt('user'); |
|
188 | - |
|
189 | - /** @var User $user */ |
|
190 | - $user = User::getById($userId, $database); |
|
191 | - |
|
192 | - if ($user === false) { |
|
193 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
194 | - } |
|
195 | - |
|
196 | - if ($user->isSuspended()) { |
|
197 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
198 | - } |
|
199 | - |
|
200 | - // Dual-mode action |
|
201 | - if (WebRequest::wasPosted()) { |
|
202 | - $this->validateCSRFToken(); |
|
203 | - $reason = WebRequest::postString('reason'); |
|
204 | - |
|
205 | - if ($reason === null || trim($reason) === "") { |
|
206 | - throw new ApplicationLogicException('No reason provided'); |
|
207 | - } |
|
208 | - |
|
209 | - $user->setStatus(User::STATUS_SUSPENDED); |
|
210 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
211 | - $user->save(); |
|
212 | - Logger::suspendedUser($database, $user, $reason); |
|
213 | - |
|
214 | - $this->getNotificationHelper()->userSuspended($user, $reason); |
|
215 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
216 | - |
|
217 | - // send email |
|
218 | - $this->sendStatusChangeEmail( |
|
219 | - 'Your WP:ACC account has been suspended', |
|
220 | - 'usermanagement/emails/suspended.tpl', |
|
221 | - $reason, |
|
222 | - $user, |
|
223 | - User::getCurrent($database)->getUsername() |
|
224 | - ); |
|
225 | - |
|
226 | - $this->redirect('userManagement'); |
|
227 | - |
|
228 | - return; |
|
229 | - } |
|
230 | - else { |
|
231 | - $this->assignCSRFToken(); |
|
232 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
233 | - $this->assign('user', $user); |
|
234 | - $this->assign('status', 'Suspended'); |
|
235 | - $this->assign("showReason", true); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Entry point for the decline action |
|
241 | - * |
|
242 | - * @throws ApplicationLogicException |
|
243 | - */ |
|
244 | - protected function decline() |
|
245 | - { |
|
246 | - $this->setHtmlTitle('User Management'); |
|
247 | - |
|
248 | - $database = $this->getDatabase(); |
|
249 | - |
|
250 | - $userId = WebRequest::getInt('user'); |
|
251 | - $user = User::getById($userId, $database); |
|
252 | - |
|
253 | - if ($user === false) { |
|
254 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
255 | - } |
|
256 | - |
|
257 | - if (!$user->isNewUser()) { |
|
258 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
259 | - } |
|
260 | - |
|
261 | - // Dual-mode action |
|
262 | - if (WebRequest::wasPosted()) { |
|
263 | - $this->validateCSRFToken(); |
|
264 | - $reason = WebRequest::postString('reason'); |
|
265 | - |
|
266 | - if ($reason === null || trim($reason) === "") { |
|
267 | - throw new ApplicationLogicException('No reason provided'); |
|
268 | - } |
|
269 | - |
|
270 | - $user->setStatus(User::STATUS_DECLINED); |
|
271 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
272 | - $user->save(); |
|
273 | - Logger::declinedUser($database, $user, $reason); |
|
274 | - |
|
275 | - $this->getNotificationHelper()->userDeclined($user, $reason); |
|
276 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
277 | - |
|
278 | - // send email |
|
279 | - $this->sendStatusChangeEmail( |
|
280 | - 'Your WP:ACC account has been declined', |
|
281 | - 'usermanagement/emails/declined.tpl', |
|
282 | - $reason, |
|
283 | - $user, |
|
284 | - User::getCurrent($database)->getUsername() |
|
285 | - ); |
|
286 | - |
|
287 | - $this->redirect('userManagement'); |
|
288 | - |
|
289 | - return; |
|
290 | - } |
|
291 | - else { |
|
292 | - $this->assignCSRFToken(); |
|
293 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
294 | - $this->assign('user', $user); |
|
295 | - $this->assign('status', 'Declined'); |
|
296 | - $this->assign("showReason", true); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Entry point for the approve action |
|
302 | - * |
|
303 | - * @throws ApplicationLogicException |
|
304 | - */ |
|
305 | - protected function approve() |
|
306 | - { |
|
307 | - $this->setHtmlTitle('User Management'); |
|
308 | - |
|
309 | - $database = $this->getDatabase(); |
|
310 | - |
|
311 | - $userId = WebRequest::getInt('user'); |
|
312 | - $user = User::getById($userId, $database); |
|
313 | - |
|
314 | - if ($user === false) { |
|
315 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
316 | - } |
|
317 | - |
|
318 | - if ($user->isActive()) { |
|
319 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
320 | - } |
|
321 | - |
|
322 | - // Dual-mode action |
|
323 | - if (WebRequest::wasPosted()) { |
|
324 | - $this->validateCSRFToken(); |
|
325 | - $user->setStatus(User::STATUS_ACTIVE); |
|
326 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
327 | - $user->save(); |
|
328 | - Logger::approvedUser($database, $user); |
|
329 | - |
|
330 | - $this->getNotificationHelper()->userApproved($user); |
|
331 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
332 | - |
|
333 | - // send email |
|
334 | - $this->sendStatusChangeEmail( |
|
335 | - 'Your WP:ACC account has been approved', |
|
336 | - 'usermanagement/emails/approved.tpl', |
|
337 | - null, |
|
338 | - $user, |
|
339 | - User::getCurrent($database)->getUsername() |
|
340 | - ); |
|
341 | - |
|
342 | - $this->redirect("userManagement"); |
|
343 | - |
|
344 | - return; |
|
345 | - } |
|
346 | - else { |
|
347 | - $this->assignCSRFToken(); |
|
348 | - $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
349 | - $this->assign("user", $user); |
|
350 | - $this->assign("status", "Active"); |
|
351 | - $this->assign("showReason", false); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - #endregion |
|
356 | - |
|
357 | - #region Renaming / Editing |
|
358 | - |
|
359 | - /** |
|
360 | - * Entry point for the rename action |
|
361 | - * |
|
362 | - * @throws ApplicationLogicException |
|
363 | - */ |
|
364 | - protected function rename() |
|
365 | - { |
|
366 | - $this->setHtmlTitle('User Management'); |
|
367 | - |
|
368 | - $database = $this->getDatabase(); |
|
369 | - |
|
370 | - $userId = WebRequest::getInt('user'); |
|
371 | - $user = User::getById($userId, $database); |
|
372 | - |
|
373 | - if ($user === false) { |
|
374 | - throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
375 | - } |
|
376 | - |
|
377 | - // Dual-mode action |
|
378 | - if (WebRequest::wasPosted()) { |
|
379 | - $this->validateCSRFToken(); |
|
380 | - $newUsername = WebRequest::postString('newname'); |
|
381 | - |
|
382 | - if ($newUsername === null || trim($newUsername) === "") { |
|
383 | - throw new ApplicationLogicException('The new username cannot be empty'); |
|
384 | - } |
|
385 | - |
|
386 | - if (User::getByUsername($newUsername, $database) != false) { |
|
387 | - throw new ApplicationLogicException('The new username already exists'); |
|
388 | - } |
|
389 | - |
|
390 | - $oldUsername = $user->getUsername(); |
|
391 | - $user->setUsername($newUsername); |
|
392 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
393 | - |
|
394 | - $user->save(); |
|
395 | - |
|
396 | - $logEntryData = serialize(array( |
|
397 | - 'old' => $oldUsername, |
|
398 | - 'new' => $newUsername, |
|
399 | - )); |
|
400 | - |
|
401 | - Logger::renamedUser($database, $user, $logEntryData); |
|
402 | - |
|
403 | - SessionAlert::quick("Changed User " |
|
404 | - . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
405 | - . " name to " |
|
406 | - . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
407 | - |
|
408 | - $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
409 | - |
|
410 | - // send an email to the user. |
|
411 | - $this->assign('targetUsername', $user->getUsername()); |
|
412 | - $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
413 | - $this->assign('oldUsername', $oldUsername); |
|
414 | - $this->assign('mailingList', $this->adminMailingList); |
|
415 | - |
|
416 | - $this->getEmailHelper()->sendMail( |
|
417 | - $user->getEmail(), |
|
418 | - 'Your username on WP:ACC has been changed', |
|
419 | - $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
420 | - array('Reply-To' => $this->adminMailingList) |
|
421 | - ); |
|
422 | - |
|
423 | - $this->redirect("userManagement"); |
|
424 | - |
|
425 | - return; |
|
426 | - } |
|
427 | - else { |
|
428 | - $this->assignCSRFToken(); |
|
429 | - $this->setTemplate('usermanagement/renameuser.tpl'); |
|
430 | - $this->assign('user', $user); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Entry point for the edit action |
|
436 | - * |
|
437 | - * @throws ApplicationLogicException |
|
438 | - */ |
|
439 | - protected function editUser() |
|
440 | - { |
|
441 | - $this->setHtmlTitle('User Management'); |
|
442 | - |
|
443 | - $database = $this->getDatabase(); |
|
444 | - |
|
445 | - $userId = WebRequest::getInt('user'); |
|
446 | - $user = User::getById($userId, $database); |
|
447 | - |
|
448 | - if ($user === false) { |
|
449 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
450 | - } |
|
451 | - |
|
452 | - // Dual-mode action |
|
453 | - if (WebRequest::wasPosted()) { |
|
454 | - $this->validateCSRFToken(); |
|
455 | - $newEmail = WebRequest::postEmail('user_email'); |
|
456 | - $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
457 | - |
|
458 | - if ($newEmail === null) { |
|
459 | - throw new ApplicationLogicException('Invalid email address'); |
|
460 | - } |
|
461 | - |
|
462 | - if (!$user->isOAuthLinked()) { |
|
463 | - if (trim($newOnWikiName) == "") { |
|
464 | - throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
465 | - } |
|
466 | - |
|
467 | - $user->setOnWikiName($newOnWikiName); |
|
468 | - } |
|
469 | - |
|
470 | - $user->setEmail($newEmail); |
|
471 | - |
|
472 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
473 | - |
|
474 | - $user->save(); |
|
475 | - |
|
476 | - Logger::userPreferencesChange($database, $user); |
|
477 | - $this->getNotificationHelper()->userPrefChange($user); |
|
478 | - SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
479 | - |
|
480 | - $this->redirect("userManagement"); |
|
481 | - |
|
482 | - return; |
|
483 | - } |
|
484 | - else { |
|
485 | - $this->assignCSRFToken(); |
|
486 | - $this->setTemplate('usermanagement/edituser.tpl'); |
|
487 | - $this->assign('user', $user); |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - #endregion |
|
492 | - |
|
493 | - /** |
|
494 | - * Sends a status change email to the user. |
|
495 | - * |
|
496 | - * @param string $subject The subject of the email |
|
497 | - * @param string $template The smarty template to use |
|
498 | - * @param string|null $reason The reason for performing the status change |
|
499 | - * @param User $user The user affected |
|
500 | - * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
501 | - */ |
|
502 | - private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
503 | - { |
|
504 | - $this->assign('targetUsername', $user->getUsername()); |
|
505 | - $this->assign('toolAdmin', $toolAdminUsername); |
|
506 | - $this->assign('actionReason', $reason); |
|
507 | - $this->assign('mailingList', $this->adminMailingList); |
|
508 | - |
|
509 | - $this->getEmailHelper()->sendMail( |
|
510 | - $user->getEmail(), |
|
511 | - $subject, |
|
512 | - $this->fetchTemplate($template), |
|
513 | - array('Reply-To' => $this->adminMailingList) |
|
514 | - ); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * @param UserRole[] $activeRoles |
|
519 | - * |
|
520 | - * @return array |
|
521 | - */ |
|
522 | - private function getRoleData($activeRoles) |
|
523 | - { |
|
524 | - $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
525 | - |
|
526 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
527 | - $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
528 | - |
|
529 | - $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
530 | - |
|
531 | - $roleData = array(); |
|
532 | - foreach ($availableRoles as $role => $data) { |
|
533 | - $intersection = array_intersect($data['editableBy'], $userRoles); |
|
534 | - |
|
535 | - $roleData[$role] = $initialValue; |
|
536 | - $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
537 | - $roleData[$role]['description'] = $data['description']; |
|
538 | - } |
|
539 | - |
|
540 | - foreach ($activeRoles as $role) { |
|
541 | - if (!isset($roleData[$role->getRole()])) { |
|
542 | - // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
543 | - $roleData[$role->getRole()] = $initialValue; |
|
544 | - $roleData[$role->getRole()]['allowEdit'] = 1; |
|
545 | - } |
|
546 | - |
|
547 | - $roleData[$role->getRole()]['object'] = $role; |
|
548 | - $roleData[$role->getRole()]['active'] = 1; |
|
549 | - } |
|
550 | - |
|
551 | - return $roleData; |
|
552 | - } |
|
26 | + /** @var string */ |
|
27 | + private $adminMailingList = '[email protected]'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + */ |
|
32 | + protected function main() |
|
33 | + { |
|
34 | + $this->setHtmlTitle('User Management'); |
|
35 | + |
|
36 | + $database = $this->getDatabase(); |
|
37 | + $currentUser = User::getCurrent($database); |
|
38 | + |
|
39 | + if (WebRequest::getBoolean("showAll")) { |
|
40 | + $this->assign("showAll", true); |
|
41 | + |
|
42 | + $this->assign("suspendedUsers", |
|
43 | + UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch()); |
|
44 | + $this->assign("declinedUsers", UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch()); |
|
45 | + |
|
46 | + UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
47 | + } |
|
48 | + else { |
|
49 | + $this->assign("showAll", false); |
|
50 | + $this->assign("suspendedUsers", array()); |
|
51 | + $this->assign("declinedUsers", array()); |
|
52 | + |
|
53 | + UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
54 | + } |
|
55 | + |
|
56 | + $this->assign('newUsers', UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch()); |
|
57 | + $this->assign('normalUsers', |
|
58 | + UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch()); |
|
59 | + $this->assign('adminUsers', |
|
60 | + UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch()); |
|
61 | + $this->assign('checkUsers', |
|
62 | + UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch()); |
|
63 | + $this->assign('toolRoots', |
|
64 | + UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch()); |
|
65 | + |
|
66 | + $this->assign('roles', $roleMap); |
|
67 | + |
|
68 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
69 | + |
|
70 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
71 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
72 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
73 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
74 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
75 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
76 | + |
|
77 | + $this->setTemplate("usermanagement/main.tpl"); |
|
78 | + } |
|
79 | + |
|
80 | + #region Access control |
|
81 | + |
|
82 | + /** |
|
83 | + * Action target for editing the roles assigned to a user |
|
84 | + */ |
|
85 | + protected function editRoles() |
|
86 | + { |
|
87 | + $this->setHtmlTitle('User Management'); |
|
88 | + $database = $this->getDatabase(); |
|
89 | + $userId = WebRequest::getInt('user'); |
|
90 | + |
|
91 | + /** @var User $user */ |
|
92 | + $user = User::getById($userId, $database); |
|
93 | + |
|
94 | + if ($user === false) { |
|
95 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
96 | + } |
|
97 | + |
|
98 | + $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
99 | + |
|
100 | + // Dual-mode action |
|
101 | + if (WebRequest::wasPosted()) { |
|
102 | + $this->validateCSRFToken(); |
|
103 | + |
|
104 | + $reason = WebRequest::postString('reason'); |
|
105 | + if ($reason === false || trim($reason) === '') { |
|
106 | + throw new ApplicationLogicException('No reason specified for roles change'); |
|
107 | + } |
|
108 | + |
|
109 | + /** @var UserRole[] $delete */ |
|
110 | + $delete = array(); |
|
111 | + /** @var string[] $delete */ |
|
112 | + $add = array(); |
|
113 | + |
|
114 | + foreach ($roleData as $name => $r) { |
|
115 | + if ($r['allowEdit'] !== 1) { |
|
116 | + // not allowed, to touch this, so ignore it |
|
117 | + continue; |
|
118 | + } |
|
119 | + |
|
120 | + $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
121 | + if ($newValue !== $r['active']) { |
|
122 | + if ($newValue === 0) { |
|
123 | + $delete[] = $r['object']; |
|
124 | + } |
|
125 | + |
|
126 | + if ($newValue === 1) { |
|
127 | + $add[] = $name; |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + // Check there's something to do |
|
133 | + if ((count($add) + count($delete)) === 0) { |
|
134 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
135 | + SessionAlert::warning('No changes made to roles.'); |
|
136 | + |
|
137 | + return; |
|
138 | + } |
|
139 | + |
|
140 | + $removed = array(); |
|
141 | + |
|
142 | + /** @var UserRole $d */ |
|
143 | + foreach ($delete as $d) { |
|
144 | + $removed[] = $d->getRole(); |
|
145 | + $d->delete(); |
|
146 | + } |
|
147 | + |
|
148 | + foreach ($add as $x) { |
|
149 | + $a = new UserRole(); |
|
150 | + $a->setUser($user->getId()); |
|
151 | + $a->setRole($x); |
|
152 | + $a->setDatabase($database); |
|
153 | + $a->save(); |
|
154 | + } |
|
155 | + |
|
156 | + Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
157 | + |
|
158 | + // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
159 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
160 | + $user->save(); |
|
161 | + |
|
162 | + $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
163 | + SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
164 | + |
|
165 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
166 | + return; |
|
167 | + } |
|
168 | + else { |
|
169 | + $this->assignCSRFToken(); |
|
170 | + $this->setTemplate('usermanagement/roleedit.tpl'); |
|
171 | + $this->assign('user', $user); |
|
172 | + $this->assign('roleData', $roleData); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Action target for suspending users |
|
178 | + * |
|
179 | + * @throws ApplicationLogicException |
|
180 | + */ |
|
181 | + protected function suspend() |
|
182 | + { |
|
183 | + $this->setHtmlTitle('User Management'); |
|
184 | + |
|
185 | + $database = $this->getDatabase(); |
|
186 | + |
|
187 | + $userId = WebRequest::getInt('user'); |
|
188 | + |
|
189 | + /** @var User $user */ |
|
190 | + $user = User::getById($userId, $database); |
|
191 | + |
|
192 | + if ($user === false) { |
|
193 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
194 | + } |
|
195 | + |
|
196 | + if ($user->isSuspended()) { |
|
197 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
198 | + } |
|
199 | + |
|
200 | + // Dual-mode action |
|
201 | + if (WebRequest::wasPosted()) { |
|
202 | + $this->validateCSRFToken(); |
|
203 | + $reason = WebRequest::postString('reason'); |
|
204 | + |
|
205 | + if ($reason === null || trim($reason) === "") { |
|
206 | + throw new ApplicationLogicException('No reason provided'); |
|
207 | + } |
|
208 | + |
|
209 | + $user->setStatus(User::STATUS_SUSPENDED); |
|
210 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
211 | + $user->save(); |
|
212 | + Logger::suspendedUser($database, $user, $reason); |
|
213 | + |
|
214 | + $this->getNotificationHelper()->userSuspended($user, $reason); |
|
215 | + SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
216 | + |
|
217 | + // send email |
|
218 | + $this->sendStatusChangeEmail( |
|
219 | + 'Your WP:ACC account has been suspended', |
|
220 | + 'usermanagement/emails/suspended.tpl', |
|
221 | + $reason, |
|
222 | + $user, |
|
223 | + User::getCurrent($database)->getUsername() |
|
224 | + ); |
|
225 | + |
|
226 | + $this->redirect('userManagement'); |
|
227 | + |
|
228 | + return; |
|
229 | + } |
|
230 | + else { |
|
231 | + $this->assignCSRFToken(); |
|
232 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
233 | + $this->assign('user', $user); |
|
234 | + $this->assign('status', 'Suspended'); |
|
235 | + $this->assign("showReason", true); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Entry point for the decline action |
|
241 | + * |
|
242 | + * @throws ApplicationLogicException |
|
243 | + */ |
|
244 | + protected function decline() |
|
245 | + { |
|
246 | + $this->setHtmlTitle('User Management'); |
|
247 | + |
|
248 | + $database = $this->getDatabase(); |
|
249 | + |
|
250 | + $userId = WebRequest::getInt('user'); |
|
251 | + $user = User::getById($userId, $database); |
|
252 | + |
|
253 | + if ($user === false) { |
|
254 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
255 | + } |
|
256 | + |
|
257 | + if (!$user->isNewUser()) { |
|
258 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
259 | + } |
|
260 | + |
|
261 | + // Dual-mode action |
|
262 | + if (WebRequest::wasPosted()) { |
|
263 | + $this->validateCSRFToken(); |
|
264 | + $reason = WebRequest::postString('reason'); |
|
265 | + |
|
266 | + if ($reason === null || trim($reason) === "") { |
|
267 | + throw new ApplicationLogicException('No reason provided'); |
|
268 | + } |
|
269 | + |
|
270 | + $user->setStatus(User::STATUS_DECLINED); |
|
271 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
272 | + $user->save(); |
|
273 | + Logger::declinedUser($database, $user, $reason); |
|
274 | + |
|
275 | + $this->getNotificationHelper()->userDeclined($user, $reason); |
|
276 | + SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
277 | + |
|
278 | + // send email |
|
279 | + $this->sendStatusChangeEmail( |
|
280 | + 'Your WP:ACC account has been declined', |
|
281 | + 'usermanagement/emails/declined.tpl', |
|
282 | + $reason, |
|
283 | + $user, |
|
284 | + User::getCurrent($database)->getUsername() |
|
285 | + ); |
|
286 | + |
|
287 | + $this->redirect('userManagement'); |
|
288 | + |
|
289 | + return; |
|
290 | + } |
|
291 | + else { |
|
292 | + $this->assignCSRFToken(); |
|
293 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
294 | + $this->assign('user', $user); |
|
295 | + $this->assign('status', 'Declined'); |
|
296 | + $this->assign("showReason", true); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Entry point for the approve action |
|
302 | + * |
|
303 | + * @throws ApplicationLogicException |
|
304 | + */ |
|
305 | + protected function approve() |
|
306 | + { |
|
307 | + $this->setHtmlTitle('User Management'); |
|
308 | + |
|
309 | + $database = $this->getDatabase(); |
|
310 | + |
|
311 | + $userId = WebRequest::getInt('user'); |
|
312 | + $user = User::getById($userId, $database); |
|
313 | + |
|
314 | + if ($user === false) { |
|
315 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
316 | + } |
|
317 | + |
|
318 | + if ($user->isActive()) { |
|
319 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
320 | + } |
|
321 | + |
|
322 | + // Dual-mode action |
|
323 | + if (WebRequest::wasPosted()) { |
|
324 | + $this->validateCSRFToken(); |
|
325 | + $user->setStatus(User::STATUS_ACTIVE); |
|
326 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
327 | + $user->save(); |
|
328 | + Logger::approvedUser($database, $user); |
|
329 | + |
|
330 | + $this->getNotificationHelper()->userApproved($user); |
|
331 | + SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
332 | + |
|
333 | + // send email |
|
334 | + $this->sendStatusChangeEmail( |
|
335 | + 'Your WP:ACC account has been approved', |
|
336 | + 'usermanagement/emails/approved.tpl', |
|
337 | + null, |
|
338 | + $user, |
|
339 | + User::getCurrent($database)->getUsername() |
|
340 | + ); |
|
341 | + |
|
342 | + $this->redirect("userManagement"); |
|
343 | + |
|
344 | + return; |
|
345 | + } |
|
346 | + else { |
|
347 | + $this->assignCSRFToken(); |
|
348 | + $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
349 | + $this->assign("user", $user); |
|
350 | + $this->assign("status", "Active"); |
|
351 | + $this->assign("showReason", false); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + #endregion |
|
356 | + |
|
357 | + #region Renaming / Editing |
|
358 | + |
|
359 | + /** |
|
360 | + * Entry point for the rename action |
|
361 | + * |
|
362 | + * @throws ApplicationLogicException |
|
363 | + */ |
|
364 | + protected function rename() |
|
365 | + { |
|
366 | + $this->setHtmlTitle('User Management'); |
|
367 | + |
|
368 | + $database = $this->getDatabase(); |
|
369 | + |
|
370 | + $userId = WebRequest::getInt('user'); |
|
371 | + $user = User::getById($userId, $database); |
|
372 | + |
|
373 | + if ($user === false) { |
|
374 | + throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
375 | + } |
|
376 | + |
|
377 | + // Dual-mode action |
|
378 | + if (WebRequest::wasPosted()) { |
|
379 | + $this->validateCSRFToken(); |
|
380 | + $newUsername = WebRequest::postString('newname'); |
|
381 | + |
|
382 | + if ($newUsername === null || trim($newUsername) === "") { |
|
383 | + throw new ApplicationLogicException('The new username cannot be empty'); |
|
384 | + } |
|
385 | + |
|
386 | + if (User::getByUsername($newUsername, $database) != false) { |
|
387 | + throw new ApplicationLogicException('The new username already exists'); |
|
388 | + } |
|
389 | + |
|
390 | + $oldUsername = $user->getUsername(); |
|
391 | + $user->setUsername($newUsername); |
|
392 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
393 | + |
|
394 | + $user->save(); |
|
395 | + |
|
396 | + $logEntryData = serialize(array( |
|
397 | + 'old' => $oldUsername, |
|
398 | + 'new' => $newUsername, |
|
399 | + )); |
|
400 | + |
|
401 | + Logger::renamedUser($database, $user, $logEntryData); |
|
402 | + |
|
403 | + SessionAlert::quick("Changed User " |
|
404 | + . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
405 | + . " name to " |
|
406 | + . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
407 | + |
|
408 | + $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
409 | + |
|
410 | + // send an email to the user. |
|
411 | + $this->assign('targetUsername', $user->getUsername()); |
|
412 | + $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
413 | + $this->assign('oldUsername', $oldUsername); |
|
414 | + $this->assign('mailingList', $this->adminMailingList); |
|
415 | + |
|
416 | + $this->getEmailHelper()->sendMail( |
|
417 | + $user->getEmail(), |
|
418 | + 'Your username on WP:ACC has been changed', |
|
419 | + $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
420 | + array('Reply-To' => $this->adminMailingList) |
|
421 | + ); |
|
422 | + |
|
423 | + $this->redirect("userManagement"); |
|
424 | + |
|
425 | + return; |
|
426 | + } |
|
427 | + else { |
|
428 | + $this->assignCSRFToken(); |
|
429 | + $this->setTemplate('usermanagement/renameuser.tpl'); |
|
430 | + $this->assign('user', $user); |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Entry point for the edit action |
|
436 | + * |
|
437 | + * @throws ApplicationLogicException |
|
438 | + */ |
|
439 | + protected function editUser() |
|
440 | + { |
|
441 | + $this->setHtmlTitle('User Management'); |
|
442 | + |
|
443 | + $database = $this->getDatabase(); |
|
444 | + |
|
445 | + $userId = WebRequest::getInt('user'); |
|
446 | + $user = User::getById($userId, $database); |
|
447 | + |
|
448 | + if ($user === false) { |
|
449 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
450 | + } |
|
451 | + |
|
452 | + // Dual-mode action |
|
453 | + if (WebRequest::wasPosted()) { |
|
454 | + $this->validateCSRFToken(); |
|
455 | + $newEmail = WebRequest::postEmail('user_email'); |
|
456 | + $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
457 | + |
|
458 | + if ($newEmail === null) { |
|
459 | + throw new ApplicationLogicException('Invalid email address'); |
|
460 | + } |
|
461 | + |
|
462 | + if (!$user->isOAuthLinked()) { |
|
463 | + if (trim($newOnWikiName) == "") { |
|
464 | + throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
465 | + } |
|
466 | + |
|
467 | + $user->setOnWikiName($newOnWikiName); |
|
468 | + } |
|
469 | + |
|
470 | + $user->setEmail($newEmail); |
|
471 | + |
|
472 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
473 | + |
|
474 | + $user->save(); |
|
475 | + |
|
476 | + Logger::userPreferencesChange($database, $user); |
|
477 | + $this->getNotificationHelper()->userPrefChange($user); |
|
478 | + SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
479 | + |
|
480 | + $this->redirect("userManagement"); |
|
481 | + |
|
482 | + return; |
|
483 | + } |
|
484 | + else { |
|
485 | + $this->assignCSRFToken(); |
|
486 | + $this->setTemplate('usermanagement/edituser.tpl'); |
|
487 | + $this->assign('user', $user); |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + #endregion |
|
492 | + |
|
493 | + /** |
|
494 | + * Sends a status change email to the user. |
|
495 | + * |
|
496 | + * @param string $subject The subject of the email |
|
497 | + * @param string $template The smarty template to use |
|
498 | + * @param string|null $reason The reason for performing the status change |
|
499 | + * @param User $user The user affected |
|
500 | + * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
501 | + */ |
|
502 | + private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
503 | + { |
|
504 | + $this->assign('targetUsername', $user->getUsername()); |
|
505 | + $this->assign('toolAdmin', $toolAdminUsername); |
|
506 | + $this->assign('actionReason', $reason); |
|
507 | + $this->assign('mailingList', $this->adminMailingList); |
|
508 | + |
|
509 | + $this->getEmailHelper()->sendMail( |
|
510 | + $user->getEmail(), |
|
511 | + $subject, |
|
512 | + $this->fetchTemplate($template), |
|
513 | + array('Reply-To' => $this->adminMailingList) |
|
514 | + ); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * @param UserRole[] $activeRoles |
|
519 | + * |
|
520 | + * @return array |
|
521 | + */ |
|
522 | + private function getRoleData($activeRoles) |
|
523 | + { |
|
524 | + $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
525 | + |
|
526 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
527 | + $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
528 | + |
|
529 | + $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
530 | + |
|
531 | + $roleData = array(); |
|
532 | + foreach ($availableRoles as $role => $data) { |
|
533 | + $intersection = array_intersect($data['editableBy'], $userRoles); |
|
534 | + |
|
535 | + $roleData[$role] = $initialValue; |
|
536 | + $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
537 | + $roleData[$role]['description'] = $data['description']; |
|
538 | + } |
|
539 | + |
|
540 | + foreach ($activeRoles as $role) { |
|
541 | + if (!isset($roleData[$role->getRole()])) { |
|
542 | + // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
543 | + $roleData[$role->getRole()] = $initialValue; |
|
544 | + $roleData[$role->getRole()]['allowEdit'] = 1; |
|
545 | + } |
|
546 | + |
|
547 | + $roleData[$role->getRole()]['object'] = $role; |
|
548 | + $roleData[$role->getRole()]['active'] = 1; |
|
549 | + } |
|
550 | + |
|
551 | + return $roleData; |
|
552 | + } |
|
553 | 553 | } |
@@ -18,147 +18,147 @@ |
||
18 | 18 | |
19 | 19 | class PageLog extends InternalPageBase |
20 | 20 | { |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - */ |
|
24 | - protected function main() |
|
25 | - { |
|
26 | - $this->setHtmlTitle('Logs'); |
|
27 | - |
|
28 | - $filterUser = WebRequest::getString('filterUser'); |
|
29 | - $filterAction = WebRequest::getString('filterAction'); |
|
30 | - $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | - $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
32 | - |
|
33 | - $database = $this->getDatabase(); |
|
34 | - |
|
35 | - if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | - $filterObjectType = null; |
|
37 | - } |
|
38 | - |
|
39 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
40 | - |
|
41 | - $limit = WebRequest::getInt('limit'); |
|
42 | - if ($limit === null) { |
|
43 | - $limit = 100; |
|
44 | - } |
|
45 | - |
|
46 | - $page = WebRequest::getInt('page'); |
|
47 | - if ($page === null) { |
|
48 | - $page = 1; |
|
49 | - } |
|
50 | - |
|
51 | - $offset = ($page - 1) * $limit; |
|
52 | - |
|
53 | - $logSearch = LogSearchHelper::get($database)->limit($limit, $offset); |
|
54 | - $this->setupSearchHelper($logSearch, $database, $filterUser, $filterAction, $filterObjectType, $filterObjectId); |
|
55 | - |
|
56 | - /** @var Log[] $logs */ |
|
57 | - $logs = $logSearch->getRecordCount($count)->fetch(); |
|
58 | - |
|
59 | - if ($count === 0) { |
|
60 | - $this->assign('logs', array()); |
|
61 | - $this->setTemplate('logs/main.tpl'); |
|
62 | - |
|
63 | - return; |
|
64 | - } |
|
65 | - |
|
66 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
67 | - |
|
68 | - $this->setupPageData($page, $limit, $count); |
|
69 | - |
|
70 | - $this->assign("logs", $logData); |
|
71 | - $this->assign("users", $users); |
|
72 | - |
|
73 | - $this->assign("filterUser", $filterUser); |
|
74 | - $this->assign("filterAction", $filterAction); |
|
75 | - $this->assign("filterObjectType", $filterObjectType); |
|
76 | - $this->assign("filterObjectId", $filterObjectId); |
|
77 | - |
|
78 | - $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
79 | - $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
80 | - |
|
81 | - $this->setTemplate("logs/main.tpl"); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param int $page |
|
86 | - * @param int $limit |
|
87 | - * @param int $count |
|
88 | - */ |
|
89 | - protected function setupPageData($page, $limit, $count) |
|
90 | - { |
|
91 | - // The number of pages on the pager to show. Must be odd |
|
92 | - $pageLimit = 9; |
|
93 | - |
|
94 | - $pageData = array( |
|
95 | - // Can the user go to the previous page? |
|
96 | - 'canprev' => $page != 1, |
|
97 | - // Can the user go to the next page? |
|
98 | - 'cannext' => ($page * $limit) < $count, |
|
99 | - // Maximum page number |
|
100 | - 'maxpage' => ceil($count / $limit), |
|
101 | - // Limit to the number of pages to display |
|
102 | - 'pagelimit' => $pageLimit, |
|
103 | - ); |
|
104 | - |
|
105 | - // number of pages either side of the current to show |
|
106 | - $pageMargin = (($pageLimit - 1) / 2); |
|
107 | - |
|
108 | - // Calculate the number of pages either side to show - this is for situations like: |
|
109 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
110 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
111 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
112 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
113 | - |
|
114 | - if ($pageCount < $pageLimit) { |
|
115 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
116 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
117 | - } |
|
118 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
119 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - // Put the range of pages into the page data |
|
124 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
125 | - |
|
126 | - $this->assign("pagedata", $pageData); |
|
127 | - |
|
128 | - $this->assign("limit", $limit); |
|
129 | - $this->assign("page", $page); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param $logSearch |
|
134 | - * @param $database |
|
135 | - * @param $filterUser |
|
136 | - * @param $filterAction |
|
137 | - * @param $filterObjectType |
|
138 | - * @param $filterObjectId |
|
139 | - */ |
|
140 | - private function setupSearchHelper( |
|
141 | - $logSearch, |
|
142 | - $database, |
|
143 | - $filterUser, |
|
144 | - $filterAction, |
|
145 | - $filterObjectType, |
|
146 | - $filterObjectId |
|
147 | - ) { |
|
148 | - if ($filterUser !== null) { |
|
149 | - $logSearch->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
150 | - } |
|
151 | - |
|
152 | - if ($filterAction !== null) { |
|
153 | - $logSearch->byAction($filterAction); |
|
154 | - } |
|
155 | - |
|
156 | - if ($filterObjectType !== null) { |
|
157 | - $logSearch->byObjectType($filterObjectType); |
|
158 | - } |
|
159 | - |
|
160 | - if ($filterObjectId !== null) { |
|
161 | - $logSearch->byObjectId($filterObjectId); |
|
162 | - } |
|
163 | - } |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + */ |
|
24 | + protected function main() |
|
25 | + { |
|
26 | + $this->setHtmlTitle('Logs'); |
|
27 | + |
|
28 | + $filterUser = WebRequest::getString('filterUser'); |
|
29 | + $filterAction = WebRequest::getString('filterAction'); |
|
30 | + $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | + $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
32 | + |
|
33 | + $database = $this->getDatabase(); |
|
34 | + |
|
35 | + if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | + $filterObjectType = null; |
|
37 | + } |
|
38 | + |
|
39 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
40 | + |
|
41 | + $limit = WebRequest::getInt('limit'); |
|
42 | + if ($limit === null) { |
|
43 | + $limit = 100; |
|
44 | + } |
|
45 | + |
|
46 | + $page = WebRequest::getInt('page'); |
|
47 | + if ($page === null) { |
|
48 | + $page = 1; |
|
49 | + } |
|
50 | + |
|
51 | + $offset = ($page - 1) * $limit; |
|
52 | + |
|
53 | + $logSearch = LogSearchHelper::get($database)->limit($limit, $offset); |
|
54 | + $this->setupSearchHelper($logSearch, $database, $filterUser, $filterAction, $filterObjectType, $filterObjectId); |
|
55 | + |
|
56 | + /** @var Log[] $logs */ |
|
57 | + $logs = $logSearch->getRecordCount($count)->fetch(); |
|
58 | + |
|
59 | + if ($count === 0) { |
|
60 | + $this->assign('logs', array()); |
|
61 | + $this->setTemplate('logs/main.tpl'); |
|
62 | + |
|
63 | + return; |
|
64 | + } |
|
65 | + |
|
66 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
67 | + |
|
68 | + $this->setupPageData($page, $limit, $count); |
|
69 | + |
|
70 | + $this->assign("logs", $logData); |
|
71 | + $this->assign("users", $users); |
|
72 | + |
|
73 | + $this->assign("filterUser", $filterUser); |
|
74 | + $this->assign("filterAction", $filterAction); |
|
75 | + $this->assign("filterObjectType", $filterObjectType); |
|
76 | + $this->assign("filterObjectId", $filterObjectId); |
|
77 | + |
|
78 | + $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
79 | + $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
80 | + |
|
81 | + $this->setTemplate("logs/main.tpl"); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param int $page |
|
86 | + * @param int $limit |
|
87 | + * @param int $count |
|
88 | + */ |
|
89 | + protected function setupPageData($page, $limit, $count) |
|
90 | + { |
|
91 | + // The number of pages on the pager to show. Must be odd |
|
92 | + $pageLimit = 9; |
|
93 | + |
|
94 | + $pageData = array( |
|
95 | + // Can the user go to the previous page? |
|
96 | + 'canprev' => $page != 1, |
|
97 | + // Can the user go to the next page? |
|
98 | + 'cannext' => ($page * $limit) < $count, |
|
99 | + // Maximum page number |
|
100 | + 'maxpage' => ceil($count / $limit), |
|
101 | + // Limit to the number of pages to display |
|
102 | + 'pagelimit' => $pageLimit, |
|
103 | + ); |
|
104 | + |
|
105 | + // number of pages either side of the current to show |
|
106 | + $pageMargin = (($pageLimit - 1) / 2); |
|
107 | + |
|
108 | + // Calculate the number of pages either side to show - this is for situations like: |
|
109 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
110 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
111 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
112 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
113 | + |
|
114 | + if ($pageCount < $pageLimit) { |
|
115 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
116 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
117 | + } |
|
118 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
119 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + // Put the range of pages into the page data |
|
124 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
125 | + |
|
126 | + $this->assign("pagedata", $pageData); |
|
127 | + |
|
128 | + $this->assign("limit", $limit); |
|
129 | + $this->assign("page", $page); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param $logSearch |
|
134 | + * @param $database |
|
135 | + * @param $filterUser |
|
136 | + * @param $filterAction |
|
137 | + * @param $filterObjectType |
|
138 | + * @param $filterObjectId |
|
139 | + */ |
|
140 | + private function setupSearchHelper( |
|
141 | + $logSearch, |
|
142 | + $database, |
|
143 | + $filterUser, |
|
144 | + $filterAction, |
|
145 | + $filterObjectType, |
|
146 | + $filterObjectId |
|
147 | + ) { |
|
148 | + if ($filterUser !== null) { |
|
149 | + $logSearch->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
150 | + } |
|
151 | + |
|
152 | + if ($filterAction !== null) { |
|
153 | + $logSearch->byAction($filterAction); |
|
154 | + } |
|
155 | + |
|
156 | + if ($filterObjectType !== null) { |
|
157 | + $logSearch->byObjectType($filterObjectType); |
|
158 | + } |
|
159 | + |
|
160 | + if ($filterObjectId !== null) { |
|
161 | + $logSearch->byObjectId($filterObjectId); |
|
162 | + } |
|
163 | + } |
|
164 | 164 | } |
@@ -16,12 +16,12 @@ |
||
16 | 16 | */ |
17 | 17 | interface IXmlApiAction extends IRoutedTask, IApiAction |
18 | 18 | { |
19 | - /** |
|
20 | - * Method that runs API action |
|
21 | - * |
|
22 | - * @param DOMElement $apiDocument |
|
23 | - * |
|
24 | - * @return DOMElement The modified API document |
|
25 | - */ |
|
26 | - public function executeApiAction(DOMElement $apiDocument); |
|
19 | + /** |
|
20 | + * Method that runs API action |
|
21 | + * |
|
22 | + * @param DOMElement $apiDocument |
|
23 | + * |
|
24 | + * @return DOMElement The modified API document |
|
25 | + */ |
|
26 | + public function executeApiAction(DOMElement $apiDocument); |
|
27 | 27 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | */ |
16 | 16 | interface IJsonApiAction extends IRoutedTask, IApiAction |
17 | 17 | { |
18 | - /** |
|
19 | - * Method that runs API action |
|
20 | - * |
|
21 | - * @return object|array The modified API document |
|
22 | - */ |
|
23 | - public function executeApiAction(); |
|
18 | + /** |
|
19 | + * Method that runs API action |
|
20 | + * |
|
21 | + * @return object|array The modified API document |
|
22 | + */ |
|
23 | + public function executeApiAction(); |
|
24 | 24 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | */ |
17 | 17 | class UnknownAction extends HelpAction implements IXmlApiAction |
18 | 18 | { |
19 | - public function executeApiAction(DOMElement $apiDocument) |
|
20 | - { |
|
21 | - $errorText = "Unknown API action specified."; |
|
22 | - $errorNode = $this->document->createElement("error", $errorText); |
|
23 | - $apiDocument->appendChild($errorNode); |
|
19 | + public function executeApiAction(DOMElement $apiDocument) |
|
20 | + { |
|
21 | + $errorText = "Unknown API action specified."; |
|
22 | + $errorNode = $this->document->createElement("error", $errorText); |
|
23 | + $apiDocument->appendChild($errorNode); |
|
24 | 24 | |
25 | - $helpElement = $this->getHelpElement(); |
|
26 | - $apiDocument->appendChild($helpElement); |
|
25 | + $helpElement = $this->getHelpElement(); |
|
26 | + $apiDocument->appendChild($helpElement); |
|
27 | 27 | |
28 | - return $apiDocument; |
|
29 | - } |
|
28 | + return $apiDocument; |
|
29 | + } |
|
30 | 30 | } |
@@ -16,18 +16,18 @@ |
||
16 | 16 | |
17 | 17 | class JsUsersAction extends JsonApiPageBase implements IJsonApiAction |
18 | 18 | { |
19 | - public function executeApiAction() |
|
20 | - { |
|
21 | - $this->getDatabase(); |
|
19 | + public function executeApiAction() |
|
20 | + { |
|
21 | + $this->getDatabase(); |
|
22 | 22 | |
23 | - $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
23 | + $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
24 | 24 | |
25 | - if (WebRequest::getString('all') === null) { |
|
26 | - $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
25 | + if (WebRequest::getString('all') === null) { |
|
26 | + $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | - return $dataset; |
|
32 | - } |
|
30 | + $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | + return $dataset; |
|
32 | + } |
|
33 | 33 | } |
@@ -18,34 +18,34 @@ |
||
18 | 18 | */ |
19 | 19 | class HelpAction extends XmlApiPageBase implements IXmlApiAction |
20 | 20 | { |
21 | - public function executeApiAction(DOMElement $apiDocument) |
|
22 | - { |
|
23 | - $helpElement = $this->getHelpElement(); |
|
24 | - $apiDocument->appendChild($helpElement); |
|
25 | - |
|
26 | - return $apiDocument; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Gets the help information |
|
31 | - * @return DOMElement |
|
32 | - */ |
|
33 | - protected function getHelpElement() |
|
34 | - { |
|
35 | - $helpInfo = "Help info goes here!"; |
|
36 | - |
|
37 | - $help = $this->document->createElement("help"); |
|
38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | - $helpactions = $this->document->createElement("actions"); |
|
40 | - |
|
41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | - $actionElement = $this->document->createElement("action", $action); |
|
43 | - $helpactions->appendChild($actionElement); |
|
44 | - } |
|
45 | - |
|
46 | - $help->appendChild($helptext); |
|
47 | - $help->appendChild($helpactions); |
|
48 | - |
|
49 | - return $help; |
|
50 | - } |
|
21 | + public function executeApiAction(DOMElement $apiDocument) |
|
22 | + { |
|
23 | + $helpElement = $this->getHelpElement(); |
|
24 | + $apiDocument->appendChild($helpElement); |
|
25 | + |
|
26 | + return $apiDocument; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Gets the help information |
|
31 | + * @return DOMElement |
|
32 | + */ |
|
33 | + protected function getHelpElement() |
|
34 | + { |
|
35 | + $helpInfo = "Help info goes here!"; |
|
36 | + |
|
37 | + $help = $this->document->createElement("help"); |
|
38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | + $helpactions = $this->document->createElement("actions"); |
|
40 | + |
|
41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | + $actionElement = $this->document->createElement("action", $action); |
|
43 | + $helpactions->appendChild($actionElement); |
|
44 | + } |
|
45 | + |
|
46 | + $help->appendChild($helptext); |
|
47 | + $help->appendChild($helpactions); |
|
48 | + |
|
49 | + return $help; |
|
50 | + } |
|
51 | 51 | } |