Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistently suppress bot actions... #8

Merged
merged 3 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 34 additions & 3 deletions src/DiscordHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ) ),
Expand All @@ -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();
Expand Down Expand Up @@ -241,13 +251,20 @@ 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;

$lf = $image->getLocalFile();
$user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+

if ( DiscordUtils::isDisabled( 'UploadComplete', NS_FILE, $user ) ) {
return true;
}

if ( $wgDiscordNoBots && $user->isBot() ) {
// Don't continue, this is a bot change
return true;
}

$comment = $lf->getDescription();
$isNewRevision = count($lf->getHistory()) > 0;

Expand All @@ -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;
Expand All @@ -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();
Expand Down