ഉപയോക്താവ്:മാതൃകാ ഉപയോക്താവ്/twinkleprod.js

വിക്കിപീഡിയ, ഒരു സ്വതന്ത്ര വിജ്ഞാനകോശം.

ശ്രദ്ധിക്കുക: സേവ് ചെയ്തശേഷം മാറ്റങ്ങൾ കാണാനായി താങ്കൾക്ക് ബ്രൗസറിന്റെ കാഷെ ഒഴിവാക്കേണ്ടി വന്നേക്കാം.

  • ഫയർഫോക്സ് / സഫാരി: Reload ബട്ടൺ അമർത്തുമ്പോൾ Shift കീ അമർത്തി പിടിക്കുകയോ, Ctrl-F5 അല്ലെങ്കിൽ Ctrl-R (മാക്കിന്റോഷിൽ ⌘-R ) എന്ന് ഒരുമിച്ച് അമർത്തുകയോ ചെയ്യുക
  • ഗൂഗിൾ ക്രോം: Ctrl-Shift-R (മാക്കിന്റോഷിൽ ⌘-Shift-R ) അമർത്തുക
  • ഇന്റർനെറ്റ് എക്സ്പ്ലോറർ: Refresh ബട്ടൺ അമർത്തുമ്പോൾ Ctrl കീ അമർത്തിപിടിക്കുക. അല്ലെങ്കിൽ Ctrl-F5 അമർത്തുക
  • ഓപ്പറ: Menu → Settings എടുക്കുക (മാക്കിൽ Opera → Preferences) എന്നിട്ട് Privacy & security → Clear browsing data → Cached images and files ചെയ്യുക.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}

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

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

/**
 TwinkleConfig.prodReasonDefault (string)
 The prefilled PROD reason.
 */
if( typeof( TwinkleConfig.prodReasonDefault ) == 'undefined' ) {
	TwinkleConfig.prodReasonDefault = "";
}

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 );
	form.append( {
			type: 'checkbox',
			list: [
				{
					label: 'Notify if possible',
					value: 'notify',
					name: 'notify',
					tooltip: 'If a notification is defined in the configuration, then notify if this is true, else no notify',
					checked: true
				}
			]
		}
	);
	var field = form.append( {
			type: 'field',
			label: 'Reason for proposed deletion'
		} );
	field.append( {
			type: 'textarea',
			name: 'reason',
			label: 'Reason:',
			value: TwinkleConfig.prodReasonDefault
		} );
	field.append( { type:'submit' } );

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

twinkleprod.callbacks = {
	main: function( self ) {
		var xmlDoc = self.responseXML;
		var exists = xmlDoc.evaluate( 'boolean(//pages/page[not(@missing)])', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;

		if( ! exists ) {
			self.statelem.error( "It seems that the page doesn't exist.  Perhaps it has already been deleted." );
			return;
		}
		
		var query = { 
			'title': wgPageName, 
			'action': 'submit'
		};
		
		var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page', query, twinkleprod.callbacks.tagPage );
		wikipedia_wiki.params = self.params;
		wikipedia_wiki.followRedirect = false;
		wikipedia_wiki.get();
	},
	tagPage: function( self ) {
		var form = self.responseXML.getElementById('editform');
		var text = form.wpTextbox1.value;

		var tag_re = /(\{\{(?:db-?|delete|[aitcmrs]fd|md1)[^{}]*?\|?[^{}]*?\}\})/i;
		if( tag_re.test( text ) ) {
			self.statelem.warn( 'Page already tagged with a deletion template, aborting procedure' );
			return;
		}

		var prod_re = /\{\{\s*dated prod\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
		if( !prod_re.test( text ) ) {
			// 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 initial contributor (' + user + ')', query, twinkleprod.callbacks.userNotification );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}

			if( self.params.usertalk ) {
				var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
				wikipedia_api.params = self.params;
				wikipedia_api.post();
			}
			
			var summaryText = "Proposing article for deletion per [[WP:PROD]].";
			text = "\{\{subst:prod|1=" + self.params.reason + "\}\}\n" + text;
		} else {
			var prod2_re = /\{\{prod-?2.*?\}\}/;
			if( prod2_re.test( text ) ) {
				self.statelem.warn( 'Page already tagged with \{\{prod\}\} and \{\{prod-2\}\} templates, aborting procedure' );
				return;
			}
			self.statelem.info( "A \{\{dated prod\}\} tag was already found on this article" );
			if( !confirm( "Would you like to add a \{\{prod-2\}\} tag with your explanation?" ) ) {
				self.statelem.info( 'Aborted per user request' );
				return;
			}
			
			var summaryText = "Endorsing proposed deletion per [[WP:PROD]].";
			text = text.replace( prod_re, text.match( prod_re ) + "\n\{\{prod-2|1=" + self.params.reason + "\}\}\n" );
		}

		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,
			'wpSection': '',
			'wpSummary': summaryText + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};

		self.post( postData );
	},
	userNotification: function( self ) {
		var form = this.responseXML.getElementById( 'editform' );
		var text = form.wpTextbox1.value;
		text += "\n\{\{subst:prodwarning|1=" + wgPageName + "|concern=" + self.params.reason + "\}\} \~\~\~\~";
		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,
			'wpSection': '',
			'wpSummary': 'PROD nomination of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};

		self.post ( postData );
	}
}

twinkleprod.callback.evaluate = function twinkleprodCallbackEvaluate(e) {
	wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country!
	var form = e.target;
	var usertalk = form.notify.checked
	var reason = form.reason.value;

	var params = {
		usertalk: usertalk,
		reason: reason
	};

	Status.init( form );

	Wikipedia.actionCompleted.redirect = wgPageName;
	Wikipedia.actionCompleted.notice = "Tagging complete";

	var query = { 
		'action': 'query',
		'titles': wgPageName
	};

	var wikipedia_api = new Wikipedia.api( 'Checking if page exists', query, twinkleprod.callbacks.main );
	wikipedia_api.params = params;
	wikipedia_api.post();
}