r37681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37680‎ | r37681 | r37682 >
Date:08:46, 15 July 2008
Author:werdna
Status:old
Tags:
Comment:
Include size delta in vars for editing
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -4,6 +4,10 @@
55
66 class AbuseFilter {
77
 8+ public static $condCount = 0;
 9+ public static $condCheckCount = array();
 10+ public static $condMatchCount = array();
 11+
812 public static function generateUserVars( $user ) {
913 $vars = array();
1014
@@ -40,6 +44,7 @@
4145 }
4246
4347 public static function checkConditions( $conds, $vars ) {
 48+ $fname = __METHOD__;
4449 $modifierWords = array( 'norm', 'supernorm', 'lcase', 'length', 'specialratio' );
4550 $operatorWords = array( 'eq', 'neq', 'gt', 'lt', 'regex', 'contains' );
4651 $validJoinConditions = array( '!', '|', '&' );
@@ -47,6 +52,9 @@
4853 // Remove leading/trailing spaces
4954 $conds = trim($conds);
5055
 56+ self::$condCount++;
 57+ self::$condCheckCount[$conds]++;
 58+
5159 // Is it a set?
5260 if (substr( $conds, 0, 1 ) == '(' && substr( $conds, -1, 1 ) == ')' ) {
5361 // We should have a set here.
@@ -76,19 +84,26 @@
7785 // Need we short-circuit?
7886 if ($setJoinCondition == '|' && $result) {
7987 // Definite yes.
 88+// print "Short-circuit YES for condition $conds, as $thisCond is TRUE\n";
 89+ self::$condMatchCount[$conds]++;
8090 return true;
8191 } elseif ($setJoinCondition == '&' && !$result) {
 92+// print "Short-circuit NO for condition $conds, as $thisCond is FALSE\n";
8293 // Definite no.
8394 return false;
8495 } elseif ($setJoinCondition == '!' && $result) {
 96+// print "Short-circuit NO for condition $conds, as $thisCond is TRUE\n";
8597 // Definite no.
8698 return false;
8799 }
88100 }
89 -
 101+ if ($setJoinCondition != '|')
 102+ self::$condMatchCount[$conds]++;
90103 // Return the default result.
91104 return ($setJoinCondition != '|'); // Only OR returns false after checking all conditions.
92105 }
 106+
 107+ wfProfileIn( "$fname-evaluate" );
93108
94109 // Grab the first word.
95110 list ($thisWord) = explode( ' ', $conds );
@@ -118,15 +133,29 @@
119134 if ( in_array( $thisWord, $operatorWords ) ) {
120135 // Get the rest of the string after the operator.
121136 $parameters = explode( ' ', $conds, $wordNum+2);
122 - $parameters = $parameters[$wordNum+1];
 137+ $parameters = trim($parameters[$wordNum+1]);
123138
124 - return self::checkOperator( $thisWord, $value, $parameters );
 139+ if (in_array( $parameters, array_keys( $vars ) )) {
 140+ $parameters = $vars[$parameters];
 141+ }
 142+
 143+ wfProfileOut( "$fname-evaluate");
 144+
 145+ $result = self::checkOperator( $thisWord, $value, $parameters );
 146+
 147+ if ($result)
 148+ self::$condMatchCount[$conds]++;
 149+
 150+ return $result;
125151 }
126152 } else {
 153+// print "Unknown var $thisWord\n";
127154 }
 155+ wfProfileOut( "$fname-evaluate");
128156 }
129157
130158 public static function tokeniseList( $list ) {
 159+ wfProfileIn( __METHOD__ );
131160 // Parse it, character by character.
132161 $escapeNext = false;
133162 $listLevel = 0;
@@ -181,6 +210,8 @@
182211 // Put any leftovers in
183212 $allTokens[] = $thisToken;
184213
 214+ wfProfileOut( __METHOD__ );
 215+
185216 return $allTokens;
186217 }
187218
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -13,9 +13,9 @@
1414 $vars = array_merge( $vars, AbuseFilter::generateTitleVars( $editor->mTitle , 'ARTICLE' ));
1515 $vars['ACTION'] = 'edit';
1616 $vars['SUMMARY'] = $summary;
17 -
18 - // TODO:
19 -// // Include added/removed lines in the vars.
 17+ $vars['EDIT_DELTA'] = strlen($editor->textbox1) - strlen($editor->getBaseRevision()->getText());
 18+ $vars['OLD_SIZE'] = strlen($editor->getBaseRevision()->getText());
 19+ $vars['NEW_SIZE'] = strlen($editor->textbox1);
2020
2121 $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle );
2222 if( $filter_result !== true ){

Status & tagging log