diff --git a/SpamBlacklistHooks.php b/SpamBlacklistHooks.php index e4dee92d..eb0d5dd9 100644 --- a/SpamBlacklistHooks.php +++ b/SpamBlacklistHooks.php @@ -189,7 +189,7 @@ class SpamBlacklistHooks { ) { if ( $revision ) { BaseBlacklist::getInstance( 'spam' ) - ->doLogging( $user, $wikiPage->getTitle(), $revision ); + ->doLogging( $user, $wikiPage->getTitle(), $revision->getId() ); } if ( !BaseBlacklist::isLocalSource( $wikiPage->getTitle() ) ) { @@ -252,4 +252,39 @@ class SpamBlacklistHooks { return true; } + + /** + * @param WikiPage $article + * @param User $user + * @param $reason + * @param $error + */ + public static function onArticleDelete( WikiPage &$article, User &$user, &$reason, &$error ) { + /** @var SpamBlacklist $spam */ + $spam = BaseBlacklist::getInstance( 'spam' ); + if ( !$spam->isLoggingEnabled() ) { + return; + } + + // Log the changes, but we only commit them once the deletion has happened. + // We do that since the external links table could get cleared before the + // ArticleDeleteComplete hook runs + $spam->logUrlChanges( $spam->getCurrentLinks( $article->getTitle() ), [], [] ); + } + + /** + * @param WikiPage $page + * @param User $user + * @param $reason + * @param $id + * @param Content|null $content + * @param LogEntry $logEntry + */ + public static function onArticleDeleteComplete( &$page, User &$user, $reason, + $id, Content $content = null, LogEntry $logEntry + ) { + /** @var SpamBlacklist $spam */ + $spam = BaseBlacklist::getInstance( 'spam' ); + $spam->doLogging( $user, $page->getTitle(), $page->getLatest() ); + } } diff --git a/SpamBlacklist_body.php b/SpamBlacklist_body.php index a4d62d85..e14fa444 100644 --- a/SpamBlacklist_body.php +++ b/SpamBlacklist_body.php @@ -175,7 +175,7 @@ class SpamBlacklist extends BaseBlacklist { return $retVal; } - private function isLoggingEnabled() { + public function isLoggingEnabled() { global $wgSpamBlacklistEventLogging; return $wgSpamBlacklistEventLogging && class_exists( 'EventLogging' ); } @@ -187,7 +187,7 @@ class SpamBlacklist extends BaseBlacklist { * @param string[] $newLinks * @param string[] $addedLinks */ - private function logUrlChanges( $oldLinks, $newLinks, $addedLinks ) { + public function logUrlChanges( $oldLinks, $newLinks, $addedLinks ) { if ( !$this->isLoggingEnabled() ) { return; } @@ -207,15 +207,15 @@ class SpamBlacklist extends BaseBlacklist { * * @param User $user * @param Title $title - * @param Revision $rev + * @param int $revId */ - public function doLogging( User $user, Title $title, Revision $rev ) { + public function doLogging( User $user, Title $title, $revId ) { if ( !$this->isLoggingEnabled() ) { return; } $baseInfo = array( - 'revId' => $rev->getId(), + 'revId' => $revId, 'pageId' => $title->getArticleID(), 'pageNamespace' => $title->getNamespace(), 'userId' => $user->getId(), diff --git a/extension.json b/extension.json index 794fb0ac..52c40b91 100644 --- a/extension.json +++ b/extension.json @@ -65,7 +65,9 @@ ], "UploadVerifyUpload": [ "SpamBlacklistHooks::onUploadVerifyUpload" - ] + ], + "ArticleDelete": "SpamBlacklistHooks::onArticleDelete", + "ArticleDeleteComplete": "SpamBlacklistHooks::onArticleDeleteComplete" }, "config": { "BlacklistSettings": {