r45813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45812‎ | r45813 | r45814 >
Date:21:50, 16 January 2009
Author:werdna
Status:deferred
Tags:
Comment:
Add new action to Abuse Filter -- tagging.
Modified paths:
  • /branches/change-tagging/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)
  • /branches/change-tagging/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php (modified) (history)
  • /branches/change-tagging/extensions/AbuseFilter/SpecialAbuseFilter.php (modified) (history)
  • /branches/change-tagging/extensions/AbuseFilter/edit.js (modified) (history)

Diff [purge]

Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php
@@ -44,6 +44,7 @@
4545 $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';
4646 $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onSchemaUpdate';
4747 $wgHooks['AbortDeleteQueueNominate'][] = 'AbuseFilterHooks::onAbortDeleteQueueNominate';
 48+$wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
4849
4950 $wgAvailableRights[] = 'abusefilter-modify';
5051 $wgAvailableRights[] = 'abusefilter-log-detail';
@@ -51,7 +52,7 @@
5253 $wgAvailableRights[] = 'abusefilter-log';
5354 $wgAvailableRights[] = 'abusefilter-private';
5455
55 -$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn', 'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock' );
 56+$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn', 'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock', 'tag' );
5657
5758 // Conditions take about 4ms to check, so 100 conditions would take 400ms
5859 // Currently, has no effect.
Index: branches/change-tagging/extensions/AbuseFilter/SpecialAbuseFilter.php
@@ -517,9 +517,22 @@
518518 $warnMsg = empty($setActions['warn']) ? 'abusefilter-warning' : $actions['warn']['parameters'][0];
519519 $warnFields['abusefilter-edit-warn-message'] = Xml::input( 'wpFilterWarnMessage', 45, $warnMsg );
520520 $output .= Xml::tags( 'p', null, Xml::buildForm( $warnFields ) );
 521+
 522+ // Special case: tagging
 523+ if ($setActions['tag']) {
 524+ $tags = $actions['tag']['parameters'];
 525+ } else {
 526+ $tags = array();
 527+ }
 528+
 529+ $checkbox = Xml::checkLabel( wfMsg('abusefilter-edit-action-tag'), 'wpFilterActionTag', 'wpFilterActionTag', $setActions['tag'] );
 530+ $output .= Xml::tags( 'p', null, $checkbox );
 531+
 532+ $tagFields['abusefilter-edit-tag-tag'] = Xml::textarea( 'wpFilterTags', implode( "\n", $tags ) );
 533+ $output .= Xml::tags( 'p', null, Xml::buildForm( $tagFields ) );
521534
522535 // The remainder are just toggles
523 - $remainingActions = array_diff( $wgAbuseFilterAvailableActions, array( 'flag', 'throttle', 'warn' ) );
 536+ $remainingActions = array_diff( $wgAbuseFilterAvailableActions, array( 'flag', 'throttle', 'warn', 'tag' ) );
524537
525538 foreach( $remainingActions as $action ) {
526539 $message = 'abusefilter-edit-action-'.$action;
@@ -661,6 +674,8 @@
662675 $parameters = array_merge( $parameters, $throttleGroups );
663676 } elseif ($action == 'warn') {
664677 $parameters[0] = $wgRequest->getVal( 'wpFilterWarnMessage' );
 678+ } elseif ($action == 'tag') {
 679+ $parameters = explode("\n", $wgRequest->getText( 'wpFilterTags' ) );
665680 }
666681
667682 $thisAction = array( 'action' => $action, 'parameters' => $parameters );
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.class.php
@@ -10,6 +10,7 @@
1111 public static $condLimitEnabled = true;
1212 public static $condCount = 0;
1313 public static $filters = array();
 14+ public static $tagsToSet = array();
1415
1516 public static function generateUserVars( $user ) {
1617 $vars = array();
@@ -354,26 +355,26 @@
355356 foreach( $parameters as $throttleType ) {
356357 $hitThrottle = $hitThrottle || self::isThrottled( $throttleId, $throttleType, $title, $rateCount, $ratePeriod );
357358 }
358 -
 359+
359360 return $hitThrottle;
360361 break;
361362 case 'degroup':
362363 wfLoadExtensionMessages( 'AbuseFilter' );
363 -
 364+
364365 global $wgUser;
365366 if (!$wgUser->isAnon()) {
366367 // Remove all groups from the user. Ouch.
367368 $groups = $wgUser->getGroups();
368 -
 369+
369370 foreach( $groups as $group ) {
370371 $wgUser->removeGroup( $group );
371372 }
372 -
 373+
373374 $display .= wfMsgNoTrans( 'abusefilter-degrouped', $rule_desc ) ."<br />\n";
374 -
 375+
375376 // Log it.
376377 $log = new LogPage( 'rights' );
377 -
 378+
378379 $log->addEntry( 'rights',
379380 $wgUser->getUserPage(),
380381 wfMsgForContent( 'abusefilter-degroupreason', $rule_desc ),
@@ -383,16 +384,16 @@
384385 )
385386 , self::getFilterUser() );
386387 }
387 -
 388+
