Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c193c24be2 | |||
| 4b46212f49 | |||
| d6d0f22c01 |
@@ -48,6 +48,7 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
|
||||
| `$wgDiscordMaxChars` | int | Maximum amount of characters for user-generated text (e.g summaries, reasons). Set to `null` to disable truncation | `null`
|
||||
| `$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 | `[]`
|
||||
|
||||
## Hooks used
|
||||
- `PageContentSaveComplete` - New edits to pages and page creations
|
||||
|
||||
+3
-2
@@ -4,7 +4,7 @@
|
||||
"[https://github.com/jaydenkieran Jayden Bailey]"
|
||||
],
|
||||
"url": "https://github.com/jaydenkieran/mw-discord",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.3",
|
||||
"descriptionmsg": "discord-desc",
|
||||
"license-name": "MIT",
|
||||
"manifest_version": 1,
|
||||
@@ -16,7 +16,8 @@
|
||||
"DiscordSuppressPreviews": true,
|
||||
"DiscordMaxChars": null,
|
||||
"DiscordDisabledHooks": [],
|
||||
"DiscordDisabledNS": []
|
||||
"DiscordDisabledNS": [],
|
||||
"DiscordDisabledUsers": []
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"DiscordHooks": "src/DiscordHooks.php",
|
||||
|
||||
+19
-18
@@ -13,7 +13,7 @@ class DiscordHooks {
|
||||
public static function onPageContentSaveComplete( &$wikiPage, &$user, $content, $summary, $isMinor, $isWatch, $section, &$flags, $revision, &$status, $baseRevId, $undidRevId ) {
|
||||
global $wgDiscordNoBots, $wgDiscordNoMinor, $wgDiscordNoNull;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'PageContentSaveComplete', $wikiPage->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'PageContentSaveComplete', $wikiPage->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ class DiscordHooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wikiPage->getTitle()->inNamespace( NS_FILE ) ) {
|
||||
// Don't continue, it's a file which onUploadComplete will handle instead
|
||||
if ( $wikiPage->getTitle()->inNamespace( NS_FILE ) && is_null( $revision->getPrevious() ) ) {
|
||||
// Don't continue, it's a new file which onUploadComplete will handle instead
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-edit', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $wikiPage->getTitle(), $wikiPage->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createRevisionText( $revision ),
|
||||
( $summary ? ('`' . DiscordUtils::truncateText( $summary ) . '`' ) : '' ) )->text();
|
||||
( $summary ? ('`' . DiscordUtils::truncateText( $summary ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class DiscordHooks {
|
||||
public static function onArticleDeleteComplete( &$article, User &$user, $reason, $id, $content, LogEntry $logEntry, $archivedRevisionCount ) {
|
||||
global $wgDiscordNoBots, $wgDiscordNoMinor, $wgDiscordNoNull;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleDeleteComplete', $article->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleDeleteComplete', $article->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class DiscordHooks {
|
||||
public static function onArticleUndelete( Title $title, $create, $comment, $oldPageId, $restoredPages ) {
|
||||
global $wgUser;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace(), $wgUser ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class DiscordHooks {
|
||||
public static function onArticleRevisionVisibilitySet( &$title, $ids, $visibilityChangeMap ) {
|
||||
global $wgUser;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace(), $wgUser ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class DiscordHooks {
|
||||
public static function onArticleProtectComplete( &$article, &$user, $protect, $reason ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleProtectComplete', $article->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleProtectComplete', $article->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class DiscordHooks {
|
||||
public static function onTitleMoveComplete( Title &$title, Title &$newTitle, User $user, $oldid, $newid, $reason, Revision $revision ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'TitleMoveComplete', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'TitleMoveComplete', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
|
||||
*/
|
||||
public static function onLocalUserCreated( $user, $autocreated ) {
|
||||
if ( DiscordUtils::isDisabled( 'LocalUserCreated', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'LocalUserCreated', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BlockIpComplete
|
||||
*/
|
||||
public static function onBlockIpComplete( Block $block, User $user ) {
|
||||
if ( DiscordUtils::isDisabled( 'BlockIpComplete', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'BlockIpComplete', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnblockUserComplete
|
||||
*/
|
||||
public static function onUnblockUserComplete( Block $block, User $user ) {
|
||||
if ( DiscordUtils::isDisabled( 'UnblockUserComplete', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'UnblockUserComplete', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGroupsChanged
|
||||
*/
|
||||
public static function onUserGroupsChanged( User $user, array $added, array $removed, $performer, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'UserGroupsChanged', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'UserGroupsChanged', NULL, $performer ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,12 +234,13 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete
|
||||
*/
|
||||
public static function onUploadComplete( &$image ) {
|
||||
if ( DiscordUtils::isDisabled( 'UploadComplete', NS_FILE ) ) {
|
||||
$lf = $image->getLocalFile();
|
||||
$user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'UploadComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$lf = $image->getLocalFile();
|
||||
$user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+
|
||||
$comment = $lf->getDescription();
|
||||
$isNewRevision = count($lf->getHistory()) > 0;
|
||||
|
||||
@@ -260,7 +261,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileDeleteComplete
|
||||
*/
|
||||
public static function onFileDeleteComplete( $file, $oldimage, $article, $user, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileDeleteComplete', NS_FILE ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileDeleteComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -281,7 +282,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileUndeleteComplete
|
||||
*/
|
||||
public static function onFileUndeleteComplete( $title, $fileVersions, $user, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileUndeleteComplete', NS_FILE ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileUndeleteComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -4,8 +4,8 @@ class DiscordUtils {
|
||||
/**
|
||||
* Checks if criteria is met for this action to be cancelled
|
||||
*/
|
||||
public static function isDisabled ( $hook, $ns ) {
|
||||
global $wgDiscordDisabledHooks, $wgDiscordDisabledNS;
|
||||
public static function isDisabled ( $hook, $ns, $user ) {
|
||||
global $wgDiscordDisabledHooks, $wgDiscordDisabledNS, $wgDiscordDisabledUsers;
|
||||
|
||||
if ( is_array( $wgDiscordDisabledHooks ) ) {
|
||||
if ( in_array( strtolower( $hook ), array_map( 'strtolower', $wgDiscordDisabledHooks ) ) ) {
|
||||
@@ -26,6 +26,18 @@ class DiscordUtils {
|
||||
} else {
|
||||
wfDebugLog( 'discord', 'The value of $wgDiscordDisabledNS is not valid and therefore all namespaces are enabled.' );
|
||||
}
|
||||
if ( is_array( $wgDiscordDisabledUsers ) ) {
|
||||
if ( !is_null( $user ) ) {
|
||||
if ( $user instanceof User ) {
|
||||
if ( in_array( $user->getName(), $wgDiscordDisabledUsers ) ) {
|
||||
// User shouldn't trigger a message, return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wfDebugLog( 'discord', 'The value of $wgDiscordDisabledUsers is not valid and therefore all users can trigger messages.' );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user