User:Beetstra/twinklearv.js

// // If TwinkleConfig aint exist. if( typeof( TwinkleConfig ) == 'undefined' ) { TwinkleConfig = function {}; }

/** TwinkleConfig.addAdToSummary If TWINKLE should be added or not to summary if( typeof( TwinkleConfig.addAdToSummary ) == 'undefined' ) { TwinkleConfig.addAdToSummary = true; }

// Twinklefluff vandalsim reporting tool // Orignallity an updated version of ARV 2.1, but nut much code left from that day now

//Status.debugLevel = 1; var AIVpageName = 'Wikipedia:Administrator_intervention_against_vandalism'; var section = '1';

var xmlObject;

$( twinkleARVBase ); function twinkleARVBase{ var username;

if ( wgNamespaceNumber == 3 || wgNamespaceNumber == 2 || ( wgNamespaceNumber == -1 && wgTitle == "Contributions" )){

// If we are on the contributions page, need to parse some then if( wgNamespaceNumber == -1 && wgTitle == "Contributions" ) { username = document.getElementById( 'contentSub' ).getElementsByTagName( 'a' )[0].getAttribute('title').split(':')[1]; } else { username = wgTitle.split( '/' )[0]; // only first part before any slashes }

if( !username ) { // Something is fishy, there was no user? lets about everything throw "given username was " + username + " and thus makes no sense."; }

var name = 'Report'; var title = 'Report user to AIV';

if( isIPAddress( username ) ) { name = 'Report IP'; title = 'Report IP to AIV'; }

var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, name, 'ca-report' ); mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '" )', name , 'td-report', title, '' ); mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '", "final" )', 'final' , 'ca-report-final', title + ' (final warning already given)', '' ); mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '", "postblock" )', 'post block' , 'ca-report-postblock', title + ' (vandalism after release of block)', '' ); mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '", "sock" )', 'sock puppet' , 'ca-report-sock', title + ' (Account is a sock puppet account)', '' ); if( !isIPAddress( username ) ) { mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '", "username" )', 'username' , 'ca-report-username', title + ' (inflammatory username)', '' ); mw.util.addPortletLink( 'ca-report', 'javascript:twinklearv( "' + username + '", "vandalonly" )', 'vandal only' , 'ca-report-vandalonly', title + ' (vandalism only account)', '' ); }	} }

function twinklearv( vandal, final ){ twinklearv.vandal = vandal; final = final || false;

if( vandal == wgUserName ){ alert( 'You don\'t want to report yourself, do you?' ); return; }

if( final ) { twinklearv.reason = 'Vandalism';

if( QueryString.exists( 'vanarticle' ) ) { twinklearv.reason += ' on Category):/i, ':$1:' ) + '';

if( QueryString.exists( 'vanarticlerevid' ) ) { var query = { 'title': QueryString.get( 'vanarticle' ), 'diff': QueryString.get( 'vanarticlerevid' ), 'oldid': QueryString.exists( 'vanarticlegoodrevid' ) ? QueryString.get( 'vanarticlegoodrevid' ) : 'prev' };				twinklearv.reason += ' ([' +  mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ) + ' diff])'; }		}		switch( final ) { case 'final': twinklearv.reason += ' after final warning.'; break; case 'postblock': twinklearv.reason += ' after release of block.'; break; case 'username': twinklearv.reason = 'Username may be rude ,inflammatory, unnecessarily long/confusing, too similar to an existing user, contains the name of an organization or website, or is otherwise inappropriate.'; break; case 'vandalonly': twinklearv.reason += ', contributions indicate vandalism-only account.'; break; case 'sock': var sock = prompt( 'Please enter the username of the sock puppeteer if possible.'); twinklearv.reason += ', contributions indicate account as a sock puppet account' + ( sock ? ' of sock puppeteer ' : '' ) + '.'; }

} else if( !( twinklearv.reason = prompt( 'Reason:' ) ) ) { return; }

Status.init( document.getElementById( 'bodyContent' ) );

Status.status( "Please wait..." ); Status.debug( 'Initiating xmlObject' );

xmlObject = sajax_init_object; xmlObject.overrideMimeType('text/xml');

if ( !xmlObject ) { Status.error( "Unable to open XML Request object, bailing out." ); return false; }

Status.status( "Grabbing page" );

var query = { 'title': AIVpageName, 'action': 'submit', 'section': section };

xmlObject.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), true ); xmlObject.onreadystatechange = function { var vandal = twinklearv.vandal; var reason = twinklearv.reason;

if( xmlObject.readyState != 4 ) { Status.progress( '.' ); return; }

if( xmlObject.status != 200 ) { Status.error( 'Bad status. bailing out.' ); return; }

Status.progress( " Done." );

var doc = xmlObject.responseXML;

var form = doc.getElementById( 'editform' ); var textbox = doc.getElementById( 'wpTextbox1' ); var summary = doc.getElementById( 'wpSummary' );

form.style.display = 'none';

Status.status( 'Searching for existing report...' );

var re = new RegExp( "\\{\\{\\s*(?:(?:[Ii][Pp])?[Vv]andal|[Uu]serlinks)\\s*\\|\\s*" + RegExp.escape( vandal, true ) + "\\s*\\}\\}" );

var myArr; if( ( myArr = re.exec( textbox.value ) ) ) { Status.debug( 'match: ' + myArr[0] );

Status.info( 'Report already present, will not add a new one' ); return; }

Status.progress( " Done." );

Status.status( 'Adding new report...' );

textbox.value += '* - ' + reason + ' ' + '';

summary.value = 'Reporting ' + vandal + '.'+ ( TwinkleConfig.addAdToSummary ? ' TWINKLE' : '');

doc.getElementById( 'wpMinoredit' ).checked = true;

Status.progress( " Done." );

Status.status( 'Submitting form...' );

document.getElementById('globalWrapper').appendChild( form ); form.submit;

Status.progress( " Done." );

}	xmlObject.send( null ); } //