Compare commits

..

18 Commits

Author SHA1 Message Date
Jayden Bailey e000672074 [backport] Do not parse any Discord mentions in webhook messages
Resolves #42, closes #41
2022-04-18 21:14:56 +01:00
Jayden Bailey 6b9222a6df Merge branch 'master' into REL1_35 2021-10-19 14:21:00 +01:00
Jayden Bailey 0a6992b13b Update README 2021-10-19 14:20:41 +01:00
Jayden Bailey 925ca2c17c Remove composer.json. I don't use unit tests here. 2021-10-19 14:12:19 +01:00
Jayden Bailey 95567934b0 Remove composer.json. I don't use unit tests here. 2021-10-19 14:06:10 +01:00
Jayden 5e04b3afda Merge pull request #36 from dodocodes/patch-2
Update README.md
2021-09-14 02:55:52 +01:00
Jayden 91610c72fd Update README.md 2021-09-14 02:55:40 +01:00
Jayden f1cae6b097 Merge pull request #35 from DesignerThan95/patch-1
Update extension.json - added missing colon
2021-09-14 02:55:08 +01:00
DodoCodes.com 1a9cbbf48f Update README.md
Added instructions for installing missing dependencies.
2021-09-12 18:16:38 -07:00
DesignerThan df0b14017b Update extension.json - added missing colon 2021-08-17 23:38:05 +02:00
Jayden Bailey ffc78324ff Fix bug with preg_replace for username truncating and change truncation to be configurable 2021-05-04 17:27:34 +01:00
Jayden Bailey 5a303252e3 Merge branch 'master' of github.com:jaydenkieran/mw-discord 2021-05-04 17:02:24 +01:00
Jayden Bailey 4ec63619f5 Change emojis to be configurable (resolves #25) 2021-05-04 17:00:55 +01:00
Jayden Bailey 572d9e3d87 Sanitise summary/reason text input (closes #13) 2021-05-04 17:00:47 +01:00
Jayden Bailey 3eb34310ef Merge pull request #33 from Joeytje50/patch-1
Abbreviate anyone with a name longer than 25 chars
2021-05-04 16:08:34 +01:00
Joeytje50 7c20f06902 Abbreviate anyone with a name longer than 25 chars
Any username of 25 or more characters will be abbreviated to the first 20 characters, then `...`, and then the last three. This is especially helpful for RC stalkers with discord taking up only half their screen.

Different ways to abbreviate names would be possible by changing the regex pattern's numbers, or the resulting string.
2021-04-23 17:13:11 +02:00
Jayden Bailey 144499a248 Update README with branch/install info 2020-09-18 14:58:28 +01:00
Jayden Bailey 079e688ee9 Fix fatal error when blocking users
Fixes #27, closes #29
2020-09-18 14:51:07 +01:00
4 changed files with 27 additions and 24 deletions
+3 -5
View File
@@ -1,5 +1,3 @@
> ⚠️ **This branch is no longer maintained.** MediaWiki 1.31 went End-of-Life in September 2021.
# Discord (mw-discord)
MediaWiki extension for sending notifications to a Discord webhook from MediaWiki. When a certain event occurs on your MediaWiki wiki, including new edits, they can be sent as a message to a channel on a Discord server using a webhook.
@@ -13,14 +11,14 @@ Multiple webhook URLs are supported and messages will be sent to all of them.
## Requirements
- **Discord webhook URL**: This can be obtained by editing a channel on a server with the correct permissions.
- **MediaWiki 1.31+**
- **MediaWiki 1.35+**. This extension aims to support the latest LTS release.
### Recommended
- **cURL**: By default, this extension sends requests using cURL. If you don't have cURL, you could try setting `$wgDiscordUseFileGetContents` to `true` instead, but this is not recommended.
## Installation
1. Clone this repository to your MediaWiki installation's `extensions` folder using `git clone https://github.com/jaydenkieran/mw-discord.git Discord`
1. Clone this repository to your MediaWiki installation's `extensions` folder using `git clone https://github.com/jaydenkieran/mw-discord.git -b REL1_35 Discord`
2. Modify your `LocalSettings.php` file and add:
```php
@@ -88,4 +86,4 @@ This extension can be translated through the messages in the `ì18n` folder if y
Any excess whitespace in text that is translated will be stripped (e.g double spaces, etc).
## License
This extension is licensed under the MIT License, [see here](LICENSE) for more information. This project is originally inspired by Szmyk's [mediawiki-discord](https://github.com/Szmyk/mediawiki-discord) project, but has been rewritten completely to be more suitable for my needs.
This extension is licensed under the MIT License, [see here](LICENSE) for more information. This project is originally inspired by Szmyk's [mediawiki-discord](https://github.com/Szmyk/mediawiki-discord) project, but has been rewritten completely to be more suitable for my needs.
+1 -1
View File
@@ -38,7 +38,7 @@
"FileUndeleteComplete": ":wastebasket:",
"AfterImportPage": ":books:",
"ArticleMergeComplete": ":card_box:",
"ApprovedRevsRevisionApproved": ":white_check_mark",
"ApprovedRevsRevisionApproved": ":white_check_mark:",
"ApprovedRevsRevisionUnapproved": ":white_check_mark:",
"ApprovedRevsFileRevisionApproved": ":white_check_mark:",
"ApprovedRevsFileRevisionUnapproved": ":white_check_mark:"
+1 -1
View File
@@ -217,7 +217,7 @@ class DiscordHooks {
}
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTarget() ),
( $block->mReason ? ('`' . DiscordUtils::sanitiseText( DiscordUtils::truncateText( $block->mReason ) ) . '`' ) : '' ),
( $block->getReasonComment()->text ? ('`' . DiscordUtils::sanitiseText( DiscordUtils::truncateText( $block->getReasonComment()->text ) ) . '`' ) : '' ),
$expiryMsg )->plain();
DiscordUtils::handleDiscord($hookName, $msg);
return true;
+22 -17
View File
@@ -81,8 +81,13 @@ class DiscordUtils {
DeferredUpdates::addCallableUpdate( function() use ( $stripped, $urls, $wgDiscordUseFileGetContents ) {
$user_agent = 'mw-discord/1.0 (github.com/jaydenkieran)';
$json_data = [ 'content' => "$stripped" ];
$json = json_encode($json_data);
$json_data = [
'content' => "$stripped",
'allowed_mentions' => [
'parse' => []
]
];
$json = json_encode($json_data);
if ( $wgDiscordUseFileGetContents ) {
// They want to use file_get_contents
@@ -101,12 +106,12 @@ class DiscordUtils {
$result = file_get_contents( $value, false, $context );
}
} else {
// By default, we use cURL
// By default, we use cURL
// Set up cURL multi handlers
$c_handlers = [];
$result = [];
$mh = curl_multi_init();
foreach ($urls as &$value) {
$c_handlers[$value] = curl_init( $value );
curl_setopt( $c_handlers[$value], CURLOPT_POST, 1 ); // Send as a POST request
@@ -122,19 +127,19 @@ class DiscordUtils {
));
curl_multi_add_handle( $mh, $c_handlers[$value] );
}
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);
// Remove all handlers and then close the multi handler
foreach($c_handlers as $k => $ch) {
$result[$k] = curl_multi_getcontent($ch);
wfDebugLog( 'discord', 'Result of cURL was: ' . $result[$k] );
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
}
} );
@@ -172,7 +177,7 @@ class DiscordUtils {
$userPage = DiscordUtils::createMarkdownLink( $user_abbr, ( $isAnon ? $contribs : $user->getUserPage() )->getFullUrl( '', '', $proto = PROTO_HTTP ) );
$userTalk = DiscordUtils::createMarkdownLink( wfMessage( 'discord-talk' )->text(), $user->getTalkPage()->getFullUrl( '', '', $proto = PROTO_HTTP ) );
$userContribs = DiscordUtils::createMarkdownLink( wfMessage( 'discord-contribs' )->text(), $contribs->getFullURL( '', '', $proto = PROTO_HTTP ) );
$text = wfMessage( 'discord-userlinks', $userPage, $userTalk, $userContribs )->text();
$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.
@@ -207,7 +212,7 @@ class DiscordUtils {
$text = wfMessage( 'discord-revisionlinks', $diff, $minor, $size )->text();
return $text;
}
/**
* Strip bad characters from a URL
*/
@@ -217,20 +222,20 @@ class DiscordUtils {
$url = str_replace(")", "%29", $url);
return $url;
}
/**
* Formats bytes to a string representing B, KB, MB, GB, TB
*/
public static function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
public static function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
return round($bytes, $precision) . ' ' . $units[$pow];
}
/**