From c3bdbecee5da4c5a5f363c0b3c373886f642964b Mon Sep 17 00:00:00 2001 From: Dinoguy1000 <818183+Dinoguy1000@users.noreply.github.com> Date: Mon, 29 Apr 2019 15:05:53 -0500 Subject: [PATCH 1/3] 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. --- src/DiscordHooks.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/DiscordHooks.php b/src/DiscordHooks.php index 9476750..088c385 100644 --- a/src/DiscordHooks.php +++ b/src/DiscordHooks.php @@ -57,7 +57,7 @@ public static function onPageContentSaveComplete( &$wikiPage, &$user, $content, * @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 @@ public static function onArticleDeleteComplete( &$article, User &$user, $reason, * @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 @@ public static function onArticleUndelete( Title $title, $create, $comment, $oldP * @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,13 @@ public static function onUserGroupsChanged( User $user, array $added, array $rem * @see https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete */ public static function onUploadComplete( &$image ) { + global $wgDiscordNoBots, $wgUser; + + if ( $wgDiscordNoBots && $wgUser->isBot() ) { + // Don't continue, this is a bot change + return true; + } + $lf = $image->getLocalFile(); $user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+ @@ -268,10 +285,17 @@ public static function onUploadComplete( &$image ) { * @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 @@ public static function onFileDeleteComplete( $file, $oldimage, $article, $user, * @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(); From ce780adf10c06c45e84bd280a23e285209a189ba Mon Sep 17 00:00:00 2001 From: Dinoguy1000 <818183+Dinoguy1000@users.noreply.github.com> Date: Tue, 30 Apr 2019 19:22:35 -0500 Subject: [PATCH 2/3] Update DiscordHooks.php --- src/DiscordHooks.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DiscordHooks.php b/src/DiscordHooks.php index 088c385..ead23f5 100644 --- a/src/DiscordHooks.php +++ b/src/DiscordHooks.php @@ -251,12 +251,7 @@ public static function onUserGroupsChanged( User $user, array $added, array $rem * @see https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete */ public static function onUploadComplete( &$image ) { - global $wgDiscordNoBots, $wgUser; - - if ( $wgDiscordNoBots && $wgUser->isBot() ) { - // Don't continue, this is a bot change - return true; - } + global $wgDiscordNoBots; $lf = $image->getLocalFile(); $user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+ @@ -265,6 +260,11 @@ public static function onUploadComplete( &$image ) { return true; } + if ( $wgDiscordNoBots && $user->isBot() ) { + // Don't continue, this is a bot change + return true; + } + $comment = $lf->getDescription(); $isNewRevision = count($lf->getHistory()) > 0; From 6c2e30deabd5cf39509ab006a5183597d07725cf Mon Sep 17 00:00:00 2001 From: Dinoguy1000 <818183+Dinoguy1000@users.noreply.github.com> Date: Tue, 30 Apr 2019 19:28:29 -0500 Subject: [PATCH 3/3] bump version number too --- extension.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.json b/extension.json index af8c248..43c0c91 100644 --- a/extension.json +++ b/extension.json @@ -4,7 +4,7 @@ "[https://github.com/jaydenkieran Jayden Bailey]" ], "url": "https://github.com/jaydenkieran/mw-discord", - "version": "1.0.4", + "version": "1.0.5", "descriptionmsg": "discord-desc", "license-name": "MIT", "manifest_version": 1,