|
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 Waca\DataObjects\Comment; |
|
12
|
|
|
use Waca\DataObjects\Request; |
|
13
|
|
|
use Waca\DataObjects\User; |
|
14
|
|
|
use Waca\Exceptions\AccessDeniedException; |
|
15
|
|
|
use Waca\Exceptions\ApplicationLogicException; |
|
16
|
|
|
use Waca\Helpers\Logger; |
|
17
|
|
|
use Waca\Tasks\InternalPageBase; |
|
18
|
|
|
use Waca\WebRequest; |
|
19
|
|
|
|
|
20
|
|
|
class PageFlagComment extends InternalPageBase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritDoc |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function main() |
|
26
|
|
|
{ |
|
27
|
|
|
if (!WebRequest::wasPosted()) { |
|
28
|
|
|
throw new ApplicationLogicException('This page does not support GET methods.'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->validateCSRFToken(); |
|
32
|
|
|
|
|
33
|
|
|
$flagState = WebRequest::postInt('flag'); |
|
34
|
|
|
$commentId = WebRequest::postInt('comment'); |
|
35
|
|
|
$updateVersion = WebRequest::postInt('updateversion'); |
|
36
|
|
|
|
|
37
|
|
|
if ($flagState !== 0 && $flagState !== 1) { |
|
38
|
|
|
throw new ApplicationLogicException('Flag status not valid'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$database = $this->getDatabase(); |
|
42
|
|
|
|
|
43
|
|
|
/** @var Comment|false $comment */ |
|
44
|
|
|
$comment = Comment::getById($commentId, $database); |
|
45
|
|
|
if ($comment === false) { |
|
|
|
|
|
|
46
|
|
|
throw new ApplicationLogicException('Unknown comment'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$currentUser = User::getCurrent($database); |
|
50
|
|
|
|
|
51
|
|
|
if ($comment->getFlagged() && !$this->barrierTest('unflag', $currentUser)) { |
|
52
|
|
|
// user isn't allowed to unflag comments |
|
53
|
|
|
throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** @var Request $request */ |
|
57
|
|
|
$request = Request::getById($comment->getRequest(), $database); |
|
58
|
|
|
|
|
59
|
|
|
if ($comment->getFlagged() |
|
60
|
|
|
&& !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData') |
|
61
|
|
|
&& $request->getReserved() !== $currentUser->getId() |
|
62
|
|
|
) { |
|
63
|
|
|
// can't unflag if you can't see it. |
|
64
|
|
|
throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$comment->setFlagged($flagState == 1); |
|
68
|
|
|
$comment->setUpdateVersion($updateVersion); |
|
69
|
|
|
$comment->save(); |
|
70
|
|
|
|
|
71
|
|
|
if ($flagState === 1) { |
|
72
|
|
|
Logger::flaggedComment($database, $comment, $request->getDomain()); |
|
73
|
|
|
} |
|
74
|
|
|
else { |
|
75
|
|
|
Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (WebRequest::postString('return') == 'list') { |
|
79
|
|
|
$this->redirect('flaggedComments'); |
|
80
|
|
|
} |
|
81
|
|
|
else { |
|
82
|
|
|
$this->redirect('viewRequest', null, ['id' => $comment->getRequest()]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |