use wcf\system\exception\UserInputException;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\like\LikeHandler;
+use wcf\system\moderation\queue\ModerationQueueActivationManager;
use wcf\system\user\activity\event\UserActivityEventHandler;
use wcf\system\user\notification\object\type\ICommentUserNotificationObjectType;
use wcf\system\user\notification\object\type\IMultiRecipientCommentUserNotificationObjectType;
]);
$action->executeAction();
}
+ else {
+ // mark comment for moderated content
+ ModerationQueueActivationManager::getInstance()->addModeratedContent('com.woltlab.wcf.comment.comment', $this->createdComment->commentID);
+ }
if (!$this->createdComment->userID) {
// save user name is session
]);
$action->executeAction();
}
+ else {
+ // mark response for moderated content
+ ModerationQueueActivationManager::getInstance()->addModeratedContent('com.woltlab.wcf.comment.response', $this->createdResponse->responseID);
+ }
if (!$this->createdResponse->userID) {
// save user name is session
}
public function enable() {
+ if ($this->comment === null) $this->comment = reset($this->objects);
+
if ($this->comment->isDisabled) {
$action = new CommentAction([$this->comment], 'triggerPublication', [
- 'commentProcessor' => $this->commentProcessor
+ 'commentProcessor' => $this->commentProcessor,
+ 'objectTypeID' => $this->comment->objectTypeID
]);
$action->executeAction();
}
}
public function enableResponse() {
+ if ($this->comment === null) $this->comment = reset($this->objects);
+ if ($this->response === null) $this->response = reset($this->parameters['responses']);
+
if ($this->response->isDisabled) {
$action = new CommentAction([], 'triggerPublicationResponse', [
'commentProcessor' => $this->commentProcessor,
--- /dev/null
+<?php
+namespace wcf\system\moderation\queue;
+use wcf\data\comment\Comment;
+use wcf\data\comment\CommentAction;
+use wcf\data\comment\ViewableComment;
+use wcf\data\moderation\queue\ModerationQueue;
+use wcf\data\moderation\queue\ViewableModerationQueue;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\cache\runtime\CommentRuntimeCache;
+use wcf\system\comment\manager\ICommentManager;
+use wcf\system\WCF;
+
+/**
+ * An abstract implementation of IModerationQueueHandler for comments.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Moderation\Queue
+ */
+class AbstractCommentCommentModerationQueueHandler extends AbstractModerationQueueHandler {
+ /**
+ * @inheritDoc
+ */
+ protected $className = Comment::class;
+
+ /**
+ * @inheritDoc
+ */
+ protected $objectType = 'com.woltlab.wcf.comment.comment';
+
+ /**
+ * list of comment managers
+ * @var ICommentManager[]
+ */
+ protected static $commentManagers = [];
+
+ /**
+ * @inheritDoc
+ */
+ public function assignQueues(array $queues) {
+ $assignments = [];
+
+ // read comments
+ $commentIDs = [];
+ foreach ($queues as $queue) {
+ $commentIDs[] = $queue->objectID;
+ }
+
+ $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
+
+ $orphanedQueueIDs = [];
+ foreach ($queues as $queue) {
+ $assignUser = false;
+
+ if ($comments[$queue->objectID] === null) {
+ $orphanedQueueIDs[] = $queue->queueID;
+ continue;
+ }
+
+ $comment = $comments[$queue->objectID];
+ if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
+ $assignUser = true;
+ }
+
+ $assignments[$queue->queueID] = $assignUser;
+ }
+
+ ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
+ ModerationQueueManager::getInstance()->setAssignment($assignments);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getContainerID($objectID) {
+ return 0;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function isValid($objectID) {
+ if ($this->getComment($objectID) === null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns a comment object by comment id or null if comment id is invalid.
+ *
+ * @param integer $objectID
+ * @return Comment|null
+ */
+ protected function getComment($objectID) {
+ return CommentRuntimeCache::getInstance()->getObject($objectID);
+ }
+
+ /**
+ * Returns a comment manager for given comment.
+ *
+ * @param Comment $comment
+ * @return ICommentManager
+ */
+ protected function getCommentManager(Comment $comment) {
+ if (!isset(self::$commentManagers[$comment->objectTypeID])) {
+ self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
+ }
+
+ return self::$commentManagers[$comment->objectTypeID];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function populate(array $queues) {
+ $objectIDs = [];
+ foreach ($queues as $object) {
+ $objectIDs[] = $object->objectID;
+ }
+
+ // fetch comments
+ $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
+ foreach ($queues as $object) {
+ if ($comments[$object->objectID] !== null) {
+ $object->setAffectedObject($comments[$object->objectID]);
+ }
+ else {
+ $object->setIsOrphaned();
+ }
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function removeContent(ModerationQueue $queue, $message) {
+ if ($this->isValid($queue->objectID)) {
+ $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
+ $commentAction->executeAction();
+ }
+ }
+
+ /**
+ * Returns the parsed template for the target comment.
+ *
+ * @param ViewableModerationQueue $queue
+ * @return string
+ */
+ protected function getRelatedContent(ViewableModerationQueue $queue) {
+ WCF::getTPL()->assign([
+ 'message' => ViewableComment::getComment($queue->objectID)
+ ]);
+
+ return WCF::getTPL()->fetch('moderationComment');
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\moderation\queue;
+use wcf\data\comment\response\CommentResponse;
+use wcf\data\comment\response\CommentResponseAction;
+use wcf\data\comment\response\ViewableCommentResponse;
+use wcf\data\comment\Comment;
+use wcf\data\moderation\queue\ModerationQueue;
+use wcf\data\moderation\queue\ViewableModerationQueue;
+use wcf\system\cache\runtime\CommentResponseRuntimeCache;
+use wcf\system\cache\runtime\CommentRuntimeCache;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\WCF;
+
+/**
+ * An implementation of IModerationQueueHandler for comment responses.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Moderation\Queue
+ */
+class AbstractCommentResponseModerationQueueHandler extends AbstractCommentCommentModerationQueueHandler {
+ /**
+ * @inheritDoc
+ */
+ protected $className = CommentResponse::class;
+
+ /**
+ * @inheritDoc
+ */
+ protected $objectType = 'com.woltlab.wcf.comment.response';
+
+ /**
+ * @inheritDoc
+ */
+ public function assignQueues(array $queues) {
+ $assignments = [];
+
+ // read comments and responses
+ $responseIDs = [];
+ foreach ($queues as $queue) {
+ $responseIDs[] = $queue->objectID;
+ }
+
+ $conditions = new PreparedStatementConditionBuilder();
+ $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
+
+ $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
+ FROM wcf".WCF_N."_comment_response comment_response
+ LEFT JOIN wcf".WCF_N."_comment comment
+ ON (comment.commentID = comment_response.commentID)
+ ".$conditions;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditions->getParameters());
+ $comments = $responses = [];
+ while ($row = $statement->fetchArray()) {
+ $comments[$row['commentID']] = new Comment(null, $row);
+ $responses[$row['responseID']] = new CommentResponse(null, $row);
+ }
+
+ $orphanedQueueIDs = [];
+ foreach ($queues as $queue) {
+ $assignUser = false;
+
+ if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
+ $orphanedQueueIDs[] = $queue->queueID;
+ continue;
+ }
+
+ $comment = $comments[$responses[$queue->objectID]->commentID];
+ if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
+ $assignUser = true;
+ }
+
+ $assignments[$queue->queueID] = $assignUser;
+ }
+
+ ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
+ ModerationQueueManager::getInstance()->setAssignment($assignments);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getRelatedContent(ViewableModerationQueue $queue) {
+ WCF::getTPL()->assign([
+ 'message' => ViewableCommentResponse::getResponse($queue->objectID)
+ ]);
+
+ return WCF::getTPL()->fetch('moderationComment');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function isValid($objectID) {
+ if ($this->getResponse($objectID) === null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns a comment response object by response id or null if response id is invalid.
+ *
+ * @param integer $objectID
+ * @return CommentResponse|null
+ */
+ protected function getResponse($objectID) {
+ return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function populate(array $queues) {
+ $objectIDs = [];
+ foreach ($queues as $object) {
+ $objectIDs[] = $object->objectID;
+ }
+
+ $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
+
+ $commentIDs = [];
+ foreach ($responses as $response) {
+ if ($response !== null) {
+ $commentIDs[] = $response->commentID;
+ }
+ }
+
+ $comments = [];
+ if (!empty($commentIDs)) {
+ $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
+ }
+
+ foreach ($queues as $object) {
+ if ($responses[$object->objectID] !== null) {
+ $response = $responses[$object->objectID];
+ $response->setComment($comments[$response->commentID]);
+
+ $object->setAffectedObject($response);
+ }
+ else {
+ $object->setIsOrphaned();
+ }
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function removeContent(ModerationQueue $queue, $message) {
+ if ($this->isValid($queue->objectID)) {
+ $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
+ $responseAction->executeAction();
+ }
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\moderation\queue\activation;
+use wcf\data\comment\CommentAction;
+use wcf\data\moderation\queue\ModerationQueue;
+use wcf\data\moderation\queue\ViewableModerationQueue;
+use wcf\system\moderation\queue\AbstractCommentCommentModerationQueueHandler;
+
+/**
+ * An implementation of IModerationQueueActivationHandler for comments.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Moderation\Queue
+ */
+class CommentCommentModerationQueueActivationHandler extends AbstractCommentCommentModerationQueueHandler implements IModerationQueueActivationHandler {
+ /**
+ * @inheritDoc
+ */
+ protected $definitionName = 'com.woltlab.wcf.moderation.activation';
+
+ /**
+ * @inheritDoc
+ */
+ public function enableContent(ModerationQueue $queue) {
+ if ($this->isValid($queue->objectID) && $this->getComment($queue->objectID)->isDisabled) {
+ $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'enable');
+ $commentAction->executeAction();
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getDisabledContent(ViewableModerationQueue $queue) {
+ return $this->getRelatedContent($queue);
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\moderation\queue\activation;
+use wcf\data\comment\CommentAction;
+use wcf\data\moderation\queue\ModerationQueue;
+use wcf\data\moderation\queue\ViewableModerationQueue;
+use wcf\system\moderation\queue\AbstractCommentResponseModerationQueueHandler;
+
+/**
+ * An implementation of IModerationQueueReportHandler for comment responses.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Moderation\Queue
+ */
+class CommentResponseModerationQueueActivationHandler extends AbstractCommentResponseModerationQueueHandler implements IModerationQueueActivationHandler {
+ /**
+ * @inheritDoc
+ */
+ public function enableContent(ModerationQueue $queue) {
+ if ($this->isValid($queue->objectID) && $this->getResponse($queue->objectID)->isDisabled) {
+ $response = $this->getResponse($queue->objectID);
+
+ $commentAction = new CommentAction([$this->getComment($response->commentID)], 'enableResponse', [
+ 'responses' => [$response]
+ ]);
+ $commentAction->executeAction();
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getDisabledContent(ViewableModerationQueue $queue) {
+ return $this->getRelatedContent($queue);
+ }
+}
<?php
namespace wcf\system\moderation\queue\report;
-use wcf\data\comment\Comment;
-use wcf\data\comment\CommentAction;
-use wcf\data\comment\ViewableComment;
-use wcf\data\moderation\queue\ModerationQueue;
use wcf\data\moderation\queue\ViewableModerationQueue;
-use wcf\data\object\type\ObjectTypeCache;
-use wcf\system\cache\runtime\CommentRuntimeCache;
-use wcf\system\comment\manager\ICommentManager;
-use wcf\system\moderation\queue\AbstractModerationQueueHandler;
-use wcf\system\moderation\queue\ModerationQueueManager;
-use wcf\system\WCF;
+use wcf\system\moderation\queue\AbstractCommentCommentModerationQueueHandler;
/**
* An implementation of IModerationQueueReportHandler for comments.
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\Moderation\Queue
*/
-class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
- /**
- * @inheritDoc
- */
- protected $className = Comment::class;
-
+class CommentCommentModerationQueueReportHandler extends AbstractCommentCommentModerationQueueHandler implements IModerationQueueReportHandler {
/**
* @inheritDoc
*/
protected $definitionName = 'com.woltlab.wcf.moderation.report';
- /**
- * @inheritDoc
- */
- protected $objectType = 'com.woltlab.wcf.comment.comment';
-
- /**
- * list of comment managers
- * @var ICommentManager[]
- */
- protected static $commentManagers = [];
-
- /**
- * @inheritDoc
- */
- public function assignQueues(array $queues) {
- $assignments = [];
-
- // read comments
- $commentIDs = [];
- foreach ($queues as $queue) {
- $commentIDs[] = $queue->objectID;
- }
-
- $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
-
- $orphanedQueueIDs = [];
- foreach ($queues as $queue) {
- $assignUser = false;
-
- if ($comments[$queue->objectID] === null) {
- $orphanedQueueIDs[] = $queue->queueID;
- continue;
- }
-
- $comment = $comments[$queue->objectID];
- if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
- $assignUser = true;
- }
-
- $assignments[$queue->queueID] = $assignUser;
- }
-
- ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
- ModerationQueueManager::getInstance()->setAssignment($assignments);
- }
-
/**
* @inheritDoc
*/
return true;
}
- /**
- * @inheritDoc
- */
- public function getContainerID($objectID) {
- return 0;
- }
-
/**
* @inheritDoc
*/
public function getReportedContent(ViewableModerationQueue $queue) {
- WCF::getTPL()->assign([
- 'message' => ViewableComment::getComment($queue->objectID)
- ]);
-
- return WCF::getTPL()->fetch('moderationComment');
+ return $this->getRelatedContent($queue);
}
/**
public function getReportedObject($objectID) {
return $this->getComment($objectID);
}
-
- /**
- * @inheritDoc
- */
- public function isValid($objectID) {
- if ($this->getComment($objectID) === null) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Returns a comment object by comment id or null if comment id is invalid.
- *
- * @param integer $objectID
- * @return Comment|null
- */
- protected function getComment($objectID) {
- return CommentRuntimeCache::getInstance()->getObject($objectID);
- }
-
- /**
- * Returns a comment manager for given comment.
- *
- * @param Comment $comment
- * @return ICommentManager
- */
- protected function getCommentManager(Comment $comment) {
- if (!isset(self::$commentManagers[$comment->objectTypeID])) {
- self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
- }
-
- return self::$commentManagers[$comment->objectTypeID];
- }
-
- /**
- * @inheritDoc
- */
- public function populate(array $queues) {
- $objectIDs = [];
- foreach ($queues as $object) {
- $objectIDs[] = $object->objectID;
- }
-
- // fetch comments
- $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
- foreach ($queues as $object) {
- if ($comments[$object->objectID] !== null) {
- $object->setAffectedObject($comments[$object->objectID]);
- }
- else {
- $object->setIsOrphaned();
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- public function removeContent(ModerationQueue $queue, $message) {
- if ($this->isValid($queue->objectID)) {
- $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
- $commentAction->executeAction();
- }
- }
}
<?php
namespace wcf\system\moderation\queue\report;
-use wcf\data\comment\response\CommentResponse;
-use wcf\data\comment\response\CommentResponseAction;
-use wcf\data\comment\response\ViewableCommentResponse;
-use wcf\data\comment\Comment;
-use wcf\data\moderation\queue\ModerationQueue;
use wcf\data\moderation\queue\ViewableModerationQueue;
-use wcf\system\cache\runtime\CommentResponseRuntimeCache;
-use wcf\system\cache\runtime\CommentRuntimeCache;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\moderation\queue\ModerationQueueManager;
-use wcf\system\WCF;
+use wcf\system\moderation\queue\AbstractCommentResponseModerationQueueHandler;
/**
* An implementation of IModerationQueueReportHandler for comment responses.
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\Moderation\Queue
*/
-class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
- /**
- * @inheritDoc
- */
- protected $className = CommentResponse::class;
-
- /**
- * @inheritDoc
- */
- protected $objectType = 'com.woltlab.wcf.comment.response';
-
- /**
- * @inheritDoc
- */
- public function assignQueues(array $queues) {
- $assignments = [];
-
- // read comments and responses
- $responseIDs = [];
- foreach ($queues as $queue) {
- $responseIDs[] = $queue->objectID;
- }
-
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
-
- $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
- FROM wcf".WCF_N."_comment_response comment_response
- LEFT JOIN wcf".WCF_N."_comment comment
- ON (comment.commentID = comment_response.commentID)
- ".$conditions;
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditions->getParameters());
- $comments = $responses = [];
- while ($row = $statement->fetchArray()) {
- $comments[$row['commentID']] = new Comment(null, $row);
- $responses[$row['responseID']] = new CommentResponse(null, $row);
- }
-
- $orphanedQueueIDs = [];
- foreach ($queues as $queue) {
- $assignUser = false;
-
- if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
- $orphanedQueueIDs[] = $queue->queueID;
- continue;
- }
-
- $comment = $comments[$responses[$queue->objectID]->commentID];
- if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
- $assignUser = true;
- }
-
- $assignments[$queue->queueID] = $assignUser;
- }
-
- ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
- ModerationQueueManager::getInstance()->setAssignment($assignments);
- }
-
+class CommentResponseModerationQueueReportHandler extends AbstractCommentResponseModerationQueueHandler implements IModerationQueueReportHandler {
/**
* @inheritDoc
*/
return true;
}
- /**
- * @inheritDoc
- */
- public function getContainerID($objectID) {
- return 0;
- }
-
/**
* @inheritDoc
*/
public function getReportedContent(ViewableModerationQueue $queue) {
- WCF::getTPL()->assign([
- 'message' => ViewableCommentResponse::getResponse($queue->objectID)
- ]);
-
- return WCF::getTPL()->fetch('moderationComment');
+ return $this->getRelatedContent($queue);
}
/**
public function getReportedObject($objectID) {
return $this->getResponse($objectID);
}
-
- /**
- * @inheritDoc
- */
- public function isValid($objectID) {
- if ($this->getResponse($objectID) === null) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Returns a comment response object by response id or null if response id is invalid.
- *
- * @param integer $objectID
- * @return CommentResponse|null
- */
- protected function getResponse($objectID) {
- return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
- }
-
- /**
- * @inheritDoc
- */
- public function populate(array $queues) {
- $objectIDs = [];
- foreach ($queues as $object) {
- $objectIDs[] = $object->objectID;
- }
-
- $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
-
- $commentIDs = [];
- foreach ($responses as $response) {
- if ($response !== null) {
- $commentIDs[] = $response->commentID;
- }
- }
-
- $comments = [];
- if (!empty($commentIDs)) {
- $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
- }
-
- foreach ($queues as $object) {
- if ($responses[$object->objectID] !== null) {
- $response = $responses[$object->objectID];
- $response->setComment($comments[$response->commentID]);
-
- $object->setAffectedObject($response);
- }
- else {
- $object->setIsOrphaned();
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- public function removeContent(ModerationQueue $queue, $message) {
- if ($this->isValid($queue->objectID)) {
- $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
- $responseAction->executeAction();
- }
- }
}