Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -4,6 +4,10 @@ |
5 | 5 | |
6 | 6 | class AbuseFilter { |
7 | 7 | |
| 8 | + public static $condCount = 0; |
| 9 | + public static $condCheckCount = array(); |
| 10 | + public static $condMatchCount = array(); |
| 11 | + |
8 | 12 | public static function generateUserVars( $user ) { |
9 | 13 | $vars = array(); |
10 | 14 | |
— | — | @@ -40,6 +44,7 @@ |
41 | 45 | } |
42 | 46 | |
43 | 47 | public static function checkConditions( $conds, $vars ) { |
| 48 | + $fname = __METHOD__; |
44 | 49 | $modifierWords = array( 'norm', 'supernorm', 'lcase', 'length', 'specialratio' ); |
45 | 50 | $operatorWords = array( 'eq', 'neq', 'gt', 'lt', 'regex', 'contains' ); |
46 | 51 | $validJoinConditions = array( '!', '|', '&' ); |
— | — | @@ -47,6 +52,9 @@ |
48 | 53 | // Remove leading/trailing spaces |
49 | 54 | $conds = trim($conds); |
50 | 55 | |
| 56 | + self::$condCount++; |
| 57 | + self::$condCheckCount[$conds]++; |
| 58 | + |
51 | 59 | // Is it a set? |
52 | 60 | if (substr( $conds, 0, 1 ) == '(' && substr( $conds, -1, 1 ) == ')' ) { |
53 | 61 | // We should have a set here. |
— | — | @@ -76,19 +84,26 @@ |
77 | 85 | // Need we short-circuit? |
78 | 86 | if ($setJoinCondition == '|' && $result) { |
79 | 87 | // Definite yes. |
| 88 | +// print "Short-circuit YES for condition $conds, as $thisCond is TRUE\n"; |
| 89 | + self::$condMatchCount[$conds]++; |
80 | 90 | return true; |
81 | 91 | } elseif ($setJoinCondition == '&' && !$result) { |
| 92 | +// print "Short-circuit NO for condition $conds, as $thisCond is FALSE\n"; |
82 | 93 | // Definite no. |
83 | 94 | return false; |
84 | 95 | } elseif ($setJoinCondition == '!' && $result) { |
| 96 | +// print "Short-circuit NO for condition $conds, as $thisCond is TRUE\n"; |
85 | 97 | // Definite no. |
86 | 98 | return false; |
87 | 99 | } |
88 | 100 | } |
89 | | - |
| 101 | + if ($setJoinCondition != '|') |
| 102 | + self::$condMatchCount[$conds]++; |
90 | 103 | // Return the default result. |
91 | 104 | return ($setJoinCondition != '|'); // Only OR returns false after checking all conditions. |
92 | 105 | } |
| 106 | + |
| 107 | + wfProfileIn( "$fname-evaluate" ); |
93 | 108 | |
94 | 109 | // Grab the first word. |
95 | 110 | list ($thisWord) = explode( ' ', $conds ); |
— | — | @@ -118,15 +133,29 @@ |
119 | 134 | if ( in_array( $thisWord, $operatorWords ) ) { |
120 | 135 | // Get the rest of the string after the operator. |
121 | 136 | $parameters = explode( ' ', $conds, $wordNum+2); |
122 | | - $parameters = $parameters[$wordNum+1]; |
| 137 | + $parameters = trim($parameters[$wordNum+1]); |
123 | 138 | |
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; |
125 | 151 | } |
126 | 152 | } else { |
| 153 | +// print "Unknown var $thisWord\n"; |
127 | 154 | } |
| 155 | + wfProfileOut( "$fname-evaluate"); |
128 | 156 | } |
129 | 157 | |
130 | 158 | public static function tokeniseList( $list ) { |
| 159 | + wfProfileIn( __METHOD__ ); |
131 | 160 | // Parse it, character by character. |
132 | 161 | $escapeNext = false; |
133 | 162 | $listLevel = 0; |
— | — | @@ -181,6 +210,8 @@ |
182 | 211 | // Put any leftovers in |
183 | 212 | $allTokens[] = $thisToken; |
184 | 213 | |
| 214 | + wfProfileOut( __METHOD__ ); |
| 215 | + |
185 | 216 | return $allTokens; |
186 | 217 | } |
187 | 218 | |
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php |
— | — | @@ -13,9 +13,9 @@ |
14 | 14 | $vars = array_merge( $vars, AbuseFilter::generateTitleVars( $editor->mTitle , 'ARTICLE' )); |
15 | 15 | $vars['ACTION'] = 'edit'; |
16 | 16 | $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); |
20 | 20 | |
21 | 21 | $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle ); |
22 | 22 | if( $filter_result !== true ){ |