mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-09-23 10:22:37 +00:00
add a whitelist regex for urls to avoid triggering captcha
This commit is contained in:
parent
cf1c61a3bd
commit
1ae38fa114
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue