Trigger Schema:ExternalLinksChange logging on page deletion

If a page is being deleted, use the ArticleDelete hook to queue a list
of URLs that are being "removed" from the page. The
ArticleDeleteComplete hook will trigger actually sending the logs - so
if something prevents the deletion, nothing will be logged.

Bug: T115119
Change-Id: I32e357bb88305a46251b05714a4ff75b75ae37aa
This commit is contained in:
Kunal Mehta 2016-09-27 13:35:58 -07:00 committed by Alex Monk
parent 2cac3f9ecd
commit 637a7435ce
3 changed files with 44 additions and 7 deletions

View file

@ -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() );
}
}

View file

@ -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(),

View file

@ -65,7 +65,9 @@
],
"UploadVerifyUpload": [
"SpamBlacklistHooks::onUploadVerifyUpload"
]
],
"ArticleDelete": "SpamBlacklistHooks::onArticleDelete",
"ArticleDeleteComplete": "SpamBlacklistHooks::onArticleDeleteComplete"
},
"config": {
"BlacklistSettings": {