1 | <?php |
||
2 | /****************************************************************************** |
||
3 | * Wikipedia Account Creation Assistance tool * |
||
4 | * * |
||
5 | * All code in this file is released into the public domain by the ACC * |
||
6 | * Development Team. Please see team.json for a list of contributors. * |
||
7 | ******************************************************************************/ |
||
8 | |||
9 | namespace Waca\Pages; |
||
10 | |||
11 | use Exception; |
||
12 | use DateTime; |
||
13 | use Waca\DataObjects\Comment; |
||
14 | use Waca\DataObjects\Domain; |
||
15 | use Waca\DataObjects\EmailTemplate; |
||
16 | use Waca\DataObjects\JobQueue; |
||
17 | use Waca\DataObjects\Log; |
||
18 | use Waca\DataObjects\Request; |
||
19 | use Waca\DataObjects\RequestQueue; |
||
20 | use Waca\DataObjects\User; |
||
21 | use Waca\Exceptions\ApplicationLogicException; |
||
22 | use Waca\Fragments\RequestData; |
||
0 ignored issues
–
show
|
|||
23 | use Waca\Helpers\LogHelper; |
||
24 | use Waca\Helpers\OAuthUserHelper; |
||
25 | use Waca\Pages\RequestAction\PageManuallyConfirm; |
||
26 | use Waca\PdoDatabase; |
||
27 | use Waca\Security\RoleConfiguration; |
||
28 | use Waca\RequestStatus; |
||
29 | use Waca\Tasks\InternalPageBase; |
||
30 | use Waca\WebRequest; |
||
31 | |||
32 | class PageViewRequest extends InternalPageBase |
||
33 | { |
||
34 | use RequestData; |
||
35 | const STATUS_SYMBOL_OPEN = 'Ο'; |
||
36 | const STATUS_SYMBOL_ACCEPTED = '☑'; |
||
37 | const STATUS_SYMBOL_REJECTED = '☒'; |
||
38 | |||
39 | /** |
||
40 | * Main function for this page, when no specific actions are called. |
||
41 | * @throws ApplicationLogicException |
||
42 | */ |
||
43 | protected function main() |
||
44 | { |
||
45 | // set up csrf protection |
||
46 | $this->assignCSRFToken(); |
||
47 | |||
48 | // get some useful objects |
||
49 | $database = $this->getDatabase(); |
||
50 | $request = $this->getRequest($database, WebRequest::getInt('id')); |
||
51 | $config = $this->getSiteConfiguration(); |
||
52 | $currentUser = User::getCurrent($database); |
||
53 | |||
54 | // FIXME: domains! |
||
55 | /** @var Domain $domain */ |
||
56 | $domain = Domain::getById(1, $this->getDatabase()); |
||
57 | $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
||
58 | |||
59 | // Shows a page if the email is not confirmed. |
||
60 | if ($request->getEmailConfirm() !== 'Confirmed') { |
||
61 | // Show a banner if the user can manually confirm the request |
||
62 | $viewConfirm = $this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageManuallyConfirm::class); |
||
63 | |||
64 | // If the request is purged, there's nothing to confirm! |
||
65 | if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
||
66 | $viewConfirm = false; |
||
67 | } |
||
68 | |||
69 | // Render |
||
70 | $this->setTemplate("view-request/not-confirmed.tpl"); |
||
71 | $this->assign("requestId", $request->getId()); |
||
72 | $this->assign("requestVersion", $request->getUpdateVersion()); |
||
73 | $this->assign('canViewConfirmButton', $viewConfirm); |
||
74 | |||
75 | // Make sure to return, to prevent the leaking of other information. |
||
76 | return; |
||
77 | } |
||
78 | |||
79 | $this->setupBasicData($request, $config); |
||
80 | |||
81 | $this->setupUsernameData($request); |
||
82 | |||
83 | $this->setupTitle($request); |
||
84 | |||
85 | $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
||
86 | $this->setupGeneralData($database); |
||
87 | |||
88 | $this->assign('requestDataCleared', false); |
||
89 | if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
||
90 | $this->assign('requestDataCleared', true); |
||
91 | } |
||
92 | |||
93 | $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
||
94 | |||
95 | $this->setupCreationTypes($currentUser); |
||
96 | |||
97 | $this->setupLogData($request, $database); |
||
98 | |||
99 | $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
||
100 | |||
101 | $this->assign('showRevealLink', false); |
||
102 | if ($request->getReserved() === $currentUser->getId() || |
||
103 | $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
||
104 | ) { |
||
105 | $this->assign('showRevealLink', true); |
||
106 | $this->assign('revealHash', $request->getRevealHash()); |
||
107 | } |
||
108 | |||
109 | $this->assign('canSeeRelatedRequests', false); |
||
110 | if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) { |
||
111 | $this->setupRelatedRequests($request, $config, $database); |
||
112 | } |
||
113 | |||
114 | $this->assign('canCreateLocalAccount', $this->barrierTest('createLocalAccount', $currentUser, 'RequestData')); |
||
115 | |||
116 | $closureDate = $request->getClosureDate(); |
||
117 | $date = new DateTime(); |
||
118 | $date->modify("-7 days"); |
||
119 | if ($request->getStatus() == "Closed" && $closureDate < $date) { |
||
120 | $this->assign('isOldRequest', true); |
||
121 | } |
||
122 | $this->assign('canResetOldRequest', $this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')); |
||
123 | $this->assign('canResetPurgedRequest', $this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')); |
||
124 | |||
125 | $this->assign('requestEmailSent', $request->getEmailSent()); |
||
126 | |||
127 | if ($allowedPrivateData) { |
||
128 | $this->setTemplate('view-request/main-with-data.tpl'); |
||
129 | $this->setupPrivateData($request, $config); |
||
130 | $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
||
131 | $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
||
132 | |||
133 | if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
||
134 | $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
||
135 | $this->setupCheckUserData($request); |
||
136 | } |
||
137 | } |
||
138 | else { |
||
139 | $this->setTemplate('view-request/main.tpl'); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @param Request $request |
||
145 | */ |
||
146 | protected function setupTitle(Request $request) |
||
147 | { |
||
148 | $statusSymbol = self::STATUS_SYMBOL_OPEN; |
||
149 | if ($request->getStatus() === RequestStatus::CLOSED) { |
||
150 | if ($request->getWasCreated()) { |
||
151 | $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
||
152 | } |
||
153 | else { |
||
154 | $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Sets up data unrelated to the request, such as the email template information |
||
163 | * |
||
164 | * @param PdoDatabase $database |
||
165 | */ |
||
166 | protected function setupGeneralData(PdoDatabase $database) |
||
167 | { |
||
168 | $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
||
169 | |||
170 | // FIXME: domains |
||
171 | /** @var Domain $domain */ |
||
172 | $domain = Domain::getById(1, $database); |
||
173 | $this->assign('defaultRequestState', RequestQueue::getDefaultQueue($database, 1)->getApiName()); |
||
174 | $this->assign('activeRequestQueues', RequestQueue::getEnabledQueues($database)); |
||
175 | |||
176 | /** @var EmailTemplate $createdTemplate */ |
||
177 | $createdTemplate = EmailTemplate::getById($domain->getDefaultClose(), $database); |
||
178 | |||
179 | $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
||
180 | $this->assign('createdId', $createdTemplate->getId()); |
||
181 | $this->assign('createdName', $createdTemplate->getName()); |
||
182 | |||
183 | $createReasons = EmailTemplate::getActiveNonpreloadTemplates(EmailTemplate::ACTION_CREATED, $database, $domain->getDefaultClose()); |
||
184 | $this->assign("createReasons", $createReasons); |
||
185 | $declineReasons = EmailTemplate::getActiveNonpreloadTemplates(EmailTemplate::ACTION_NOT_CREATED, $database); |
||
186 | $this->assign("declineReasons", $declineReasons); |
||
187 | |||
188 | $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::ACTION_CREATED, $database); |
||
189 | $this->assign("allCreateReasons", $allCreateReasons); |
||
190 | $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::ACTION_NOT_CREATED, $database); |
||
191 | $this->assign("allDeclineReasons", $allDeclineReasons); |
||
192 | $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
||
193 | $this->assign("allOtherReasons", $allOtherReasons); |
||
194 | } |
||
195 | |||
196 | private function setupLogData(Request $request, PdoDatabase $database) |
||
197 | { |
||
198 | $currentUser = User::getCurrent($database); |
||
199 | |||
200 | $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
||
201 | $requestLogs = array(); |
||
202 | |||
203 | /** @var User[] $nameCache */ |
||
204 | $nameCache = array(); |
||
205 | |||
206 | $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
||
207 | |||
208 | $canFlag = $this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageFlagComment::class); |
||
209 | $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
||
210 | |||
211 | /** @var Log|Comment $entry */ |
||
212 | foreach ($logs as $entry) { |
||
213 | // both log and comment have a 'user' field |
||
214 | if (!array_key_exists($entry->getUser(), $nameCache)) { |
||
215 | $entryUser = User::getById($entry->getUser(), $database); |
||
216 | $nameCache[$entry->getUser()] = $entryUser; |
||
217 | } |
||
218 | |||
219 | if ($entry instanceof Comment) { |
||
220 | $requestLogs[] = array( |
||
221 | 'type' => 'comment', |
||
222 | 'security' => $entry->getVisibility(), |
||
223 | 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
||
224 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
||
225 | 'entry' => null, |
||
226 | 'time' => $entry->getTime(), |
||
227 | 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
||
228 | 'id' => $entry->getId(), |
||
229 | 'comment' => $entry->getComment(), |
||
230 | 'flagged' => $entry->getFlagged(), |
||
231 | 'canflag' => $canFlag && (!$entry->getFlagged() || ($entry->getFlagged() && $canUnflag)), |
||
232 | 'updateversion' => $entry->getUpdateVersion(), |
||
233 | 'edited' => $entry->getEdited() |
||
234 | ); |
||
235 | } |
||
236 | |||
237 | if ($entry instanceof Log) { |
||
238 | $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
||
239 | $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
||
240 | |||
241 | $entryComment = $entry->getComment(); |
||
242 | |||
243 | if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
||
244 | $data = unserialize($entry->getComment()); |
||
245 | /** @var JobQueue $job */ |
||
246 | $job = JobQueue::getById($data['job'], $database); |
||
247 | $requestLogs[] = array( |
||
248 | 'type' => 'joblog', |
||
249 | 'security' => 'user', |
||
250 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
||
251 | 'user' => $entryUser->getUsername(), |
||
252 | 'entry' => LogHelper::getLogDescription($entry), |
||
253 | 'time' => $entry->getTimestamp(), |
||
254 | 'canedit' => false, |
||
255 | 'id' => $entry->getId(), |
||
256 | 'jobId' => $job->getId(), |
||
257 | 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
||
258 | ); |
||
259 | } |
||
260 | else { |
||
261 | $requestLogs[] = array( |
||
262 | 'type' => 'log', |
||
263 | 'security' => 'user', |
||
264 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
||
265 | 'user' => $entryUser->getUsername(), |
||
266 | 'entry' => LogHelper::getLogDescription($entry), |
||
267 | 'time' => $entry->getTimestamp(), |
||
268 | 'canedit' => false, |
||
269 | 'id' => $entry->getId(), |
||
270 | 'comment' => $entryComment, |
||
271 | ); |
||
272 | } |
||
273 | } |
||
274 | } |
||
275 | |||
276 | $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
||
277 | |||
278 | $this->assign("requestLogs", $requestLogs); |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * @param Request $request |
||
283 | */ |
||
284 | protected function setupUsernameData(Request $request) |
||
285 | { |
||
286 | $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
||
287 | |||
288 | $this->assign('requestIsBlacklisted', $blacklistData !== false); |
||
289 | $this->assign('requestBlacklist', $blacklistData); |
||
290 | |||
291 | try { |
||
292 | $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
||
293 | } |
||
294 | catch (Exception $ex) { |
||
295 | $spoofs = $ex->getMessage(); |
||
296 | } |
||
297 | |||
298 | $this->assign("spoofs", $spoofs); |
||
299 | } |
||
300 | |||
301 | private function setupCreationTypes(User $user) |
||
302 | { |
||
303 | $this->assign('allowWelcomeSkip', false); |
||
304 | $this->assign('forceWelcomeSkip', false); |
||
305 | |||
306 | $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
||
307 | |||
308 | if ($user->getWelcomeTemplate() != 0) { |
||
309 | $this->assign('allowWelcomeSkip', true); |
||
310 | |||
311 | if (!$oauth->canWelcome()) { |
||
312 | $this->assign('forceWelcomeSkip', true); |
||
313 | } |
||
314 | } |
||
315 | |||
316 | // test credentials |
||
317 | $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
||
318 | $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
||
319 | $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
||
320 | |||
321 | $this->assign('canManualCreate', $canManualCreate); |
||
322 | $this->assign('canOauthCreate', $canOauthCreate); |
||
323 | $this->assign('canBotCreate', $canBotCreate); |
||
324 | |||
325 | // show/hide the type radio buttons |
||
326 | $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
||
327 | |||
328 | if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
||
329 | // user is not allowed to use their default. Force a choice. |
||
330 | $creationHasChoice = true; |
||
331 | } |
||
332 | |||
333 | $this->assign('creationHasChoice', $creationHasChoice); |
||
334 | |||
335 | // determine problems in creation types |
||
336 | $this->assign('botProblem', false); |
||
337 | if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
||
338 | $this->assign('botProblem', true); |
||
339 | } |
||
340 | |||
341 | $this->assign('oauthProblem', false); |
||
342 | if ($canOauthCreate && !$oauth->canCreateAccount()) { |
||
343 | $this->assign('oauthProblem', true); |
||
344 | } |
||
345 | } |
||
346 | } |
||
347 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths