mediawiki-extensions-SpamBl.../SpamBlacklist.php

115 lines
3.1 KiB
PHP
Raw Normal View History

2004-12-11 09:59:06 +00:00
<?php
# Loader for spam blacklist feature
# Include this from LocalSettings.php
if ( !defined( 'MEDIAWIKI' ) ) {
exit;
}
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
$wgSpamBlacklistFiles = false;
2005-07-08 16:29:22 +00:00
$wgSpamBlacklistSettings = array();
2004-12-11 09:59:06 +00:00
$wgPreSpamFilterCallback = false;
if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
$wgHooks['EditFilterMerged'][] = 'wfSpamBlacklistFilterMerged';
2004-12-11 09:59:06 +00:00
} else {
if ( $wgFilterCallback ) {
$wgPreSpamFilterCallback = $wgFilterCallback;
}
$wgFilterCallback = 'wfSpamBlacklistFilter';
2004-12-11 09:59:06 +00:00
}
2005-08-26 14:33:40 +00:00
$wgExtensionCredits['other'][] = array(
'name' => 'SpamBlacklist',
2006-06-23 22:22:09 +00:00
'author' => 'Tim Starling',
2007-06-26 10:38:04 +00:00
'url' => 'http://www.mediawiki.org/wiki/Extension:SpamBlacklist',
'description' => 'Regex-based anti-spam tool',
2005-08-26 14:33:40 +00:00
);
2004-12-11 09:59:06 +00:00
$wgHooks['EditFilter'][] = 'wfSpamBlacklistValidate';
$wgHooks['ArticleSaveComplete'][] = 'wfSpamBlacklistArticleSave';
/**
* Load SpamBlacklist.i18n.php
*/
function wfSpamBlacklistLoadMessages() {
global $wgMessageCache;
static $done = false;
if ( $done ) {
return;
}
$done = true;
2004-12-11 09:59:06 +00:00
require( 'SpamBlacklist.i18n.php' );
if ( is_callable( array( $wgMessageCache, 'addMessagesByLang' ) ) ) {
$wgMessageCache->addMessagesByLang( $messages );
} else {
foreach( $messages as $lang => $langMessages ) {
$wgMessageCache->addMessages( $langMessages, $lang );
}
2004-12-11 09:59:06 +00:00
}
}
/**
* Get an instance of SpamBlacklist and do some first-call initialisation.
* All actual functionality is implemented in that object
*/
function wfSpamBlacklistObject() {
global $wgSpamBlacklistFiles, $wgSpamBlacklistSettings, $wgPreSpamFilterCallback;
static $spamObj;
if ( !$spamObj ) {
require_once( "SpamBlacklist_body.php" );
$spamObj = new SpamBlacklist( $wgSpamBlacklistSettings );
if( $wgSpamBlacklistFiles ) {
$spamObj->files = $wgSpamBlacklistFiles;
}
$spamObj->previousFilter = $wgPreSpamFilterCallback;
wfSpamBlacklistLoadMessages();
}
return $spamObj;
}
2007-06-29 01:36:09 +00:00
/**
* Hook function for $wgFilterCallback
*/
function wfSpamBlacklistFilter( &$title, $text, $section ) {
$spamObj = wfSpamBlacklistObject();
return $spamObj->filter( $title, $text, $section );
}
/**
* Hook function for EditFilterMerged, replaces wfSpamBlacklistFilter
*/
function wfSpamBlacklistFilterMerged( $editPage, $text ) {
$spamObj = wfSpamBlacklistObject();
$ret = $spamObj->filter( $editPage->mArticle->getTitle(), $text, '', $editPage );
// Return convention for hooks is the inverse of $wgFilterCallback
return !$ret;
}
/**
* Hook function for EditFilter
* 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();
return $spamObj->validate( $editPage, $text, $section, &$hookError );
}
/**
* Hook function for ArticleSaveComplete
* Clear local spam blacklist caches on page save.
*/
function wfSpamBlacklistArticleSave( &$article, &$user, $text, $summary, $isminor, $iswatch, $section ) {
$spamObj = wfSpamBlacklistObject();
return $spamObj->onArticleSave( &$article, &$user, $text, $summary, $isminor, $iswatch, $section );
}
2007-12-16 18:27:23 +00:00