UltrasonicNXT has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184227
Change subject: Add desktop notifications
......................................................................
Add desktop notifications
Also make JS accessible from window, and change chat-mod-image to an absolute
URL, as it should be
Change-Id: I010b7fb9566435e44998b14a6ff86a723f3f5f1e
---
M MediaWikiChat.hooks.php
M MediaWikiChat.js
M MediaWikiChat.php
M SpecialChat.php
M i18n/en.json
M i18n/qqq.json
6 files changed, 117 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiChat
refs/changes/27/184227/1
diff --git a/MediaWikiChat.hooks.php b/MediaWikiChat.hooks.php
index b6a6802..ad67e23 100644
--- a/MediaWikiChat.hooks.php
+++ b/MediaWikiChat.hooks.php
@@ -153,6 +153,27 @@
'section' => 'misc/chat',
);
+ $preferences['chat-notify-mention'] = array(
+ 'type' => 'toggle',
+ 'label-message' => 'tog-chat-notify-mention',
+ 'section' => 'misc/chat',
+ );
+ $preferences['chat-notify-pm'] = array(
+ 'type' => 'toggle',
+ 'label-message' => 'tog-chat-notify-pm',
+ 'section' => 'misc/chat',
+ );
+ $preferences['chat-notify-message'] = array(
+ 'type' => 'toggle',
+ 'label-message' => 'tog-chat-notify-message',
+ 'section' => 'misc/chat',
+ );
+ $preferences['chat-notify-joinleave'] = array(
+ 'type' => 'toggle',
+ 'label-message' => 'tog-chat-notify-joinleave',
+ 'section' => 'misc/chat',
+ );
+
return true;
}
diff --git a/MediaWikiChat.js b/MediaWikiChat.js
index b34dd2c..8b479ef 100644
--- a/MediaWikiChat.js
+++ b/MediaWikiChat.js
@@ -1,5 +1,5 @@
/* global $, mw */
-var MediaWikiChat = {
+window.MediaWikiChat = {
users: [],
amIMod: false,
amI: false,
@@ -283,11 +283,13 @@
var html = '<tr class="mwchat-message">';
var mention = false;
- if ( message.toLowerCase().indexOf( mw.config.get( 'wgUserName'
).toLowerCase() ) != -1 ) {
+ if ( message.toLowerCase().indexOf(
mw.user.getName().toLowerCase() ) != -1 ) {
mention = true;
- MediaWikiChat.flashMention();
+ MediaWikiChat.flashMention( mw.message(
'chat-mentioned-by', user.name).text(), message );
} else {
- MediaWikiChat.flash();
+ if ( userId != mw.user.getId() ) { // don't flash if we
sent the message
+ MediaWikiChat.flash( mw.message(
'chat-message-from', user.name).text(), message );
+ }
}
html += '<td class="mwchat-item-user">';
@@ -352,15 +354,15 @@
html += MediaWikiChat.htmlTimestamp( timestamp );
html += '</div>';
- // Open any link in private messages in a new tab
- var elem = $( html ).appendTo( $( '#' + convwithE + '
.mwchat-useritem-content' ) );
- elem.find( 'a' ).attr( 'target', '_blank' );
+ // Open any link in private messages in a new tab
+ var elem = $( html ).appendTo( $( '#' + convwithE + '
.mwchat-useritem-content' ) );
+ elem.find( 'a' ).attr( 'target', '_blank' );
if ( user.name != mw.config.get( 'wgUserName' ) ) {
$( '#' + convwithE ).attr( 'data-read', 'true' );
}
- MediaWikiChat.flashPrivate();
+ MediaWikiChat.flashPrivate( mw.message(
'chat-private-message-from', user.name).text(), message );
},
greyscale: function( element, microseconds ) {
@@ -512,7 +514,7 @@
MediaWikiChat.addSystemMessage( mw.message( 'chat-left',
user.name, user.gender ).text(), MediaWikiChat.now() );
MediaWikiChat.scrollToBottom();
- MediaWikiChat.flashJoinLeave();
+ MediaWikiChat.flashJoinLeave( mw.message( 'chat-left',
user.name, user.gender ).text());
},
clickUser: function() {
@@ -567,41 +569,53 @@
}
},
- flash: function() {
+ flash: function( title, message ) {
if ( !MediaWikiChat.focussed ) {
- if ( mw.config.get( 'wgChatPingMessages' ) ) {
+ if ( mw.user.options.get( 'chat-ping-message' ) ) {
MediaWikiChat.audio( 'message' );
}
document.title = "* " + MediaWikiChat.title;
+ if ( mw.user.options.get( 'chat-ping-pm' ) ) {
+ MediaWikiChat.notify( title, message );
+ }
}
},
- flashPrivate: function() {
+ flashPrivate: function( title, message ) {
if ( !MediaWikiChat.focussed ) {
- if ( mw.config.get( 'wgChatPingPMs' ) ) {
+ if ( mw.user.options.get( 'chat-ping-pm' ) ) {
MediaWikiChat.audio( 'pm' );
}
document.title = "> " + MediaWikiChat.title;
+ if ( mw.user.options.get( 'chat-ping-pm' ) ) {
+ MediaWikiChat.notify( title, message );
+ }
}
},
- flashMention: function() {
+ flashMention: function( title, message ) {
if ( !MediaWikiChat.focussed ) {
- if ( mw.config.get( 'wgChatPingMentions' ) ) {
+ if ( mw.user.options.get( 'chat-ping-mention' ) ) {
MediaWikiChat.audio( 'mention' );
- } else if ( mw.config.get( 'wgChatPingMessages' ) ) {
// user may want pinging on all msgs, but not mentions
+ } else if ( mw.user.options.get( 'chat-ping-message' )
) { // user may want pinging on all msgs, but not mentions
MediaWikiChat.audio( 'message' );
}
document.title = "! " + MediaWikiChat.title;
+ if ( mw.user.options.get( 'chat-ping-pm' ) ) {
+ MediaWikiChat.notify( title, message );
+ }
}
},
- flashJoinLeave: function() {
+ flashJoinLeave: function( title ) {
if ( !MediaWikiChat.focussed ) {
- if ( mw.config.get( 'wgChatPingJoinLeaves' ) ) {
+ if ( mw.user.options.get( 'chat-ping-joinleave' ) ) {
MediaWikiChat.audio( 'message' );
}
document.title = "+ " + MediaWikiChat.title;
+ if ( mw.user.options.get( 'chat-ping-pm' ) ) {
+ MediaWikiChat.notify( title, '' );
+ }
}
},
@@ -626,6 +640,24 @@
audio.play();
},
+ notify: function( title, message ) {
+ if (!Notification) {
+ return;
+ }
+
+ if (Notification.permission !== "granted")
+ Notification.requestPermission();
+
+ var notification = new Notification( title, {
+ icon: mw.config.get( 'wgCanonicalServer' ) +
'/favicon.ico',
+ body: message
+ } );
+
+ notification.onclick = function () {
+ window.focus();
+ }
+ },
+
restartInterval: function( interval ) {
if ( !interval ) {
interval = MediaWikiChat.interval;
diff --git a/MediaWikiChat.php b/MediaWikiChat.php
index 0f83571..baadc6f 100644
--- a/MediaWikiChat.php
+++ b/MediaWikiChat.php
@@ -16,7 +16,7 @@
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'MediaWikiChat',
- 'version' => '2.12.10',
+ 'version' => '2.13.0',
'author' => 'Adam Carter/UltrasonicNXT',
'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat',
'descriptionmsg' => 'chat-desc',
@@ -39,7 +39,8 @@
'chat-kicked', 'chat-kick', '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-too-long',
- 'chat-idle-minutes', 'chat-idle-hours', 'chat-idle-more',
'chat-today'
+ 'chat-idle-minutes', 'chat-idle-hours', 'chat-idle-more',
'chat-today', 'chat-message-from',
+ 'chat-private-message-from', 'chat-mentioned-by'
),
'dependencies' => 'mediawiki.jqueryMsg',
'localBasePath' => dirname( __FILE__ ),
@@ -106,3 +107,10 @@
$wgRemoveGroups['chatmod'][] = 'blockedfromchat';
$wgAddGroups['sysop'][] = 'blockedfromchat';
$wgRemoveGroups['sysop'][] = 'blockedfromchat';
+
+// Add default preferences
+$wgDefaultUserOptions['chat-ping-mention'] = 1;
+$wgDefaultUserOptions['chat-ping-pm'] = 1;
+$wgDefaultUserOptions['chat-notify-mention'] = 1;
+$wgDefaultUserOptions['chat-notify-message'] = 1;
+$wgDefaultUserOptions['chat-notify-pm'] = 1;
diff --git a/SpecialChat.php b/SpecialChat.php
index 6d1b86c..0b6e8f2 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 $wgChatKicks, $wgChatLinkUsernames, $wgChatMeCommand,
$wgChatMaxMessageLength;
+ global $wgChatKicks, $wgChatLinkUsernames, $wgChatMeCommand,
$wgChatMaxMessageLength, $wgCanonicalServer;
$out = $this->getOutput();
$user = $this->getUser();
@@ -36,11 +36,6 @@
include( 'SpecialChat.template.php' );
$template = new SpecialChatTemplate;
- $mention = $user->getOption( 'chat-ping-mention' );
- $pm = $user->getOption( 'chat-ping-pm' );
- $message = $user->getOption( 'chat-ping-message' );
- $joinleave = $user->getOption( 'chat-ping-joinleave' );
-
// Load modules via ResourceLoader
$modules = array(
'ext.mediawikichat.css',
@@ -53,12 +48,9 @@
'wgChatKicks' => $wgChatKicks,
'wgChatSocialAvatars' => class_exists(
'SocialProfileHooks' ), // has SocialProfile been installed?
'wgChatLinkUsernames' =>
$wgChatLinkUsernames,
- 'wgChatPingMentions' => $mention,
- 'wgChatPingPMs' => $pm,
- 'wgChatPingMessages' => $message,
- 'wgChatPingJoinLeaves' => $joinleave,
'wgChatMeCommand' => $wgChatMeCommand,
'wgChatMaxMessageLength' =>
$wgChatMaxMessageLength,
+ 'wgCanonicalServer' =>
$wgCanonicalServer,
)
);
diff --git a/i18n/en.json b/i18n/en.json
index 15e2041..e94ff1a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -20,6 +20,7 @@
"chat-yesterday": "yesterday",
"chat-kick": "kick",
"chat-block": "block",
+
"chat-youve-been-kicked": "You have been {{GENDER:$2|kicked}} by $1.
Refresh the page to chat.",
"chat-you-kicked": "You {{GENDER:$2|kicked}} $1.",
"chat-kicked": "$1 {{GENDER:$3|kicked}} $2.",
@@ -30,6 +31,7 @@
"chat-unblocked": "$1 {{GENDER:$3|unblocked}} $2.",
"chat-joined": "$1 has {{GENDER:$2|joined}} the chat.",
"chat-left": "$1 has {{GENDER:$2|left}} chat.",
+
"chat-private-message": "click to private message",
"chat-user-is-moderator": "This user {{GENDER:$1|is}} a moderator",
"chat-you-are-moderator": "You {{GENDER:$1|are}} a moderator",
@@ -37,8 +39,9 @@
"chat-change-preferences": "Change your chat preferences (fullscreen and
sounds)",
"chat-sidebar-online": "Online users in chat:",
"chat-sidebar-join": "Join the chat",
- "chat-mod-image": "/extensions/MediaWikiChat/assets/chatmod.png",
+ "chat-mod-image":
"http://192.168.1.78/mediawiki-core/extensions/MediaWikiChat/assets/chatmod.png",
"chat-smileys": "",
+
"log-name-chat": "Chat log",
"log-description-chat": "Messages sent by MediaWikiChat, as well as user
kicks",
"logentry-chat-send": "$1: $4",
@@ -48,6 +51,7 @@
"log-description-privatechat": "Private messages sent by MediaWikiChat",
"logentry-privatechat-send": "$1 to $5: $4",
"log-show-hide-privatechat": "$1 private chat log",
+
"group-chatmod": "Chat moderators",
"group-chatmod-member": "{{GENDER:$1|chat moderator}}",
"grouppage-chatmod": "{{ns:project}}:Chat moderators",
@@ -56,18 +60,26 @@
"grouppage-blockedfromchat": "{{ns:project}}:Users blocked from chat",
"right-mediawikichat-chat": "Use Special:Chat",
"right-mediawikichat-modchat": "Block and kick (if enabled) users from
Special:Chat",
+
"tog-chat-fullscreen": "Use chat in fullscreen mode (experimental)",
"tog-chat-ping-mention": "Play a sound on receiving mentions",
"tog-chat-ping-pm": "Play a sound on receiving private messages",
"tog-chat-ping-message": "Play a sound on receiving normal messages",
"tog-chat-ping-joinleave": "Play a sound when users join or leave the
chat",
"prefs-chat": "Chat",
+ "tog-chat-notify-mention": "Show a notification on receiving mentions
(Chrome & Firefox only)",
+ "tog-chat-notify-pm": "Show a notification receiving private messages
(Chrome & Firefox only)",
+ "tog-chat-notify-message": "Show a notification receiving normal messages
(Chrome & Firefox only)",
+ "tog-chat-notify-joinleave": "Show a notification when users join or leave
the chat (Chrome & Firefox only)",
+
"chat-idle-minutes": "This user has been idle for {{PLURAL:$1|a minute|$1
minutes}}",
"chat-idle-hours": "This user has been idle for {{PLURAL:$1|an hour|$1
hours}}",
"chat-idle-more": "This user has been idle for over 24 hours",
+
"action-chat": "chat with other users",
"action-modchat": "moderate chat",
"action-viewpmlog": "view the private chat messages log",
+
"apihelp-chatgetnew-description": "Get new messages in the chat.",
"apihelp-chatgetnew-param-focussed": "is the chat tab open/focused right
now?",
"apihelp-chatgetnew-example-1": "Get new messages in the chat",
@@ -80,5 +92,9 @@
"apihelp-chatsendpm-description": "Send a private message to a user",
"apihelp-chatsendpm-param-id": "The user ID to send a PM to",
"apihelp-chatsendpm-param-message": "The message to send",
- "apihelp-chatsendpm-example-1": "Send \"Hello World!\" to user with ID 5"
+ "apihelp-chatsendpm-example-1": "Send \"Hello World!\" to user with ID 5",
+
+ "chat-message-from": "Message from $1",
+ "chat-private-message-from": "Private message from $1",
+ "chat-mentioned-by": "Mentioned by $1"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 5eab5c6..c97ccf2 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -23,6 +23,7 @@
"chat-yesterday": "Timestamps: the message was sent
yesterday.\n{{Related|Chat-ago}}\n{{Identical|Yesterday}}",
"chat-kick": "{{Identical|Kick}}",
"chat-block": "The link shown to chatmods to block a
user.\n{{Identical|Block}}",
+
"chat-youve-been-kicked": "Shown to users who have been kicked from the
chat. Parameters:\n* $1 - the user who kicked from the chat\n* $2 - GENDER of
the user who kicked\nSee also:\n* {{msg-mw|Chat-youve-been-blocked}}",
"chat-you-kicked": "Shown when the current user kicked the user $1.
Parameters:\n* $1 - username\n* $2 - GENDER\nSee also:\n*
{{msg-mw|Chat-you-blocked}}\n* {{msg-mw|Chat-you-unblocked}}",
"chat-kicked": "Shown when the user $1 kicked the user $2.
Parameters:\n* $1 - the user who kicked\n* $2 - the user who was kicked\n* $3 -
GENDER of the user who kicked\nSee also:\n* {{msg-mw|Chat-blocked}}\n*
{{msg-mw|Chat-unblocked}}\n{{Identical|Kicked}}",
@@ -33,6 +34,7 @@
"chat-unblocked": "Shown when the user $1 unblocked the user $2.
Parameters:\n* $1 - the user who unblocked\n* $2 - the user who was
unblocked\n* $3 - GENDER of the user who unblocked\nSee also:\n*
{{msg-mw|Chat-kicked}}\n* {{msg-mw|Chat-blocked}}\n{{Identical|Unblocked}}",
"chat-joined": "Shown when the user $1 joined the chat. Parameters:\n*
$1 - the username\n* $2 - GENDER of the user\nSee also:\n*
{{msg-mw|Chat-left}}",
"chat-left": "Shown when the user $1 left the chat. Parameters:\n* $1 -
the username\n* $2 - GENDER of the user\nSee also:\n* {{msg-mw|Chat-joined}}",
+
"chat-private-message": "The link shown to users to private message
another user.\n{{Identical|Private message}}",
"chat-user-is-moderator": "Parameters:\n* $1 - GENDER of the user\nSee
also:\n* {{msg-mw|Chat-you-are-moderator}}",
"chat-you-are-moderator": "Shown when the current user is a moderator.
Parameters:\n* $1 - GENDER of the current user\nSee also:\n*
{{msg-mw|Chat-user-is-moderator}}",
@@ -40,6 +42,7 @@
"chat-change-preferences": "The title of the link taking users to
[[Special:Preferences]] to change their chat preferences.",
"chat-sidebar-online": "The header for the chat unit on the sidebar
that shows online users on chat.\n\nUsed if there are one or more online users,
and followed by usernames.",
"chat-sidebar-join": "A link in the sidebar, below the currently active
users, linking to [[Special:Chat]].\n{{Identical|Join the chat}}",
+
"log-name-chat": "The name of the chat log.\n\nAlso used as page title
in [[Special:Log/chat]].\n\nSee also:\n* {{msg-mw|Chat-topic}}",
"log-description-chat": "Used as description for log in
[[Special:Log/chat]].",
"logentry-chat-send": "The user $1 sent the message $4",
@@ -49,6 +52,7 @@
"log-description-privatechat": "Used as description for log in
[[Special:Log/privatechat]].",
"logentry-privatechat-send": "The user $1 sent the private message $4,
to the user $5.\n\n\n{{logentry}}\nAdditional parameters:\n* $4 - private
message\n* $5 - user\n{{Identical|To}}",
"log-show-hide-privatechat": "For [[Special:Log]].\n\nThis should be
consistent with {{msg-mw|Log-name-privatechat}}.\n\nParameters:\n* $1 -
{{msg-mw|Show}} or {{msg-mw|Hide}}\n{{Related|Log-show-hide}}",
+
"group-chatmod": "{{doc-group|chatmod}}",
"group-chatmod-member": "{{doc-group|forumadmin|member}}",
"grouppage-chatmod": "{{doc-group|chatmod|page}}",
@@ -57,18 +61,25 @@
"grouppage-blockedfromchat": "{{doc-group|blockedfromchat|page}}",
"right-mediawikichat-chat": "{{doc-right|mediawikichat-chat}}",
"right-mediawikichat-modchat": "{{doc-right|mediawikichat-modchat}}",
+
"tog-chat-fullscreen": "Used as checkbox label in
[[Special:Preferences]], for whether to use chat in fullscreen.",
"tog-chat-ping-mention": "Label for checkbox for whether to play a
sound on receiving mentions.\n{{Related|Tog-chat-ping}}",
"tog-chat-ping-pm": "Label for checkbox for whether to play a sound on
receiving private messages.\n{{Related|Tog-chat-ping}}",
"tog-chat-ping-message": "Label for checkbox for whether to play a
sound on recieving messages.\n{{Related|Tog-chat-ping}}",
"tog-chat-ping-joinleave": "Label for checkbox for whether to play a
sound when users join or leave the chat.\n{{Related|Tog-chat-ping}}",
+ "tog-chat-notify-mention": "Label for checkbox for whether to show a
notification on receiving mentions. Will only work on chrome and firefox
browsers",
+ "tog-chat-notify-pm": "Label for checkbox for whether to show a
notification receiving private messages. Will only work on chrome and firefox
browsers",
+ "tog-chat-notify-message": "Label for checkbox for whether to show a
notification receiving normal messages. Will only work on chrome and firefox
browsers",
+ "tog-chat-notify-joinleave": "Label for checkbox for whether to show a
notification when users join or leave the chat. Will only work on chrome and
firefox browsers",
"prefs-chat": "Header for the chat preferences at
[[Special:Preferences]].\n{{Identical|Chat}}",
+
"chat-idle-minutes": "Tooltip for users who have been away for over 10
minutes. Parameters:\n* $1 - the number of minutes\n{{Related|Chat-idle}}",
"chat-idle-hours": "Tooltip for users who have been away for over 1
hour. Parameters:\n* $1 - the number of hours\n{{Related|Chat-idle}}",
"chat-idle-more": "Tooltip for users who have been away for over 24
hours.\n{{Related|Chat-idle}}",
"action-chat": "Description of chat right.\n\n{{Doc-action|chat}}",
"action-modchat": "Description of chatmod
right.\n\n{{Doc-action|modchat}}",
"action-viewpmlog": "Description of right to view private chat
messages.\n\n{{Doc-action|viewpmlog}}",
+
"apihelp-chatgetnew-description":
"{{doc-apihelp-description|chatgetnew}}",
"apihelp-chatgetnew-param-focussed":
"{{doc-apihelp-param|chatgetnew|focussed}}",
"apihelp-chatgetnew-example-1": "{{doc-apihelp-example|chatgetnew}}",
@@ -81,5 +92,9 @@
"apihelp-chatsendpm-description":
"{{doc-apihelp-description|chatsendpm}}",
"apihelp-chatsendpm-param-id": "{{doc-apihelp-param|chatsendpm|id}}",
"apihelp-chatsendpm-param-message":
"{{doc-apihelp-param|chatsendpm|message}}",
- "apihelp-chatsendpm-example-1": "{{doc-apihelp-example|chatsendpm}}"
+ "apihelp-chatsendpm-example-1": "{{doc-apihelp-example|chatsendpm}}",
+
+ "chat-message-from": "Notification for receiving message",
+ "chat-private-message-from": "Notification for receiving private
message",
+ "chat-mentioned-by": "Notification for being mentioned"
}
--
To view, visit https://gerrit.wikimedia.org/r/184227
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I010b7fb9566435e44998b14a6ff86a723f3f5f1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiChat
Gerrit-Branch: master
Gerrit-Owner: UltrasonicNXT <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits