Jump to content

User:Gregbard/assessortags2.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript('User:AzaToth/morebits.js');
 
// If assessortagsConfig aint exist.
if( typeof( assessortagsConfig ) == 'undefined' ) {
	assessortagsConfig = {};
}
 
/**
 assessortagsConfig.summaryAd ( string )
 */
if( typeof( assessortagsConfig.summaryAd ) == 'undefined' ) {
	assessortagsConfig.summaryAd = " using [[User:Gregbard/inphilo.js/doc|INPHILO]]";
}
 
/**
 assessortagsConfig.markTaggedPagesAsMinor ( boolean )
 */
if( typeof( assessortagsConfig.markTaggedPagesAsMinor ) == 'undefined' ) {
	assessortagsConfig.markTaggedPagesAsMinor = true;
}
 
function assessortags() {
	if( wgNamespaceNumber == 1 || wgNamespaceNumber == 5 || wgNamespaceNumber == 7 || wgNamespaceNumber == 11 || wgNamespaceNumber == 13 ||wgNamespaceNumber == 15 || wgNamespaceNumber == 101 )
	mw.util.addPortletLink( 'p-cactions', "javascript:assessortags.callback()", "WP:PHILO", "ca-wikiprojecttags", "Add WikiProject banners", "");
}
 
addOnloadHook(assessortags);
 
assessortags.callback = function assessortagsCallback() {
	var Window = new SimpleWindow( 400, 500 );
	var form = new QuickForm( assessortags.callback.evaluate );
 
		Window.setTitle( "WikiProject Philosophy Banner" );
 
			}
 
		form.append( { type:'header', label:'Task Forces' } );
		form.append( { type:'checkbox', name: 'main', list: assessortags.mainList } );
 
	}
 
	form.append( { type:'submit' } );
 
	var result = form.render();
	Window.setContent( result );
	Window.display();
}
 

