Applying censorship on comments
authorAlexander Ebert <ebert@woltlab.com>
Sat, 17 Jan 2015 01:07:39 +0000 (02:07 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 17 Jan 2015 01:07:39 +0000 (02:07 +0100)
wcfsetup/install/files/js/WCF.Comment.js
wcfsetup/install/files/lib/data/comment/CommentAction.class.php
wcfsetup/install/files/lib/system/comment/CommentHandler.class.php

index fda684115fb19205bb2797c5ead4edfc2dcfc2f9..34f02fd2e0c7b497b99a3727278639315f8ef2c7 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  */
 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) {
+                                                       $('<small class="innerError">' + data.returnValues.errorType + '</small>').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) {
+                                               $('<small class="innerError">' + data.returnValues.errorType + '</small>').insertAfter($input);
+                                               
+                                               return false;
+                                       }
+                               }
+                               
+                               this._failure(data, jqXHR, textStatus, errorThrown);
+                       }).bind(this)
                });
-               this._proxy.sendRequest();
        },
        
        /**
index 9f36418847edda4879142817c4ca9a0484429de9..93e496b4ff601b17dd41bae5597f6339ac3ac62b 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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']);
        }
        
        /**
index 8863456d64df39ccc35891c57df63334ce310e6e..130d85022306af311ea8ba612bdc43bfcee1a538 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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)));
+                       }
+               }
+       }
 }