User:Lost Labyrinth/admin/autoreport.js

//

bp = {}; bp.add = function { if ( wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk' ) { bp.user = encodeURIComponent( wgTitle ); } else if ( wgCanonicalSpecialPageName == 'Contributions' ) { bp.user = document.forms[0].target.value; }	if ( bp.user != undefined ) { addPortletLink(			'my-tools-menu',			'javascript:bp.go',			'Report user',			'td-bp',			'Report this user'		); } } bp.debugOutput = function( str ) { bp.output += str; bp.panel.setBody( bp.output ); } bp.debugStatus = function( i ) { var s = ( i ) ? 'green;"> [OK]' : 'red;"> [FAILED]'; bp.debugOutput( 'Spang ' );	bp.output = ;	bp.debugOutput( ' Loading Report page...' );	bp.panel.render( document.body );	bp.panel.show;	YAHOO.util.Connect.asyncRequest(		'GET',		'/api.php?action=query&titles=The_Sims_Wiki:Report&prop=revisions|info|links&pllimit=500&rvprop=content&rvlimit=1&rvsection=1&format=xml&intoken=edit',		bp.update,		null	); } bp.update = {	success: function( o ) {		bp.debugStatus( 1 );		bp.debugOutput( ' Checking Reports for selected user...' ); var titles = o.responseXML.getElementsByTagName( 'pl' ); for ( lk in titles ) { try { if ( titles[lk].getAttribute( 'title' ) == 'User:' + bp.user.replace( /%20/ig, ' ' ).replace( /%2F/ig, '/' ).replace( /%3A/ig, ':' ) ) { bp.debugStatus( 0 ); bp.debugOutput( ' User already Reported! Close' ); return; }			} catch( e ) {}; }		bp.debugStatus( 1 ); bp.debugOutput( ' User not listed, adding them now...' ); try { var sectionText = o.responseXML.getElementsByTagName( 'rev' )[0].firstChild.nodeValue; var lines = sectionText.split( '\n' ); var ip = ( bp.user.match( /^\b(?:\d{1,3}\.){3}\d{1,3}\b$/g ) ) ? 1 : 0;			if ( ip ) { lines.splice( 1, 0, '* - ' + bp.comment + ' ' ); } else { // delicious copypasta from wikibits.js, function importScript // bug reported by Lyrithya on IRC on 14 February 2011 --Jack Phoenix lines.splice( 1, 0, '* - ' + bp.comment + ' ' ); };			sectionText = lines.join( '\n' ); } catch( e ) { bp.debugStatus( 0 ); bp.debugOutput( ' Could not add text to the page! Close' ); return; }		bp.debugStatus( 1 ); bp.debugOutput( ' Saving page...' ); var token = o.responseXML.getElementsByTagName( 'page' )[0].getAttribute( 'edittoken' ); var post = 'title=The_Sims_Wiki:Report&section=1&token=' + encodeURIComponent( token ) + '&summary=%2BUser:' +			encodeURIComponent( bp.user ) + '&text=' + encodeURIComponent( sectionText ); YAHOO.util.Connect.asyncRequest(			'POST',			'/api.php?action=edit&format=xml',			bp.saved,			post		); },	failure: function { bp.debugStatus( 0 ); bp.debugOutput( ' Couldn\'t connect to the Report page! Close' ); } } bp.saved = { success: function( o ) { try { result = ( o.responseXML.getElementsByTagName( 'edit' )[0].getAttribute( 'result' ) == 'Success' ) ? 1 : 0;		} catch( e ) { result = 0; }		if ( result ) { bp.debugStatus( 1 ); bp.debugOutput( ' Saved! Go to the Report Page or close' ); } else { with( o.responseXML.getElementsByTagName( 'error' )[0] ) { bp.debugStatus( 0 ); bp.debugOutput(					' Saving failed :( Error: ' + getAttribute( 'code' ) + ' - ' + getAttribute( 'info' ) + ' Add manually or close' );			}		}	},	failure: function( o ) {		bp.debugStatus( 0 );		bp.debugOutput( ' Connection failed :( Add manually</a> or close</a>'		); } } YAHOO.util.Event.onContentReady('my-tools-menu', bp.add); //