2008-08-08 09:37:05 +00:00
|
|
|
function doSyntaxCheck()
|
|
|
|
{
|
2009-01-23 22:49:13 +00:00
|
|
|
var filter = document.getElementById(wgFilterBoxName).value;
|
2008-08-08 09:37:05 +00:00
|
|
|
injectSpinner( document.getElementById( 'mw-abusefilter-syntaxcheck' ), 'abusefilter-syntaxcheck' );
|
2009-01-27 06:19:16 +00:00
|
|
|
document.getElementById( 'mw-abusefilter-syntaxcheck' ).disabled = true;
|
2008-08-08 09:37:05 +00:00
|
|
|
sajax_do_call( 'AbuseFilter::ajaxCheckSyntax', [filter], processSyntaxResult );
|
|
|
|
}
|
2009-01-23 22:49:13 +00:00
|
|
|
|
2008-08-08 09:37:05 +00:00
|
|
|
function processSyntaxResult( request ) {
|
|
|
|
var response = request.responseText;
|
|
|
|
|
|
|
|
removeSpinner( 'abusefilter-syntaxcheck' );
|
2009-01-27 06:19:16 +00:00
|
|
|
document.getElementById( 'mw-abusefilter-syntaxcheck' ).disabled = false;
|
2009-01-15 19:04:36 +00:00
|
|
|
|
|
|
|
var el = document.getElementById( 'mw-abusefilter-syntaxresult' );
|
|
|
|
el.style.display = 'block';
|
2008-08-08 09:37:05 +00:00
|
|
|
|
|
|
|
if (response.match( /OK/ )) {
|
|
|
|
// Successful
|
2009-01-15 19:04:36 +00:00
|
|
|
changeText( el, 'No syntax errors.' );
|
2009-01-23 22:49:13 +00:00
|
|
|
el.syntaxOk = true;
|
2009-01-30 00:54:20 +00:00
|
|
|
el.className = 'mw-abusefilter-syntaxresult-ok';
|
2008-08-08 09:37:05 +00:00
|
|
|
} else {
|
2009-01-26 23:32:46 +00:00
|
|
|
var errorData = eval(response.substr(4));
|
|
|
|
changeText( el, 'Syntax error: '+errorData[0] );
|
2009-01-23 22:49:13 +00:00
|
|
|
el.syntaxOk = false;
|
2009-01-30 00:54:20 +00:00
|
|
|
el.className = 'mw-abusefilter-syntaxresult-error';
|
2009-01-23 23:35:26 +00:00
|
|
|
|
2009-01-26 23:32:46 +00:00
|
|
|
var position = errorData[1];
|
|
|
|
var textArea = document.getElementById( wgFilterBoxName );
|
2009-01-23 23:35:26 +00:00
|
|
|
|
2009-01-26 23:32:46 +00:00
|
|
|
textArea.focus();
|
|
|
|
if (document.selection) {
|
|
|
|
var sel = document.selection.createRange();
|
|
|
|
sel.moveStart( 'character', -textArea.value.length );
|
|
|
|
sel.moveStart( 'character', position );
|
|
|
|
sel.select();
|
|
|
|
} else if (textArea.selectionStart && textArea.selectionEnd) {
|
|
|
|
textArea.selectionStart = position;
|
|
|
|
textArea.selectionEnd = position;
|
2009-01-23 23:35:26 +00:00
|
|
|
}
|
2008-08-08 09:37:05 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-23 22:49:13 +00:00
|
|
|
|
2008-08-08 09:37:05 +00:00
|
|
|
function addText() {
|
|
|
|
if (document.getElementById('wpFilterBuilder').selectedIndex == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-23 22:49:13 +00:00
|
|
|
insertAtCursor(document.getElementById(wgFilterBoxName), document.getElementById('wpFilterBuilder').value + " ");
|
2008-08-08 09:37:05 +00:00
|
|
|
document.getElementById('wpFilterBuilder').selectedIndex = 0;
|
|
|
|
}
|
|
|
|
|
2009-01-28 23:54:41 +00:00
|
|
|
function fetchFilter() {
|
|
|
|
var filter = document.getElementById( 'mw-abusefilter-load-filter' ).value;
|
|
|
|
|
|
|
|
sajax_do_call( 'AbuseFilter::ajaxGetFilter', [filter], function(request) {
|
|
|
|
var filter = request.responseText;
|
|
|
|
document.getElementById( wgFilterBoxName ).value = filter;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2008-08-08 09:37:05 +00:00
|
|
|
//From http://clipmarks.com/clipmark/CEFC94CB-94D6-4495-A7AA-791B7355E284/
|
|
|
|
function insertAtCursor(myField, myValue) {
|
|
|
|
//IE support
|
|
|
|
if (document.selection) {
|
|
|
|
myField.focus();
|
|
|
|
sel = document.selection.createRange();
|
|
|
|
sel.text = myValue;
|
|
|
|
}
|
|
|
|
//MOZILLA/NETSCAPE support
|
|
|
|
else if (myField.selectionStart || myField.selectionStart == '0') {
|
|
|
|
var startPos = myField.selectionStart;
|
|
|
|
var endPos = myField.selectionEnd;
|
|
|
|
myField.value = myField.value.substring(0, startPos)
|
|
|
|
+ myValue
|
|
|
|
+ myField.value.substring(endPos, myField.value.length);
|
|
|
|
} else {
|
|
|
|
myField.value += myValue;
|
|
|
|
}
|
2009-01-15 19:04:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 19:40:15 +00:00
|
|
|
function setupActions() {
|
|
|
|
var checkboxen = getElementsByClassName( document, 'input', 'mw-abusefilter-action-checkbox' );
|
|
|
|
|
|
|
|
for( var i=0; i<checkboxen.length; i++ ) {
|
|
|
|
var checkbox = checkboxen[i];
|
|
|
|
|
|
|
|
addHandler( checkbox, 'click', hideDeselectedActions );
|
|
|
|
}
|
|
|
|
// A second loop, so sue me.
|
|
|
|
hideDeselectedActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideDeselectedActions() {
|
|
|
|
var checkboxen = getElementsByClassName( document, 'input', 'mw-abusefilter-action-checkbox' );
|
|
|
|
|
|
|
|
for( var i=0; i<checkboxen.length; i++ ) {
|
|
|
|
// ID format is mw-abusefilter-action-checkbox-$action
|
|
|
|
// We want substr(31)
|
|
|
|
var checkbox = checkboxen[i];
|
|
|
|
var action = checkbox.id.substr(31);
|
|
|
|
var params = document.getElementById( "mw-abusefilter-"+action+"-parameters" );
|
|
|
|
|
|
|
|
if (params && checkbox.checked) {
|
|
|
|
params.style.display = 'block';
|
|
|
|
} else if (params) {
|
|
|
|
params.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:45:42 +00:00
|
|
|
function previewWarnMessage() {
|
|
|
|
var message = document.getElementById( 'mw-abusefilter-warn-message-existing' ).value;
|
|
|
|
|
|
|
|
if (message == 'other') {
|
|
|
|
message = document.getElementById( 'mw-abusefilter-warn-message-other' ).value;
|
|
|
|
}
|
|
|
|
|
|
|
|
var xmlHttp = sajax_init_object();
|
|
|
|
|
|
|
|
xmlHttp.open( 'GET', wgScript + '?title=MediaWiki:' + encodeURIComponent( message ) + '&action=render', true );
|
|
|
|
|
|
|
|
xmlHttp.onreadystatechange = function() {
|
|
|
|
if (xmlHttp.readyState != 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var responseText = xmlHttp.responseText;
|
|
|
|
|
|
|
|
// Beware of raptors.
|
|
|
|
document.getElementById( 'mw-abusefilter-warn-preview' ).innerHTML = responseText;
|
|
|
|
};
|
|
|
|
|
|
|
|
xmlHttp.send(null);
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:54:46 +00:00
|
|
|
function editWarnMessage() {
|
|
|
|
var message = document.getElementById( 'mw-abusefilter-warn-message-existing' ).value;
|
|
|
|
|
|
|
|
if (message == 'other') {
|
|
|
|
message = document.getElementById( 'mw-abusefilter-warn-message-other' ).value;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location = wgScript + '?title=MediaWiki:'+encodeURIComponent( message )+'&action=edit';
|
|
|
|
}
|
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
function afShowExport() {
|
|
|
|
document.getElementById( 'mw-abusefilter-export' ).style.display = 'block';
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:04:36 +00:00
|
|
|
addOnloadHook( function() {
|
2009-01-23 22:49:13 +00:00
|
|
|
addHandler( document.getElementById( wgFilterBoxName ), 'keyup', function() {
|
|
|
|
el = document.getElementById( 'mw-abusefilter-syntaxresult' );
|
|
|
|
if (el.syntaxOk == true) {
|
|
|
|
el.style.display = 'none';
|
|
|
|
}
|
2009-01-15 19:04:36 +00:00
|
|
|
} );
|
2009-01-28 19:40:15 +00:00
|
|
|
|
2009-01-28 23:54:41 +00:00
|
|
|
var loader = document.getElementById( 'mw-abusefilter-load' );
|
|
|
|
if (loader) {
|
|
|
|
addHandler( loader, 'click', fetchFilter );
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:45:42 +00:00
|
|
|
var warnMsgPreview = document.getElementById( 'mw-abusefilter-warn-preview-button' );
|
|
|
|
if (warnMsgPreview) {
|
|
|
|
addHandler( warnMsgPreview, 'click', previewWarnMessage );
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:54:46 +00:00
|
|
|
var warnMsgEdit = document.getElementById( 'mw-abusefilter-warn-edit-button' );
|
|
|
|
if (warnMsgEdit) {
|
|
|
|
addHandler( warnMsgEdit, 'click', editWarnMessage );
|
|
|
|
}
|
|
|
|
|
2009-01-28 19:40:15 +00:00
|
|
|
setupActions();
|
2009-04-23 04:23:56 +00:00
|
|
|
|
|
|
|
var exporter = document.getElementById( 'mw-abusefilter-export' );
|
|
|
|
|
|
|
|
if (exporter ) {
|
|
|
|
exporter.style.display = 'none';
|
|
|
|
}
|
|
|
|
} );
|