User:DannyS712 test/Abuse filters.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:DannyS712 test/Abuse filters. |
//<nowiki>
$(function (){
var AFQ_config = {
name: '[[User:DannyS712/Abuse filters query|Abuse filters query.js]]',
version: 2.0,
debug: true
};
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Get abuse filters', 'ca-getFilters');
$('#ca-getFilters').on('click', function() {
getFilters();
} );
} );
} );
async function getFilters(){
var initial = await doQuery();
var data = initial.query.abusefilters;
var offset, shouldRun;
if ( initial && initial.continue && initial.continue.abfstartid ) {
offset = parseInt(iter.continue.abfstartid);
shouldRun = true;
} else {
shouldRun = false;
}
var iter = {};
while ( shouldRun ){
console.log( data );
iter = await doQuery( offset );
console.log( iter );
data = data.concat( iter.query.abusefilters );
console.log( data );
if ( iter && iter.continue && iter.continue.abfstartid ) {
offset = parseInt(iter.continue.abfstartid);
} else {
console.log( "Done" );
shouldRun = false;
}
}
if (AFQ_config.debug) console.log( data );
parseFilters( data );
}
function doQuery( offset ){
return new Promise((resolve) => {
var to_send = {
action: 'query',
list: 'abusefilters',
abfprop: 'id|description|pattern|actions|hits|comments|lasteditor|lastedittime|status|private',
abfshow: 'enabled',
abflimit: 500,
format: 'json',
};
if (offset || false ) to_send.abfstartid = offset;
if (AFQ_config.debug) console.log( to_send );
$.post( mw.config.get( 'wgScriptPath' ) + '/api.php', to_send, function( full_data ){
if (AFQ_config.debug) console.log( full_data );
resolve( full_data );
});
});
}
function parseFilters( data ){
console.log( data );
var filters, conds, usesDeprecated;
var skip = [];
var withDeprecated = [];
var shouldUseEqualsAny = [];
for ( var iii = 0; iii < data.length; iii++ ){
filter = data[iii];
console.log( filter, typeof filter.pattern );
if ( typeof filter.pattern === 'undefined' ){
skip = skip.concat( filter );
} else {
conds = filter.pattern;
console.log( conds );
if ( testDeprecated( conds ) ){
withDeprecated = withDeprecated.concat( filter );
}
if ( testEqualAny( conds ) ) {
shouldUseEqualsAny = shouldUseEqualsAny.concat( filter );
}
}
}
console.log( 'Skipped due to not being able to view the pattern: ', skip );
console.log( 'Using deprecated parameters: ', withDeprecated );
console.log( 'Should use equals to any: ', shouldUseEqualsAny)
report( skip, withDeprecated, shouldUseEqualsAny );
}
function report( skip, withDeprecated, shouldUseEqualsAny ){
var skipList = skip.map( function( filter ) { return filter.id; } );
var withDeprecatedList = withDeprecated.map( function( filter ) { return filter.id; } );
var shouldUseEqualsAnyList = shouldUseEqualsAny.map( function( filter ) { return filter.id; } );
console.log( 'Skipped due to not being able to view the pattern: ', skipList.join( ', ' ) );
console.log( 'Using deprecated parameters: ', withDeprecatedList.join( ', ' ) );
console.log( 'Should use equals to any: ', shouldUseEqualsAnyList.join( ', ' ) );
}
function testDeprecated( conds ){
var deprecated = [
"article_text",
"article_prefixedtext",
"article_namespace",
"article_articleid",
"article_restrictions_edit",
"article_restrictions_move",
"article_restrictions_create",
"article_restrictions_upload",
"article_recent_contributors",
"article_first_contributor",
"moved_from_text",
"moved_from_prefixedtext",
"moved_from_articleid",
"moved_to_text",
"moved_to_prefixedtext",
"moved_to_articleid",
"board_articleid", // From flow
"board_text", // From flow
"board_prefixedtext", // From flow
"article_views", // From hitcounters
];
for ( var jjj = 0; jjj < deprecated.length; jjj++ ){
if ( conds.includes( deprecated[jjj] ) ){
console.log( conds, deprecated[jjj] );
return true;
}
}
return false;
}
function testEqualAny( conds ) {
if ( conds.match( /\^\(\d+(\|\d+)+\)\$/ ) === null ) {
return false;
}
return true;
}
});
//</nowiki>