<commit_before><?php
namespace wcf\system\comment\manager;
use wcf\data\comment\response\CommentResponse;
use wcf\data\comment\Comment;
use wcf\system\SingletonFactory;
use wcf\system\WCF;

/**
 * Default implementation for comment managers.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Comment\Manager
 */
abstract class AbstractCommentManager extends SingletonFactory implements ICommentManager {
	/**
	 * display comments per page
	 * @var	integer
	 */
	public $commentsPerPage = 30;
	
	/**
	 * permission name for comment/response creation
	 * @var	string
	 */
	protected $permissionAdd = '';
	
	/**
	 * permission name for comment/response creation without approval
	 * @var string
	 */
	protected $permissionAddWithoutModeration = '';
	
	/**
	 * permission name for comment/response moderation
	 * @var	string
	 */
	protected $permissionCanModerate = '';
	
	/**
	 * permission name for deletion of own comments/responses
	 * @var	string
	 */
	protected $permissionDelete = '';
	
	/**
	 * permission name for editing of own comments/responses
	 * @var	string
	 */
	protected $permissionEdit = '';
	
	/**
	 * permission name for deletion of comments/responses (moderator)
	 * @var	string
	 */
	protected $permissionModDelete = '';
	
	/**
	 * permission name for editing of comments/responses (moderator)
	 * @var	string
	 */
	protected $permissionModEdit = '';
	
	/**
	 * @inheritDoc
	 */
	public function canAdd($objectID) {
		if (!VISITOR_USE_TINY_BUILD && !WCF::getUser()->userID) {
			return false;
		}
		
		if (!$this->isAccessible($objectID, true)) {
			return false;
		}
		
		return (WCF::getSession()->getPermission($this->permissionAdd) ? true : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function canAddWithoutApproval($objectID) {
		if (!VISITOR_USE_TINY_BUILD && !WCF::getUser()->userID) {
			return false;
		}
		
		if (empty($this->permissionAddWithoutModeration)) {
			return false;
		}
		
		return (WCF::getSession()->getPermission($this->permissionAddWithoutModeration) ? true : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function canEditComment(Comment $comment) {
		return $this->canEdit($comment->userID == WCF::getUser()->userID);
	}
	<commit_msg>Improved behavior for missing comment approval permission<commit_after><?php
namespace wcf\system\comment\manager;
use wcf\data\comment\response\CommentResponse;
use wcf\data\comment\Comment;
use wcf\system\SingletonFactory;
use wcf\system\WCF;

/**
 * Default implementation for comment managers.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Comment\Manager
 */
abstract class AbstractCommentManager extends SingletonFactory implements ICommentManager {
	/**
	 * display comments per page
	 * @var	integer
	 */
	public $commentsPerPage = 30;
	
	/**
	 * permission name for comment/response creation
	 * @var	string
	 */
	protected $permissionAdd = '';
	
	/**
	 * permission name for comment/response creation without approval
	 * @var string
	 */
	protected $permissionAddWithoutModeration = '';
	
	/**
	 * permission name for comment/response moderation
	 * @var	string
	 */
	protected $permissionCanModerate = '';
	
	/**
	 * permission name for deletion of own comments/responses
	 * @var	string
	 */
	protected $permissionDelete = '';
	
	/**
	 * permission name for editing of own comments/responses
	 * @var	string
	 */
	protected $permissionEdit = '';
	
	/**
	 * permission name for deletion of comments/responses (moderator)
	 * @var	string
	 */
	protected $permissionModDelete = '';
	
	/**
	 * permission name for editing of comments/responses (moderator)
	 * @var	string
	 */
	protected $permissionModEdit = '';
	
	/**
	 * @inheritDoc
	 */
	public function canAdd($objectID) {
		if (!VISITOR_USE_TINY_BUILD && !WCF::getUser()->userID) {
			return false;
		}
		
		if (!$this->isAccessible($objectID, true)) {
			return false;
		}
		
		return (WCF::getSession()->getPermission($this->permissionAdd) ? true : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function canAddWithoutApproval($objectID) {
		if (!VISITOR_USE_TINY_BUILD && !WCF::getUser()->userID) {
			return false;
		}
		
		if (empty($this->permissionAddWithoutModeration)) {
			if (ENABLE_DEBUG_MODE) {
				throw new \RuntimeException("Missing permission name to create comments without approval.");
			}
			
			// backwards-compatibility in production mode
			return true;
		}
		
		return (WCF::getSession()->getPermission($this->permissionAddWithoutModeration) ? true : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function canEditComment(Comment $comment) {
		return $this->canEdit($comment->userID == WCF::getUser()->userID);
	}
	
{'fraction_non_alphanumeric': 0.12956129561295612, 'fraction_numerical': 0.004100041000410004, 'mean_word_length': 3.849900596421471, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1796967', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1410, 'n_words': 348}