388389 break;
389390 case 'blockautopromote':
390391 global $wgUser, $wgMemc;
391392 if (!$wgUser->isAnon()) {
392393 wfLoadExtensionMessages( 'AbuseFilter' );
393 -
 394+
394395 $blockPeriod = (int)mt_rand( 3*86400, 7*86400 ); // Block for 3-7 days.
395396 $wgMemc->set( self::autoPromoteBlockKey( $wgUser ), true, $blockPeriod );
396 -
 397+
397398 $display .= wfMsgNoTrans( 'abusefilter-autopromote-blocked', $rule_desc ) ."<br />\n";
398399 }
399400 break;
@@ -400,6 +401,17 @@
401402 case 'flag':
402403 // Do nothing. Here for completeness.
403404 break;
 405+
 406+ case 'tag':
 407+ // Mark with a tag on recentchanges.
 408+ global $wgUser;
 409+
 410+ $actionID = implode( '-', array(
 411+ $title->getPrefixedText(), $wgUser->getName(), $vars['ACTION']
 412+ ) );
 413+
 414+ AbuseFilter::$tagsToSet[$actionID] = $parameters;
 415+ break;
404416 }
405417
406418 return true;
Index: branches/change-tagging/extensions/AbuseFilter/edit.js
@@ -15,9 +15,11 @@
1616 if (response.match( /OK/ )) {
1717 // Successful
1818 changeText( el, 'No syntax errors.' );
 19+ el.syntaxOk = true;
1920 } else {
2021 var error = response.substr(4);
2122 changeText( el, 'Syntax error: '+error );
 23+ el.syntaxOk = false;
2224 }
2325 }
2426 function addText() {
@@ -51,6 +53,9 @@
5254
5355 addOnloadHook( function() {
5456 addHandler( document.getElementById( 'wpFilterRules' ), 'keyup', function() {
55 - document.getElementById( 'mw-abusefilter-syntaxresult' ).style.display = 'none';
 57+ el = document.getElementById( 'mw-abusefilter-syntaxresult' );
 58+ if (el.syntaxOk == true) {
 59+ el.style.display = 'none';
 60+ }
5661 } );
5762 } );
\ No newline at end of file
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -149,11 +149,13 @@
150150 'abusefilter-edit-action-block' => 'Block the user and/or IP address from editing',
151151 'abusefilter-edit-action-throttle' => 'Trigger actions only if the user trips a rate limit',
152152 'abusefilter-edit-action-rangeblock' => 'Block the /16 range from which the user originates.',
 153+ 'abusefilter-edit-action-tag' => 'Tag the edit for further review.',
153154 'abusefilter-edit-throttle-count' => 'Number of actions to allow:',
154155 'abusefilter-edit-throttle-period' => 'Period of time:',
155156 'abusefilter-edit-throttle-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
156157 'abusefilter-edit-throttle-groups' => "Group throttle by:\n:''(one per line, combine with commas)''",
157158 'abusefilter-edit-warn-message' => 'System message to use for warning:',
 159+ 'abusefilter-edit-tag-tag' => 'Tags to apply (one per line) :',
158160 'abusefilter-edit-denied' => "You may not view details of this filter, because it is hidden from public view",
159161 'abusefilter-edit-main' => 'Filter parameters',
160162 'abusefilter-edit-done-subtitle' => 'Filter edited',
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -161,4 +161,18 @@
162162
163163 return $filter_result == '' || $filter_result === true;
164164 }
 165+
 166+ public static function onRecentChangeSave( $recentChange ) {
 167+ $title = Title::makeTitle( $recentChange->mAttribs['rc_namespace'], $recentChange->mAttribs['rc_title'] );
 168+ $action = $recentChange->mAttribs['rc_log_type'] ? $recentChange->mAttribs['rc_log_type'] : 'edit';
 169+ $actionID = implode( '-', array(
 170+ $title->getPrefixedText(), $recentChange->mAttribs['rc_user_text'], $action
 171+ ) );
 172+
 173+ if ( !empty( AbuseFilter::$tagsToSet[$actionID] ) && count( $tags = AbuseFilter::$tagsToSet[$actionID]) ) {
 174+ ChangeTags::addTags( $tags, $recentChange->mAttribs['rc_id'], $recentChange->mAttribs['rc_logid'], $recentChange->mAttribs['rc_this_oldid'] );
 175+ }
 176+
 177+ return true;
 178+ }
165179 }

Status & tagging log