Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -212,37 +212,46 @@ |
213 | 213 | private function findAbuse( &$value, $pageId ) { |
214 | 214 | // Respect $wgSpamRegex |
215 | 215 | global $wgSpamRegex; |
216 | | - // In older versions, $wgSpamRegex may be a single string rather than |
217 | | - // an array of regexes, so make it compatible. |
218 | | - $regexes = ( array ) $wgSpamRegex; |
219 | | - foreach ( $regexes as $regex ) { |
220 | | - if ( preg_match( $regex, $value ) ) { |
221 | | - return true; |
| 216 | + if ( ( is_array( $wgSpamRegex ) && count( $wgSpamRegex ) > 0 ) |
| 217 | + || ( is_string( $wgSpamRegex ) && strlen( $wgSpamRegex ) > 0 ) ) { |
| 218 | + // In older versions, $wgSpamRegex may be a single string rather than |
| 219 | + // an array of regexes, so make it compatible. |
| 220 | + $regexes = ( array ) $wgSpamRegex; |
| 221 | + foreach ( $regexes as $regex ) { |
| 222 | + if ( preg_match( $regex, $value ) ) { |
| 223 | + return true; |
| 224 | + } |
222 | 225 | } |
223 | 226 | } |
224 | 227 | |
225 | 228 | // Create a fake title so we can pretend this is an article edit |
226 | 229 | $title = Title::newFromText( '__article_feedback_5__' ); |
227 | 230 | |
228 | | - // Check SpamBlacklist |
229 | | - $spam = wfSpamBlacklistObject(); |
230 | | - $ret = $spam->filter( $title, $value, '' ); |
231 | | - if ( $ret !== false ) { |
232 | | - return true; |
| 231 | + // Check SpamBlacklist, if installed |
| 232 | + if ( function_exists( 'wfSpamBlacklistObject' ) ) { |
| 233 | + $spam = wfSpamBlacklistObject(); |
| 234 | + $ret = $spam->filter( $title, $value, '' ); |
| 235 | + if ( $ret !== false ) { |
| 236 | + return true; |
| 237 | + } |
233 | 238 | } |
234 | 239 | |
235 | | - // Check the abuse filter |
236 | | - global $wgUser; |
237 | | - $vars = new AbuseFilterVariableHolder; |
238 | | - $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) ); |
239 | | - $vars->addHolder( AbuseFilter::generateTitleVars( $title, 'FEEDBACK' ) ); |
240 | | - $vars->setVar( 'SUMMARY', 'Article Feedback 5' ); |
241 | | - $vars->setVar( 'ACTION', 'feedback' ); |
242 | | - $vars->setVar( 'old_wikitext', '' ); |
243 | | - $vars->setVar( 'new_wikitext', $value ); |
244 | | - $vars->addHolder( AbuseFilter::getEditVars( $title ) ); |
245 | | - $filter_result = AbuseFilter::filterAction( $vars, $title ); |
246 | | - return $filter_result != '' && $filter_result !== true; |
| 240 | + // Check AbuseFilter, if installed |
| 241 | + if ( class_exists( 'AbuseFilter' ) ) { |
| 242 | + global $wgUser; |
| 243 | + $vars = new AbuseFilterVariableHolder; |
| 244 | + $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) ); |
| 245 | + $vars->addHolder( AbuseFilter::generateTitleVars( $title, 'FEEDBACK' ) ); |
| 246 | + $vars->setVar( 'SUMMARY', 'Article Feedback 5' ); |
| 247 | + $vars->setVar( 'ACTION', 'feedback' ); |
| 248 | + $vars->setVar( 'old_wikitext', '' ); |
| 249 | + $vars->setVar( 'new_wikitext', $value ); |
| 250 | + $vars->addHolder( AbuseFilter::getEditVars( $title ) ); |
| 251 | + $filter_result = AbuseFilter::filterAction( $vars, $title ); |
| 252 | + return $filter_result != '' && $filter_result !== true; |
| 253 | + } |
| 254 | + |
| 255 | + return false; |
247 | 256 | } |
248 | 257 | |
249 | 258 | /** |