Index: trunk/extensions/AbuseFilter/Views/edit.js |
— | — | @@ -1,61 +0,0 @@ |
2 | | -function doSyntaxCheck() |
3 | | -{ |
4 | | - var filter = document.getElementById('wpFilterRules').value; |
5 | | - injectSpinner( document.getElementById( 'mw-abusefilter-syntaxcheck' ), 'abusefilter-syntaxcheck' ); |
6 | | - sajax_do_call( 'AbuseFilter::ajaxCheckSyntax', [filter], processSyntaxResult ); |
7 | | -} |
8 | | -function processSyntaxResult( request ) { |
9 | | - var response = request.responseText; |
10 | | - |
11 | | - removeSpinner( 'abusefilter-syntaxcheck' ); |
12 | | - |
13 | | - var el = document.getElementById( 'mw-abusefilter-syntaxresult' ); |
14 | | - el.style.display = 'block'; |
15 | | - |
16 | | - if (response.match( /OK/ )) { |
17 | | - // Successful |
18 | | - changeText( el, 'No syntax errors.' ); |
19 | | - el.syntaxOk = true; |
20 | | - } else { |
21 | | - var error = response.substr(4); |
22 | | - changeText( el, 'Syntax error: '+error ); |
23 | | - el.syntaxOk = false; |
24 | | - } |
25 | | -} |
26 | | -function addText() { |
27 | | - if (document.getElementById('wpFilterBuilder').selectedIndex == 0) { |
28 | | - return; |
29 | | - } |
30 | | - |
31 | | - insertAtCursor(document.getElementById('wpFilterRules'), document.getElementById('wpFilterBuilder').value + " "); |
32 | | - document.getElementById('wpFilterBuilder').selectedIndex = 0; |
33 | | -} |
34 | | - |
35 | | -//From http://clipmarks.com/clipmark/CEFC94CB-94D6-4495-A7AA-791B7355E284/ |
36 | | -function insertAtCursor(myField, myValue) { |
37 | | - //IE support |
38 | | - if (document.selection) { |
39 | | - myField.focus(); |
40 | | - sel = document.selection.createRange(); |
41 | | - sel.text = myValue; |
42 | | - } |
43 | | - //MOZILLA/NETSCAPE support |
44 | | - else if (myField.selectionStart || myField.selectionStart == '0') { |
45 | | - var startPos = myField.selectionStart; |
46 | | - var endPos = myField.selectionEnd; |
47 | | - myField.value = myField.value.substring(0, startPos) |
48 | | - + myValue |
49 | | - + myField.value.substring(endPos, myField.value.length); |
50 | | - } else { |
51 | | - myField.value += myValue; |
52 | | - } |
53 | | -} |
54 | | - |
55 | | -addOnloadHook( function() { |
56 | | - addHandler( document.getElementById( 'wpFilterRules' ), 'keyup', function() { |
57 | | - el = document.getElementById( 'mw-abusefilter-syntaxresult' ); |
58 | | - if (el.syntaxOk == true) { |
59 | | - el.style.display = 'none'; |
60 | | - } |
61 | | - } ); |
62 | | -} ); |
\ No newline at end of file |
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewTools.php |
— | — | @@ -13,44 +13,15 @@ |
14 | 14 | |
15 | 15 | // Expression evaluator |
16 | 16 | $eval = ''; |
17 | | - $eval .= Xml::textarea( 'wpTestExpr', "" ); |
| 17 | + $eval .= AbuseFilter::buildEditBox( '', 'wpTestExpr' ); |
18 | 18 | $eval .= Xml::tags( 'p', null, Xml::element( 'input', array( 'type' => 'button', 'id' => 'mw-abusefilter-submitexpr', 'onclick' => 'doExprSubmit();', 'value' => wfMsg( 'abusefilter-tools-submitexpr' ) ) ) ); |
19 | 19 | $eval .= Xml::element( 'p', array( 'id' => 'mw-abusefilter-expr-result' ), ' ' ); |
20 | 20 | $eval = Xml::fieldset( wfMsg( 'abusefilter-tools-expr' ), $eval ); |
21 | 21 | $wgOut->addHTML( $eval ); |
22 | 22 | |
23 | 23 | // Associated script |
24 | | - $exprScript = "function doExprSubmit() |
25 | | - { |
26 | | - var expr = document.getElementById('wpTestExpr').value; |
27 | | - injectSpinner( document.getElementById( 'mw-abusefilter-submitexpr' ), 'abusefilter-expr' ); |
28 | | - sajax_do_call( 'AbuseFilter::ajaxEvaluateExpression', [expr], processExprResult ); |
29 | | - } |
30 | | - function processExprResult( request ) { |
31 | | - var response = request.responseText; |
| 24 | + $exprScript = file_get_contents( dirname( __FILE__ ) . '/tools.js' ); |
32 | 25 | |
33 | | - removeSpinner( 'abusefilter-expr' ); |
34 | | - |
35 | | - var el = document.getElementById( 'mw-abusefilter-expr-result' ); |
36 | | - changeText( el, response ); |
37 | | - } |
38 | | - function doReautoSubmit() |
39 | | - { |
40 | | - var name = document.getElementById('reautoconfirm-user').value; |
41 | | - injectSpinner( document.getElementById( 'mw-abusefilter-reautoconfirmsubmit' ), 'abusefilter-reautoconfirm' ); |
42 | | - sajax_do_call( 'AbuseFilter::ajaxReAutoconfirm', [name], processReautoconfirm ); |
43 | | - } |
44 | | - function processReautoconfirm( request ) { |
45 | | - var response = request.responseText; |
46 | | - |
47 | | - if (strlen(response)) { |
48 | | - jsMsg( response ); |
49 | | - } |
50 | | - |
51 | | - removeSpinner( 'abusefilter-reautoconfirm' ); |
52 | | - } |
53 | | - "; |
54 | | - |
55 | 26 | $wgOut->addInlineScript( $exprScript ); |
56 | 27 | |
57 | 28 | global $wgUser; |
— | — | @@ -59,6 +30,7 @@ |
60 | 31 | // Hacky little box to re-enable autoconfirmed if it got disabled |
61 | 32 | $rac = ''; |
62 | 33 | $rac .= Xml::inputLabel( wfMsg( 'abusefilter-tools-reautoconfirm-user' ), 'wpReAutoconfirmUser', 'reautoconfirm-user', 45 ); |
| 34 | + $rac .= ' '; |
63 | 35 | $rac .= Xml::element( 'input', array( 'type' => 'button', 'id' => 'mw-abusefilter-reautoconfirmsubmit', 'onclick' => 'doReautoSubmit();', 'value' => wfMsg( 'abusefilter-tools-reautoconfirm-submit' ) ) ); |
64 | 36 | $rac = Xml::fieldset( wfMsg( 'abusefilter-tools-reautoconfirm' ), $rac ); |
65 | 37 | $wgOut->addHTML( $rac ); |
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php |
— | — | @@ -195,7 +195,7 @@ |
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | | - $fields['abusefilter-edit-rules'] = $this->buildEditBox($row); |
| 199 | + $fields['abusefilter-edit-rules'] = AbuseFilter::buildEditBox($row->af_pattern); |
200 | 200 | $fields['abusefilter-edit-notes'] = Xml::textarea( 'wpFilterNotes', ( isset( $row->af_comments ) ? $row->af_comments."\n" : "\n" ) ); |
201 | 201 | |
202 | 202 | // Build checkboxen |
— | — | @@ -243,47 +243,6 @@ |
244 | 244 | return $output; |
245 | 245 | } |
246 | 246 | |
247 | | - function buildEditBox( $row ) { |
248 | | - global $wgOut; |
249 | | - |
250 | | - $rules = Xml::textarea( 'wpFilterRules', ( isset( $row->af_pattern ) ? $row->af_pattern."\n" : "\n" ) ); |
251 | | - |
252 | | - $dropDown = array( |
253 | | - 'op-arithmetic' => array('+' => 'addition', '-' => 'subtraction', '*' => 'multiplication', '/' => 'divide', '%' => 'modulo', '**' => 'pow'), |
254 | | - 'op-comparison' => array('==' => 'equal', '!=' => 'notequal', '<' => 'lt', '>' => 'gt', '<=' => 'lte', '>=' => 'gte'), |
255 | | - 'op-bool' => array( '!' => 'not', '&' => 'and', '|' => 'or', '^' => 'xor' ), |
256 | | - 'misc' => array( 'in' => 'in', 'like' => 'like', '""' => 'stringlit', ), |
257 | | - 'funcs' => array( 'length(string)' => 'length', 'lcase(string)' => 'lcase', 'ccnorm(string)' => 'ccnorm', 'rmdoubles(string)' => 'rmdoubles', 'specialratio(string)' => 'specialratio', 'norm(string)' => 'norm', 'count(needle,haystack)' => 'count' ), |
258 | | - 'vars' => array( 'ACCOUNTNAME' => 'accountname', 'ACTION' => 'action', 'ADDED_LINES' => 'addedlines', 'EDIT_DELTA' => 'delta', 'EDIT_DIFF' => 'diff', 'NEW_SIZE' => 'newsize', 'OLD_SIZE' => 'oldsize', 'REMOVED_LINES' => 'removedlines', 'SUMMARY' => 'summary', 'ARTICLE_ARTICLEID' => 'article-id', 'ARTICLE_NAMESPACE' => 'article-ns', 'ARTICLE_TEXT' => 'article-text', 'ARTICLE_PREFIXEDTEXT' => 'article-prefixedtext', 'MOVED_FROM_ARTICLEID' => 'movedfrom-id', 'MOVED_FROM_NAMESPACE' => 'movedfrom-ns', 'MOVED_FROM_TEXT' => 'movedfrom-text', 'MOVED_FROM_PREFIXEDTEXT' => 'movedfrom-prefixedtext', 'MOVED_TO_ARTICLEID' => 'movedto-id', 'MOVED_TO_NAMESPACE' => 'movedto-ns', 'MOVED_TO_TEXT' => 'movedto-text', 'MOVED_TO_PREFIXEDTEXT' => 'movedto-prefixedtext', 'USER_EDITCOUNT' => 'user-editcount', 'USER_AGE' => 'user-age', 'USER_NAME' => 'user-name', 'USER_GROUPS' => 'user-groups', 'USER_EMAILCONFIRM' => 'user-emailconfirm'), |
259 | | - ); |
260 | | - |
261 | | - // Generate builder drop-down |
262 | | - $builder = ''; |
263 | | - |
264 | | - $builder .= Xml::option( wfMsg( "abusefilter-edit-builder-select") ); |
265 | | - |
266 | | - foreach( $dropDown as $group => $values ) { |
267 | | - $builder .= Xml::openElement( 'optgroup', array( 'label' => wfMsg( "abusefilter-edit-builder-group-$group" ) ) ) . "\n"; |
268 | | - |
269 | | - foreach( $values as $content => $name ) { |
270 | | - $builder .= Xml::option( wfMsg( "abusefilter-edit-builder-$group-$name" ), $content ) . "\n"; |
271 | | - } |
272 | | - |
273 | | - $builder .= Xml::closeElement( 'optgroup' ) . "\n"; |
274 | | - } |
275 | | - |
276 | | - $rules .= Xml::tags( 'select', array( 'id' => 'wpFilterBuilder', 'onchange' => 'addText();' ), $builder ); |
277 | | - |
278 | | - // Add syntax checking |
279 | | - $rules .= Xml::element( 'input', array( 'type' => 'button', 'onclick' => 'doSyntaxCheck()', 'value' => wfMsg( 'abusefilter-edit-check' ), 'id' => 'mw-abusefilter-syntaxcheck' ) ); |
280 | | - $rules .= Xml::element( 'div', array( 'id' => 'mw-abusefilter-syntaxresult', 'style' => 'display: none;' ), ' ' ); |
281 | | - |
282 | | - // Add script |
283 | | - $wgOut->addInlineScript( file_get_contents(dirname(__FILE__)."/edit.js") ); |
284 | | - |
285 | | - return $rules; |
286 | | - } |
287 | | - |
288 | 247 | function buildConsequenceEditor( $row, $actions ) { |
289 | 248 | global $wgAbuseFilterAvailableActions; |
290 | 249 | $setActions = array(); |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -627,4 +627,47 @@ |
628 | 628 | |
629 | 629 | return $user; |
630 | 630 | } |
| 631 | + |
| 632 | + function buildEditBox( $rules, $textName = 'wpFilterRules' ) { |
| 633 | + global $wgOut; |
| 634 | + |
| 635 | + $rules = Xml::textarea( $textName, ( isset( $rules ) ? $rules."\n" : "\n" ) ); |
| 636 | + |
| 637 | + $dropDown = array( |
| 638 | + 'op-arithmetic' => array('+' => 'addition', '-' => 'subtraction', '*' => 'multiplication', '/' => 'divide', '%' => 'modulo', '**' => 'pow'), |
| 639 | + 'op-comparison' => array('==' => 'equal', '!=' => 'notequal', '<' => 'lt', '>' => 'gt', '<=' => 'lte', '>=' => 'gte'), |
| 640 | + 'op-bool' => array( '!' => 'not', '&' => 'and', '|' => 'or', '^' => 'xor' ), |
| 641 | + 'misc' => array( 'in' => 'in', 'like' => 'like', '""' => 'stringlit', ), |
| 642 | + 'funcs' => array( 'length(string)' => 'length', 'lcase(string)' => 'lcase', 'ccnorm(string)' => 'ccnorm', 'rmdoubles(string)' => 'rmdoubles', 'specialratio(string)' => 'specialratio', 'norm(string)' => 'norm', 'count(needle,haystack)' => 'count' ), |
| 643 | + 'vars' => array( 'ACCOUNTNAME' => 'accountname', 'ACTION' => 'action', 'ADDED_LINES' => 'addedlines', 'EDIT_DELTA' => 'delta', 'EDIT_DIFF' => 'diff', 'NEW_SIZE' => 'newsize', 'OLD_SIZE' => 'oldsize', 'REMOVED_LINES' => 'removedlines', 'SUMMARY' => 'summary', 'ARTICLE_ARTICLEID' => 'article-id', 'ARTICLE_NAMESPACE' => 'article-ns', 'ARTICLE_TEXT' => 'article-text', 'ARTICLE_PREFIXEDTEXT' => 'article-prefixedtext', 'MOVED_FROM_ARTICLEID' => 'movedfrom-id', 'MOVED_FROM_NAMESPACE' => 'movedfrom-ns', 'MOVED_FROM_TEXT' => 'movedfrom-text', 'MOVED_FROM_PREFIXEDTEXT' => 'movedfrom-prefixedtext', 'MOVED_TO_ARTICLEID' => 'movedto-id', 'MOVED_TO_NAMESPACE' => 'movedto-ns', 'MOVED_TO_TEXT' => 'movedto-text', 'MOVED_TO_PREFIXEDTEXT' => 'movedto-prefixedtext', 'USER_EDITCOUNT' => 'user-editcount', 'USER_AGE' => 'user-age', 'USER_NAME' => 'user-name', 'USER_GROUPS' => 'user-groups', 'USER_EMAILCONFIRM' => 'user-emailconfirm'), |
| 644 | + ); |
| 645 | + |
| 646 | + // Generate builder drop-down |
| 647 | + $builder = ''; |
| 648 | + |
| 649 | + $builder .= Xml::option( wfMsg( "abusefilter-edit-builder-select") ); |
| 650 | + |
| 651 | + foreach( $dropDown as $group => $values ) { |
| 652 | + $builder .= Xml::openElement( 'optgroup', array( 'label' => wfMsg( "abusefilter-edit-builder-group-$group" ) ) ) . "\n"; |
| 653 | + |
| 654 | + foreach( $values as $content => $name ) { |
| 655 | + $builder .= Xml::option( wfMsg( "abusefilter-edit-builder-$group-$name" ), $content ) . "\n"; |
| 656 | + } |
| 657 | + |
| 658 | + $builder .= Xml::closeElement( 'optgroup' ) . "\n"; |
| 659 | + } |
| 660 | + |
| 661 | + $rules .= Xml::tags( 'select', array( 'id' => 'wpFilterBuilder', 'onchange' => 'addText();' ), $builder ); |
| 662 | + |
| 663 | + // Add syntax checking |
| 664 | + $rules .= Xml::element( 'input', array( 'type' => 'button', 'onclick' => 'doSyntaxCheck()', 'value' => wfMsg( 'abusefilter-edit-check' ), 'id' => 'mw-abusefilter-syntaxcheck' ) ); |
| 665 | + $rules .= Xml::element( 'div', array( 'id' => 'mw-abusefilter-syntaxresult', 'style' => 'display: none;' ), ' ' ); |
| 666 | + |
| 667 | + // Add script |
| 668 | + $editScript = file_get_contents(dirname(__FILE__)."/edit.js"); |
| 669 | + $editScript = "var wgFilterBoxName = ".Xml::encodeJSVar( $textName ).";\n$editScript"; |
| 670 | + $wgOut->addInlineScript( $editScript ); |
| 671 | + |
| 672 | + return $rules; |
| 673 | + } |
631 | 674 | } |
Index: trunk/extensions/AbuseFilter/edit.js |
— | — | @@ -1,9 +1,10 @@ |
2 | 2 | function doSyntaxCheck() |
3 | 3 | { |
4 | | - var filter = document.getElementById('wpFilterRules').value; |
| 4 | + var filter = document.getElementById(wgFilterBoxName).value; |
5 | 5 | injectSpinner( document.getElementById( 'mw-abusefilter-syntaxcheck' ), 'abusefilter-syntaxcheck' ); |
6 | 6 | sajax_do_call( 'AbuseFilter::ajaxCheckSyntax', [filter], processSyntaxResult ); |
7 | 7 | } |
| 8 | + |
8 | 9 | function processSyntaxResult( request ) { |
9 | 10 | var response = request.responseText; |
10 | 11 | |
— | — | @@ -15,17 +16,20 @@ |
16 | 17 | if (response.match( /OK/ )) { |
17 | 18 | // Successful |
18 | 19 | changeText( el, 'No syntax errors.' ); |
| 20 | + el.syntaxOk = true; |
19 | 21 | } else { |
20 | 22 | var error = response.substr(4); |
21 | 23 | changeText( el, 'Syntax error: '+error ); |
| 24 | + el.syntaxOk = false; |
22 | 25 | } |
23 | 26 | } |
| 27 | + |
24 | 28 | function addText() { |
25 | 29 | if (document.getElementById('wpFilterBuilder').selectedIndex == 0) { |
26 | 30 | return; |
27 | 31 | } |
28 | 32 | |
29 | | - insertAtCursor(document.getElementById('wpFilterRules'), document.getElementById('wpFilterBuilder').value + " "); |
| 33 | + insertAtCursor(document.getElementById(wgFilterBoxName), document.getElementById('wpFilterBuilder').value + " "); |
30 | 34 | document.getElementById('wpFilterBuilder').selectedIndex = 0; |
31 | 35 | } |
32 | 36 | |
— | — | @@ -50,7 +54,10 @@ |
51 | 55 | } |
52 | 56 | |
53 | 57 | addOnloadHook( function() { |
54 | | - addHandler( document.getElementById( 'wpFilterRules' ), 'keyup', function() { |
55 | | - document.getElementById( 'mw-abusefilter-syntaxresult' ).style.display = 'none'; |
| 58 | + addHandler( document.getElementById( wgFilterBoxName ), 'keyup', function() { |
| 59 | + el = document.getElementById( 'mw-abusefilter-syntaxresult' ); |
| 60 | + if (el.syntaxOk == true) { |
| 61 | + el.style.display = 'none'; |
| 62 | + } |
56 | 63 | } ); |
57 | 64 | } ); |
\ No newline at end of file |
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | 'abusefilter-tools-expr' => 'Expression tester', |
116 | 116 | 'abusefilter-tools-submitexpr' => 'Evaluate', |
117 | 117 | 'abusefilter-tools-reautoconfirm' => 'Restore autoconfirmed status', |
118 | | - 'abusefilter-tools-reautoconfirm-user' => 'User', |
| 118 | + 'abusefilter-tools-reautoconfirm-user' => 'User:', |
119 | 119 | 'abusefilter-tools-reautoconfirm-submit' => 'Re-autoconfirm', |
120 | 120 | 'abusefilter-reautoconfirm-none' => 'That user has not had their autoconfirmed status suspended.', |
121 | 121 | 'abusefilter-reautoconfirm-notallowed' => 'You are not allowed to restore autoconfirmed status.', |