r74157 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74156‎ | r74157 | r74158 >
Date:21:38, 2 October 2010
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Fix to r74152: do not check the url when not provided.
Do not piggyback $isspam and the return value. They have different meanings.
Modified paths:
  • /trunk/extensions/ArticleComments/ArticleComments.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleComments/ArticleComments.php
@@ -316,7 +316,7 @@
317317 if ( !$commenterName ) $messages[] = wfMsgForContent(
318318 'article-comments-required-field', wfMsgForContent( 'article-comments-name-string' ) );
319319
320 - if ( !preg_match( "/^(" . wfUrlProtocols() . ')' . Parser::EXT_LINK_URL_CLASS . '+$/', $commenterURL ) )
 320+ if ( ( $commenterURL != '' ) && !preg_match( "/^(" . wfUrlProtocols() . ')' . Parser::EXT_LINK_URL_CLASS . '+$/', $commenterURL ) )
321321 $messages[] = wfMsgForContent(
322322 'article-comments-invalid-field', wfMsgForContent( 'article-comments-url-string' ), $commenterURL );
323323
@@ -450,17 +450,23 @@
451451 * @param Boolean $isspam Whether the comment is spam (passed by reference)
452452 * @return Boolean Always true to indicate other hooking methods may continue to check for spam.
453453 */
454 -function defaultArticleCommentSpamCheck( $comment, $commenterName, $commenterURL, $isspam ) {
 454+function defaultArticleCommentSpamCheck( $comment, $commenterName, $commenterURL, &$isspam ) {
455455
456 - # Short-circuit if spam has already been determined
457 - if ( $isspam ) return true;
 456+ if ( $isspam ) {
 457+ # This module only marks comments as spam (other modules may unspam)
 458+ return true;
 459+ }
 460+
458461 $fields = array( $comment, $commenterName, $commenterURL );
459462
460463 # Run everything through $wgSpamRegex if it has been specified
461464 global $wgSpamRegex;
462465 if ( $wgSpamRegex ) {
463466 foreach ( $fields as $field ) {
464 - if ( preg_match( $wgSpamRegex, $field ) ) return $isspam = true;
 467+ if ( preg_match( $wgSpamRegex, $field ) ) {
 468+ $isspam = true;
 469+ return true;
 470+ }
465471 }
466472 }
467473
@@ -470,21 +476,33 @@
471477 '%<a\\s+[^>]*href\\s*=\\s*[\'"]?\\s*(https?|ftp)://%smi'
472478 );
473479 foreach ( $spampatterns as $sp ) {
474 - foreach ( array( $comment, $commenterName, $commenterURL ) as $field ) {
475 - if ( preg_match( $sp, $field ) ) return $isspam = true;
 480+ foreach ( $fields as $field ) {
 481+ if ( preg_match( $sp, $field ) ) { echo "Is spam! ";
 482+ $isspam = true;
 483+ return true;
 484+ }
476485 }
477486 }
478487
479488 # Check for bad input for commenterName (seems to be a popular spam location)
 489+ # These patterns are more general than those above
480490 $spampatterns = array(
481491 '%<a\\s+%smi',
482492 '%(https?|ftp)://%smi',
483493 '%(\\n|\\r)%smi'
484494 );
485 - foreach ( $spampatterns as $sp ) if ( preg_match( $sp, $commenterName ) ) return $isspam = true;
 495+ foreach ( $spampatterns as $sp ) {
 496+ if ( preg_match( $sp, $commenterName ) ) {
 497+ $isspam = true;
 498+ return true;
 499+ }
 500+ }
486501
487502 # Fail for length violations
488 - if ( strlen( $commenterName ) > 255 || strlen( $commenterURL ) > 300 ) return $isspam = true;
 503+ if ( strlen( $commenterName ) > 255 || strlen( $commenterURL ) > 300 ) {
 504+ $isspam = true;
 505+ return true;
 506+ }
489507
490508 # We made it this far, leave $isspam alone and give other implementors a chance.
491509 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r74180Remove r74157 debug output (thanks Brion)platonides23:50, 2 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74152Always use doEdit()....platonides21:13, 2 October 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   23:45, 2 October 2010

Stray debug output?

+            if ( preg_match( $sp, $field ) ) { echo "Is spam! ";
#Comment by Platonides (talk | contribs)   23:51, 2 October 2010

Ouch yes. Fixed in r74180.

Status & tagging log