User:Mercury~enwiki/AzaToth/twinkleprod.js

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

/** TwinkleConfig.summaryAd (string) If ad should be added or not to summary, default TWINKLE if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) { TwinkleConfig.summaryAd = " using TW"; }

/** TwinkleConfig.markProdPagesAsMinor (boolean) If, when applying prod template to page, to mark the edit as minor, default true if( typeof( TwinkleConfig.markProdPagesAsMinor ) == 'undefined' ) { TwinkleConfig.markProdPagesAsMinor = false; }

/** TwinkleConfig.watchProdPages (boolean) If, when applying prod template to page, watch it, default true if( typeof( TwinkleConfig.watchProdPages ) == 'undefined' ) { TwinkleConfig.watchProdPages = true; }

/** TwinkleConfig.toolboxButtons (string) If id defined in this array, the button of the action is located inthe toolbox instead of in the actions bar. if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) { TwinkleConfig.toolboxButtons = []; }

function twinkleProdButtons { if( wgNamespaceNumber != 0 || wgCurRevisionId == false ) { return; }	mw.util.addPortletLink( chooseBox( 'tw-prod', TwinkleConfig.toolboxButtons ), "javascript:twinkleProd", "prod", "tw-prod", "Propose deletion via WP:PROD", ""); } addOnloadHook(twinkleProdButtons);

function twinkleProd { twinkleProd.Window = new SimpleWindow( 800, 400 ); twinkleProd.Window.setTitle( "WP:PROD" );

var div = document.createElement( 'div' ); twinkleProd.Window.setContent( div ); Status.init( div ); twinkleProd.Window.display; Status.status( 'checking if article already is proposed for deletion...' );

httpXML = sajax_init_object; httpXML.overrideMimeType('text/xml'); httpXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'submit' } ), true); httpXML.onreadystatechange = twinkleProdCallback1; httpXML.send( null ); }

function twinkleProdCallback1 { if ( httpXML.readyState != 4 ){ return; }

if( httpXML.status != 200 ){ Status.error('Error retrieving page, bailing out'); return; }

var doc = httpXML.responseXML; var form = doc.getElementById( 'editform' ); var text = form.wpTextbox1.value;

var alreadyTagged = /(\{\{(?:db-?|delete|[aitcm]fd|md1)[^{}]*?\|?[^{}]*?\}\})/.exec( text );

if( alreadyTagged ) { Status.warn( 'page is already tagged with ' + alreadtTagged[0] + ', will abort.' ); }

var reason = prompt('Please state your reason for prod.'); if( !reason ) { Status.info( 'aborting per no reason given.'); return; }	text = '' + text; var postData = { 'wpMinoredit': form.wpMinoredit.checked || TwinkleConfig.markProdPagesAsMinor, 'wpWatchthis': form.wpWatchthis.checked || TwinkleConfig.watchProdPages, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': 'Proposing deletion per WP:PROD.' + TwinkleConfig.summaryAd, 'wpTextbox1': text };	Status.status( 'updating article with tag added...'); httpXML = sajax_init_object; httpXML.overrideMimeType('text/xml'); httpXML.open( 'POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'submit' } ), true); httpXML.setRequestHeader('Content-type','application/x-www-form-urlencoded'); httpXML.send( QueryString.create( postData ) );

Status.status( 'Getting data for first contributor...' ); var query = { 'action': 'query', 'prop': 'revisions', 'titles': wgPageName, 'rvlimit': 1, 'rvprop': 'user', 'rvdir': 'newer', 'format': 'xml' }	httpXML = sajax_init_object; httpXML.overrideMimeType('text/xml'); httpXML.onreadystatechange = twinkleProdCallbackUserTalk1; httpXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?' + QueryString.create( query ), true ); httpXML.send( null );

}

function twinkleProdCallbackUserTalk1 { if ( httpXML.readyState != 4 ){ return; }

if( httpXML.status != 200 ){ Status.error('Error retrieving page, bailing out'); return; }	var user = httpXML.responseXML.documentElement.getElementsByTagName('rev')[0].getAttribute('user'); Status.status( 'found user ' + user + ' as first contributor, proceeding to notify user...' );

var query = { 'title': 'User talk:' + user, 'action': 'submit' }	twinkleProdCallbackUserTalk1.query = QueryString.create( query ); httpXML = sajax_init_object; httpXML.overrideMimeType('text/xml'); httpXML.onreadystatechange = twinkleProdCallbackUserTalk2; httpXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + twinkleProdCallbackUserTalk1.query, true ); httpXML.send( null );

}

function twinkleProdCallbackUserTalk2 { if ( httpXML.readyState != 4 ){ return; }

if( httpXML.status != 200 ){ Status.error('Error retrieving page, bailing out'); return; }	var doc = httpXML.responseXML;

var form = doc.getElementById( 'editform' ); var text = form.wpTextbox1.value;

text += "\n ' + '';	var postData = {		'wpMinoredit': form.wpMinoredit.checked || TwinkleConfig.markProdPagesAsMinor,		'wpWatchthis': form.wpWatchthis.checked || TwinkleConfig.watchProdPages,		'wpStarttime': form.wpStarttime.value,		'wpEdittime': form.wpEdittime.value,		'wpAutoSummary': form.wpAutoSummary.value,		'wpEditToken': form.wpEditToken.value,		'wpSummary': 'Notifying user about a proposed deletion via WP:PROD.' + TwinkleConfig.summaryAd,		'wpTextbox1': text	};	Status.status( 'updating usertalk with warning added...');	httpXML = sajax_init_object;	httpXML.overrideMimeType('text/xml');	httpXML.open( 'POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + twinkleProdCallbackUserTalk1.query, true);	httpXML.setRequestHeader('Content-type','application/x-www-form-urlencoded');	httpXML.send( QueryString.create( postData ) );

Status.status( 'hopefully we are done now...'); } //