Compare commits

..

13 Commits

Author SHA1 Message Date
Jayden Bailey fa9149165d Bump version and update readme 2019-06-16 13:39:56 +01:00
Jayden Bailey ca3a5f8047 Add option to include timestamps on messages
Closes #11
2019-06-16 13:38:15 +01:00
Jayden Bailey 591ef8746e Merge pull request #8 from Dinoguy1000/patch-2
consistently suppress bot actions...
2019-05-13 18:33:47 +01:00
Dinoguy1000 6c2e30deab bump version number too 2019-04-30 19:28:29 -05:00
Dinoguy1000 ce780adf10 Update DiscordHooks.php 2019-04-30 19:22:35 -05:00
Jayden Bailey 680040e823 Merge pull request #3 from Railfail536/patch-1
Add Polish i18n
2019-05-01 01:20:57 +01:00
Jayden Bailey 8fa8dce03d Merge pull request #7 from Dinoguy1000/patch-1
default to revision size for diff size
2019-05-01 01:14:21 +01:00
Dinoguy1000 c3bdbecee5 consistently suppress bot actions...
...when $wgDiscordNoBots is true. This prevents (un)deletions, (un)protections, and file uploads from being reported when performed by a bot. Also did a bit of globals cleanup in one function.
2019-04-29 15:05:53 -05:00
Dinoguy1000 6ccca7b823 default to revision size for diff size
Certain events (primarily page creations) fail to display a diff size because there effectively is no diff (there is no previous revision to diff with); in these cases, just display the size of the current revision.
2019-04-29 14:52:52 -05:00
Jayden Bailey 03d612a3f7 handle potential strings in createUserLinks 2019-04-24 11:11:00 +01:00
Jayden Bailey 9830df7e97 Merge pull request #5 from xunto/xunto-patch-2
Fix unneeded broken curl_exec (Unknown Error with Visual Editor)
2019-01-29 22:16:11 +00:00
Orlov Valentine cecb90dffc Fix unneeded broken curl_exec 2019-01-30 00:44:53 +03:00
Rail 78d66e5e31 + pl.json 2019-01-28 12:19:52 +01:00
7 changed files with 103 additions and 13 deletions
+1
View File
@@ -49,6 +49,7 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
| `$wgDiscordDisabledHooks` | array | List of hooks to disable sending webhooks for (see [below](#hooks-used)) | `[]`
| `$wgDiscordDisabledNS` | array | List of namespaces to disable sending webhooks for | `[]`
| `$wgDiscordDisabledUsers` | array | List of users whose performed actions shouldn't send webhooks | `[]`
| `$wgDiscordPrependTimestamp` | bool | Prepend a timestamp (in UTC) to all sent messages. The format can be changed by editing the MediaWiki message `discord-timestampformat` | `false`
## Hooks used
- `PageContentSaveComplete` - New edits to pages and page creations
+3 -2
View File
@@ -4,7 +4,7 @@
"[https://github.com/jaydenkieran Jayden Bailey]"
],
"url": "https://github.com/jaydenkieran/mw-discord",
"version": "1.0.4",
"version": "1.0.6",
"descriptionmsg": "discord-desc",
"license-name": "MIT",
"manifest_version": 1,
@@ -17,7 +17,8 @@
"DiscordMaxChars": null,
"DiscordDisabledHooks": [],
"DiscordDisabledNS": [],
"DiscordDisabledUsers": []
"DiscordDisabledUsers": [],
"DiscordPrependTimestamp": false
},
"AutoloadClasses": {
"DiscordHooks": "src/DiscordHooks.php",
+7 -1
View File
@@ -1,4 +1,9 @@
{
"@metadata": {
"authors": [
"Jayden Bailey"
]
},
"discord-desc": "Sends messages to a Discord channel when certain events occur",
"discord-userlinks": "$1 ($2|$3)",
"discord-revisionlinks": "($1) $2 $3",
@@ -23,5 +28,6 @@
"discord-uploadnewver": "new version of",
"discord-uploadcomplete": "$1 uploaded $2 $3 $4 ($5, $6x$7, $8)",
"discord-filedeletecomplete": "$1 deleted a version of file $2 $3",
"discord-fileundeletecomplete": "$1 restored some versions of file $2 $3"
"discord-fileundeletecomplete": "$1 restored some versions of file $2 $3",
"discord-timestampformat": "**H:i e:**"
}
+31
View File
@@ -0,0 +1,31 @@
{
"@metadata": {
"authors": [
"Railfail536"
]
},
"discord-desc": "Wysyła wiadomości o dokonywanych akcjach na serwer Discord",
"discord-userlinks": "$1 ($2|$3)",
"discord-revisionlinks": "($1) $2 $3",
"discord-talk": "d",
"discord-contribs": "w",
"discord-diff": "różn.",
"discord-minor": "(m)",
"discord-size": "($1)",
"discord-edit": "$1 edytował $2 $3 $4",
"discord-articledelete": "$1 usunął $2 $3 ($4 wersje usunięte)",
"discord-undeleterev": "wersje",
"discord-articleundelete": "$1 odtworzył $2 $3 $4",
"discord-revvisibility": "$1 zmienił widoczność $2 wersji $3",
"discord-articleprotect": "$1 zmienił poziom zabezpoeczenia strony $2 $2 $3 ($4)",
"discord-titlemove": "$1 przeniósł $2 na $3 $4 $5",
"discord-localusercreated": "$1 założył konto",
"discord-blocktimeformat": "d F Y H:i",
"discord-blockipcomplete": "$1 zablokował $2 $3 ($4)",
"discord-unblockusercomplete": "$1 zdjął blokadę z $2",
"discord-usergroupschanged": "$1 zmienił uprawnienia użytkownika $2 $3 ($4) ($5)",
"discord-uploadnewver": "nową wersję",
"discord-uploadcomplete": "$1 przesłał $2 $3 $4 ($5, $6x$7, $8)",
"discord-filedeletecomplete": "$1 usunął wersję pliku $2 $3",
"discord-fileundeletecomplete": "$1 odtworzył wersje pliku $2 $3"
}
+7 -1
View File
@@ -1,4 +1,9 @@
{
"@metadata": {
"authors": [
"Jayden Bailey"
]
},
"discord-desc": "The description used for the Discord extension",
"discord-userlinks": "Used for display of the user links. Parameters\n* $1 - User page link\n* $2 - discord-talk\n* $3 - discord-contribs",
"discord-revisionlinks": "Used for display of revision links. Parameters\n* $1 - discord-diff\n* $2 - discord-minor\n* $3 - discord-size",
@@ -23,5 +28,6 @@
"discord-uploadnewver": "Used as the text for $2 in discord-uploadcomplete",
"discord-uploadcomplete": "Message sent to Discord when an upload is made. Parameters:\n$1 - discord-userlinks\n$2 - discord-uploadnewver\n$3 - File link\n$4 - Comment (always surrounded in tildes)\n$5 - Size (formatted as KB/MB/GB)\n$6 - File width\n$7 - File height\n$8 - File MIME type",
"discord-filedeletecomplete": "Message sent to Discord when a file version is deleted (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)",
"discord-fileundeletecomplete": "Message sent to Discord when a file version is restored (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)"
"discord-fileundeletecomplete": "Message sent to Discord when a file version is restored (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)",
"discord-timestampformat": "The formatting used in the gmtime() function for displaying the time an event happened in UTC."
}
+34 -3
View File
@@ -57,7 +57,7 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDeleteComplete
*/
public static function onArticleDeleteComplete( &$article, User &$user, $reason, $id, $content, LogEntry $logEntry, $archivedRevisionCount ) {
global $wgDiscordNoBots, $wgDiscordNoMinor, $wgDiscordNoNull;
global $wgDiscordNoBots;
if ( DiscordUtils::isDisabled( 'ArticleDeleteComplete', $article->getTitle()->getNamespace(), $user ) ) {
return true;
@@ -81,12 +81,17 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleUndelete
*/
public static function onArticleUndelete( Title $title, $create, $comment, $oldPageId, $restoredPages ) {
global $wgUser;
global $wgDiscordNoBots, $wgUser;
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace(), $wgUser ) ) {
return true;
}
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
// Don't continue, this is a bot change
return true;
}
$msg = wfMessage( 'discord-articleundelete', DiscordUtils::createUserLinks( $wgUser ),
($create ? '' : wfMessage( 'discord-undeleterev' )->text() ),
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
@@ -100,12 +105,17 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleRevisionVisibilitySet
*/
public static function onArticleRevisionVisibilitySet( &$title, $ids, $visibilityChangeMap ) {
global $wgUser;
global $wgDiscordNoBots, $wgUser;
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace(), $wgUser ) ) {
return true;
}
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
// Don't continue, this is a bot change
return true;
}
$msg = wfMessage( 'discord-revvisibility', DiscordUtils::createUserLinks( $wgUser ),
count($visibilityChangeMap),
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ) )->plain();
@@ -241,6 +251,8 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete
*/
public static function onUploadComplete( &$image ) {
global $wgDiscordNoBots;
$lf = $image->getLocalFile();
$user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+
@@ -248,6 +260,11 @@ class DiscordHooks {
return true;
}
if ( $wgDiscordNoBots && $user->isBot() ) {
// Don't continue, this is a bot change
return true;
}
$comment = $lf->getDescription();
$isNewRevision = count($lf->getHistory()) > 0;
@@ -268,10 +285,17 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileDeleteComplete
*/
public static function onFileDeleteComplete( $file, $oldimage, $article, $user, $reason ) {
global $wgDiscordNoBots;
if ( DiscordUtils::isDisabled( 'FileDeleteComplete', NS_FILE, $user ) ) {
return true;
}
if ( $wgDiscordNoBots && $user->isBot() ) {
// Don't continue, this is a bot change
return true;
}
if ( $article ) {
// Entire page was deleted, onArticleDeleteComplete will handle this
return true;
@@ -289,10 +313,17 @@ class DiscordHooks {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileUndeleteComplete
*/
public static function onFileUndeleteComplete( $title, $fileVersions, $user, $reason ) {
global $wgDiscordNoBots;
if ( DiscordUtils::isDisabled( 'FileUndeleteComplete', NS_FILE, $user ) ) {
return true;
}
if ( $wgDiscordNoBots && $user->isBot() ) {
// Don't continue, this is a bot change
return true;
}
$msg = wfMessage( 'discord-fileundeletecomplete', DiscordUtils::createUserLinks( $user ),
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->plain();
+20 -6
View File
@@ -46,7 +46,7 @@ class DiscordUtils {
* Handles sending a webhook to Discord using cURL
*/
public static function handleDiscord ($msg) {
global $wgDiscordWebhookURL;
global $wgDiscordWebhookURL, $wgDiscordPrependTimestamp;
if ( !$wgDiscordWebhookURL ) {
// There's nothing in here, so we won't do anything
@@ -67,6 +67,12 @@ class DiscordUtils {
// Strip whitespace to just one space
$stripped = preg_replace('/\s+/', ' ', $msg);
if ( $wgDiscordPrependTimestamp ) {
// Add timestamp
$dateString = gmdate( wfMessage( 'discord-timestampformat' )->text() );
$stripped = $dateString . ' ' . $stripped;
}
DeferredUpdates::addCallableUpdate( function() use ( $stripped, $urls ) {
$json_data = [ 'content' => "$stripped" ];
$json = json_encode($json_data);
@@ -87,7 +93,6 @@ class DiscordUtils {
curl_setopt( $c_handlers[$value], CURLOPT_TIMEOUT, 20 ); // Do not allow cURL to run for a long time
curl_setopt( $c_handlers[$value], CURLOPT_USERAGENT, 'mw-discord/1.0 (github.com/jaydenkieran)' ); // Add a unique user agent
curl_multi_add_handle( $mh, $c_handlers[$value] );
$response = curl_exec( $ch );
}
$running = null;
@@ -120,10 +125,16 @@ class DiscordUtils {
* Creates links for a specific MediaWiki User object
*/
public static function createUserLinks ($user) {
$userPage = DiscordUtils::createMarkdownLink( $user, $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(), Title::newFromText("Special:Contributions/" . $user)->getFullURL( '', '', $proto = PROTO_HTTP ) );
$text = wfMessage( 'discord-userlinks', $userPage, $userTalk, $userContribs )->text();
if ( $user instanceof User ) {
$userPage = DiscordUtils::createMarkdownLink( $user, $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(), Title::newFromText("Special:Contributions/" . $user)->getFullURL( '', '', $proto = PROTO_HTTP ) );
$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.
$text = wfMessage( 'discord-userlinks', $user, 'n/a', 'n/a' )->text();
}
return $text;
}
@@ -147,6 +158,9 @@ class DiscordUtils {
$size .= wfMessage( 'discord-size', sprintf( "%+d", $revision->getSize() - $previous->getSize() ) )->text();
}
}
if ( $size == '' ) {
$size .= wfMessage( 'discord-size', sprintf( "%d", $revision->getSize() ) )->text();
}
$text = wfMessage( 'discord-revisionlinks', $diff, $minor, $size )->text();
return $text;
}