2004-12-11 09:59:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
# Loader for spam blacklist feature
|
|
|
|
# Include this from LocalSettings.php
|
|
|
|
|
2007-11-12 07:44:17 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
2004-12-11 09:59:06 +00:00
|
|
|
|
2008-02-16 20:47:29 +00:00
|
|
|
$wgExtensionCredits['other'][] = array(
|
|
|
|
'name' => 'SpamBlacklist',
|
|
|
|
'author' => 'Tim Starling',
|
2008-05-06 11:59:58 +00:00
|
|
|
'svn-date' => '$LastChangedDate$',
|
|
|
|
'svn-revision' => '$LastChangedRevision$',
|
2008-02-16 20:47:29 +00:00
|
|
|
'url' => 'http://www.mediawiki.org/wiki/Extension:SpamBlacklist',
|
|
|
|
'description' => 'Regex-based anti-spam tool',
|
|
|
|
'descriptionmsg' => 'spam-blacklist-desc',
|
|
|
|
);
|
|
|
|
|
|
|
|
$dir = dirname(__FILE__) . '/';
|
|
|
|
$wgExtensionMessagesFiles['SpamBlackList'] = $dir . 'SpamBlacklist.i18n.php';
|
|
|
|
|
2004-12-11 09:59:06 +00:00
|
|
|
global $wgFilterCallback, $wgPreSpamFilterCallback;
|
|
|
|
global $wgSpamBlacklistFiles;
|
2005-07-08 16:29:22 +00:00
|
|
|
global $wgSpamBlacklistSettings;
|
2004-12-11 09:59:06 +00:00
|
|
|
|
2008-02-16 20:47:29 +00:00
|
|
|
|
2004-12-11 09:59:06 +00:00
|
|
|
$wgSpamBlacklistFiles = false;
|
2005-07-08 16:29:22 +00:00
|
|
|
$wgSpamBlacklistSettings = array();
|
2004-12-11 09:59:06 +00:00
|
|
|
|
2007-11-12 07:44:17 +00:00
|
|
|
$wgPreSpamFilterCallback = false;
|
|
|
|
|
|
|
|
if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
|
|
|
|
$wgHooks['EditFilterMerged'][] = 'wfSpamBlacklistFilterMerged';
|
2004-12-11 09:59:06 +00:00
|
|
|
} else {
|
2007-11-12 07:44:17 +00:00
|
|
|
if ( $wgFilterCallback ) {
|
|
|
|
$wgPreSpamFilterCallback = $wgFilterCallback;
|
|
|
|
}
|
|
|
|
$wgFilterCallback = 'wfSpamBlacklistFilter';
|
2004-12-11 09:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-20 21:13:26 +00:00
|
|
|
$wgHooks['EditFilter'][] = 'wfSpamBlacklistValidate';
|
2007-11-12 07:44:17 +00:00
|
|
|
$wgHooks['ArticleSaveComplete'][] = 'wfSpamBlacklistArticleSave';
|
2007-07-20 21:13:26 +00:00
|
|
|
|
2007-11-12 07:44:17 +00:00
|
|
|
/**
|
2008-02-16 20:47:29 +00:00
|
|
|
* Internationalization messages
|
2007-11-12 07:44:17 +00:00
|
|
|
*/
|
|
|
|
function wfSpamBlacklistLoadMessages() {
|
2008-02-17 19:48:47 +00:00
|
|
|
wfLoadExtensionMessages('SpamBlackList');
|
2004-12-11 09:59:06 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 07:44:17 +00:00
|
|
|
/**
|
|
|
|
* Get an instance of SpamBlacklist and do some first-call initialisation.
|
|
|
|
* All actual functionality is implemented in that object
|
|
|
|
*/
|
2007-07-20 21:13:26 +00:00
|
|
|
function wfSpamBlacklistObject() {
|
|
|
|
global $wgSpamBlacklistFiles, $wgSpamBlacklistSettings, $wgPreSpamFilterCallback;
|
2007-11-12 07:44:17 +00:00
|
|
|
static $spamObj;
|
|
|
|
if ( !$spamObj ) {
|
|
|
|
require_once( "SpamBlacklist_body.php" );
|
|
|
|
$spamObj = new SpamBlacklist( $wgSpamBlacklistSettings );
|
|
|
|
if( $wgSpamBlacklistFiles ) {
|
|
|
|
$spamObj->files = $wgSpamBlacklistFiles;
|
|
|
|
}
|
|
|
|
$spamObj->previousFilter = $wgPreSpamFilterCallback;
|
|
|
|
wfSpamBlacklistLoadMessages();
|
2007-07-20 21:13:26 +00:00
|
|
|
}
|
|
|
|
return $spamObj;
|
|
|
|
}
|
2007-06-29 01:36:09 +00:00
|
|
|
|
2007-07-20 21:13:26 +00:00
|
|
|
/**
|
2007-11-12 07:44:17 +00:00
|
|
|
* Hook function for $wgFilterCallback
|
|
|
|
*/
|
2008-06-19 03:14:34 +00:00
|
|
|
function wfSpamBlacklistFilter( &$title, $text, $section, &$hookErr, $editSummary ) {
|
2007-11-12 07:44:17 +00:00
|
|
|
$spamObj = wfSpamBlacklistObject();
|
2008-06-19 03:14:34 +00:00
|
|
|
return $spamObj->filter( $title, $text, $section, $editSummary );
|
2007-11-12 07:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook function for EditFilterMerged, replaces wfSpamBlacklistFilter
|
|
|
|
*/
|
2008-08-16 21:40:30 +00:00
|
|
|
function wfSpamBlacklistFilterMerged( &$editPage, $text, &$hookErr, $editSummary ) {
|
2007-11-12 07:44:17 +00:00
|
|
|
$spamObj = wfSpamBlacklistObject();
|
2008-05-14 12:44:34 +00:00
|
|
|
$title = $editPage->mArticle->getTitle();
|
2008-08-16 21:40:30 +00:00
|
|
|
$ret = $spamObj->filter( $title, $text, '', $editSummary, $editPage );
|
2007-11-12 07:44:17 +00:00
|
|
|
// Return convention for hooks is the inverse of $wgFilterCallback
|
|
|
|
return !$ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook function for EditFilter
|
2007-07-20 21:13:26 +00:00
|
|
|
* Confirm that a local blacklist page being saved is valid,
|
|
|
|
* and toss back a warning to the user if it isn't.
|
|
|
|
*/
|
|
|
|
function wfSpamBlacklistValidate( $editPage, $text, $section, &$hookError ) {
|
|
|
|
$spamObj = wfSpamBlacklistObject();
|
2008-03-14 18:31:28 +00:00
|
|
|
return $spamObj->validate( $editPage, $text, $section, $hookError );
|
2007-07-20 21:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-12 07:44:17 +00:00
|
|
|
* Hook function for ArticleSaveComplete
|
2007-07-20 21:13:26 +00:00
|
|
|
* Clear local spam blacklist caches on page save.
|
|
|
|
*/
|
2007-11-12 07:44:17 +00:00
|
|
|
function wfSpamBlacklistArticleSave( &$article, &$user, $text, $summary, $isminor, $iswatch, $section ) {
|
2007-07-20 21:13:26 +00:00
|
|
|
$spamObj = wfSpamBlacklistObject();
|
2008-03-14 18:31:28 +00:00
|
|
|
return $spamObj->onArticleSave( $article, $user, $text, $summary, $isminor, $iswatch, $section );
|
2007-07-20 21:13:26 +00:00
|
|
|
}
|
2007-12-16 18:27:23 +00:00
|
|
|
|