User:Message From Xenu/twinkletag.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}
 
/**
 TwinkleConfig.summaryAd (string)en.wikipedia.org
 If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
 */
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = " [[WP:TW|(TW)]]";
}
 
/**
 TwinkleConfig.deletionSummaryAd (string)
 If ad should be added or not to deletion summary, default [[WP:TWINKLE|TWINKLE]]
 */
if( typeof( TwinkleConfig.deletionSummaryAd ) == 'undefined' ) {
	TwinkleConfig.deletionSummaryAd = " [[WP:TW|(TW)]]";
}
 
 
/**
 TwinkleConfig.watchSpeedyPages (array)
 What types of actions that should result in forced addition to watchlist
 */
if( typeof( TwinkleConfig.watchSpeedyPages ) == 'undefined' ) {
	TwinkleConfig.watchSpeedyPages = [ 'G3', 'G10', 'G11', 'G12' ];
}
 
/**
 TwinkleConfig.markSpeedyPagesAsMinor (boolean)
 If, when applying speedy template to page, to mark the edit as minor, default true
 */
if( typeof( TwinkleConfig.markSpeedyPagesAsMinor ) == 'undefined' ) {
	TwinkleConfig.markSpeedyPagesAsMinor = true;
}
 
/**
 TwinkleConfig.notifyUserOnSpeedyDeletionNomination (array)
 What types of actions that should result that the author of the page should be notified of nomination
 */
if( typeof( TwinkleConfig.notifyUserOnSpeedyDeletionNomination ) == 'undefined' ) {
	TwinkleConfig.notifyUserOnSpeedyDeletionNomination = [ 'G1', 'G2', 'G3', 'G4', 'G10', 'G11', 'G12', 'A1', 'A2', 'A3', 'A4', 'A5', 'I1','T2' ];
} 
 
/**
 TwinkleConfig.userTalkPageMode may take arguments:
 'window': open a new window, remmenber the opened window
 'tab': opens in a new tab, if possible.
 'blank': force open in a new window, even if a such window exist
 */
if( typeof( TwinkleConfig.userTalkPageMode ) == 'undefined' ) {
	TwinkleConfig.userTalkPageMode = 'window';
}
 
/**
 TwinkleConfig.deleteTalkPageOnDelete
 If talk page if exists should also be deleted (QD G8) when speedying a page (admin only)
 */
if( typeof( TwinkleConfig.deleteTalkPageOnDelete ) == 'undefined' ) {
	TwinkleConfig.deleteTalkPageOnDelete = false;
}
 
/**
 TwinkleConfig.toolboxButtons (string)
 If id defined in this array, the button of the action is located in
the toolbox instead of in the actions bar.
 */
if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) {
	TwinkleConfig.toolboxButtons = [];
}
 
/**
 TwinkleConfig.orphanNormalPagesOnSpeedyDelete (hash)
 Defines if all backlinks to a page should be removed.
 property 'exclude' defined actions not to orphan
 */
if( typeof( TwinkleConfig.orphanBacklinksOnSpeedyDelete ) == 'undefined' ) {
	TwinkleConfig.orphanBacklinksOnSpeedyDelete = { exclude: ['G6'], orphan:true };
}
 
function twinkletag() {
	if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
		return;
	}
	if (twinkleConfigExists) {
		mw.util.addPortletLink( 'p-cactions', "javascript:twinkletag.callback()", "tag", "tw-tag", "Tag article", "");
	}
	else
	{
		mw.util.addPortletLink('p-cactions', 'javascript:alert("Your account is too new to use Twinkle.");', 'qd', 'tw-csd', 'Tag article', '');
	}
}
$(twinkletag);
 
