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