| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
( function () { |
| 9 |
'use strict'; |
| 10 |
|
| 11 |
|
| 12 |
var $syntaxResult; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 33 |
|
| 34 |
.text( mw.msg( msg ) ) |
| 35 |
.show(); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
|
| 57 |
|
| 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 |
|
| 67 |
|
| 68 |
.text( mw.msg( msg, details && details.exception ) ) |
| 69 |
.show(); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 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 |
|
| 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 |
}() ); |