mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SpamBlacklist
synced 2024-11-27 16:40:04 +00:00
Abandon EventLogging instrumentation
The instrumentation attempted here has been implemented more correctly by https://phabricator.wikimedia.org/T214706. This change removes instrumentation from this extension. It should not affect much, because emitting events was already disabled. Bug: T162365 Change-Id: I8f02c62d41260a62b37a7738d69c039d2ce7562f
This commit is contained in:
parent
3f6da90ccf
commit
a72c0f339a
|
@ -84,9 +84,7 @@
|
|||
],
|
||||
"UploadVerifyUpload": [
|
||||
"SpamBlacklistHooks::onUploadVerifyUpload"
|
||||
],
|
||||
"ArticleDelete": "SpamBlacklistHooks::onArticleDelete",
|
||||
"ArticleDeleteComplete": "SpamBlacklistHooks::onArticleDeleteComplete"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"BlacklistSettings": {
|
||||
|
@ -95,8 +93,7 @@
|
|||
},
|
||||
"_merge_strategy": "array_plus_2d"
|
||||
},
|
||||
"LogSpamBlacklistHits": false,
|
||||
"SpamBlacklistEventLogging": false
|
||||
"LogSpamBlacklistHits": false
|
||||
},
|
||||
"AuthManagerAutoConfig": {
|
||||
"preauth": {
|
||||
|
|
|
@ -11,12 +11,6 @@ class SpamBlacklist extends BaseBlacklist {
|
|||
const STASH_TTL = 180;
|
||||
const STASH_AGE_DYING = 150;
|
||||
|
||||
/**
|
||||
* Changes to external links, for logging purposes
|
||||
* @var array[]
|
||||
*/
|
||||
private $urlChangeLog = [];
|
||||
|
||||
/**
|
||||
* Returns the code for the blacklist implementation
|
||||
*
|
||||
|
@ -56,12 +50,6 @@ class SpamBlacklist extends BaseBlacklist {
|
|||
$statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
|
||||
$cache = ObjectCache::getLocalClusterInstance();
|
||||
|
||||
// If there are no new links, and we are logging,
|
||||
// mark all of the current links as being removed.
|
||||
if ( !$links && $this->isLoggingEnabled() ) {
|
||||
$this->logUrlChanges( $this->getCurrentLinks( $title ), [], [] );
|
||||
}
|
||||
|
||||
if ( !$links ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -110,10 +98,6 @@ class SpamBlacklist extends BaseBlacklist {
|
|||
wfDebugLog( 'SpamBlacklist', "New URLs: " . implode( ', ', $newLinks ) );
|
||||
wfDebugLog( 'SpamBlacklist', "Added URLs: " . implode( ', ', $addedLinks ) );
|
||||
|
||||
if ( !$preventLog ) {
|
||||
$this->logUrlChanges( $oldLinks, $newLinks, $addedLinks );
|
||||
}
|
||||
|
||||
$links = implode( "\n", $addedLinks );
|
||||
|
||||
# Strip whitelisted URLs from the match
|
||||
|
@ -176,92 +160,6 @@ class SpamBlacklist extends BaseBlacklist {
|
|||
return $retVal;
|
||||
}
|
||||
|
||||
public function isLoggingEnabled() {
|
||||
global $wgSpamBlacklistEventLogging;
|
||||
return $wgSpamBlacklistEventLogging &&
|
||||
ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff added/removed urls and generate events for them
|
||||
*
|
||||
* @param string[] $oldLinks
|
||||
* @param string[] $newLinks
|
||||
* @param string[] $addedLinks
|
||||
*/
|
||||
public function logUrlChanges( $oldLinks, $newLinks, $addedLinks ) {
|
||||
if ( !$this->isLoggingEnabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$removedLinks = array_diff( $oldLinks, $newLinks );
|
||||
foreach ( $addedLinks as $url ) {
|
||||
$this->logUrlChange( $url, 'insert' );
|
||||
}
|
||||
|
||||
foreach ( $removedLinks as $url ) {
|
||||
$this->logUrlChange( $url, 'remove' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually push the url change events post-save
|
||||
*
|
||||
* @param User $user
|
||||
* @param Title $title
|
||||
* @param int $revId
|
||||
*/
|
||||
public function doLogging( User $user, Title $title, $revId ) {
|
||||
if ( !$this->isLoggingEnabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$baseInfo = [
|
||||
'revId' => $revId,
|
||||
'pageId' => $title->getArticleID(),
|
||||
'pageNamespace' => $title->getNamespace(),
|
||||
'userId' => $user->getId(),
|
||||
'userText' => $user->getName(),
|
||||
];
|
||||
$changes = $this->urlChangeLog;
|
||||
// Empty the changes queue in case this function gets called more than once
|
||||
$this->urlChangeLog = [];
|
||||
|
||||
DeferredUpdates::addCallableUpdate( function () use ( $changes, $baseInfo ) {
|
||||
foreach ( $changes as $change ) {
|
||||
EventLogging::logEvent(
|
||||
'ExternalLinksChange',
|
||||
15716074,
|
||||
$baseInfo + $change
|
||||
);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue log data about change for a url addition or removal
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $action 'insert' or 'remove'
|
||||
*/
|
||||
private function logUrlChange( $url, $action ) {
|
||||
$parsed = wfParseUrl( $url );
|
||||
if ( !isset( $parsed['host'] ) ) {
|
||||
wfDebugLog( 'SpamBlacklist', "Unable to parse $url" );
|
||||
return;
|
||||
}
|
||||
$info = [
|
||||
'action' => $action,
|
||||
'protocol' => $parsed['scheme'],
|
||||
'domain' => $parsed['host'],
|
||||
'path' => $parsed['path'] ?? '',
|
||||
'query' => $parsed['query'] ?? '',
|
||||
'fragment' => $parsed['fragment'] ?? '',
|
||||
];
|
||||
|
||||
$this->urlChangeLog[] = $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the links currently in the article, so we can
|
||||
* ignore them on a second run.
|
||||
|
|
|
@ -171,11 +171,6 @@ class SpamBlacklistHooks {
|
|||
Status $status,
|
||||
$baseRevId
|
||||
) {
|
||||
if ( $revision ) {
|
||||
BaseBlacklist::getSpamBlacklist()
|
||||
->doLogging( $user, $wikiPage->getTitle(), $revision->getId() );
|
||||
}
|
||||
|
||||
if ( !BaseBlacklist::isLocalSource( $wikiPage->getTitle() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -242,43 +237,4 @@ class SpamBlacklistHooks {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WikiPage &$article
|
||||
* @param User &$user
|
||||
* @param string &$reason
|
||||
* @param string &$error
|
||||
*/
|
||||
public static function onArticleDelete( WikiPage &$article, User &$user, &$reason, &$error ) {
|
||||
$spam = BaseBlacklist::getSpamBlacklist();
|
||||
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 string $reason
|
||||
* @param int $id
|
||||
* @param Content|null $content
|
||||
* @param LogEntry $logEntry
|
||||
* @suppress PhanParamReqAfterOpt
|
||||
*/
|
||||
public static function onArticleDeleteComplete(
|
||||
&$page,
|
||||
User &$user,
|
||||
$reason,
|
||||
$id,
|
||||
Content $content = null,
|
||||
LogEntry $logEntry
|
||||
) {
|
||||
$spam = BaseBlacklist::getSpamBlacklist();
|
||||
$spam->doLogging( $user, $page->getTitle(), $page->getLatest() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue