r108812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108811‎ | r108812 | r108813 >
Date:15:04, 13 January 2012
Author:rsterbin
Status:ok (Comments)
Tags:
Comment:
Do the , SpamBlacklist, and AbuseFilter checks only when those are set up (followup to r108778)
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -212,37 +212,46 @@
213213 private function findAbuse( &$value, $pageId ) {
214214 // Respect $wgSpamRegex
215215 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+ }
222225 }
223226 }
224227
225228 // Create a fake title so we can pretend this is an article edit
226229 $title = Title::newFromText( '__article_feedback_5__' );
227230
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+ }
233238 }
234239
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;
247256 }
248257
249258 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108778Added spam and abuse filtering:...rsterbin23:16, 12 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   16:58, 13 January 2012

svn ci -m?

#Comment by Rsterbin (talk | contribs)   17:57, 13 January 2012

Yeah, that was supposed to be $wgSpamRegex

Status & tagging log