Add $wgCaptchaRegexes array; if set, captcha also triggers on new matches
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 24 Jun 2006 21:26:48 +0000 (21:26 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 24 Jun 2006 21:26:48 +0000 (21:26 +0000)
to the regexes contained therein.

ConfirmEdit.php

index 37bcae59159ffec1fdb55149baa347fb470478bf..bb869ae5fca85213bf449a66661d0c1645216c0c 100644 (file)
@@ -79,9 +79,21 @@ $ceAllowConfirmedEmail = false;
  * Regex to whitelist URLs to known-good sites...
  * For instance:
  * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
  * Regex to whitelist URLs to known-good sites...
  * For instance:
  * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
+ * @fixme Use the 'spam-whitelist' thingy instead?
  */
 $wgCaptchaWhitelist = false;
 
  */
 $wgCaptchaWhitelist = false;
 
+/**
+ * Additional regexes to check for. Use full regexes; can match things
+ * other than URLs such as junk edits.
+ *
+ * If the new version matches one and the old version doesn't,
+ * toss up the captcha screen.
+ *
+ * @fixme Add a message for local admins to add items as well.
+ */
+$wgCaptchaRegexes = array();
+
 /**
  * Set up message strings for captcha utilities.
  */
 /**
  * Set up message strings for captcha utilities.
  */
@@ -275,6 +287,34 @@ class SimpleCaptcha {
                        }
                }
                
                        }
                }
                
+               global $wgCaptchaRegexes;
+               if( !empty( $wgCaptchaRegexes ) ) {
+                       // Custom regex checks
+                       $oldtext = $this->loadText( $editPage, $section );
+                       
+                       foreach( $wgCaptchaRegexes as $regex ) {
+                               $newMatches = array();
+                               if( preg_match_all( $regex, $newtext, $newMatches ) ) {
+                                       $oldMatches = array();
+                                       preg_match_all( $regex, $oldtext, $oldMatches );
+                                       
+                                       $addedMatches = array_diff( $newMatches[0], $oldMatches[0] );
+                                       
+                                       $numHits = count( $addedMatches );
+                                       if( $numHits > 0 ) {
+                                               global $wgUser, $wgTitle;
+                                               $this->trigger = sprintf( "%dx %s at [[%s]]: %s",
+                                                       $numHits,
+                                                       $regex,
+                                                       $wgUser->getName(),
+                                                       $wgTitle->getPrefixedText(),
+                                                       implode( ", ", $addedMatches ) );
+                                               return true;
+                                       }
+                               }
+                       }
+               }
+               
                return false;
        }
        
                return false;
        }