Properly handle UserIdentity objects in createUserLinks and ensure CIDR blocks appear on blocked messages
Fixes #47
This commit is contained in:
+12
-2
@@ -224,7 +224,12 @@ class DiscordHooks {
|
||||
$expiryMsg = $expiry;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTargetUserIdentity() ),
|
||||
$target = $block->getTargetUserIdentity();
|
||||
if ( $target === null ) {
|
||||
$target = $block->getTargetName();
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $target ),
|
||||
( $block->getReasonComment()->text ? ('`' . DiscordUtils::sanitiseText( DiscordUtils::truncateText( $block->getReasonComment()->text ) ) . '`' ) : '' ),
|
||||
$expiryMsg )->plain();
|
||||
DiscordUtils::handleDiscord($hookName, $msg);
|
||||
@@ -242,7 +247,12 @@ class DiscordHooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-unblockusercomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTargetUserIdentity() ) )->text();
|
||||
$target = $block->getTargetUserIdentity();
|
||||
if ( $target === null ) {
|
||||
$target = $block->getTargetName();
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-unblockusercomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $target ) )->text();
|
||||
DiscordUtils::handleDiscord($hookName, $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
|
||||
class DiscordUtils {
|
||||
/**
|
||||
@@ -161,9 +162,14 @@ class DiscordUtils {
|
||||
/**
|
||||
* Creates links for a specific MediaWiki User object
|
||||
*/
|
||||
public static function createUserLinks ($user) {
|
||||
public static function createUserLinks ( $user ) {
|
||||
global $wgDiscordMaxCharsUsernames;
|
||||
|
||||
if ( $user instanceof UserIdentity ) {
|
||||
// If we were passed a UserIdentity object, get the relevant user.
|
||||
$user = MediaWikiServices::getInstance()->getUserFactory()->newFromUserIdentity($user);
|
||||
}
|
||||
|
||||
if ( $user instanceof User ) {
|
||||
$isAnon = $user->isAnon();
|
||||
$contribs = Title::newFromText("Special:Contributions/" . $user);
|
||||
@@ -181,8 +187,7 @@ class DiscordUtils {
|
||||
$userContribs = DiscordUtils::createMarkdownLink( wfMessage( 'discord-contribs' )->text(), $contribs->getFullURL( '', false, PROTO_CANONICAL ) );
|
||||
$text = wfMessage( 'discord-userlinks', $userPage, $userTalk, $userContribs )->text();
|
||||
} else {
|
||||
// If it's a string, which can be likely (for example when range blocking a user)
|
||||
// We need to handle this differently.
|
||||
// If we were given a string, handle this differently.
|
||||
$text = wfMessage( 'discord-userlinks', $user, 'n/a', 'n/a' )->text();
|
||||
}
|
||||
return $text;
|
||||
|
||||
Reference in New Issue
Block a user