Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.php |
— | — | @@ -44,6 +44,7 @@ |
45 | 45 | $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete'; |
46 | 46 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onSchemaUpdate'; |
47 | 47 | $wgHooks['AbortDeleteQueueNominate'][] = 'AbuseFilterHooks::onAbortDeleteQueueNominate'; |
| 48 | +$wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave'; |
48 | 49 | |
49 | 50 | $wgAvailableRights[] = 'abusefilter-modify'; |
50 | 51 | $wgAvailableRights[] = 'abusefilter-log-detail'; |
— | — | @@ -51,7 +52,7 @@ |
52 | 53 | $wgAvailableRights[] = 'abusefilter-log'; |
53 | 54 | $wgAvailableRights[] = 'abusefilter-private'; |
54 | 55 | |
55 | | -$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn', 'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock' ); |
| 56 | +$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn', 'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock', 'tag' ); |
56 | 57 | |
57 | 58 | // Conditions take about 4ms to check, so 100 conditions would take 400ms |
58 | 59 | // Currently, has no effect. |
Index: branches/change-tagging/extensions/AbuseFilter/SpecialAbuseFilter.php |
— | — | @@ -517,9 +517,22 @@ |
518 | 518 | $warnMsg = empty($setActions['warn']) ? 'abusefilter-warning' : $actions['warn']['parameters'][0]; |
519 | 519 | $warnFields['abusefilter-edit-warn-message'] = Xml::input( 'wpFilterWarnMessage', 45, $warnMsg ); |
520 | 520 | $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 ) ); |
521 | 534 | |
522 | 535 | // The remainder are just toggles |
523 | | - $remainingActions = array_diff( $wgAbuseFilterAvailableActions, array( 'flag', 'throttle', 'warn' ) ); |
| 536 | + $remainingActions = array_diff( $wgAbuseFilterAvailableActions, array( 'flag', 'throttle', 'warn', 'tag' ) ); |
524 | 537 | |
525 | 538 | foreach( $remainingActions as $action ) { |
526 | 539 | $message = 'abusefilter-edit-action-'.$action; |
— | — | @@ -661,6 +674,8 @@ |
662 | 675 | $parameters = array_merge( $parameters, $throttleGroups ); |
663 | 676 | } elseif ($action == 'warn') { |
664 | 677 | $parameters[0] = $wgRequest->getVal( 'wpFilterWarnMessage' ); |
| 678 | + } elseif ($action == 'tag') { |
| 679 | + $parameters = explode("\n", $wgRequest->getText( 'wpFilterTags' ) ); |
665 | 680 | } |
666 | 681 | |
667 | 682 | $thisAction = array( 'action' => $action, 'parameters' => $parameters ); |
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | public static $condLimitEnabled = true; |
12 | 12 | public static $condCount = 0; |
13 | 13 | public static $filters = array(); |
| 14 | + public static $tagsToSet = array(); |
14 | 15 | |
15 | 16 | public static function generateUserVars( $user ) { |
16 | 17 | $vars = array(); |
— | — | @@ -354,26 +355,26 @@ |
355 | 356 | foreach( $parameters as $throttleType ) { |
356 | 357 | $hitThrottle = $hitThrottle || self::isThrottled( $throttleId, $throttleType, $title, $rateCount, $ratePeriod ); |
357 | 358 | } |
358 | | - |
| 359 | + |
359 | 360 | return $hitThrottle; |
360 | 361 | break; |
361 | 362 | case 'degroup': |
362 | 363 | wfLoadExtensionMessages( 'AbuseFilter' ); |
363 | | - |
| 364 | + |
364 | 365 | global $wgUser; |
365 | 366 | if (!$wgUser->isAnon()) { |
366 | 367 | // Remove all groups from the user. Ouch. |
367 | 368 | $groups = $wgUser->getGroups(); |
368 | | - |
| 369 | + |
369 | 370 | foreach( $groups as $group ) { |
370 | 371 | $wgUser->removeGroup( $group ); |
371 | 372 | } |
372 | | - |
| 373 | + |
373 | 374 | $display .= wfMsgNoTrans( 'abusefilter-degrouped', $rule_desc ) ."<br />\n"; |
374 | | - |
| 375 | + |
375 | 376 | // Log it. |
376 | 377 | $log = new LogPage( 'rights' ); |
377 | | - |
| 378 | + |
378 | 379 | $log->addEntry( 'rights', |
379 | 380 | $wgUser->getUserPage(), |
380 | 381 | wfMsgForContent( 'abusefilter-degroupreason', $rule_desc ), |
— | — | @@ -383,16 +384,16 @@ |
384 | 385 | ) |
385 | 386 | , self::getFilterUser() ); |
386 | 387 | } |
387 | | - |
| 388 | + |
388 | 389 | break; |
389 | 390 | case 'blockautopromote': |
390 | 391 | global $wgUser, $wgMemc; |
391 | 392 | if (!$wgUser->isAnon()) { |
392 | 393 | wfLoadExtensionMessages( 'AbuseFilter' ); |
393 | | - |
| 394 | + |
394 | 395 | $blockPeriod = (int)mt_rand( 3*86400, 7*86400 ); // Block for 3-7 days. |
395 | 396 | $wgMemc->set( self::autoPromoteBlockKey( $wgUser ), true, $blockPeriod ); |
396 | | - |
| 397 | + |
397 | 398 | $display .= wfMsgNoTrans( 'abusefilter-autopromote-blocked', $rule_desc ) ."<br />\n"; |
398 | 399 | } |
399 | 400 | break; |
— | — | @@ -400,6 +401,17 @@ |
401 | 402 | case 'flag': |
402 | 403 | // Do nothing. Here for completeness. |
403 | 404 | 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; |
404 | 416 | } |
405 | 417 | |
406 | 418 | return true; |
Index: branches/change-tagging/extensions/AbuseFilter/edit.js |
— | — | @@ -15,9 +15,11 @@ |
16 | 16 | if (response.match( /OK/ )) { |
17 | 17 | // Successful |
18 | 18 | changeText( el, 'No syntax errors.' ); |
| 19 | + el.syntaxOk = true; |
19 | 20 | } else { |
20 | 21 | var error = response.substr(4); |
21 | 22 | changeText( el, 'Syntax error: '+error ); |
| 23 | + el.syntaxOk = false; |
22 | 24 | } |
23 | 25 | } |
24 | 26 | function addText() { |
— | — | @@ -51,6 +53,9 @@ |
52 | 54 | |
53 | 55 | addOnloadHook( function() { |
54 | 56 | 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 | + } |
56 | 61 | } ); |
57 | 62 | } ); |
\ No newline at end of file |
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.i18n.php |
— | — | @@ -149,11 +149,13 @@ |
150 | 150 | 'abusefilter-edit-action-block' => 'Block the user and/or IP address from editing', |
151 | 151 | 'abusefilter-edit-action-throttle' => 'Trigger actions only if the user trips a rate limit', |
152 | 152 | 'abusefilter-edit-action-rangeblock' => 'Block the /16 range from which the user originates.', |
| 153 | + 'abusefilter-edit-action-tag' => 'Tag the edit for further review.', |
153 | 154 | 'abusefilter-edit-throttle-count' => 'Number of actions to allow:', |
154 | 155 | 'abusefilter-edit-throttle-period' => 'Period of time:', |
155 | 156 | 'abusefilter-edit-throttle-seconds' => '$1 {{PLURAL:$1|second|seconds}}', |
156 | 157 | 'abusefilter-edit-throttle-groups' => "Group throttle by:\n:''(one per line, combine with commas)''", |
157 | 158 | 'abusefilter-edit-warn-message' => 'System message to use for warning:', |
| 159 | + 'abusefilter-edit-tag-tag' => 'Tags to apply (one per line) :', |
158 | 160 | 'abusefilter-edit-denied' => "You may not view details of this filter, because it is hidden from public view", |
159 | 161 | 'abusefilter-edit-main' => 'Filter parameters', |
160 | 162 | 'abusefilter-edit-done-subtitle' => 'Filter edited', |
Index: branches/change-tagging/extensions/AbuseFilter/AbuseFilter.hooks.php |
— | — | @@ -161,4 +161,18 @@ |
162 | 162 | |
163 | 163 | return $filter_result == '' || $filter_result === true; |
164 | 164 | } |
| 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 | + } |
165 | 179 | } |