Dereckson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108331


Change subject: Improve UTF-8 and links support
......................................................................

Improve UTF-8 and links support

Bug: 60227
Change-Id: I163ae628f0e903c9bcd16b9a9d3155d759d9a213
---
M TweetANew.body.php
1 file changed, 8 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TweetANew 
refs/changes/31/108331/1

diff --git a/TweetANew.body.php b/TweetANew.body.php
index 4f52685..791385c 100644
--- a/TweetANew.body.php
+++ b/TweetANew.body.php
@@ -231,17 +231,19 @@
         */
        public static function makeSendTweet( $tweet_text, $finalurl ) {
                global $wgTweetANewTwitter, $wgLang;
-               
-               # Calculate length of tweet factoring in longURL
-               if ( strlen( $finalurl ) > 20 ) {
-                       $tweet_text_count = ( strlen( $finalurl ) - 20 ) + 140;
+
+        # Calculate length of tweet factoring in t.co
+        if ( stripos( $finalurl, 'https:' ) !== false ) {
+            $tweet_text_count = 140 - 23 + mb_strlen( $finalurl );
+        } elseif ( stripos( $finalurl, 'http:' ) !== false ) {
+            $tweet_text_count = 140 - 22 + mb_strlen( $finalurl );
                } else {
                        $tweet_text_count = 140;
                }
 
                # Check if length of tweet is beyond 140 characters and shorten 
if necessary
-               if ( strlen( $tweet_text ) > $tweet_text_count ) {
-                       $tweet_text = $wgLang->truncate( $tweet_text, 
$tweet_text_count );
+               if ( mb_strlen( $tweet_text ) > $tweet_text_count ) {
+                       $tweet_text = mb_substr( $tweet_text, 0, 
$tweet_text_count - 3 )  . '...';
                }
 
                # Make connection to Twitter

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I163ae628f0e903c9bcd16b9a9d3155d759d9a213
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TweetANew
Gerrit-Branch: master
Gerrit-Owner: Dereckson <dereck...@espace-win.org>

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

Reply via email to