add a whitelist regex for urls to avoid triggering captcha

This commit is contained in:
Brion Vibber 2006-01-27 11:05:50 +00:00
parent cf1c61a3bd
commit 1ae38fa114

View file

@ -73,6 +73,13 @@ $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
global $ceAllowConfirmedEmail;
$ceAllowConfirmedEmail = false;
/**
* Regex to whitelist URLs to known-good sites...
* For instance:
* $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
*/
$wgCaptchaWhitelist = false;
/**
* Set up message strings for captcha utilities.
*/
@ -209,8 +216,9 @@ class SimpleCaptcha {
$oldLinks = $this->findLinks( $oldtext );
$newLinks = $this->findLinks( $newtext );
$unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) );
$addedLinks = array_diff( $newLinks, $oldLinks );
$addedLinks = array_diff( $unknownLinks, $oldLinks );
$numLinks = count( $addedLinks );
if( $numLinks > 0 ) {
@ -227,6 +235,16 @@ class SimpleCaptcha {
return false;
}
/**
* Filter callback function for URL whitelisting
* @return bool true if unknown, false if whitelisted
* @access private
*/
function filterLink( $url ) {
global $wgCaptchaWhitelist;
return !( $wgCaptchaWhitelist && preg_match( $wgCaptchaWhitelist, $url ) );
}
/**
* The main callback run on edit attempts.
* @param EditPage $editPage