assessortags.mainList = [
	{
		label: 'Philosophy',
		value: 'WikiProject Philosophy',
		subgroup: {
			name: 'phil',
			type: 'checkbox',
			list: [
				{
					label: "Aesthetics task force",
					value: "|aesthetics=yes"
				},
				{
					label: "Epistemology War task force",
					value: "|epistemology=yes"
				},
				{
					label: "Ethics task force",
					value: "|ethics=yes"
				},
				{
					label: "Logic task force",
					value: "|logic=yes"
				},
				{
					label: "Metaphysics task force",
					value: "|metaphysics=yes"
				},
				{
					label: "Social and Political Philosophy task force",
					value: "|social=yes"
				},
				{
					label: "Ancient Philosophy task force",
					value: "|ancient=yes"
				},
				{
					label: "Medieval Philosophy task force",
					value: "|medieval=yes"
				},
				{
					label: "Modern Philosophy task force",
					value: "|modern=yes"
				},
				{
					label: "Contemporary Philosophy task force",
					value: "|contemporary=yes"
				},
				{
					label: "Analytic Philosophy task force",
					value: "|analytic=yes"
				},
				{
					label: "Continental Philosophy task force",
					value: "|continental=yes"
				},
				{
					label: "Eastern Philosophy task force",
					value: "|eastern=yes"
				},
				{
					label: "Jurisprudence task force",
					value: "|law=yes"
				},
				{
					label: "Philosophy of language task force",
					value: "|language=yes"
				},
				{
					label: "Philosophy of mind task force",
					value: "|mind=yes"
				},
				{
					label: "Philosophy of religion task force",
					value: "|religion=yes"
				},
				{
					label: "Philosophy of science task force",
					value: "|science=yes"
				},
				{
					label: "Philosophers task force",
					value: "|philosopher=yes"
				},
				{
					label: "Philosophical literature task force",
					value: "|literature=yes"
				},
				{
					label: "Top Importance",
					value: "|importance=top"
				},
				{
					label: "High Importance",
					value: "|importance=high"
				},
				{
					label: "Mid Importance",
					value: "|importance=mid"
				},
				{
					label: "Low Importance",
					value: "|importance=low"
				},
				{
					label: "Stub Class",
					value: "|class=stub"
				},
				{
					label: "Start Class",
					value: "|class=start"
				},
				{
					label: "C-Class",
					value: "|class=C"
				},
				{
					label: "Peer Review",
					value: "|peer-review=yes"
				},
				{
					label: "Needs Attention",
					value: "|attention=yes"
				}
                              ]
                               }
	},
];
 
 
assessortags.callbacks = {
	main: function( self ) {
		var form = self.responseXML.getElementById( 'editform' );
		var tagRe, text = '', summaryText = ''; //Is the summaryText still needed?
		var tags = new Array(), groupableTags = new Array(); //Is the groupableTags really still needed? Removing it fowls stuff up, but it seems like it should be removable
 
		// Check for preexisting tags
		Status.info( 'Info', 'Looking for banners already on page' );
		for( var i = 0; i < self.params.tags.length; i++ ) {
			tagRe = new RegExp( '(\\{\\{' + self.params.tags[i] + '(\\||\\}\\}))', 'im' );
			if( !tagRe.exec( form.wpTextbox1.value ) ) {
				tags = tags.concat( self.params.tags[i] );
			} else {
				Status.info( 'Info', 'Found \{\{' + self.params.tags[i]
					+ '\}\} on the article already...excluding' );
			}
		}
 
		if( self.params.group && tags.length >= 2 ) {
			Status.info( 'Info', 'Adding banners to top of page' );
 
			groupableTags.sort();
			for( var i = 0; i < tags.length; i++ ) {
				text += '\{\{' + tags[i];
 
				if( tags[i] == 'D&D' ) {
					text += self.params.dungeonsanddragonsSubcategory.join("");
				} else if( tags[i] == 'WikiProject Philosophy' ) {
					text += self.params.philSubcategory.join("");
				}  
				text += '\}\}\n';
			}
		} else {
			tags = tags.concat( groupableTags );
		}
 
		if( self.params.group && tags.length < 2 ) {
			Status.info( 'Info', 'Adding banners to top of page' );
 
			tags.sort();
			for( var i = 0; i < tags.length; i++ ) {
				text += '\{\{' + tags[i];
				if( tags[i] == 'WikiProject Philosophy' ) {
					text += self.params.philSubcategory.join("");
				} 
				text += '\}\}\n';
			}
 		}
 
		text += form.wpTextbox1.value;
		summaryText += 'Added WikiProject banners to page' + assessortagsConfig.summaryAd;
 
		var postData = {
			'wpMinoredit': assessortagsConfig.markTaggedPagesAsMinor ? 1 : undefined,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': summaryText,
			'wpTextbox1': text
		};
 
		self.post( postData );
	}
}
 
assessortags.callback.evaluate = function assessortagsCallbackEvaluate(e) {
	var form = e.target;
	{
		var philSubcategory = form.getChecked( 'main.phil' );
	}
	var params;
 
	if( tags.length == 0 ) {
		alert( 'Please select at least one banner.' );
		return;
	}
	params = {
		tags: tags,
		group: form.group.checked,
		philSubcategory: philSubcategory ? philSubcategory : null,
		rcid: QueryString.exists( 'rcid' ) ? QueryString.get( 'rcid' ) : ''
		}
 
	Status.init( form );
 
	var query = { 
		'title': wgPageName, 
		'action': 'submit'
	};
	Wikipedia.actionCompleted.redirect = wgPageName;
	Wikipedia.actionCompleted.notice = "Tagging complete, reloading article";
	var wikipedia_wiki = new Wikipedia.wiki( 'Article modification', query, assessortags.callbacks.main );
	wikipedia_wiki.params = params;
	wikipedia_wiki.get();
}
// </nowiki>