
brion at svn
Aug 19, 2008, 1:32 PM
Post #1 of 1
(109 views)
Permalink
|
|
SVN: [39660] trunk/phase3
|
|
Revision: 39660 Author: brion Date: 2008-08-19 20:32:30 +0000 (Tue, 19 Aug 2008) Log Message: ----------- * $wgSpamRegex now matches the edit summary and page move descriptions in addition to body text. Could use some cleanup to the error display on page moves; it recycles the general edit notice for spam hits currently, which is pretty big on English Wikipedia, and doesn't say what match you hit. Modified Paths: -------------- trunk/phase3/RELEASE-NOTES trunk/phase3/includes/DefaultSettings.php trunk/phase3/includes/EditPage.php trunk/phase3/includes/Title.php Modified: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES 2008-08-19 19:44:10 UTC (rev 39659) +++ trunk/phase3/RELEASE-NOTES 2008-08-19 20:32:30 UTC (rev 39660) @@ -37,6 +37,7 @@ * $wgRestrictDisplayTitle controls if the use of the {{DISPLAYTITLE}} magic word is restricted to titles equivalent to the actual page title. This is true per default, but can be set to false to allow any title. +* $wgSpamRegex may now be an array of multiple regular expressions. === New features in 1.14 === @@ -134,7 +135,10 @@ * Avoid recursive crazy expansions in section edit comments for pages which contain '/*' in the title * Fix excessive memory usage when parsing pages with lots of links +* $wgSpamRegex now matches the edit summary and page move descriptions in + addition to body text. + === API changes in 1.14 === * Registration time of users registered before the DB field was created is now Modified: trunk/phase3/includes/DefaultSettings.php =================================================================== --- trunk/phase3/includes/DefaultSettings.php 2008-08-19 19:44:10 UTC (rev 39659) +++ trunk/phase3/includes/DefaultSettings.php 2008-08-19 20:32:30 UTC (rev 39660) @@ -2095,9 +2095,17 @@ $wgExportAllowListContributors = false ; -/** Text matching this regular expression will be recognised as spam - * See http://en.wikipedia.org/wiki/Regular_expression */ -$wgSpamRegex = false; +/** + * Edits matching these regular expressions in body text or edit summary + * will be recognised as spam and rejected automatically. + * + * There's no administrator override on-wiki, so be careful what you set. :) + * May be an array of regexes or a single string for backwards compatibility. + * + * See http://en.wikipedia.org/wiki/Regular_expression + */ +$wgSpamRegex = 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 Modified: trunk/phase3/includes/EditPage.php =================================================================== --- trunk/phase3/includes/EditPage.php 2008-08-19 19:44:10 UTC (rev 39659) +++ trunk/phase3/includes/EditPage.php 2008-08-19 20:32:30 UTC (rev 39660) @@ -733,7 +733,7 @@ * @return one of the constants describing the result */ function internalAttemptSave( &$result, $bot = false ) { - global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser; + global $wgFilterCallback, $wgUser, $wgOut, $wgParser; global $wgMaxArticleSize; $fname = 'EditPage::attemptSave'; @@ -762,12 +762,15 @@ $this->mMetaData = '' ; # Check for spam - $matches = array(); - if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) { - $result['spam'] = $matches[0]; + $match = self::matchSpamRegex( $this->summary ); + if( $match === false ) { + $match = self::matchSpamRegex( $this->textbox1 ); + } + if( $match !== false ) { + $result['spam'] = $match; $ip = wfGetIP(); $pdbk = $this->mTitle->getPrefixedDBkey(); - $match = str_replace( "\n", '', $matches[0] ); + $match = str_replace( "\n", '', $match ); wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); wfProfileOut( "$fname-checks" ); wfProfileOut( $fname ); @@ -1022,6 +1025,25 @@ wfProfileOut( $fname ); return self::AS_END; } + + /** + * Check given input text against $wgSpamRegex, and return the text of the first match. + * @return mixed -- matching string or false + */ + 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]; + } + } + } + return false; + } /** * Initialise form fields in the object Modified: trunk/phase3/includes/Title.php =================================================================== --- trunk/phase3/includes/Title.php 2008-08-19 19:44:10 UTC (rev 39659) +++ trunk/phase3/includes/Title.php 2008-08-19 20:32:30 UTC (rev 39660) @@ -2500,6 +2500,12 @@ $nt->getUserPermissionsErrors('edit', $wgUser)); } + $match = EditPage::matchSpamRegex( $reason ); + if( $match !== false ) { + // This is kind of lame, won't display nice + $errors[] = array('spamprotectiontext'); + } + global $wgUser; $err = null; if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS[at]lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|