Page MenuHomePhabricator

Pressing the block button should open up a pop-up modal in MediaWikiChat
Open, Needs TriagePublic

Description

Originally reported by @lcf119

Currently, pressing the block button links directly to Special:UserRights/username, this should be fixed so a pop-up modal is opened (so you're staying on the same page). This would be convenient since when a chat block is needed, it's usually needed to be done fast.

Event Timeline

SamanthaNguyen moved this task from Backlog to Feedback / Suggestions on the MediaWikiChat board.
SamanthaNguyen moved this task from Backlog to MediaWikiChat on the Brickimedia board.

Would this actually be possible?

@UltrasonicNXT Why wouldn't it be? Here's my old and untested patch:

diff --git a/MediaWikiChat.js b/MediaWikiChat.js
index 3ee281b..d08d0ed 100644
--- a/MediaWikiChat.js
+++ b/MediaWikiChat.js
@@ -489,7 +489,7 @@ var MediaWikiChat = {
 		html += '</div><span class="mwchat-useritem-header-links">';
 
 		if ( MediaWikiChat.amIMod && ( !user.mod ) ) {
-			html += '<a class="mwchat-useritem-blocklink" href="' + mw.util.getUrl( 'Special:UserRights', { user: user.name } );
+			html += '<a class="mwchat-useritem-blocklink" href="#" data-user-name="' + mw.html.escape( user.name );
 			html += '" target="_blank">' + mw.message( 'chat-block' ).text() + '</a>';
 
 			if ( mw.config.get( 'wgChatKicks' ) ) {
@@ -719,6 +719,47 @@ var MediaWikiChat = {
 $( document ).ready( function() {
 	MediaWikiChat.loadingBackground();
 
+	// Chat mods' "block user" links; clicking on such a link opens up a dialog
+	// for supplying the block reason and pressing the button POSTs a request
+	// to the userrights API, so the chat mod doesn't have to leave the chat
+	// page in order to block a misbehaving user
+	$( 'body' ).on( 'click', '.mwchat-useritem-blocklink', function( e ) {
+		e.preventDefault();
+
+		var user = $( this ).data( 'user-name' );
+		var submitBtn = mw.msg( 'chat-submit-btn' );
+		var cancelBtn = mw.msg( 'cancel' );
+		$(
+			'<div class="mediawikichat-block-dialog">' +
+			mw.msg( 'chat-block-dialog-message', user ) +
+			'<br /><input type="text" id="mediawikichat-block-reason-input" /></div>'
+		).dialog( {
+			buttons: {
+				submitBtn: function() {
+					( new mw.Api() ).postWithToken( 'edit', {
+						action: 'userrights',
+						format: 'json',
+						user: user,
+						add: 'blockedfromchat',
+						reason: $( '#mediawikichat-block-reason-input' ).text()
+					} );
+					$( this ).dialog( 'close' );
+				},
+				cancelBtn: function() {
+					$( this ).dialog( 'close' );
+					return;
+				}
+			},
+			hide: 'slide',
+			minWidth: 250,
+			modal: true,
+			resizable: true,
+			show: 'slide',
+			title: mw.msg( 'chat-block-dialog-title' ),
+			zIndex: 1501
+		} );
+	} );
+
 	$( $( '#mwchat-type input' )[0] ).keydown( function( e ) { // Send text
 		MediaWikiChat.clearMentions();
 
diff --git a/extension.json b/extension.json
index 5528da6..eb416c8 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
 	"name": "MediaWikiChat",
-	"version": "2.17",
+	"version": "2.18",
 	"author": [
 		"Adam Carter/UltrasonicNXT"
 	],
@@ -96,9 +96,10 @@
 				"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-message-from",
-				"chat-private-message-from", "chat-mentioned-by"
+				"chat-private-message-from", "chat-mentioned-by", "cancel", "chat-submit-btn",
+				"chat-block-dialog-title", "chat-block-dialog-message"
 			],
-			"dependencies": [ "mediawiki.jqueryMsg", "mediawiki.user", "mediawiki.util" ],
+			"dependencies": [ "mediawiki.jqueryMsg", "mediawiki.api", "mediawiki.user", "mediawiki.util", "jquery.ui.dialog" ],
 			"position": "bottom"
 		}
 	},
diff --git a/i18n/en.json b/i18n/en.json
index 5e93906..fb197ce 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -21,6 +21,9 @@
 	"chat-kick": "kick",
 	"chat-block": "block",
 	"chat-autoscroll": "autoscroll",
+	"chat-submit-btn": "Submit",
+	"chat-block-dialog-title": "Block user",
+	"chat-block-dialog-message": "Please supply a reason for blocking $1",
 
 	"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.",

The extension.json part currently fails to apply, most likely due to the version number change, but other than that, I'd imagine it applies relatively cleanly. I haven't tested it, hence why I never committed this to gerrit. It's also worth noting that jQuery UI is slowly being deprecated in favor of OOjs UI, but I don't know how to use that, hence why this still uses jQuery UI's dialog widget.

Change 333503 had a related patch set uploaded (by SamanthaNguyen):
[WIP] v2.20.2 - open up a prompt dialog when pressing block

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

SamanthaNguyen changed the task status from Open to Stalled.EditedFeb 13 2017, 12:24 AM

Somewhat stalled-ish and blocked by T106999. This ticket's goal is to have the block action in MediaWikiChat to open up a prompt dialog which calls the block API and requires adding 4 fields which are a custom reason field, field dropdown, custom expiry time, and expiry dropdown.

Technically, we don't need dropdowns and just let chat administrators/moderators enter their own reason and time, but having them would make blocking much faster and easier for when such a tool is called for. (e.g a user has been disrupting despite continuous warnings, so a prompt dialog would allow a moderator to quickly block without having to wait for a new page to load)

...And also blocked by T107039 because MediaWikiChat allows the option for anons to join chat by giving the chat permission to anons. The configuration setup in LocalSettings.php for such a thing would be:

LocalSettings.php
$wgGroupPermissions['*']['chat'] = true;
SamanthaNguyen changed the task status from Stalled to Open.Oct 2 2017, 11:02 AM

No longer stalled - both tasks blocking this are now resolved. Will pick up the patch again

Change 333503 abandoned by SamanthaNguyen:
[WIP] v2.20.2 - open up a prompt dialog when pressing block

Reason:
Currently not working on any social tool extensions.

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

SamanthaNguyen removed SamanthaNguyen as the assignee of this task.Jun 30 2018, 8:48 PM
SamanthaNguyen removed a project: Patch-For-Review.