r46101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46100‎ | r46101 | r46102 >
Date:22:49, 23 January 2009
Author:werdna
Status:deferred
Tags:
Comment:
Put filter-builterator on tools page.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewTools.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/edit.js (deleted) (history)
  • /trunk/extensions/AbuseFilter/edit.js (modified) (history)

Diff [purge]

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 @@
1414
1515 // Expression evaluator
1616 $eval = '';
17 - $eval .= Xml::textarea( 'wpTestExpr', "" );
 17+ $eval .= AbuseFilter::buildEditBox( '', 'wpTestExpr' );
1818 $eval .= Xml::tags( 'p', null, Xml::element( 'input', array( 'type' => 'button', 'id' => 'mw-abusefilter-submitexpr', 'onclick' => 'doExprSubmit();', 'value' => wfMsg( 'abusefilter-tools-submitexpr' ) ) ) );
1919 $eval .= Xml::element( 'p', array( 'id' => 'mw-abusefilter-expr-result' ), ' ' );
2020 $eval = Xml::fieldset( wfMsg( 'abusefilter-tools-expr' ), $eval );
2121 $wgOut->addHTML( $eval );
2222
2323 // 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' );
3225
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 -
5526 $wgOut->addInlineScript( $exprScript );
5627
5728 global $wgUser;
@@ -59,6 +30,7 @@
6031 // Hacky little box to re-enable autoconfirmed if it got disabled
6132 $rac = '';
6233 $rac .= Xml::inputLabel( wfMsg( 'abusefilter-tools-reautoconfirm-user' ), 'wpReAutoconfirmUser', 'reautoconfirm-user', 45 );
 34+ $rac .= ' ';
6335 $rac .= Xml::element( 'input', array( 'type' => 'button', 'id' => 'mw-abusefilter-reautoconfirmsubmit', 'onclick' => 'doReautoSubmit();', 'value' => wfMsg( 'abusefilter-tools-reautoconfirm-submit' ) ) );
6436 $rac = Xml::fieldset( wfMsg( 'abusefilter-tools-reautoconfirm' ), $rac );
6537 $wgOut->addHTML( $rac );
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
@@ -195,7 +195,7 @@
196196 }
197197 }
198198
199 - $fields['abusefilter-edit-rules'] = $this->buildEditBox($row);
 199+ $fields['abusefilter-edit-rules'] = AbuseFilter::buildEditBox($row->af_pattern);
200200 $fields['abusefilter-edit-notes'] = Xml::textarea( 'wpFilterNotes', ( isset( $row->af_comments ) ? $row->af_comments."\n" : "\n" ) );
201201
202202 // Build checkboxen
@@ -243,47 +243,6 @@
244244 return $output;
245245 }
246246
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;' ), '&nbsp;' );
281 -
282 - // Add script
283 - $wgOut->addInlineScript( file_get_contents(dirname(__FILE__)."/edit.js") );
284 -
285 - return $rules;
286 - }
287 -
288247 function buildConsequenceEditor( $row, $actions ) {
289248 global $wgAbuseFilterAvailableActions;
290249 $setActions = array();
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -627,4 +627,47 @@
628628
629629 return $user;
630630 }
 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;' ), '&nbsp;' );
 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+ }
631674 }
Index: trunk/extensions/AbuseFilter/edit.js
@@ -1,9 +1,10 @@
22 function doSyntaxCheck()
33 {
4 - var filter = document.getElementById('wpFilterRules').value;
 4+ var filter = document.getElementById(wgFilterBoxName).value;
55 injectSpinner( document.getElementById( 'mw-abusefilter-syntaxcheck' ), 'abusefilter-syntaxcheck' );
66 sajax_do_call( 'AbuseFilter::ajaxCheckSyntax', [filter], processSyntaxResult );
77 }
 8+
89 function processSyntaxResult( request ) {
910 var response = request.responseText;
1011
@@ -15,17 +16,20 @@
1617 if (response.match( /OK/ )) {
1718 // Successful
1819 changeText( el, 'No syntax errors.' );
 20+ el.syntaxOk = true;
1921 } else {
2022 var error = response.substr(4);
2123 changeText( el, 'Syntax error: '+error );
 24+ el.syntaxOk = false;
2225 }
2326 }
 27+
2428 function addText() {
2529 if (document.getElementById('wpFilterBuilder').selectedIndex == 0) {
2630 return;
2731 }
2832
29 - insertAtCursor(document.getElementById('wpFilterRules'), document.getElementById('wpFilterBuilder').value + " ");
 33+ insertAtCursor(document.getElementById(wgFilterBoxName), document.getElementById('wpFilterBuilder').value + " ");
3034 document.getElementById('wpFilterBuilder').selectedIndex = 0;
3135 }
3236
@@ -50,7 +54,10 @@
5155 }
5256
5357 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+ }
5663 } );
5764 } );
\ No newline at end of file
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -114,7 +114,7 @@
115115 'abusefilter-tools-expr' => 'Expression tester',
116116 'abusefilter-tools-submitexpr' => 'Evaluate',
117117 'abusefilter-tools-reautoconfirm' => 'Restore autoconfirmed status',
118 - 'abusefilter-tools-reautoconfirm-user' => 'User',
 118+ 'abusefilter-tools-reautoconfirm-user' => 'User:',
119119 'abusefilter-tools-reautoconfirm-submit' => 'Re-autoconfirm',
120120 'abusefilter-reautoconfirm-none' => 'That user has not had their autoconfirmed status suspended.',
121121 'abusefilter-reautoconfirm-notallowed' => 'You are not allowed to restore autoconfirmed status.',

Status & tagging log