From: Alexander Ebert Date: Sat, 17 Jan 2015 01:07:39 +0000 (+0100) Subject: Applying censorship on comments X-Git-Tag: 2.1.0_Beta_4~85 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d5b193c2e04f1b2e51460348640d1b29db552a18;p=GitHub%2FWoltLab%2FWCF.git Applying censorship on comments --- diff --git a/wcfsetup/install/files/js/WCF.Comment.js b/wcfsetup/install/files/js/WCF.Comment.js index fda684115f..34f02fd2e0 100644 --- a/wcfsetup/install/files/js/WCF.Comment.js +++ b/wcfsetup/install/files/js/WCF.Comment.js @@ -9,7 +9,7 @@ WCF.Comment = { }; * Comment support for WCF * * @author Alexander Ebert - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License */ WCF.Comment.Handler = Class.extend({ @@ -435,7 +435,8 @@ WCF.Comment.Handler = Class.extend({ * @param jQuery input */ _save: function(event, isResponse, input) { - var $input = (event === null) ? input : $(event.currentTarget).prev('textarea'); + var $input = (event === null) ? input : $(event.currentTarget).parent().children('textarea'); + $input.next('small.innerError').remove(); var $value = $.trim($input.val()); // ignore empty comments @@ -472,14 +473,28 @@ WCF.Comment.Handler = Class.extend({ this._proxy.sendRequest(); } else { - this._proxy.setOption('data', { - actionName: $actionName, - className: 'wcf\\data\\comment\\CommentAction', - parameters: { - data: $data - } + new WCF.Action.Proxy({ + autoSend: true, + data: { + actionName: $actionName, + className: 'wcf\\data\\comment\\CommentAction', + parameters: { + data: $data + } + }, + success: $.proxy(this._success, this), + failure: (function(data, jqXHR, textStatus, errorThrown) { + if (data.returnValues && data.returnValues.fieldName) { + if (data.returnValues.fieldName === 'text' && data.returnValues.errorType) { + $('' + data.returnValues.errorType + '').insertAfter($input); + + return false; + } + } + + this._failure(data, jqXHR, textStatus, errorThrown); + }).bind(this) }); - this._proxy.sendRequest(); } }, @@ -806,6 +821,7 @@ WCF.Comment.Handler = Class.extend({ _saveEdit: function(event) { var $input = $(event.currentTarget); if ($input.is('button')) { + $input.prev('small.innerError').remove(); $input = $input.prev('textarea'); } var $message = $.trim($input.val()); @@ -827,14 +843,28 @@ WCF.Comment.Handler = Class.extend({ $data.responseID = $input.data('responseID'); } - this._proxy.setOption('data', { - actionName: 'edit', - className: 'wcf\\data\\comment\\CommentAction', - parameters: { - data: $data - } + new WCF.Action.Proxy({ + autoSend: true, + data: { + actionName: 'edit', + className: 'wcf\\data\\comment\\CommentAction', + parameters: { + data: $data + } + }, + success: $.proxy(this._success, this), + failure: (function(data, jqXHR, textStatus, errorThrown) { + if (data.returnValues && data.returnValues.fieldName) { + if (data.returnValues.fieldName === 'text' && data.returnValues.errorType) { + $('' + data.returnValues.errorType + '').insertAfter($input); + + return false; + } + } + + this._failure(data, jqXHR, textStatus, errorThrown); + }).bind(this) }); - this._proxy.sendRequest(); }, /** diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index 9f36418847..93e496b4ff 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -26,7 +26,7 @@ use wcf\util\UserUtil; * Executes comment-related actions. * * @author Alexander Ebert - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data.comment @@ -678,6 +678,8 @@ class CommentAction extends AbstractDatabaseObjectAction { if (empty($this->parameters['data']['message'])) { throw new UserInputException('message'); } + + CommentHandler::enforceCensorship($this->parameters['data']['message']); } /** diff --git a/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php b/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php index 8863456d64..130d850223 100644 --- a/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php +++ b/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php @@ -8,7 +8,9 @@ use wcf\data\object\type\ObjectTypeCache; use wcf\system\comment\manager\ICommentManager; use wcf\system\exception\NamedUserException; use wcf\system\exception\SystemException; +use wcf\system\exception\UserInputException; use wcf\system\like\LikeHandler; +use wcf\system\message\censorship\Censorship; use wcf\system\user\activity\event\UserActivityEventHandler; use wcf\system\user\notification\UserNotificationHandler; use wcf\system\SingletonFactory; @@ -18,7 +20,7 @@ use wcf\system\WCF; * Provides methods for comment object handling. * * @author Alexander Ebert - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.comment @@ -227,4 +229,19 @@ class CommentHandler extends SingletonFactory { } } } + + /** + * Enforces the censorship. + * + * @param string $text + */ + public static function enforceCensorship($text) { + // search for censored words + if (ENABLE_CENSORSHIP) { + $result = Censorship::getInstance()->test($text); + if ($result) { + throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', array('censoredWords' => $result))); + } + } + } }