From 09d5ac4c09c47a6ba2d0750592267fc9225dc8a5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 27 Feb 2009 20:50:25 +0000 Subject: [PATCH] (bug 17677) $wgSpamRegex should be seperated into summary- and page text-regex --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 5 ++++- includes/EditPage.php | 30 +++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e67e277f64..597324d9af 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 55d2b96650..1a5e95eed6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/EditPage.php b/includes/EditPage.php index 840497ed6a..37568b4217 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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; -- 2.20.1