Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | * $wgRestrictDisplayTitle controls if the use of the {{DISPLAYTITLE}} magic |
39 | 39 | word is restricted to titles equivalent to the actual page title. This |
40 | 40 | is true per default, but can be set to false to allow any title. |
| 41 | +* $wgSpamRegex may now be an array of multiple regular expressions. |
41 | 42 | |
42 | 43 | === New features in 1.14 === |
43 | 44 | |
— | — | @@ -134,7 +135,10 @@ |
135 | 136 | * Avoid recursive crazy expansions in section edit comments for pages which |
136 | 137 | contain '/*' in the title |
137 | 138 | * Fix excessive memory usage when parsing pages with lots of links |
| 139 | +* $wgSpamRegex now matches the edit summary and page move descriptions in |
| 140 | + addition to body text. |
138 | 141 | |
| 142 | + |
139 | 143 | === API changes in 1.14 === |
140 | 144 | |
141 | 145 | * Registration time of users registered before the DB field was created is now |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -733,7 +733,7 @@ |
734 | 734 | * @return one of the constants describing the result |
735 | 735 | */ |
736 | 736 | function internalAttemptSave( &$result, $bot = false ) { |
737 | | - global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser; |
| 737 | + global $wgFilterCallback, $wgUser, $wgOut, $wgParser; |
738 | 738 | global $wgMaxArticleSize; |
739 | 739 | |
740 | 740 | $fname = 'EditPage::attemptSave'; |
— | — | @@ -762,12 +762,15 @@ |
763 | 763 | $this->mMetaData = '' ; |
764 | 764 | |
765 | 765 | # Check for spam |
766 | | - $matches = array(); |
767 | | - if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) { |
768 | | - $result['spam'] = $matches[0]; |
| 766 | + $match = self::matchSpamRegex( $this->summary ); |
| 767 | + if( $match === false ) { |
| 768 | + $match = self::matchSpamRegex( $this->textbox1 ); |
| 769 | + } |
| 770 | + if( $match !== false ) { |
| 771 | + $result['spam'] = $match; |
769 | 772 | $ip = wfGetIP(); |
770 | 773 | $pdbk = $this->mTitle->getPrefixedDBkey(); |
771 | | - $match = str_replace( "\n", '', $matches[0] ); |
| 774 | + $match = str_replace( "\n", '', $match ); |
772 | 775 | wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); |
773 | 776 | wfProfileOut( "$fname-checks" ); |
774 | 777 | wfProfileOut( $fname ); |
— | — | @@ -1022,6 +1025,25 @@ |
1023 | 1026 | wfProfileOut( $fname ); |
1024 | 1027 | return self::AS_END; |
1025 | 1028 | } |
| 1029 | + |
| 1030 | + /** |
| 1031 | + * Check given input text against $wgSpamRegex, and return the text of the first match. |
| 1032 | + * @return mixed -- matching string or false |
| 1033 | + */ |
| 1034 | + public static function matchSpamRegex( $text ) { |
| 1035 | + global $wgSpamRegex; |
| 1036 | + if( $wgSpamRegex ) { |
| 1037 | + // For back compatibility, $wgSpamRegex may be a single string or an array of regexes. |
| 1038 | + $regexes = (array)$wgSpamRegex; |
| 1039 | + foreach( $regexes as $regex ) { |
| 1040 | + $matches = array(); |
| 1041 | + if ( preg_match( $regex, $text, $matches ) ) { |
| 1042 | + return $matches[0]; |
| 1043 | + } |
| 1044 | + } |
| 1045 | + } |
| 1046 | + return false; |
| 1047 | + } |
1026 | 1048 | |
1027 | 1049 | /** |
1028 | 1050 | * Initialise form fields in the object |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2095,9 +2095,17 @@ |
2096 | 2096 | $wgExportAllowListContributors = false ; |
2097 | 2097 | |
2098 | 2098 | |
2099 | | -/** Text matching this regular expression will be recognised as spam |
2100 | | - * See http://en.wikipedia.org/wiki/Regular_expression */ |
2101 | | -$wgSpamRegex = false; |
| 2099 | +/** |
| 2100 | + * Edits matching these regular expressions in body text or edit summary |
| 2101 | + * will be recognised as spam and rejected automatically. |
| 2102 | + * |
| 2103 | + * There's no administrator override on-wiki, so be careful what you set. :) |
| 2104 | + * May be an array of regexes or a single string for backwards compatibility. |
| 2105 | + * |
| 2106 | + * See http://en.wikipedia.org/wiki/Regular_expression |
| 2107 | + */ |
| 2108 | +$wgSpamRegex = array(); |
| 2109 | + |
2102 | 2110 | /** Similarly you can get a function to do the job. The function will be given |
2103 | 2111 | * the following args: |
2104 | 2112 | * - a Title object for the article the edit is made on |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -2500,6 +2500,12 @@ |
2501 | 2501 | $nt->getUserPermissionsErrors('edit', $wgUser)); |
2502 | 2502 | } |
2503 | 2503 | |
| 2504 | + $match = EditPage::matchSpamRegex( $reason ); |
| 2505 | + if( $match !== false ) { |
| 2506 | + // This is kind of lame, won't display nice |
| 2507 | + $errors[] = array('spamprotectiontext'); |
| 2508 | + } |
| 2509 | + |
2504 | 2510 | global $wgUser; |
2505 | 2511 | $err = null; |
2506 | 2512 | if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { |