Debian Codegraph @

extensions/AbuseFilter/modules/ext.abuseFilter.examine.js

raw symbols SCIP
1 /**
2 * Check a filter against a change
3 *
4 * @author John Du Hart
5 * @author Marius Hoch <[email protected]>
6 */
7
8 ( function () {
9 'use strict';
10
11 // @var {jQuery} Syntax result div
12 var $syntaxResult;
13
14 /**
15 * Processes the results of the filter test
16 *
17 * @param {Object} data The response of the API request
18 */
19 function examinerTestProcess( data ) {
20 $.removeSpinner( 'filter-check' );
21
22 var msg, exClass;
23 if ( data.abusefiltercheckmatch.result ) {
24 exClass = 'mw-abusefilter-examine-match';
25 msg = 'abusefilter-examine-match';
26 } else {
27 exClass = 'mw-abusefilter-examine-nomatch';
28 msg = 'abusefilter-examine-nomatch';
29 }
30 $syntaxResult
31 .attr( 'class', exClass )
32 // Messages listed above
33 // eslint-disable-next-line mediawiki/msg-doc
34 .text( mw.msg( msg ) )
35 .show();
36 }
37
38 /**
39 * Processes the results of the filter test in case of an error
40 *
41 * @param {string} error Error code returned from the AJAX request
42 * @param {Object} details Details about the error
43 */
44 function examinerTestProcessFailure( error, details ) {
45 $.removeSpinner( 'filter-check' );
46
47 var msg;
48 if ( error === 'badsyntax' ) {
49 $syntaxResult.attr(
50 'class', 'mw-abusefilter-syntaxresult-error'
51 );
52 msg = 'abusefilter-examine-syntaxerror';
53 } else if ( error === 'nosuchrcid' || error === 'nosuchlogid' ) {
54 msg = 'abusefilter-examine-notfound';
55 } else if ( error === 'permissiondenied' ) {
56 // The 'abusefilter-modify' or 'abusefilter-view-private' right is needed
57 // to use this API
58 msg = 'abusefilter-mustviewprivateoredit';
59 } else if ( error === 'http' ) {
60 msg = 'abusefilter-http-error';
61 } else {
62 msg = 'unknown-error';
63 }
64
65 $syntaxResult
66 // Messages listed above
67 // eslint-disable-next-line mediawiki/msg-doc
68 .text( mw.msg( msg, details && details.exception ) )
69 .show();
70 }
71
72 /**
73 * Tests the filter against an rc event or abuse log entry.
74 *
75 * @this HTMLElement
76 * @param {jQuery.Event} e The event fired when the function is called
77 */
78 function examinerTestFilter() {
79 var filter = $( '#wpFilterRules' ).val(),
80 examine = mw.config.get( 'abuseFilterExamine' ),
81 params = {
82 action: 'abusefiltercheckmatch',
83 filter: filter
84 };
85
86 $( this ).injectSpinner( { id: 'filter-check', size: 'large' } );
87
88 params[ examine.type === 'rc' ? 'rcid' : 'logid' ] = examine.id;
89
90 // Use post due to the rather large amount of data
91 new mw.Api().post( params )
92 .done( examinerTestProcess )
93 .fail( examinerTestProcessFailure );
94 }
95
96 $( function initialize() {
97 $syntaxResult = $( '#mw-abusefilter-syntaxresult' );
98 $( '#mw-abusefilter-examine-test' ).on( 'click', examinerTestFilter );
99 } );
100 }() );