Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb6e0f7755 | |||
| 4e17d17de6 | |||
| f3b2531380 | |||
| 536a4afe13 | |||
| b3648a462c | |||
| bbff717a24 | |||
| 6d8b2c33cb | |||
| 47eef3c35d | |||
| 7f51c4f310 | |||
| ad101a326f | |||
| 687d1abf1f |
@@ -1,7 +1,7 @@
|
||||
# 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.
|
||||
|
||||
Multiple webhook URLs are supported and messages will be sent to all of them using cURL, so your web server is required to have cURL installed (for most Linux distros, installing using `sudo apt install curl` should work).
|
||||
Multiple webhook URLs are supported and messages will be sent to all of them.
|
||||
|
||||
**Live demo**: https://runescape.wiki (https://discord.gg/runescapewiki)
|
||||
|
||||
@@ -12,7 +12,9 @@ Multiple webhook URLs are supported and messages will be sent to all of them usi
|
||||
## Requirements
|
||||
- **Discord webhook URL**: This can be obtained by editing a channel on a server with the correct permissions.
|
||||
- **MediaWiki 1.31+**
|
||||
- **cURL**
|
||||
|
||||
### 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
|
||||
|
||||
@@ -51,6 +53,7 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
|
||||
| `$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`
|
||||
| `$wgDiscordUseFileGetContents` | bool | Use `file_get_contents` instead of cURL. Requires `allow_url_fopen` to be set to true in `php.ini`. Not recommended as cURL makes simultaneous calls instead. | `false`
|
||||
| `$wgDiscordUseEmojis` | bool | Prepend emojis to different types of messages to help distinguish them | `false`
|
||||
|
||||
## Hooks used
|
||||
- `PageContentSaveComplete` - New edits to pages and page creations
|
||||
@@ -66,6 +69,14 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
|
||||
- `UploadComplete` - File was uploaded
|
||||
- `FileDeleteComplete` - File revision was deleted
|
||||
- `FileUndeleteComplete` - File revision was restored
|
||||
- `AfterImportPage` - Page was imported
|
||||
- `ArticleMergeComplete` - Article histories was merged
|
||||
|
||||
### [Approved Revs](https://www.mediawiki.org/wiki/Extension:Approved_Revs)
|
||||
- `ApprovedRevsRevisionApproved` - Revision was approved
|
||||
- `ApprovedRevsRevisionUnapproved` - Revision was unapproved
|
||||
- `ApprovedRevsFileRevisionApproved` - File revision was approved
|
||||
- `ApprovedRevsFileRevisionUnapproved` - File revision was unapproved
|
||||
|
||||
## Translation
|
||||
This extension can be translated through the messages in the `ì18n` folder if you're a developer. As a wiki administrator, you may find it a better option to edit the messages on-site in the MediaWiki namespace.
|
||||
|
||||
+10
-3
@@ -4,7 +4,7 @@
|
||||
"[https://github.com/jaydenkieran Jayden Bailey]"
|
||||
],
|
||||
"url": "https://github.com/jaydenkieran/mw-discord",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.12",
|
||||
"descriptionmsg": "discord-desc",
|
||||
"license-name": "MIT",
|
||||
"manifest_version": 1,
|
||||
@@ -19,7 +19,8 @@
|
||||
"DiscordDisabledNS": [],
|
||||
"DiscordDisabledUsers": [],
|
||||
"DiscordPrependTimestamp": false,
|
||||
"DiscordUseFileGetContents": false
|
||||
"DiscordUseFileGetContents": false,
|
||||
"DiscordUseEmojis": false
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"DiscordHooks": "src/DiscordHooks.php",
|
||||
@@ -41,6 +42,12 @@
|
||||
"UserGroupsChanged": "DiscordHooks::onUserGroupsChanged",
|
||||
"UploadComplete": "DiscordHooks::onUploadComplete",
|
||||
"FileDeleteComplete": "DiscordHooks::onFileDeleteComplete",
|
||||
"FileUndeleteComplete": "DiscordHooks::onFileUndeleteComplete"
|
||||
"FileUndeleteComplete": "DiscordHooks::onFileUndeleteComplete",
|
||||
"AfterImportPage": "DiscordHooks::onAfterImportPage",
|
||||
"ArticleMergeComplete": "DiscordHooks::onArticleMergeComplete",
|
||||
"ApprovedRevsRevisionApproved": "DiscordHooks::externalonApprovedRevsRevisionApproved",
|
||||
"ApprovedRevsRevisionUnapproved": "DiscordHooks::externalonApprovedRevsRevisionUnapproved",
|
||||
"ApprovedRevsFileRevisionApproved": "DiscordHooks::externalonApprovedRevsFileRevisionApproved",
|
||||
"ApprovedRevsFileRevisionUnapproved": "DiscordHooks::externalonApprovedRevsFileRevisionUnapproved"
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -29,5 +29,11 @@
|
||||
"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-timestampformat": "**H:i e:**"
|
||||
"discord-afterimportpage": "$1 imported $2 (imported $4/$3 revisions)",
|
||||
"discord-timestampformat": "**H:i e:**",
|
||||
"discord-articlemergecomplete": "$1 merged revisions from $2 into $3",
|
||||
"discord-approvedrevsrevisionapproved": "$1 approved a new revision of $2 (revision $3) from user $4",
|
||||
"discord-approvedrevsrevisionunapproved": "$1 unapproved the approved revision for $2",
|
||||
"discord-approvedrevsfilerevisionapproved": "$1 approved a new file revision of $2 ($3) from user $4",
|
||||
"discord-approvedrevsfilerevisionunapproved": "$1 unapproved the approved file revision for $2"
|
||||
}
|
||||
|
||||
+7
-1
@@ -29,5 +29,11 @@
|
||||
"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-timestampformat": "The formatting used in the gmtime() function for displaying the time an event happened in UTC."
|
||||
"discord-afterimportpage": "Message sent to Discord when a page is imported. Parameters:\n$1 - discord-userlinks\n$2 - Page link\n$3 - Number of revisions in XML file\n$4 - Number of revisions successfully imported",
|
||||
"discord-timestampformat": "The formatting used in the gmtime() function for displaying the time an event happened in UTC.",
|
||||
"discord-articlemergecomplete": "Message sent to Discord when page histories are merged. Parameters:\n$1 - discord-userlinks\n$2 - Target link\n$3 - Destination link",
|
||||
"discord-approvedrevsrevisionapproved": "Message sent to Discord when a revision is approved (Approved Revs extension). Parameters:\n$1 - discord-userlinks (admin user)\n$2 - Target link\n$3 - Revision link or ID\n$4 - discord-userlinks (revision author) or ID",
|
||||
"discord-approvedrevsrevisionunapproved": "Message sent to Discord when a revision is unapproved (Approved Revs extension). Parameters:\n$1 - discord-userlinks (admin user)\n$2 - Target link",
|
||||
"discord-approvedrevsfilerevisionapproved": "Message sent to Discord when a file revision is approved (Approved Revs extension). Parameters:\n$1 - discord-userlinks (admin user)\n$2 - Target link\n$3 - SHA of uploaded file\n$4 - discord-userlinks (revision author)",
|
||||
"discord-approvedrevsfilerevisionunapproved": "Message sent to Discord when a file revision is unapproved (Approved Revs extension). Parameters:\n$1 - discord-userlinks (admin user)\n$2 - Target link"
|
||||
}
|
||||
|
||||
+193
-21
@@ -48,7 +48,7 @@ class DiscordHooks {
|
||||
DiscordUtils::createMarkdownLink( $wikiPage->getTitle(), $wikiPage->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createRevisionText( $revision ),
|
||||
( $summary ? ('`' . DiscordUtils::truncateText( $summary ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':pencil2:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class DiscordHooks {
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
$archivedRevisionCount)->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':wastebasket:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,22 +81,24 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleUndelete
|
||||
*/
|
||||
public static function onArticleUndelete( Title $title, $create, $comment, $oldPageId, $restoredPages ) {
|
||||
global $wgDiscordNoBots, $wgUser;
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace(), $wgUser ) ) {
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-articleundelete', DiscordUtils::createUserLinks( $wgUser ),
|
||||
$msg = wfMessage( 'discord-articleundelete', DiscordUtils::createUserLinks( $user ),
|
||||
($create ? '' : wfMessage( 'discord-undeleterev' )->text() ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $comment ? ('`' . DiscordUtils::truncateText( $comment ) . '`' ) : '' ))->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':wastebasket:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -105,21 +107,23 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleRevisionVisibilitySet
|
||||
*/
|
||||
public static function onArticleRevisionVisibilitySet( &$title, $ids, $visibilityChangeMap ) {
|
||||
global $wgDiscordNoBots, $wgUser;
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace(), $wgUser ) ) {
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-revvisibility', DiscordUtils::createUserLinks( $wgUser ),
|
||||
$msg = wfMessage( 'discord-revvisibility', DiscordUtils::createUserLinks( $user ),
|
||||
count($visibilityChangeMap),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':spy:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ class DiscordHooks {
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
implode(", ", $protect) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':lock:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -168,7 +172,7 @@ class DiscordHooks {
|
||||
DiscordUtils::createMarkdownLink( $newTitle, $newTitle->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
DiscordUtils::createRevisionText( $revision ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':truck:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -182,7 +186,7 @@ class DiscordHooks {
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-localusercreated', DiscordUtils::createUserLinks( $user ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':wave:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -205,7 +209,7 @@ class DiscordHooks {
|
||||
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTarget() ),
|
||||
( $block->mReason ? ('`' . DiscordUtils::truncateText( $block->mReason ) . '`' ) : '' ),
|
||||
$expiryMsg )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':no_entry_sign:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -219,7 +223,7 @@ class DiscordHooks {
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-unblockusercomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTarget() ) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':no_entry_sign:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -242,7 +246,7 @@ class DiscordHooks {
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
( ( count($added) > 0 ) ? ( '+ ' . join(', ', $added) ) : ''),
|
||||
( ( count($removed) > 0 ) ? ( '- ' . join(', ', $removed) ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':people_holding_hands:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -276,7 +280,7 @@ class DiscordHooks {
|
||||
$lf->getWidth(),
|
||||
$lf->getHeight(),
|
||||
$lf->getMimeType() )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':inbox_tray:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -304,7 +308,7 @@ class DiscordHooks {
|
||||
$msg = wfMessage( 'discord-filedeletecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $file->getName(), $file->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':wastebasket:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -327,7 +331,175 @@ class DiscordHooks {
|
||||
$msg = wfMessage( 'discord-fileundeletecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
DiscordUtils::handleDiscord(':wastebasket:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a page is imported
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/AfterImportPage
|
||||
*/
|
||||
public static function onAfterImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'AfterImportPage', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-afterimportpage', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
$revCount, $sRevCount)->plain();
|
||||
DiscordUtils::handleDiscord(':books:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function onArticleMergeComplete( $targetTitle, $destTitle ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleMergeComplete', $destTitle->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-articlemergecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $targetTitle, $targetTitle->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createMarkdownLink( $destTitle, $destTitle->getFullUrl( '', '', $proto = PROTO_HTTP ) ))->plain();
|
||||
DiscordUtils::handleDiscord(':card_box:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a revision is approved (Approved Revs extension)
|
||||
* @see https://github.com/wikimedia/mediawiki-extensions-ApprovedRevs/blob/REL1_34/includes/ApprovedRevs_body.php
|
||||
*/
|
||||
public static function externalonApprovedRevsRevisionApproved ( $output, $title, $rev_id, $content ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ApprovedRevsRevisionApproved', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the revision being approved here
|
||||
$rev = Revision::newFromTitle( $title, $rev_id );
|
||||
$revLink = $title->getFullURL( array( 'oldid' => $rev_id ), '', $proto = PROTO_HTTP );
|
||||
$revAuthor = $rev->getUser( Revision::RAW );
|
||||
|
||||
if ($revAuthor === 0) {
|
||||
$revAuthor = DiscordUtils::createUserLinks( User::newFromName($rev->getUserText(), false) );
|
||||
} else if ($revAuthor) {
|
||||
$revAuthor = DiscordUtils::createUserLinks( User::newFromId($revAuthor) );
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-approvedrevsrevisionapproved', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createMarkdownLink( $rev_id, $revLink ),
|
||||
$revAuthor)->plain();
|
||||
DiscordUtils::handleDiscord(':white_check_mark:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a revision is unapproved (Approved Revs extension)
|
||||
* @see https://github.com/wikimedia/mediawiki-extensions-ApprovedRevs/blob/REL1_34/includes/ApprovedRevs_body.php
|
||||
*/
|
||||
public static function externalonApprovedRevsRevisionUnapproved ( $output, $title, $content ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ApprovedRevsRevisionUnapproved', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-approvedrevsrevisionunapproved', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ))->plain();
|
||||
DiscordUtils::handleDiscord(':white_check_mark:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a file is approved (Approved Revs extension)
|
||||
* @see https://github.com/wikimedia/mediawiki-extensions-ApprovedRevs/blob/REL1_34/includes/ApprovedRevs_body.php
|
||||
*/
|
||||
public static function externalonApprovedRevsFileRevisionApproved ( $parser, $title, $timestamp, $sha1 ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ApprovedRevsFileRevisionApproved', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
$imagepage = ImagePage::newFromID( $title->getArticleID() );
|
||||
$displayedFile = $imagepage->getDisplayedFile();
|
||||
$displayedFileUrl = $displayedFile->getCanonicalUrl(); // getFullURL doesn't work quite the same on File classes
|
||||
$uploader = $displayedFile->getUser();
|
||||
|
||||
if (is_string($uploader)) {
|
||||
$uploader = User::newFromName($uploader, false);
|
||||
} else {
|
||||
$uploader = User::newFromId($uploader);
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-approvedrevsfilerevisionapproved', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullURL('', '', $proto = PROTO_HTTP) ),
|
||||
DiscordUtils::createMarkdownLink( 'direct', $displayedFileUrl ),
|
||||
DiscordUtils::createUserLinks( $uploader ) )->plain();
|
||||
DiscordUtils::handleDiscord(':white_check_mark:', $msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a file is unapproved (Approved Revs extension)
|
||||
* @see https://github.com/wikimedia/mediawiki-extensions-ApprovedRevs/blob/REL1_34/includes/ApprovedRevs_body.php
|
||||
*/
|
||||
public static function externalonApprovedRevsFileRevisionUnapproved ( $parser, $title ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ApprovedRevsFileRevisionUnapproved', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-approvedrevsfilerevisionunapproved', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ))->plain();
|
||||
DiscordUtils::handleDiscord(':white_check_mark:', $msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -45,8 +45,8 @@ class DiscordUtils {
|
||||
/**
|
||||
* Handles sending a webhook to Discord using cURL
|
||||
*/
|
||||
public static function handleDiscord ($msg) {
|
||||
global $wgDiscordWebhookURL, $wgDiscordPrependTimestamp, $wgDiscordUseFileGetContents;
|
||||
public static function handleDiscord ($emoji, $msg) {
|
||||
global $wgDiscordWebhookURL, $wgDiscordUseEmojis, $wgDiscordPrependTimestamp, $wgDiscordUseFileGetContents;
|
||||
|
||||
if ( !$wgDiscordWebhookURL ) {
|
||||
// There's nothing in here, so we won't do anything
|
||||
@@ -73,7 +73,12 @@ class DiscordUtils {
|
||||
$stripped = $dateString . ' ' . $stripped;
|
||||
}
|
||||
|
||||
DeferredUpdates::addCallableUpdate( function() use ( $stripped, $urls ) {
|
||||
if ( $wgDiscordUseEmojis ) {
|
||||
// Add emoji
|
||||
$stripped = $emoji . ' ' . $stripped;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -111,6 +116,9 @@ class DiscordUtils {
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_CONNECTTIMEOUT, 10 ); // Add a timeout for connecting to the site
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_TIMEOUT, 10 ); // Do not allow cURL to run for a long time
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_USERAGENT, $user_agent ); // Add a unique user agent
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json'
|
||||
));
|
||||
curl_multi_add_handle( $mh, $c_handlers[$value] );
|
||||
}
|
||||
|
||||
@@ -122,6 +130,7 @@ class DiscordUtils {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user