Clear the queue when logging is done

Follows-up 5910bfd7ba.

* Remove one-off $domain variable.
* Rename $urlChanges to highlight that urlChanges is a log of changes,
  not a list of changes to be applied.
* Rename doEventLogging() to isLoggingEnabled().

Change-Id: Idbd6551502362422beea4d86b912128a43e9c96b
This commit is contained in:
Timo Tijhof 2016-05-18 22:00:00 +01:00 committed by Kaldari
parent ecb2f3fbfa
commit 19afb10841

View file

@ -10,7 +10,7 @@ class SpamBlacklist extends BaseBlacklist {
* Changes to external links, for logging purposes
* @var array[]
*/
private $urlChanges = array();
private $urlChangeLog = array();
/**
* Returns the code for the blacklist implementation
@ -123,7 +123,7 @@ class SpamBlacklist extends BaseBlacklist {
return $retVal;
}
private function shouldDoEventLogging() {
private function isLoggingEnabled() {
global $wgSpamBlacklistEventLogging;
return $wgSpamBlacklistEventLogging && class_exists( 'EventLogging' );
}
@ -136,7 +136,7 @@ class SpamBlacklist extends BaseBlacklist {
* @param string[] $addedLinks
*/
private function logUrlChanges( $oldLinks, $newLinks, $addedLinks ) {
if ( !$this->shouldDoEventLogging() ) {
if ( !$this->isLoggingEnabled() ) {
return;
}
@ -158,7 +158,7 @@ class SpamBlacklist extends BaseBlacklist {
* @param Revision $rev
*/
public function doLogging( User $user, Title $title, Revision $rev ) {
if ( !$this->shouldDoEventLogging() ) {
if ( !$this->isLoggingEnabled() ) {
return;
}
@ -169,7 +169,9 @@ class SpamBlacklist extends BaseBlacklist {
'userId' => $user->getId(),
'userText' => $user->getName(),
);
$changes = $this->urlChanges;
$changes = $this->urlChangeLog;
// Empty the changes queue in case this function gets called more than once
$this->urlChangeLog = array();
DeferredUpdates::addCallableUpdate( function() use ( $changes, $baseInfo ) {
foreach ( $changes as $change ) {
@ -180,30 +182,26 @@ class SpamBlacklist extends BaseBlacklist {
);
}
} );
// Empty the changes queue in case this function gets called more than once
$this->urlChanges = array();
}
/**
* Generate events for each url addition or removal
* Queue log data about change for a url addition or removal
*
* @param string $url
* @param string $type 'insert' or 'remove'
* @param string $action 'insert' or 'remove'
*/
private function logUrlChange( $url, $type ) {
private function logUrlChange( $url, $action ) {
$parsed = wfParseUrl( $url );
$domain = $parsed['host'];
$info = array(
'action' => $type,
'action' => $action,
'protocol' => $parsed['scheme'],
'domain' => $domain,
'domain' => $parsed['host'],
'path' => $parsed['path'],
'query' => $parsed['query'],
'fragment' => $parsed['fragment'],
);
$this->urlChanges[] = $info;
$this->urlChangeLog[] = $info;
}
/**