UltrasonicNXT has submitted this change and it was merged.

Change subject: Add max message length
......................................................................


Add max message length

Via $wgChatMaxMessageLength

Change-Id: I959dee1b9718d137300c765f2859110722978a42
---
M MediaWikiChat.i18n.php
M MediaWikiChat.js
M MediaWikiChat.php
M Send.api.php
M SpecialChat.php
5 files changed, 23 insertions(+), 9 deletions(-)

Approvals:
  UltrasonicNXT: Verified; Looks good to me, approved



diff --git a/MediaWikiChat.i18n.php b/MediaWikiChat.i18n.php
index 234e77a..cd1cce8 100644
--- a/MediaWikiChat.i18n.php
+++ b/MediaWikiChat.i18n.php
@@ -21,6 +21,7 @@
        'chat-not-allowed' => 'You are not allowed to chat, try logging in 
first.',
        'chat-sounds' => 'Play sounds',
        'chat-flood' => 'You can\'t send messages that fast, please wait before 
sending more.',
+       'chat-too-long' => 'That message was too long, please send a shorter 
message.',
 
        'chat-just-now' => 'just now',
        'chat-a-minute-ago' => 'a minute ago',
@@ -205,6 +206,7 @@
 {{Related|Tog-chat-ping}}',
        'prefs-chat' => 'Header for the chat preferences at 
[[Special:Preferences]].
 {{Identical|Chat}}',
+       'chat-too-long' => 'Shown to users when their message was too long to 
send.',
 );
 
 /** Bengali (বাংলা)
diff --git a/MediaWikiChat.js b/MediaWikiChat.js
index a1bbe94..2351bbf 100644
--- a/MediaWikiChat.js
+++ b/MediaWikiChat.js
@@ -547,15 +547,21 @@
        $( $( '#mwchat-type input' )[0] ).keydown( function( e ) { // Send text
                MediaWikiChat.clearMentions();
 
-               var userInput = $( '#mwchat-type input' )[0].value;
+               var message = $( '#mwchat-type input' )[0].value;
 
                if ( e.which == 13 && e.shiftKey ) {
                        return false;
                } else if ( e.which == 13 ) { // Enter
+                       if ( message.length > mw.config.get( 
'wgChatMaxMessageLength' ) ) {
+                               alert( mw.message( 'chat-too-long' ).text() );
+                       } else {
+                               $( '#mwchat-type input' ).val( '' );
+                       }
+
                        $.ajax( {
                                type: 'POST',
                                url: mw.config.get( 'wgScriptPath' ) + 
'/api.php',
-                               data: { 'action': 'chatsend', 'message': $( 
'#mwchat-type input' )[0].value, 'format': 'json' }
+                               data: { 'action': 'chatsend', 'message': 
message, 'format': 'json' }
                        } ).done( function( msg ) {
                                MediaWikiChat.getNew();
                                window.clearInterval( MediaWikiChat.newInterval 
);
@@ -563,13 +569,12 @@
 
                                // Error: flood
                                if ( msg.chatsend.error == 'flood' ) {
-                                       $( '#mwchat-type input' )[0].value = 
userInput;
+                                       $( '#mwchat-type input' ).val( message 
);
                                        alert( mw.message( 'chat-flood' 
).text() );
                                }
 
                        } );
 
-                       $( '#mwchat-type input' ).val( '' );
                } else if ( e.which == 9 ) { // Tab - autocompletion
                        for ( var userId in MediaWikiChat.userData ) {
                                if ( userId != mw.config.get( 'wgUserId' ) ) {
diff --git a/MediaWikiChat.php b/MediaWikiChat.php
index 980bbc7..e568e63 100644
--- a/MediaWikiChat.php
+++ b/MediaWikiChat.php
@@ -17,7 +17,7 @@
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'MediaWikiChat',
-       'version' => '2.6.3',
+       'version' => '2.6.4',
        'author' => 'Adam Carter/UltrasonicNXT',
        'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat',
        'descriptionmsg' => 'chat-desc',
@@ -44,7 +44,7 @@
                'chat-youve-been-blocked', 'chat-you-blocked', 'chat-blocked',
                'chat-block', 'chat-private-message', 'chat-user-is-moderator',
                'chat-you-are-moderator', 'chat-joined', 'chat-left',
-               'chat-mod-image', 'chat-yesterday', 'chat-flood',
+               'chat-mod-image', 'chat-yesterday', 'chat-flood', 
'chat-too-long',
        ),
        'dependencies' => 'mediawiki.jqueryMsg',
        'localBasePath' => dirname( __FILE__ ),
@@ -70,6 +70,7 @@
 $wgChatLinkUsernames = false; // link to user pages?
 $wgChatMeCommand = false; // enable "/me <text>" command?
 $wgChatUseStyleAttribute = true; // allow use of the style attribute on html 
tags?
+$wgChatMaxMessageLength = 1000; // maximum length (characters) of messages
 
 // Hooks
 $wgHooks['ParserBeforeInternalParse'][] = 
'MediaWikiChatHooks::onParserBeforeInternalParse';
diff --git a/Send.api.php b/Send.api.php
index e9afcfd..fd07d3e 100644
--- a/Send.api.php
+++ b/Send.api.php
@@ -3,7 +3,7 @@
 class ChatSendAPI extends ApiBase {
 
        public function execute() {
-               global $wgUser, $wgChatFloodMessages, $wgChatFloodSeconds;
+               global $wgUser, $wgChatFloodMessages, $wgChatFloodSeconds, 
$wgChatMaxMessageLength;
 
                $result = $this->getResult();
                $originalMessage = $this->getMain()->getVal( 'message' );
@@ -17,6 +17,11 @@
                                $id = $wgUser->getId();
                                $timestamp = MediaWikiChat::now();
 
+                               if ( strlen( $message ) > 
$wgChatMaxMessageLength ) {
+                                       $result->addValue( 
$this->getModuleName(), 'error', 'length' );
+                                       return true;
+                               }
+
                                // Flood check
                                $res = $dbw->selectField(
                                        'chat',
diff --git a/SpecialChat.php b/SpecialChat.php
index f5c1f20..d2bf565 100644
--- a/SpecialChat.php
+++ b/SpecialChat.php
@@ -15,7 +15,7 @@
         * @param $par Mixed: parameter passed to the special page or null
         */
        public function execute( $par ) {
-               global $wgChatSocialAvatars, $wgChatKicks, 
$wgChatLinkUsernames, $wgChatMeCommand;
+               global $wgChatSocialAvatars, $wgChatKicks, 
$wgChatLinkUsernames, $wgChatMeCommand, $wgChatMaxMessageLength;
 
                $out = $this->getOutput();
                $user = $this->getUser();
@@ -51,7 +51,8 @@
                                        'wgChatPingMentions' => $mention,
                                        'wgChatPingPMs' => $pm,
                                        'wgChatPingMessages' => $message,
-                                       'wgChatMeCommand' => $wgChatMeCommand
+                                       'wgChatMeCommand' => $wgChatMeCommand,
+                                       'wgChatMaxMessageLength' => 
$wgChatMaxMessageLength,
                                )
                        );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/114452
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I959dee1b9718d137300c765f2859110722978a42
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiChat
Gerrit-Branch: master
Gerrit-Owner: UltrasonicNXT <adamr_car...@btinternet.com>
Gerrit-Reviewer: UltrasonicNXT <adamr_car...@btinternet.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to