add a whitelist regex for urls to avoid triggering captcha
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 27 Jan 2006 11:05:50 +0000 (11:05 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 27 Jan 2006 11:05:50 +0000 (11:05 +0000)
ConfirmEdit.php

index cd1e04e1410358510dbb3848c95b0b3aca018af3..18725aa77e6a681a764297b48287096a759b52dd 100644 (file)
@@ -73,6 +73,13 @@ $wgCaptchaTriggers['addurl'] = true;  // Check on edits that add URLs
 global $ceAllowConfirmedEmail;
 $ceAllowConfirmedEmail = false;
 
 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.
  */
 /**
  * Set up message strings for captcha utilities.
  */
@@ -209,8 +216,9 @@ class SimpleCaptcha {
                        
                        $oldLinks = $this->findLinks( $oldtext );
                        $newLinks = $this->findLinks( $newtext );
                        
                        $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 ) {
                        $numLinks = count( $addedLinks );
                        
                        if( $numLinks > 0 ) {
@@ -227,6 +235,16 @@ class SimpleCaptcha {
                return false;
        }
        
                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
        /**
         * The main callback run on edit attempts.
         * @param EditPage $editPage