(bug 17677) $wgSpamRegex should be seperated into summary- and page text-regex
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 27 Feb 2009 20:50:25 +0000 (20:50 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 27 Feb 2009 20:50:25 +0000 (20:50 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/EditPage.php

index e67e277..597324d 100644 (file)
@@ -121,6 +121,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   username
 * Wrap special page summary message '$specialPageName-summary' into a div
   with class 'mw-specialpage-summary'
+* $wgSummarySpamRegex added to handle edit summary spam. This is used *instead*
+  of $wgSpamRegex for edit summary checks. Text checks still use $wgSpamRegex.
 
 === Bug fixes in 1.15 ===
 * (bug 16968) Special:Upload no longer throws useless warnings.
index 55d2b96..1a5e95e 100644 (file)
@@ -2286,7 +2286,7 @@ $wgExportMaxLinkDepth = 0;
 
 
 /**
- * Edits matching these regular expressions in body text or edit summary
+ * Edits matching these regular expressions in body text
  * will be recognised as spam and rejected automatically.
  *
  * There's no administrator override on-wiki, so be careful what you set. :)
@@ -2296,6 +2296,9 @@ $wgExportMaxLinkDepth = 0;
  */
 $wgSpamRegex = array();
 
+/** Same as the above except for edit summaries */
+$wgSummarySpamRegex = array();
+
 /** Similarly you can get a function to do the job. The function will be given
  * the following args:
  *   - a Title object for the article the edit is made on
index 840497e..37568b4 100644 (file)
@@ -766,7 +766,7 @@ class EditPage {
                $this->mMetaData = '' ;
 
                # Check for spam
-               $match = self::matchSpamRegex( $this->summary );
+               $match = self::matchSummarySpamRegex( $this->summary );
                if ( $match === false ) {
                        $match = self::matchSpamRegex( $this->textbox1 );
                }
@@ -1063,14 +1063,26 @@ class EditPage {
         */
        public static function matchSpamRegex( $text ) {
                global $wgSpamRegex;
-               if ( $wgSpamRegex ) {
-                       // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
-                       $regexes = (array)$wgSpamRegex;
-                       foreach( $regexes as $regex ) {
-                               $matches = array();
-                               if ( preg_match( $regex, $text, $matches ) ) {
-                                       return $matches[0];
-                               }
+               // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
+               $regexes = (array)$wgSpamRegex;
+               return self::matchSpamRegexInternal( $text, $regexes );
+       }
+       
+       /**
+        * Check given input text against $wgSpamRegex, and return the text of the first match.
+        * @return mixed -- matching string or false
+        */
+       public static function matchSummarySpamRegex( $text ) {
+               global $wgSummarySpamRegex;
+               $regexes = (array)$wgSummarySpamRegex;
+               return self::matchSpamRegexInternal( $text, $regexes );
+       }
+       
+       protected static function matchSpamRegexInternal( $text, $regexes ) {
+               foreach( $regexes as $regex ) {
+                       $matches = array();
+                       if( preg_match( $regex, $text, $matches ) ) {
+                               return $matches[0];
                        }
                }
                return false;