MediaWiki r47876 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r47875‎ | r47876 (on ViewVC)‎ | r47877 >
Date:20:50, 27 February 2009
Author:aaron
Status:ok
Tags:
Comment:
(bug 17677) $wgSpamRegex should be seperated into summary- and page text-regex
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php	(revision 47875)
+++ trunk/phase3/includes/EditPage.php	(revision 47876)
@@ -766,7 +766,7 @@
 		$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 @@
 	 */
 	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;
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 47875)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 47876)
@@ -2286,7 +2286,7 @@
 
 
 /**
- * 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 @@
  */
 $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: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 47875)
+++ trunk/phase3/RELEASE-NOTES	(revision 47876)
@@ -121,6 +121,8 @@
   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.

Follow-up revisions

Rev.Commit summaryAuthorDate
r48613Follow up to r47876, make spamregex check on move summary use $wgSummarySpamR...mrzman21:48, 19 March 2009

Status & tagging log

Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox