Revision: 46091
Author: werdna
Date: 2009-01-23 19:23:44 +0000 (Fri, 23 Jan 2009)
Log Message:
-----------
Remove dependency on change-tagging being branch-merged to trunk for now, and
fix a few miscellaneous related bugs that came up in final testing.
Modified Paths:
--------------
trunk/extensions/AbuseFilter/AbuseFilter.class.php
trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
trunk/extensions/AbuseFilter/AbuseFilter.php
trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
Modified: trunk/extensions/AbuseFilter/AbuseFilter.class.php
===================================================================
--- trunk/extensions/AbuseFilter/AbuseFilter.class.php 2009-01-23 19:23:19 UTC
(rev 46090)
+++ trunk/extensions/AbuseFilter/AbuseFilter.class.php 2009-01-23 19:23:44 UTC
(rev 46091)
@@ -197,6 +197,26 @@
foreach( $actionsByFilter as $filter => $actions ) {
// Special-case handling for warnings.
+
+ if ( !empty( $actions['throttle'] ) ) {
+ $parameters =
$actions['throttle']['parameters'];
+ $throttleId = array_shift( $parameters );
+ list( $rateCount, $ratePeriod ) = explode( ',',
array_shift( $parameters ) );
+
+ $hitThrottle = false;
+
+ // The rest are throttle-types.
+ foreach( $parameters as $throttleType ) {
+ $hitThrottle = $hitThrottle ||
self::isThrottled( $throttleId, $throttleType, $title, $rateCount, $ratePeriod
);
+ }
+
+ unset( $actions['throttle'] );
+ if (!$hitThrottle) {
+ $actionsTaken[$filter][] = 'throttle';
+ continue;
+ }
+ }
+
if ( !empty( $actions['warn'] ) ) {
$parameters = $actions['warn']['parameters'];
$warnKey =
'abusefilter-warned-'.$title->getPrefixedText();
@@ -207,7 +227,7 @@
$msg = ( !empty($parameters[0]) &&
strlen($parameters[0]) ) ? $parameters[0] : 'abusefilter-warning';
$messages[] = wfMsgNoTrans( $msg,
self::$filters[$filter]->af_public_comments ) . "<br />\n";
- $actionsTaken[] = 'warn';
+ $actionsTaken[$filter][] = 'warn';
continue; // Don't do anything else.
} else {
@@ -218,25 +238,6 @@
unset( $actions['warn'] );
}
- if ( !empty( $actions['throttle'] ) ) {
- $parameters =
$actions['throttle']['parameters'];
- $throttleId = array_shift( $parameters );
- list( $rateCount, $ratePeriod ) = explode( ',',
array_shift( $parameters ) );
-
- $hitThrottle = false;
-
- // The rest are throttle-types.
- foreach( $parameters as $throttleType ) {
- $hitThrottle = $hitThrottle ||
self::isThrottled( $throttleId, $throttleType, $title, $rateCount, $ratePeriod
);
- }
-
- unset( $actions['throttle'] );
- if (!$hitThrottle) {
- $actionsTaken[] = 'throttle';
- continue;
- }
- }
-
// Do the rest of the actions
foreach( $actions as $action => $info ) {
$newMsg = self::takeConsequenceAction( $action,
$info['parameters'], $title, $vars, self::$filters[$filter]->af_public_comments
);
@@ -259,7 +260,6 @@
// Short-cut any remaining code if no filters were hit.
if ( count( array_filter( $filter_matched) ) == 0 ) {
- die( var_dump( $filter_matched ) );
return true;
}
@@ -284,7 +284,7 @@
$thisLog = $log_template;
$thisLog['afl_filter'] = $filter;
$thisLog['afl_action'] = $action;
- $thisLog['afl_actions'] = implode( ',',
$actions_taken[$filter] );
+ $thisLog['afl_actions'] = implode( ',', $actions );
// Don't log if we were only throttling.
if ($thisLog['afl_actions'] != 'throttle') {
@@ -418,16 +418,16 @@
// Do nothing. Here for completeness.
break;
- case 'tag':
- // Mark with a tag on recentchanges.
- global $wgUser;
-
- $actionID = implode( '-', array(
- $title->getPrefixedText(),
$wgUser->getName(), $vars['ACTION']
- ) );
-
- AbuseFilter::$tagsToSet[$actionID] =
$parameters;
- break;
+// case 'tag':
+// // Mark with a tag on recentchanges.
+// global $wgUser;
+//
+// $actionID = implode( '-', array(
+// $title->getPrefixedText(),
$wgUser->getName(), $vars['ACTION']
+// ) );
+//
+// AbuseFilter::$tagsToSet[$actionID] =
$parameters;
+// break;
}
return $display;
@@ -442,7 +442,6 @@
if ($count > 0) {
$wgMemc->incr( $key );
if ($count > $rateCount) {
- $wgMemc->delete( $key );
return true; // THROTTLED
}
} else {
Modified: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
===================================================================
--- trunk/extensions/AbuseFilter/AbuseFilter.hooks.php 2009-01-23 19:23:19 UTC
(rev 46090)
+++ trunk/extensions/AbuseFilter/AbuseFilter.hooks.php 2009-01-23 19:23:44 UTC
(rev 46091)
@@ -165,30 +165,31 @@
return $filter_result == '' || $filter_result === true;
}
- public static function onRecentChangeSave( $recentChange ) {
- $title = Title::makeTitle(
$recentChange->mAttribs['rc_namespace'], $recentChange->mAttribs['rc_title'] );
- $action = $recentChange->mAttribs['rc_log_type'] ?
$recentChange->mAttribs['rc_log_type'] : 'edit';
- $actionID = implode( '-', array(
- $title->getPrefixedText(),
$recentChange->mAttribs['rc_user_text'], $action
- ) );
+// Commented out to avoid trunk changes for now.
+// public static function onRecentChangeSave( $recentChange ) {
+// $title = Title::makeTitle(
$recentChange->mAttribs['rc_namespace'], $recentChange->mAttribs['rc_title'] );
+// $action = $recentChange->mAttribs['rc_log_type'] ?
$recentChange->mAttribs['rc_log_type'] : 'edit';
+// $actionID = implode( '-', array(
+// $title->getPrefixedText(),
$recentChange->mAttribs['rc_user_text'], $action
+// ) );
+//
+// if ( !empty( AbuseFilter::$tagsToSet[$actionID] ) && count(
$tags = AbuseFilter::$tagsToSet[$actionID]) ) {
+// ChangeTags::addTags( $tags,
$recentChange->mAttribs['rc_id'], $recentChange->mAttribs['rc_this_oldid'],
$recentChange->mAttribs['rc_logid'] );
+// }
+//
+// return true;
+// }
- if ( !empty( AbuseFilter::$tagsToSet[$actionID] ) && count(
$tags = AbuseFilter::$tagsToSet[$actionID]) ) {
- ChangeTags::addTags( $tags,
$recentChange->mAttribs['rc_id'], $recentChange->mAttribs['rc_this_oldid'],
$recentChange->mAttribs['rc_logid'] );
- }
-
- return true;
- }
-
- public static function onListDefinedTags( &$emptyTags ) {
- ## This is a pretty awful hack.
- $dbr = wfGetDB( DB_SLAVE );
-
- $res = $dbr->select( 'abuse_filter_action', 'afa_parameters',
array( 'afa_consequence' => 'tag' ), __METHOD__ );
-
- while( $row = $res->fetchObject() ) {
- $emptyTags = array_filter( array_merge( explode( "\n",
$row->afa_parameters ), $emptyTags ) );
- }
-
- return true;
- }
+// public static function onListDefinedTags( &$emptyTags ) {
+// ## This is a pretty awful hack.
+// $dbr = wfGetDB( DB_SLAVE );
+//
+// $res = $dbr->select( 'abuse_filter_action', 'afa_parameters',
array( 'afa_consequence' => 'tag' ), __METHOD__ );
+//
+// while( $row = $res->fetchObject() ) {
+// $emptyTags = array_filter( array_merge( explode( "\n",
$row->afa_parameters ), $emptyTags ) );
+// }
+//
+// return true;
+// }
}
Modified: trunk/extensions/AbuseFilter/AbuseFilter.php
===================================================================
--- trunk/extensions/AbuseFilter/AbuseFilter.php 2009-01-23 19:23:19 UTC
(rev 46090)
+++ trunk/extensions/AbuseFilter/AbuseFilter.php 2009-01-23 19:23:44 UTC
(rev 46091)
@@ -49,8 +49,8 @@
$wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';
$wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onSchemaUpdate';
$wgHooks['AbortDeleteQueueNominate'][] =
'AbuseFilterHooks::onAbortDeleteQueueNominate';
-$wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
-$wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags';
+// $wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
+// $wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags';
$wgAvailableRights[] = 'abusefilter-modify';
$wgAvailableRights[] = 'abusefilter-log-detail';
@@ -58,7 +58,7 @@
$wgAvailableRights[] = 'abusefilter-log';
$wgAvailableRights[] = 'abusefilter-private';
-$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn',
'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock', 'tag' );
+$wgAbuseFilterAvailableActions = array( 'flag', 'throttle', 'warn',
'disallow', 'blockautopromote', 'block', 'degroup', 'rangeblock' /*, 'tag'
Disabled for now to avoid trunk changes. */ );
// Conditions take about 4ms to check, so 100 conditions would take 400ms
// Currently, has no effect.
Modified: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
===================================================================
--- trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php 2009-01-23
19:23:19 UTC (rev 46090)
+++ trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php 2009-01-23
19:23:44 UTC (rev 46091)
@@ -109,7 +109,7 @@
// Do the update
$dbw->insert( 'abuse_filter_history', $afh_row,
__METHOD__ );
- $dbw->delete( 'abuse_filter_action', array(
'afa_filter' => $filter, 'afa_consequence' => $deadActions ), __METHOD__ );
+ $dbw->delete( 'abuse_filter_action', array(
'afa_filter' => $filter ), __METHOD__ );
$dbw->insert( 'abuse_filter_action', $actionsRows,
__METHOD__ );
$dbw->commit();
@@ -293,70 +293,80 @@
$output = '';
- // Special case: flagging - always on.
- $checkbox = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-flag' ), 'wpFilterActionFlag', 'wpFilterActionFlag',
true, array( 'disabled' => '1' ) );
- $output .= Xml::tags( 'p', null, $checkbox );
-
- // Special case: throttling
- $throttleSettings = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-throttle' ), 'wpFilterActionThrottle',
'wpFilterActionThrottle', $setActions['throttle'] );
- $throttleFields = array();
-
- if ($setActions['throttle']) {
- array_shift( $actions['throttle']['parameters'] );
- $throttleRate =
explode(',',$actions['throttle']['parameters'][0]);
- $throttleCount = $throttleRate[0];
- $throttlePeriod = $throttleRate[1];
-
- $throttleGroups = implode("\n",
array_slice($actions['throttle']['parameters'], 1 ) );
- } else {
- $throttleCount = 3;
- $throttlePeriod = 60;
-
- $throttleGroups = "user\n";
+ foreach( $wgAbuseFilterAvailableActions as $action ) {
+ $output .= $this->buildConsequenceSelector( $action,
$setActions[$action], @$actions[$action]['parameters'] );
}
- $throttleFields['abusefilter-edit-throttle-count'] =
Xml::input( 'wpFilterThrottleCount', 20, $throttleCount );
- $throttleFields['abusefilter-edit-throttle-period'] = wfMsgExt(
'abusefilter-edit-throttle-seconds', array( 'parseinline', 'replaceafter' ),
array(Xml::input( 'wpFilterThrottlePeriod', 20, $throttlePeriod ) ) );
- $throttleFields['abusefilter-edit-throttle-groups'] =
Xml::textarea( 'wpFilterThrottleGroups', $throttleGroups."\n" );
- $throttleSettings .= Xml::buildForm( $throttleFields );
- $output .= Xml::tags( 'p', null, $throttleSettings );
+ return $output;
+ }
- // Special case: Warning
- $checkbox = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-warn' ), 'wpFilterActionWarn', 'wpFilterActionWarn',
$setActions['warn'] );
- $output .= Xml::tags( 'p', null, $checkbox );
+ function buildConsequenceSelector( $action, $set, $parameters ) {
+ global $wgAbuseFilterAvailableActions;
- $warnMsg = empty($setActions['warn']) ? 'abusefilter-warning' :
$actions['warn']['parameters'][0];
- $warnFields['abusefilter-edit-warn-message'] = Xml::input(
'wpFilterWarnMessage', 45, $warnMsg );
- $output .= Xml::tags( 'p', null, Xml::buildForm( $warnFields )
);
-
- // Special case: tagging
- if ($setActions['tag']) {
- $tags = $actions['tag']['parameters'];
- } else {
- $tags = array();
+ if ( !in_array( $action, $wgAbuseFilterAvailableActions ) ) {
+ return;
}
+
+ switch( $action ) {
+ case 'throttle':
+ $throttleSettings = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-throttle' ), 'wpFilterActionThrottle',
'wpFilterActionThrottle', $set );
+ $throttleFields = array();
- $checkbox = Xml::checkLabel(
wfMsg('abusefilter-edit-action-tag'), 'wpFilterActionTag', 'wpFilterActionTag',
$setActions['tag'] );
- $output .= Xml::tags( 'p', null, $checkbox );
+ if ($set) {
+ array_shift( $parameters );
+ $throttleRate = explode(',',
$parameters[0]);
+ $throttleCount = $throttleRate[0];
+ $throttlePeriod = $throttleRate[1];
- $tagFields['abusefilter-edit-tag-tag'] = Xml::textarea(
'wpFilterTags', implode( "\n", $tags ) );
- $output .= Xml::tags( 'p', null, Xml::buildForm( $tagFields ) );
+ $throttleGroups = implode("\n",
array_slice($parameters, 1 ) );
+ } else {
+ $throttleCount = 3;
+ $throttlePeriod = 60;
- // The remainder are just toggles
- $remainingActions = array_diff( $wgAbuseFilterAvailableActions,
array( 'flag', 'throttle', 'warn', 'tag' ) );
+ $throttleGroups = "user\n";
+ }
- foreach( $remainingActions as $action ) {
- $message = 'abusefilter-edit-action-'.$action;
- $form_field = 'wpFilterAction' . ucfirst($action);
- $status = $setActions[$action];
+
$throttleFields['abusefilter-edit-throttle-count'] = Xml::input(
'wpFilterThrottleCount', 20, $throttleCount );
+
$throttleFields['abusefilter-edit-throttle-period'] = wfMsgExt(
'abusefilter-edit-throttle-seconds', array( 'parseinline', 'replaceafter' ),
array(Xml::input( 'wpFilterThrottlePeriod', 20, $throttlePeriod ) ) );
+
$throttleFields['abusefilter-edit-throttle-groups'] = Xml::textarea(
'wpFilterThrottleGroups', $throttleGroups."\n" );
+ $throttleSettings .= Xml::buildForm(
$throttleFields );
+ return Xml::tags( 'p', null, $throttleSettings
);
+ case 'flag':
+ $checkbox = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-flag' ), 'wpFilterActionFlag', 'wpFilterActionFlag',
true, array( 'disabled' => '1' ) );
+ return Xml::tags( 'p', null, $checkbox );
+ case 'warn':
+ $output = '';
+ $checkbox = Xml::checkLabel( wfMsg(
'abusefilter-edit-action-warn' ), 'wpFilterActionWarn', 'wpFilterActionWarn',
$set );
+ $output .= Xml::tags( 'p', null, $checkbox );
- $thisAction = Xml::checkLabel( wfMsg( $message ),
$form_field, $form_field, $status );
- $thisAction = Xml::tags( 'p', null, $thisAction );
+ $warnMsg = empty($set) ? 'abusefilter-warning'
: $parameters[0];
+ $warnFields['abusefilter-edit-warn-message'] =
Xml::input( 'wpFilterWarnMessage', 45, $warnMsg );
+ $output .= Xml::tags( 'p', null,
Xml::buildForm( $warnFields ) );
+ return $output;
+ // Commented out to avoid trunk changes for now.
+// case 'tag':
+// if ($set) {
+// $tags = $parameters;
+// } else {
+// $tags = array();
+// }
+// $output = '';
+//
+// $checkbox = Xml::checkLabel(
wfMsg('abusefilter-edit-action-tag'), 'wpFilterActionTag', 'wpFilterActionTag',
$set );
+// $output .= Xml::tags( 'p', null, $checkbox );
+//
+// $tagFields['abusefilter-edit-tag-tag'] =
Xml::textarea( 'wpFilterTags', implode( "\n", $tags ) );
+// $output .= Xml::tags( 'p', null,
Xml::buildForm( $tagFields ) );
+// return $output;
+ default:
+ $message = 'abusefilter-edit-action-'.$action;
+ $form_field = 'wpFilterAction' .
ucfirst($action);
+ $status = $set;
- $output .= $thisAction;
+ $thisAction = Xml::checkLabel( wfMsg( $message
), $form_field, $form_field, $status );
+ $thisAction = Xml::tags( 'p', null, $thisAction
);
+ return $thisAction;
}
-
- return $output;
}
function loadFilterData( $id ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs