User:Flewis/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.watchProdPages (boolean) If, when applying prod template to page, watch it, default true */ if( typeof( TwinkleConfig.watchProdPages ) == 'undefined' ) { TwinkleConfig.watchProdPages = true; }

function twinkleprod { if( wgNamespaceNumber != 0 || wgCurRevisionId == false ) { return; }	if (twinkleConfigExists) {		mw.util.addPortletLink( 'p-cactions', "javascript:twinkleprod.callback", "prod", "tw-prod", "Propose deletion via WP:PROD", ""); }	else {		mw.util.addPortletLink('p-cactions', 'javascript:alert("Your account is too new to use Twinkle.");', 'prod', 'tw-prod', 'Propose deletion via WP:PROD', ''); } } $(twinkleprod);

twinkleprod.callback = function twinkleprodCallback { var Window = new SimpleWindow( 800, 400 ); Window.setTitle( "WP:PROD" ); var form = new QuickForm( twinkleprod.callback.evaluate ); var field = form.append( {			type: 'field',			label: 'Reason for proposed deletion'		} ); field.append( {			type: 'textarea',			name: 'reason',			label: 'Reason:'		} ); field.append( { type:'submit' } );

var result = form.render; Window.setContent( result ); Window.display; }

twinkleprod.callbacks = { main: function( self ) { var form = self.responseXML.getElementById('editform'); var text = form.wpTextbox1.value;

var tag_re = /(\{\{(?:db-?|delete|[aitcmrs]fd|md1)[^{}]*?\|?[^{}]*?\}\})/;

if( tag_re.test( text ) ) { self.statelem.warn( 'Page already tagged with a deletion template, aborting procedure' ); return; }		// Notification to first contributor var query = { 'action': 'query', 'prop': 'revisions', 'titles': wgPageName, 'rvlimit': 1, 'rvprop': 'user', 'rvdir': 'newer' }		var callback = function( self ) { var xmlDoc = self.responseXML; var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue; var query = { 'title': 'User talk:' + user, 'action': 'submit' };			var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinkleprod.callbacks.userNotification ); wikipedia_wiki.params = self.params; wikipedia_wiki.get; }

var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback ); wikipedia_api.params = self.params; wikipedia_api.post;

var postData = { 'wpMinoredit': undefined, // Per memo 'wpWatchthis': TwinkleConfig.watchProdPages ? '' : form.wpWatchthis.checked ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': "Proposing article for deletion per WP:PROD." + TwinkleConfig.summaryAd, 'wpTextbox1': "\{\{subst:prod|1=" + self.params.reason + "}}\n" + text };

self.post( postData ); },	userNotification: function( self ) { var form = this.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; text += "\n\{\{subst:PRODWarning|1=" + wgPageName + "\}\} \~\~\~\~"; var postData = { 'wpMinoredit': form.wpMinoredit.checked ? '' : undefined, 'wpWatchthis': form.wpWatchthis.checked ? '' : undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': 'PROD nomination of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': text };

self.post ( postData ); } }

twinkleprod.callback.evaluate = function twinkleprodCallbackEvaluate(e) { var form = e.target; var reason = form.reason.value;

wgPageName = wgPageName.replace(/_/g, ' ');

Status.init( form ); var query = { 'title': wgPageName, 'action': 'submit' };

var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page', query, twinkleprod.callbacks.main ); wikipedia_wiki.params = { reason: reason }; wikipedia_wiki.followRedirect = false; wikipedia_wiki.get; }