twinkletag.callback = function twinkletagCallback() {
	var Window = new SimpleWindow( 800, 400 );
	Window.setTitle( "Tag Article" );
 
	var form = new QuickForm( twinkletag.callback.evaluateUser, 'change' );
 
	/*if( wgNamespaceNumber ==  Namespace.IMAGE ) {
		form.append( {type:'header', label:'Images/Media' } );
		form.append ( {
				type: 'radio',
				name: 'csd',
				list: [
					{ 
						label: 'I1: Prohibited image',
						value: 'prohibitedimage',
						tooltip: 'Most media uploads are not allowed on Simple English Wikipedia. They should be uploaded to Wikimedia Commons instead. There are a few exceptions to this rule. Firstly, all spoken articles should be uploaded here, as they are for local use. Secondly, there are some logos that Commons does not accept, but are needed here, for example Image:Wiki.png, which is used as the Wikipedia logo.' 
					},
 
				]
			} );
	}*/
 
	form.append( { type:'header', label:'Article content' } );
	form.append( {
			type: 'radio',
			name: 'mtpl',
			list: [
				{ 
					label: '\{\{stub\}\}',
					value: 'stub',
					tooltip: 'article needs expansion' 
				},
				{ 
					label: '\{\{npov\}\}',
					value: 'npov',
					tooltip: 'article may not be neutral'
				},
				{
					label: '\{\{complex\}\}',
					value: 'complex',
					tooltip: 'article may be too complex; not easy enough to understand'
				},
				{ 
					label: '\{\{cleanup\}\}', 
					value: 'cleanup', 
					tooltip: 'article needs cleanup' 
				},
				{
					label: '\{\{redlinks\}\}',
					value: 'redlinks',
					tooltip: 'article has too many red links'
				}
			]
		});
	form.append( { type:'header', label:'Time related' } );
	form.append( {
			type: 'radio',
			name: 'mtpl',
			list: [
				{ 
					label: '\{\{inuse\}\}',
					value: 'inuse',
					tooltip: 'article undergoing major edit' 
				},
				{ 
					label: '\{\{update\}\}',
					value: 'update',
					tooltip: 'article requires update'
				},
				{
					label: '\{\{current\}\}',
					value: 'current',
					tooltip: 'article indicates current event'
				}
			]
		});
	var result = form.render();
	Window.setContent( result );
	Window.display();
}

 
twinkletag.callbacks = {
	user: {
		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 exists, perhaps it has been deleted" );
				return;
			}
			var query = { 
				'title': wgPageName, 
				'action': 'submit'
			};
 
			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page', query, twinkletag.callbacks.user.tagPage );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.followRedirect = false;
			wikipedia_wiki.get();
		},
		tagPage: function( self ) {
			form = this.responseXML.getElementById( 'editform' );
 
			var text = form.wpTextbox1.value;
 
			self.statelem.status( 'Checking for tags on the page...' );

			var tag = new RegExp('(\{\{(?:'+self.params.normalized+')\}\})').exec( text );
 
			if( tag ) {
				self.statelem.error( [ htmlNode( 'strong', tag[0] ) , " is already placed on the page." ] )
				return;
			}
 
			var code, content;
			switch( self.params.normalized ) {
 
				case "stub":
					code = "\{\{" +  self.params.normalized+ "\}\}";
					content = text + "\n" + code;
					break;
				default:
					code = "\{\{" +  self.params.normalized+ "\}\}";
					content = code + "\n" + text;
					break;
			}
 
			// 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, twinklespeedy.callbacks.user.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 postData = {
				'wpMinoredit': TwinkleConfig.markSpeedyPagesAsMinor ? '' : undefined,
				'wpWatchthis': (self.params.watch || form.wpWatchthis.checked ) ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSummary': "Adding tag to page; " + self.params.normalized + ". " + TwinkleConfig.summaryAd,
				'wpTextbox1': content
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:QD-notice|page=" + wgPageName + "|cat=" + self.params.normalized + "|reason=" + twinklespeedy.reasonHash[ self.params.value ] + "\}\} \~\~\~\~";
 
			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': 'Notification: Quick deletion nomination of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	}
}
 
 
twinkletag.callback.evaluateUser = function twinkletagCallbackEvaluateUser(e) {
	wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country!
	var value = e.target.value;
	//var normalized = twinkletag.normalizeHash[ value ];
 
	var params = {
		value: value,
		normalized: value,
		watch: false,
		usertalk: false
	};
 
	Status.init( e.target.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, twinkletag.callbacks.user.main );
	wikipedia_api.params = params;
	wikipedia_api.post();
 
}